aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/abi_decoder.ts
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-08-24 01:58:33 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-08-24 01:58:33 +0800
commit57c104119c409c053eb977553c92341c3ca83afd (patch)
tree7f1129fd01001604e7412e33ccef202c1ff90612 /packages/utils/src/abi_decoder.ts
parentcd5c73550b969fe0a87524143ce617749935427a (diff)
parent6e27324a341801e1a2d8d6989d749dfe021ae39b (diff)
downloaddexon-sol-tools-57c104119c409c053eb977553c92341c3ca83afd.tar
dexon-sol-tools-57c104119c409c053eb977553c92341c3ca83afd.tar.gz
dexon-sol-tools-57c104119c409c053eb977553c92341c3ca83afd.tar.bz2
dexon-sol-tools-57c104119c409c053eb977553c92341c3ca83afd.tar.lz
dexon-sol-tools-57c104119c409c053eb977553c92341c3ca83afd.tar.xz
dexon-sol-tools-57c104119c409c053eb977553c92341c3ca83afd.tar.zst
dexon-sol-tools-57c104119c409c053eb977553c92341c3ca83afd.zip
Merge branch 'development' into feature/forwarder-helper/init
* development: (187 commits) Remove trailing slash Fix linter Stop nesting interfaces and add necessary type exports Remove duplicate type and remove nested interface Add support for rending the Tuple type Add missing keyu Remove excessive timestamp Improve doc commebnt Remove docs catch-all endpoint Fix comments Look for all TS mapped types Add catch and exit with non-zero Remove superfluous dep Fix CHANGELOG entry Fix double assignment Upgrade Typedoc to 0.12.0, which works with TS 3.x Fix prettier issues Enable dry run of release publishing and handle git tags existing update yarn.lock Missing/superfluous type exports from connect ...
Diffstat (limited to 'packages/utils/src/abi_decoder.ts')
-rw-r--r--packages/utils/src/abi_decoder.ts19
1 files changed, 18 insertions, 1 deletions
diff --git a/packages/utils/src/abi_decoder.ts b/packages/utils/src/abi_decoder.ts
index cc05321ab..265eb105e 100644
--- a/packages/utils/src/abi_decoder.ts
+++ b/packages/utils/src/abi_decoder.ts
@@ -15,12 +15,25 @@ import * as _ from 'lodash';
import { addressUtils } from './address_utils';
import { BigNumber } from './configured_bignumber';
+/**
+ * AbiDecoder allows you to decode event logs given a set of supplied contract ABI's. It takes the contract's event
+ * signature from the ABI and attempts to decode the logs using it.
+ */
export class AbiDecoder {
private readonly _methodIds: { [signatureHash: string]: { [numIndexedArgs: number]: EventAbi } } = {};
+ /**
+ * Instantiate an AbiDecoder
+ * @param abiArrays An array of contract ABI's
+ * @return AbiDecoder instance
+ */
constructor(abiArrays: AbiDefinition[][]) {
_.forEach(abiArrays, this.addABI.bind(this));
}
- // This method can only decode logs from the 0x & ERC20 smart contracts
+ /**
+ * Attempt to decode a log given the ABI's the AbiDecoder knows about.
+ * @param log The log to attempt to decode
+ * @return The decoded log if the requisite ABI was available. Otherwise the log unaltered.
+ */
public tryToDecodeLogOrNoop<ArgsType extends DecodedLogArgs>(log: LogEntry): LogWithDecodedArgs<ArgsType> | RawLog {
const methodId = log.topics[0];
const numIndexedArgs = log.topics.length - 1;
@@ -75,6 +88,10 @@ export class AbiDecoder {
};
}
}
+ /**
+ * Add additional ABI definitions to the AbiDecoder
+ * @param abiArray An array of ABI definitions to add to the AbiDecoder
+ */
public addABI(abiArray: AbiDefinition[]): void {
if (_.isUndefined(abiArray)) {
return;