aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/counter/main.go10
-rw-r--r--examples/payments/main.go6
2 files changed, 11 insertions, 5 deletions
diff --git a/examples/counter/main.go b/examples/counter/main.go
index e802a33..86e839a 100644
--- a/examples/counter/main.go
+++ b/examples/counter/main.go
@@ -6,11 +6,10 @@ import (
"encoding/json"
"fmt"
"github.com/ava-labs/coreth"
+ "github.com/ava-labs/coreth/core"
"github.com/ava-labs/coreth/eth"
"github.com/ava-labs/go-ethereum/common"
"github.com/ava-labs/go-ethereum/common/compiler"
- //"github.com/ava-labs/go-ethereum/common/hexutil"
- "github.com/ava-labs/go-ethereum/core"
"github.com/ava-labs/go-ethereum/core/types"
"github.com/ava-labs/go-ethereum/crypto"
"github.com/ava-labs/go-ethereum/log"
@@ -94,6 +93,7 @@ func main() {
blockCount := 0
chain := coreth.NewETHChain(&config, nil, nil, nil)
+ newTxPoolHeadChan := make(chan core.NewTxPoolHeadEvent, 1)
log.Info(chain.GetGenesisBlock().Hash().Hex())
firstBlock := false
var contractAddr common.Address
@@ -145,11 +145,15 @@ func main() {
if postGen(block) {
return nil
}
- chain.GenBlock()
+ go func() {
+ <-newTxPoolHeadChan
+ chain.GenBlock()
+ }()
return nil
})
// start the chain
+ chain.GetTxPool().SubscribeNewHeadEvent(newTxPoolHeadChan)
chain.Start()
_ = contract
diff --git a/examples/payments/main.go b/examples/payments/main.go
index 1eab70b..5076737 100644
--- a/examples/payments/main.go
+++ b/examples/payments/main.go
@@ -4,10 +4,10 @@ import (
"crypto/rand"
"fmt"
"github.com/ava-labs/coreth"
+ "github.com/ava-labs/coreth/core"
"github.com/ava-labs/coreth/eth"
"github.com/ava-labs/go-ethereum/common"
"github.com/ava-labs/go-ethereum/common/hexutil"
- "github.com/ava-labs/go-ethereum/core"
"github.com/ava-labs/go-ethereum/core/types"
"github.com/ava-labs/go-ethereum/log"
"github.com/ava-labs/go-ethereum/params"
@@ -83,11 +83,13 @@ func main() {
header.Extra = append(header.Extra, hid...)
})
newBlockChan := make(chan *types.Block)
+ newTxPoolHeadChan := make(chan core.NewTxPoolHeadEvent, 1)
chain.SetOnSealFinish(func(block *types.Block) error {
newBlockChan <- block
return nil
})
+ chain.GetTxPool().SubscribeNewHeadEvent(newTxPoolHeadChan)
// start the chain
chain.Start()
for i := 0; i < 42; i++ {
@@ -98,7 +100,7 @@ func main() {
nonce++
chain.GenBlock()
block := <-newBlockChan
- chain.SetTail(block.Hash())
+ <-newTxPoolHeadChan
log.Info("finished generating block, starting the next iteration", "height", block.Number())
}
showBalance()