aboutsummaryrefslogtreecommitdiff
path: root/examples/block
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-08-04 10:47:20 -0400
committerDeterminant <[email protected]>2020-08-04 10:47:20 -0400
commit1bb314f767785fe617c3c5efeca1a64127339506 (patch)
tree1b86c0dab079115e811512bd979de53a5137add4 /examples/block
parent232173cbd4669223c7541fcb1d5ec77befaf2fdc (diff)
include extra block data into hash calculation
Diffstat (limited to 'examples/block')
-rw-r--r--examples/block/main.go13
1 files changed, 8 insertions, 5 deletions
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()
}