(tx: Transaction, network: Network = defaultNetwork)
| 16 | import { TransactionBuilder } from '../src/TransactionBuilder.js'; |
| 17 | |
| 18 | export 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 | |
| 41 | export function getLargestUtxo(utxos: Utxo[]): Utxo { |
| 42 | return [...utxos].sort(utxoComparator).reverse()[0]; |
no test coverage detected