diff options
Diffstat (limited to 'src/mint/taler-mint-httpd_db.c')
-rw-r--r-- | src/mint/taler-mint-httpd_db.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c index 60218ab66..2beaa8f97 100644 --- a/src/mint/taler-mint-httpd_db.c +++ b/src/mint/taler-mint-httpd_db.c | |||
@@ -686,3 +686,124 @@ TALER_MINT_db_execute_refresh_melt (struct MHD_Connection *connection, | |||
686 | 686 | ||
687 | 687 | ||
688 | } | 688 | } |
689 | |||
690 | |||
691 | /** | ||
692 | * Execute a /refresh/commit. | ||
693 | * | ||
694 | * @param connection the MHD connection to handle | ||
695 | * @param kappa size of x-dimension of @commit_coin and @commit_link arrays | ||
696 | * @param num_oldcoins size of y-dimension of @commit_coin and @commit_link arrays | ||
697 | * @param num_newcoins size of y-dimension of @commit_coin and @commit_link arrays | ||
698 | * @return MHD result code | ||
699 | */ | ||
700 | int | ||
701 | TALER_MINT_db_execute_refresh_commit (struct MHD_Connection *connection, | ||
702 | const struct GNUNET_CRYPTO_EddsaPublicKey *refresh_session_pub, | ||
703 | unsigned int kappa, | ||
704 | unsigned int num_oldcoins, | ||
705 | unsigned int num_newcoins, | ||
706 | struct RefreshCommitCoin *const*commit_coin, | ||
707 | struct RefreshCommitLink *const*commit_link) | ||
708 | |||
709 | { | ||
710 | PGconn *db_conn; | ||
711 | struct RefreshSession refresh_session; | ||
712 | unsigned int i; | ||
713 | unsigned int j; | ||
714 | int res; | ||
715 | |||
716 | if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) | ||
717 | { | ||
718 | // FIXME: return 'internal error'? | ||
719 | GNUNET_break (0); | ||
720 | return MHD_NO; | ||
721 | } | ||
722 | |||
723 | /* Send response immediately if we already know the session. | ||
724 | * Do _not_ care about fields other than session_pub in this case. */ | ||
725 | |||
726 | res = TALER_MINT_DB_get_refresh_session (db_conn, | ||
727 | refresh_session_pub, | ||
728 | &refresh_session); | ||
729 | // FIXME: this should check that kappa and num_newcoins match | ||
730 | // our expectations from refresh_session! | ||
731 | |||
732 | for (i = 0; i < refresh_session.kappa; i++) | ||
733 | { | ||
734 | for (j = 0; j < refresh_session.num_newcoins; j++) | ||
735 | { | ||
736 | if (GNUNET_OK != | ||
737 | TALER_MINT_DB_insert_refresh_commit_coin (db_conn, | ||
738 | &commit_coin[i][j])) | ||
739 | { | ||
740 | // FIXME: return 'internal error'? | ||
741 | GNUNET_break (0); | ||
742 | GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn)); | ||
743 | return MHD_NO; | ||
744 | } | ||
745 | |||
746 | if (GNUNET_OK != | ||
747 | TALER_MINT_DB_insert_refresh_commit_link (db_conn, &commit_link[i][j])) | ||
748 | { | ||
749 | // FIXME: return 'internal error'? | ||
750 | GNUNET_break (0); | ||
751 | GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn)); | ||
752 | return MHD_NO; | ||
753 | } | ||
754 | } | ||
755 | } | ||
756 | |||
757 | |||
758 | |||
759 | |||
760 | |||
761 | if ( (GNUNET_YES == res) && | ||
762 | (GNUNET_YES == refresh_session.has_commit_sig) ) | ||
763 | { | ||
764 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
765 | "sending cached commit response\n"); | ||
766 | res = TALER_MINT_reply_refresh_commit_success (connection, | ||
767 | &refresh_session); | ||
768 | GNUNET_break (res != GNUNET_SYSERR); | ||
769 | return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES; | ||
770 | } | ||
771 | if (GNUNET_SYSERR == res) | ||
772 | { | ||
773 | // FIXME: return 'internal error'? | ||
774 | GNUNET_break (0); | ||
775 | return MHD_NO; | ||
776 | } | ||
777 | |||
778 | if (GNUNET_OK != TALER_MINT_DB_transaction (db_conn)) | ||
779 | { | ||
780 | // FIXME: return 'internal error'? | ||
781 | GNUNET_break (0); | ||
782 | return MHD_NO; | ||
783 | } | ||
784 | |||
785 | /* Re-fetch the session information from the database, | ||
786 | * in case a concurrent transaction modified it. */ | ||
787 | |||
788 | res = TALER_MINT_DB_get_refresh_session (db_conn, | ||
789 | refresh_session_pub, | ||
790 | &refresh_session); | ||
791 | if (GNUNET_OK != res) | ||
792 | { | ||
793 | // FIXME: return 'internal error'? | ||
794 | GNUNET_break (GNUNET_SYSERR != res); | ||
795 | GNUNET_break (GNUNET_OK == TALER_MINT_DB_rollback (db_conn)); | ||
796 | return MHD_NO; | ||
797 | } | ||
798 | |||
799 | |||
800 | |||
801 | if (GNUNET_OK != TALER_MINT_DB_commit (db_conn)) | ||
802 | { | ||
803 | // FIXME: return 'internal error'? | ||
804 | GNUNET_break (0); | ||
805 | return MHD_NO; | ||
806 | } | ||
807 | |||
808 | return TALER_MINT_reply_refresh_commit_success (connection, &refresh_session); | ||
809 | } | ||