From 2593b3952d523f9c6b8e68465b1801df9cfe72b3 Mon Sep 17 00:00:00 2001 From: kcw-grunt Date: Sun, 7 Jan 2024 14:05:09 -0500 Subject: [PATCH] added ops transaction --- BRWallet.c | 30 ++++++++++++++++++++++++++++++ BRWallet.h | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/BRWallet.c b/BRWallet.c index 4d31b0ed2..269e6dbae 100644 --- a/BRWallet.c +++ b/BRWallet.c @@ -550,6 +550,36 @@ BRTransaction *BRWalletCreateTransaction(BRWallet *wallet, uint64_t amount, cons return BRWalletCreateTxForOutputs(wallet, &o, 1); } +// 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() 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()