Skip to content

Commit

Permalink
on dev
Browse files Browse the repository at this point in the history
  • Loading branch information
a committed Apr 13, 2023
1 parent e36666a commit b89302f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 112 deletions.
1 change: 1 addition & 0 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"packages/caliper-ethereum",
"packages/caliper-fabric",
"packages/caliper-fisco-bcos",
"packages/caliper-dp-chain",
"packages/caliper-cli",
"packages/caliper-publish",
"packages/caliper-tests-integration",
Expand Down
24 changes: 3 additions & 21 deletions packages/caliper-dp-chain/lib/dp-chain-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const {
CaliperUtils,
ConfigUtil
} = require('@hyperledger/caliper-core');
const installSmartContractImpl = require('./installSmartContract');
const invokeSmartContractImpl = require('./invokeSmartContract');
const generateRawTransactionImpl = require('./generateRawTransactions');
const sendRawTransactionImpl = require('./sendRawTransactions');
Expand All @@ -32,7 +31,7 @@ const commLogger = CaliperUtils.getLogger('fiscoBcos-connector');
*/
class DpChainConnector extends ConnectorBase {
/**
* Create a new instance of the {FISCO BCOS} connector class.
* Create a new instance of the {dp-chain} connector class.
* @param {number} workerIndex The zero-based index of the worker who wants to create an adapter instance. -1 for the manager process.
* @param {string} bcType The target SUT type
*/
Expand All @@ -42,37 +41,20 @@ class DpChainConnector extends ConnectorBase {
let networkConfig = CaliperUtils.resolvePath(ConfigUtil.get(ConfigUtil.keys.NetworkConfig));
this.dpChainSettings = CaliperUtils.parseYaml(networkConfig)['dp-chain'];

if (this.fiscoBcosSettings.network && this.fiscoBcosSettings.network.authentication) {
for (let k in this.fiscoBcosSettings.network.authentication) {
this.fiscoBcosSettings.network.authentication[k] = CaliperUtils.resolvePath(this.fiscoBcosSettings.network.authentication[k]);
}
}
this.clientIdx = workerIndex;
this.context = undefined;
}

/**
* Initialize the {FISCO BCOS} object.
* Initialize the {dp-chain} object.
* @async
* @return {Promise<object>} The promise for the result of the execution.
*/
async init() {
return Promise.resolve();
}

/**
* Deploy the smart contract specified in the network configuration file to all nodes.
* @async
*/
async installSmartContract() {
const fiscoBcosSettings = this.fiscoBcosSettings;
try {
await installSmartContractImpl.run(fiscoBcosSettings, this.workspaceRoot);
} catch (error) {
commLogger.error(`FISCO BCOS smart contract install failed: ${(error.stack ? error.stack : error)}`);
throw error;
}
}


/**
* Get a context for subsequent operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,11 @@ module.exports.getBlockNumber = async function (networkConfig) {
let node = selectNode(networkConfig.nodes);
// Use RPC
let requestData = {
method: 'POST',
uri: `http://${node.ip}:${node.rpcPort}`,
method: 'GET',
uri: `http://${node.ip}:${node.rpcPort}/block/blockNumber`,
json: true,
body: {
'jsonrpc': '2.0',
'method': 'getBlockNumber',
'params': [networkConfig.groupID],
'id': 1
}
body: {}
};

return requestPromise(requestData);
};

Expand All @@ -65,7 +59,7 @@ let initializationPromise = null;
async function updateCurrentBlockNumber(networkConfig) {
module.exports.getBlockNumber(networkConfig).then((result) => {
if (!result.error && result.result) {
let blockNumber = parseInt(result.result);
let blockNumber = parseInt(result.data);
if (blockNumber > currentBlockNumber) {
if (currentBlockNumber === -1) {
initializeBlockNumberEventEmitter.emit('initialized');
Expand Down Expand Up @@ -106,85 +100,6 @@ async function getCurrentBlockNumber(networkConfig) {
return currentBlockNumber;
}

// Deploy solidity smart contract only
module.exports.deploy = async function (networkConfig, account, privateKey, contractPath) {
let contractName = path.basename(contractPath, '.sol');

// assume the imports are located at the same directory
let contractContent = fs.readFileSync(contractPath, 'utf-8');

const input = {
language: 'Solidity',
sources: {
[contractPath]: {
content: contractContent
}
},
settings: {
outputSelection: {
'*': {
'*': ['evm.bytecode']
}
}
}
};

let outputJson = solc.compileStandard(JSON.stringify(input), pathDeclared => {
let importPath = pathDeclared;
try {
let content = fs.readFileSync(importPath, 'utf-8');
return { contents: content };
} catch (err) {
return { error: err.toString() };
}
});
commLogger.debug(`solc output: ${outputJson}`);

let output = JSON.parse(outputJson);

if ('errors' in output) {
let errorStr = '';

for(let error of output.errors) {
errorStr = errorStr + error.formattedMessage;
}
// Signal the error
throw new Error(errorStr);
}

// The concatenation may not be necessary if we are certain there will be only one contract
let contractBin = '';
for (let name in output.contracts[contractPath]) {
contractBin = contractBin + output.contracts[contractPath][name].evm.bytecode.object;
}

commLogger.debug(`contract bin: ${contractBin}`);

let blockNumber = await getCurrentBlockNumber(networkConfig);
let groupID = networkConfig.groupID;
let signTx = web3Sync.getSignDeployTx(groupID, account, privateKey, contractBin, blockNumber + 500);

let requestData = {
'jsonrpc': '2.0',
'method': 'sendRawTransaction',
'params': [networkConfig.groupID, signTx],
'id': 1
};

let node = selectNode(networkConfig.nodes);
let spinner = ora(`Depolying ${contractName}.sol ...`).start();
return channelPromise(node, networkConfig.authentication, requestData, networkConfig.timeout).then((result) => {
if (result.error) {
spinner.fail();
}
else {
spinner.succeed();
}

return result;
});
};

module.exports.call = async function (networkConfig, from, to, func, params) {
if (!isArray(params)) {
params = [params];
Expand Down
2 changes: 1 addition & 1 deletion packages/caliper-dp-chain/lib/installSmartContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const fiscoBcosApi = require('./fiscoBcosApi');
const assert = require('assert');
const commLogger = CaliperUtils.getLogger('installSmartContract.js');

module.exports.run = async function (fiscoBcosSettings, workspaceRoot) {
module.exports.run = async function (fiscoBcosSettings, workspaceRoot) {``
const fiscoBcosConfig = fiscoBcosSettings.config;
const account = fiscoBcosConfig.account;
const privateKey = fiscoBcosConfig.privateKey;
Expand Down
2 changes: 1 addition & 1 deletion packages/caliper-dp-chain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"repository": {
"type": "git",
"url": "https://github.com/zan-san/caliper",
"directory": "packages/caliper-fisco-bcos"
"directory": "packages/caliper-dp-chain"
},
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit b89302f

Please sign in to comment.