depositcontract

package
v0.0.0-...-c85edb6 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2019 License: GPL-3.0 Imports: 10 Imported by: 0

README

Deposit Contract

A validator will deposit 32 ETH to the deposit contract. The contract will generate a log showing the validator as a qualified validator. The deposit is considered to be burned. As you burn the 32 ETH to participate, the beacon chain will see it and will credit the validator with the validator bond, At some point in the future, after a hard fork, the original deposit + interest can be withdrawn back on one of the shards.
To call the registration function, it takes arguments of pubkey, proof_of_possession, withdrawal_credentials and randao_commitment. If the user wants to deposit more than DEPOSIT_SIZE ETH, they would need to make multiple deposit calls.
When the contract publishes the ChainStart log, beacon nodes will start off the beacon chain with slot 0 and last recorded block.timestamp as beacon chain genesis time. The registration contract generate logs with the various arguments for consumption by beacon nodes. It does not validate proof_of_possession and withdrawal_credentials, pushing the validation logic to the beacon chain.

How to generate bindings for vyper contract

This requires that you have vyper and abigen installed in your local machine. Vyper: https://github.com/ethereum/vyper Abigen: https://github.com/ethereum/go-ethereum/tree/master/cmd/abigen

To generate the abi using the vyper compiler, you can use


vyper -f abi  ./depositContract.v.py

Then the abi will be outputted and you can save it in abi.json in the folder.

To generate the bytecode you can then use


vyper  ./depositContract.v.py

and save the bytecode in bytecode.bin in the folder. Now with both the abi and bytecode we can generate the go bindings.

abigen -bin ./bytecode.bin -abi ./abi.json -out ./depositContract.go --pkg depositContract

How to execute tests

go test ./...

Run with -v option for detailed log output

go test ./... -v
=== RUN   TestSetupAndContractRegistration
--- PASS: TestSetupAndContractRegistration (0.01s)
=== RUN   TestRegisterWithLessThan32Eth
--- PASS: TestRegisterWithLessThan32Eth (0.00s)
=== RUN   TestRegisterWithMoreThan32Eth
--- PASS: TestRegisterWithMoreThan32Eth (0.00s)
=== RUN   TestRegisterTwice
--- PASS: TestRegisterTwice (0.01s)
=== RUN   TestRegister
--- PASS: TestRegister (0.01s)
PASS
ok      beacon-chain/contracts/deposit-contract/  0.151s

Documentation

Index

Constants

View Source
const DepositContractABI = "" /* 1295-byte string literal not displayed */

DepositContractABI is the input ABI used to generate the binding from.

View Source
const DepositContractBin = `` /* 18004-byte string literal not displayed */

DepositContractBin is the compiled bytecode used for deploying new contracts.

Variables

This section is empty.

Functions

func UnpackChainStartLogData

func UnpackChainStartLogData(data []byte) (depositRoot [32]byte, timestamp []byte, err error)

UnpackChainStartLogData unpacks the data from a chain start log using the ABI decoder.

func UnpackDepositLogData

func UnpackDepositLogData(data []byte) (depositRoot [32]byte, depositData []byte, merkleTreeIndex []byte, err error)

UnpackDepositLogData unpacks the data from a deposit log using the ABI decoder.

Types

type DepositContract

type DepositContract struct {
	DepositContractCaller     // Read-only binding to the contract
	DepositContractTransactor // Write-only binding to the contract
	DepositContractFilterer   // Log filterer for contract events
}

DepositContract is an auto generated Go binding around an Ethereum contract.

func DeployDepositContract

func DeployDepositContract(auth *bind.TransactOpts, backend bind.ContractBackend, depositThreshold *big.Int, minDeposit *big.Int, maxDeposit *big.Int) (common.Address, *types.Transaction, *DepositContract, error)

DeployDepositContract deploys a new Ethereum contract, binding an instance of DepositContract to it.

func NewDepositContract

func NewDepositContract(address common.Address, backend bind.ContractBackend) (*DepositContract, error)

NewDepositContract creates a new instance of DepositContract, bound to a specific deployed contract.

type DepositContractCaller

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

DepositContractCaller is an auto generated read-only Go binding around an Ethereum contract.

func NewDepositContractCaller

func NewDepositContractCaller(address common.Address, caller bind.ContractCaller) (*DepositContractCaller, error)

NewDepositContractCaller creates a new read-only instance of DepositContract, bound to a specific deployed contract.

func (*DepositContractCaller) GetBranch

func (_DepositContract *DepositContractCaller) GetBranch(opts *bind.CallOpts, leaf *big.Int) ([32][32]byte, error)

GetBranch is a free data retrieval call binding the contract method 0x118e4575.

Solidity: function get_branch(uint256 leaf) constant returns(bytes32[32] out)

func (*DepositContractCaller) GetDepositRoot

func (_DepositContract *DepositContractCaller) GetDepositRoot(opts *bind.CallOpts) ([32]byte, error)

GetDepositRoot is a free data retrieval call binding the contract method 0xc5f2892f.

Solidity: function get_deposit_root() constant returns(bytes32 out)

type DepositContractCallerRaw

type DepositContractCallerRaw struct {
	Contract *DepositContractCaller // Generic read-only contract binding to access the raw methods on
}

DepositContractCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.

func (*DepositContractCallerRaw) Call

func (_DepositContract *DepositContractCallerRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error

Call invokes the (constant) contract method with params as input values and sets the output to result. The result type might be a single field for simple returns, a slice of interfaces for anonymous returns and a struct for named returns.

type DepositContractCallerSession

type DepositContractCallerSession struct {
	Contract *DepositContractCaller // Generic contract caller binding to set the session for
	CallOpts bind.CallOpts          // Call options to use throughout this session
}

DepositContractCallerSession is an auto generated read-only Go binding around an Ethereum contract, with pre-set call options.

func (*DepositContractCallerSession) GetBranch

func (_DepositContract *DepositContractCallerSession) GetBranch(leaf *big.Int) ([32][32]byte, error)

GetBranch is a free data retrieval call binding the contract method 0x118e4575.

Solidity: function get_branch(uint256 leaf) constant returns(bytes32[32] out)

func (*DepositContractCallerSession) GetDepositRoot

func (_DepositContract *DepositContractCallerSession) GetDepositRoot() ([32]byte, error)

GetDepositRoot is a free data retrieval call binding the contract method 0xc5f2892f.

Solidity: function get_deposit_root() constant returns(bytes32 out)

type DepositContractChainStart

type DepositContractChainStart struct {
	DepositRoot [32]byte
	Time        []byte
	Raw         types.Log // Blockchain specific contextual infos
}

DepositContractChainStart represents a ChainStart event raised by the DepositContract contract.

type DepositContractChainStartIterator

type DepositContractChainStartIterator struct {
	Event *DepositContractChainStart // Event containing the contract specifics and raw log
	// contains filtered or unexported fields
}

DepositContractChainStartIterator is returned from FilterChainStart and is used to iterate over the raw logs and unpacked data for ChainStart events raised by the DepositContract contract.

func (*DepositContractChainStartIterator) Close

Close terminates the iteration process, releasing any pending underlying resources.

func (*DepositContractChainStartIterator) Error

Error returns any retrieval or parsing error occurred during filtering.

func (*DepositContractChainStartIterator) Next

Next advances the iterator to the subsequent event, returning whether there are any more events found. In case of a retrieval or parsing error, false is returned and Error() can be queried for the exact failure.

type DepositContractDeposit

type DepositContractDeposit struct {
	PreviousDepositRoot [32]byte
	Data                []byte
	MerkleTreeIndex     []byte
	Raw                 types.Log // Blockchain specific contextual infos
}

DepositContractDeposit represents a Deposit event raised by the DepositContract contract.

type DepositContractDepositIterator

type DepositContractDepositIterator struct {
	Event *DepositContractDeposit // Event containing the contract specifics and raw log
	// contains filtered or unexported fields
}

DepositContractDepositIterator is returned from FilterDeposit and is used to iterate over the raw logs and unpacked data for Deposit events raised by the DepositContract contract.

func (*DepositContractDepositIterator) Close

Close terminates the iteration process, releasing any pending underlying resources.

func (*DepositContractDepositIterator) Error

Error returns any retrieval or parsing error occurred during filtering.

func (*DepositContractDepositIterator) Next

Next advances the iterator to the subsequent event, returning whether there are any more events found. In case of a retrieval or parsing error, false is returned and Error() can be queried for the exact failure.

type DepositContractFilterer

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

DepositContractFilterer is an auto generated log filtering Go binding around an Ethereum contract events.

func NewDepositContractFilterer

func NewDepositContractFilterer(address common.Address, filterer bind.ContractFilterer) (*DepositContractFilterer, error)

NewDepositContractFilterer creates a new log filterer instance of DepositContract, bound to a specific deployed contract.

func (*DepositContractFilterer) FilterChainStart

func (_DepositContract *DepositContractFilterer) FilterChainStart(opts *bind.FilterOpts) (*DepositContractChainStartIterator, error)

FilterChainStart is a free log retrieval operation binding the contract event 0xd1faa3f9bca1d698df559716fe6d1c9999155b38d3158fffbc98d76d568091fc.

Solidity: event ChainStart(bytes32 deposit_root, bytes time)

func (*DepositContractFilterer) FilterDeposit

func (_DepositContract *DepositContractFilterer) FilterDeposit(opts *bind.FilterOpts) (*DepositContractDepositIterator, error)

FilterDeposit is a free log retrieval operation binding the contract event 0xfef24b0e170d72eb566899dc3a6d4396d901ceb46442d0b04f22e5fc8ec3c611.

Solidity: event Deposit(bytes32 previous_deposit_root, bytes data, bytes merkle_tree_index)

func (*DepositContractFilterer) WatchChainStart

func (_DepositContract *DepositContractFilterer) WatchChainStart(opts *bind.WatchOpts, sink chan<- *DepositContractChainStart) (event.Subscription, error)

WatchChainStart is a free log subscription operation binding the contract event 0xd1faa3f9bca1d698df559716fe6d1c9999155b38d3158fffbc98d76d568091fc.

Solidity: event ChainStart(bytes32 deposit_root, bytes time)

func (*DepositContractFilterer) WatchDeposit

func (_DepositContract *DepositContractFilterer) WatchDeposit(opts *bind.WatchOpts, sink chan<- *DepositContractDeposit) (event.Subscription, error)

WatchDeposit is a free log subscription operation binding the contract event 0xfef24b0e170d72eb566899dc3a6d4396d901ceb46442d0b04f22e5fc8ec3c611.

Solidity: event Deposit(bytes32 previous_deposit_root, bytes data, bytes merkle_tree_index)

type DepositContractRaw

type DepositContractRaw struct {
	Contract *DepositContract // Generic contract binding to access the raw methods on
}

DepositContractRaw is an auto generated low-level Go binding around an Ethereum contract.

func (*DepositContractRaw) Call

func (_DepositContract *DepositContractRaw) Call(opts *bind.CallOpts, result interface{}, method string, params ...interface{}) error

Call invokes the (constant) contract method with params as input values and sets the output to result. The result type might be a single field for simple returns, a slice of interfaces for anonymous returns and a struct for named returns.

func (*DepositContractRaw) Transact

func (_DepositContract *DepositContractRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error)

Transact invokes the (paid) contract method with params as input values.

func (*DepositContractRaw) Transfer

func (_DepositContract *DepositContractRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error)

Transfer initiates a plain transaction to move funds to the contract, calling its default method if one is available.

type DepositContractSession

type DepositContractSession struct {
	Contract     *DepositContract  // Generic contract binding to set the session for
	CallOpts     bind.CallOpts     // Call options to use throughout this session
	TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}

DepositContractSession is an auto generated Go binding around an Ethereum contract, with pre-set call and transact options.

func (*DepositContractSession) Deposit

func (_DepositContract *DepositContractSession) Deposit(deposit_input []byte) (*types.Transaction, error)

Deposit is a paid mutator transaction binding the contract method 0x98b1e06a.

Solidity: function deposit(bytes deposit_input) returns()

func (*DepositContractSession) GetBranch

func (_DepositContract *DepositContractSession) GetBranch(leaf *big.Int) ([32][32]byte, error)

GetBranch is a free data retrieval call binding the contract method 0x118e4575.

Solidity: function get_branch(uint256 leaf) constant returns(bytes32[32] out)

func (*DepositContractSession) GetDepositRoot

func (_DepositContract *DepositContractSession) GetDepositRoot() ([32]byte, error)

GetDepositRoot is a free data retrieval call binding the contract method 0xc5f2892f.

Solidity: function get_deposit_root() constant returns(bytes32 out)

type DepositContractTransactor

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

DepositContractTransactor is an auto generated write-only Go binding around an Ethereum contract.

func NewDepositContractTransactor

func NewDepositContractTransactor(address common.Address, transactor bind.ContractTransactor) (*DepositContractTransactor, error)

NewDepositContractTransactor creates a new write-only instance of DepositContract, bound to a specific deployed contract.

func (*DepositContractTransactor) Deposit

func (_DepositContract *DepositContractTransactor) Deposit(opts *bind.TransactOpts, deposit_input []byte) (*types.Transaction, error)

Deposit is a paid mutator transaction binding the contract method 0x98b1e06a.

Solidity: function deposit(bytes deposit_input) returns()

type DepositContractTransactorRaw

type DepositContractTransactorRaw struct {
	Contract *DepositContractTransactor // Generic write-only contract binding to access the raw methods on
}

DepositContractTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.

func (*DepositContractTransactorRaw) Transact

func (_DepositContract *DepositContractTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error)

Transact invokes the (paid) contract method with params as input values.

func (*DepositContractTransactorRaw) Transfer

func (_DepositContract *DepositContractTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error)

Transfer initiates a plain transaction to move funds to the contract, calling its default method if one is available.

type DepositContractTransactorSession

type DepositContractTransactorSession struct {
	Contract     *DepositContractTransactor // Generic contract transactor binding to set the session for
	TransactOpts bind.TransactOpts          // Transaction auth options to use throughout this session
}

DepositContractTransactorSession is an auto generated write-only Go binding around an Ethereum contract, with pre-set transact options.

func (*DepositContractTransactorSession) Deposit

func (_DepositContract *DepositContractTransactorSession) Deposit(deposit_input []byte) (*types.Transaction, error)

Deposit is a paid mutator transaction binding the contract method 0x98b1e06a.

Solidity: function deposit(bytes deposit_input) returns()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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