Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
strict decoding of return values using generics
Browse files Browse the repository at this point in the history
  • Loading branch information
hysz committed Jan 14, 2019
1 parent 1907ecc commit b081785
Show file tree
Hide file tree
Showing 17 changed files with 815 additions and 332 deletions.
6 changes: 4 additions & 2 deletions packages/abi-gen-templates/partials/callAsync.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ async callAsync(
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('{{this.functionSignature}}');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray{{#singleReturnValue}}[0]{{/singleReturnValue}};
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<{{> return_type outputs=outputs}}>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
189 changes: 135 additions & 54 deletions packages/abi-gen-wrappers/src/generated-wrappers/asset_proxy_owner.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('name()');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray[0];
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<string
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public approve = {
Expand Down Expand Up @@ -137,8 +140,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('approve(address,uint256)');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray[0];
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<boolean
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public totalSupply = {
Expand All @@ -160,8 +166,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('totalSupply()');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray[0];
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<BigNumber
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public transferFrom = {
Expand Down Expand Up @@ -251,8 +260,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('transferFrom(address,address,uint256)');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray[0];
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<boolean
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public decimals = {
Expand All @@ -274,8 +286,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('decimals()');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray[0];
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<BigNumber
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public balanceOf = {
Expand All @@ -299,8 +314,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('balanceOf(address)');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray[0];
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<BigNumber
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public owner = {
Expand All @@ -322,8 +340,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('owner()');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray[0];
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<string
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public symbol = {
Expand All @@ -345,8 +366,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('symbol()');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray[0];
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<string
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public mint = {
Expand Down Expand Up @@ -418,8 +442,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('mint(uint256)');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray;
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<void
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public transfer = {
Expand Down Expand Up @@ -500,8 +527,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('transfer(address,uint256)');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray[0];
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<boolean
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public allowance = {
Expand All @@ -527,8 +557,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('allowance(address,address)');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray[0];
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<BigNumber
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public setBalance = {
Expand Down Expand Up @@ -609,8 +642,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('setBalance(address,uint256)');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray;
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<void
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public transferOwnership = {
Expand Down Expand Up @@ -682,8 +718,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('transferOwnership(address)');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray;
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<void
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public MAX_MINT_AMOUNT = {
Expand All @@ -705,8 +744,11 @@ export class DummyERC20TokenContract extends BaseContract {
const rawCallResult = await self._web3Wrapper.callAsync(callDataWithDefaults, defaultBlock);
BaseContract._throwIfRevertWithReasonCallResult(rawCallResult);
const abiEncoder = self._lookupAbiEncoder('MAX_MINT_AMOUNT()');
const resultArray = abiEncoder.decodeReturnValuesAsArrayOrNull(rawCallResult);
return resultArray[0];
// tslint:disable boolean-naming
const result = abiEncoder.strictDecodeReturnValue<BigNumber
>(rawCallResult);
// tslint:enable boolean-naming
return result;
},
};
public static async deployFrom0xArtifactAsync(
Expand Down
Loading

0 comments on commit b081785

Please sign in to comment.