add more receipt helper proc and test

This commit is contained in:
andri lim 2018-11-28 09:42:30 +07:00 committed by zah
parent 623d0e3c2b
commit e9facfb9d0
2 changed files with 20 additions and 0 deletions

View File

@ -204,6 +204,20 @@ proc hashOrStatus*(hash: Hash256): HashOrStatus =
proc hashOrStatus*(status: bool): HashOrStatus =
HashOrStatus(isHash: false, status: status)
proc hasStatus*(rec: Receipt): bool {.inline.} =
rec.stateRootOrStatus.isHash == false
proc hasStateRoot*(rec: Receipt): bool {.inline.} =
rec.stateRootOrStatus.isHash == true
proc stateRoot*(rec: Receipt): Hash256 {.inline.} =
assert(rec.hasStateRoot)
rec.stateRootOrStatus.hash
proc status*(rec: Receipt): int {.inline.} =
assert(rec.hasStatus)
if rec.stateRootOrStatus.status: 1 else: 0
#
# Rlp serialization:
#
@ -255,6 +269,7 @@ proc append*(rlpWriter: var RlpWriter, t: Transaction, a: EthAddress) {.inline.}
rlpWriter.append(a)
proc read*(rlp: var Rlp, T: typedesc[HashOrStatus]): T {.inline.} =
assert(rlp.blobLen() == 32 or rlp.blobLen() == 1)
if rlp.blobLen == 1:
result = hashOrStatus(rlp.read(uint8) == 1)
else:

View File

@ -29,3 +29,8 @@ suite "rlp encoding":
d = y.decode(Receipt)
check c == a
check d == b
check c.hasStateRoot
check c.stateRoot == hash
check d.hasStatus
check d.status == 1