Skip to content

Commit

Permalink
Refactor inline fees (#37)
Browse files Browse the repository at this point in the history
* added notes to the BRCreateTransactionOutputs

Signed-off-by: kcw-grunt <[email protected]>

* added ops transaction

---------

Signed-off-by: kcw-grunt <[email protected]>
  • Loading branch information
kcw-grunt committed Jan 7, 2024
1 parent 44b3f9c commit ffc219f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 34 additions & 1 deletion BRWallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion BRWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ffc219f

Please sign in to comment.