eth

package
v0.0.0-...-e04c47b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2022 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAccountNil is used when the calls can not be made because the account is nil
	ErrAccountNil = fmt.Errorf("Authorized calls can't be made when the account is nil")
	// ErrBlockHashMismatchEvent is used when there's a block hash mismatch
	// between different events of the same block
	ErrBlockHashMismatchEvent = fmt.Errorf("block hash mismatch in event log")
)

Functions

This section is empty.

Types

type AuctionClient

type AuctionClient struct {
	// contains filtered or unexported fields
}

AuctionClient is the implementation of the interface to the Auction Smart Contract in ethereum.

func NewAuctionClient

func NewAuctionClient(client *EthereumClient, address, tokenAddress ethCommon.Address) (*AuctionClient, error)

NewAuctionClient creates a new AuctionClient. `tokenAddress` is the address of the CB tokens.

func (*AuctionClient) AuctionBid

func (c *AuctionClient) AuctionBid(amount *big.Int, slot int64, bidAmount *big.Int,
	deadline *big.Int) (tx *types.Transaction, err error)

AuctionBid is the interface to call the smart contract function

func (*AuctionClient) AuctionCanForge

func (c *AuctionClient) AuctionCanForge(forger ethCommon.Address, blockNum int64) (canForge bool,
	err error)

AuctionCanForge is the interface to call the smart contract function

func (*AuctionClient) AuctionChangeDefaultSlotSetBid

func (c *AuctionClient) AuctionChangeDefaultSlotSetBid(slotSet int64,
	newInitialMinBid *big.Int) (tx *types.Transaction, err error)

AuctionChangeDefaultSlotSetBid is the interface to call the smart contract function

func (*AuctionClient) AuctionClaimCB

func (c *AuctionClient) AuctionClaimCB() (tx *types.Transaction, err error)

AuctionClaimCB is the interface to call the smart contract function

func (*AuctionClient) AuctionConstants

func (c *AuctionClient) AuctionConstants() (auctionConstants *common.AuctionConstants, err error)

AuctionConstants returns the Constants of the Auction Smart Contract

func (*AuctionClient) AuctionEventInit

func (c *AuctionClient) AuctionEventInit(genesisBlockNum int64) (*AuctionEventInitialize, int64, error)

AuctionEventInit returns the initialize event with its corresponding block number

func (*AuctionClient) AuctionEventsByBlock

func (c *AuctionClient) AuctionEventsByBlock(blockNum int64,
	blockHash *ethCommon.Hash) (*AuctionEvents, error)

AuctionEventsByBlock returns the events in a block that happened in the Auction Smart Contract. To query by blockNum, set blockNum >= 0 and blockHash == nil. To query by blockHash set blockHash != nil, and blockNum will be ignored. If there are no events in that block the result is nil.

func (*AuctionClient) AuctionForge

func (c *AuctionClient) AuctionForge(forger ethCommon.Address) (tx *types.Transaction, err error)

AuctionForge is the interface to call the smart contract function

func (*AuctionClient) AuctionGetAllocationRatio

func (c *AuctionClient) AuctionGetAllocationRatio() (allocationRation [3]uint16, err error)

AuctionGetAllocationRatio is the interface to call the smart contract function

func (*AuctionClient) AuctionGetBootCoordinator

func (c *AuctionClient) AuctionGetBootCoordinator() (bootCoordinator *ethCommon.Address,
	err error)

AuctionGetBootCoordinator is the interface to call the smart contract function

func (*AuctionClient) AuctionGetClaimableCB

func (c *AuctionClient) AuctionGetClaimableCB(
	claimAddress ethCommon.Address) (claimableCB *big.Int, err error)

AuctionGetClaimableCB is the interface to call the smart contract function

func (*AuctionClient) AuctionGetClosedAuctionSlots

func (c *AuctionClient) AuctionGetClosedAuctionSlots() (closedAuctionSlots uint16, err error)

AuctionGetClosedAuctionSlots is the interface to call the smart contract function

func (*AuctionClient) AuctionGetCurrentSlotNumber

func (c *AuctionClient) AuctionGetCurrentSlotNumber() (currentSlotNumber int64, err error)

AuctionGetCurrentSlotNumber is the interface to call the smart contract function

func (*AuctionClient) AuctionGetDefaultSlotSetBid

func (c *AuctionClient) AuctionGetDefaultSlotSetBid(slotSet uint8) (minBidSlotSet *big.Int,
	err error)

AuctionGetDefaultSlotSetBid is the interface to call the smart contract function

func (*AuctionClient) AuctionGetDonationAddress

func (c *AuctionClient) AuctionGetDonationAddress() (donationAddress *ethCommon.Address,
	err error)

AuctionGetDonationAddress is the interface to call the smart contract function

func (*AuctionClient) AuctionGetMinBidBySlot

func (c *AuctionClient) AuctionGetMinBidBySlot(slot int64) (minBid *big.Int, err error)

AuctionGetMinBidBySlot is the interface to call the smart contract function

func (*AuctionClient) AuctionGetOpenAuctionSlots

func (c *AuctionClient) AuctionGetOpenAuctionSlots() (openAuctionSlots uint16, err error)

AuctionGetOpenAuctionSlots is the interface to call the smart contract function

func (*AuctionClient) AuctionGetOutbidding

func (c *AuctionClient) AuctionGetOutbidding() (outbidding uint16, err error)

AuctionGetOutbidding is the interface to call the smart contract function

func (*AuctionClient) AuctionGetSlotDeadline

func (c *AuctionClient) AuctionGetSlotDeadline() (slotDeadline uint8, err error)

AuctionGetSlotDeadline is the interface to call the smart contract function

func (*AuctionClient) AuctionGetSlotNumber

func (c *AuctionClient) AuctionGetSlotNumber(blockNum int64) (slot int64, err error)

AuctionGetSlotNumber is the interface to call the smart contract function

func (*AuctionClient) AuctionGetSlotSet

func (c *AuctionClient) AuctionGetSlotSet(slot int64) (slotSet *big.Int, err error)

AuctionGetSlotSet is the interface to call the smart contract function

func (*AuctionClient) AuctionMultiBid

func (c *AuctionClient) AuctionMultiBid(amount *big.Int, startingSlot, endingSlot int64,
	slotSets [6]bool, maxBid, minBid, deadline *big.Int) (tx *types.Transaction, err error)

AuctionMultiBid is the interface to call the smart contract function

func (*AuctionClient) AuctionSetAllocationRatio

func (c *AuctionClient) AuctionSetAllocationRatio(
	newAllocationRatio [3]uint16) (tx *types.Transaction, err error)

AuctionSetAllocationRatio is the interface to call the smart contract function

func (*AuctionClient) AuctionSetBootCoordinator

func (c *AuctionClient) AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address,
	newBootCoordinatorURL string) (tx *types.Transaction, err error)

AuctionSetBootCoordinator is the interface to call the smart contract function

func (*AuctionClient) AuctionSetClosedAuctionSlots

func (c *AuctionClient) AuctionSetClosedAuctionSlots(
	newClosedAuctionSlots uint16) (tx *types.Transaction, err error)

AuctionSetClosedAuctionSlots is the interface to call the smart contract function

func (*AuctionClient) AuctionSetCoordinator

func (c *AuctionClient) AuctionSetCoordinator(forger ethCommon.Address,
	coordinatorURL string) (tx *types.Transaction, err error)

AuctionSetCoordinator is the interface to call the smart contract function

func (*AuctionClient) AuctionSetDonationAddress

func (c *AuctionClient) AuctionSetDonationAddress(
	newDonationAddress ethCommon.Address) (tx *types.Transaction, err error)

AuctionSetDonationAddress is the interface to call the smart contract function

func (*AuctionClient) AuctionSetOpenAuctionSlots

func (c *AuctionClient) AuctionSetOpenAuctionSlots(
	newOpenAuctionSlots uint16) (tx *types.Transaction, err error)

AuctionSetOpenAuctionSlots is the interface to call the smart contract function

func (*AuctionClient) AuctionSetOutbidding

func (c *AuctionClient) AuctionSetOutbidding(newOutbidding uint16) (tx *types.Transaction,
	err error)

AuctionSetOutbidding is the interface to call the smart contract function

func (*AuctionClient) AuctionSetSlotDeadline

func (c *AuctionClient) AuctionSetSlotDeadline(newDeadline uint8) (*types.Transaction, error)

AuctionSetSlotDeadline is the interface to call the smart contract function

func (*AuctionClient) AuctionVariables

func (c *AuctionClient) AuctionVariables() (auctionVariables *common.AuctionVariables, err error)

AuctionVariables returns the variables of the Auction Smart Contract

type AuctionEventCBClaimed

type AuctionEventCBClaimed struct {
	Owner  ethCommon.Address
	Amount *big.Int
}

AuctionEventCBClaimed is an event of the Auction Smart Contract

type AuctionEventInitialize

type AuctionEventInitialize struct {
	DonationAddress        ethCommon.Address
	BootCoordinatorAddress ethCommon.Address
	BootCoordinatorURL     string
	Outbidding             uint16
	SlotDeadline           uint8
	ClosedAuctionSlots     uint16
	OpenAuctionSlots       uint16
	AllocationRatio        [3]uint16
}

AuctionEventInitialize is the InitializeChainbingAuctionProtocolEvent event of the Smart Contract

func (*AuctionEventInitialize) AuctionVariables

func (ei *AuctionEventInitialize) AuctionVariables(
	InitialMinimalBidding *big.Int) *common.AuctionVariables

AuctionVariables returns the AuctionVariables from the initialize event

type AuctionEventNewAllocationRatio

type AuctionEventNewAllocationRatio struct {
	NewAllocationRatio [3]uint16
}

AuctionEventNewAllocationRatio is an event of the Auction Smart Contract

type AuctionEventNewBid

type AuctionEventNewBid struct {
	Slot      int64
	BidAmount *big.Int
	Bidder    ethCommon.Address
}

AuctionEventNewBid is an event of the Auction Smart Contract

type AuctionEventNewBootCoordinator

type AuctionEventNewBootCoordinator struct {
	NewBootCoordinator    ethCommon.Address
	NewBootCoordinatorURL string
}

AuctionEventNewBootCoordinator is an event of the Auction Smart Contract

type AuctionEventNewClosedAuctionSlots

type AuctionEventNewClosedAuctionSlots struct {
	NewClosedAuctionSlots uint16
}

AuctionEventNewClosedAuctionSlots is an event of the Auction Smart Contract

type AuctionEventNewDefaultSlotSetBid

type AuctionEventNewDefaultSlotSetBid struct {
	SlotSet          int64
	NewInitialMinBid *big.Int
}

AuctionEventNewDefaultSlotSetBid is an event of the Auction Smart Contract

type AuctionEventNewDonationAddress

type AuctionEventNewDonationAddress struct {
	NewDonationAddress ethCommon.Address
}

AuctionEventNewDonationAddress is an event of the Auction Smart Contract

type AuctionEventNewForge

type AuctionEventNewForge struct {
	Forger      ethCommon.Address
	SlotToForge int64
}

AuctionEventNewForge is an event of the Auction Smart Contract

type AuctionEventNewForgeAllocated

type AuctionEventNewForgeAllocated struct {
	Bidder           ethCommon.Address
	Forger           ethCommon.Address
	SlotToForge      int64
	BurnAmount       *big.Int
	DonationAmount   *big.Int
	GovernanceAmount *big.Int
}

AuctionEventNewForgeAllocated is an event of the Auction Smart Contract

type AuctionEventNewOpenAuctionSlots

type AuctionEventNewOpenAuctionSlots struct {
	NewOpenAuctionSlots uint16
}

AuctionEventNewOpenAuctionSlots is an event of the Auction Smart Contract

type AuctionEventNewOutbidding

type AuctionEventNewOutbidding struct {
	NewOutbidding uint16
}

AuctionEventNewOutbidding is an event of the Auction Smart Contract

type AuctionEventNewSlotDeadline

type AuctionEventNewSlotDeadline struct {
	NewSlotDeadline uint8
}

AuctionEventNewSlotDeadline is an event of the Auction Smart Contract

type AuctionEventSetCoordinator

type AuctionEventSetCoordinator struct {
	BidderAddress  ethCommon.Address
	ForgerAddress  ethCommon.Address
	CoordinatorURL string
}

AuctionEventSetCoordinator is an event of the Auction Smart Contract

type AuctionEvents

type AuctionEvents struct {
	NewBid                []AuctionEventNewBid
	NewSlotDeadline       []AuctionEventNewSlotDeadline
	NewClosedAuctionSlots []AuctionEventNewClosedAuctionSlots
	NewOutbidding         []AuctionEventNewOutbidding
	NewDonationAddress    []AuctionEventNewDonationAddress
	NewBootCoordinator    []AuctionEventNewBootCoordinator
	NewOpenAuctionSlots   []AuctionEventNewOpenAuctionSlots
	NewAllocationRatio    []AuctionEventNewAllocationRatio
	SetCoordinator        []AuctionEventSetCoordinator
	NewForgeAllocated     []AuctionEventNewForgeAllocated
	NewDefaultSlotSetBid  []AuctionEventNewDefaultSlotSetBid
	NewForge              []AuctionEventNewForge
	CBClaimed             []AuctionEventCBClaimed
}

AuctionEvents is the list of events in a block of the Auction Smart Contract

func NewAuctionEvents

func NewAuctionEvents() AuctionEvents

NewAuctionEvents creates an empty AuctionEvents with the slices initialized.

type AuctionInterface

type AuctionInterface interface {

	// Getter/Setter, where Setter is onlyOwner
	AuctionSetSlotDeadline(newDeadline uint8) (*types.Transaction, error)
	AuctionGetSlotDeadline() (uint8, error)
	AuctionSetOpenAuctionSlots(newOpenAuctionSlots uint16) (*types.Transaction, error)
	AuctionGetOpenAuctionSlots() (uint16, error)
	AuctionSetClosedAuctionSlots(newClosedAuctionSlots uint16) (*types.Transaction, error)
	AuctionGetClosedAuctionSlots() (uint16, error)
	AuctionSetOutbidding(newOutbidding uint16) (*types.Transaction, error)
	AuctionGetOutbidding() (uint16, error)
	AuctionSetAllocationRatio(newAllocationRatio [3]uint16) (*types.Transaction, error)
	AuctionGetAllocationRatio() ([3]uint16, error)
	AuctionSetDonationAddress(newDonationAddress ethCommon.Address) (*types.Transaction, error)
	AuctionGetDonationAddress() (*ethCommon.Address, error)
	AuctionSetBootCoordinator(newBootCoordinator ethCommon.Address,
		newBootCoordinatorURL string) (*types.Transaction, error)
	AuctionGetBootCoordinator() (*ethCommon.Address, error)
	AuctionChangeDefaultSlotSetBid(slotSet int64,
		newInitialMinBid *big.Int) (*types.Transaction, error)

	// Coordinator Management
	AuctionSetCoordinator(forger ethCommon.Address, coordinatorURL string) (*types.Transaction,
		error)

	// Slot Info
	AuctionGetSlotNumber(blockNum int64) (int64, error)
	AuctionGetCurrentSlotNumber() (int64, error)
	AuctionGetMinBidBySlot(slot int64) (*big.Int, error)
	AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error)
	AuctionGetSlotSet(slot int64) (*big.Int, error)

	// Bidding
	AuctionBid(amount *big.Int, slot int64, bidAmount *big.Int, deadline *big.Int) (
		tx *types.Transaction, err error)
	AuctionMultiBid(amount *big.Int, startingSlot, endingSlot int64, slotSets [6]bool,
		maxBid, minBid, deadline *big.Int) (tx *types.Transaction, err error)

	// Forge
	AuctionCanForge(forger ethCommon.Address, blockNum int64) (bool, error)
	AuctionForge(forger ethCommon.Address) (*types.Transaction, error)

	// Fees
	AuctionClaimCB() (*types.Transaction, error)
	AuctionGetClaimableCB(bidder ethCommon.Address) (*big.Int, error)

	AuctionConstants() (*common.AuctionConstants, error)
	AuctionEventsByBlock(blockNum int64, blockHash *ethCommon.Hash) (*AuctionEvents, error)
	AuctionEventInit(genesisBlockNum int64) (*AuctionEventInitialize, int64, error)
}

AuctionInterface is the inteface to to Auction Smart Contract

type AuctionState

type AuctionState struct {
	// Mapping to control slot state
	Slots map[int64]*SlotState
	// Mapping to control balances pending to claim
	PendingBalances map[ethCommon.Address]*big.Int
	// Mapping to register all the coordinators. The address used for the mapping is the forger address
	Coordinators map[ethCommon.Address]*Coordinator
}

AuctionState represents the state of the Rollup in the Smart Contract

type Client

type Client struct {
	EthereumClient
	AuctionClient
	RollupClient
	WDelayerClient
}

Client is used to interact with Ethereum and the Chainbing smart contracts.

func NewClient

func NewClient(client *ethclient.Client, account *accounts.Account, ks *ethKeystore.KeyStore,
	cfg *ClientConfig) (*Client, error)

NewClient creates a new Client to interact with Ethereum and the Chainbing smart contracts.

type ClientConfig

type ClientConfig struct {
	Ethereum EthereumConfig
	Rollup   RollupConfig
}

ClientConfig is the configuration of the Client

type ClientInterface

type ClientInterface interface {
	EthereumInterface
	RollupInterface
	AuctionInterface
	WDelayerInterface
}

ClientInterface is the eth Client interface used by node modules to interact with Ethereum Blockchain and smart contracts.

type ContractData

type ContractData struct {
	Address ethCommon.Address
	Tx      *types.Transaction
	Receipt *types.Receipt
}

ContractData contains the contract data

type Coordinator

type Coordinator struct {
	Forger ethCommon.Address
	URL    string
}

Coordinator is the details of the Coordinator identified by the forger address

type ERC20Consts

type ERC20Consts struct {
	Name     string
	Symbol   string
	Decimals uint64
}

ERC20Consts are the constants defined in a particular ERC20 Token instance

type EthereumClient

type EthereumClient struct {
	// contains filtered or unexported fields
}

EthereumClient is an ethereum client to call Smart Contract methods and check blockchain information.

func NewEthereumClient

func NewEthereumClient(client *ethclient.Client, account *accounts.Account,
	ks *ethKeystore.KeyStore, config *EthereumConfig) (*EthereumClient, error)

NewEthereumClient creates a EthereumClient instance. The account is not mandatory (it can be nil). If the account is nil, CallAuth will fail with ErrAccountNil.

func (*EthereumClient) Account

func (c *EthereumClient) Account() *accounts.Account

Account returns the underlying ethereum account

func (*EthereumClient) BalanceAt

func (c *EthereumClient) BalanceAt(addr ethCommon.Address) (*big.Int, error)

BalanceAt retieves information about the default account

func (*EthereumClient) Call

func (c *EthereumClient) Call(fn func(*ethclient.Client) error) error

Call performs a read only Smart Contract method call.

func (*EthereumClient) CallAuth

func (c *EthereumClient) CallAuth(gasLimit uint64, fn func(*ethclient.Client, *bind.TransactOpts) (*types.Transaction, error)) (*types.Transaction,
	error)

CallAuth performs a Smart Contract method call that requires authorization. This call requires a valid account with Ether that can be spend during the call.

func (*EthereumClient) Client

func (c *EthereumClient) Client() *ethclient.Client

Client returns the internal ethclient.Client

func (*EthereumClient) EthAddress

func (c *EthereumClient) EthAddress() (*ethCommon.Address, error)

EthAddress returns the ethereum address of the account loaded into the EthereumClient

func (*EthereumClient) EthBlockByNumber

func (c *EthereumClient) EthBlockByNumber(ctx context.Context, number int64) (*common.Block,
	error)

EthBlockByNumber internally calls ethclient.Client BlockByNumber and returns *common.Block. If number == -1, the latests known block is returned.

func (*EthereumClient) EthCall

func (c *EthereumClient) EthCall(ctx context.Context, tx *types.Transaction,
	blockNum *big.Int) ([]byte, error)

EthCall runs the transaction as a call (without paying) in the local node at blockNum.

func (*EthereumClient) EthChainID

func (c *EthereumClient) EthChainID() (*big.Int, error)

EthChainID returns the ChainID of the ethereum network

func (*EthereumClient) EthERC20Consts

func (c *EthereumClient) EthERC20Consts(tokenAddress ethCommon.Address) (*ERC20Consts, error)

EthERC20Consts returns the constants defined for a particular ERC20 Token instance.

func (*EthereumClient) EthKeyStore

func (c *EthereumClient) EthKeyStore() *ethKeystore.KeyStore

EthKeyStore returns the keystore in the EthereumClient

func (*EthereumClient) EthLastBlock

func (c *EthereumClient) EthLastBlock() (int64, error)

EthLastBlock returns the last block number in the blockchain

func (*EthereumClient) EthNonceAt

func (c *EthereumClient) EthNonceAt(ctx context.Context,
	account ethCommon.Address, blockNumber *big.Int) (uint64, error)

EthNonceAt returns the account nonce of the given account. The block number can be nil, in which case the nonce is taken from the latest known block.

func (*EthereumClient) EthPendingNonceAt

func (c *EthereumClient) EthPendingNonceAt(ctx context.Context,
	account ethCommon.Address) (uint64, error)

EthPendingNonceAt returns the account nonce of the given account in the pending state. This is the nonce that should be used for the next transaction.

func (*EthereumClient) EthSuggestGasPrice

func (c *EthereumClient) EthSuggestGasPrice(ctx context.Context) (gasPrice *big.Int, err error)

EthSuggestGasPrice retrieves the currently suggested gas price to allow a timely execution of a transaction.

func (*EthereumClient) EthTransactionReceipt

func (c *EthereumClient) EthTransactionReceipt(ctx context.Context,
	txHash ethCommon.Hash) (*types.Receipt, error)

EthTransactionReceipt returns the transaction receipt of the given txHash

func (*EthereumClient) NewAuth

func (c *EthereumClient) NewAuth() (*bind.TransactOpts, error)

NewAuth builds a new auth object to make a transaction

type EthereumConfig

type EthereumConfig struct {
	CallGasLimit uint64
	GasPriceDiv  uint64
}

EthereumConfig defines the configuration parameters of the EthereumClient

type EthereumInterface

type EthereumInterface interface {
	EthLastBlock() (int64, error)
	// EthHeaderByNumber(context.Context, *big.Int) (*types.Header, error)
	EthBlockByNumber(context.Context, int64) (*common.Block, error)
	EthAddress() (*ethCommon.Address, error)
	EthTransactionReceipt(context.Context, ethCommon.Hash) (*types.Receipt, error)

	EthERC20Consts(ethCommon.Address) (*ERC20Consts, error)
	EthChainID() (*big.Int, error)

	EthPendingNonceAt(ctx context.Context, account ethCommon.Address) (uint64, error)
	EthNonceAt(ctx context.Context, account ethCommon.Address, blockNumber *big.Int) (uint64, error)
	EthSuggestGasPrice(ctx context.Context) (*big.Int, error)
	EthKeyStore() *ethKeystore.KeyStore
	EthCall(ctx context.Context, tx *types.Transaction, blockNum *big.Int) ([]byte, error)
}

EthereumInterface is the interface to Ethereum

type RollupConfig

type RollupConfig struct {
	Address ethCommon.Address
}

RollupConfig is the configuration for the Rollup smart contract interface

type SlotState

type SlotState struct {
	Bidder           ethCommon.Address
	ForgerCommitment bool
	Fulfilled        bool
	BidAmount        *big.Int
	ClosedMinBid     *big.Int
}

SlotState is the state of a slot

func NewSlotState

func NewSlotState() *SlotState

NewSlotState returns an empty SlotState

Directories

Path Synopsis
contracts

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL