Skip to content

Commit

Permalink
Merge pull request #10 from DIG-Network/memos-for-send-xch
Browse files Browse the repository at this point in the history
Memos for `sendXch`
  • Loading branch information
MichaelTaylor3D authored Sep 18, 2024
2 parents cfd9e64 + b299099 commit 20877b0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export declare function selectCoins(allCoins: Array<Coin>, totalAmount: bigint):
export interface Output {
puzzleHash: Buffer
amount: bigint
memos: Array<Buffer>
}
/**
* Sends XCH to a given set of puzzle hashes.
Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ pub fn select_coins(all_coins: Vec<Coin>, total_amount: BigInt) -> napi::Result<
pub struct Output {
pub puzzle_hash: Buffer,
pub amount: BigInt,
pub memos: Vec<Buffer>,
}

/// Sends XCH to a given set of puzzle hashes.
Expand All @@ -752,6 +753,11 @@ pub fn send_xch(
items.push((
RustBytes32::from_js(output.puzzle_hash)?,
u64::from_js(output.amount)?,
output
.memos
.into_iter()
.map(RustBytes::from_js)
.collect::<Result<Vec<RustBytes>>>()?,
));
}

Expand Down
4 changes: 2 additions & 2 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fn spend_coins_together(
pub fn send_xch(
synthetic_key: PublicKey,
coins: &[Coin],
outputs: &[(Bytes32, u64)],
outputs: &[(Bytes32, u64, Vec<Bytes>)],
fee: u64,
) -> Result<Vec<CoinSpend>, WalletError> {
let mut ctx = SpendContext::new();
Expand All @@ -202,7 +202,7 @@ pub fn send_xch(
let mut total_amount = fee;

for output in outputs {
conditions = conditions.create_coin(output.0, output.1, Vec::new());
conditions = conditions.create_coin(output.0, output.1, output.2.clone());
total_amount += output.1;
}

Expand Down

0 comments on commit 20877b0

Please sign in to comment.