aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-08-12 00:00:20 -0400
committerDeterminant <[email protected]>2019-08-12 00:00:20 -0400
commit068cb794976da713fb4671e1bb4e4657d3dcc2b3 (patch)
tree59a869bc21de8d7cba654ad7161ea5495c1eafe7
parent4c1616a746a648c816042f596eb199174a9858f1 (diff)
...
-rw-r--r--coreth.go24
-rw-r--r--examples/payments/main.go24
-rw-r--r--miner/miner.go5
-rw-r--r--node/service.go2
4 files changed, 52 insertions, 3 deletions
diff --git a/coreth.go b/coreth.go
index c7b5e42..e43ce3e 100644
--- a/coreth.go
+++ b/coreth.go
@@ -27,8 +27,8 @@ type Hash = common.Hash
type ETHChain struct {
mux *event.TypeMux
- worker *miner.Worker
backend *eth.Ethereum
+ worker *miner.Worker
}
type DummyEngine struct {
@@ -248,7 +248,7 @@ func isLocalBlock(block *types.Block) bool {
return false
}
-func NewETHChain(config *miner.Config, chainConfig *params.ChainConfig) *ETHChain {
+func NewETHChain(config *miner.Config, chainConfig *params.ChainConfig, etherBase *common.Address) *ETHChain {
if config == nil {
config = &eth.DefaultConfig.Miner
}
@@ -260,11 +260,31 @@ func NewETHChain(config *miner.Config, chainConfig *params.ChainConfig) *ETHChai
backend, _ := eth.New(&ctx, &eth.DefaultConfig)
chain := &ETHChain {
mux: mux,
+ backend: backend,
worker: miner.NewWorker(config, chainConfig, &DummyEngine{}, backend, mux, isLocalBlock),
}
+ if etherBase == nil {
+ etherBase = &common.Address{
+ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ }
+ }
+ chain.worker.SetEtherbase(*etherBase)
return chain
}
func (self *ETHChain) Start() {
self.worker.Start()
}
+
+func (self *ETHChain) Stop() {
+ self.worker.Stop()
+}
+
+func (self *ETHChain) AddRemoteTxs(txs []*types.Transaction) []error {
+ return self.backend.TxPool().AddRemotes(txs)
+}
+
+func (self *ETHChain) AddLocalTxs(txs []*types.Transaction) []error {
+ return self.backend.TxPool().AddLocals(txs)
+}
diff --git a/examples/payments/main.go b/examples/payments/main.go
index da29a2c..9a0298d 100644
--- a/examples/payments/main.go
+++ b/examples/payments/main.go
@@ -1,4 +1,28 @@
package main
+import (
+ "math/big"
+ "encoding/hex"
+ "github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/common"
+ "github.com/Determinant/coreth"
+ "github.com/ethereum/go-ethereum/log"
+ "time"
+)
+
func main() {
+ log.Root().SetHandler(log.StdoutHandler)
+ chain := coreth.NewETHChain(nil, nil, nil)
+ to := common.Address{}
+ nouce := 0
+ amount := big.NewInt(0)
+ gasLimit := 1000000000
+ gasPrice := big.NewInt(0)
+ deployCode, _ := hex.DecodeString("608060405234801561001057600080fd5b50600760008190555060cc806100276000396000f3fe6080604052600436106039576000357c0100000000000000000000000000000000000000000000000000000000900480631003e2d214603e575b600080fd5b348015604957600080fd5b50607360048036036020811015605e57600080fd5b81019080803590602001909291905050506089565b6040518082815260200191505060405180910390f35b60008160005401600081905550600054905091905056fea165627a7a7230582075069a1c11ef20dd272178c92ff7d593d7ef9c39b1a63e85588f9e45be9fb6420029")
+ tx := types.NewTransaction(uint64(nouce), to, amount, uint64(gasLimit), gasPrice, deployCode)
+ chain.Start()
+ //_ = tx
+ chain.AddLocalTxs([]*types.Transaction{tx})
+ time.Sleep(10000 * time.Millisecond)
+ chain.Stop()
}
diff --git a/miner/miner.go b/miner/miner.go
index b342bb8..b55d4fc 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -24,6 +24,7 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/params"
+ "github.com/ethereum/go-ethereum/common"
eminer "github.com/ethereum/go-ethereum/miner"
)
@@ -42,6 +43,10 @@ func NewWorker(config *Config, chainConfig *params.ChainConfig, engine consensus
return newWorker(config, chainConfig, engine, eth, mux, isLocalBlock)
}
+func (self *Worker) SetEtherbase(addr common.Address) {
+ self.setEtherbase(addr)
+}
+
func (self *Worker) Start() {
self.start()
}
diff --git a/node/service.go b/node/service.go
index fd03a57..9f54ba4 100644
--- a/node/service.go
+++ b/node/service.go
@@ -93,7 +93,7 @@ func (ctx *ServiceContext) ExtRPCEnabled() bool {
func NewServiceContext(mux *event.TypeMux) ServiceContext {
return ServiceContext {
- config: nil,
+ config: &Config{},
services: make(map[reflect.Type]Service),
EventMux: mux,
AccountManager: nil,