// Deploy deploys a fresh instance of the EtherAPIs contract, returning the // transaction seeded into the network. func (eapis *EtherAPIs) Deploy(from common.Address) (common.Address, *types.Transaction, error) { rpc, err := eapis.client.Stack().Attach() if err != nil { return common.Address{}, nil, err } auth := &bind.TransactOpts{ From: from, Signer: eapis.signer, } target, tx, etherapis, err := contract.DeployEtherAPIs(auth, backends.NewRPCBackend(rpc)) if err == nil { eapis.contract = etherapis } return target, tx, err }
// New creates a new Ether APIs instance, connects with it to the Ethereum network // via an embedded Geth instance and attaches an RPC in-process endpoint to it. func New(datadir string, network geth.EthereumNetwork, address common.Address) (*EtherAPIs, error) { // Create a Geth instance and boot it up client, err := geth.New(datadir, network) if err != nil { return nil, err } if err := client.Start(); err != nil { return nil, err } // Retrieve the underlying ethereum service and attach global RPC interface var ethereum *eth.Ethereum if err := client.Stack().Service(ðereum); err != nil { return nil, err } api, err := client.Attach() if err != nil { return nil, err } // Assemble an interface around the consensus contract rpcClient, err := client.Stack().Attach() if err != nil { return nil, err } contract, err := contract.NewEtherAPIs(address, backends.NewRPCBackend(rpcClient)) if err != nil { return nil, err } // Assemble and return the Ether APIs instance return &EtherAPIs{ client: client, ethereum: ethereum, eventmux: client.Stack().EventMux(), rpcapi: api, contract: contract, signer: func(from common.Address, tx *types.Transaction) (*types.Transaction, error) { signature, err := ethereum.AccountManager().Sign(accounts.Account{Address: from}, tx.SigHash().Bytes()) if err != nil { return nil, err } return tx.WithSignature(signature) }, }, nil }