diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-04 20:05:35 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-04 20:05:35 +0200 |
commit | 5a645d73a8a7bf8aab448af2a957912120cbf7f0 (patch) | |
tree | c31c53599d1ade469206cdacba0f7e370c03006f /src/include | |
parent | 2521aebb798054bf1a1f3511244236339be19280 (diff) | |
download | merchant-5a645d73a8a7bf8aab448af2a957912120cbf7f0.tar.gz merchant-5a645d73a8a7bf8aab448af2a957912120cbf7f0.tar.bz2 merchant-5a645d73a8a7bf8aab448af2a957912120cbf7f0.zip |
revisiting merchant backenddb, towards fixing #4502/#4160
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/taler_merchant_service.h | 2 | ||||
-rw-r--r-- | src/include/taler_merchantdb_plugin.h | 198 |
2 files changed, 175 insertions, 25 deletions
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index 7a22b47c..fef668e3 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -55,7 +55,7 @@ typedef void struct TALER_MERCHANT_TrackDepositOperation * TALER_MERCHANT_track_deposit (struct GNUNET_CURL_Context *ctx, const char *backend_uri, - const char *wtid, + const struct TALER_WireTransferIdentifierRawP *wtid, const char *exchange_uri, TALER_MERCHANT_TrackDepositCallback trackdeposit_cb, void *trackdeposit_cb_cls); diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h index ca7870d7..16064448 100644 --- a/src/include/taler_merchantdb_plugin.h +++ b/src/include/taler_merchantdb_plugin.h @@ -31,9 +31,68 @@ struct TALER_MERCHANTDB_Plugin; +/** + * Function called with information about a transaction. + * + * @param cls closure + * @param transaction_id of the contract + * @param h_contract hash of the contract + * @param h_wire hash of our wire details + * @param timestamp time of the confirmation + * @param refund refund deadline + * @param total_amount total amount we receive for the contract after fees + */ +typedef void +(*TALER_MERCHANTDB_TransactionCallback)(void *cls, + uint64_t transaction_id, + const struct GNUNET_HashCode *h_contract, + const struct GNUNET_HashCode *h_wire, + struct GNUNET_TIME_Absolute timestamp, + struct GNUNET_TIME_Absolute refund, + const struct TALER_Amount *total_amount); + + +/** + * Function called with information about a coin that was deposited. + * + * @param cls closure + * @param transaction_id of the contract + * @param coin_pub public key of the coin + * @param amount_with_fee amount the exchange will deposit for this coin + * @param deposit_fee fee the exchange will charge for this coin + * @param exchange_proof proof from exchange that coin was accepted + */ +typedef void +(*TALER_MERCHANTDB_CoinDepositCallback)(void *cls, + uint64_t transaction_id, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_Amount *amount_with_fee, + const struct TALER_Amount *deposit_fee, + const json_t *exchange_proof); + + +/** + * Information about the wire transfer corresponding to + * a deposit operation. Note that it is in theory possible + * that we have a @a transaction_id and @a coin_pub in the + * result that do not match a deposit that we know about, + * for example because someone else deposited funds into + * our account. + * + * @param cls closure + * @param transaction_id ID of the contract + * @param coin_pub public key of the coin + * @param wtid identifier of the wire transfer in which the exchange + * send us the money for the coin deposit + * @param exchange_proof proof from exchange about what the deposit was for + * NULL if we have not asked for this signature + */ typedef void -(*TALER_MERCHANTDB_PaymentCallback)(void *cls, - ...); +(*TALER_MERCHANTDB_TransferCallback)(void *cls, + uint64_t transaction_id, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_WireTransferIdentifierRawP *wtid, + const json_t *exchange_proof); /** @@ -71,62 +130,153 @@ struct TALER_MERCHANTDB_Plugin int (*initialize) (void *cls); + /** - * Insert payment confirmation from the exchange into the database. + * Insert transaction data into the database. * * @param cls closure + * @param transaction_id of the contract * @param h_contract hash of the contract * @param h_wire hash of our wire details - * @param transaction_id of the contract * @param timestamp time of the confirmation * @param refund refund deadline - * @param amount_without_fee amount the exchange will deposit + * @param total_amount total amount we receive for the contract after fees + * @return #GNUNET_OK on success, #GNUNET_SYSERR upon error + */ + int + (*store_transaction) (void *cls, + uint64_t transaction_id, + const struct GNUNET_HashCode *h_contract, + const struct GNUNET_HashCode *h_wire, + struct GNUNET_TIME_Absolute timestamp, + struct GNUNET_TIME_Absolute refund, + const struct TALER_Amount *total_amount); + + + /** + * Insert payment confirmation from the exchange into the database. + * + * @param cls closure + * @param transaction_id of the contract * @param coin_pub public key of the coin + * @param amount_with_fee amount the exchange will deposit for this coin + * @param deposit_fee fee the exchange will charge for this coin * @param exchange_proof proof from exchange that coin was accepted * @return #GNUNET_OK on success, #GNUNET_SYSERR upon error */ int - (*store_payment) (void *cls, - const struct GNUNET_HashCode *h_contract, - const struct GNUNET_HashCode *h_wire, + (*store_deposit) (void *cls, uint64_t transaction_id, - struct GNUNET_TIME_Absolute timestamp, - struct GNUNET_TIME_Absolute refund, - const struct TALER_Amount *amount_without_fee, const struct TALER_CoinSpendPublicKeyP *coin_pub, - const json_t *exchange_proof); + const struct TALER_Amount *amount_with_fee, + const struct TALER_Amount *deposit_fee, + const json_t *exchange_proof); /** - * Check whether a payment has already been stored + * Insert mapping of @a coin_pub and @a transaction_id to + * corresponding @a wtid. * - * @param cls our plugin handle - * @param transaction_id the transaction id to search into - * the db + * @param cls closure + * @param transaction_id ID of the contract + * @param coin_pub public key of the coin + * @param wtid identifier of the wire transfer in which the exchange + * send us the money for the coin deposit + * @return #GNUNET_OK on success, #GNUNET_SYSERR upon error + */ + int + (*store_coin_to_transfer) (void *cls, + uint64_t transaction_id, + const struct TALER_CoinSpendPublicKeyP *coin_pub, + const struct TALER_WireTransferIdentifierRawP *wtid); + + + /** + * Insert wire transfer confirmation from the exchange into the database. * + * @param cls closure + * @param wtid identifier of the wire transfer + * @param exchange_proof proof from exchange about what the deposit was for + * @return #GNUNET_OK on success, #GNUNET_SYSERR upon error + */ + int + (*store_transfer_to_proof) (void *cls, + const struct TALER_WireTransferIdentifierRawP *wtid, + const json_t *exchange_proof); + + + /** + * Find information about a transaction. + * + * @param cls our plugin handle + * @param transaction_id the transaction id to search + * @param cb function to call with transaction data + * @param cb_cls closure for @a cb * @return #GNUNET_OK if found, #GNUNET_NO if not, #GNUNET_SYSERR - * upon error + * upon error + */ + int + (*find_transaction_by_id) (void *cls, + uint64_t transaction_id, + TALER_MERCHANTDB_TransactionCallback cb, + void *cb_cls); + + + /** + * Lookup information about coin payments by transaction ID. + * + * @param cls closure + * @param transaction_id key for the search + * @param cb function to call with payment data + * @param cb_cls closure for @a cb + * @return #GNUNET_OK on success, #GNUNET_NO if transaction Id is unknown, + * #GNUNET_SYSERR on hard errors */ int - (*check_payment) (void *cls, - uint64_t transaction_id); + (*find_payments_by_id) (void *cls, + uint64_t transaction_id, + TALER_MERCHANTDB_CoinDepositCallback cb, + void *cb_cls); /** - * Lookup information about a payment by transaction ID. + * Lookup information about a transfer by @a transaction_id. Note + * that in theory there could be multiple wire transfers for a + * single @a transaction_id, as the transaction may have involved + * multiple coins and the coins may be spread over different wire + * transfers. * * @param cls closure * @param transaction_id key for the search + * @param cb function to call with transfer data + * @param cb_cls closure for @a cb + * @return #GNUNET_OK on success, #GNUNET_NO if transaction Id is unknown, + * #GNUNET_SYSERR on hard errors + */ + int + (*find_transfers_by_id) (void *cls, + uint64_t transaction_id, + TALER_MERCHANTDB_TransferCallback cb, + void *cb_cls); + + + /** + * Lookup information about a coin deposits by @a wtid. + * + * @param cls closure + * @param wtid wire transfer identifier to find matching transactions for * @param cb function to call with payment data * @param cb_cls closure for @a cb * @return #GNUNET_OK on success, #GNUNET_NO if transaction Id is unknown, * #GNUNET_SYSERR on hard errors */ int - (*find_payment) (void *cls, - uint64_t transaction_id, - TALER_MERCHANTDB_PaymentCallback cb, - void *cb_cls); + (*find_deposits_by_wtid) (void *cls, + const struct TALER_WireTransferIdentifierRawP *wtid, + TALER_MERCHANTDB_CoinDepositCallback cb, + void *cb_cls); }; + + #endif |