From 841b2b7225a9318718c3c856a9debdf01bc4f061 Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 26 Sep 2019 22:34:43 -0400 Subject: update examples --- examples/counter/main.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'examples/counter') diff --git a/examples/counter/main.go b/examples/counter/main.go index 8dfb6bf..db6e1de 100644 --- a/examples/counter/main.go +++ b/examples/counter/main.go @@ -92,7 +92,7 @@ func main() { gasPrice := big.NewInt(1000000000) blockCount := 0 - chain := coreth.NewETHChain(&config, nil, nil) + chain := coreth.NewETHChain(&config, nil, nil, nil) log.Info(chain.GetGenesisBlock().Hash().Hex()) firstBlock := false var contractAddr common.Address @@ -125,17 +125,22 @@ func main() { signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), genKey.PrivateKey) checkError(err) chain.AddRemoteTxs([]*types.Transaction{signedTx}) - time.Sleep(1000 * time.Millisecond) nonce++ } }() } return false } - chain.SetOnSeal(func(block *types.Block) error { + chain.SetOnHeaderNew(func(header *types.Header) { + hid := make([]byte, 32) + _, err := rand.Read(hid) + if err != nil { + panic("cannot generate hid") + } + header.Extra = append(header.Extra, hid...) + }) + chain.SetOnSealFinish(func(block *types.Block) error { go func() { - // the minimum time gap is 1s - time.Sleep(1000 * time.Millisecond) // generate 15 blocks blockCount++ if postGen(block) { -- cgit v1.2.3