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

Function getTxOutputs

packages/cashscript/test/test-util.ts:18–39  ·  view source on GitHub ↗
(tx: Transaction, network: Network = defaultNetwork)

Source from the content-addressed store, hash-verified

16import { TransactionBuilder } from '../src/TransactionBuilder.js';
17
18export function getTxOutputs(tx: Transaction, network: Network = defaultNetwork): Output[] {
19 return tx.outputs.map((o) => {
20 const OP_RETURN = '6a';
21 const scriptHex = binToHex(o.lockingBytecode);
22
23 if (scriptHex.startsWith(OP_RETURN)) {
24 return { to: hexToBin(scriptHex), amount: 0n };
25 }
26
27 const prefix = getNetworkPrefix(network);
28 const cashscriptOutput = libauthOutputToCashScriptOutput(o);
29 const hasTokens = Boolean(cashscriptOutput.token);
30 const result = lockingBytecodeToCashAddress({ bytecode: hexToBin(scriptHex), prefix, tokenSupport: hasTokens });
31 if (typeof result === 'string') throw new Error(result);
32
33 return {
34 to: result.address,
35 amount: o.valueSatoshis,
36 token: cashscriptOutput.token,
37 };
38 });
39}
40
41export function getLargestUtxo(utxos: Utxo[]): Utxo {
42 return [...utxos].sort(utxoComparator).reverse()[0];

Calls 2

getNetworkPrefixFunction · 0.85

Tested by

no test coverage detected