diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-11-15 05:51:08 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-11-29 08:38:10 +0800 |
commit | 2d2255e9af42f6441ee620c4aa74bd1981dfe03a (patch) | |
tree | c94089561cd9fdf84600c49ca29ad8c6d8eda341 /packages/order-utils/test/abi/calldata.ts | |
parent | 93e967c3b356f0081254946bbf8d6875fc791a09 (diff) | |
download | dexon-sol-tools-2d2255e9af42f6441ee620c4aa74bd1981dfe03a.tar dexon-sol-tools-2d2255e9af42f6441ee620c4aa74bd1981dfe03a.tar.gz dexon-sol-tools-2d2255e9af42f6441ee620c4aa74bd1981dfe03a.tar.bz2 dexon-sol-tools-2d2255e9af42f6441ee620c4aa74bd1981dfe03a.tar.lz dexon-sol-tools-2d2255e9af42f6441ee620c4aa74bd1981dfe03a.tar.xz dexon-sol-tools-2d2255e9af42f6441ee620c4aa74bd1981dfe03a.tar.zst dexon-sol-tools-2d2255e9af42f6441ee620c4aa74bd1981dfe03a.zip |
Cleaner interface for encoding/decoding. Moved encode/decode parameters into a struct.
Diffstat (limited to 'packages/order-utils/test/abi/calldata.ts')
-rw-r--r-- | packages/order-utils/test/abi/calldata.ts | 43 |
1 files changed, 16 insertions, 27 deletions
diff --git a/packages/order-utils/test/abi/calldata.ts b/packages/order-utils/test/abi/calldata.ts index 754d8f823..7eb4e0026 100644 --- a/packages/order-utils/test/abi/calldata.ts +++ b/packages/order-utils/test/abi/calldata.ts @@ -2,6 +2,15 @@ import ethUtil = require('ethereumjs-util'); import CommunicationChatBubbleOutline from 'material-ui/SvgIcon'; var _ = require('lodash'); +export interface DecodingRules { + structsAsObjects: boolean; +} + +export interface EncodingRules { + optimize?: boolean; + annotate?: boolean; +} + export abstract class CalldataBlock { private name: string; private signature: string; @@ -237,11 +246,13 @@ class Queue<T> { export class Calldata { private selector: string; + private rules: EncodingRules; private sizeInBytes: number; private root: MemberCalldataBlock | undefined; - constructor() { - this.selector = '0x'; + constructor(rules: EncodingRules) { + this.selector = ''; + this.rules = rules; this.sizeInBytes = 0; this.root = undefined; } @@ -272,28 +283,6 @@ export class Calldata { return blockQueue; } - /* - - // Basic optimize method that prunes duplicate branches of the tree - // Notes: - // 1. Pruning is at the calldata block level, so it is independent of type - // 2. - private optimize(blocks: CalldataBlock[]) { - // Build hash table of blocks - const blockLookupTable: { [key: string]: string } = {}; - _.each(blocks, (block: CalldataBlock) => { - if (blocks instanceof DependentCalldataBlock === false) { - - return; - } - - const leavesHash = block.hashLeaves(); - if (leavesHash in blockLookupTable) { - - } - }) - }*/ - private generateAnnotatedHexString(): string { let hexValue = `${this.selector}`; if (this.root === undefined) { @@ -413,12 +402,12 @@ export class Calldata { console.log('*'.repeat(100), ' FINISHED OPTIMIZING ', '*'.repeat(100)); } - public toHexString(optimize: boolean = false, annotate: boolean = false): string { + public toHexString(): string { if (this.root === undefined) { throw new Error('expected root'); } - if (optimize) this.optimize(); + if (this.rules.optimize) this.optimize(); const offsetQueue = this.createQueue(this.root); let block: CalldataBlock | undefined; @@ -428,7 +417,7 @@ export class Calldata { offset += block.getSizeInBytes(); } - const hexValue = annotate ? this.generateAnnotatedHexString() : this.generateCondensedHexString(); + const hexValue = this.rules.annotate ? this.generateAnnotatedHexString() : this.generateCondensedHexString(); return hexValue; } |