mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
Fixed move method getBlockSingers by blockNumber to utils of contact package.
This commit is contained in:
parent
124f587abf
commit
d502c6b2e4
2 changed files with 38 additions and 20 deletions
|
|
@ -2,10 +2,14 @@ package contracts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
|
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/contracts/blocksigner/contract"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"math/big"
|
"math/big"
|
||||||
)
|
)
|
||||||
|
|
@ -14,6 +18,18 @@ const (
|
||||||
HexSignMethod = "2fb1b25f"
|
HexSignMethod = "2fb1b25f"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Get ethClient over IPC of current node.
|
||||||
|
func GetEthClient(ctx *node.ServiceContext) (*ethclient.Client, error) {
|
||||||
|
conf := ctx.GetConfig()
|
||||||
|
client, err := ethclient.Dial(conf.IPCEndpoint())
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Fail to connect RPC", "error", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Send tx sign for block number to smart contract blockSigner.
|
// Send tx sign for block number to smart contract blockSigner.
|
||||||
func CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, manager *accounts.Manager, block *types.Block) {
|
func CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, manager *accounts.Manager, block *types.Block) {
|
||||||
// Find active account.
|
// Find active account.
|
||||||
|
|
@ -41,3 +57,22 @@ func CreateTransactionSign(chainConfig *params.ChainConfig, pool *core.TxPool, m
|
||||||
// Add tx signed to local tx pool.
|
// Add tx signed to local tx pool.
|
||||||
pool.AddLocal(txSigned)
|
pool.AddLocal(txSigned)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get signers signed for blockNumber from blockSigner contract.
|
||||||
|
func GetSignersFromContract(ctx *node.ServiceContext, blockNumber uint64) ([]common.Address, error) {
|
||||||
|
client, err := GetEthClient(ctx)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Fail to connect IPC from blockSigner", "error", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
addr := common.HexToAddress(common.BlockSigners)
|
||||||
|
blockSigner, err := contract.NewBlockSigner(addr, client)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Fail get block signers", "error", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
opts := new(bind.CallOpts)
|
||||||
|
addrs, err := blockSigner.GetSigners(opts, new(big.Int).SetUint64(blockNumber))
|
||||||
|
|
||||||
|
return addrs, nil
|
||||||
|
}
|
||||||
|
|
@ -27,13 +27,12 @@ import (
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
"github.com/ethereum/go-ethereum/accounts/abi/bind"
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/consensus"
|
"github.com/ethereum/go-ethereum/consensus"
|
||||||
"github.com/ethereum/go-ethereum/consensus/clique"
|
"github.com/ethereum/go-ethereum/consensus/clique"
|
||||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||||
"github.com/ethereum/go-ethereum/contracts/blocksigner/contract"
|
"github.com/ethereum/go-ethereum/contracts"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/bloombits"
|
"github.com/ethereum/go-ethereum/core/bloombits"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
|
|
@ -42,7 +41,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
"github.com/ethereum/go-ethereum/eth/downloader"
|
||||||
"github.com/ethereum/go-ethereum/eth/filters"
|
"github.com/ethereum/go-ethereum/eth/filters"
|
||||||
"github.com/ethereum/go-ethereum/eth/gasprice"
|
"github.com/ethereum/go-ethereum/eth/gasprice"
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/internal/ethapi"
|
"github.com/ethereum/go-ethereum/internal/ethapi"
|
||||||
|
|
@ -199,21 +197,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
|
|
||||||
number := header.Number.Uint64()
|
number := header.Number.Uint64()
|
||||||
rCheckpoint := chain.Config().Clique.RewardCheckpoint
|
rCheckpoint := chain.Config().Clique.RewardCheckpoint
|
||||||
|
|
||||||
// Call to smart contract signer.
|
|
||||||
config := ctx.GetConfig()
|
|
||||||
client, err := ethclient.Dial(config.IPCEndpoint())
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Fail to connect RPC", "error", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
addr := common.HexToAddress(common.BlockSigners)
|
|
||||||
blockSigner, err := contract.NewBlockSigner(addr, client)
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Fail get block signer", "error", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
opts := new(bind.CallOpts)
|
|
||||||
prevCheckpoint := number - rCheckpoint
|
prevCheckpoint := number - rCheckpoint
|
||||||
|
|
||||||
if number > 0 && prevCheckpoint > 0 {
|
if number > 0 && prevCheckpoint > 0 {
|
||||||
|
|
@ -225,9 +208,9 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
|
|
||||||
for i := startBlockNumber; i <= endBlockNumber; i++ {
|
for i := startBlockNumber; i <= endBlockNumber; i++ {
|
||||||
// Get signers in blockSigner smartcontract.
|
// Get signers in blockSigner smartcontract.
|
||||||
addrs, err := blockSigner.GetSigners(opts, new(big.Int).SetUint64(i))
|
addrs, err := contracts.GetSignersFromContract(ctx, i)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Fail to get signers from smartcontract.", "error", err)
|
log.Error("Fail to get signers from smartcontract.", "error", err, "blockNumber", i)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Filter duplicate address.
|
// Filter duplicate address.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue