Class: Proposal

Proposal

This is an base class represents a Proposal definition and the base for actions on a proposal. This class allows an application to contain all proposal attributes and artifacts in one place during runtime. Use the Endorsement Query and Commit to endorse, query, and to commit a proposal.

new Proposal(chaincodeId, channel)

Construct a Proposal object.
Parameters:
Name Type Description
chaincodeId string The chaincode this proposal will execute
channel Channel The channel of this proposal
Returns:
The Proposal instance.
Type
Proposal

Methods


addChaincodeCollectionsInterest(chaincodeId, collectionNames)

Use this method to add a chaincode name and collection names that this proposal's chaincode will call. These will be used to build a Discovery interest when this proposal is used with the Discovery Service.
Parameters:
Name Type Argument Description
chaincodeId string chaincode name
collectionNames string <repeatable>
one or more collection names

addChaincodeNoPrivateReadsCollectionsInterest(chaincodeId, noPrivateReads, collectionNames)

Use this method to add a chaincode name and the collection names that this proposal's chaincode will call along with the no private read setting. These will be used to build a Discovery interest when this proposal is used with the Discovery Service.
Parameters:
Name Type Argument Description
chaincodeId string chaincode name
noPrivateReads boolean Indicates we do not need to read from private data
collectionNames string <repeatable>
one or more collection names

addCollectionInterest(collectionName)

Use this method to add collection names associated with this proposal's chaincode name. These will be used to build a Discovery interest. Proposal#buildProposalInterest
Parameters:
Name Type Description
collectionName string collection name

build(idContext, request)

Use this method to build a proposal. The proposal will be stored internally and also returned as bytes. Use the bytes when signing the proposal externally. When signing the proposal externally the user object of the IdentityContext does not have to have a signing identity, only an identity that has the user's certificate is required. This identity will be used to build the protobuf objects of the proposal that must be signed later and sent to the fabric Peer for endorsement.
Parameters:
Name Type Description
idContext IdentityContext Contains the User object needed to build this proposal.
request BuildProposalRequest The proposals values of the request.

buildProposalInterest()

Returns a JSON object representing this proposal's chaincodes, collections and the no private reads as an "interest" for the Discovery Service. The Discovery will use an interest to build a query request for an endorsement plan to a Peer's Discovery service. Use the Proposal#addCollectionInterest to add collections for the chaincode of this proposal. Use the Proposal#setNoPrivateReads to set this "no private reads" setting for this proposal's chaincode. The default will be false when not set. Use the Proposal#addChaincodeCollectionInterest to add chaincodes and collections that this chaincode code will call.
Examples
[
     { name: "mychaincode", collectionNames: ["mycollection"] }
   ]
[
     { name: "mychaincode", collectionNames: ["mycollection"], noPrivateReads: true }
   ]

getTransactionId()

Returns the transaction ID used for the proposal
Returns:
The transaction ID of the proposal
Type
string

<async> send(request)

Send a signed transaction proposal to peer(s)
Parameters:
Name Type Description
request SendProposalRequest options
Returns:
The results of sending
Type
ProposalResponse

setNoPrivateReads(noPrivateReads)

Use this method to set the "no private reads" of the discovery hint (interest) for the chaincode of this proposal.
Parameters:
Name Type Description
noPrivateReads boolean Indicates we do not need to read from private data

toString()

return a printable representation of this object

verifyProposalResponse(proposalResponse)

Utility method to verify a single proposal response. It checks the following aspects:
  • The endorser's identity belongs to a legitimate MSP of the channel and can be successfully deserialized
  • The endorsement signature can be successfully verified with the endorser's identity certificate

    This method requires that the initialize method of this channel object has been called to load this channel's MSPs. The MSPs will have the trusted root certificates for this channel.
  • Parameters:
    Name Type Description
    proposalResponse ProposalResponse The endorsement response from the peer, includes the endorser certificate and signature over the proposal + endorsement result + endorser certificate.
    Returns:
    A boolean value of true when both the identity and the signature are valid, false otherwise.
    Type
    boolean