Code Monkey home page Code Monkey logo

fabric-node-chaincode-utils's Introduction

Build Status npm version codecov

fabric-node-chaincode-utils

A Nodejs module that helps you build your Hyperledger Fabric nodejs chaincode. Testing is done using the fabric-mock-stub.

Table of contents

Version matching

Fabric node SDK Chaincode utils
v1.3.X v4.X.X
v1.2.X v3.X.X
V1.1.X v2.1.0

Installation

yarn add @theledger/fabric-chaincode-utils

Changes

v2.0.0 - BREAKING

  • Objects parsed as multiple arguments, should now only be passed as a JSON object in 1 argument.

before

["function","prop1","prop2"]
const verifiedArgs = await Helpers.checkArgs<{ prop1: string, prop2: string }>(args, Yup.object()
            .shape({
                prop1: Yup.string().required(),
                prop2: Yup.string().required(),
            }));

after

["function","{\"prop1\":\"prop1\",\"prop2\":\"prop2\"}"]
const verifiedArgs = await Helpers.checkArgs<{ prop1: string, prop2: string }>(args[0], Yup.object()
            .shape({
                prop1: Yup.string().required(),
                prop2: Yup.string().required(),
            }));

Contributing

  1. Fork it! ๐Ÿด
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request ๐Ÿ˜ ๐ŸŽ‰

Credits

License

The MIT License (MIT)

Copyright (c) 2018 TheLedger

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

fabric-node-chaincode-utils's People

Contributors

diestrin avatar greenkeeper[bot] avatar jestersimpps avatar kevinnio1 avatar sneljo1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fabric-node-chaincode-utils's Issues

Correct HTTP Status Code from Errors

Hi all, thanks for sharing this library. It is very useful.

I was trying to send appropriate HTTP status codes for some errors in my smart contract chaincode.

Whenever I do throw new NotFoundError('data.not.found');, I get:

{ "statusCode": 500, "error": "Internal Server Error", "message": "Error: transaction returned with failure: {\"name\":\"Error\",\"status\":500,\"message\":\"data.not.found\"}" }

I get the same HTTP 500 error messages even when I use new ChaincodeError('message', <any HTTP status>);

What am I doing wrong?

Ssend a json with some empty values fail

Hello,

I use @theledger/fabric-chaincode-utils to write my chaincode,
and do stubHelper.putState(verifiedArgs.key, myObject).

I have a json object with a empty value, like:
{
name: 'HOME',
firstname: 'John',
foo: '',
age: 30
}
When I want to do channel.sendTransactionProposal() I got a error "Calling chaincode Invoke() returned error response [undefined]. Sending ERROR message back to peer"

How It is possible to put/send a json with some empty values?

Thanks by advance ๐Ÿ™‚

About Typescript chaincode package getQueryResultAsList

Excuse me, I have some questions.
I am using your typescript package to develop fabric application.
I face some problems about gerQueryResultAsList.

  1. I use limit, but it still output all datas.
  2. I use field and sort but it can't work.

here is part of my code to test limit and skip:
const Data = stubHelper.getQueryResultAsList({
"selector": {"Frequency": "Daily"},"limit":2,"skip":0
});

test sort:
const Data = stubHelper.getQueryResultAsList({
"selector": {"Frequency": "Daily"},"limit":2,"skip":1,"sort": {"Name": "desc"},"fields": ["name"]
})

Different assignment errors when building the library with @theledger/fabric-shim-types removed

node_modules/@theledger/fabric-chaincode-utils/dist/Chaincode.d.ts:28:5 - error TS2416: Property 'Init' in type 'Chaincode' is not assignable to the same property in base type 'ChaincodeInterface'.
Type '(stub: Stub) => Promise' is not assignable to type '{ (stub: Stub): Promise; (stub: ChaincodeStub): Promise; }'.
Types of parameters 'stub' and 'stub' are incompatible.
Type 'ChaincodeStub' is not assignable to type 'Stub'.
Types of property 'getSignedProposal' are incompatible.
Type '() => import("fabric-shim").ChaincodeProposal.SignedProposal' is not assignable to type '() => import("fabric-shim").SignedProposal'.
Property 'proposal' is missing in type 'import("fabric-shim").ChaincodeProposal.SignedProposal' but required in type 'import("fabric-shim").SignedProposal'.

28 Init(stub: Stub): Promise;
~~~~

node_modules/@theledger/fabric-shim-types/index.d.ts:53:9
53 proposal: Proposal;
~~~~~~~~
'proposal' is declared here.

node_modules/@theledger/fabric-chaincode-utils/dist/Chaincode.d.ts:38:5 - error TS2416: Property 'Invoke' in type 'Chaincode' is not assignable to the same property in base type 'ChaincodeInterface'.
Type '(stub: Stub) => Promise' is not assignable to type '{ (stub: Stub): Promise; (stub: ChaincodeStub): Promise; }'.
Types of parameters 'stub' and 'stub' are incompatible.
Type 'ChaincodeStub' is not assignable to type 'Stub'.

38 Invoke(stub: Stub): Promise;
~~~~~~

node_modules/@theledger/fabric-shim-types/index.d.ts:29:18 - error TS2300: Duplicate identifier 'ClientIdentity'.

29 export class ClientIdentity {
~~~~~~~~~~~~~~

node_modules/fabric-shim/types/index.d.ts:31:18
31 export class ClientIdentity {
~~~~~~~~~~~~~~
'ClientIdentity' was also declared here.

node_modules/@theledger/fabric-shim-types/index.d.ts:95:10 - error TS2300: Duplicate identifier 'ChaincodeResponse'.

95 type ChaincodeResponse = {
~~~~~~~~~~~~~~~~~

node_modules/fabric-shim/types/index.d.ts:13:15
13 interface ChaincodeResponse {
~~~~~~~~~~~~~~~~~
'ChaincodeResponse' was also declared here.

node_modules/@theledger/fabric-shim-types/index.d.ts:207:19 - error TS2320: Interface 'HistoryQueryIterator' cannot simultaneously extend types 'Iterator' and 'CommonIterator'.
Named property 'close' of types 'Iterator' and 'CommonIterator' are not identical.

207 interface HistoryQueryIterator extends Iterator {
~~~~~~~~~~~~~~~~~~~~

node_modules/@theledger/fabric-shim-types/index.d.ts:211:19 - error TS2320: Interface 'StateQueryIterator' cannot simultaneously extend types 'Iterator' and 'CommonIterator'.
Named property 'close' of types 'Iterator' and 'CommonIterator' are not identical.

211 interface StateQueryIterator extends Iterator {
~~~~~~~~~~~~~~~~~~

node_modules/fabric-shim/types/index.d.ts:13:15 - error TS2300: Duplicate identifier 'ChaincodeResponse'.

13 interface ChaincodeResponse {
~~~~~~~~~~~~~~~~~

node_modules/@theledger/fabric-shim-types/index.d.ts:95:10
95 type ChaincodeResponse = {
~~~~~~~~~~~~~~~~~
'ChaincodeResponse' was also declared here.

node_modules/fabric-shim/types/index.d.ts:31:18 - error TS2300: Duplicate identifier 'ClientIdentity'.

31 export class ClientIdentity {
~~~~~~~~~~~~~~

node_modules/@theledger/fabric-shim-types/index.d.ts:29:18
29 export class ClientIdentity {
~~~~~~~~~~~~~~
'ClientIdentity' was also declared here.

src/index.ts:6:12 - error TS2345: Argument of type 'MyChaincode' is not assignable to parameter of type 'ChaincodeInterface'.
Types of property 'Init' are incompatible.
Type '(stub: Stub) => Promise' is not assignable to type '{ (stub: Stub): Promise; (stub: ChaincodeStub): Promise; }'.

6 shim.start(new MyChaincode());
~~~~~~~~~~~~~~~~~

Found 9 errors.

Different assignment errors when building the library

Hi all,

unfortunately, I can no longer build the project because of different assignment issues.
Same happens if I only checkout the project (v2.x) and run npm run build.

`
node_modules/@theledger/fabric-shim-types/index.d.ts:29:18 - error TS2300: Duplicate identifier 'ClientIdentity'.

29 export class ClientIdentity {
~~~~~~~~~~~~~~

node_modules/fabric-shim/types/index.d.ts:31:18 - error TS2300: Duplicate identifier 'ClientIdentity'.

31 export class ClientIdentity {
~~~~~~~~~~~~~~

node_modules/fabric-shim/types/index.d.ts:128:19 - error TS2320: Interface 'HistoryQueryIterator' cannot simultaneously extend types 'CommonIterator' and 'Iterator'.
Named property 'close' of types 'CommonIterator' and 'Iterator' are not identical.

128 interface HistoryQueryIterator extends CommonIterator {
~~~~~~~~~~~~~~~~~~~~

node_modules/fabric-shim/types/index.d.ts:132:19 - error TS2320: Interface 'StateQueryIterator' cannot simultaneously extend types 'CommonIterator' and 'Iterator'.
Named property 'close' of types 'CommonIterator' and 'Iterator' are not identical.

132 interface StateQueryIterator extends CommonIterator {
~~~~~~~~~~~~~~~~~~

Type '() => 'fabric-shim'.ChaincodeProposal.SignedProposal' is not assignable to type '() => 'fabric-shim'.SignedProposal'.
Type ''fabric-shim'.ChaincodeProposal.SignedProposal' is not assignable to type ''fabric-shim'.SignedProposal'.
Property 'proposal' is missing in type 'SignedProposal'.

44 async Init(stub: Stub): Promise {
~~~~

src/Chaincode.ts:65:11 - error TS2416: Property 'Invoke' in type 'Chaincode' is not assignable to the same property in base type 'ChaincodeInterface'.
Type '(stub: Stub) => Promise' is not assignable to type '{ (stub: ChaincodeStub): Promise; (stub: Stub): Promise; }'.
Types of parameters 'stub' and 'stub' are incompatible.
Type 'ChaincodeStub' is not assignable to type 'Stub'.

65 async Invoke(stub: Stub): Promise {
~~~~~~

src/StubHelper.ts:49:35 - error TS2345: Argument of type 'Stub' is not assignable to a parameter of type 'ChaincodeStub'.
Property 'getStateByRangeWithPagination' is missing in type 'Stub'.

49 return new ClientIdentity(this.stub);
~~~~~~~~~

`

I already have tried to figure out the issue by checking and dependency version but without success :-(.
Any idea what is going on?

Issue running on HLF 1.3

I have tried to test the library on a modified version of fabcar example and deployed on HLF 1.3.
When calling a chaincode function using the StubHelper.generateUUID method, I got the following issue:

message: 'this.stub.getTxTimestamp(...).toDate is not a function'

Any idea ??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.