@ -32,80 +32,80 @@ type EthereumClient struct {
}
}
// NewEthereumClient connects a client to the given URL.
// NewEthereumClient connects a client to the given URL.
func NewEthereumClient ( rawurl string ) ( * EthereumClient , error ) {
func NewEthereumClient ( rawurl string ) ( client * EthereumClient , _ error ) {
c lient, err := ethclient . Dial ( rawurl )
rawC lient, err := ethclient . Dial ( rawurl )
return & EthereumClient { c lient} , err
return & EthereumClient { rawC lient} , err
}
}
// GetBlockByHash returns the given full block.
// GetBlockByHash returns the given full block.
func ( ec * EthereumClient ) GetBlockByHash ( ctx * Context , hash * Hash ) ( * Block , error ) {
func ( ec * EthereumClient ) GetBlockByHash ( ctx * Context , hash * Hash ) ( block * Block , _ error ) {
b lock, err := ec . client . BlockByHash ( ctx . context , hash . hash )
rawB lock, err := ec . client . BlockByHash ( ctx . context , hash . hash )
return & Block { b lock} , err
return & Block { rawB lock} , err
}
}
// GetBlockByNumber returns a block from the current canonical chain. If number is <0, the
// GetBlockByNumber returns a block from the current canonical chain. If number is <0, the
// latest known block is returned.
// latest known block is returned.
func ( ec * EthereumClient ) GetBlockByNumber ( ctx * Context , number int64 ) ( * Block , error ) {
func ( ec * EthereumClient ) GetBlockByNumber ( ctx * Context , number int64 ) ( block * Block , _ error ) {
if number < 0 {
if number < 0 {
b lock, err := ec . client . BlockByNumber ( ctx . context , nil )
rawB lock, err := ec . client . BlockByNumber ( ctx . context , nil )
return & Block { b lock} , err
return & Block { rawB lock} , err
}
}
b lock, err := ec . client . BlockByNumber ( ctx . context , big . NewInt ( number ) )
rawB lock, err := ec . client . BlockByNumber ( ctx . context , big . NewInt ( number ) )
return & Block { b lock} , err
return & Block { rawB lock} , err
}
}
// GetHeaderByHash returns the block header with the given hash.
// GetHeaderByHash returns the block header with the given hash.
func ( ec * EthereumClient ) GetHeaderByHash ( ctx * Context , hash * Hash ) ( * Header , error ) {
func ( ec * EthereumClient ) GetHeaderByHash ( ctx * Context , hash * Hash ) ( header * Header , _ error ) {
h eader, err := ec . client . HeaderByHash ( ctx . context , hash . hash )
rawH eader, err := ec . client . HeaderByHash ( ctx . context , hash . hash )
return & Header { h eader} , err
return & Header { rawH eader} , err
}
}
// GetHeaderByNumber returns a block header from the current canonical chain. If number is <0,
// GetHeaderByNumber returns a block header from the current canonical chain. If number is <0,
// the latest known header is returned.
// the latest known header is returned.
func ( ec * EthereumClient ) GetHeaderByNumber ( ctx * Context , number int64 ) ( * Header , error ) {
func ( ec * EthereumClient ) GetHeaderByNumber ( ctx * Context , number int64 ) ( header * Header , _ error ) {
if number < 0 {
if number < 0 {
h eader, err := ec . client . HeaderByNumber ( ctx . context , nil )
rawH eader, err := ec . client . HeaderByNumber ( ctx . context , nil )
return & Header { h eader} , err
return & Header { rawH eader} , err
}
}
h eader, err := ec . client . HeaderByNumber ( ctx . context , big . NewInt ( number ) )
rawH eader, err := ec . client . HeaderByNumber ( ctx . context , big . NewInt ( number ) )
return & Header { h eader} , err
return & Header { rawH eader} , err
}
}
// GetTransactionByHash returns the transaction with the given hash.
// GetTransactionByHash returns the transaction with the given hash.
func ( ec * EthereumClient ) GetTransactionByHash ( ctx * Context , hash * Hash ) ( * Transaction , error ) {
func ( ec * EthereumClient ) GetTransactionByHash ( ctx * Context , hash * Hash ) ( tx * Transaction , _ error ) {
// TODO(karalabe): handle isPending
// TODO(karalabe): handle isPending
t x, _ , err := ec . client . TransactionByHash ( ctx . context , hash . hash )
rawT x, _ , err := ec . client . TransactionByHash ( ctx . context , hash . hash )
return & Transaction { t x} , err
return & Transaction { rawT x} , err
}
}
// GetTransactionCount returns the total number of transactions in the given block.
// GetTransactionCount returns the total number of transactions in the given block.
func ( ec * EthereumClient ) GetTransactionCount ( ctx * Context , hash * Hash ) ( int , error ) {
func ( ec * EthereumClient ) GetTransactionCount ( ctx * Context , hash * Hash ) ( count int , _ error ) {
c ount, err := ec . client . TransactionCount ( ctx . context , hash . hash )
rawC ount, err := ec . client . TransactionCount ( ctx . context , hash . hash )
return int ( c ount) , err
return int ( rawC ount) , err
}
}
// GetTransactionInBlock returns a single transaction at index in the given block.
// GetTransactionInBlock returns a single transaction at index in the given block.
func ( ec * EthereumClient ) GetTransactionInBlock ( ctx * Context , hash * Hash , index int ) ( * Transaction , error ) {
func ( ec * EthereumClient ) GetTransactionInBlock ( ctx * Context , hash * Hash , index int ) ( tx * Transaction , _ error ) {
t x, err := ec . client . TransactionInBlock ( ctx . context , hash . hash , uint ( index ) )
rawT x, err := ec . client . TransactionInBlock ( ctx . context , hash . hash , uint ( index ) )
return & Transaction { t x} , err
return & Transaction { rawT x} , err
}
}
// GetTransactionReceipt returns the receipt of a transaction by transaction hash.
// GetTransactionReceipt returns the receipt of a transaction by transaction hash.
// Note that the receipt is not available for pending transactions.
// Note that the receipt is not available for pending transactions.
func ( ec * EthereumClient ) GetTransactionReceipt ( ctx * Context , hash * Hash ) ( * Receipt , error ) {
func ( ec * EthereumClient ) GetTransactionReceipt ( ctx * Context , hash * Hash ) ( receipt * Receipt , _ error ) {
receipt , err := ec . client . TransactionReceipt ( ctx . context , hash . hash )
rawR eceipt , err := ec . client . TransactionReceipt ( ctx . context , hash . hash )
return & Receipt { receipt } , err
return & Receipt { rawR eceipt } , err
}
}
// SyncProgress retrieves the current progress of the sync algorithm. If there's
// SyncProgress retrieves the current progress of the sync algorithm. If there's
// no sync currently running, it returns nil.
// no sync currently running, it returns nil.
func ( ec * EthereumClient ) SyncProgress ( ctx * Context ) ( * SyncProgress , error ) {
func ( ec * EthereumClient ) SyncProgress ( ctx * Context ) ( progress * SyncProgress , _ error ) {
p rogress, err := ec . client . SyncProgress ( ctx . context )
rawP rogress, err := ec . client . SyncProgress ( ctx . context )
if p rogress == nil {
if rawP rogress == nil {
return nil , err
return nil , err
}
}
return & SyncProgress { * p rogress} , err
return & SyncProgress { * rawP rogress} , err
}
}
// NewHeadHandler is a client-side subscription callback to invoke on events and
// NewHeadHandler is a client-side subscription callback to invoke on events and
@ -117,10 +117,10 @@ type NewHeadHandler interface {
// SubscribeNewHead subscribes to notifications about the current blockchain head
// SubscribeNewHead subscribes to notifications about the current blockchain head
// on the given channel.
// on the given channel.
func ( ec * EthereumClient ) SubscribeNewHead ( ctx * Context , handler NewHeadHandler , buffer int ) ( * Subscription , error ) {
func ( ec * EthereumClient ) SubscribeNewHead ( ctx * Context , handler NewHeadHandler , buffer int ) ( sub * Subscription , _ error ) {
// Subscribe to the event internally
// Subscribe to the event internally
ch := make ( chan * types . Header , buffer )
ch := make ( chan * types . Header , buffer )
s ub, err := ec . client . SubscribeNewHead ( ctx . context , ch )
rawS ub, err := ec . client . SubscribeNewHead ( ctx . context , ch )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -131,31 +131,31 @@ func (ec *EthereumClient) SubscribeNewHead(ctx *Context, handler NewHeadHandler,
case header := <- ch :
case header := <- ch :
handler . OnNewHead ( & Header { header } )
handler . OnNewHead ( & Header { header } )
case err := <- s ub. Err ( ) :
case err := <- rawS ub. Err ( ) :
handler . OnError ( err . Error ( ) )
handler . OnError ( err . Error ( ) )
return
return
}
}
}
}
} ( )
} ( )
return & Subscription { s ub} , nil
return & Subscription { rawS ub} , nil
}
}
// State Access
// State Access
// GetBalanceAt returns the wei balance of the given account.
// GetBalanceAt returns the wei balance of the given account.
// The block number can be <0, in which case the balance is taken from the latest known block.
// The block number can be <0, in which case the balance is taken from the latest known block.
func ( ec * EthereumClient ) GetBalanceAt ( ctx * Context , account * Address , number int64 ) ( * BigInt , error ) {
func ( ec * EthereumClient ) GetBalanceAt ( ctx * Context , account * Address , number int64 ) ( balance * BigInt , _ error ) {
if number < 0 {
if number < 0 {
b alance, err := ec . client . BalanceAt ( ctx . context , account . address , nil )
rawB alance, err := ec . client . BalanceAt ( ctx . context , account . address , nil )
return & BigInt { b alance} , err
return & BigInt { rawB alance} , err
}
}
b alance, err := ec . client . BalanceAt ( ctx . context , account . address , big . NewInt ( number ) )
rawB alance, err := ec . client . BalanceAt ( ctx . context , account . address , big . NewInt ( number ) )
return & BigInt { b alance} , err
return & BigInt { rawB alance} , err
}
}
// GetStorageAt returns the value of key in the contract storage of the given account.
// GetStorageAt returns the value of key in the contract storage of the given account.
// The block number can be <0, in which case the value is taken from the latest known block.
// The block number can be <0, in which case the value is taken from the latest known block.
func ( ec * EthereumClient ) GetStorageAt ( ctx * Context , account * Address , key * Hash , number int64 ) ( [ ] byte , error ) {
func ( ec * EthereumClient ) GetStorageAt ( ctx * Context , account * Address , key * Hash , number int64 ) ( storage [ ] byte , _ error ) {
if number < 0 {
if number < 0 {
return ec . client . StorageAt ( ctx . context , account . address , key . hash , nil )
return ec . client . StorageAt ( ctx . context , account . address , key . hash , nil )
}
}
@ -164,7 +164,7 @@ func (ec *EthereumClient) GetStorageAt(ctx *Context, account *Address, key *Hash
// GetCodeAt returns the contract code of the given account.
// GetCodeAt returns the contract code of the given account.
// The block number can be <0, in which case the code is taken from the latest known block.
// The block number can be <0, in which case the code is taken from the latest known block.
func ( ec * EthereumClient ) GetCodeAt ( ctx * Context , account * Address , number int64 ) ( [ ] byte , error ) {
func ( ec * EthereumClient ) GetCodeAt ( ctx * Context , account * Address , number int64 ) ( code [ ] byte , _ error ) {
if number < 0 {
if number < 0 {
return ec . client . CodeAt ( ctx . context , account . address , nil )
return ec . client . CodeAt ( ctx . context , account . address , nil )
}
}
@ -173,26 +173,26 @@ func (ec *EthereumClient) GetCodeAt(ctx *Context, account *Address, number int64
// GetNonceAt returns the account nonce of the given account.
// GetNonceAt returns the account nonce of the given account.
// The block number can be <0, in which case the nonce is taken from the latest known block.
// The block number can be <0, in which case the nonce is taken from the latest known block.
func ( ec * EthereumClient ) GetNonceAt ( ctx * Context , account * Address , number int64 ) ( int64 , error ) {
func ( ec * EthereumClient ) GetNonceAt ( ctx * Context , account * Address , number int64 ) ( nonce int64 , _ error ) {
if number < 0 {
if number < 0 {
n once, err := ec . client . NonceAt ( ctx . context , account . address , nil )
rawN once, err := ec . client . NonceAt ( ctx . context , account . address , nil )
return int64 ( n once) , err
return int64 ( rawN once) , err
}
}
n once, err := ec . client . NonceAt ( ctx . context , account . address , big . NewInt ( number ) )
rawN once, err := ec . client . NonceAt ( ctx . context , account . address , big . NewInt ( number ) )
return int64 ( n once) , err
return int64 ( rawN once) , err
}
}
// Filters
// Filters
// FilterLogs executes a filter query.
// FilterLogs executes a filter query.
func ( ec * EthereumClient ) FilterLogs ( ctx * Context , query * FilterQuery ) ( * Logs , error ) {
func ( ec * EthereumClient ) FilterLogs ( ctx * Context , query * FilterQuery ) ( logs * Logs , _ error ) {
l ogs, err := ec . client . FilterLogs ( ctx . context , query . query )
rawL ogs, err := ec . client . FilterLogs ( ctx . context , query . query )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
// Temp hack due to vm.Logs being []*vm.Log
// Temp hack due to vm.Logs being []*vm.Log
res := make ( vm . Logs , len ( l ogs) )
res := make ( vm . Logs , len ( rawL ogs) )
for i , log := range l ogs {
for i , log := range rawL ogs {
res [ i ] = & log
res [ i ] = & log
}
}
return & Logs { res } , nil
return & Logs { res } , nil
@ -206,10 +206,10 @@ type FilterLogsHandler interface {
}
}
// SubscribeFilterLogs subscribes to the results of a streaming filter query.
// SubscribeFilterLogs subscribes to the results of a streaming filter query.
func ( ec * EthereumClient ) SubscribeFilterLogs ( ctx * Context , query * FilterQuery , handler FilterLogsHandler , buffer int ) ( * Subscription , error ) {
func ( ec * EthereumClient ) SubscribeFilterLogs ( ctx * Context , query * FilterQuery , handler FilterLogsHandler , buffer int ) ( sub * Subscription , _ error ) {
// Subscribe to the event internally
// Subscribe to the event internally
ch := make ( chan vm . Log , buffer )
ch := make ( chan vm . Log , buffer )
s ub, err := ec . client . SubscribeFilterLogs ( ctx . context , query . query , ch )
rawS ub, err := ec . client . SubscribeFilterLogs ( ctx . context , query . query , ch )
if err != nil {
if err != nil {
return nil , err
return nil , err
}
}
@ -220,44 +220,44 @@ func (ec *EthereumClient) SubscribeFilterLogs(ctx *Context, query *FilterQuery,
case log := <- ch :
case log := <- ch :
handler . OnFilterLogs ( & Log { & log } )
handler . OnFilterLogs ( & Log { & log } )
case err := <- s ub. Err ( ) :
case err := <- rawS ub. Err ( ) :
handler . OnError ( err . Error ( ) )
handler . OnError ( err . Error ( ) )
return
return
}
}
}
}
} ( )
} ( )
return & Subscription { s ub} , nil
return & Subscription { rawS ub} , nil
}
}
// Pending State
// Pending State
// GetPendingBalanceAt returns the wei balance of the given account in the pending state.
// GetPendingBalanceAt returns the wei balance of the given account in the pending state.
func ( ec * EthereumClient ) GetPendingBalanceAt ( ctx * Context , account * Address ) ( * BigInt , error ) {
func ( ec * EthereumClient ) GetPendingBalanceAt ( ctx * Context , account * Address ) ( balance * BigInt , _ error ) {
b alance, err := ec . client . PendingBalanceAt ( ctx . context , account . address )
rawB alance, err := ec . client . PendingBalanceAt ( ctx . context , account . address )
return & BigInt { b alance} , err
return & BigInt { rawB alance} , err
}
}
// GetPendingStorageAt returns the value of key in the contract storage of the given account in the pending state.
// GetPendingStorageAt returns the value of key in the contract storage of the given account in the pending state.
func ( ec * EthereumClient ) GetPendingStorageAt ( ctx * Context , account * Address , key * Hash ) ( [ ] byte , error ) {
func ( ec * EthereumClient ) GetPendingStorageAt ( ctx * Context , account * Address , key * Hash ) ( storage [ ] byte , _ error ) {
return ec . client . PendingStorageAt ( ctx . context , account . address , key . hash )
return ec . client . PendingStorageAt ( ctx . context , account . address , key . hash )
}
}
// GetPendingCodeAt returns the contract code of the given account in the pending state.
// GetPendingCodeAt returns the contract code of the given account in the pending state.
func ( ec * EthereumClient ) GetPendingCodeAt ( ctx * Context , account * Address ) ( [ ] byte , error ) {
func ( ec * EthereumClient ) GetPendingCodeAt ( ctx * Context , account * Address ) ( code [ ] byte , _ error ) {
return ec . client . PendingCodeAt ( ctx . context , account . address )
return ec . client . PendingCodeAt ( ctx . context , account . address )
}
}
// GetPendingNonceAt returns the account nonce of the given account in the pending state.
// GetPendingNonceAt returns the account nonce of the given account in the pending state.
// This is the nonce that should be used for the next transaction.
// This is the nonce that should be used for the next transaction.
func ( ec * EthereumClient ) GetPendingNonceAt ( ctx * Context , account * Address ) ( int64 , error ) {
func ( ec * EthereumClient ) GetPendingNonceAt ( ctx * Context , account * Address ) ( nonce int64 , _ error ) {
n once, err := ec . client . PendingNonceAt ( ctx . context , account . address )
rawN once, err := ec . client . PendingNonceAt ( ctx . context , account . address )
return int64 ( n once) , err
return int64 ( rawN once) , err
}
}
// GetPendingTransactionCount returns the total number of transactions in the pending state.
// GetPendingTransactionCount returns the total number of transactions in the pending state.
func ( ec * EthereumClient ) GetPendingTransactionCount ( ctx * Context ) ( int , error ) {
func ( ec * EthereumClient ) GetPendingTransactionCount ( ctx * Context ) ( count int , _ error ) {
c ount, err := ec . client . PendingTransactionCount ( ctx . context )
rawC ount, err := ec . client . PendingTransactionCount ( ctx . context )
return int ( c ount) , err
return int ( rawC ount) , err
}
}
// Contract Calling
// Contract Calling
@ -268,7 +268,7 @@ func (ec *EthereumClient) GetPendingTransactionCount(ctx *Context) (int, error)
// blockNumber selects the block height at which the call runs. It can be <0, in which
// blockNumber selects the block height at which the call runs. It can be <0, in which
// case the code is taken from the latest known block. Note that state from very old
// case the code is taken from the latest known block. Note that state from very old
// blocks might not be available.
// blocks might not be available.
func ( ec * EthereumClient ) CallContract ( ctx * Context , msg * CallMsg , number int64 ) ( [ ] byte , error ) {
func ( ec * EthereumClient ) CallContract ( ctx * Context , msg * CallMsg , number int64 ) ( output [ ] byte , _ error ) {
if number < 0 {
if number < 0 {
return ec . client . CallContract ( ctx . context , msg . msg , nil )
return ec . client . CallContract ( ctx . context , msg . msg , nil )
}
}
@ -277,24 +277,24 @@ func (ec *EthereumClient) CallContract(ctx *Context, msg *CallMsg, number int64)
// PendingCallContract executes a message call transaction using the EVM.
// PendingCallContract executes a message call transaction using the EVM.
// The state seen by the contract call is the pending state.
// The state seen by the contract call is the pending state.
func ( ec * EthereumClient ) PendingCallContract ( ctx * Context , msg * CallMsg ) ( [ ] byte , error ) {
func ( ec * EthereumClient ) PendingCallContract ( ctx * Context , msg * CallMsg ) ( output [ ] byte , _ error ) {
return ec . client . PendingCallContract ( ctx . context , msg . msg )
return ec . client . PendingCallContract ( ctx . context , msg . msg )
}
}
// SuggestGasPrice retrieves the currently suggested gas price to allow a timely
// SuggestGasPrice retrieves the currently suggested gas price to allow a timely
// execution of a transaction.
// execution of a transaction.
func ( ec * EthereumClient ) SuggestGasPrice ( ctx * Context ) ( * BigInt , error ) {
func ( ec * EthereumClient ) SuggestGasPrice ( ctx * Context ) ( price * BigInt , _ error ) {
p rice, err := ec . client . SuggestGasPrice ( ctx . context )
rawP rice, err := ec . client . SuggestGasPrice ( ctx . context )
return & BigInt { p rice} , err
return & BigInt { rawP rice} , err
}
}
// EstimateGas tries to estimate the gas needed to execute a specific transaction based on
// EstimateGas tries to estimate the gas needed to execute a specific transaction based on
// the current pending state of the backend blockchain. There is no guarantee that this is
// the current pending state of the backend blockchain. There is no guarantee that this is
// the true gas limit requirement as other transactions may be added or removed by miners,
// the true gas limit requirement as other transactions may be added or removed by miners,
// but it should provide a basis for setting a reasonable default.
// but it should provide a basis for setting a reasonable default.
func ( ec * EthereumClient ) EstimateGas ( ctx * Context , msg * CallMsg ) ( * BigInt , error ) {
func ( ec * EthereumClient ) EstimateGas ( ctx * Context , msg * CallMsg ) ( gas * BigInt , _ error ) {
price , err := ec . client . EstimateGas ( ctx . context , msg . msg )
rawGas , err := ec . client . EstimateGas ( ctx . context , msg . msg )
return & BigInt { price } , err
return & BigInt { rawGas } , err
}
}
// SendTransaction injects a signed transaction into the pending pool for execution.
// SendTransaction injects a signed transaction into the pending pool for execution.