Skip to content

Commit

Permalink
Uniform with Ethereum doc and update copyright notes
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Russo <[email protected]>
  • Loading branch information
russanto committed Jun 8, 2019
1 parent 2bfea26 commit c50289f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 32 deletions.
5 changes: 5 additions & 0 deletions packages/caliper-application/benchmark/simple/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ function generateWorkload() {
chaincodeFunction: 'open',
chaincodeArguments: [acc_id, initMoney.toString()],
});
} else if (bc.bcType === 'ethereum') {
workload.push({
verb: 'open',
args: [acc_id, initMoney]
});
} else {
workload.push({
'verb': 'open',
Expand Down
59 changes: 29 additions & 30 deletions packages/caliper-ethereum/lib/ethereum.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/**
* Copyright 2017 HUAWEI. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* SPDX-License-Identifier: Apache-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* @file, definition of the Burrow class, which implements the Caliper's NBI for Hyperledger Burrow.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @file, definition of the Ethereum class, which implements the Caliper's NBI for Ethereum Web3 interface.
*/

'use strict';
Expand All @@ -14,13 +22,13 @@ const {BlockchainInterface, CaliperUtils, TxStatus} = require('caliper-core');
const logger = CaliperUtils.getLogger('ethereum.js');

/**
* Implements {BlockchainInterface} for a Geth backend.
* Implements {BlockchainInterface} for a web3 Ethereum backend.
*/
class Ethereum extends BlockchainInterface {

/**
* Create a new instance of the {Burrow} class.
* @param {string} config_path The path of the Burrow network configuration file.
* Create a new instance of the {Ethereum} class.
* @param {string} config_path The path of the network configuration file.
* @param {string} workspace_root The absolute path to the root location for the application configuration files.
*/
constructor(config_path, workspace_root) {
Expand All @@ -43,17 +51,20 @@ class Ethereum extends BlockchainInterface {
}

/**
* Deploy the smart contracts specified in the network configuration file.
* Deploy smart contracts specified in the network configuration file.
* @return {object} Promise execution for all the contract creations.
*/
async installSmartContract() {
let promises = [];
let self = this;
logger.info("Creating contracts...")
for (const key of Object.keys(this.ethereumConfig.contracts)) {
let contractData = require(CaliperUtils.resolvePath(this.ethereumConfig.contracts[key].path, this.workspaceRoot)); // TODO remove path property
promises.push(new Promise(function(resolve, reject) {
self.deployContract(contractData).then((contractInstance) => {
logger.info("Deployed contract " + contractData.name + " at " + contractInstance.options.address);
self.bindContract(key, contractInstance.address).then((receipt) => {
logger.info("Registered contract " + contractData.name);
resolve()
})
})
Expand Down Expand Up @@ -84,8 +95,8 @@ class Ethereum extends BlockchainInterface {
}

/**
* Release the given Burrow context.
* @param {object} context The Burrow context to release.
* Release the given Ethereum context.
* @param {object} context The Ethereum context to release.
* @async
*/
async releaseContext(context) {
Expand All @@ -97,14 +108,14 @@ class Ethereum extends BlockchainInterface {
* @param {Object} context Context object.
* @param {String} contractID Identity of the contract.
* @param {String} contractVer Version of the contract.
* @param {Array} args Array of JSON formatted arguments for multiple transactions.
* @param {Array} invokeData Array of methods calls.
* @param {Number} timeout Request timeout, in seconds.
* @return {Promise<object>} The promise for the result of the execution.
*/
async invokeSmartContract(context, contractID, contractVer, args, timeout) {
async invokeSmartContract(context, contractID, contractVer, invokeData, timeout) {
let promises = [];
args.forEach((item, index) => {
promises.push(this.sendTransaction(context, contractID, contractVer, item, 100));
invokeData.forEach((item, index) => {
promises.push(this.sendTransaction(context, contractID, contractVer, item, timeout));
});
return Promise.all(promises);
}
Expand All @@ -114,17 +125,15 @@ class Ethereum extends BlockchainInterface {
* @param {Object} context Context object.
* @param {String} contractID Identity of the contract.
* @param {String} contractVer Version of the contract.
* @param {Array} args Array of JSON formatted arguments for multiple transactions.
* @param {Object} methodCall Array of JSON containing methods data.
* @param {Number} timeout Request timeout, in seconds.
* @return {Promise<TxStatus>} Result and stats of the transaction invocation.
*/
async sendTransaction(context, contractID, contractVer, args, timeout) {
let verb = args.verb;
delete args.verb
async sendTransaction(context, contractID, contractVer, methodCall, timeout) {
let status = new TxStatus();
try {
context.engine.submitCallback(1);
let receipt = await context.contracts[contractID].methods[verb](...Object.values(args)).send({from: context.fromAddress});
let receipt = await context.contracts[contractID].methods[methodCall.verb](...methodCall.args).send({from: context.fromAddress});
status.SetID(receipt.transactionHash);
status.SetResult(receipt);
status.SetVerification(true);
Expand Down Expand Up @@ -155,7 +164,7 @@ class Ethereum extends BlockchainInterface {

try {
let receipt = await context.contracts[contractID].methods[fcn](key).call();
status.SetID(receipt.transactionHash);
status.SetID(null);
status.SetResult(receipt);
status.SetVerification(true);
status.SetStatusSuccess();
Expand All @@ -166,15 +175,6 @@ class Ethereum extends BlockchainInterface {
return Promise.resolve(status);
}

/**
* Get adapter specific transaction statistics.
* @param {JSON} stats txStatistics object
* @param {Array} results array of txStatus objects.
*/
getDefaultTxStats(stats, results) {
// empty
}

/**
* Fetch the address for the contract with the given label from the registry
* @param {string} contract_id
Expand All @@ -195,7 +195,7 @@ class Ethereum extends BlockchainInterface {

/**
* Deploys a new contract using the given web3 instance
* @param {JSON} contractData Contract data with abi and bytecode properties
* @param {JSON} contractData Contract data with abi, bytecode and gas properties
* @returns {Promise<web3.eth.Contract>} The deployed contract instance
*/
deployContract(contractData) {
Expand All @@ -212,7 +212,6 @@ class Ethereum extends BlockchainInterface {
}).on('error', (error) => {
reject(error)
}).then((newContractInstance) => {
logger.info("Deployed contract " + contractData.name + " at " + newContractInstance.options.address);
resolve(newContractInstance)
});
});
Expand Down
11 changes: 10 additions & 1 deletion packages/caliper-ethereum/lib/ethereumClientFactory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* SPDX-License-Identifier: Apache-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @file, definition of the Ethereum client factory
*/
Expand Down
11 changes: 10 additions & 1 deletion packages/caliper-ethereum/lib/ethereumClientWorker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* SPDX-License-Identifier: Apache-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @file, definition of the Ethereum client worker
*/
Expand Down

0 comments on commit c50289f

Please sign in to comment.