mobile: iOS naming and API fixes for generators and Swift (#3408)

* build: modify the iOS namespace to iGeth (gomobile limitation)
* mobile: assign names to return types for ObjC wrapper
* mobile: use more expanded names for iOS/Swift API
This commit is contained in:
Péter Szilágyi 2016-12-08 14:09:26 +02:00 committed by Felix Lange
parent 3fc7c97827
commit 0fe35b907a
15 changed files with 151 additions and 147 deletions

View File

@ -800,7 +800,7 @@ func doXCodeFramework(cmdline []string) {
// Build the iOS XCode framework // Build the iOS XCode framework
build.MustRun(goTool("get", "golang.org/x/mobile/cmd/gomobile")) build.MustRun(goTool("get", "golang.org/x/mobile/cmd/gomobile"))
build.MustRun(gomobileTool("init")) build.MustRun(gomobileTool("init"))
bind := gomobileTool("bind", "--target", "ios", "--tags", "ios", "--prefix", "GE", "-v", "github.com/ethereum/go-ethereum/mobile") bind := gomobileTool("bind", "--target", "ios", "--tags", "ios", "--prefix", "i", "-v", "github.com/ethereum/go-ethereum/mobile")
if *local { if *local {
// If we're building locally, use the build folder and stop afterwards // If we're building locally, use the build folder and stop afterwards

View File

@ -56,7 +56,7 @@ func (a *Accounts) Size() int {
} }
// Get returns the account at the given index from the slice. // Get returns the account at the given index from the slice.
func (a *Accounts) Get(index int) (*Account, error) { func (a *Accounts) Get(index int) (account *Account, _ error) {
if index < 0 || index >= len(a.accounts) { if index < 0 || index >= len(a.accounts) {
return nil, errors.New("index out of bounds") return nil, errors.New("index out of bounds")
} }
@ -91,8 +91,8 @@ func NewAccountManager(keydir string, scryptN, scryptP int) *AccountManager {
} }
// HasAddress reports whether a key with the given address is present. // HasAddress reports whether a key with the given address is present.
func (am *AccountManager) HasAddress(addr *Address) bool { func (am *AccountManager) HasAddress(address *Address) bool {
return am.manager.HasAddress(addr.address) return am.manager.HasAddress(address.address)
} }
// GetAccounts returns all key files present in the directory. // GetAccounts returns all key files present in the directory.
@ -102,32 +102,32 @@ func (am *AccountManager) GetAccounts() *Accounts {
// DeleteAccount deletes the key matched by account if the passphrase is correct. // DeleteAccount deletes the key matched by account if the passphrase is correct.
// If a contains no filename, the address must match a unique key. // If a contains no filename, the address must match a unique key.
func (am *AccountManager) DeleteAccount(a *Account, passphrase string) error { func (am *AccountManager) DeleteAccount(account *Account, passphrase string) error {
return am.manager.DeleteAccount(accounts.Account{ return am.manager.DeleteAccount(accounts.Account{
Address: a.account.Address, Address: account.account.Address,
File: a.account.File, File: account.account.File,
}, passphrase) }, passphrase)
} }
// Sign signs hash with an unlocked private key matching the given address. // Sign signs hash with an unlocked private key matching the given address.
func (am *AccountManager) Sign(addr *Address, hash []byte) ([]byte, error) { func (am *AccountManager) Sign(address *Address, hash []byte) (signature []byte, _ error) {
return am.manager.Sign(addr.address, hash) return am.manager.Sign(address.address, hash)
} }
// SignWithPassphrase signs hash if the private key matching the given address can be // SignWithPassphrase signs hash if the private key matching the given address can be
// decrypted with the given passphrase. // decrypted with the given passphrase.
func (am *AccountManager) SignWithPassphrase(addr *Address, passphrase string, hash []byte) ([]byte, error) { func (am *AccountManager) SignWithPassphrase(address *Address, passphrase string, hash []byte) (signature []byte, _ error) {
return am.manager.SignWithPassphrase(addr.address, passphrase, hash) return am.manager.SignWithPassphrase(address.address, passphrase, hash)
} }
// Unlock unlocks the given account indefinitely. // Unlock unlocks the given account indefinitely.
func (am *AccountManager) Unlock(a *Account, passphrase string) error { func (am *AccountManager) Unlock(account *Account, passphrase string) error {
return am.manager.TimedUnlock(a.account, passphrase, 0) return am.manager.TimedUnlock(account.account, passphrase, 0)
} }
// Lock removes the private key with the given address from memory. // Lock removes the private key with the given address from memory.
func (am *AccountManager) Lock(addr *Address) error { func (am *AccountManager) Lock(address *Address) error {
return am.manager.Lock(addr.address) return am.manager.Lock(address.address)
} }
// TimedUnlock unlocks the given account with the passphrase. The account // TimedUnlock unlocks the given account with the passphrase. The account
@ -152,27 +152,27 @@ func (am *AccountManager) NewAccount(passphrase string) (*Account, error) {
} }
// ExportKey exports as a JSON key, encrypted with newPassphrase. // ExportKey exports as a JSON key, encrypted with newPassphrase.
func (am *AccountManager) ExportKey(a *Account, passphrase, newPassphrase string) ([]byte, error) { func (am *AccountManager) ExportKey(account *Account, passphrase, newPassphrase string) (key []byte, _ error) {
return am.manager.Export(a.account, passphrase, newPassphrase) return am.manager.Export(account.account, passphrase, newPassphrase)
} }
// ImportKey stores the given encrypted JSON key into the key directory. // ImportKey stores the given encrypted JSON key into the key directory.
func (am *AccountManager) ImportKey(keyJSON []byte, passphrase, newPassphrase string) (*Account, error) { func (am *AccountManager) ImportKey(keyJSON []byte, passphrase, newPassphrase string) (account *Account, _ error) {
account, err := am.manager.Import(keyJSON, passphrase, newPassphrase) acc, err := am.manager.Import(keyJSON, passphrase, newPassphrase)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &Account{account}, nil return &Account{acc}, nil
} }
// Update changes the passphrase of an existing account. // Update changes the passphrase of an existing account.
func (am *AccountManager) Update(a *Account, passphrase, newPassphrase string) error { func (am *AccountManager) Update(account *Account, passphrase, newPassphrase string) error {
return am.manager.Update(a.account, passphrase, newPassphrase) return am.manager.Update(account.account, passphrase, newPassphrase)
} }
// ImportPreSaleKey decrypts the given Ethereum presale wallet and stores // ImportPreSaleKey decrypts the given Ethereum presale wallet and stores
// a key file in the key directory. The key file is encrypted with the same passphrase. // a key file in the key directory. The key file is encrypted with the same passphrase.
func (am *AccountManager) ImportPreSaleKey(keyJSON []byte, passphrase string) (*Account, error) { func (am *AccountManager) ImportPreSaleKey(keyJSON []byte, passphrase string) (ccount *Account, _ error) {
account, err := am.manager.ImportPreSaleKey(keyJSON, passphrase) account, err := am.manager.ImportPreSaleKey(keyJSON, passphrase)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -78,7 +78,7 @@ func (bi *BigInts) Size() int {
} }
// Get returns the bigint at the given index from the slice. // Get returns the bigint at the given index from the slice.
func (bi *BigInts) Get(index int) (*BigInt, error) { func (bi *BigInts) Get(index int) (bigint *BigInt, _ error) {
if index < 0 || index >= len(bi.bigints) { if index < 0 || index >= len(bi.bigints) {
return nil, errors.New("index out of bounds") return nil, errors.New("index out of bounds")
} }

View File

@ -31,15 +31,15 @@ import (
// Signer is an interaface defining the callback when a contract requires a // Signer is an interaface defining the callback when a contract requires a
// method to sign the transaction before submission. // method to sign the transaction before submission.
type Signer interface { type Signer interface {
Sign(*Address, *Transaction) (*Transaction, error) Sign(*Address, *Transaction) (tx *Transaction, _ error)
} }
type signer struct { type signer struct {
sign bind.SignerFn sign bind.SignerFn
} }
func (s *signer) Sign(addr *Address, tx *Transaction) (*Transaction, error) { func (s *signer) Sign(addr *Address, unsignedTx *Transaction) (signedTx *Transaction, _ error) {
sig, err := s.sign(types.HomesteadSigner{}, addr.address, tx.tx) sig, err := s.sign(types.HomesteadSigner{}, addr.address, unsignedTx.tx)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -113,7 +113,7 @@ type BoundContract struct {
// DeployContract deploys a contract onto the Ethereum blockchain and binds the // DeployContract deploys a contract onto the Ethereum blockchain and binds the
// deployment address with a wrapper. // deployment address with a wrapper.
func DeployContract(opts *TransactOpts, abiJSON string, bytecode []byte, client *EthereumClient, args *Interfaces) (*BoundContract, error) { func DeployContract(opts *TransactOpts, abiJSON string, bytecode []byte, client *EthereumClient, args *Interfaces) (contract *BoundContract, _ error) {
// Convert all the deployment parameters to Go types // Convert all the deployment parameters to Go types
params := make([]interface{}, len(args.objects)) params := make([]interface{}, len(args.objects))
for i, obj := range args.objects { for i, obj := range args.objects {
@ -137,7 +137,7 @@ func DeployContract(opts *TransactOpts, abiJSON string, bytecode []byte, client
// BindContract creates a low level contract interface through which calls and // BindContract creates a low level contract interface through which calls and
// transactions may be made through. // transactions may be made through.
func BindContract(address *Address, abiJSON string, client *EthereumClient) (*BoundContract, error) { func BindContract(address *Address, abiJSON string, client *EthereumClient) (contract *BoundContract, _ error) {
parsed, err := abi.JSON(strings.NewReader(abiJSON)) parsed, err := abi.JSON(strings.NewReader(abiJSON))
if err != nil { if err != nil {
return nil, err return nil, err
@ -179,24 +179,24 @@ func (c *BoundContract) Call(opts *CallOpts, out *Interfaces, method string, arg
} }
// Transact invokes the (paid) contract method with params as input values. // Transact invokes the (paid) contract method with params as input values.
func (c *BoundContract) Transact(opts *TransactOpts, method string, args *Interfaces) (*Transaction, error) { func (c *BoundContract) Transact(opts *TransactOpts, method string, args *Interfaces) (tx *Transaction, _ error) {
params := make([]interface{}, len(args.objects)) params := make([]interface{}, len(args.objects))
for i, obj := range args.objects { for i, obj := range args.objects {
params[i] = obj params[i] = obj
} }
tx, err := c.contract.Transact(&opts.opts, method, params) rawTx, err := c.contract.Transact(&opts.opts, method, params)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &Transaction{tx}, nil return &Transaction{rawTx}, nil
} }
// Transfer initiates a plain transaction to move funds to the contract, calling // Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available. // its default method if one is available.
func (c *BoundContract) Transfer(opts *TransactOpts) (*Transaction, error) { func (c *BoundContract) Transfer(opts *TransactOpts) (tx *Transaction, _ error) {
tx, err := c.contract.Transfer(&opts.opts) rawTx, err := c.contract.Transfer(&opts.opts)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &Transaction{tx}, nil return &Transaction{rawTx}, nil
} }

View File

@ -33,18 +33,18 @@ type Hash struct {
} }
// NewHashFromBytes converts a slice of bytes to a hash value. // NewHashFromBytes converts a slice of bytes to a hash value.
func NewHashFromBytes(hash []byte) (*Hash, error) { func NewHashFromBytes(binary []byte) (hash *Hash, _ error) {
h := new(Hash) h := new(Hash)
if err := h.SetBytes(hash); err != nil { if err := h.SetBytes(binary); err != nil {
return nil, err return nil, err
} }
return h, nil return h, nil
} }
// NewHashFromHex converts a hex string to a hash value. // NewHashFromHex converts a hex string to a hash value.
func NewHashFromHex(hash string) (*Hash, error) { func NewHashFromHex(hex string) (hash *Hash, _ error) {
h := new(Hash) h := new(Hash)
if err := h.SetHex(hash); err != nil { if err := h.SetHex(hex); err != nil {
return nil, err return nil, err
} }
return h, nil return h, nil
@ -95,7 +95,7 @@ func (h *Hashes) Size() int {
} }
// Get returns the hash at the given index from the slice. // Get returns the hash at the given index from the slice.
func (h *Hashes) Get(index int) (*Hash, error) { func (h *Hashes) Get(index int) (hash *Hash, _ error) {
if index < 0 || index >= len(h.hashes) { if index < 0 || index >= len(h.hashes) {
return nil, errors.New("index out of bounds") return nil, errors.New("index out of bounds")
} }
@ -108,18 +108,18 @@ type Address struct {
} }
// NewAddressFromBytes converts a slice of bytes to a hash value. // NewAddressFromBytes converts a slice of bytes to a hash value.
func NewAddressFromBytes(address []byte) (*Address, error) { func NewAddressFromBytes(binary []byte) (address *Address, _ error) {
a := new(Address) a := new(Address)
if err := a.SetBytes(address); err != nil { if err := a.SetBytes(binary); err != nil {
return nil, err return nil, err
} }
return a, nil return a, nil
} }
// NewAddressFromHex converts a hex string to a address value. // NewAddressFromHex converts a hex string to a address value.
func NewAddressFromHex(address string) (*Address, error) { func NewAddressFromHex(hex string) (address *Address, _ error) {
a := new(Address) a := new(Address)
if err := a.SetHex(address); err != nil { if err := a.SetHex(hex); err != nil {
return nil, err return nil, err
} }
return a, nil return a, nil
@ -170,7 +170,7 @@ func (a *Addresses) Size() int {
} }
// Get returns the address at the given index from the slice. // Get returns the address at the given index from the slice.
func (a *Addresses) Get(index int) (*Address, error) { func (a *Addresses) Get(index int) (address *Address, _ error) {
if index < 0 || index >= len(a.addresses) { if index < 0 || index >= len(a.addresses) {
return nil, errors.New("index out of bounds") return nil, errors.New("index out of bounds")
} }

View File

@ -53,7 +53,7 @@ type Enode struct {
// and UDP discovery port 30301. // and UDP discovery port 30301.
// //
// enode://<hex node id>@10.3.58.6:30303?discport=30301 // enode://<hex node id>@10.3.58.6:30303?discport=30301
func NewEnode(rawurl string) (*Enode, error) { func NewEnode(rawurl string) (enode *Enode, _ error) {
node, err := discv5.ParseNode(rawurl) node, err := discv5.ParseNode(rawurl)
if err != nil { if err != nil {
return nil, err return nil, err
@ -82,7 +82,7 @@ func (e *Enodes) Size() int {
} }
// Get returns the enode at the given index from the slice. // Get returns the enode at the given index from the slice.
func (e *Enodes) Get(index int) (*Enode, error) { func (e *Enodes) Get(index int) (enode *Enode, _ error) {
if index < 0 || index >= len(e.nodes) { if index < 0 || index >= len(e.nodes) {
return nil, errors.New("index out of bounds") return nil, errors.New("index out of bounds")
} }

View File

@ -51,6 +51,10 @@
// should not be provided to limit the remote code complexity. Arrays should be // should not be provided to limit the remote code complexity. Arrays should be
// avoided as much as possible since they complicate bounds checking. // avoided as much as possible since they complicate bounds checking.
// //
// If a method has multiple return values (e.g. some return + an error), those
// are generated as output arguments in ObjC. To avoid weird generated names like
// ret_0 for them, please always assign names to output variables if tuples.
//
// Note, a panic *cannot* cross over language boundaries, instead will result in // Note, a panic *cannot* cross over language boundaries, instead will result in
// an undebuggable SEGFAULT in the process. For error handling only ever use error // an undebuggable SEGFAULT in the process. For error handling only ever use error
// returns, which may be the only or the second return. // returns, which may be the only or the second return.

View File

@ -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) {
client, err := ethclient.Dial(rawurl) rawClient, err := ethclient.Dial(rawurl)
return &EthereumClient{client}, err return &EthereumClient{rawClient}, 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) {
block, err := ec.client.BlockByHash(ctx.context, hash.hash) rawBlock, err := ec.client.BlockByHash(ctx.context, hash.hash)
return &Block{block}, err return &Block{rawBlock}, 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 {
block, err := ec.client.BlockByNumber(ctx.context, nil) rawBlock, err := ec.client.BlockByNumber(ctx.context, nil)
return &Block{block}, err return &Block{rawBlock}, err
} }
block, err := ec.client.BlockByNumber(ctx.context, big.NewInt(number)) rawBlock, err := ec.client.BlockByNumber(ctx.context, big.NewInt(number))
return &Block{block}, err return &Block{rawBlock}, 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) {
header, err := ec.client.HeaderByHash(ctx.context, hash.hash) rawHeader, err := ec.client.HeaderByHash(ctx.context, hash.hash)
return &Header{header}, err return &Header{rawHeader}, 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 {
header, err := ec.client.HeaderByNumber(ctx.context, nil) rawHeader, err := ec.client.HeaderByNumber(ctx.context, nil)
return &Header{header}, err return &Header{rawHeader}, err
} }
header, err := ec.client.HeaderByNumber(ctx.context, big.NewInt(number)) rawHeader, err := ec.client.HeaderByNumber(ctx.context, big.NewInt(number))
return &Header{header}, err return &Header{rawHeader}, 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
tx, _, err := ec.client.TransactionByHash(ctx.context, hash.hash) rawTx, _, err := ec.client.TransactionByHash(ctx.context, hash.hash)
return &Transaction{tx}, err return &Transaction{rawTx}, 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) {
count, err := ec.client.TransactionCount(ctx.context, hash.hash) rawCount, err := ec.client.TransactionCount(ctx.context, hash.hash)
return int(count), err return int(rawCount), 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) {
tx, err := ec.client.TransactionInBlock(ctx.context, hash.hash, uint(index)) rawTx, err := ec.client.TransactionInBlock(ctx.context, hash.hash, uint(index))
return &Transaction{tx}, err return &Transaction{rawTx}, 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) rawReceipt, err := ec.client.TransactionReceipt(ctx.context, hash.hash)
return &Receipt{receipt}, err return &Receipt{rawReceipt}, 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) {
progress, err := ec.client.SyncProgress(ctx.context) rawProgress, err := ec.client.SyncProgress(ctx.context)
if progress == nil { if rawProgress == nil {
return nil, err return nil, err
} }
return &SyncProgress{*progress}, err return &SyncProgress{*rawProgress}, 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)
sub, err := ec.client.SubscribeNewHead(ctx.context, ch) rawSub, 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 := <-sub.Err(): case err := <-rawSub.Err():
handler.OnError(err.Error()) handler.OnError(err.Error())
return return
} }
} }
}() }()
return &Subscription{sub}, nil return &Subscription{rawSub}, 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 {
balance, err := ec.client.BalanceAt(ctx.context, account.address, nil) rawBalance, err := ec.client.BalanceAt(ctx.context, account.address, nil)
return &BigInt{balance}, err return &BigInt{rawBalance}, err
} }
balance, err := ec.client.BalanceAt(ctx.context, account.address, big.NewInt(number)) rawBalance, err := ec.client.BalanceAt(ctx.context, account.address, big.NewInt(number))
return &BigInt{balance}, err return &BigInt{rawBalance}, 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 {
nonce, err := ec.client.NonceAt(ctx.context, account.address, nil) rawNonce, err := ec.client.NonceAt(ctx.context, account.address, nil)
return int64(nonce), err return int64(rawNonce), err
} }
nonce, err := ec.client.NonceAt(ctx.context, account.address, big.NewInt(number)) rawNonce, err := ec.client.NonceAt(ctx.context, account.address, big.NewInt(number))
return int64(nonce), err return int64(rawNonce), 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) {
logs, err := ec.client.FilterLogs(ctx.context, query.query) rawLogs, 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(logs)) res := make(vm.Logs, len(rawLogs))
for i, log := range logs { for i, log := range rawLogs {
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)
sub, err := ec.client.SubscribeFilterLogs(ctx.context, query.query, ch) rawSub, 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 := <-sub.Err(): case err := <-rawSub.Err():
handler.OnError(err.Error()) handler.OnError(err.Error())
return return
} }
} }
}() }()
return &Subscription{sub}, nil return &Subscription{rawSub}, 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) {
balance, err := ec.client.PendingBalanceAt(ctx.context, account.address) rawBalance, err := ec.client.PendingBalanceAt(ctx.context, account.address)
return &BigInt{balance}, err return &BigInt{rawBalance}, 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) {
nonce, err := ec.client.PendingNonceAt(ctx.context, account.address) rawNonce, err := ec.client.PendingNonceAt(ctx.context, account.address)
return int64(nonce), err return int64(rawNonce), 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) {
count, err := ec.client.PendingTransactionCount(ctx.context) rawCount, err := ec.client.PendingTransactionCount(ctx.context)
return int(count), err return int(rawCount), 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) {
price, err := ec.client.SuggestGasPrice(ctx.context) rawPrice, err := ec.client.SuggestGasPrice(ctx.context)
return &BigInt{price}, err return &BigInt{rawPrice}, 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.

View File

@ -93,7 +93,7 @@ func (t *Topics) Size() int {
} }
// Get returns the topic list at the given index from the slice. // Get returns the topic list at the given index from the slice.
func (t *Topics) Get(index int) (*Hashes, error) { func (t *Topics) Get(index int) (hashes *Hashes, _ error) {
if index < 0 || index >= len(t.topics) { if index < 0 || index >= len(t.topics) {
return nil, errors.New("index out of bounds") return nil, errors.New("index out of bounds")
} }

View File

@ -99,7 +99,7 @@ type Node struct {
} }
// NewNode creates and configures a new Geth node. // NewNode creates and configures a new Geth node.
func NewNode(datadir string, config *NodeConfig) (*Node, error) { func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
// If no or partial configurations were specified, use defaults // If no or partial configurations were specified, use defaults
if config == nil { if config == nil {
config = NewNodeConfig() config = NewNodeConfig()
@ -124,7 +124,7 @@ func NewNode(datadir string, config *NodeConfig) (*Node, error) {
NAT: nat.Any(), NAT: nat.Any(),
MaxPeers: config.MaxPeers, MaxPeers: config.MaxPeers,
} }
stack, err := node.New(nodeConf) rawStack, err := node.New(nodeConf)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -153,14 +153,14 @@ func NewNode(datadir string, config *NodeConfig) (*Node, error) {
GpobaseStepUp: 100, GpobaseStepUp: 100,
GpobaseCorrectionFactor: 110, GpobaseCorrectionFactor: 110,
} }
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { if err := rawStack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
return les.New(ctx, ethConf) return les.New(ctx, ethConf)
}); err != nil { }); err != nil {
return nil, fmt.Errorf("ethereum init: %v", err) return nil, fmt.Errorf("ethereum init: %v", err)
} }
// If netstats reporting is requested, do it // If netstats reporting is requested, do it
if config.EthereumNetStats != "" { if config.EthereumNetStats != "" {
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { if err := rawStack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
var lesServ *les.LightEthereum var lesServ *les.LightEthereum
ctx.Service(&lesServ) ctx.Service(&lesServ)
@ -172,11 +172,11 @@ func NewNode(datadir string, config *NodeConfig) (*Node, error) {
} }
// Register the Whisper protocol if requested // Register the Whisper protocol if requested
if config.WhisperEnabled { if config.WhisperEnabled {
if err := stack.Register(func(*node.ServiceContext) (node.Service, error) { return whisperv2.New(), nil }); err != nil { if err := rawStack.Register(func(*node.ServiceContext) (node.Service, error) { return whisperv2.New(), nil }); err != nil {
return nil, fmt.Errorf("whisper init: %v", err) return nil, fmt.Errorf("whisper init: %v", err)
} }
} }
return &Node{stack}, nil return &Node{rawStack}, nil
} }
// Start creates a live P2P node and starts running it. // Start creates a live P2P node and starts running it.
@ -191,7 +191,7 @@ func (n *Node) Stop() error {
} }
// GetEthereumClient retrieves a client to access the Ethereum subsystem. // GetEthereumClient retrieves a client to access the Ethereum subsystem.
func (n *Node) GetEthereumClient() (*EthereumClient, error) { func (n *Node) GetEthereumClient() (client *EthereumClient, _ error) {
rpc, err := n.node.Attach() rpc, err := n.node.Attach()
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -131,7 +131,7 @@ func (i *Interfaces) Size() int {
} }
// Get returns the bigint at the given index from the slice. // Get returns the bigint at the given index from the slice.
func (i *Interfaces) Get(index int) (*Interface, error) { func (i *Interfaces) Get(index int) (iface *Interface, _ error) {
if index < 0 || index >= len(i.objects) { if index < 0 || index >= len(i.objects) {
return nil, errors.New("index out of bounds") return nil, errors.New("index out of bounds")
} }

View File

@ -66,7 +66,7 @@ func (pi *PeerInfos) Size() int {
} }
// Get returns the peer info at the given index from the slice. // Get returns the peer info at the given index from the slice.
func (pi *PeerInfos) Get(index int) (*PeerInfo, error) { func (pi *PeerInfos) Get(index int) (info *PeerInfo, _ error) {
if index < 0 || index >= len(pi.infos) { if index < 0 || index >= len(pi.infos) {
return nil, errors.New("index out of bounds") return nil, errors.New("index out of bounds")
} }

View File

@ -32,7 +32,7 @@ func (s *Strings) Size() int {
} }
// Get returns the string at the given index from the slice. // Get returns the string at the given index from the slice.
func (s *Strings) Get(index int) (string, error) { func (s *Strings) Get(index int) (str string, _ error) {
if index < 0 || index >= len(s.strs) { if index < 0 || index >= len(s.strs) {
return "", errors.New("index out of bounds") return "", errors.New("index out of bounds")
} }

View File

@ -89,7 +89,7 @@ func (h *Headers) Size() int {
} }
// Get returns the header at the given index from the slice. // Get returns the header at the given index from the slice.
func (h *Headers) Get(index int) (*Header, error) { func (h *Headers) Get(index int) (header *Header, _ error) {
if index < 0 || index >= len(h.headers) { if index < 0 || index >= len(h.headers) {
return nil, errors.New("index out of bounds") return nil, errors.New("index out of bounds")
} }
@ -142,7 +142,7 @@ func (tx *Transaction) GetHash() *Hash { return &Hash{tx.tx.Hash()} }
func (tx *Transaction) GetSigHash() *Hash { return &Hash{tx.tx.SigHash(types.HomesteadSigner{})} } func (tx *Transaction) GetSigHash() *Hash { return &Hash{tx.tx.SigHash(types.HomesteadSigner{})} }
func (tx *Transaction) GetCost() *BigInt { return &BigInt{tx.tx.Cost()} } func (tx *Transaction) GetCost() *BigInt { return &BigInt{tx.tx.Cost()} }
func (tx *Transaction) GetFrom() (*Address, error) { func (tx *Transaction) GetFrom() (address *Address, _ error) {
from, err := types.Sender(types.HomesteadSigner{}, tx.tx) from, err := types.Sender(types.HomesteadSigner{}, tx.tx)
return &Address{from}, err return &Address{from}, err
} }
@ -154,25 +154,25 @@ func (tx *Transaction) GetTo() *Address {
return nil return nil
} }
func (tx *Transaction) WithSignature(sig []byte) (*Transaction, error) { func (tx *Transaction) WithSignature(sig []byte) (signedTx *Transaction, _ error) {
t, err := tx.tx.WithSignature(types.HomesteadSigner{}, sig) rawTx, err := tx.tx.WithSignature(types.HomesteadSigner{}, sig)
return &Transaction{t}, err return &Transaction{rawTx}, err
} }
// Transactions represents a slice of transactions. // Transactions represents a slice of transactions.
type Transactions struct{ txs types.Transactions } type Transactions struct{ txs types.Transactions }
// Size returns the number of transactions in the slice. // Size returns the number of transactions in the slice.
func (t *Transactions) Size() int { func (txs *Transactions) Size() int {
return len(t.txs) return len(txs.txs)
} }
// Get returns the transaction at the given index from the slice. // Get returns the transaction at the given index from the slice.
func (t *Transactions) Get(index int) (*Transaction, error) { func (txs *Transactions) Get(index int) (tx *Transaction, _ error) {
if index < 0 || index >= len(t.txs) { if index < 0 || index >= len(txs.txs) {
return nil, errors.New("index out of bounds") return nil, errors.New("index out of bounds")
} }
return &Transaction{t.txs[index]}, nil return &Transaction{txs.txs[index]}, nil
} }
// Receipt represents the results of a transaction. // Receipt represents the results of a transaction.

View File

@ -48,7 +48,7 @@ func (l *Logs) Size() int {
} }
// Get returns the log at the given index from the slice. // Get returns the log at the given index from the slice.
func (l *Logs) Get(index int) (*Log, error) { func (l *Logs) Get(index int) (log *Log, _ error) {
if index < 0 || index >= len(l.logs) { if index < 0 || index >= len(l.logs) {
return nil, errors.New("index out of bounds") return nil, errors.New("index out of bounds")
} }