diff --git a/modules/sdk-coin-sui/src/lib/customTransaction.ts b/modules/sdk-coin-sui/src/lib/customTransaction.ts index 93137d8833..46a0961426 100644 --- a/modules/sdk-coin-sui/src/lib/customTransaction.ts +++ b/modules/sdk-coin-sui/src/lib/customTransaction.ts @@ -8,11 +8,12 @@ import { import { Transaction } from './transaction'; import { BaseCoin as CoinConfig } from '@bitgo/statics'; import utils from './utils'; -import { BaseKey, InvalidTransactionError, TransactionRecipient, TransactionType } from '@bitgo/sdk-core'; +import { BaseKey, InvalidTransactionError, Recipient, TransactionRecipient, TransactionType } from '@bitgo/sdk-core'; import { UNAVAILABLE_TEXT } from './constants'; export class CustomTransaction extends Transaction { private _rawTransaction: string; + private _recipients: Recipient[]; constructor(_coinConfig: Readonly) { super(_coinConfig); @@ -70,13 +71,13 @@ export class CustomTransaction extends Transaction ({ + this._recipients = utils.getRecipients(this._suiTransaction); + this._outputs = this._recipients.map((recipient, index) => ({ address: recipient.address, value: recipient.amount, coin: this._coinConfig.name, })); - const totalAmount = recipients.reduce((accumulator, current) => accumulator + Number(current.amount), 0); + const totalAmount = this._recipients.reduce((accumulator, current) => accumulator + Number(current.amount), 0); this._inputs = [ { diff --git a/modules/sdk-coin-sui/src/lib/customTransactionBuilder.ts b/modules/sdk-coin-sui/src/lib/customTransactionBuilder.ts index 83d58c0e32..d8cac02b4f 100644 --- a/modules/sdk-coin-sui/src/lib/customTransactionBuilder.ts +++ b/modules/sdk-coin-sui/src/lib/customTransactionBuilder.ts @@ -2,7 +2,7 @@ import { TransactionBuilder } from './transactionBuilder'; import { CustomProgrammableTransaction, SuiTransaction, SuiTransactionType } from './iface'; import { BaseCoin as CoinConfig } from '@bitgo/statics'; import { CustomTransaction } from './customTransaction'; -import { BuildTransactionError, TransactionType } from '@bitgo/sdk-core'; +import { BuildTransactionError, InvalidTransactionError, TransactionType } from '@bitgo/sdk-core'; import { Transaction } from './transaction'; import assert from 'assert'; import utils from './utils'; @@ -63,6 +63,10 @@ export class CustomTransactionBuilder extends TransactionBuilder { - utils.getSuiTransactionType(tx); - }); + try { + this.transaction.suiTransaction.tx.transactions.forEach((tx) => { + utils.getSuiTransactionType(tx); + }); + } catch (e) { + if (e instanceof InvalidTransactionError) { + throw new BuildTransactionError(e.message); + } + throw e; + } } /** diff --git a/modules/sdk-coin-sui/src/lib/utils.ts b/modules/sdk-coin-sui/src/lib/utils.ts index a3a86c5587..00e59df2de 100644 --- a/modules/sdk-coin-sui/src/lib/utils.ts +++ b/modules/sdk-coin-sui/src/lib/utils.ts @@ -214,10 +214,10 @@ export class Utils implements BaseUtils { } else if (command.target.endsWith(MethodNames.StakingPoolSplit)) { return SuiTransactionType.CustomTx; } else { - throw new InvalidTransactionError(`unsupported target method`); + throw new InvalidTransactionError(`unsupported target method ${command.target}`); } default: - throw new InvalidTransactionError(`unsupported transaction kind`); + throw new InvalidTransactionError(`unsupported transaction kind ${command.kind}`); } }