diff options
author | Felix Lange <fjl@twurst.com> | 2016-12-17 22:39:55 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-12-20 21:41:58 +0800 |
commit | cf71f5cd604f4d5c94d9e9b12b121a614d662dc7 (patch) | |
tree | a89491c26dc19fc39bb6d8273eeefa2778ff5ec2 /eth | |
parent | adab2e16bdf24c2eaf498722187fb36c04a5376b (diff) | |
download | go-tangerine-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.tar go-tangerine-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.tar.gz go-tangerine-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.tar.bz2 go-tangerine-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.tar.lz go-tangerine-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.tar.xz go-tangerine-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.tar.zst go-tangerine-cf71f5cd604f4d5c94d9e9b12b121a614d662dc7.zip |
rpc: remove HexNumber, replace all uses with hexutil types
This change couldn't be automated because HexNumber was used for numbers
of all sizes.
Diffstat (limited to 'eth')
-rw-r--r-- | eth/api.go | 32 | ||||
-rw-r--r-- | eth/bind.go | 16 |
2 files changed, 25 insertions, 23 deletions
diff --git a/eth/api.go b/eth/api.go index 2cc9c843d..6010d149c 100644 --- a/eth/api.go +++ b/eth/api.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/ethash" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" @@ -69,8 +70,8 @@ func (s *PublicEthereumAPI) Coinbase() (common.Address, error) { } // Hashrate returns the POW hashrate -func (s *PublicEthereumAPI) Hashrate() *rpc.HexNumber { - return rpc.NewHexNumber(s.e.Miner().HashRate()) +func (s *PublicEthereumAPI) Hashrate() hexutil.Uint64 { + return hexutil.Uint64(s.e.Miner().HashRate()) } // PublicMinerAPI provides an API to control the miner. @@ -95,8 +96,8 @@ func (s *PublicMinerAPI) Mining() bool { // SubmitWork can be used by external miner to submit their POW solution. It returns an indication if the work was // accepted. Note, this is not an indication if the provided work was valid! -func (s *PublicMinerAPI) SubmitWork(nonce rpc.HexNumber, solution, digest common.Hash) bool { - return s.agent.SubmitWork(nonce.Uint64(), digest, solution) +func (s *PublicMinerAPI) SubmitWork(nonce hexutil.Uint64, solution, digest common.Hash) bool { + return s.agent.SubmitWork(uint64(nonce), digest, solution) } // GetWork returns a work package for external miner. The work package consists of 3 strings @@ -119,8 +120,8 @@ func (s *PublicMinerAPI) GetWork() (work [3]string, err error) { // SubmitHashrate can be used for remote miners to submit their hash rate. This enables the node to report the combined // hash rate of all miners which submit work through this node. It accepts the miner hash rate and an identifier which // must be unique between nodes. -func (s *PublicMinerAPI) SubmitHashrate(hashrate rpc.HexNumber, id common.Hash) bool { - s.agent.SubmitHashrate(id, hashrate.Uint64()) +func (s *PublicMinerAPI) SubmitHashrate(hashrate hexutil.Uint64, id common.Hash) bool { + s.agent.SubmitHashrate(id, uint64(hashrate)) return true } @@ -137,18 +138,15 @@ func NewPrivateMinerAPI(e *Ethereum) *PrivateMinerAPI { // Start the miner with the given number of threads. If threads is nil the number of // workers started is equal to the number of logical CPU's that are usable by this process. -func (s *PrivateMinerAPI) Start(threads *rpc.HexNumber) (bool, error) { +func (s *PrivateMinerAPI) Start(threads *hexutil.Uint) (bool, error) { s.e.StartAutoDAG() - + var err error if threads == nil { - threads = rpc.NewHexNumber(runtime.NumCPU()) - } - - err := s.e.StartMining(threads.Int()) - if err == nil { - return true, nil + err = s.e.StartMining(runtime.NumCPU()) + } else { + err = s.e.StartMining(int(*threads)) } - return false, err + return err == nil, err } // Stop the miner @@ -166,8 +164,8 @@ func (s *PrivateMinerAPI) SetExtra(extra string) (bool, error) { } // SetGasPrice sets the minimum accepted gas price for the miner. -func (s *PrivateMinerAPI) SetGasPrice(gasPrice rpc.HexNumber) bool { - s.e.Miner().SetGasPrice(gasPrice.BigInt()) +func (s *PrivateMinerAPI) SetGasPrice(gasPrice hexutil.Big) bool { + s.e.Miner().SetGasPrice((*big.Int)(&gasPrice)) return true } diff --git a/eth/bind.go b/eth/bind.go index 747965d37..6f7aee4f7 100644 --- a/eth/bind.go +++ b/eth/bind.go @@ -21,6 +21,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/rlp" @@ -86,13 +87,13 @@ func toCallArgs(msg ethereum.CallMsg) ethapi.CallArgs { Data: common.ToHex(msg.Data), } if msg.Gas != nil { - args.Gas = *rpc.NewHexNumber(msg.Gas) + args.Gas = hexutil.Big(*msg.Gas) } if msg.GasPrice != nil { - args.GasPrice = *rpc.NewHexNumber(msg.GasPrice) + args.GasPrice = hexutil.Big(*msg.GasPrice) } if msg.Value != nil { - args.Value = *rpc.NewHexNumber(msg.Value) + args.Value = hexutil.Big(*msg.Value) } return args } @@ -106,9 +107,12 @@ func toBlockNumber(num *big.Int) rpc.BlockNumber { // PendingAccountNonce implements bind.ContractTransactor retrieving the current // pending nonce associated with an account. -func (b *ContractBackend) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error) { +func (b *ContractBackend) PendingNonceAt(ctx context.Context, account common.Address) (nonce uint64, err error) { out, err := b.txapi.GetTransactionCount(ctx, account, rpc.PendingBlockNumber) - return out.Uint64(), err + if out != nil { + nonce = uint64(*out) + } + return nonce, err } // SuggestGasPrice implements bind.ContractTransactor retrieving the currently @@ -124,7 +128,7 @@ func (b *ContractBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error) // should provide a basis for setting a reasonable default. func (b *ContractBackend) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (*big.Int, error) { out, err := b.bcapi.EstimateGas(ctx, toCallArgs(msg)) - return out.BigInt(), err + return out.ToInt(), err } // SendTransaction implements bind.ContractTransactor injects the transaction |