mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-06 19:06:42 +01:00
Get ChainID from ethereum node
This commit is contained in:
@@ -265,6 +265,7 @@ type AuctionInterface interface {
|
||||
// AuctionClient is the implementation of the interface to the Auction Smart Contract in ethereum.
|
||||
type AuctionClient struct {
|
||||
client *EthereumClient
|
||||
chainID *big.Int
|
||||
address ethCommon.Address
|
||||
tokenHEZCfg TokenConfig
|
||||
auction *HermezAuctionProtocol.HermezAuctionProtocol
|
||||
@@ -287,8 +288,13 @@ func NewAuctionClient(client *EthereumClient, address ethCommon.Address, tokenHE
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
chainID, err := client.EthChainID()
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
return &AuctionClient{
|
||||
client: client,
|
||||
chainID: chainID,
|
||||
address: address,
|
||||
tokenHEZCfg: tokenHEZCfg,
|
||||
auction: auction,
|
||||
@@ -580,8 +586,7 @@ func (c *AuctionClient) AuctionBid(amount *big.Int, slot int64, bidAmount *big.I
|
||||
}
|
||||
tokenName := c.tokenHEZCfg.Name
|
||||
tokenAddr := c.tokenHEZCfg.Address
|
||||
chainid, _ := c.client.Client().ChainID(context.Background())
|
||||
digest, _ := createPermitDigest(tokenAddr, owner, spender, chainid, amount, nonce, deadline, tokenName)
|
||||
digest, _ := createPermitDigest(tokenAddr, owner, spender, c.chainID, amount, nonce, deadline, tokenName)
|
||||
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
|
||||
permit := createPermit(owner, spender, amount, deadline, digest, signature)
|
||||
_slot := big.NewInt(slot)
|
||||
@@ -607,9 +612,8 @@ func (c *AuctionClient) AuctionMultiBid(amount *big.Int, startingSlot, endingSlo
|
||||
}
|
||||
tokenName := c.tokenHEZCfg.Name
|
||||
tokenAddr := c.tokenHEZCfg.Address
|
||||
chainid, _ := c.client.Client().ChainID(context.Background())
|
||||
|
||||
digest, _ := createPermitDigest(tokenAddr, owner, spender, chainid, amount, nonce, deadline, tokenName)
|
||||
digest, _ := createPermitDigest(tokenAddr, owner, spender, c.chainID, amount, nonce, deadline, tokenName)
|
||||
signature, _ := c.client.ks.SignHash(*c.client.account, digest)
|
||||
permit := createPermit(owner, spender, amount, deadline, digest, signature)
|
||||
_startingSlot := big.NewInt(startingSlot)
|
||||
|
||||
@@ -34,6 +34,7 @@ type EthereumInterface interface {
|
||||
EthTransactionReceipt(context.Context, ethCommon.Hash) (*types.Receipt, error)
|
||||
|
||||
EthERC20Consts(ethCommon.Address) (*ERC20Consts, error)
|
||||
EthChainID() (*big.Int, error)
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -101,6 +102,15 @@ func NewEthereumClient(client *ethclient.Client, account *accounts.Account, ks *
|
||||
}
|
||||
}
|
||||
|
||||
// EthChainID returns the ChainID of the ethereum network
|
||||
func (c *EthereumClient) EthChainID() (*big.Int, error) {
|
||||
chainID, err := c.client.ChainID(context.Background())
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
return chainID, nil
|
||||
}
|
||||
|
||||
// BalanceAt retieves information about the default account
|
||||
func (c *EthereumClient) BalanceAt(addr ethCommon.Address) (*big.Int, error) {
|
||||
return c.client.BalanceAt(context.TODO(), addr, nil)
|
||||
|
||||
@@ -283,6 +283,7 @@ type RollupClient struct {
|
||||
tokenHEZ *HEZ.HEZ
|
||||
contractAbi abi.ABI
|
||||
opts *bind.CallOpts
|
||||
consts *common.RollupConstants
|
||||
}
|
||||
|
||||
// NewRollupClient creates a new RollupClient
|
||||
@@ -299,11 +300,11 @@ func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenHEZ
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
chainID, err := client.client.ChainID(context.Background())
|
||||
chainID, err := client.EthChainID()
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
return &RollupClient{
|
||||
c := &RollupClient{
|
||||
client: client,
|
||||
chainID: chainID,
|
||||
address: address,
|
||||
@@ -312,7 +313,13 @@ func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenHEZ
|
||||
tokenHEZ: tokenHEZ,
|
||||
contractAbi: contractAbi,
|
||||
opts: newCallOpts(),
|
||||
}, nil
|
||||
}
|
||||
consts, err := c.RollupConstants()
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
c.consts = consts
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// RollupForgeBatch is the interface to call the smart contract function
|
||||
@@ -320,11 +327,7 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (tx *types.T
|
||||
if tx, err = c.client.CallAuth(
|
||||
1000000, //nolint:gomnd
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
rollupConst, err := c.RollupConstants()
|
||||
if err != nil {
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
nLevels := rollupConst.Verifiers[args.VerifierIdx].NLevels
|
||||
nLevels := c.consts.Verifiers[args.VerifierIdx].NLevels
|
||||
lenBytes := nLevels / 8 //nolint:gomnd
|
||||
newLastIdx := big.NewInt(int64(args.NewLastIdx))
|
||||
// L1CoordinatorBytes
|
||||
@@ -915,11 +918,7 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, l1UserTxsL
|
||||
L2TxsData: []common.L2Tx{},
|
||||
FeeIdxCoordinator: []common.Idx{},
|
||||
}
|
||||
rollupConsts, err := c.RollupConstants()
|
||||
if err != nil {
|
||||
return nil, nil, tracerr.Wrap(err)
|
||||
}
|
||||
nLevels := rollupConsts.Verifiers[rollupForgeBatchArgs.VerifierIdx].NLevels
|
||||
nLevels := c.consts.Verifiers[rollupForgeBatchArgs.VerifierIdx].NLevels
|
||||
lenL1L2TxsBytes := int((nLevels/8)*2 + 2 + 1)
|
||||
numBytesL1TxUser := int(l1UserTxsLen) * lenL1L2TxsBytes
|
||||
numTxsL1Coord := len(aux.EncodedL1CoordinatorTx) / common.L1CoordinatorTxBytesLen
|
||||
|
||||
Reference in New Issue
Block a user