aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-04-28 17:00:11 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-05-02 21:20:21 +0800
commit586eddfd09558bfd71f23c2e50c270d2ca665d49 (patch)
tree4015e542e0397c606d1f14ef23d15463881be554 /eth
parentd46da273c6731512b4114393856a96be06505797 (diff)
downloadgo-tangerine-586eddfd09558bfd71f23c2e50c270d2ca665d49.tar
go-tangerine-586eddfd09558bfd71f23c2e50c270d2ca665d49.tar.gz
go-tangerine-586eddfd09558bfd71f23c2e50c270d2ca665d49.tar.bz2
go-tangerine-586eddfd09558bfd71f23c2e50c270d2ca665d49.tar.lz
go-tangerine-586eddfd09558bfd71f23c2e50c270d2ca665d49.tar.xz
go-tangerine-586eddfd09558bfd71f23c2e50c270d2ca665d49.tar.zst
go-tangerine-586eddfd09558bfd71f23c2e50c270d2ca665d49.zip
release, all: integrate the release service into geth
Diffstat (limited to 'eth')
-rw-r--r--eth/api.go30
-rw-r--r--eth/backend.go22
-rw-r--r--eth/bind.go110
3 files changed, 137 insertions, 25 deletions
diff --git a/eth/api.go b/eth/api.go
index 2c84cf471..bd8179962 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -52,14 +52,14 @@ import (
"golang.org/x/net/context"
)
-// ErrNoCode is returned by call and transact operations for which the requested
+// errNoCode is returned by call and transact operations for which the requested
// recipient contract to operate on does not exist in the state db or does not
// have any code associated with it (i.e. suicided).
//
// Please note, this error string is part of the RPC API and is expected by the
// native contract bindings to signal this particular error. Do not change this
// as it will break all dependent code!
-var ErrNoCode = errors.New("no contract code at given address")
+var errNoCode = errors.New("no contract code at given address")
const defaultGas = uint64(90000)
@@ -107,8 +107,11 @@ type PublicEthereumAPI struct {
}
// NewPublicEthereumAPI creates a new Ethereum protocol API.
-func NewPublicEthereumAPI(e *Ethereum, gpo *GasPriceOracle) *PublicEthereumAPI {
- return &PublicEthereumAPI{e, gpo}
+func NewPublicEthereumAPI(e *Ethereum) *PublicEthereumAPI {
+ return &PublicEthereumAPI{
+ e: e,
+ gpo: e.gpo,
+ }
}
// GasPrice returns a suggestion for a gas price.
@@ -717,7 +720,7 @@ func (s *PublicBlockChainAPI) doCall(args CallArgs, blockNr rpc.BlockNumber) (st
// If there's no code to interact with, respond with an appropriate error
if args.To != nil {
if code := stateDb.GetCode(*args.To); len(code) == 0 {
- return "0x", nil, ErrNoCode
+ return "0x", nil, errNoCode
}
}
// Retrieve the account state object to interact with
@@ -914,18 +917,17 @@ type PublicTransactionPoolAPI struct {
}
// NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool.
-func NewPublicTransactionPoolAPI(e *Ethereum, gpo *GasPriceOracle) *PublicTransactionPoolAPI {
+func NewPublicTransactionPoolAPI(e *Ethereum) *PublicTransactionPoolAPI {
api := &PublicTransactionPoolAPI{
- eventMux: e.EventMux(),
- gpo: gpo,
- chainDb: e.ChainDb(),
- bc: e.BlockChain(),
- am: e.AccountManager(),
- txPool: e.TxPool(),
- miner: e.Miner(),
+ eventMux: e.eventMux,
+ gpo: e.gpo,
+ chainDb: e.chainDb,
+ bc: e.blockchain,
+ am: e.accountManager,
+ txPool: e.txPool,
+ miner: e.miner,
pendingTxSubs: make(map[string]rpc.Subscription),
}
-
go api.subscriptionLoop()
return api
diff --git a/eth/backend.go b/eth/backend.go
index 76cf8783b..9722e9625 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -119,6 +119,7 @@ type Ethereum struct {
protocolManager *ProtocolManager
SolcPath string
solc *compiler.Solidity
+ gpo *GasPriceOracle
GpoMinGasPrice *big.Int
GpoMaxGasPrice *big.Int
@@ -260,6 +261,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
}
return nil, err
}
+ eth.gpo = NewGasPriceOracle(eth)
+
newPool := core.NewTxPool(eth.chainConfig, eth.EventMux(), eth.blockchain.State, eth.blockchain.GasLimit)
eth.txPool = newPool
@@ -276,34 +279,31 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
// APIs returns the collection of RPC services the ethereum package offers.
// NOTE, some of these services probably need to be moved to somewhere else.
func (s *Ethereum) APIs() []rpc.API {
- // share gas price oracle in API's
- gpo := NewGasPriceOracle(s)
-
return []rpc.API{
{
Namespace: "eth",
Version: "1.0",
- Service: NewPublicEthereumAPI(s, gpo),
+ Service: NewPublicEthereumAPI(s),
Public: true,
}, {
Namespace: "eth",
Version: "1.0",
- Service: NewPublicAccountAPI(s.AccountManager()),
+ Service: NewPublicAccountAPI(s.accountManager),
Public: true,
}, {
Namespace: "personal",
Version: "1.0",
- Service: NewPrivateAccountAPI(s.AccountManager()),
+ Service: NewPrivateAccountAPI(s.accountManager),
Public: false,
}, {
Namespace: "eth",
Version: "1.0",
- Service: NewPublicBlockChainAPI(s.chainConfig, s.BlockChain(), s.Miner(), s.ChainDb(), gpo, s.EventMux(), s.AccountManager()),
+ Service: NewPublicBlockChainAPI(s.chainConfig, s.blockchain, s.miner, s.chainDb, s.gpo, s.eventMux, s.accountManager),
Public: true,
}, {
Namespace: "eth",
Version: "1.0",
- Service: NewPublicTransactionPoolAPI(s, gpo),
+ Service: NewPublicTransactionPoolAPI(s),
Public: true,
}, {
Namespace: "eth",
@@ -313,7 +313,7 @@ func (s *Ethereum) APIs() []rpc.API {
}, {
Namespace: "eth",
Version: "1.0",
- Service: downloader.NewPublicDownloaderAPI(s.Downloader(), s.EventMux()),
+ Service: downloader.NewPublicDownloaderAPI(s.protocolManager.downloader, s.eventMux),
Public: true,
}, {
Namespace: "miner",
@@ -328,7 +328,7 @@ func (s *Ethereum) APIs() []rpc.API {
}, {
Namespace: "eth",
Version: "1.0",
- Service: filters.NewPublicFilterAPI(s.ChainDb(), s.EventMux()),
+ Service: filters.NewPublicFilterAPI(s.chainDb, s.eventMux),
Public: true,
}, {
Namespace: "admin",
@@ -351,7 +351,7 @@ func (s *Ethereum) APIs() []rpc.API {
}, {
Namespace: "admin",
Version: "1.0",
- Service: ethreg.NewPrivateRegistarAPI(s.chainConfig, s.BlockChain(), s.ChainDb(), s.TxPool(), s.AccountManager()),
+ Service: ethreg.NewPrivateRegistarAPI(s.chainConfig, s.blockchain, s.chainDb, s.txPool, s.accountManager),
},
}
}
diff --git a/eth/bind.go b/eth/bind.go
new file mode 100644
index 000000000..3a3eca062
--- /dev/null
+++ b/eth/bind.go
@@ -0,0 +1,110 @@
+// Copyright 2016 The go-ethereum Authors
+// This file is part of the go-ethereum library.
+//
+// The go-ethereum library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Lesser General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// The go-ethereum library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
+
+package eth
+
+import (
+ "math/big"
+
+ "github.com/ethereum/go-ethereum/accounts/abi/bind"
+ "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/rlp"
+ "github.com/ethereum/go-ethereum/rpc"
+)
+
+// ContractBackend implements bind.ContractBackend with direct calls to Ethereum
+// internals to support operating on contracts within subprotocols like eth and
+// swarm.
+//
+// Internally this backend uses the already exposed API endpoints of the Ethereum
+// object. These should be rewritten to internal Go method calls when the Go API
+// is refactored to support a clean library use.
+type ContractBackend struct {
+ eapi *PublicEthereumAPI // Wrapper around the Ethereum object to access metadata
+ bcapi *PublicBlockChainAPI // Wrapper around the blockchain to access chain data
+ txapi *PublicTransactionPoolAPI // Wrapper around the transaction pool to access transaction data
+}
+
+// NewContractBackend creates a new native contract backend using an existing
+// Etheruem object.
+func NewContractBackend(eth *Ethereum) *ContractBackend {
+ return &ContractBackend{
+ eapi: NewPublicEthereumAPI(eth),
+ bcapi: NewPublicBlockChainAPI(eth.chainConfig, eth.blockchain, eth.miner, eth.chainDb, eth.gpo, eth.eventMux, eth.accountManager),
+ txapi: NewPublicTransactionPoolAPI(eth),
+ }
+}
+
+// ContractCall implements bind.ContractCaller executing an Ethereum contract
+// call with the specified data as the input. The pending flag requests execution
+// against the pending block, not the stable head of the chain.
+func (b *ContractBackend) ContractCall(contract common.Address, data []byte, pending bool) ([]byte, error) {
+ // Convert the input args to the API spec
+ args := CallArgs{
+ To: &contract,
+ Data: common.ToHex(data),
+ }
+ block := rpc.LatestBlockNumber
+ if pending {
+ block = rpc.PendingBlockNumber
+ }
+ // Execute the call and convert the output back to Go types
+ out, err := b.bcapi.Call(args, block)
+ if err == errNoCode {
+ err = bind.ErrNoCode
+ }
+ return common.FromHex(out), err
+}
+
+// PendingAccountNonce implements bind.ContractTransactor retrieving the current
+// pending nonce associated with an account.
+func (b *ContractBackend) PendingAccountNonce(account common.Address) (uint64, error) {
+ out, err := b.txapi.GetTransactionCount(account, rpc.PendingBlockNumber)
+ return out.Uint64(), err
+}
+
+// SuggestGasPrice implements bind.ContractTransactor retrieving the currently
+// suggested gas price to allow a timely execution of a transaction.
+func (b *ContractBackend) SuggestGasPrice() (*big.Int, error) {
+ return b.eapi.GasPrice(), nil
+}
+
+// EstimateGasLimit implements bind.ContractTransactor triing 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 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.
+func (b *ContractBackend) EstimateGasLimit(sender common.Address, contract *common.Address, value *big.Int, data []byte) (*big.Int, error) {
+ out, err := b.bcapi.EstimateGas(CallArgs{
+ From: sender,
+ To: contract,
+ Value: *rpc.NewHexNumber(value),
+ Data: common.ToHex(data),
+ })
+ if err == errNoCode {
+ err = bind.ErrNoCode
+ }
+ return out.BigInt(), err
+}
+
+// SendTransaction implements bind.ContractTransactor injects the transaction
+// into the pending pool for execution.
+func (b *ContractBackend) SendTransaction(tx *types.Transaction) error {
+ raw, _ := rlp.EncodeToBytes(tx)
+ _, err := b.txapi.SendRawTransaction(common.ToHex(raw))
+ return err
+}