3.3 Record Generation
A Record () is a data structure that captures the state transition of a protocol instance and can be represented as a tuple:
Where:
- is the unique identifier of the protocol instance
- is the reference to the state transition event (i.e. the block number, transaction hash, log index)
- is the pre-state hash
- is the post-state hash
Records exsists as serialized binary-object. The construction of the Recrod object is performed by the Record Generator, a component of the ASP system.
The Record Generator performs the following steps:
- Compute the using the protocol’s function if not allready provided.
- Compute and using the protocol’s state hash function .
- Assemble the Record object.
- Compute the Record hash .
Example go-implementation of :
package record
// 32-byte Scope
// 32-byte Tx Hash
// uint Log Index
// 32-byte pre-state hash
// 32-byte post-state hash
type RecordT [130]byte
type Record interface {
Hash() [32]byte
Scope() [32]byte
TxHash() [32]byte
LogIdx() uint
PreState() [32]byte
PostState() [32]byte
}
var _ Record = (*RecordT)(nil)
func (r RecordT) Hash() [32]byte {
return HashAlgorithm(r)
}
func (r RecordT) Scope() (scope [32]byte) {
copy(scope[:], r[:32])
return
}
func (r RecordT) TxHash() (txHash [32]byte) {
copy(txHash[:], r[32:64])
return
}
func (r RecordT) LogIndex() (logIndex uint) {
return uint(r[64])
}
func (r RecordT) PreState() (preStateHash [32]byte) {
copy(preStateHash[:], r[65:97])
return
}
func (r RecordT) PostState() (postStateHash [32]byte) {
copy(postStateHash[:], r[97:129])
return
}