mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-06 19:06:42 +01:00
Simplify eth code
This commit is contained in:
308
eth/auction.go
308
eth/auction.go
@@ -265,7 +265,7 @@ type AuctionClient struct {
|
||||
client *EthereumClient
|
||||
address ethCommon.Address
|
||||
tokenAddress ethCommon.Address
|
||||
gasLimit uint64
|
||||
auction *HermezAuctionProtocol.HermezAuctionProtocol
|
||||
contractAbi abi.ABI
|
||||
}
|
||||
|
||||
@@ -275,11 +275,15 @@ func NewAuctionClient(client *EthereumClient, address, tokenAddress ethCommon.Ad
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(address, client.Client())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &AuctionClient{
|
||||
client: client,
|
||||
address: address,
|
||||
tokenAddress: tokenAddress,
|
||||
gasLimit: 1000000, //nolint:gomnd
|
||||
auction: auction,
|
||||
contractAbi: contractAbi,
|
||||
}, nil
|
||||
}
|
||||
@@ -289,13 +293,9 @@ func (c *AuctionClient) AuctionSetSlotDeadline(newDeadline uint8) (*types.Transa
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auction.SetSlotDeadline(auth, newDeadline)
|
||||
return c.auction.SetSlotDeadline(auth, newDeadline)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed setting slotDeadline: %w", err)
|
||||
@@ -304,14 +304,9 @@ func (c *AuctionClient) AuctionSetSlotDeadline(newDeadline uint8) (*types.Transa
|
||||
}
|
||||
|
||||
// AuctionGetSlotDeadline is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetSlotDeadline() (uint8, error) {
|
||||
var slotDeadline uint8
|
||||
func (c *AuctionClient) AuctionGetSlotDeadline() (slotDeadline uint8, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
slotDeadline, err = auction.GetSlotDeadline(nil)
|
||||
slotDeadline, err = c.auction.GetSlotDeadline(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
@@ -320,17 +315,11 @@ func (c *AuctionClient) AuctionGetSlotDeadline() (uint8, error) {
|
||||
}
|
||||
|
||||
// AuctionSetOpenAuctionSlots is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *AuctionClient) AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auction.SetOpenAuctionSlots(auth, newOpenAuctionSlots)
|
||||
return c.auction.SetOpenAuctionSlots(auth, newOpenAuctionSlots)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed setting openAuctionSlots: %w", err)
|
||||
@@ -339,14 +328,9 @@ func (c *AuctionClient) AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (
|
||||
}
|
||||
|
||||
// AuctionGetOpenAuctionSlots is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetOpenAuctionSlots() (uint16, error) {
|
||||
var openAuctionSlots uint16
|
||||
func (c *AuctionClient) AuctionGetOpenAuctionSlots() (openAuctionSlots uint16, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
openAuctionSlots, err = auction.GetOpenAuctionSlots(nil)
|
||||
openAuctionSlots, err = c.auction.GetOpenAuctionSlots(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
@@ -355,17 +339,11 @@ func (c *AuctionClient) AuctionGetOpenAuctionSlots() (uint16, error) {
|
||||
}
|
||||
|
||||
// AuctionSetClosedAuctionSlots is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint16) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *AuctionClient) AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint16) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auction.SetClosedAuctionSlots(auth, newClosedAuctionSlots)
|
||||
return c.auction.SetClosedAuctionSlots(auth, newClosedAuctionSlots)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed setting closedAuctionSlots: %w", err)
|
||||
@@ -374,14 +352,9 @@ func (c *AuctionClient) AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint1
|
||||
}
|
||||
|
||||
// AuctionGetClosedAuctionSlots is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetClosedAuctionSlots() (uint16, error) {
|
||||
var closedAuctionSlots uint16
|
||||
func (c *AuctionClient) AuctionGetClosedAuctionSlots() (closedAuctionSlots uint16, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
closedAuctionSlots, err = auction.GetClosedAuctionSlots(nil)
|
||||
closedAuctionSlots, err = c.auction.GetClosedAuctionSlots(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
@@ -390,17 +363,11 @@ func (c *AuctionClient) AuctionGetClosedAuctionSlots() (uint16, error) {
|
||||
}
|
||||
|
||||
// AuctionSetOutbidding is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint16) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint16) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
12500000, //nolint:gomnd
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auction.SetOutbidding(auth, newOutbidding)
|
||||
return c.auction.SetOutbidding(auth, newOutbidding)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed setting setOutbidding: %w", err)
|
||||
@@ -409,14 +376,9 @@ func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint16) (*types.Trans
|
||||
}
|
||||
|
||||
// AuctionGetOutbidding is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetOutbidding() (uint16, error) {
|
||||
var outbidding uint16
|
||||
func (c *AuctionClient) AuctionGetOutbidding() (outbidding uint16, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
outbidding, err = auction.GetOutbidding(nil)
|
||||
outbidding, err = c.auction.GetOutbidding(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
@@ -425,17 +387,11 @@ func (c *AuctionClient) AuctionGetOutbidding() (uint16, error) {
|
||||
}
|
||||
|
||||
// AuctionSetAllocationRatio is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionSetAllocationRatio(newAllocationRatio [3]uint16) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *AuctionClient) AuctionSetAllocationRatio(newAllocationRatio [3]uint16) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auction.SetAllocationRatio(auth, newAllocationRatio)
|
||||
return c.auction.SetAllocationRatio(auth, newAllocationRatio)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed setting allocationRatio: %w", err)
|
||||
@@ -444,14 +400,9 @@ func (c *AuctionClient) AuctionSetAllocationRatio(newAllocationRatio [3]uint16)
|
||||
}
|
||||
|
||||
// AuctionGetAllocationRatio is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetAllocationRatio() ([3]uint16, error) {
|
||||
var allocationRation [3]uint16
|
||||
func (c *AuctionClient) AuctionGetAllocationRatio() (allocationRation [3]uint16, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
allocationRation, err = auction.GetAllocationRatio(nil)
|
||||
allocationRation, err = c.auction.GetAllocationRatio(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return [3]uint16{}, err
|
||||
@@ -460,17 +411,11 @@ func (c *AuctionClient) AuctionGetAllocationRatio() ([3]uint16, error) {
|
||||
}
|
||||
|
||||
// AuctionSetDonationAddress is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionSetDonationAddress(newDonationAddress ethCommon.Address) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *AuctionClient) AuctionSetDonationAddress(newDonationAddress ethCommon.Address) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auction.SetDonationAddress(auth, newDonationAddress)
|
||||
return c.auction.SetDonationAddress(auth, newDonationAddress)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed setting donationAddress: %w", err)
|
||||
@@ -479,33 +424,23 @@ func (c *AuctionClient) AuctionSetDonationAddress(newDonationAddress ethCommon.A
|
||||
}
|
||||
|
||||
// AuctionGetDonationAddress is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetDonationAddress() (*ethCommon.Address, error) {
|
||||
var donationAddress ethCommon.Address
|
||||
func (c *AuctionClient) AuctionGetDonationAddress() (donationAddress *ethCommon.Address, err error) {
|
||||
var _donationAddress ethCommon.Address
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
donationAddress, err = auction.GetDonationAddress(nil)
|
||||
_donationAddress, err = c.auction.GetDonationAddress(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &donationAddress, nil
|
||||
return &_donationAddress, nil
|
||||
}
|
||||
|
||||
// AuctionSetBootCoordinator is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auction.SetBootCoordinator(auth, newBootCoordinator)
|
||||
return c.auction.SetBootCoordinator(auth, newBootCoordinator)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed setting bootCoordinator: %w", err)
|
||||
@@ -514,34 +449,24 @@ func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.A
|
||||
}
|
||||
|
||||
// AuctionGetBootCoordinator is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetBootCoordinator() (*ethCommon.Address, error) {
|
||||
var bootCoordinator ethCommon.Address
|
||||
func (c *AuctionClient) AuctionGetBootCoordinator() (bootCoordinator *ethCommon.Address, err error) {
|
||||
var _bootCoordinator ethCommon.Address
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bootCoordinator, err = auction.GetBootCoordinator(nil)
|
||||
_bootCoordinator, err = c.auction.GetBootCoordinator(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &bootCoordinator, nil
|
||||
return &_bootCoordinator, nil
|
||||
}
|
||||
|
||||
// AuctionChangeDefaultSlotSetBid is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionChangeDefaultSlotSetBid(slotSet int64, newInitialMinBid *big.Int) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *AuctionClient) AuctionChangeDefaultSlotSetBid(slotSet int64, newInitialMinBid *big.Int) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
slotSetToSend := big.NewInt(slotSet)
|
||||
return auction.ChangeDefaultSlotSetBid(auth, slotSetToSend, newInitialMinBid)
|
||||
return c.auction.ChangeDefaultSlotSetBid(auth, slotSetToSend, newInitialMinBid)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed changing slotSet Bid: %w", err)
|
||||
@@ -550,14 +475,9 @@ func (c *AuctionClient) AuctionChangeDefaultSlotSetBid(slotSet int64, newInitial
|
||||
}
|
||||
|
||||
// AuctionGetClaimableHEZ is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetClaimableHEZ(claimAddress ethCommon.Address) (*big.Int, error) {
|
||||
var claimableHEZ *big.Int
|
||||
func (c *AuctionClient) AuctionGetClaimableHEZ(claimAddress ethCommon.Address) (claimableHEZ *big.Int, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
claimableHEZ, err = auction.GetClaimableHEZ(nil, claimAddress)
|
||||
claimableHEZ, err = c.auction.GetClaimableHEZ(nil, claimAddress)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
@@ -566,17 +486,11 @@ func (c *AuctionClient) AuctionGetClaimableHEZ(claimAddress ethCommon.Address) (
|
||||
}
|
||||
|
||||
// AuctionSetCoordinator is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionSetCoordinator(forger ethCommon.Address, coordinatorURL string) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *AuctionClient) AuctionSetCoordinator(forger ethCommon.Address, coordinatorURL string) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auction.SetCoordinator(auth, forger, coordinatorURL)
|
||||
return c.auction.SetCoordinator(auth, forger, coordinatorURL)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed set coordinator: %w", err)
|
||||
@@ -585,32 +499,22 @@ func (c *AuctionClient) AuctionSetCoordinator(forger ethCommon.Address, coordina
|
||||
}
|
||||
|
||||
// AuctionGetCurrentSlotNumber is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetCurrentSlotNumber() (int64, error) {
|
||||
func (c *AuctionClient) AuctionGetCurrentSlotNumber() (currentSlotNumber int64, err error) {
|
||||
var _currentSlotNumber *big.Int
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_currentSlotNumber, err = auction.GetCurrentSlotNumber(nil)
|
||||
_currentSlotNumber, err = c.auction.GetCurrentSlotNumber(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
currentSlotNumber := _currentSlotNumber.Int64()
|
||||
return currentSlotNumber, nil
|
||||
return _currentSlotNumber.Int64(), nil
|
||||
}
|
||||
|
||||
// AuctionGetMinBidBySlot is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetMinBidBySlot(slot int64) (*big.Int, error) {
|
||||
var minBid *big.Int
|
||||
func (c *AuctionClient) AuctionGetMinBidBySlot(slot int64) (minBid *big.Int, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
slotToSend := big.NewInt(slot)
|
||||
minBid, err = auction.GetMinBidBySlot(nil, slotToSend)
|
||||
minBid, err = c.auction.GetMinBidBySlot(nil, slotToSend)
|
||||
return err
|
||||
}); err != nil {
|
||||
return big.NewInt(0), err
|
||||
@@ -619,15 +523,10 @@ func (c *AuctionClient) AuctionGetMinBidBySlot(slot int64) (*big.Int, error) {
|
||||
}
|
||||
|
||||
// AuctionGetSlotSet is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetSlotSet(slot int64) (*big.Int, error) {
|
||||
var slotSet *big.Int
|
||||
func (c *AuctionClient) AuctionGetSlotSet(slot int64) (slotSet *big.Int, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
slotToSend := big.NewInt(slot)
|
||||
slotSet, err = auction.GetSlotSet(nil, slotToSend)
|
||||
slotSet, err = c.auction.GetSlotSet(nil, slotToSend)
|
||||
return err
|
||||
}); err != nil {
|
||||
return big.NewInt(0), err
|
||||
@@ -636,14 +535,9 @@ func (c *AuctionClient) AuctionGetSlotSet(slot int64) (*big.Int, error) {
|
||||
}
|
||||
|
||||
// AuctionGetDefaultSlotSetBid is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error) {
|
||||
var minBidSlotSet *big.Int
|
||||
func (c *AuctionClient) AuctionGetDefaultSlotSetBid(slotSet uint8) (minBidSlotSet *big.Int, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
minBidSlotSet, err = auction.GetDefaultSlotSetBid(nil, slotSet)
|
||||
minBidSlotSet, err = c.auction.GetDefaultSlotSetBid(nil, slotSet)
|
||||
return err
|
||||
}); err != nil {
|
||||
return big.NewInt(0), err
|
||||
@@ -652,28 +546,21 @@ func (c *AuctionClient) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, er
|
||||
}
|
||||
|
||||
// AuctionGetSlotNumber is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetSlotNumber(blockNum int64) (int64, error) {
|
||||
var slot *big.Int
|
||||
func (c *AuctionClient) AuctionGetSlotNumber(blockNum int64) (slot int64, err error) {
|
||||
var _slot *big.Int
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
blockNumBig := big.NewInt(blockNum)
|
||||
slot, err = auction.GetSlotNumber(nil, blockNumBig)
|
||||
_slot, err = c.auction.GetSlotNumber(nil, big.NewInt(blockNum))
|
||||
return err
|
||||
}); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return slot.Int64(), nil
|
||||
return _slot.Int64(), nil
|
||||
}
|
||||
|
||||
// AuctionBid is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
tokens, err := ERC777.NewERC777(c.tokenAddress, ec)
|
||||
if err != nil {
|
||||
@@ -703,11 +590,10 @@ func (c *AuctionClient) AuctionBid(slot int64, bidAmount *big.Int) (*types.Trans
|
||||
}
|
||||
|
||||
// AuctionMultiBid is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool, maxBid, closedMinBid, budget *big.Int) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *AuctionClient) AuctionMultiBid(startingSlot int64, endingSlot int64, slotSet [6]bool,
|
||||
maxBid, closedMinBid, budget *big.Int) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
1000000, //nolint:gomnd
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
tokens, err := ERC777.NewERC777(c.tokenAddress, ec)
|
||||
if err != nil {
|
||||
@@ -752,14 +638,9 @@ func (c *AuctionClient) AuctionMultiBid(startingSlot int64, endingSlot int64, sl
|
||||
}
|
||||
|
||||
// AuctionCanForge is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error) {
|
||||
var canForge bool
|
||||
func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address, blockNum int64) (canForge bool, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
canForge, err = auction.CanForge(nil, forger, big.NewInt(blockNum))
|
||||
canForge, err = c.auction.CanForge(nil, forger, big.NewInt(blockNum))
|
||||
return err
|
||||
}); err != nil {
|
||||
return false, err
|
||||
@@ -768,17 +649,11 @@ func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address, blockNum int64
|
||||
}
|
||||
|
||||
// AuctionClaimHEZ is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionClaimHEZ() (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *AuctionClient) AuctionClaimHEZ() (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auction.ClaimHEZ(auth)
|
||||
return c.auction.ClaimHEZ(auth)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed claim HEZ: %w", err)
|
||||
@@ -787,17 +662,11 @@ func (c *AuctionClient) AuctionClaimHEZ() (*types.Transaction, error) {
|
||||
}
|
||||
|
||||
// AuctionForge is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionForge(forger ethCommon.Address) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *AuctionClient) AuctionForge(forger ethCommon.Address) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return auction.Forge(auth, forger)
|
||||
return c.auction.Forge(auth, forger)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed forge: %w", err)
|
||||
@@ -806,31 +675,27 @@ func (c *AuctionClient) AuctionForge(forger ethCommon.Address) (*types.Transacti
|
||||
}
|
||||
|
||||
// AuctionConstants returns the Constants of the Auction Smart Contract
|
||||
func (c *AuctionClient) AuctionConstants() (*AuctionConstants, error) {
|
||||
auctionConstants := new(AuctionConstants)
|
||||
func (c *AuctionClient) AuctionConstants() (auctionConstants *AuctionConstants, err error) {
|
||||
auctionConstants = new(AuctionConstants)
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
auctionConstants.BlocksPerSlot, err = c.auction.BLOCKSPERSLOT(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auctionConstants.BlocksPerSlot, err = auction.BLOCKSPERSLOT(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
genesisBlock, err := auction.GenesisBlock(nil)
|
||||
genesisBlock, err := c.auction.GenesisBlock(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auctionConstants.GenesisBlockNum = genesisBlock.Int64()
|
||||
auctionConstants.HermezRollup, err = auction.HermezRollup(nil)
|
||||
auctionConstants.HermezRollup, err = c.auction.HermezRollup(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auctionConstants.InitialMinimalBidding, err = auction.INITIALMINIMALBIDDING(nil)
|
||||
auctionConstants.InitialMinimalBidding, err = c.auction.INITIALMINIMALBIDDING(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
auctionConstants.TokenHEZ, err = auction.TokenHEZ(nil)
|
||||
auctionConstants.TokenHEZ, err = c.auction.TokenHEZ(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
@@ -839,10 +704,9 @@ func (c *AuctionClient) AuctionConstants() (*AuctionConstants, error) {
|
||||
}
|
||||
|
||||
// AuctionVariables returns the variables of the Auction Smart Contract
|
||||
func (c *AuctionClient) AuctionVariables() (*AuctionVariables, error) {
|
||||
auctionVariables := new(AuctionVariables)
|
||||
func (c *AuctionClient) AuctionVariables() (auctionVariables *AuctionVariables, err error) {
|
||||
auctionVariables = new(AuctionVariables)
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
var err error
|
||||
auctionVariables.AllocationRatio, err = c.AuctionGetAllocationRatio()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts"
|
||||
ethKeystore "github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
)
|
||||
|
||||
@@ -29,14 +30,38 @@ type Client struct {
|
||||
RollupClient
|
||||
}
|
||||
|
||||
// RollupConfig is the configuration for the Rollup smart contract interface
|
||||
type RollupConfig struct {
|
||||
Address ethCommon.Address
|
||||
}
|
||||
|
||||
// AuctionConfig is the configuration for the Auction smart contract interface
|
||||
type AuctionConfig struct {
|
||||
Address ethCommon.Address
|
||||
TokenHEZAddress ethCommon.Address
|
||||
}
|
||||
|
||||
// ClientConfig is the configuration of the Client
|
||||
type ClientConfig struct {
|
||||
Ethereum EthereumConfig
|
||||
Rollup RollupConfig
|
||||
Auction AuctionConfig
|
||||
}
|
||||
|
||||
// NewClient creates a new Client to interact with Ethereum and the Hermez smart contracts.
|
||||
func NewClient(client *ethclient.Client, account *accounts.Account, ks *ethKeystore.KeyStore, config *EthereumConfig) *Client {
|
||||
ethereumClient := NewEthereumClient(client, account, ks, config)
|
||||
auctionClient := &AuctionClient{}
|
||||
rollupCient := &RollupClient{}
|
||||
func NewClient(client *ethclient.Client, account *accounts.Account, ks *ethKeystore.KeyStore, cfg *ClientConfig) (*Client, error) {
|
||||
ethereumClient := NewEthereumClient(client, account, ks, &cfg.Ethereum)
|
||||
auctionClient, err := NewAuctionClient(ethereumClient, cfg.Auction.Address, cfg.Auction.TokenHEZAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rollupCient, err := NewRollupClient(ethereumClient, cfg.Rollup.Address, cfg.Auction.TokenHEZAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Client{
|
||||
EthereumClient: *ethereumClient,
|
||||
AuctionClient: *auctionClient,
|
||||
RollupClient: *rollupCient,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
func TestClientInterface(t *testing.T) {
|
||||
var c ClientInterface
|
||||
client := NewClient(nil, nil, nil, nil)
|
||||
client, _ := NewClient(nil, nil, nil, &ClientConfig{})
|
||||
c = client
|
||||
require.NotNil(t, c)
|
||||
}
|
||||
|
||||
@@ -301,3 +301,8 @@ func (c *EthereumClient) EthERC20Consts(tokenAddress ethCommon.Address) (*ERC20C
|
||||
Decimals: uint64(decimals),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Client returns the internal ethclient.Client
|
||||
func (c *EthereumClient) Client() *ethclient.Client {
|
||||
return c.client
|
||||
}
|
||||
|
||||
129
eth/rollup.go
129
eth/rollup.go
@@ -153,9 +153,9 @@ type RollupState struct {
|
||||
|
||||
// RollupEventL1UserTx is an event of the Rollup Smart Contract
|
||||
type RollupEventL1UserTx struct {
|
||||
ToForgeL1TxsNum int64 // QueueIndex *big.Int
|
||||
Position int // TransactionIndex *big.Int
|
||||
L1UserTx common.L1Tx
|
||||
// ToForgeL1TxsNum int64 // QueueIndex *big.Int
|
||||
// Position int // TransactionIndex *big.Int
|
||||
L1UserTx common.L1Tx
|
||||
}
|
||||
|
||||
// RollupEventL1UserTxAux is an event of the Rollup Smart Contract
|
||||
@@ -173,7 +173,8 @@ type RollupEventAddToken struct {
|
||||
|
||||
// RollupEventForgeBatch is an event of the Rollup Smart Contract
|
||||
type RollupEventForgeBatch struct {
|
||||
BatchNum int64
|
||||
BatchNum int64
|
||||
// Sender ethCommon.Address
|
||||
EthTxHash ethCommon.Hash
|
||||
}
|
||||
|
||||
@@ -279,7 +280,7 @@ type RollupInterface interface {
|
||||
|
||||
RollupConstants() (*RollupPublicConstants, error)
|
||||
RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethCommon.Hash, error)
|
||||
RollupForgeBatchArgs(ethCommon.Hash) (*RollupForgeBatchArgs, error)
|
||||
RollupForgeBatchArgs(ethCommon.Hash) (*RollupForgeBatchArgs, *ethCommon.Address, error)
|
||||
}
|
||||
|
||||
//
|
||||
@@ -291,7 +292,7 @@ type RollupClient struct {
|
||||
client *EthereumClient
|
||||
address ethCommon.Address
|
||||
tokenHEZAddress ethCommon.Address
|
||||
gasLimit uint64
|
||||
hermez *Hermez.Hermez
|
||||
contractAbi abi.ABI
|
||||
}
|
||||
|
||||
@@ -301,26 +302,24 @@ func NewRollupClient(client *EthereumClient, address ethCommon.Address, tokenHEZ
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hermez, err := Hermez.NewHermez(address, client.Client())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &RollupClient{
|
||||
client: client,
|
||||
address: address,
|
||||
tokenHEZAddress: tokenHEZAddress,
|
||||
gasLimit: 1000000, //nolint:gomnd
|
||||
hermez: hermez,
|
||||
contractAbi: contractAbi,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// RollupForgeBatch is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
1000000, //nolint:gomnd
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
hermez, err := Hermez.NewHermez(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rollupConst, err := c.RollupConstants()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -362,7 +361,7 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (*types.Tran
|
||||
}
|
||||
feeIdxCoordinator = append(feeIdxCoordinator, bytesFeeIdx[len(bytesFeeIdx)-int(lenBytes):]...)
|
||||
}
|
||||
return hermez.ForgeBatch(auth, newLastIdx, args.NewStRoot, args.NewExitRoot, l1CoordinatorBytes, l2DataBytes, feeIdxCoordinator, args.VerifierIdx, args.L1Batch, args.ProofA, args.ProofB, args.ProofC)
|
||||
return c.hermez.ForgeBatch(auth, newLastIdx, args.NewStRoot, args.NewExitRoot, l1CoordinatorBytes, l2DataBytes, feeIdxCoordinator, args.VerifierIdx, args.L1Batch, args.ProofA, args.ProofB, args.ProofC)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed forge batch: %w", err)
|
||||
@@ -373,11 +372,9 @@ func (c *RollupClient) RollupForgeBatch(args *RollupForgeBatchArgs) (*types.Tran
|
||||
// RollupAddToken is the interface to call the smart contract function.
|
||||
// `feeAddToken` is the amount of HEZ tokens that will be paid to add the
|
||||
// token. `feeAddToken` must match the public value of the smart contract.
|
||||
func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address, feeAddToken *big.Int) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
tokens, err := ERC777.NewERC777(c.tokenHEZAddress, ec)
|
||||
if err != nil {
|
||||
@@ -403,11 +400,9 @@ func (c *RollupClient) RollupAddToken(tokenAddress ethCommon.Address, feeAddToke
|
||||
}
|
||||
|
||||
// RollupWithdrawMerkleProof is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupWithdrawMerkleProof(fromBJJ *babyjub.PublicKey, tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, instantWithdraw bool) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *RollupClient) RollupWithdrawMerkleProof(fromBJJ *babyjub.PublicKey, tokenID uint32, numExitRoot, idx int64, amount *big.Int, siblings []*big.Int, instantWithdraw bool) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
hermez, err := Hermez.NewHermez(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -433,11 +428,9 @@ func (c *RollupClient) RollupWithdrawCircuit(proofA, proofC [2]*big.Int, proofB
|
||||
}
|
||||
|
||||
// RollupL1UserTxERC20ETH is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
hermez, err := Hermez.NewHermez(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -469,11 +462,9 @@ func (c *RollupClient) RollupL1UserTxERC20ETH(fromBJJ *babyjub.PublicKey, fromId
|
||||
}
|
||||
|
||||
// RollupL1UserTxERC777 is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *RollupClient) RollupL1UserTxERC777(fromBJJ *babyjub.PublicKey, fromIdx int64, loadAmount *big.Int, amount *big.Int, tokenID uint32, toIdx int64) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
tokens, err := ERC777.NewERC777(c.tokenHEZAddress, ec)
|
||||
if err != nil {
|
||||
@@ -544,11 +535,9 @@ func (c *RollupClient) RollupRegisterTokensCount() (*big.Int, error) {
|
||||
}
|
||||
|
||||
// RollupUpdateForgeL1L2BatchTimeout is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout int64) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *RollupClient) RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeout int64) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
hermez, err := Hermez.NewHermez(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -563,11 +552,9 @@ func (c *RollupClient) RollupUpdateForgeL1L2BatchTimeout(newForgeL1L2BatchTimeou
|
||||
}
|
||||
|
||||
// RollupUpdateFeeAddToken is the interface to call the smart contract function
|
||||
func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
hermez, err := Hermez.NewHermez(c.address, ec)
|
||||
if err != nil {
|
||||
@@ -582,25 +569,21 @@ func (c *RollupClient) RollupUpdateFeeAddToken(newFeeAddToken *big.Int) (*types.
|
||||
}
|
||||
|
||||
// RollupConstants returns the Constants of the Rollup Smart Contract
|
||||
func (c *RollupClient) RollupConstants() (*RollupPublicConstants, error) {
|
||||
rollupConstants := new(RollupPublicConstants)
|
||||
func (c *RollupClient) RollupConstants() (rollupConstants *RollupPublicConstants, err error) {
|
||||
rollupConstants = new(RollupPublicConstants)
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
hermez, err := Hermez.NewHermez(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
absoluteMaxL1L2BatchTimeout, err := hermez.ABSOLUTEMAXL1L2BATCHTIMEOUT(nil)
|
||||
absoluteMaxL1L2BatchTimeout, err := c.hermez.ABSOLUTEMAXL1L2BATCHTIMEOUT(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.AbsoluteMaxL1L2BatchTimeout = int64(absoluteMaxL1L2BatchTimeout)
|
||||
rollupConstants.TokenHEZ, err = hermez.TokenHEZ(nil)
|
||||
rollupConstants.TokenHEZ, err = c.hermez.TokenHEZ(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := int64(0); i < int64(LenVerifiers); i++ {
|
||||
var newRollupVerifier RollupVerifierStruct
|
||||
rollupVerifier, err := hermez.RollupVerifiers(nil, big.NewInt(i))
|
||||
rollupVerifier, err := c.hermez.RollupVerifiers(nil, big.NewInt(i))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -608,19 +591,19 @@ func (c *RollupClient) RollupConstants() (*RollupPublicConstants, error) {
|
||||
newRollupVerifier.NLevels = rollupVerifier.NLevels.Int64()
|
||||
rollupConstants.Verifiers = append(rollupConstants.Verifiers, newRollupVerifier)
|
||||
}
|
||||
rollupConstants.HermezAuctionContract, err = hermez.HermezAuctionContract(nil)
|
||||
rollupConstants.HermezAuctionContract, err = c.hermez.HermezAuctionContract(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.HermezGovernanceDAOAddress, err = hermez.HermezGovernanceDAOAddress(nil)
|
||||
rollupConstants.HermezGovernanceDAOAddress, err = c.hermez.HermezGovernanceDAOAddress(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.SafetyAddress, err = hermez.SafetyAddress(nil)
|
||||
rollupConstants.SafetyAddress, err = c.hermez.SafetyAddress(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rollupConstants.WithdrawDelayerContract, err = hermez.WithdrawDelayerContract(nil)
|
||||
rollupConstants.WithdrawDelayerContract, err = c.hermez.WithdrawDelayerContract(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
@@ -670,12 +653,14 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
L1Tx, err := common.L1TxFromBytes(L1UserTxAux.L1UserTx)
|
||||
L1Tx, err := common.L1UserTxFromBytes(L1UserTxAux.L1UserTx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
L1UserTx.ToForgeL1TxsNum = new(big.Int).SetBytes(vLog.Topics[1][:]).Int64()
|
||||
L1UserTx.Position = int(new(big.Int).SetBytes(vLog.Topics[2][:]).Int64())
|
||||
toForgeL1TxsNum := new(big.Int).SetBytes(vLog.Topics[1][:]).Int64()
|
||||
L1Tx.ToForgeL1TxsNum = &toForgeL1TxsNum
|
||||
L1Tx.Position = int(new(big.Int).SetBytes(vLog.Topics[2][:]).Int64())
|
||||
L1Tx.UserOrigin = true
|
||||
L1UserTx.L1UserTx = *L1Tx
|
||||
rollupEvents.L1UserTx = append(rollupEvents.L1UserTx, L1UserTx)
|
||||
case logHermezAddToken:
|
||||
@@ -690,6 +675,7 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
|
||||
var forgeBatch RollupEventForgeBatch
|
||||
forgeBatch.BatchNum = new(big.Int).SetBytes(vLog.Topics[1][:]).Int64()
|
||||
forgeBatch.EthTxHash = vLog.TxHash
|
||||
// forgeBatch.Sender = vLog.Address
|
||||
rollupEvents.ForgeBatch = append(rollupEvents.ForgeBatch, forgeBatch)
|
||||
case logHermezUpdateForgeL1L2BatchTimeout:
|
||||
var updateForgeL1L2BatchTimeout struct {
|
||||
@@ -724,20 +710,29 @@ func (c *RollupClient) RollupEventsByBlock(blockNum int64) (*RollupEvents, *ethC
|
||||
return &rollupEvents, &blockHash, nil
|
||||
}
|
||||
|
||||
// RollupForgeBatchArgs returns the arguments used in a ForgeBatch call in the Rollup Smart Contract in the given transaction
|
||||
func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupForgeBatchArgs, error) {
|
||||
// RollupForgeBatchArgs returns the arguments used in a ForgeBatch call in the
|
||||
// Rollup Smart Contract in the given transaction, and the sender address.
|
||||
func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupForgeBatchArgs, *ethCommon.Address, error) {
|
||||
tx, _, err := c.client.client.TransactionByHash(context.Background(), ethTxHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
txData := tx.Data()
|
||||
method, err := c.contractAbi.MethodById(txData[:4])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
receipt, err := c.client.client.TransactionReceipt(context.Background(), ethTxHash)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
sender, err := c.client.client.TransactionSender(context.Background(), tx, receipt.Logs[0].BlockHash, receipt.Logs[0].Index)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
var aux RollupForgeBatchArgsAux
|
||||
if err := method.Inputs.Unpack(&aux, txData[4:]); err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
rollupForgeBatchArgs := RollupForgeBatchArgs{
|
||||
L1Batch: aux.L1Batch,
|
||||
@@ -763,16 +758,16 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
|
||||
signature = append(signature, r[:]...)
|
||||
signature = append(signature, s[:]...)
|
||||
signature = append(signature, v)
|
||||
l1Tx, err := common.L1TxFromCoordinatorBytes(bytesL1Coordinator)
|
||||
l1Tx, err := common.L1CoordinatorTxFromBytes(bytesL1Coordinator)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
rollupForgeBatchArgs.L1CoordinatorTxs = append(rollupForgeBatchArgs.L1CoordinatorTxs, *l1Tx)
|
||||
rollupForgeBatchArgs.L1CoordinatorTxsAuths = append(rollupForgeBatchArgs.L1CoordinatorTxsAuths, signature)
|
||||
}
|
||||
rollupConsts, err := c.RollupConstants()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
nLevels := rollupConsts.Verifiers[rollupForgeBatchArgs.VerifierIdx].NLevels
|
||||
lenL2TxsBytes := int((nLevels/8)*2 + 2 + 1)
|
||||
@@ -780,7 +775,7 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
|
||||
for i := 0; i < numTxsL2; i++ {
|
||||
l2Tx, err := common.L2TxFromBytes(aux.L2TxsData[i*lenL2TxsBytes:(i+1)*lenL2TxsBytes], int(nLevels))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
rollupForgeBatchArgs.L2TxsData = append(rollupForgeBatchArgs.L2TxsData, *l2Tx)
|
||||
}
|
||||
@@ -796,11 +791,11 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash) (*RollupFo
|
||||
}
|
||||
feeIdxCoordinator, err := common.IdxFromBytes(paddedFeeIdx[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
if feeIdxCoordinator != common.Idx(0) {
|
||||
rollupForgeBatchArgs.FeeIdxCoordinator = append(rollupForgeBatchArgs.FeeIdxCoordinator, feeIdxCoordinator)
|
||||
}
|
||||
}
|
||||
return &rollupForgeBatchArgs, nil
|
||||
return &rollupForgeBatchArgs, &sender, nil
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ func TestRollupForgeBatch(t *testing.T) {
|
||||
signature = append(signature, r[:]...)
|
||||
signature = append(signature, s[:]...)
|
||||
signature = append(signature, v)
|
||||
l1Tx, err := common.L1TxFromCoordinatorBytes(bytesL1Coordinator)
|
||||
l1Tx, err := common.L1CoordinatorTxFromBytes(bytesL1Coordinator)
|
||||
require.Nil(t, err)
|
||||
args.L1CoordinatorTxs = append(args.L1CoordinatorTxs, *l1Tx)
|
||||
args.L1CoordinatorTxsAuths = append(args.L1CoordinatorTxsAuths, signature)
|
||||
@@ -190,8 +190,9 @@ func TestRollupForgeBatch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRollupForgeBatchArgs(t *testing.T) {
|
||||
args, err := rollupClient.RollupForgeBatchArgs(ethHashForge)
|
||||
args, sender, err := rollupClient.RollupForgeBatchArgs(ethHashForge)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, *sender, rollupClient.client.account.Address)
|
||||
assert.Equal(t, argsForge.FeeIdxCoordinator, args.FeeIdxCoordinator)
|
||||
assert.Equal(t, argsForge.L1Batch, args.L1Batch)
|
||||
assert.Equal(t, argsForge.L1CoordinatorTxs, args.L1CoordinatorTxs)
|
||||
|
||||
176
eth/wdelayer.go
176
eth/wdelayer.go
@@ -136,7 +136,7 @@ type WDelayerInterface interface {
|
||||
type WDelayerClient struct {
|
||||
client *EthereumClient
|
||||
address ethCommon.Address
|
||||
gasLimit uint64
|
||||
wdelayer *WithdrawalDelayer.WithdrawalDelayer
|
||||
contractAbi abi.ABI
|
||||
}
|
||||
|
||||
@@ -146,42 +146,36 @@ func NewWDelayerClient(client *EthereumClient, address ethCommon.Address) (*WDel
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(address, client.Client())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &WDelayerClient{
|
||||
client: client,
|
||||
address: address,
|
||||
gasLimit: 1000000, //nolint:gomnd
|
||||
wdelayer: wdelayer,
|
||||
contractAbi: contractAbi,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WDelayerGetHermezGovernanceDAOAddress is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerGetHermezGovernanceDAOAddress() (*ethCommon.Address, error) {
|
||||
var hermezGovernanceDAOAddress ethCommon.Address
|
||||
func (c *WDelayerClient) WDelayerGetHermezGovernanceDAOAddress() (hermezGovernanceDAOAddress *ethCommon.Address, err error) {
|
||||
var _hermezGovernanceDAOAddress ethCommon.Address
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
hermezGovernanceDAOAddress, err = wdelayer.GetHermezGovernanceDAOAddress(nil)
|
||||
_hermezGovernanceDAOAddress, err = c.wdelayer.GetHermezGovernanceDAOAddress(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &hermezGovernanceDAOAddress, nil
|
||||
return &_hermezGovernanceDAOAddress, nil
|
||||
}
|
||||
|
||||
// WDelayerSetHermezGovernanceDAOAddress is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerSetHermezGovernanceDAOAddress(newAddress ethCommon.Address) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *WDelayerClient) WDelayerSetHermezGovernanceDAOAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wdelayer.SetHermezGovernanceDAOAddress(auth, newAddress)
|
||||
return c.wdelayer.SetHermezGovernanceDAOAddress(auth, newAddress)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed setting hermezGovernanceDAOAddress: %w", err)
|
||||
@@ -190,33 +184,23 @@ func (c *WDelayerClient) WDelayerSetHermezGovernanceDAOAddress(newAddress ethCom
|
||||
}
|
||||
|
||||
// WDelayerGetHermezKeeperAddress is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerGetHermezKeeperAddress() (*ethCommon.Address, error) {
|
||||
var hermezKeeperAddress ethCommon.Address
|
||||
func (c *WDelayerClient) WDelayerGetHermezKeeperAddress() (hermezKeeperAddress *ethCommon.Address, err error) {
|
||||
var _hermezKeeperAddress ethCommon.Address
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
hermezKeeperAddress, err = wdelayer.GetHermezKeeperAddress(nil)
|
||||
_hermezKeeperAddress, err = c.wdelayer.GetHermezKeeperAddress(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &hermezKeeperAddress, nil
|
||||
return &_hermezKeeperAddress, nil
|
||||
}
|
||||
|
||||
// WDelayerSetHermezKeeperAddress is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *WDelayerClient) WDelayerSetHermezKeeperAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wdelayer.SetHermezKeeperAddress(auth, newAddress)
|
||||
return c.wdelayer.SetHermezKeeperAddress(auth, newAddress)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed setting hermezKeeperAddress: %w", err)
|
||||
@@ -225,33 +209,23 @@ func (c *WDelayerClient) WDelayerSetHermezKeeperAddress(newAddress ethCommon.Add
|
||||
}
|
||||
|
||||
// WDelayerGetWhiteHackGroupAddress is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerGetWhiteHackGroupAddress() (*ethCommon.Address, error) {
|
||||
var whiteHackGroupAddress ethCommon.Address
|
||||
func (c *WDelayerClient) WDelayerGetWhiteHackGroupAddress() (whiteHackGroupAddress *ethCommon.Address, err error) {
|
||||
var _whiteHackGroupAddress ethCommon.Address
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
whiteHackGroupAddress, err = wdelayer.GetWhiteHackGroupAddress(nil)
|
||||
_whiteHackGroupAddress, err = c.wdelayer.GetWhiteHackGroupAddress(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &whiteHackGroupAddress, nil
|
||||
return &_whiteHackGroupAddress, nil
|
||||
}
|
||||
|
||||
// WDelayerSetWhiteHackGroupAddress is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.Address) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *WDelayerClient) WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.Address) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wdelayer.SetWhiteHackGroupAddress(auth, newAddress)
|
||||
return c.wdelayer.SetWhiteHackGroupAddress(auth, newAddress)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed setting whiteHackGroupAddress: %w", err)
|
||||
@@ -260,14 +234,9 @@ func (c *WDelayerClient) WDelayerSetWhiteHackGroupAddress(newAddress ethCommon.A
|
||||
}
|
||||
|
||||
// WDelayerIsEmergencyMode is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerIsEmergencyMode() (bool, error) {
|
||||
var ermergencyMode bool
|
||||
func (c *WDelayerClient) WDelayerIsEmergencyMode() (ermergencyMode bool, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ermergencyMode, err = wdelayer.IsEmergencyMode(nil)
|
||||
ermergencyMode, err = c.wdelayer.IsEmergencyMode(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return false, err
|
||||
@@ -276,14 +245,9 @@ func (c *WDelayerClient) WDelayerIsEmergencyMode() (bool, error) {
|
||||
}
|
||||
|
||||
// WDelayerGetWithdrawalDelay is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerGetWithdrawalDelay() (*big.Int, error) {
|
||||
var withdrawalDelay *big.Int
|
||||
func (c *WDelayerClient) WDelayerGetWithdrawalDelay() (withdrawalDelay *big.Int, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
withdrawalDelay, err = wdelayer.GetWithdrawalDelay(nil)
|
||||
withdrawalDelay, err = c.wdelayer.GetWithdrawalDelay(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
@@ -292,14 +256,9 @@ func (c *WDelayerClient) WDelayerGetWithdrawalDelay() (*big.Int, error) {
|
||||
}
|
||||
|
||||
// WDelayerGetEmergencyModeStartingTime is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerGetEmergencyModeStartingTime() (*big.Int, error) {
|
||||
var emergencyModeStartingTime *big.Int
|
||||
func (c *WDelayerClient) WDelayerGetEmergencyModeStartingTime() (emergencyModeStartingTime *big.Int, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
emergencyModeStartingTime, err = wdelayer.GetEmergencyModeStartingTime(nil)
|
||||
emergencyModeStartingTime, err = c.wdelayer.GetEmergencyModeStartingTime(nil)
|
||||
return err
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
@@ -308,17 +267,11 @@ func (c *WDelayerClient) WDelayerGetEmergencyModeStartingTime() (*big.Int, error
|
||||
}
|
||||
|
||||
// WDelayerEnableEmergencyMode is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerEnableEmergencyMode() (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *WDelayerClient) WDelayerEnableEmergencyMode() (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wdelayer.EnableEmergencyMode(auth)
|
||||
return c.wdelayer.EnableEmergencyMode(auth)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed setting enable emergency mode: %w", err)
|
||||
@@ -327,17 +280,11 @@ func (c *WDelayerClient) WDelayerEnableEmergencyMode() (*types.Transaction, erro
|
||||
}
|
||||
|
||||
// WDelayerChangeWithdrawalDelay is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerChangeWithdrawalDelay(newWithdrawalDelay uint64) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *WDelayerClient) WDelayerChangeWithdrawalDelay(newWithdrawalDelay uint64) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wdelayer.ChangeWithdrawalDelay(auth, newWithdrawalDelay)
|
||||
return c.wdelayer.ChangeWithdrawalDelay(auth, newWithdrawalDelay)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed setting withdrawal delay: %w", err)
|
||||
@@ -346,14 +293,9 @@ func (c *WDelayerClient) WDelayerChangeWithdrawalDelay(newWithdrawalDelay uint64
|
||||
}
|
||||
|
||||
// WDelayerDepositInfo is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerDepositInfo(owner, token ethCommon.Address) (DepositState, error) {
|
||||
var depositInfo DepositState
|
||||
func (c *WDelayerClient) WDelayerDepositInfo(owner, token ethCommon.Address) (depositInfo DepositState, err error) {
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
amount, depositTimestamp, err := wdelayer.DepositInfo(nil, owner, token)
|
||||
amount, depositTimestamp, err := c.wdelayer.DepositInfo(nil, owner, token)
|
||||
depositInfo.Amount = amount
|
||||
depositInfo.DepositTimestamp = depositTimestamp
|
||||
return err
|
||||
@@ -364,17 +306,11 @@ func (c *WDelayerClient) WDelayerDepositInfo(owner, token ethCommon.Address) (De
|
||||
}
|
||||
|
||||
// WDelayerDeposit is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerDeposit(owner, token ethCommon.Address, amount *big.Int) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *WDelayerClient) WDelayerDeposit(owner, token ethCommon.Address, amount *big.Int) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wdelayer.Deposit(auth, owner, token, amount)
|
||||
return c.wdelayer.Deposit(auth, owner, token, amount)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed deposit: %w", err)
|
||||
@@ -383,17 +319,11 @@ func (c *WDelayerClient) WDelayerDeposit(owner, token ethCommon.Address, amount
|
||||
}
|
||||
|
||||
// WDelayerWithdrawal is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerWithdrawal(owner, token ethCommon.Address) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *WDelayerClient) WDelayerWithdrawal(owner, token ethCommon.Address) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wdelayer.Withdrawal(auth, owner, token)
|
||||
return c.wdelayer.Withdrawal(auth, owner, token)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed withdrawal: %w", err)
|
||||
@@ -402,17 +332,11 @@ func (c *WDelayerClient) WDelayerWithdrawal(owner, token ethCommon.Address) (*ty
|
||||
}
|
||||
|
||||
// WDelayerEscapeHatchWithdrawal is the interface to call the smart contract function
|
||||
func (c *WDelayerClient) WDelayerEscapeHatchWithdrawal(to, token ethCommon.Address, amount *big.Int) (*types.Transaction, error) {
|
||||
var tx *types.Transaction
|
||||
var err error
|
||||
func (c *WDelayerClient) WDelayerEscapeHatchWithdrawal(to, token ethCommon.Address, amount *big.Int) (tx *types.Transaction, err error) {
|
||||
if tx, err = c.client.CallAuth(
|
||||
c.gasLimit,
|
||||
0,
|
||||
func(ec *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
wdelayer, err := WithdrawalDelayer.NewWithdrawalDelayer(c.address, ec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return wdelayer.EscapeHatchWithdrawal(auth, to, token, amount)
|
||||
return c.wdelayer.EscapeHatchWithdrawal(auth, to, token, amount)
|
||||
},
|
||||
); err != nil {
|
||||
return nil, fmt.Errorf("Failed escapeHatchWithdrawal: %w", err)
|
||||
|
||||
Reference in New Issue
Block a user