From ffc219f9e707684ff4f32e87c9522f2acaa36c36 Mon Sep 17 00:00:00 2001 From: Kerry Washington Date: Sun, 7 Jan 2024 18:25:43 -0500 Subject: [PATCH] Refactor inline fees (#37) * added notes to the BRCreateTransactionOutputs Signed-off-by: kcw-grunt * added ops transaction --------- Signed-off-by: kcw-grunt --- BRWallet.c | 35 ++++++++++++++++++++++++++++++++++- BRWallet.h | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/BRWallet.c b/BRWallet.c index 11ae36da7..269e6dbae 100644 --- a/BRWallet.c +++ b/BRWallet.c @@ -550,8 +550,41 @@ BRTransaction *BRWalletCreateTransaction(BRWallet *wallet, uint64_t amount, cons return BRWalletCreateTxForOutputs(wallet, &o, 1); } -// returns an unsigned transaction that satisifes the given transaction outputs +// returns an unsigned transaction that sends the specified amount from the wallet to the given address // result must be freed by calling BRTransactionFree() +BRTransaction *BRWalletCreateOpsTransaction(BRWallet *wallet, + uint64_t amount, + const char *addr, + uint64_t opsFee, + const char *opsAddr) { + + BRTxOutput mainOutput = BR_TX_OUTPUT_NONE; + BRTxOutput opsOutput = BR_TX_OUTPUT_NONE; + + assert(wallet != NULL); + assert(amount > 0); + assert(addr != NULL && BRAddressIsValid(addr)); + mainOutput.amount = amount; + BRTxOutputSetAddress(&mainOutput, addr); + + assert(wallet != NULL); + assert(opsFee > 0); + assert(opsAddr != NULL && BRAddressIsValid(opsAddr)); + opsOutput.amount = opsFee; + BRTxOutputSetAddress(&opsOutput, opsAddr); + + BRTxOutput outputs[2]; + outputs[0] = opsOutput; + outputs[1] = mainOutput; + + return BRWalletCreateTxForOutputs(wallet, outputs, 2); +} + +/// Description: +/// returns an unsigned transaction that satisifes the given transaction outputs +/// result must be freed by calling BRTransactionFree() +/// Parameters +/// returns Transaction BRTransaction *BRWalletCreateTxForOutputs(BRWallet *wallet, const BRTxOutput outputs[], size_t outCount) { BRTransaction *tx, *transaction = BRTransactionNew(); diff --git a/BRWallet.h b/BRWallet.h index 452104489..f37ec1cbf 100644 --- a/BRWallet.h +++ b/BRWallet.h @@ -123,7 +123,7 @@ void BRWalletSetFeePerKb(BRWallet *wallet, uint64_t feePerKb); // returns an unsigned transaction that sends the specified amount from the wallet to the given address // result must be freed using BRTransactionFree() -BRTransaction *BRWalletCreateTransaction(BRWallet *wallet, uint64_t amount, const char *addr); +BRTransaction *BRWalletCreateOpsTransaction(BRWallet *wallet, uint64_t amount, const char *addr, uint64_t opsFee, const char *opsAddr); // returns an unsigned transaction that satisifes the given transaction outputs // result must be freed using BRTransactionFree()