How to use the fabric-shim.success function in fabric-shim

To help you get started, we’ve selected a few fabric-shim examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / fabric-sdk-node / test / fixtures / chaincode / node_cc / example_cc / chaincode.js View on Github external
Aval = parseInt(args[1]);
			if (isNaN(Aval)) {
				return shim.error('Expecting integer value for asset holding');
			}
			Bval = parseInt(args[3]);
			if (isNaN(Bval)) {
				return shim.error('Expecting integer value for asset holding');
			}

			logger.info(`Aval = ${Aval}, Bval = ${Bval}`);

			try {
				// Write the state to the ledger
				await stub.putState(A, Buffer.from(Aval.toString()));
				await stub.putState(B, Buffer.from(Bval.toString()));
				return shim.success();
			} catch (e) {
				return shim.error(e);
			}
		} else {
			return shim.error('init expects 4 args');
		}
	}
github hyperledger / fabric-sdk-node / test / fixtures / chaincode / node_cc / example_cc / chaincode.js View on Github external
}
		// Perform the execution
		const X = parseInt(args[2]);
		if (isNaN(X)) {
			return shim.error('Invalid transaction amount, expecting a integer value');
		}

		Aval = Aval - X;
		Bval = Bval + X;
		logger.info(`Aval = ${Aval}, Bval = ${Bval}`);
		// Write the state back to the ledger
		try {
			await stub.putState(A, Buffer.from(Aval.toString()));
			await stub.putState(B, Buffer.from(Bval.toString()));
			logger.info(' example_cc0 - move succeed');
			return shim.success(Buffer.from('move succeed'));
		} catch (e) {
			return shim.error(e);
		}

	}
github hyperledger / fabric-chaincode-node / test / typescript / chaincode.ts View on Github external
async Init(stub: ChaincodeStub): Promise {
        const logger: LoggerInstance = shim.newLogger('init');
        return shim.success();
    }
github hyperledger / fabric-test / chaincodes / example02 / node / chaincode_example02.js View on Github external
async Invoke(stub) {
    console.info('Transaction ID: ' + stub.getTxID());
    console.info(util.format('Args: %j', stub.getArgs()));

    let ret = stub.getFunctionAndParameters();
    console.info(ret);
    let method = this[ret.fcn];
    if (!method) {
      console.log('no method of name:' + ret.fcn + ' found');
      return shim.success();
    }
    try {
      let payload = await method(stub, ret.params);
      return shim.success(payload);
    } catch (err) {
      console.log(err);
      return shim.error(err);
    }
  }
github hyperledger / fabric-sdk-node / test / scenario / chaincode / marbles0 / node / marbles.js View on Github external
async queryMarbles(stub, args, thisObject) {
		if (args.length !== 1) {
			return shim.error('Incorrect number of arguments. Expecting queryString');
		}
		const queryString = args[0];
		if (!queryString) {
			return shim.error('queryString must not be empty');
		}

		const queryResults = await thisObject.getQueryResultForQueryString(stub, queryString, thisObject);
		return shim.success(queryResults);
	}
github hyperledger / fabric-sdk-node / test / fixtures / chaincode / node_cc / example_cc / chaincode.js View on Github external
async echo(stub, args) {
		stub.setEvent('echo', Buffer.from('content'));
		if (args.length > 0) {
			return shim.success(Buffer.from(args[0]));
		} else {
			return shim.success();
		}
	}
};
github hyperledger / fabric-chaincode-node / test / typescript / chaincode.ts View on Github external
return shim.error(Buffer.from(err.message));
        }

        if (fcn === 'ThrowErrorShim') {
            const err: Error = new Error('Had a problem');
            return Shim.error(Buffer.from(err.message));
        }

        if (fcn === 'SuccessShim') {
            return Shim.success();
        }

        await this.testAll(stub);

        if (fcn === 'nopayload') {
            return shim.success();
        }

        if (fcn === 'myReturnCode') {
            let rc: number;
            rc = ChaincodeStub.RESPONSE_CODE.OK;
            rc = shim.RESPONSE_CODE.OK;
            rc = ChaincodeStub.RESPONSE_CODE.ERRORTHRESHOLD;
            rc = shim.RESPONSE_CODE.ERRORTHRESHOLD;
            rc = ChaincodeStub.RESPONSE_CODE.ERROR;
            rc = shim.RESPONSE_CODE.ERROR;
            rc++;
        }

        return shim.success(Buffer.from('all good'));
    }
github accordproject / concerto / packages / composer-runtime-hlfv1 / lib / composer.js View on Github external
try {
            await this.container.initLogging(stub);
            LOG.entry(method, stub);
            let {fcn: fcn, params: params} = stub.getFunctionAndParameters();

            let engine = this._createEngine();
            let nodeContext = this._createContext(engine, stub);
            let payload = await engine.invoke(nodeContext, fcn, params);
            if (payload !== null && payload !== undefined) {
                LOG.exit(method, payload);
                LOG.debug('@PERF ' + method, 'Total (ms) duration for txnID [' + stub.getTxID() + ']: ' + (Date.now() - t0).toFixed(2));
                return shim.success(Buffer.from(JSON.stringify(payload)));
            }
            LOG.exit(method);
            LOG.debug('@PERF ' + method, 'Total (ms) duration for txnID [' + stub.getTxID() + ']: ' + (Date.now() - t0).toFixed(2));
            return shim.success();
        }
        catch(err) {
            LOG.error(method, err);
            LOG.debug('@PERF ' + method, 'Total (ms) duration for txnID [' + stub.getTxID() + ']: ' + (Date.now() - t0).toFixed(2));
            return shim.error(err);
        }
    }
}
github Kunstmaan / hyperledger-fabric-chaincode-dev-setup / example-chaincode / fabcar2 / chaincode.js View on Github external
async Invoke(stub) {
    console.info('Transaction ID: ' + stub.getTxID());
    console.info(util.format('Args: %j', stub.getArgs()));

    let ret = stub.getFunctionAndParameters();
    console.info(ret);

    let method = this[ret.fcn];
    if (!method) {
      console.log('no function of name:' + ret.fcn + ' found');
      throw new Error('Received unknown function ' + ret.fcn + ' invocation');
    }
    try {
      let payload = await method(stub, ret.params);
      return shim.success(payload);
    } catch (err) {
      console.log(err);
      return shim.error(err);
    }
  }
github accordproject / concerto / packages / composer-runtime-hlfv1 / lib / composer.js View on Github external
async Invoke(stub) {
        const method = 'Invoke';
        const t0 = Date.now();
        try {
            await this.container.initLogging(stub);
            LOG.entry(method, stub);
            let {fcn: fcn, params: params} = stub.getFunctionAndParameters();

            let engine = this._createEngine();
            let nodeContext = this._createContext(engine, stub);
            let payload = await engine.invoke(nodeContext, fcn, params);
            if (payload !== null && payload !== undefined) {
                LOG.exit(method, payload);
                LOG.debug('@PERF ' + method, 'Total (ms) duration for txnID [' + stub.getTxID() + ']: ' + (Date.now() - t0).toFixed(2));
                return shim.success(Buffer.from(JSON.stringify(payload)));
            }
            LOG.exit(method);
            LOG.debug('@PERF ' + method, 'Total (ms) duration for txnID [' + stub.getTxID() + ']: ' + (Date.now() - t0).toFixed(2));
            return shim.success();
        }
        catch(err) {
            LOG.error(method, err);
            LOG.debug('@PERF ' + method, 'Total (ms) duration for txnID [' + stub.getTxID() + ']: ' + (Date.now() - t0).toFixed(2));
            return shim.error(err);
        }
    }
}