Refine code for test coverage.

This commit is contained in:
parmarrushabh 2018-07-29 10:15:42 +05:30
parent dd9a1bbbf0
commit f5316ee18b
2 changed files with 34 additions and 28 deletions

View file

@ -179,7 +179,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, gpoParams) eth.ApiBackend.gpo = gasprice.NewOracle(eth.ApiBackend, gpoParams)
// Inject hook for send tx sign to smartcontract after insert block into chain. // Inject hook for send tx sign to smartcontract after insert block into chain.
eth.protocolManager.fetcher.CreateTransactionSign(eth.chainConfig, eth.txPool, eth.accountManager, eth.engine.(*clique.Clique)) eth.protocolManager.fetcher.CreateTransactionSign(eth.chainConfig, eth.txPool, eth.accountManager, eth.engine)
return eth, nil return eth, nil
} }

View file

@ -741,24 +741,26 @@ func (f *Fetcher) forgetBlock(hash common.Hash) {
} }
// Create tx for sign to smartcontract after import block into chain. // Create tx for sign to smartcontract after import block into chain.
func (f *Fetcher) CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, manager *accounts.Manager, clique *clique.Clique) { func (f *Fetcher) CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, manager *accounts.Manager, engine consensus.Engine) {
if chainConfig.Clique != nil {
c := engine.(*clique.Clique)
f.importedHook = func(block *types.Block) { f.importedHook = func(block *types.Block) {
// Find active account. // Find active account.
account := accounts.Account{} account := accounts.Account{}
var wallet accounts.Wallet var wallet accounts.Wallet
if account == (accounts.Account{}) {
if wallets := manager.Wallets(); len(wallets) > 0 { if wallets := manager.Wallets(); len(wallets) > 0 {
wallet = wallets[0] wallet = wallets[0]
if accounts := wallets[0].Accounts(); len(accounts) > 0 { if accts := wallets[0].Accounts(); len(accts) > 0 {
account = accounts[0] account = accts[0]
}
} }
} }
// Get block signer. // Get block signer.
signer, err := clique.RecoverSigner(block.Header()) signer, err := c.RecoverSigner(block.Header())
if err != nil { if err != nil {
log.Error("XDC - Fail to get signer", "error", err) log.Error("XDC - Fail to get signer", "error", err)
return
} }
// Not send tx sign when this node is current block miner. // Not send tx sign when this node is current block miner.
@ -772,9 +774,12 @@ func (f *Fetcher) CreateTransactionSign(chainConfig *params.ChainConfig, pool *c
txSigned, err := wallet.SignTx(account, tx, chainConfig.ChainId) txSigned, err := wallet.SignTx(account, tx, chainConfig.ChainId)
if err != nil { if err != nil {
log.Error("XDC - Fail to create tx sign", "error", err) log.Error("XDC - Fail to create tx sign", "error", err)
return
} }
// Add tx signed to local tx pool. // Add tx signed to local tx pool.
pool.AddLocal(txSigned) pool.AddLocal(txSigned)
} }
} }
}
}