From c73ba009031126e16da6999468851b33f93e8005 Mon Sep 17 00:00:00 2001 From: Determinant Date: Mon, 3 Aug 2020 17:16:53 -0400 Subject: allow using extra binary data in a block for state transition --- examples/block/main.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'examples') 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() -- cgit v1.2.3-70-g09d2