Skip to content

Commit

Permalink
rpc: remove HexNumber, replace all uses with hexutil types
Browse files Browse the repository at this point in the history
This change couldn't be automated because HexNumber was used for numbers
of all sizes.
  • Loading branch information
fjl committed Dec 20, 2016
1 parent adab2e1 commit cf71f5c
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 534 deletions.
32 changes: 15 additions & 17 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
}

Expand All @@ -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
Expand All @@ -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
}

Expand Down
16 changes: 10 additions & 6 deletions eth/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit cf71f5c

Please sign in to comment.