Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
1609df32
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1609df32
编写于
11月 28, 2016
作者:
F
Felix Lange
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ethclient: use package hexutil for JSON handling
上级
24f28877
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
35 addition
and
34 deletion
+35
-34
ethclient/ethclient.go
ethclient/ethclient.go
+35
-34
未找到文件。
ethclient/ethclient.go
浏览文件 @
1609df32
...
...
@@ -24,6 +24,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/core/vm"
"github.com/ethereum/go-ethereum/rlp"
...
...
@@ -156,9 +157,9 @@ func (ec *Client) TransactionByHash(ctx context.Context, hash common.Hash) (*typ
// TransactionCount returns the total number of transactions in the given block.
func
(
ec
*
Client
)
TransactionCount
(
ctx
context
.
Context
,
blockHash
common
.
Hash
)
(
uint
,
error
)
{
var
num
rpc
.
HexNumber
var
num
hexutil
.
Uint
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
num
,
"eth_getBlockTransactionCountByHash"
,
blockHash
)
return
num
.
Uint
(
),
err
return
uint
(
num
),
err
}
// TransactionInBlock returns a single transaction at index in the given block.
...
...
@@ -196,11 +197,11 @@ func toBlockNumArg(number *big.Int) string {
}
type
rpcProgress
struct
{
StartingBlock
rpc
.
HexNumber
CurrentBlock
rpc
.
HexNumber
HighestBlock
rpc
.
HexNumber
PulledStates
rpc
.
HexNumber
KnownStates
rpc
.
HexNumber
StartingBlock
hexutil
.
Uint64
CurrentBlock
hexutil
.
Uint64
HighestBlock
hexutil
.
Uint64
PulledStates
hexutil
.
Uint64
KnownStates
hexutil
.
Uint64
}
// SyncProgress retrieves the current progress of the sync algorithm. If there's
...
...
@@ -220,11 +221,11 @@ func (ec *Client) SyncProgress(ctx context.Context) (*ethereum.SyncProgress, err
return
nil
,
err
}
return
&
ethereum
.
SyncProgress
{
StartingBlock
:
progress
.
StartingBlock
.
Uint64
(
),
CurrentBlock
:
progress
.
CurrentBlock
.
Uint64
(
),
HighestBlock
:
progress
.
HighestBlock
.
Uint64
(
),
PulledStates
:
progress
.
PulledStates
.
Uint64
(
),
KnownStates
:
progress
.
KnownStates
.
Uint64
(
),
StartingBlock
:
uint64
(
progress
.
StartingBlock
),
CurrentBlock
:
uint64
(
progress
.
CurrentBlock
),
HighestBlock
:
uint64
(
progress
.
HighestBlock
),
PulledStates
:
uint64
(
progress
.
PulledStates
),
KnownStates
:
uint64
(
progress
.
KnownStates
),
},
nil
}
...
...
@@ -239,7 +240,7 @@ func (ec *Client) SubscribeNewHead(ctx context.Context, ch chan<- *types.Header)
// BalanceAt returns the wei balance of the given account.
// The block number can be nil, in which case the balance is taken from the latest known block.
func
(
ec
*
Client
)
BalanceAt
(
ctx
context
.
Context
,
account
common
.
Address
,
blockNumber
*
big
.
Int
)
(
*
big
.
Int
,
error
)
{
var
result
rpc
.
HexNumber
var
result
hexutil
.
Big
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
result
,
"eth_getBalance"
,
account
,
toBlockNumArg
(
blockNumber
))
return
(
*
big
.
Int
)(
&
result
),
err
}
...
...
@@ -247,7 +248,7 @@ func (ec *Client) BalanceAt(ctx context.Context, account common.Address, blockNu
// StorageAt returns the value of key in the contract storage of the given account.
// The block number can be nil, in which case the value is taken from the latest known block.
func
(
ec
*
Client
)
StorageAt
(
ctx
context
.
Context
,
account
common
.
Address
,
key
common
.
Hash
,
blockNumber
*
big
.
Int
)
([]
byte
,
error
)
{
var
result
rpc
.
Hex
Bytes
var
result
hexutil
.
Bytes
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
result
,
"eth_getStorageAt"
,
account
,
key
,
toBlockNumArg
(
blockNumber
))
return
result
,
err
}
...
...
@@ -255,7 +256,7 @@ func (ec *Client) StorageAt(ctx context.Context, account common.Address, key com
// CodeAt returns the contract code of the given account.
// The block number can be nil, in which case the code is taken from the latest known block.
func
(
ec
*
Client
)
CodeAt
(
ctx
context
.
Context
,
account
common
.
Address
,
blockNumber
*
big
.
Int
)
([]
byte
,
error
)
{
var
result
rpc
.
Hex
Bytes
var
result
hexutil
.
Bytes
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
result
,
"eth_getCode"
,
account
,
toBlockNumArg
(
blockNumber
))
return
result
,
err
}
...
...
@@ -263,9 +264,9 @@ func (ec *Client) CodeAt(ctx context.Context, account common.Address, blockNumbe
// NonceAt returns the account nonce of the given account.
// The block number can be nil, in which case the nonce is taken from the latest known block.
func
(
ec
*
Client
)
NonceAt
(
ctx
context
.
Context
,
account
common
.
Address
,
blockNumber
*
big
.
Int
)
(
uint64
,
error
)
{
var
result
rpc
.
HexNumber
var
result
hexutil
.
Uint64
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
result
,
"eth_getTransactionCount"
,
account
,
toBlockNumArg
(
blockNumber
))
return
result
.
Uint64
(
),
err
return
uint64
(
result
),
err
}
// Filters
...
...
@@ -299,21 +300,21 @@ func toFilterArg(q ethereum.FilterQuery) interface{} {
// PendingBalanceAt returns the wei balance of the given account in the pending state.
func
(
ec
*
Client
)
PendingBalanceAt
(
ctx
context
.
Context
,
account
common
.
Address
)
(
*
big
.
Int
,
error
)
{
var
result
rpc
.
HexNumber
var
result
hexutil
.
Big
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
result
,
"eth_getBalance"
,
account
,
"pending"
)
return
(
*
big
.
Int
)(
&
result
),
err
}
// PendingStorageAt returns the value of key in the contract storage of the given account in the pending state.
func
(
ec
*
Client
)
PendingStorageAt
(
ctx
context
.
Context
,
account
common
.
Address
,
key
common
.
Hash
)
([]
byte
,
error
)
{
var
result
rpc
.
Hex
Bytes
var
result
hexutil
.
Bytes
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
result
,
"eth_getStorageAt"
,
account
,
key
,
"pending"
)
return
result
,
err
}
// PendingCodeAt returns the contract code of the given account in the pending state.
func
(
ec
*
Client
)
PendingCodeAt
(
ctx
context
.
Context
,
account
common
.
Address
)
([]
byte
,
error
)
{
var
result
rpc
.
Hex
Bytes
var
result
hexutil
.
Bytes
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
result
,
"eth_getCode"
,
account
,
"pending"
)
return
result
,
err
}
...
...
@@ -321,16 +322,16 @@ func (ec *Client) PendingCodeAt(ctx context.Context, account common.Address) ([]
// PendingNonceAt returns the account nonce of the given account in the pending state.
// This is the nonce that should be used for the next transaction.
func
(
ec
*
Client
)
PendingNonceAt
(
ctx
context
.
Context
,
account
common
.
Address
)
(
uint64
,
error
)
{
var
result
rpc
.
HexNumber
var
result
hexutil
.
Uint64
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
result
,
"eth_getTransactionCount"
,
account
,
"pending"
)
return
result
.
Uint64
(
),
err
return
uint64
(
result
),
err
}
// PendingTransactionCount returns the total number of transactions in the pending state.
func
(
ec
*
Client
)
PendingTransactionCount
(
ctx
context
.
Context
)
(
uint
,
error
)
{
var
num
rpc
.
HexNumber
var
num
hexutil
.
Uint
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
num
,
"eth_getBlockTransactionCountByNumber"
,
"pending"
)
return
num
.
Uint
(
),
err
return
uint
(
num
),
err
}
// TODO: SubscribePendingTransactions (needs server side)
...
...
@@ -344,29 +345,29 @@ func (ec *Client) PendingTransactionCount(ctx context.Context) (uint, error) {
// case the code is taken from the latest known block. Note that state from very old
// blocks might not be available.
func
(
ec
*
Client
)
CallContract
(
ctx
context
.
Context
,
msg
ethereum
.
CallMsg
,
blockNumber
*
big
.
Int
)
([]
byte
,
error
)
{
var
hex
string
var
hex
hexutil
.
Bytes
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
hex
,
"eth_call"
,
toCallArg
(
msg
),
toBlockNumArg
(
blockNumber
))
if
err
!=
nil
{
return
nil
,
err
}
return
common
.
FromHex
(
hex
)
,
nil
return
hex
,
nil
}
// PendingCallContract executes a message call transaction using the EVM.
// The state seen by the contract call is the pending state.
func
(
ec
*
Client
)
PendingCallContract
(
ctx
context
.
Context
,
msg
ethereum
.
CallMsg
)
([]
byte
,
error
)
{
var
hex
string
var
hex
hexutil
.
Bytes
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
hex
,
"eth_call"
,
toCallArg
(
msg
),
"pending"
)
if
err
!=
nil
{
return
nil
,
err
}
return
common
.
FromHex
(
hex
)
,
nil
return
hex
,
nil
}
// SuggestGasPrice retrieves the currently suggested gas price to allow a timely
// execution of a transaction.
func
(
ec
*
Client
)
SuggestGasPrice
(
ctx
context
.
Context
)
(
*
big
.
Int
,
error
)
{
var
hex
rpc
.
HexNumber
var
hex
hexutil
.
Big
if
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
hex
,
"eth_gasPrice"
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -378,7 +379,7 @@ func (ec *Client) SuggestGasPrice(ctx context.Context) (*big.Int, error) {
// 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
(
ec
*
Client
)
EstimateGas
(
ctx
context
.
Context
,
msg
ethereum
.
CallMsg
)
(
*
big
.
Int
,
error
)
{
var
hex
rpc
.
HexNumber
var
hex
hexutil
.
Big
err
:=
ec
.
c
.
CallContext
(
ctx
,
&
hex
,
"eth_estimateGas"
,
toCallArg
(
msg
))
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -404,16 +405,16 @@ func toCallArg(msg ethereum.CallMsg) interface{} {
"to"
:
msg
.
To
,
}
if
len
(
msg
.
Data
)
>
0
{
arg
[
"data"
]
=
fmt
.
Sprintf
(
"%#x"
,
msg
.
Data
)
arg
[
"data"
]
=
hexutil
.
Bytes
(
msg
.
Data
)
}
if
msg
.
Value
!=
nil
{
arg
[
"value"
]
=
fmt
.
Sprintf
(
"%#x"
,
msg
.
Value
)
arg
[
"value"
]
=
(
*
hexutil
.
Big
)(
msg
.
Value
)
}
if
msg
.
Gas
!=
nil
{
arg
[
"gas"
]
=
fmt
.
Sprintf
(
"%#x"
,
msg
.
Gas
)
arg
[
"gas"
]
=
(
*
hexutil
.
Big
)(
msg
.
Gas
)
}
if
msg
.
GasPrice
!=
nil
{
arg
[
"gasPrice"
]
=
fmt
.
Sprintf
(
"%#x"
,
msg
.
GasPrice
)
arg
[
"gasPrice"
]
=
(
*
hexutil
.
Big
)(
msg
.
GasPrice
)
}
return
arg
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录