Commit 0fe35b90 authored by Péter Szilágyi's avatar Péter Szilágyi Committed by Felix Lange

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
parent 3fc7c978
......@@ -800,7 +800,7 @@ func doXCodeFramework(cmdline []string) {
// Build the iOS XCode framework
build.MustRun(goTool("get", "golang.org/x/mobile/cmd/gomobile"))
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 we're building locally, use the build folder and stop afterwards
......
......@@ -56,7 +56,7 @@ func (a *Accounts) Size() int {
}
// 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) {
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.
func (am *AccountManager) HasAddress(addr *Address) bool {
return am.manager.HasAddress(addr.address)
func (am *AccountManager) HasAddress(address *Address) bool {
return am.manager.HasAddress(address.address)
}
// 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.
// 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{
Address: a.account.Address,
File: a.account.File,
Address: account.account.Address,
File: account.account.File,
}, passphrase)
}
// Sign signs hash with an unlocked private key matching the given address.
func (am *AccountManager) Sign(addr *Address, hash []byte) ([]byte, error) {
return am.manager.Sign(addr.address, hash)
func (am *AccountManager) Sign(address *Address, hash []byte) (signature []byte, _ error) {
return am.manager.Sign(address.address, hash)
}
// SignWithPassphrase signs hash if the private key matching the given address can be
// decrypted with the given passphrase.
func (am *AccountManager) SignWithPassphrase(addr *Address, passphrase string, hash []byte) ([]byte, error) {
return am.manager.SignWithPassphrase(addr.address, passphrase, hash)
func (am *AccountManager) SignWithPassphrase(address *Address, passphrase string, hash []byte) (signature []byte, _ error) {
return am.manager.SignWithPassphrase(address.address, passphrase, hash)
}
// Unlock unlocks the given account indefinitely.
func (am *AccountManager) Unlock(a *Account, passphrase string) error {
return am.manager.TimedUnlock(a.account, passphrase, 0)
func (am *AccountManager) Unlock(account *Account, passphrase string) error {
return am.manager.TimedUnlock(account.account, passphrase, 0)
}
// Lock removes the private key with the given address from memory.
func (am *AccountManager) Lock(addr *Address) error {
return am.manager.Lock(addr.address)
func (am *AccountManager) Lock(address *Address) error {
return am.manager.Lock(address.address)
}
// 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.
func (am *AccountManager) ExportKey(a *Account, passphrase, newPassphrase string) ([]byte, error) {
return am.manager.Export(a.account, passphrase, newPassphrase)
func (am *AccountManager) ExportKey(account *Account, passphrase, newPassphrase string) (key []byte, _ error) {
return am.manager.Export(account.account, passphrase, newPassphrase)
}
// ImportKey stores the given encrypted JSON key into the key directory.
func (am *AccountManager) ImportKey(keyJSON []byte, passphrase, newPassphrase string) (*Account, error) {
account, err := am.manager.Import(keyJSON, passphrase, newPassphrase)
func (am *AccountManager) ImportKey(keyJSON []byte, passphrase, newPassphrase string) (account *Account, _ error) {
acc, err := am.manager.Import(keyJSON, passphrase, newPassphrase)
if err != nil {
return nil, err
}
return &Account{account}, nil
return &Account{acc}, nil
}
// Update changes the passphrase of an existing account.
func (am *AccountManager) Update(a *Account, passphrase, newPassphrase string) error {
return am.manager.Update(a.account, passphrase, newPassphrase)
func (am *AccountManager) Update(account *Account, passphrase, newPassphrase string) error {
return am.manager.Update(account.account, passphrase, newPassphrase)
}
// 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.
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)
if err != nil {
return nil, err
......
......@@ -78,7 +78,7 @@ func (bi *BigInts) Size() int {
}
// 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) {
return nil, errors.New("index out of bounds")
}
......
......@@ -31,15 +31,15 @@ import (
// Signer is an interaface defining the callback when a contract requires a
// method to sign the transaction before submission.
type Signer interface {
Sign(*Address, *Transaction) (*Transaction, error)
Sign(*Address, *Transaction) (tx *Transaction, _ error)
}
type signer struct {
sign bind.SignerFn
}
func (s *signer) Sign(addr *Address, tx *Transaction) (*Transaction, error) {
sig, err := s.sign(types.HomesteadSigner{}, addr.address, tx.tx)
func (s *signer) Sign(addr *Address, unsignedTx *Transaction) (signedTx *Transaction, _ error) {
sig, err := s.sign(types.HomesteadSigner{}, addr.address, unsignedTx.tx)
if err != nil {
return nil, err
}
......@@ -113,7 +113,7 @@ type BoundContract struct {
// DeployContract deploys a contract onto the Ethereum blockchain and binds the
// 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
params := make([]interface{}, len(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
// 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))
if err != nil {
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.
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))
for i, obj := range args.objects {
params[i] = obj
}
tx, err := c.contract.Transact(&opts.opts, method, params)
rawTx, err := c.contract.Transact(&opts.opts, method, params)
if err != nil {
return nil, err
}
return &Transaction{tx}, nil
return &Transaction{rawTx}, nil
}
// Transfer initiates a plain transaction to move funds to the contract, calling
// its default method if one is available.
func (c *BoundContract) Transfer(opts *TransactOpts) (*Transaction, error) {
tx, err := c.contract.Transfer(&opts.opts)
func (c *BoundContract) Transfer(opts *TransactOpts) (tx *Transaction, _ error) {
rawTx, err := c.contract.Transfer(&opts.opts)
if err != nil {
return nil, err
}
return &Transaction{tx}, nil
return &Transaction{rawTx}, nil
}
......@@ -33,18 +33,18 @@ type Hash struct {
}
// 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)
if err := h.SetBytes(hash); err != nil {
if err := h.SetBytes(binary); err != nil {
return nil, err
}
return h, nil
}
// 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)
if err := h.SetHex(hash); err != nil {
if err := h.SetHex(hex); err != nil {
return nil, err
}
return h, nil
......@@ -95,7 +95,7 @@ func (h *Hashes) Size() int {
}
// 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) {
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.
func NewAddressFromBytes(address []byte) (*Address, error) {
func NewAddressFromBytes(binary []byte) (address *Address, _ error) {
a := new(Address)
if err := a.SetBytes(address); err != nil {
if err := a.SetBytes(binary); err != nil {
return nil, err
}
return a, nil
}
// 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)
if err := a.SetHex(address); err != nil {
if err := a.SetHex(hex); err != nil {
return nil, err
}
return a, nil
......@@ -170,7 +170,7 @@ func (a *Addresses) Size() int {
}
// 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) {
return nil, errors.New("index out of bounds")
}
......
......@@ -53,7 +53,7 @@ type Enode struct {
// and UDP discovery port 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)
if err != nil {
return nil, err
......@@ -82,7 +82,7 @@ func (e *Enodes) Size() int {
}
// 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) {
return nil, errors.New("index out of bounds")
}
......
......@@ -51,6 +51,10 @@
// should not be provided to limit the remote code complexity. Arrays should be
// 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
// an undebuggable SEGFAULT in the process. For error handling only ever use error
// returns, which may be the only or the second return.
......
This diff is collapsed.
......@@ -93,7 +93,7 @@ func (t *Topics) Size() int {
}
// 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) {
return nil, errors.New("index out of bounds")
}
......
......@@ -99,7 +99,7 @@ type Node struct {
}
// 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 config == nil {
config = NewNodeConfig()
......@@ -124,7 +124,7 @@ func NewNode(datadir string, config *NodeConfig) (*Node, error) {
NAT: nat.Any(),
MaxPeers: config.MaxPeers,
}
stack, err := node.New(nodeConf)
rawStack, err := node.New(nodeConf)
if err != nil {
return nil, err
}
......@@ -153,14 +153,14 @@ func NewNode(datadir string, config *NodeConfig) (*Node, error) {
GpobaseStepUp: 100,
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)
}); err != nil {
return nil, fmt.Errorf("ethereum init: %v", err)
}
// If netstats reporting is requested, do it
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
ctx.Service(&lesServ)
......@@ -172,11 +172,11 @@ func NewNode(datadir string, config *NodeConfig) (*Node, error) {
}
// Register the Whisper protocol if requested
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 &Node{stack}, nil
return &Node{rawStack}, nil
}
// 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.
func (n *Node) GetEthereumClient() (*EthereumClient, error) {
func (n *Node) GetEthereumClient() (client *EthereumClient, _ error) {
rpc, err := n.node.Attach()
if err != nil {
return nil, err
......
......@@ -131,7 +131,7 @@ func (i *Interfaces) Size() int {
}
// 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) {
return nil, errors.New("index out of bounds")
}
......
......@@ -66,7 +66,7 @@ func (pi *PeerInfos) Size() int {
}
// 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) {
return nil, errors.New("index out of bounds")
}
......
......@@ -32,7 +32,7 @@ func (s *Strings) Size() int {
}
// 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) {
return "", errors.New("index out of bounds")
}
......
......@@ -89,7 +89,7 @@ func (h *Headers) Size() int {
}
// 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) {
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) 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)
return &Address{from}, err
}
......@@ -154,25 +154,25 @@ func (tx *Transaction) GetTo() *Address {
return nil
}
func (tx *Transaction) WithSignature(sig []byte) (*Transaction, error) {
t, err := tx.tx.WithSignature(types.HomesteadSigner{}, sig)
return &Transaction{t}, err
func (tx *Transaction) WithSignature(sig []byte) (signedTx *Transaction, _ error) {
rawTx, err := tx.tx.WithSignature(types.HomesteadSigner{}, sig)
return &Transaction{rawTx}, err
}
// Transactions represents a slice of transactions.
type Transactions struct{ txs types.Transactions }
// Size returns the number of transactions in the slice.
func (t *Transactions) Size() int {
return len(t.txs)
func (txs *Transactions) Size() int {
return len(txs.txs)
}
// Get returns the transaction at the given index from the slice.
func (t *Transactions) Get(index int) (*Transaction, error) {
if index < 0 || index >= len(t.txs) {
func (txs *Transactions) Get(index int) (tx *Transaction, _ error) {
if index < 0 || index >= len(txs.txs) {
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.
......
......@@ -48,7 +48,7 @@ func (l *Logs) Size() int {
}
// 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) {
return nil, errors.New("index out of bounds")
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment