|
1 | | -import { BaseTransaction, BaseTransactionBuilderFactory } from '@bitgo/sdk-core'; |
| 1 | +import { |
| 2 | + BaseTransaction, |
| 3 | + BaseTransactionBuilderFactory, |
| 4 | + InvalidTransactionError, |
| 5 | + TransactionType, |
| 6 | +} from '@bitgo/sdk-core'; |
| 7 | +import { BaseCoin as CoinConfig } from '@bitgo/statics'; |
2 | 8 | import { TransactionBuilder } from './transactionBuilder'; |
3 | 9 | import { TransferBuilder } from './transferBuilder'; |
| 10 | +import { Transaction } from './transaction/transaction'; |
4 | 11 | import { WalletInitBuilder } from './walletInitBuilder'; |
5 | 12 | import { WalletInitTransaction } from './walletInitialization/walletInitTransaction'; |
6 | 13 |
|
7 | 14 | export class TransactionBuilderFactory extends BaseTransactionBuilderFactory { |
| 15 | + constructor(_coinConfig: Readonly<CoinConfig>) { |
| 16 | + super(_coinConfig); |
| 17 | + } |
8 | 18 | /** @inheritdoc */ |
9 | | - from(raw: string): TransactionBuilder { |
10 | | - throw new Error('Method not implemented.'); |
| 19 | + from(raw: string): TransactionBuilder | WalletInitBuilder { |
| 20 | + try { |
| 21 | + const tx = new WalletInitTransaction(this._coinConfig); |
| 22 | + tx.fromRawTransaction(raw); |
| 23 | + return this.getWalletInitializationBuilder(tx); |
| 24 | + } catch { |
| 25 | + const tx = new Transaction(this._coinConfig); |
| 26 | + tx.fromRawTransaction(raw); |
| 27 | + if (tx.type === TransactionType.Send) { |
| 28 | + return this.getTransferBuilder(tx); |
| 29 | + } |
| 30 | + throw new InvalidTransactionError('unsupported transaction'); |
| 31 | + } |
11 | 32 | } |
12 | 33 |
|
13 | 34 | /** @inheritdoc */ |
14 | | - getTransferBuilder(): TransferBuilder { |
15 | | - throw new Error('Method not implemented.'); |
| 35 | + getTransferBuilder(tx?: Transaction): TransferBuilder { |
| 36 | + return TransactionBuilderFactory.initializeBuilder(tx, new TransferBuilder(this._coinConfig)); |
16 | 37 | } |
17 | 38 |
|
18 | 39 | /** @inheritdoc */ |
|
0 commit comments