Implementing Hyperledger Sawtooth Transaction Family
After the namespace and address scheme is defined for the transaction family, the state, transaction, and payload encoding scheme can be defined.
To define the state, you should analyze the data requirements for your organization and follow an appropriate modeling process to define the semantic data model for the system. For example, you could use entity-relationship modeling to represent conceptual data logic in your enterprise. In our example, the state is as follows:
This can be explained as follows:
- House APN (Key): The Assessor Parcel Number (APN) for a house is a unique number assigned to each parcel of land by a county tax assessor. The APN is based on formatting codes, depending on the home’s location. Local governments use APNs to identify and keep track of land ownership for property tax purposes.
- House Owner: The name of the person who currently owns the house.
Defining transactions involves analyzing all your business use cases and the attributes used to perform these business operations. In our example, transactions and their payloads are as follows:
- House APN (Key): The key attribute for the state.
- Action: This can be either the create keyword or the transfer keyword.
- House Owner: The name of the house owner.
To define payload encoding schemes, you could choose from one of the following methods:
- Protobuf Encoding: Protocol buffers are Google’s language and platform-neutral mechanism for serializing data. With protobuf encoding, you define the message formats in a .proto file and compile them using the protocol buffer compiler. To find out more, you can follow the guide that can be found here: https://developers.google.com/protocol-buffers/. It is small, fast, and simple, but it is not human-readable. Like JSON, it is also supported in many languages, such as Java, Python, C++, and Go.
- Simple text encoding: This involves defining your own message format and carrying out character encoding using your own protocol with a special delimiter, or following common formats, such as .csv or base64, to represent data in an ASCII format or string. These are human-readable, simple, easy, fast, and language- and platform-neutral.
For our example, the encoding for the state and payload is simple text encoding that encodes the data with UTF8 and the CSV format. We are using the Sawtooth XO family as a template.
For hash collisions, the colliding state will be stored as the UTF-8 encoding of the string with a delimiter, |, such as entry 1|entry 2:
for house, (owner) in house_list.items()])).encode()