@@ -15,7 +15,7 @@ import {
1515 VerifyTransactionOptions ,
1616} from '@bitgo/sdk-core' ;
1717import { BaseCoin as StaticsBaseCoin , coins } from '@bitgo/statics' ;
18- import { KeyPair as AptKeyPair , Transaction , TransactionBuilderFactory , TransferTransaction } from './lib' ;
18+ import { KeyPair as AptKeyPair , TransactionBuilderFactory } from './lib' ;
1919import utils from './lib/utils' ;
2020import * as _ from 'lodash' ;
2121import BigNumber from 'bignumber.js' ;
@@ -79,20 +79,16 @@ export class Apt extends BaseCoin {
7979 return true ;
8080 }
8181
82- getTransaction ( coinConfig : Readonly < StaticsBaseCoin > ) : Transaction {
83- return new TransferTransaction ( coinConfig ) ;
84- }
85-
8682 async verifyTransaction ( params : VerifyTransactionOptions ) : Promise < boolean > {
87- const coinConfig = coins . get ( this . getChain ( ) ) ;
8883 const { txPrebuild : txPrebuild , txParams : txParams } = params ;
89- const transaction = this . getTransaction ( coinConfig ) ;
90- const rawTx = txPrebuild . txHex ;
91- if ( ! rawTx ) {
84+ const txHex = txPrebuild . txHex ;
85+ if ( ! txHex ) {
9286 throw new Error ( 'missing required tx prebuild property txHex' ) ;
9387 }
94- transaction . fromRawTransaction ( rawTx ) ;
95- const explainedTx = transaction . explainTransaction ( ) ;
88+ const explainedTx = await this . explainTransaction ( { txHex } ) ;
89+ if ( ! explainedTx ) {
90+ throw new Error ( 'failed to explain transaction' ) ;
91+ }
9692 if ( txParams . recipients !== undefined ) {
9793 const filteredRecipients = txParams . recipients ?. map ( ( recipient ) => {
9894 return {
@@ -155,11 +151,9 @@ export class Apt extends BaseCoin {
155151 * @param params
156152 */
157153 async explainTransaction ( params : ExplainTransactionOptions ) : Promise < AptTransactionExplanation | undefined > {
158- const factory = this . getBuilder ( ) ;
159154 let rebuiltTransaction : BaseTransaction ;
160155 try {
161- const transactionBuilder = factory . from ( params . txHex ) ;
162- rebuiltTransaction = await transactionBuilder . build ( ) ;
156+ rebuiltTransaction = await this . rebuildTransaction ( params . txHex ) ;
163157 } catch {
164158 return undefined ;
165159 }
@@ -190,7 +184,17 @@ export class Apt extends BaseCoin {
190184 throw new Error ( 'Method not implemented.' ) ;
191185 }
192186
193- private getBuilder ( ) : TransactionBuilderFactory {
187+ protected getTxBuilderFactory ( ) : TransactionBuilderFactory {
194188 return new TransactionBuilderFactory ( coins . get ( this . getChain ( ) ) ) ;
195189 }
190+
191+ protected async rebuildTransaction ( txHex : string ) : Promise < BaseTransaction > {
192+ const txBuilderFactory = this . getTxBuilderFactory ( ) ;
193+ try {
194+ const txBuilder = txBuilderFactory . from ( txHex ) ;
195+ return await txBuilder . build ( ) ;
196+ } catch {
197+ throw new Error ( 'Failed to rebuild transaction' ) ;
198+ }
199+ }
196200}
0 commit comments