Giter Site home page Giter Site logo

Comments (3)

bestbeforetoday avatar bestbeforetoday commented on August 24, 2024 1

Definitely you are correct that the error function should take a string parameter: error(msg: string): ErrorResponse.

The only slight concern is that the ChaincodeResponse returned from the ChaincodeInterface methods really can be anything that fits the shape:

interface ChaincodeResponse {
    status: number;
    message?: string;
    payload? Uint8Array;
}

However, this is really an implementation detail only affecting the low-level shim API for developing chaincode, and the values that actually make sense better fit your type definitions.

Please feel free to open a PR to modify the types as you've described.

from fabric-chaincode-node.

bestbeforetoday avatar bestbeforetoday commented on August 24, 2024

I agree. Perhaps the TypeScript types would be better defined like this?

interface SuccessResponse {
    status: RESPONSE_CODE.OK;
    message?: string;
    payload: Uint8Array;
}

interface ErrorResponse {
    status: RESPONSE_CODE.ERROR;
    message: string;
    payload?: Uint8Array;
}

type ChaincodeResponse = SuccessResponse | ErrorResponse;

export class Shim {
    static error(msg: Uint8Array): ErrorResponse;
    static success(payload?: Uint8Array): SuccessResponse;
    // ...
}

So any fix can properly address your issue, I'm interested to know the impact of this typing mismatch on your use of the API.

from fabric-chaincode-node.

Jerrylum avatar Jerrylum commented on August 24, 2024

I think the fix could be the following:

interface SuccessResponse { // <- message is unnecessary for SuccessResponse 
    status: ChaincodeStub.RESPONSE_CODE.OK;
    payload: Uint8Array;
}

interface ErrorResponse { // <- payload is unnecessary for ErrorResponse 
    status: ChaincodeStub.RESPONSE_CODE.ERROR;
    message: string;
}

type ChaincodeResponse = SuccessResponse | ErrorResponse;

export class Shim {
    static error(msg: string): ErrorResponse; // <- this should be string instead of Uint8Array
    static success(payload?: Uint8Array): SuccessResponse;
    // ...
}

I was writing test cases for my chain code and discovered the issue. Do you think we can make a pull request?

from fabric-chaincode-node.

Related Issues (20)

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.