diff options
author | Determinant <[email protected]> | 2020-08-03 17:16:53 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2020-08-03 17:16:53 -0400 |
commit | c73ba009031126e16da6999468851b33f93e8005 (patch) | |
tree | 961111c84794cf3807946d073bcef36ec8ba6025 /examples | |
parent | 746a107e2a7bb1f66049240d320e29d0a0536eae (diff) |
allow using extra binary data in a block for state transition
Diffstat (limited to 'examples')
-rw-r--r-- | examples/block/main.go | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/examples/block/main.go b/examples/block/main.go index d9ea16b..e5349e0 100644 --- a/examples/block/main.go +++ b/examples/block/main.go @@ -103,15 +103,22 @@ func main() { checkError(err) buff.Reset() extra, err := rlp.EncodeToBytes("test extra data") - err = blk2.EncodeRLPTest(buff, 0xffffffff, extra) + blk2.SetExtraData(extra) + err = blk2.EncodeRLPTest(buff, 0xffffffff) checkError(err) buff.WriteString("somesuffix") fmt.Println(buff.Len()) fmt.Println(common.ToHex(buff.Bytes())) err = rlp.Decode(buff, blk2) - fmt.Println(buff.Len(), (string)(blk2.RawExtraData())) + fmt.Println(buff.Len(), (string)(blk2.ExtraData())) checkError(err) + decoded1 := new(string) + err = rlp.DecodeBytes(blk2.ExtraData(), decoded1) + checkError(err) + fmt.Println(buff.Len(), decoded1) + fmt.Println(common.ToHex(buff.Bytes())) + buff.Reset() type NestedData struct { A uint16 @@ -128,18 +135,13 @@ func main() { X: 4200, Y: 4300, Msg: "hello", Inner: NestedData{A: 1, B: 2, S: "world"}, }) checkError(err) - err = blk2.EncodeRLPTest(buff, 0xfffffffe, extra) + blk2.SetExtraData(extra) + err = blk2.EncodeRLPTest(buff, 0xfffffffe) checkError(err) - decoded1 := new(string) - err = rlp.DecodeBytes(blk2.RawExtraData(), decoded1) - checkError(err) - fmt.Println(buff.Len(), decoded1) - fmt.Println(common.ToHex(buff.Bytes())) - err = rlp.Decode(buff, blk2) checkError(err) decoded2 := new(MyData) - err = rlp.DecodeBytes(blk2.RawExtraData(), decoded2) + err = rlp.DecodeBytes(blk2.ExtraData(), decoded2) checkError(err) fmt.Println(buff.Len(), decoded2) buff.Reset() |