/
rlp_marshal_storage.go
89 lines (71 loc) · 1.74 KB
/
rlp_marshal_storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package types
import (
"github.com/umbracle/fastrlp"
)
type RLPStoreMarshaler interface {
MarshalStoreRLPTo(dst []byte) []byte
}
func (b *Body) MarshalRLPTo(dst []byte) []byte {
return MarshalRLPTo(b.MarshalRLPWith, dst)
}
func (b *Body) MarshalRLPWith(ar *fastrlp.Arena) *fastrlp.Value {
vv := ar.NewArray()
if len(b.Transactions) == 0 {
vv.Set(ar.NewNullArray())
} else {
v0 := ar.NewArray()
for _, tx := range b.Transactions {
v0.Set(tx.MarshalStoreRLPWith(ar))
}
vv.Set(v0)
}
if len(b.Uncles) == 0 {
vv.Set(ar.NewNullArray())
} else {
v1 := ar.NewArray()
for _, uncle := range b.Uncles {
v1.Set(uncle.MarshalRLPWith(ar))
}
vv.Set(v1)
}
return vv
}
func (t *Transaction) MarshalStoreRLPTo(dst []byte) []byte {
return MarshalRLPTo(t.MarshalStoreRLPWith, dst)
}
func (t *Transaction) MarshalStoreRLPWith(a *fastrlp.Arena) *fastrlp.Value {
vv := a.NewArray()
// consensus part
vv.Set(t.MarshalRLPWith(a))
// context part
vv.Set(a.NewBytes(t.From.Bytes()))
return vv
}
func (r Receipts) MarshalStoreRLPTo(dst []byte) []byte {
return MarshalRLPTo(r.MarshalStoreRLPWith, dst)
}
func (r *Receipts) MarshalStoreRLPWith(a *fastrlp.Arena) *fastrlp.Value {
vv := a.NewArray()
for _, rr := range *r {
vv.Set(rr.MarshalStoreRLPWith(a))
}
return vv
}
func (r *Receipt) MarshalStoreRLPTo(dst []byte) []byte {
return MarshalRLPTo(r.MarshalStoreRLPWith, dst)
}
func (r *Receipt) MarshalStoreRLPWith(a *fastrlp.Arena) *fastrlp.Value {
// use the hash part
vv := a.NewArray()
vv.Set(r.MarshalRLPWith(a))
if r.ContractAddress == nil {
vv.Set(a.NewNull())
} else {
vv.Set(a.NewBytes(r.ContractAddress.Bytes()))
}
// gas used
vv.Set(a.NewUint(r.GasUsed))
// TxHash
vv.Set(a.NewBytes(r.TxHash.Bytes()))
return vv
}