|
1 | | -import { bitgo } from '@bitgo/utxo-lib'; |
2 | 1 | import { AddressInfo, TransactionIO } from '@bitgo/blockapis'; |
3 | | -import * as utxolib from '@bitgo/utxo-lib'; |
4 | 2 | import { address as wasmAddress, AddressFormat } from '@bitgo/wasm-utxo'; |
5 | 3 |
|
6 | 4 | import { AbstractUtxoCoin, RecoveryProvider } from '../../../src'; |
7 | 5 | import { Bch } from '../../../src/impl/bch'; |
8 | 6 | import { Bsv } from '../../../src/impl/bsv'; |
9 | | -import type { Unspent, UnspentWithPrevTx, WalletUnspent } from '../../../src/unspent'; |
| 7 | +import { parseOutputId, type Unspent, type UnspentWithPrevTx, type WalletUnspent } from '../../../src/unspent'; |
10 | 8 | export class MockRecoveryProvider implements RecoveryProvider { |
11 | 9 | public unspents: Unspent<bigint>[]; |
12 | 10 | private prevTxCache: Record<string, string> = {}; |
13 | 11 | constructor(unspents: Unspent<bigint>[]) { |
14 | 12 | this.unspents = unspents; |
15 | 13 | this.unspents.forEach((u) => { |
16 | | - if (utxolib.bitgo.isUnspentWithPrevTx(u)) { |
17 | | - const { txid } = bitgo.parseOutputId(u.id); |
| 14 | + if ('prevTx' in u) { |
| 15 | + const { txid } = parseOutputId(u.id); |
18 | 16 | this.prevTxCache[txid] = (u as UnspentWithPrevTx<bigint>).prevTx.toString('hex'); |
19 | 17 | } |
20 | 18 | }); |
@@ -49,72 +47,6 @@ export class MockRecoveryProvider implements RecoveryProvider { |
49 | 47 | throw new Error(`not implemented`); |
50 | 48 | } |
51 | 49 | } |
52 | | -export class MockCrossChainRecoveryProvider<TNumber extends number | bigint> implements RecoveryProvider { |
53 | | - private addressVersion: 'cashaddr' | 'base58'; |
54 | | - private addressFormat: AddressFormat; |
55 | | - constructor( |
56 | | - public coin: AbstractUtxoCoin, |
57 | | - public unspents: Unspent<TNumber>[], |
58 | | - public tx: utxolib.bitgo.UtxoTransaction<TNumber> |
59 | | - ) { |
60 | | - // this is how blockchair will return the data, as a cashaddr for BCH like coins |
61 | | - // BSV supports cashaddr, but at the time of writing the SDK does not support cashaddr for bsv |
62 | | - this.addressFormat = this.coin instanceof Bch && !(this.coin instanceof Bsv) ? 'cashaddr' : 'default'; |
63 | | - this.addressVersion = this.coin instanceof Bch && !(this.coin instanceof Bsv) ? 'cashaddr' : 'base58'; |
64 | | - } |
65 | | - |
66 | | - async getUnspentsForAddresses(addresses: string[]): Promise<Unspent[]> { |
67 | | - return this.tx.outs.map((o, vout: number) => { |
68 | | - let address = wasmAddress.fromOutputScriptWithCoin(o.script, this.coin.name, this.addressFormat); |
69 | | - if (address.includes(':')) { |
70 | | - [, address] = address.split(':'); |
71 | | - } |
72 | | - return { |
73 | | - id: `${this.tx?.getId()}:${vout}`, |
74 | | - address, |
75 | | - value: Number(o.value), |
76 | | - ...(this.coin.amountType === 'bigint' ? { valueString: o.value.toString() } : {}), |
77 | | - }; |
78 | | - }); |
79 | | - } |
80 | | - |
81 | | - async getTransactionIO(txid: string): Promise<TransactionIO> { |
82 | | - const payload: TransactionIO = { |
83 | | - inputs: this.unspents.map((u) => { |
84 | | - // imitate how blockchair returns data |
85 | | - let address = this.coin.canonicalAddress(u.address, this.addressVersion); |
86 | | - if (address.includes(':')) { |
87 | | - [, address] = address.split(':'); |
88 | | - } |
89 | | - return { |
90 | | - address, |
91 | | - }; |
92 | | - }), |
93 | | - outputs: this.tx.outs.map((o) => { |
94 | | - let address = wasmAddress.fromOutputScriptWithCoin(o.script, this.coin.name, this.addressFormat); |
95 | | - if (address.includes(':')) { |
96 | | - [, address] = address.split(':'); |
97 | | - } |
98 | | - return { |
99 | | - address, |
100 | | - }; |
101 | | - }), |
102 | | - }; |
103 | | - return payload; |
104 | | - } |
105 | | - |
106 | | - async getAddressInfo(address: string): Promise<AddressInfo> { |
107 | | - throw new Error(`not implemented`); |
108 | | - } |
109 | | - |
110 | | - async getTransactionHex(txid: string): Promise<string> { |
111 | | - throw new Error(`not implemented`); |
112 | | - } |
113 | | - |
114 | | - getTransactionInputs(txid: string): Promise<Unspent<TNumber>[]> { |
115 | | - throw new Error(`not implemented`); |
116 | | - } |
117 | | -} |
118 | 50 |
|
119 | 51 | /** |
120 | 52 | * Cross-chain recovery mock provider using wasm-utxo only (no utxolib dependency). |
|
0 commit comments