MCPcopy Create free account
hub / github.com/CashScript/cashscript / sendLiveAddUtxo

Function sendLiveAddUtxo

packages/cashscript/test/test-util.ts:88–111  ·  view source on GitHub ↗
(
  provider: NetworkProvider,
  address: string,
  utxo: Utxo,
)

Source from the content-addressed store, hash-verified

86}
87
88async function sendLiveAddUtxo(
89 provider: NetworkProvider,
90 address: string,
91 utxo: Utxo,
92): Promise<Utxo> {
93 const funderUtxos = (await provider.getUtxos(funderAddress))
94 .filter(isNonTokenUtxo)
95 .sort(utxoComparator)
96 .reverse();
97
98 const { utxos: selected } = gatherUtxos(funderUtxos, { amount: utxo.satoshis, fee: 2000n });
99
100 const tx = await new TransactionBuilder({ provider })
101 .addInputs(selected, new SignatureTemplate(funderPriv).unlockP2PKH())
102 .addOutput({ to: address, amount: utxo.satoshis })
103 .addBchChangeOutputIfNeeded({ to: funderAddress, feeRate: 1.0 })
104 .send();
105
106 return {
107 txid: tx.txid,
108 vout: 0,
109 satoshis: utxo.satoshis,
110 };
111}
112
113export function gatherUtxos(
114 utxos: Utxo[],

Callers 1

addUtxoFunction · 0.85

Calls 7

gatherUtxosFunction · 0.85
sendMethod · 0.80
addInputsMethod · 0.80
unlockP2PKHMethod · 0.80
getUtxosMethod · 0.65
addOutputMethod · 0.45

Tested by

no test coverage detected