Skip to content

Commit

Permalink
Merge branch 'release/v2.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wulfraem committed Jul 25, 2019
2 parents 106a369 + 57795d0 commit e07b986
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ language: node_js

sudo: required

cache:
npm: false

matrix:
include:
- name: "services contracts & digital-twin tests"
Expand Down Expand Up @@ -60,3 +63,4 @@ install:
- NODE_ENV='local' CHAIN_ENDPOINT='ws://localhost:8546' ACCOUNT_ID='0x001De828935e8c7e4cb56Fe610495cAe63fb2612' PRIVATE_KEY='01734663843202e2245e5796cb120510506343c67915eb4f9348ac0d8c2cf22a' node scripts/build-contracts.js && cd ../../../
- rm -f node_modules/web3/*.d.ts
- rm -f node_modules/web3/node_modules/web3-eth/types/*.d.ts
- rm -f node_modules/web3-eth/types/*.d.ts
14 changes: 13 additions & 1 deletion VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# api-blockchain-core


## Next Version
### Features

Expand All @@ -9,6 +8,19 @@
### Deprecations


## Version 2.9.0
### Features
- add support for `timeout` (adjusts transaction timeout) option to `Wallet` and `ExecutorWallet`

### Fixes
- fix executor agent to be compatible with web3 1.2 and 2.0


## Version 2.8.4
### Fixes
- add `toString` to return correct value for `verification.raw.topic` BigNumber result returned by `web3` `1.0.0-beta.55`


## Version 2.8.3
### Fixes
- fix verification v2 status compute and statusComputer
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"author": "evan GmbH",
"dependencies": {
"@evan.network/dbcp": "^1.6.4",
"@evan.network/smart-contracts-core": "^2.4.2",
"@evan.network/dbcp": "^1.7.0",
"@evan.network/smart-contracts-core": "^2.4.3",
"@types/node": "11.11.4",
"ajv": "^5.5.1",
"async-mutex": "^0.1.3",
Expand Down Expand Up @@ -85,5 +85,5 @@
"testunitcoverage": "env-cmd ./.env.local npm run build && nyc -r lcov -e .ts -x \"$TESTSPECS\" mocha --exit -r ts-node/register $TESTSPECS && nyc report --reporter=text-lcov | coveralls"
},
"types": "./dist/index.d.ts",
"version": "2.8.3"
"version": "2.9.0"
}
33 changes: 30 additions & 3 deletions src/contracts/executor-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,23 @@ export class ExecutorAgent extends Executor {
public async executeContractCall(contract: any, functionName: string, ...args): Promise<any> {
this.log(`starting contract call "${functionName}" via agent`, 'debug');

// web3 compatibility for 1.2 and 2.0
let functionSignature;
if (contract.options.jsonInterface) {
// web3 1.2
functionSignature = contract.options.jsonInterface.filter(fun => fun.name === functionName)[0];
} else {
// web3 2.0
functionSignature = contract.abiModel.abi.methods[functionName].abiItem;
}

// submit to action
return request({
url: `${this.agentUrl}/api/smart-agents/executor/executeContractCall`,
method: 'POST',
body: {
contractId: contract.options.address,
functionSignature: contract.options.jsonInterface.filter(fun => fun.name === functionName)[0],
functionSignature,
functionName,
functionArguments: args,
},
Expand Down Expand Up @@ -204,13 +214,23 @@ export class ExecutorAgent extends Executor {
`value has been set to ${inputOptions.value} for tx "${functionName}"`);
}

// web3 compatibility for 1.2 and 2.0
let functionSignature;
if (contract.options.jsonInterface) {
// web3 1.2
functionSignature = contract.options.jsonInterface.filter(fun => fun.name === functionName)[0];
} else {
// web3 2.0
functionSignature = contract.abiModel.abi.methods[functionName].abiItem;
}

// submit to action
return request({
url: `${this.agentUrl}/api/smart-agents/executor/executeContractTransaction`,
method: 'POST',
body: {
contractId: contract.options.address,
functionSignature: contract.options.jsonInterface.filter(fun => fun.name === functionName)[0],
functionSignature,
functionName,
options: inputOptions,
functionArguments,
Expand Down Expand Up @@ -254,10 +274,17 @@ export class ExecutorAgent extends Executor {
signature: fun.signature || null,
count: fun.count || 1,
};

if (fun.contract) {
newFun.contractId = fun.contract.options.address;
if (fun.functionName) {
newFun.signature = fun.contract.options.jsonInterface.filter(ff => ff.name === fun.functionName)[0];
if (fun.contract.options.jsonInterface) {
// web3 1.2
newFun.signature = fun.contract.options.jsonInterface.filter(ff => ff.name === fun.functionName)[0];
} else {
// web3 2.0
newFun.signature = fun.contract.abiModel.abi.methods[fun.functionName].abiItem;
}
}
}
return newFun;
Expand Down
22 changes: 13 additions & 9 deletions src/contracts/executor-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface ExecutorWalletOptions extends ExecutorOptions {
contractLoader: ContractLoader;
accountId: string;
wallet: Wallet;
defaultOptions?: any;
}


Expand All @@ -65,6 +66,7 @@ export class ExecutorWallet extends Executor {
constructor(options: ExecutorWalletOptions) {
super(options);
this.options = options;
this.defaultOptions = options.defaultOptions || {};
}

/**
Expand Down Expand Up @@ -177,15 +179,17 @@ export class ExecutorWallet extends Executor {
}

// every argument beyond the third is an argument for the contract function
let options = Object.assign({}, this.defaultOptions || {}, inputOptions);
let options = Object.assign(
{ timeout: 300000 },
this.defaultOptions || {},
inputOptions,
);

// keep timeout before deletion
const transactionTimeout = options.eventTimeout || options.timeout;

// strip unrelated option
const validProperties = ['from', 'to', 'gasPrice', 'gas', 'value', 'data', 'nonce'];
Object.keys(options).forEach((option) => {
if (!validProperties.includes(option)) {
delete options[option];
}
});
this.scrubOptions(options);

let autoGas;
if (inputOptions.autoGas) {
Expand Down Expand Up @@ -248,9 +252,9 @@ export class ExecutorWallet extends Executor {
if (isPending) {
await stopWatching(true);
logGas({ status: 'error', message: 'timeout' });
reject(new Error(`timeout during ${functionName}`));
reject(new Error(`timeout after ${transactionTimeout}ms during ${functionName}`));
}
}, inputOptions.eventTimeout || 300000);
}, transactionTimeout);

// if we wait for a 'result', pick this result from event watch and resolve the promise
if (inputOptions.event) {
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('Wallet handler', function() {
expect(await web3.eth.getBalance(walletAddress)).to.eq(valueToSend.toString());
});

it('intantly submits funds to target if instantly submitting transaction', async () => {
it('instantly submits funds to target if instantly submitting transaction', async () => {
await createWallet(accounts[0], accounts[0], [accounts[0]]);
const walletAddress = wallet.walletAddress;

Expand Down
16 changes: 12 additions & 4 deletions src/contracts/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface WalletOptions extends LoggerOptions {
eventHub: EventHub;
executor: Executor;
nameResolver: NameResolver;
defaultOptions?: any;
}

/**
Expand All @@ -55,6 +56,7 @@ export interface WalletOptions extends LoggerOptions {
*/
export class Wallet extends Logger {
options: WalletOptions;
defaultOptions: any;
defaultDescription: any = {
'public': {
'name': 'MultiSigWallet contract',
Expand All @@ -75,6 +77,7 @@ export class Wallet extends Logger {
constructor(options: WalletOptions) {
super(options);
this.options = options;
this.defaultOptions = options.defaultOptions || {};
this.defaultDescription.public.abis = {
own: JSON.parse(this.options.contractLoader.contracts.MultiSigWallet.interface),
};
Expand Down Expand Up @@ -283,16 +286,22 @@ export class Wallet extends Logger {
target: any, functionName: string, inputOptions: any, ...functionArguments): Promise<any> {
const subscriptions = [];
let receipt;
let walletOptions = Object.assign(
{ timeout: 300000 },
this.defaultOptions || {},
inputOptions,
);
try {
receipt = await new Promise(async (resolve, reject) => {
try {
let txResolved;
const transactionTimeout = walletOptions.eventTimeout || walletOptions.timeout;
setTimeout(() => {
if (!txResolved) {
txResolved = true;
reject('wallet timeout');
reject(`wallet timeout after ${transactionTimeout}ms`);
}
}, 600000);
}, transactionTimeout);

// tx status variables
let transactionHash;
Expand Down Expand Up @@ -358,7 +367,7 @@ export class Wallet extends Logger {
};

// execute to contract
const options = Object.assign(JSON.parse(JSON.stringify(inputOptions)), {
const options = Object.assign(JSON.parse(JSON.stringify(walletOptions)), {
event: { target: 'MultiSigWallet', eventName: 'Confirmation', },
getEventResult: async (event, args) => {
this.log('received MultiSigWallet Confirmation event with hash: ' +
Expand Down Expand Up @@ -399,7 +408,6 @@ export class Wallet extends Logger {
}
});
} catch (ex) {
console.error(ex.stack)
throw new Error(ex.message || ex);
} finally {
// cleanup subscriptions
Expand Down
4 changes: 2 additions & 2 deletions src/verifications/verifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ export class Verifications extends Logger {
signature: (<any>verification).signature,
status: verificationFlag,
subject,
topic: verification.topic,
topic: verification.topic.toString(),
uri: (<any>verification).uri,
valid: await this.validateVerification(subject, verificationId, isIdentity),
};
Expand Down Expand Up @@ -1556,7 +1556,7 @@ export class Verifications extends Logger {
);

const dataHash = this.options.nameResolver.soliditySha3(
subjectIdentity, verification.topic, verification.data).replace('0x', '');
subjectIdentity, verification.topic.toString(), verification.data).replace('0x', '');
const recoveredAddress = this.options.executor.web3.eth.accounts.recover(
dataHash, verification.signature);
const issuerContract = this.options.contractLoader.loadContract(
Expand Down

0 comments on commit e07b986

Please sign in to comment.