Search code examples
protocol-buffershyperledger-sawtooth

What is the difference between encode and create functions in protobuf in Hyperledger Sawtooth?


When writing client application for Hyperledger Sawtooth, protobuf.Transaction.create() is used to create a Transaction and protobuf.TransactionHeader.encode() is used to create TransactionHeader.

So what exactly is the difference between these two functions?


Solution

  • The transaction header encode method encodes the transaction header into a string of base64-encoded bytes.

    The transaction contains the transaction header, the transaction payload (application data), and the signature of the header. The create method creates this from the header and payload and signature.

    Here's a simple application that illustrates this (using the protobuf branch):

    https://github.com/danintel/sawtooth-cookiejar/tree/protobuf