aboutsummaryrefslogtreecommitdiff
path: root/examples/block
diff options
context:
space:
mode:
Diffstat (limited to 'examples/block')
-rw-r--r--examples/block/main.go22
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()