Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async _evaluateGatewayTransaction(context, querySettings) {
// Retrieve the existing contract and a client
const contract = await this._getUserContract(querySettings.invokerIdentity, querySettings.chaincodeId);
const client = this.clientProfiles.get(querySettings.invokerIdentity);
// Build the Caliper TxStatus, this is a reduced item when compared to the low level API capabilities
const txIdObject = client.newTransactionID();
const txId = txIdObject.getTransactionID();
let invokeStatus = new TxStatus(txId);
invokeStatus.Set('request_type', 'query');
if(context.engine) {
context.engine.submitCallback(1);
}
try {
const result = await contract.evaluateTransaction(querySettings.chaincodeFunction, ...querySettings.chaincodeArguments);
invokeStatus.result = result;
invokeStatus.verified = true;
invokeStatus.SetStatusSuccess();
return invokeStatus;
} catch (err) {
logger.error(`Failed to evaluate transaction [${querySettings.chaincodeFunction}] using arguments [${querySettings.chaincodeArguments}], with error: ${err.stack ? err.stack : err}`);
invokeStatus.SetStatusFail();
invokeStatus.result = [];
async function submitBatches(block_num, batchBytes, timeout) {
let txStatus = new TxStatus(0);
let restApiUrl = getRESTUrl();
const request = require('request-promise');
let options = {
method: 'POST',
url: restApiUrl + '/batches',
body: batchBytes,
headers: {'Content-Type': 'application/octet-stream'}
};
return request(options)
.then(function (body) {
let batchId = (JSON.parse(body).link.split('id='))[1];
if(batchCommitStatus.get(batchId) !== 'success') {
batchCommitStatus.set(batchId,'pending');
}
let txnStatus = getBatchEventResponse(batchId, txStatus, timeout);
return Promise.resolve(txnStatus);
module.exports.run = async function (context, fiscoBcosSettings, contractID, fcn, args, workspaceRoot, readOnly = false) {
let smartContracts = fiscoBcosSettings.smartContracts;
let address = findContractAddress(workspaceRoot, smartContracts, contractID);
if (address === null) {
throw new Error(`Can't invoke smart contract ${contractID}`);
}
const networkConfig = fiscoBcosSettings.network;
const account = fiscoBcosSettings.config.account;
let invokeStatus = new TxStatus(account);
invokeStatus.SetFlag(TxErrorEnum.NoError);
let receipt = null;
try {
if (context && context.engine) {
context.engine.submitCallback(1);
}
if (readOnly) {
receipt = await fiscoBcosApi.call(networkConfig, account, address, fcn, args);
} else {
const privateKey = fiscoBcosSettings.config.privateKey;
receipt = await fiscoBcosApi.sendTransaction(networkConfig, account, privateKey, address, fcn, args);
}
invokeStatus.SetID(receipt.result);
function getState(address) {
let txStatus = new TxStatus(0);
let restApiUrl = getRESTUrl();
const stateLink = restApiUrl + '/state?address=' + address;
let options = {
uri: stateLink
};
return request(options)
.then(function(body) {
let data = (JSON.parse(body)).data;
if (data.length > 0) {
let stateDataBase64 = data[0].data;
let stateDataBuffer = new Buffer(stateDataBase64, 'base64');
let stateData = stateDataBuffer.toString('hex');
txStatus.SetStatusSuccess();
txStatus.SetResult(stateData);
module.exports.run = async function (fiscoBcosSettings, workspaceRoot, context, contractID, arg, file) {
if (context && context.engine) {
context.engine.submitCallback(1);
}
let smartContracts = fiscoBcosSettings.smartContracts;
let address = findContractAddress(workspaceRoot, smartContracts, contractID);
let account = fiscoBcosSettings.config.account;
let privateKey = fiscoBcosSettings.config.privateKey;
let network = fiscoBcosSettings.network;
let invokeStatus = new TxStatus(uuid());
try {
let fcn = null;
let fcArgs = [];
for (let key in arg) {
if (key === 'transaction_type') {
fcn = arg[key].toString();
} else {
fcArgs.push(arg[key].toString());
}
}
let tx = await fiscoBcosApi.generateRawTransaction(network,
account,
privateKey,
async sendTransaction(context, contractID, contractVer, methodCall, timeout) {
let status = new TxStatus();
let params = {from: context.fromAddress};
let contractInfo = context.contracts[contractID];
try {
context.engine.submitCallback(1);
let receipt = null;
let methodType = 'send';
if (methodCall.isView) {
methodType = 'call';
} else if (context.nonces && context.nonces[context.fromAddress]) {
let nonce = context.nonces[context.fromAddress];
context.nonces[context.fromAddress] = nonce + 1;
params.nonce = nonce;
}
if (methodCall.args) {
if (contractInfo.gas && contractInfo.gas[methodCall.verb]) {
params.gas = contractInfo.gas[methodCall.verb];
module.exports.run = async function (fiscoBcosSettings, context, transactions) {
let promises = [];
let hasEngine = context && context.engine;
let network = fiscoBcosSettings.network;
for (let transaction of transactions) {
let invokeStatus = new TxStatus(uuid());
if(hasEngine) {
context.engine.submitCallback(1);
}
promises.push(fiscoBcosApi.sendRawTransaction(network, transaction).then(receipt => {
invokeStatus.SetFlag(TxErrorEnum.NoError);
invokeStatus.SetResult(receipt.result);
invokeStatus.SetVerification(true);
if (receipt.error === undefined && (receipt.status === '0x0' || (receipt.result && receipt.result.status === '0x0'))) {
invokeStatus.SetStatusSuccess();
} else {
commLogger.error('Failed to invoke smart contract: ' + JSON.stringify(receipt));
invokeStatus.SetStatusFail();
}
async queryState(context, contractID, contractVer, account, fcn = 'query') {
if(!context.contract.hasOwnProperty(contractID)) {
throw new Error('Could not find contract named ' + contractID);
}
let accountId = account + '@' + context.domain;
let argsIroha = {accountId: accountId, verb: fcn};
let commands = context.contract[contractID](context, argsIroha);
if(commands.length === 0) {
throw new Error('Empty output of contract ' + contractID);
}
let status = new TxStatus(null);
if(context.engine) {
context.engine.submitCallback(1);
}
try {
let queryOptions = {
privateKey: context.privKey,
creatorAccountId: context.id,
queryService: this.grpcQueryClient,
timeoutLimit: 5000
};
await irohaQuery(queryOptions,commands);
status.SetStatusSuccess();
return Promise.resolve(status);
}
catch(err) {