From 1bb314f767785fe617c3c5efeca1a64127339506 Mon Sep 17 00:00:00 2001 From: Determinant Date: Tue, 4 Aug 2020 10:47:20 -0400 Subject: include extra block data into hash calculation --- examples/block/main.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'examples') diff --git a/examples/block/main.go b/examples/block/main.go index e5349e0..45d7586 100644 --- a/examples/block/main.go +++ b/examples/block/main.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "crypto/rand" "fmt" "github.com/ava-labs/coreth" "github.com/ava-labs/coreth/core" @@ -11,6 +10,7 @@ import ( "github.com/ava-labs/coreth/params" "github.com/ava-labs/go-ethereum/common" "github.com/ava-labs/go-ethereum/common/hexutil" + "github.com/ava-labs/go-ethereum/crypto" "github.com/ava-labs/go-ethereum/rlp" "math/big" ) @@ -43,7 +43,9 @@ func main() { // configure the genesis block genBalance := big.NewInt(100000000000000000) - genKey, _ := coreth.NewKey(rand.Reader) + hk, _ := crypto.HexToECDSA( + "abd71b35d559563fea757f0f5edbde286fb8c043105b15abb7cd57189306d7d1") + genKey := coreth.NewKeyFromECDSA(hk) config.Genesis = &core.Genesis{ Config: chainConfig, @@ -108,11 +110,11 @@ func main() { checkError(err) buff.WriteString("somesuffix") fmt.Println(buff.Len()) - fmt.Println(common.ToHex(buff.Bytes())) + fmt.Println(blk2.Hash().Hex()) err = rlp.Decode(buff, blk2) - fmt.Println(buff.Len(), (string)(blk2.ExtraData())) checkError(err) + fmt.Println(buff.Len(), (string)(blk2.ExtraData()), blk2.Hash().Hex()) decoded1 := new(string) err = rlp.DecodeBytes(blk2.ExtraData(), decoded1) checkError(err) @@ -138,11 +140,12 @@ func main() { blk2.SetExtraData(extra) err = blk2.EncodeRLPTest(buff, 0xfffffffe) checkError(err) + fmt.Println(blk2.Hash().Hex()) err = rlp.Decode(buff, blk2) checkError(err) decoded2 := new(MyData) err = rlp.DecodeBytes(blk2.ExtraData(), decoded2) checkError(err) - fmt.Println(buff.Len(), decoded2) + fmt.Println(buff.Len(), decoded2, blk2.Hash().Hex()) buff.Reset() } -- cgit v1.2.3-70-g09d2