Skip to content

Commit

Permalink
feat(NodeInvocationError): store tx-encoded transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Apr 22, 2022
1 parent 3fa58de commit a74da7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/contract/aci.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,12 @@ export default async function getContractInstance ({
if (options.waitMined === false) return result
const { callInfo } = await this.api.getTransactionInfoByHash(txData.hash)
Object.assign(result.txData, callInfo) // TODO: don't duplicate data in result
await handleCallError(callInfo)
await handleCallError(callInfo, tx)
return { ...result, result: callInfo }
}

const handleCallError = ({ returnType, returnValue }) => {
const handleCallError = ({ returnType, returnValue }, transaction) => {
let message
// TODO: ensure that it works correctly https://github.com/aeternity/aepp-calldata-js/issues/88
switch (returnType) {
case 'ok': return
case 'revert':
Expand All @@ -161,7 +160,7 @@ export default async function getContractInstance ({
break
default: throw new InternalError(`Unknown returnType: ${returnType}`)
}
throw new NodeInvocationError(message)
throw new NodeInvocationError(message, transaction)
}

instance._estimateGas = async (name, params, options) => {
Expand Down Expand Up @@ -260,7 +259,7 @@ export default async function getContractInstance ({
: await this.contractCallTx({ ...txOpt, callerId, contractId })

const { callObj, ...dryRunOther } = await this.txDryRun(tx, callerId, opt)
await handleCallError(callObj)
await handleCallError(callObj, tx)
res = { ...dryRunOther, tx: TxObject({ tx }), result: callObj }
} else {
const tx = await this.contractCallTx({
Expand Down
8 changes: 5 additions & 3 deletions src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,12 @@ export class MissingFunctionNameError extends ContractError {
}

export class NodeInvocationError extends ContractError {
constructor (message?: string) {
message = message ?? ''
super(`Invocation failed${message === '' ? '' : `: "${message}"`}`)
transaction: string

constructor (message: string, transaction: string) {
super(`Invocation failed${message == null ? '' : `: "${message}"`}`)
this.name = 'NodeInvocationError'
this.transaction = transaction
}
}

Expand Down

0 comments on commit a74da7c

Please sign in to comment.