Transaction Proposal Data

The transaction proposal is a request to invoke a chaincode function with certain input parameters, with the intent of reading and/or updating the ledger.

The transaction proposal is packed into a properly architected format (protocol buffer over gRPC) and takes the user’s cryptographic credentials to produce a unique signature for this transaction proposal.

During the chaincode execution, we can fetch transaction proposal details, such as input parameters, creator’s certificate, channel identifier, and others, with the help of ChaincodeStub interface.

While the ChaincodeStub interface defines a group of functions to parse the input parameters, fabric-contract-api implements a default parsing strategy for the Contract class inheritors. An array of arguments would be mapped to the transaction arguments following the mandatory transaction context (ctx) argument in the first position. For example, if we have myFunction(ctx, name, surname) and we receive an array of arguments from a caller ["John", "Adams"], then the arguments would be mapped as myFunction(ctx, "John", "Adams"). This is processed without any developer intervention. Every argument is passed as a string, so further conversion might be required. If an unexpected number of parameters are passed, the chaincode will throw an exception.

Let’s extend the SimpleContract implementation with some simple transaction functions. First of all, we should define the business logic of the chaincode. Let SimpleContract have three main operations:

  1. put(k, v) - store a key-value pair (k, v)

  2. get(k) - retrieve a value v associated with the key k

  3. del(k) - remove a key-value pair associated with the key k in a sense that the value v cannot be retrieved using get(k) operation

For the time being, we do not know how to properly update the blockchain ledger. However, we can still define the corresponding transaction functions in SimpleContract, though they will not be of use for now.

async put(ctx, key, value) {} async get(ctx, key) {} async del(ctx, key) {}

Last updated

Was this helpful?