@@ -37,6 +37,7 @@ import BigNumber from 'bignumber.js'
3737import NodePool from '../node-pool'
3838import { AMOUNT , DEPOSIT , DRY_RUN_ACCOUNT , GAS , MIN_GAS_PRICE } from '../tx/builder/schema'
3939import { decode , produceNameId } from '../tx/builder/helpers'
40+ import TxObject from '../tx/tx-object'
4041
4142function sendAndProcess ( tx , options ) {
4243 return async function ( onSuccess , onError ) {
@@ -49,8 +50,8 @@ function sendAndProcess (tx, options) {
4950
5051 const result = await this . getTxInfo ( txData . hash )
5152 return result . returnType === 'ok'
52- ? onSuccess ( { hash : txData . hash , rawTx : txData . rawTx , result, txData } )
53- : typeof onError === 'function' ? onError ( result ) : this . handleCallError ( result )
53+ ? onSuccess ( { hash : txData . hash , tx : TxObject ( { tx : txData . rawTx } ) , result, txData } )
54+ : typeof onError === 'function' ? onError ( result ) : this . handleCallError ( { result, tx : TxObject ( { tx : txData . rawTx } ) } )
5455 }
5556}
5657
@@ -60,21 +61,24 @@ function sendAndProcess (tx, options) {
6061 * @alias module:@aeternity /aepp-sdk/es/ae/contract
6162 * @category async
6263 * @param {Object } result call result object
64+ * @param {Object } tx Unpacked transaction
6365 * @throws Error Decoded error
6466 * @return {Promise<void> }
6567 */
66- async function handleCallError ( result ) {
68+ async function handleCallError ( { result, tx } ) {
6769 const error = Buffer . from ( result . returnValue ) . toString ( )
6870 if ( isBase64 ( error . slice ( 3 ) ) ) {
6971 const decodedError = Buffer . from ( error . slice ( 3 ) , 'base64' ) . toString ( )
7072 throw Object . assign ( Error ( `Invocation failed: ${ error } . Decoded: ${ decodedError } ` ) , R . merge ( result , {
73+ tx,
7174 error,
7275 decodedError
7376 } ) )
7477 }
7578
7679 const decodedError = await this . contractDecodeDataAPI ( 'string' , error )
7780 throw Object . assign ( Error ( `Invocation failed: ${ error } . Decoded: ${ decodedError } ` ) , R . merge ( result , {
81+ tx,
7882 error,
7983 decodedError
8084 } ) )
@@ -186,12 +190,13 @@ async function dryRunContractTx (tx, callerId, source, name, opt = {}) {
186190 const [ { result : status , callObj, reason } ] = ( await this . txDryRun ( [ tx ] , [ dryRunAccount ] , top ) ) . results
187191
188192 // Process response
189- if ( status !== 'ok' ) throw new Error ( 'Dry run error, ' + reason )
193+ if ( status !== 'ok' ) throw Object . assign ( new Error ( 'Dry run error, ' + reason ) , { tx : TxObject ( { tx } ) , dryRunParams : { accounts : [ dryRunAccount ] , top } } )
190194 const { returnType, returnValue } = callObj
191195 if ( returnType !== 'ok' ) {
192- await this . handleCallError ( callObj )
196+ await this . handleCallError ( { result : callObj , tx : TxObject ( { tx } ) } )
193197 }
194198 return {
199+ tx : TxObject ( { tx } ) ,
195200 result : callObj ,
196201 decode : ( ) => this . contractDecodeData ( source , name , returnValue , returnType , opt )
197202 }
0 commit comments