|
| 1 | +import { BaseCoin as CoinConfig, EthereumNetwork, CoinFeature, NetworkType } from '@bitgo/statics'; |
| 2 | +import { BuildTransactionError, TransactionType } from '@bitgo/sdk-core'; |
| 3 | +import { |
| 4 | + TransactionBuilder as AbstractTransactionBuilder, |
| 5 | + Transaction, |
| 6 | + TransferBuilder, |
| 7 | + getCommon as getAbstractCommon, |
| 8 | +} from '@bitgo/abstract-eth'; |
| 9 | +import EthereumCommon from '@ethereumjs/common'; |
| 10 | + |
| 11 | +/** |
| 12 | + * Get the Ethereum common configuration for Irys. |
| 13 | + * @param coin - The coin configuration |
| 14 | + * @returns Ethereum common configuration object |
| 15 | + */ |
| 16 | +function getCommon(coin: Readonly<CoinConfig>): EthereumCommon { |
| 17 | + return EthereumCommon.custom( |
| 18 | + { |
| 19 | + name: coin.network.name, |
| 20 | + networkId: (coin.network as EthereumNetwork).chainId, |
| 21 | + chainId: (coin.network as EthereumNetwork).chainId, |
| 22 | + }, |
| 23 | + { |
| 24 | + baseChain: coin.network.type === NetworkType.MAINNET ? 'mainnet' : 'sepolia', |
| 25 | + hardfork: coin.features.includes(CoinFeature.EIP1559) ? 'london' : undefined, |
| 26 | + eips: coin.features.includes(CoinFeature.EIP1559) ? [1559] : undefined, |
| 27 | + } |
| 28 | + ); |
| 29 | +} |
| 30 | + |
| 31 | +/** |
| 32 | + * Irys transaction builder for standard EVM transactions. |
| 33 | + */ |
| 34 | +export class TransactionBuilder extends AbstractTransactionBuilder { |
| 35 | + protected _transfer: TransferBuilder; |
| 36 | + |
| 37 | + constructor(_coinConfig: Readonly<CoinConfig>) { |
| 38 | + super(_coinConfig); |
| 39 | + this._common = getCommon(this._coinConfig); |
| 40 | + this.transaction = new Transaction(this._coinConfig, this._common); |
| 41 | + } |
| 42 | + |
| 43 | + /** @inheritdoc */ |
| 44 | + transfer(data?: string): TransferBuilder { |
| 45 | + if (this._type !== TransactionType.Send) { |
| 46 | + throw new BuildTransactionError('Transfers can only be set for send transactions'); |
| 47 | + } |
| 48 | + if (!this._transfer) { |
| 49 | + this._transfer = new TransferBuilder(data); |
| 50 | + } |
| 51 | + return this._transfer; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Get contract data for wallet initialization. |
| 56 | + * |
| 57 | + * This method is intentionally not implemented for Irys. Irys uses commitment |
| 58 | + * transactions (STAKE, PLEDGE) for staking operations, which are built via |
| 59 | + * IrysCommitmentTransactionBuilder, not through standard EVM contract calls. |
| 60 | + * Standard EVM transfers work normally via the inherited transfer() method. |
| 61 | + * |
| 62 | + * @throws Error - Always throws as this is not supported for Irys |
| 63 | + */ |
| 64 | + protected getContractData(addresses: string[]): string { |
| 65 | + throw new Error( |
| 66 | + 'getContractData is not implemented for Irys. Use IrysCommitmentTransactionBuilder for staking operations.' |
| 67 | + ); |
| 68 | + } |
| 69 | +} |
0 commit comments