aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <tederminant@gmail.com>2019-09-24 12:55:57 -0400
committerDeterminant <tederminant@gmail.com>2019-09-24 12:55:57 -0400
commitfc9229d7d25dafe2eb37965115888d17e473ebe4 (patch)
tree251fde169b5f35dbbf27e720b98393e3a8165634
parent215fec775fc457fb69d77fd0fc128893721fa34e (diff)
enable AccountManager; add a channel to notify new txs
-rw-r--r--coreth.go13
-rw-r--r--eth/api_backend.go7
-rw-r--r--eth/backend.go7
-rw-r--r--node/service.go18
4 files changed, 36 insertions, 9 deletions
diff --git a/coreth.go b/coreth.go
index 0dbb226..3046b97 100644
--- a/coreth.go
+++ b/coreth.go
@@ -2,6 +2,7 @@ package coreth
import (
"crypto/ecdsa"
+ "fmt"
"io"
"os"
@@ -38,7 +39,13 @@ func NewETHChain(config *eth.Config, etherBase *common.Address) *ETHChain {
config = &eth.DefaultConfig
}
mux := new(event.TypeMux)
- ctx := node.NewServiceContext(mux)
+ ctx, ep, err := node.NewServiceContext(nil, mux)
+ if err != nil {
+ panic(err)
+ }
+ if ep != "" {
+ log.Info(fmt.Sprintf("ephemeral = %s", ep))
+ }
cb := new(dummy.ConsensusCallbacks)
mcb := new(miner.MinerCallbacks)
backend, _ := eth.New(&ctx, config, cb, mcb)
@@ -151,6 +158,10 @@ func (self *ETHChain) AttachEthService(handler *rpc.Server, namespaces []string)
}
}
+func (self *ETHChain) GetTxSubmitCh() <-chan struct{} {
+ return self.backend.GetTxSubmitCh()
+}
+
type Key struct {
Address common.Address
PrivateKey *ecdsa.PrivateKey
diff --git a/eth/api_backend.go b/eth/api_backend.go
index 7befd96..f4c0101 100644
--- a/eth/api_backend.go
+++ b/eth/api_backend.go
@@ -160,7 +160,12 @@ func (b *EthAPIBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscri
}
func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error {
- return b.eth.txPool.AddLocal(signedTx)
+ err := b.eth.txPool.AddLocal(signedTx)
+ select {
+ case b.eth.txSubmitChan <- struct{}{}:
+ default:
+ }
+ return err
}
func (b *EthAPIBackend) GetPoolTransactions() (types.Transactions, error) {
diff --git a/eth/backend.go b/eth/backend.go
index 666f0fb..b297b9b 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -99,6 +99,8 @@ type Ethereum struct {
netRPCService *ethapi.PublicNetAPI
lock sync.RWMutex // Protects the variadic fields (e.g. gas price and etherbase)
+
+ txSubmitChan chan struct{}
}
func (s *Ethereum) AddLesServer(ls LesServer) {
@@ -157,6 +159,7 @@ func New(ctx *node.ServiceContext, config *Config, cb *dummy.ConsensusCallbacks,
etherbase: config.Miner.Etherbase,
bloomRequests: make(chan chan *bloombits.Retrieval),
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms),
+ txSubmitChan: make(chan struct{}, 1),
}
bcVersion := rawdb.ReadDatabaseVersion(chainDb)
@@ -545,3 +548,7 @@ func (s *Ethereum) StopPart() error {
close(s.shutdownChan)
return nil
}
+
+func (s *Ethereum) GetTxSubmitCh() <-chan struct{} {
+ return s.txSubmitChan
+}
diff --git a/node/service.go b/node/service.go
index f72ac54..fca9d90 100644
--- a/node/service.go
+++ b/node/service.go
@@ -91,13 +91,17 @@ func (ctx *ServiceContext) ExtRPCEnabled() bool {
return ctx.config.ExtRPCEnabled()
}
-func NewServiceContext(mux *event.TypeMux) ServiceContext {
- return ServiceContext {
- config: &Config{},
- services: make(map[reflect.Type]Service),
- EventMux: mux,
- AccountManager: nil,
- }
+func NewServiceContext(cfg *Config, mux *event.TypeMux) (ServiceContext, string, error) {
+ if cfg == nil {
+ cfg = &Config{}
+ }
+ am, ep, err := makeAccountManager(cfg)
+ return ServiceContext{
+ config: cfg,
+ services: make(map[reflect.Type]Service),
+ EventMux: mux,
+ AccountManager: am,
+ }, ep, err
}
// ServiceConstructor is the function signature of the constructors needed to be