Skip to content

Commit

Permalink
Added description and renamed function
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Sep 29, 2023
1 parent c1d3f0f commit 17f4917
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
28 changes: 25 additions & 3 deletions typescript/src/redemption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export async function submitRedemptionTransaction(
const bitcoinNetwork = await bitcoinClient.getNetwork()

const { transactionHash, newMainUtxo, rawTransaction } =
await assembleRedemptionTransactionBitcoinJsLib(
await assembleRedemptionTransaction(
bitcoinNetwork,
walletPrivateKey,
mainUtxoWithRaw,
Expand Down Expand Up @@ -239,8 +239,30 @@ async function getWalletRedemptionRequests(
return redemptionRequests
}

// TODO: Description.
export async function assembleRedemptionTransactionBitcoinJsLib(
/**
* Assembles a Bitcoin redemption transaction.
* The transaction will have a single input (main UTXO of the wallet making
* the redemption), an output for each redemption request provided, and a change
* output if the redemption requests do not consume the entire amount of the
* single input.
* @dev The caller is responsible for ensuring the redemption request list is
* correctly formed:
* - there is at least one redemption
* - the `requestedAmount` in each redemption request is greater than
* the sum of its `txFee` and `treasuryFee`
* @param bitcoinNetwork - The target Bitcoin network (mainnet or testnet).
* @param walletPrivateKey - The private key of the wallet in the WIF format
* @param mainUtxo - The main UTXO of the wallet. Must match the main UTXO held
* by the on-chain Bridge contract
* @param redemptionRequests - The list of redemption requests
* @param witness - The parameter used to decide the type of the change output.
* P2WPKH if `true`, P2PKH if `false`
* @returns The outcome consisting of:
* - the redemption transaction hash,
* - the optional new wallet's main UTXO produced by this transaction.
* - the redemption transaction in the raw format
*/
export async function assembleRedemptionTransaction(
bitcoinNetwork: BitcoinNetwork,
walletPrivateKey: string,
mainUtxo: UnspentTransactionOutput & RawTransaction,
Expand Down
18 changes: 9 additions & 9 deletions typescript/test/redemption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
findWalletForRedemptionData,
} from "./data/redemption"
import {
assembleRedemptionTransactionBitcoinJsLib,
assembleRedemptionTransaction,
findWalletForRedemption,
getRedemptionRequest,
RedemptionRequest,
Expand Down Expand Up @@ -494,7 +494,7 @@ describe("Redemption", () => {
transactionHash,
newMainUtxo,
rawTransaction: transaction,
} = await assembleRedemptionTransactionBitcoinJsLib(
} = await assembleRedemptionTransaction(
BitcoinNetwork.Testnet,
walletPrivateKey,
data.mainUtxo,
Expand Down Expand Up @@ -608,7 +608,7 @@ describe("Redemption", () => {
transactionHash,
newMainUtxo,
rawTransaction: transaction,
} = await assembleRedemptionTransactionBitcoinJsLib(
} = await assembleRedemptionTransaction(
BitcoinNetwork.Testnet,
walletPrivateKey,
data.mainUtxo,
Expand Down Expand Up @@ -721,7 +721,7 @@ describe("Redemption", () => {
transactionHash,
newMainUtxo,
rawTransaction: transaction,
} = await assembleRedemptionTransactionBitcoinJsLib(
} = await assembleRedemptionTransaction(
BitcoinNetwork.Testnet,
walletPrivateKey,
data.mainUtxo,
Expand Down Expand Up @@ -834,7 +834,7 @@ describe("Redemption", () => {
transactionHash,
newMainUtxo,
rawTransaction: transaction,
} = await assembleRedemptionTransactionBitcoinJsLib(
} = await assembleRedemptionTransaction(
BitcoinNetwork.Testnet,
walletPrivateKey,
data.mainUtxo,
Expand Down Expand Up @@ -946,7 +946,7 @@ describe("Redemption", () => {
transactionHash,
newMainUtxo,
rawTransaction: transaction,
} = await assembleRedemptionTransactionBitcoinJsLib(
} = await assembleRedemptionTransaction(
BitcoinNetwork.Testnet,
walletPrivateKey,
data.mainUtxo,
Expand Down Expand Up @@ -1104,7 +1104,7 @@ describe("Redemption", () => {
transactionHash,
newMainUtxo,
rawTransaction: transaction,
} = await assembleRedemptionTransactionBitcoinJsLib(
} = await assembleRedemptionTransaction(
BitcoinNetwork.Testnet,
walletPrivateKey,
data.mainUtxo,
Expand Down Expand Up @@ -1211,7 +1211,7 @@ describe("Redemption", () => {
transactionHash,
newMainUtxo,
rawTransaction: transaction,
} = await assembleRedemptionTransactionBitcoinJsLib(
} = await assembleRedemptionTransaction(
BitcoinNetwork.Testnet,
walletPrivateKey,
data.mainUtxo,
Expand Down Expand Up @@ -1301,7 +1301,7 @@ describe("Redemption", () => {

it("should revert", async () => {
await expect(
assembleRedemptionTransactionBitcoinJsLib(
assembleRedemptionTransaction(
BitcoinNetwork.Testnet,
walletPrivateKey,
data.mainUtxo,
Expand Down

0 comments on commit 17f4917

Please sign in to comment.