Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
7330c97b
Commit
7330c97b
authored
Mar 16, 2015
by
Maran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRY up the use of toHex in the project and move it to common
parent
22893b7a
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
108 additions
and
113 deletions
+108
-113
common.go
common/common.go
+9
-0
api.go
rpc/api.go
+14
-14
responses.go
rpc/responses.go
+31
-30
util.go
rpc/util.go
+4
-13
whisper.go
ui/qt/qwhisper/whisper.go
+2
-4
types.go
xeth/types.go
+30
-34
whisper.go
xeth/whisper.go
+5
-5
xeth.go
xeth/xeth.go
+13
-13
No files found.
common/common.go
View file @
7330c97b
...
...
@@ -65,6 +65,15 @@ func DefaultDataDir() string {
}
}
func
ToHex
(
b
[]
byte
)
string
{
hex
:=
Bytes2Hex
(
b
)
// Prefer output of "0x0" instead of "0x"
if
len
(
hex
)
==
0
{
hex
=
"0"
}
return
"0x"
+
hex
}
func
FromHex
(
s
string
)
[]
byte
{
if
len
(
s
)
>
1
{
if
s
[
0
:
2
]
==
"0x"
{
...
...
rpc/api.go
View file @
7330c97b
...
...
@@ -9,11 +9,11 @@ import (
"sync"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/event/filter"
"github.com/ethereum/go-ethereum/state"
...
...
@@ -251,7 +251,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error)
result, _ := account.Transact(common.FromHex(args.To), common.FromHex(args.Value), common.FromHex(args.Gas), common.FromHex(args.GasPrice), common.FromHex(args.Data))
if len(result) > 0 {
*reply =
t
oHex(result)
*reply =
common.T
oHex(result)
}
} else if _, exists := p.register[args.From]; exists {
p.register[ags.From] = append(p.register[args.From], args)
...
...
@@ -291,7 +291,7 @@ func (p *EthereumApi) GetBalance(args *GetBalanceArgs, reply *interface{}) error
return
err
}
state
:=
p
.
getStateWithNum
(
args
.
BlockNumber
)
.
SafeGet
(
args
.
Address
)
*
reply
=
t
oHex
(
state
.
Balance
()
.
Bytes
())
*
reply
=
common
.
T
oHex
(
state
.
Balance
()
.
Bytes
())
return
nil
}
...
...
@@ -384,7 +384,7 @@ func (p *EthereumApi) NewWhisperFilter(args *WhisperFilterArgs, reply *interface
}
id
=
p
.
xeth
()
.
Whisper
()
.
Watch
(
opts
)
p
.
messages
[
id
]
=
&
whisperFilter
{
timeout
:
time
.
Now
()}
*
reply
=
t
oHex
(
big
.
NewInt
(
int64
(
id
))
.
Bytes
())
*
reply
=
common
.
T
oHex
(
big
.
NewInt
(
int64
(
id
))
.
Bytes
())
return
nil
}
...
...
@@ -480,7 +480,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
*
reply
=
t
oHex
(
crypto
.
Sha3
(
common
.
FromHex
(
args
.
Data
)))
*
reply
=
common
.
T
oHex
(
crypto
.
Sha3
(
common
.
FromHex
(
args
.
Data
)))
case
"web3_clientVersion"
:
*
reply
=
p
.
xeth
()
.
Backend
()
.
Version
()
case
"net_version"
:
...
...
@@ -488,7 +488,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
case
"net_listening"
:
*
reply
=
p
.
xeth
()
.
IsListening
()
case
"net_peerCount"
:
*
reply
=
t
oHex
(
big
.
NewInt
(
int64
(
p
.
xeth
()
.
PeerCount
()))
.
Bytes
())
*
reply
=
common
.
T
oHex
(
big
.
NewInt
(
int64
(
p
.
xeth
()
.
PeerCount
()))
.
Bytes
())
case
"eth_coinbase"
:
// TODO handling of empty coinbase due to lack of accounts
res
:=
p
.
xeth
()
.
Coinbase
()
...
...
@@ -500,11 +500,11 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
case
"eth_mining"
:
*
reply
=
p
.
xeth
()
.
IsMining
()
case
"eth_gasPrice"
:
*
reply
=
t
oHex
(
defaultGasPrice
.
Bytes
())
*
reply
=
common
.
T
oHex
(
defaultGasPrice
.
Bytes
())
case
"eth_accounts"
:
*
reply
=
p
.
xeth
()
.
Accounts
()
case
"eth_blockNumber"
:
*
reply
=
t
oHex
(
p
.
xeth
()
.
Backend
()
.
ChainManager
()
.
CurrentBlock
()
.
Number
()
.
Bytes
())
*
reply
=
common
.
T
oHex
(
p
.
xeth
()
.
Backend
()
.
ChainManager
()
.
CurrentBlock
()
.
Number
()
.
Bytes
())
case
"eth_getBalance"
:
args
:=
new
(
GetBalanceArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
...
...
@@ -539,7 +539,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
if
err
!=
nil
{
return
err
}
*
reply
=
t
oHex
(
big
.
NewInt
(
v
)
.
Bytes
())
*
reply
=
common
.
T
oHex
(
big
.
NewInt
(
v
)
.
Bytes
())
case
"eth_getBlockTransactionCountByNumber"
:
args
:=
new
(
GetBlockByNumberArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
...
...
@@ -550,7 +550,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
if
err
!=
nil
{
return
err
}
*
reply
=
t
oHex
(
big
.
NewInt
(
v
)
.
Bytes
())
*
reply
=
common
.
T
oHex
(
big
.
NewInt
(
v
)
.
Bytes
())
case
"eth_getUncleCountByBlockHash"
:
args
:=
new
(
GetBlockByHashArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
...
...
@@ -561,7 +561,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
if
err
!=
nil
{
return
err
}
*
reply
=
t
oHex
(
big
.
NewInt
(
v
)
.
Bytes
())
*
reply
=
common
.
T
oHex
(
big
.
NewInt
(
v
)
.
Bytes
())
case
"eth_getUncleCountByBlockNumber"
:
args
:=
new
(
GetBlockByNumberArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
...
...
@@ -572,7 +572,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
if
err
!=
nil
{
return
err
}
*
reply
=
t
oHex
(
big
.
NewInt
(
v
)
.
Bytes
())
*
reply
=
common
.
T
oHex
(
big
.
NewInt
(
v
)
.
Bytes
())
case
"eth_getData"
,
"eth_getCode"
:
args
:=
new
(
GetDataArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
...
...
@@ -663,7 +663,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
return
NewValidationError
(
"Index"
,
"does not exist"
)
}
uncle
,
err
:=
p
.
GetBlockByHash
(
t
oHex
(
v
.
Uncles
[
args
.
Index
]),
false
)
uncle
,
err
:=
p
.
GetBlockByHash
(
common
.
T
oHex
(
v
.
Uncles
[
args
.
Index
]),
false
)
if
err
!=
nil
{
return
err
}
...
...
@@ -682,7 +682,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
return
NewValidationError
(
"Index"
,
"does not exist"
)
}
uncle
,
err
:=
p
.
GetBlockByHash
(
t
oHex
(
v
.
Uncles
[
args
.
Index
]),
false
)
uncle
,
err
:=
p
.
GetBlockByHash
(
common
.
T
oHex
(
v
.
Uncles
[
args
.
Index
]),
false
)
if
err
!=
nil
{
return
err
}
...
...
rpc/responses.go
View file @
7330c97b
...
...
@@ -5,6 +5,7 @@ import (
// "fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
...
...
@@ -56,23 +57,23 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) {
}
// convert strict types to hexified strings
ext
.
BlockNumber
=
t
oHex
(
big
.
NewInt
(
b
.
BlockNumber
)
.
Bytes
())
ext
.
BlockHash
=
t
oHex
(
b
.
BlockHash
)
ext
.
ParentHash
=
t
oHex
(
b
.
ParentHash
)
ext
.
Nonce
=
t
oHex
(
b
.
Nonce
)
ext
.
Sha3Uncles
=
t
oHex
(
b
.
Sha3Uncles
)
ext
.
LogsBloom
=
t
oHex
(
b
.
LogsBloom
)
ext
.
TransactionRoot
=
t
oHex
(
b
.
TransactionRoot
)
ext
.
StateRoot
=
t
oHex
(
b
.
StateRoot
)
ext
.
Miner
=
t
oHex
(
b
.
Miner
)
ext
.
Difficulty
=
t
oHex
(
big
.
NewInt
(
b
.
Difficulty
)
.
Bytes
())
ext
.
TotalDifficulty
=
t
oHex
(
big
.
NewInt
(
b
.
TotalDifficulty
)
.
Bytes
())
ext
.
Size
=
t
oHex
(
big
.
NewInt
(
b
.
Size
)
.
Bytes
())
// ext.ExtraData =
t
oHex(b.ExtraData)
ext
.
GasLimit
=
t
oHex
(
big
.
NewInt
(
b
.
GasLimit
)
.
Bytes
())
// ext.MinGasPrice =
t
oHex(big.NewInt(b.MinGasPrice).Bytes())
ext
.
GasUsed
=
t
oHex
(
big
.
NewInt
(
b
.
GasUsed
)
.
Bytes
())
ext
.
UnixTimestamp
=
t
oHex
(
big
.
NewInt
(
b
.
UnixTimestamp
)
.
Bytes
())
ext
.
BlockNumber
=
common
.
T
oHex
(
big
.
NewInt
(
b
.
BlockNumber
)
.
Bytes
())
ext
.
BlockHash
=
common
.
T
oHex
(
b
.
BlockHash
)
ext
.
ParentHash
=
common
.
T
oHex
(
b
.
ParentHash
)
ext
.
Nonce
=
common
.
T
oHex
(
b
.
Nonce
)
ext
.
Sha3Uncles
=
common
.
T
oHex
(
b
.
Sha3Uncles
)
ext
.
LogsBloom
=
common
.
T
oHex
(
b
.
LogsBloom
)
ext
.
TransactionRoot
=
common
.
T
oHex
(
b
.
TransactionRoot
)
ext
.
StateRoot
=
common
.
T
oHex
(
b
.
StateRoot
)
ext
.
Miner
=
common
.
T
oHex
(
b
.
Miner
)
ext
.
Difficulty
=
common
.
T
oHex
(
big
.
NewInt
(
b
.
Difficulty
)
.
Bytes
())
ext
.
TotalDifficulty
=
common
.
T
oHex
(
big
.
NewInt
(
b
.
TotalDifficulty
)
.
Bytes
())
ext
.
Size
=
common
.
T
oHex
(
big
.
NewInt
(
b
.
Size
)
.
Bytes
())
// ext.ExtraData =
common.T
oHex(b.ExtraData)
ext
.
GasLimit
=
common
.
T
oHex
(
big
.
NewInt
(
b
.
GasLimit
)
.
Bytes
())
// ext.MinGasPrice =
common.T
oHex(big.NewInt(b.MinGasPrice).Bytes())
ext
.
GasUsed
=
common
.
T
oHex
(
big
.
NewInt
(
b
.
GasUsed
)
.
Bytes
())
ext
.
UnixTimestamp
=
common
.
T
oHex
(
big
.
NewInt
(
b
.
UnixTimestamp
)
.
Bytes
())
ext
.
Transactions
=
make
([]
interface
{},
len
(
b
.
Transactions
))
if
b
.
fullTx
{
for
i
,
tx
:=
range
b
.
Transactions
{
...
...
@@ -80,12 +81,12 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) {
}
}
else
{
for
i
,
tx
:=
range
b
.
Transactions
{
ext
.
Transactions
[
i
]
=
t
oHex
(
tx
.
Hash
)
ext
.
Transactions
[
i
]
=
common
.
T
oHex
(
tx
.
Hash
)
}
}
ext
.
Uncles
=
make
([]
string
,
len
(
b
.
Uncles
))
for
i
,
v
:=
range
b
.
Uncles
{
ext
.
Uncles
[
i
]
=
t
oHex
(
v
)
ext
.
Uncles
[
i
]
=
common
.
T
oHex
(
v
)
}
return
json
.
Marshal
(
ext
)
...
...
@@ -160,17 +161,17 @@ func (t *TransactionRes) MarshalJSON() ([]byte, error) {
Input
string
`json:"input"`
}
ext
.
Hash
=
t
oHex
(
t
.
Hash
)
ext
.
Nonce
=
t
oHex
(
big
.
NewInt
(
t
.
Nonce
)
.
Bytes
())
ext
.
BlockHash
=
t
oHex
(
t
.
BlockHash
)
ext
.
BlockNumber
=
t
oHex
(
big
.
NewInt
(
t
.
BlockNumber
)
.
Bytes
())
ext
.
TxIndex
=
t
oHex
(
big
.
NewInt
(
t
.
TxIndex
)
.
Bytes
())
ext
.
From
=
t
oHex
(
t
.
From
)
ext
.
To
=
t
oHex
(
t
.
To
)
ext
.
Value
=
t
oHex
(
big
.
NewInt
(
t
.
Value
)
.
Bytes
())
ext
.
Gas
=
t
oHex
(
big
.
NewInt
(
t
.
Gas
)
.
Bytes
())
ext
.
GasPrice
=
t
oHex
(
big
.
NewInt
(
t
.
GasPrice
)
.
Bytes
())
ext
.
Input
=
t
oHex
(
t
.
Input
)
ext
.
Hash
=
common
.
T
oHex
(
t
.
Hash
)
ext
.
Nonce
=
common
.
T
oHex
(
big
.
NewInt
(
t
.
Nonce
)
.
Bytes
())
ext
.
BlockHash
=
common
.
T
oHex
(
t
.
BlockHash
)
ext
.
BlockNumber
=
common
.
T
oHex
(
big
.
NewInt
(
t
.
BlockNumber
)
.
Bytes
())
ext
.
TxIndex
=
common
.
T
oHex
(
big
.
NewInt
(
t
.
TxIndex
)
.
Bytes
())
ext
.
From
=
common
.
T
oHex
(
t
.
From
)
ext
.
To
=
common
.
T
oHex
(
t
.
To
)
ext
.
Value
=
common
.
T
oHex
(
big
.
NewInt
(
t
.
Value
)
.
Bytes
())
ext
.
Gas
=
common
.
T
oHex
(
big
.
NewInt
(
t
.
Gas
)
.
Bytes
())
ext
.
GasPrice
=
common
.
T
oHex
(
big
.
NewInt
(
t
.
GasPrice
)
.
Bytes
())
ext
.
Input
=
common
.
T
oHex
(
t
.
Input
)
return
json
.
Marshal
(
ext
)
}
...
...
rpc/util.go
View file @
7330c97b
...
...
@@ -119,17 +119,8 @@ func (self JsonWrapper) ParseRequestBody(req *http.Request) (RpcRequest, error)
return
reqParsed
,
nil
}
func
toHex
(
b
[]
byte
)
string
{
hex
:=
common
.
Bytes2Hex
(
b
)
// Prefer output of "0x0" instead of "0x"
if
len
(
hex
)
==
0
{
hex
=
"0"
}
return
"0x"
+
hex
}
func
i2hex
(
n
int
)
string
{
return
t
oHex
(
big
.
NewInt
(
int64
(
n
))
.
Bytes
())
return
common
.
T
oHex
(
big
.
NewInt
(
int64
(
n
))
.
Bytes
())
}
type
RpcServer
interface
{
...
...
@@ -150,11 +141,11 @@ func toLogs(logs state.Logs) (ls []Log) {
for
i
,
log
:=
range
logs
{
var
l
Log
l
.
Topic
=
make
([]
string
,
len
(
log
.
Topics
()))
l
.
Address
=
t
oHex
(
log
.
Address
())
l
.
Data
=
t
oHex
(
log
.
Data
())
l
.
Address
=
common
.
T
oHex
(
log
.
Address
())
l
.
Data
=
common
.
T
oHex
(
log
.
Data
())
l
.
Number
=
log
.
Number
()
for
j
,
topic
:=
range
log
.
Topics
()
{
l
.
Topic
[
j
]
=
t
oHex
(
topic
)
l
.
Topic
[
j
]
=
common
.
T
oHex
(
topic
)
}
ls
[
i
]
=
l
}
...
...
ui/qt/qwhisper/whisper.go
View file @
7330c97b
...
...
@@ -4,8 +4,8 @@ package qwhisper
import
(
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/whisper"
"github.com/obscuren/qml"
...
...
@@ -13,8 +13,6 @@ import (
var
qlogger
=
logger
.
NewLogger
(
"QSHH"
)
func
toHex
(
b
[]
byte
)
string
{
return
"0x"
+
common
.
Bytes2Hex
(
b
)
}
type
Whisper
struct
{
*
whisper
.
Whisper
view
qml
.
Object
...
...
@@ -66,7 +64,7 @@ func (self *Whisper) Post(payload []string, to, from string, topics []string, pr
func
(
self
*
Whisper
)
NewIdentity
()
string
{
key
:=
self
.
Whisper
.
NewIdentity
()
return
t
oHex
(
crypto
.
FromECDSAPub
(
&
key
.
PublicKey
))
return
common
.
T
oHex
(
crypto
.
FromECDSAPub
(
&
key
.
PublicKey
))
}
func
(
self
*
Whisper
)
HasIdentity
(
key
string
)
bool
{
...
...
xeth/types.go
View file @
7330c97b
...
...
@@ -5,19 +5,15 @@ import (
"fmt"
"strings"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/state"
)
func
toHex
(
b
[]
byte
)
string
{
return
"0x"
+
common
.
Bytes2Hex
(
b
)
}
type
Object
struct
{
*
state
.
StateObject
}
...
...
@@ -49,7 +45,7 @@ func (self *Object) Storage() (storage map[string]string) {
for
it
.
Next
()
{
var
data
[]
byte
rlp
.
Decode
(
bytes
.
NewReader
(
it
.
Value
),
&
data
)
storage
[
toHex
(
it
.
Key
)]
=
t
oHex
(
data
)
storage
[
common
.
ToHex
(
it
.
Key
)]
=
common
.
T
oHex
(
data
)
}
return
...
...
@@ -59,19 +55,19 @@ func (self *Object) Storage() (storage map[string]string) {
type
Block
struct
{
//Transactions string `json:"transactions"`
ref
*
types
.
Block
Size
string
`json:"size"`
Number
int
`json:"number"`
Hash
string
`json:"hash"`
Size
string
`json:"size"`
Number
int
`json:"number"`
Hash
string
`json:"hash"`
Transactions
*
common
.
List
`json:"transactions"`
Uncles
*
common
.
List
`json:"uncles"`
Time
int64
`json:"time"`
Coinbase
string
`json:"coinbase"`
Name
string
`json:"name"`
GasLimit
string
`json:"gasLimit"`
GasUsed
string
`json:"gasUsed"`
PrevHash
string
`json:"prevHash"`
Bloom
string
`json:"bloom"`
Raw
string
`json:"raw"`
Time
int64
`json:"time"`
Coinbase
string
`json:"coinbase"`
Name
string
`json:"name"`
GasLimit
string
`json:"gasLimit"`
GasUsed
string
`json:"gasUsed"`
PrevHash
string
`json:"prevHash"`
Bloom
string
`json:"bloom"`
Raw
string
`json:"raw"`
}
// Creates a new QML Block from a chain block
...
...
@@ -95,12 +91,12 @@ func NewBlock(block *types.Block) *Block {
return
&
Block
{
ref
:
block
,
Size
:
block
.
Size
()
.
String
(),
Number
:
int
(
block
.
NumberU64
()),
GasUsed
:
block
.
GasUsed
()
.
String
(),
GasLimit
:
block
.
GasLimit
()
.
String
(),
Hash
:
t
oHex
(
block
.
Hash
()),
GasLimit
:
block
.
GasLimit
()
.
String
(),
Hash
:
common
.
T
oHex
(
block
.
Hash
()),
Transactions
:
txlist
,
Uncles
:
ulist
,
Time
:
block
.
Time
(),
Coinbase
:
t
oHex
(
block
.
Coinbase
()),
PrevHash
:
t
oHex
(
block
.
ParentHash
()),
Bloom
:
t
oHex
(
block
.
Bloom
()),
Coinbase
:
common
.
T
oHex
(
block
.
Coinbase
()),
PrevHash
:
common
.
T
oHex
(
block
.
ParentHash
()),
Bloom
:
common
.
T
oHex
(
block
.
Bloom
()),
Raw
:
block
.
String
(),
}
}
...
...
@@ -139,22 +135,22 @@ type Transaction struct {
}
func
NewTx
(
tx
*
types
.
Transaction
)
*
Transaction
{
hash
:=
t
oHex
(
tx
.
Hash
())
receiver
:=
t
oHex
(
tx
.
To
())
hash
:=
common
.
T
oHex
(
tx
.
Hash
())
receiver
:=
common
.
T
oHex
(
tx
.
To
())
if
len
(
receiver
)
==
0
{
receiver
=
t
oHex
(
core
.
AddressFromMessage
(
tx
))
receiver
=
common
.
T
oHex
(
core
.
AddressFromMessage
(
tx
))
}
sender
:=
t
oHex
(
tx
.
From
())
sender
:=
common
.
T
oHex
(
tx
.
From
())
createsContract
:=
core
.
MessageCreatesContract
(
tx
)
var
data
string
if
createsContract
{
data
=
strings
.
Join
(
core
.
Disassemble
(
tx
.
Data
()),
"
\n
"
)
}
else
{
data
=
t
oHex
(
tx
.
Data
())
data
=
common
.
T
oHex
(
tx
.
Data
())
}
return
&
Transaction
{
ref
:
tx
,
Hash
:
hash
,
Value
:
common
.
CurrencyToString
(
tx
.
Value
()),
Address
:
receiver
,
Contract
:
createsContract
,
Gas
:
tx
.
Gas
()
.
String
(),
GasPrice
:
tx
.
GasPrice
()
.
String
(),
Data
:
data
,
Sender
:
sender
,
CreatesContract
:
createsContract
,
RawData
:
t
oHex
(
tx
.
Data
())}
return
&
Transaction
{
ref
:
tx
,
Hash
:
hash
,
Value
:
common
.
CurrencyToString
(
tx
.
Value
()),
Address
:
receiver
,
Contract
:
createsContract
,
Gas
:
tx
.
Gas
()
.
String
(),
GasPrice
:
tx
.
GasPrice
()
.
String
(),
Data
:
data
,
Sender
:
sender
,
CreatesContract
:
createsContract
,
RawData
:
common
.
T
oHex
(
tx
.
Data
())}
}
func
(
self
*
Transaction
)
ToString
()
string
{
...
...
@@ -168,7 +164,7 @@ type Key struct {
}
func
NewKey
(
key
*
crypto
.
KeyPair
)
*
Key
{
return
&
Key
{
toHex
(
key
.
Address
()),
toHex
(
key
.
PrivateKey
),
t
oHex
(
key
.
PublicKey
)}
return
&
Key
{
common
.
ToHex
(
key
.
Address
()),
common
.
ToHex
(
key
.
PrivateKey
),
common
.
T
oHex
(
key
.
PublicKey
)}
}
type
PReceipt
struct
{
...
...
@@ -181,9 +177,9 @@ type PReceipt struct {
func
NewPReciept
(
contractCreation
bool
,
creationAddress
,
hash
,
address
[]
byte
)
*
PReceipt
{
return
&
PReceipt
{
contractCreation
,
t
oHex
(
creationAddress
),
t
oHex
(
hash
),
t
oHex
(
address
),
common
.
T
oHex
(
creationAddress
),
common
.
T
oHex
(
hash
),
common
.
T
oHex
(
address
),
}
}
...
...
@@ -220,8 +216,8 @@ type Receipt struct {
func
NewReciept
(
contractCreation
bool
,
creationAddress
,
hash
,
address
[]
byte
)
*
Receipt
{
return
&
Receipt
{
contractCreation
,
t
oHex
(
creationAddress
),
t
oHex
(
hash
),
t
oHex
(
address
),
common
.
T
oHex
(
creationAddress
),
common
.
T
oHex
(
hash
),
common
.
T
oHex
(
address
),
}
}
xeth/whisper.go
View file @
7330c97b
...
...
@@ -4,8 +4,8 @@ import (
"errors"
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/whisper"
)
...
...
@@ -56,7 +56,7 @@ func (self *Whisper) Post(payload string, to, from string, topics []string, prio
func
(
self
*
Whisper
)
NewIdentity
()
string
{
key
:=
self
.
Whisper
.
NewIdentity
()
return
t
oHex
(
crypto
.
FromECDSAPub
(
&
key
.
PublicKey
))
return
common
.
T
oHex
(
crypto
.
FromECDSAPub
(
&
key
.
PublicKey
))
}
func
(
self
*
Whisper
)
HasIdentity
(
key
string
)
bool
{
...
...
@@ -108,9 +108,9 @@ type WhisperMessage struct {
func
NewWhisperMessage
(
msg
*
whisper
.
Message
)
WhisperMessage
{
return
WhisperMessage
{
ref
:
msg
,
Payload
:
t
oHex
(
msg
.
Payload
),
From
:
t
oHex
(
crypto
.
FromECDSAPub
(
msg
.
Recover
())),
To
:
t
oHex
(
crypto
.
FromECDSAPub
(
msg
.
To
)),
Payload
:
common
.
T
oHex
(
msg
.
Payload
),
From
:
common
.
T
oHex
(
crypto
.
FromECDSAPub
(
msg
.
Recover
())),
To
:
common
.
T
oHex
(
crypto
.
FromECDSAPub
(
msg
.
To
)),
Sent
:
msg
.
Sent
,
}
}
xeth/xeth.go
View file @
7330c97b
...
...
@@ -8,10 +8,10 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p"
...
...
@@ -170,7 +170,7 @@ func (self *XEth) Accounts() []string {
accounts
,
_
:=
self
.
eth
.
AccountManager
()
.
Accounts
()
accountAddresses
:=
make
([]
string
,
len
(
accounts
))
for
i
,
ac
:=
range
accounts
{
accountAddresses
[
i
]
=
t
oHex
(
ac
.
Address
)
accountAddresses
[
i
]
=
common
.
T
oHex
(
ac
.
Address
)
}
return
accountAddresses
}
...
...
@@ -201,7 +201,7 @@ func (self *XEth) IsListening() bool {
func
(
self
*
XEth
)
Coinbase
()
string
{
cb
,
_
:=
self
.
eth
.
AccountManager
()
.
Coinbase
()
return
t
oHex
(
cb
)
return
common
.
T
oHex
(
cb
)
}
func
(
self
*
XEth
)
NumberToHuman
(
balance
string
)
string
{
...
...
@@ -213,7 +213,7 @@ func (self *XEth) NumberToHuman(balance string) string {
func
(
self
*
XEth
)
StorageAt
(
addr
,
storageAddr
string
)
string
{
storage
:=
self
.
State
()
.
SafeGet
(
addr
)
.
StorageString
(
storageAddr
)
return
t
oHex
(
storage
.
Bytes
())
return
common
.
T
oHex
(
storage
.
Bytes
())
}
func
(
self
*
XEth
)
BalanceAt
(
addr
string
)
string
{
...
...
@@ -225,7 +225,7 @@ func (self *XEth) TxCountAt(address string) int {
}
func
(
self
*
XEth
)
CodeAt
(
address
string
)
string
{
return
t
oHex
(
self
.
State
()
.
SafeGet
(
address
)
.
Code
())
return
common
.
T
oHex
(
self
.
State
()
.
SafeGet
(
address
)
.
Code
())
}
func
(
self
*
XEth
)
IsContract
(
address
string
)
bool
{
...
...
@@ -238,7 +238,7 @@ func (self *XEth) SecretToAddress(key string) string {
return
""
}
return
t
oHex
(
pair
.
Address
())
return
common
.
T
oHex
(
pair
.
Address
())
}
type
KeyVal
struct
{
...
...
@@ -251,7 +251,7 @@ func (self *XEth) EachStorage(addr string) string {
object
:=
self
.
State
()
.
SafeGet
(
addr
)
it
:=
object
.
Trie
()
.
Iterator
()
for
it
.
Next
()
{
values
=
append
(
values
,
KeyVal
{
toHex
(
it
.
Key
),
t
oHex
(
it
.
Value
)})
values
=
append
(
values
,
KeyVal
{
common
.
ToHex
(
it
.
Key
),
common
.
T
oHex
(
it
.
Value
)})
}
valuesJson
,
err
:=
json
.
Marshal
(
values
)
...
...
@@ -265,7 +265,7 @@ func (self *XEth) EachStorage(addr string) string {
func
(
self
*
XEth
)
ToAscii
(
str
string
)
string
{
padded
:=
common
.
RightPadBytes
([]
byte
(
str
),
32
)
return
"0x"
+
t
oHex
(
padded
)
return
"0x"
+
common
.
T
oHex
(
padded
)
}
func
(
self
*
XEth
)
FromAscii
(
str
string
)
string
{
...
...
@@ -293,9 +293,9 @@ func (self *XEth) PushTx(encodedTx string) (string, error) {
if
tx
.
To
()
==
nil
{
addr
:=
core
.
AddressFromMessage
(
tx
)
return
t
oHex
(
addr
),
nil
return
common
.
T
oHex
(
addr
),
nil
}
return
t
oHex
(
tx
.
Hash
()),
nil
return
common
.
T
oHex
(
tx
.
Hash
()),
nil
}
var
(
...
...
@@ -325,7 +325,7 @@ func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr st
vmenv
:=
core
.
NewEnv
(
statedb
,
self
.
chainManager
,
msg
,
block
)
res
,
err
:=
vmenv
.
Call
(
msg
.
from
,
msg
.
to
,
msg
.
data
,
msg
.
gas
,
msg
.
gasPrice
,
msg
.
value
)
return
t
oHex
(
res
),
err
return
common
.
T
oHex
(
res
),
err
}
func
(
self
*
XEth
)
Transact
(
fromStr
,
toStr
,
valueStr
,
gasStr
,
gasPriceStr
,
codeStr
string
)
(
string
,
error
)
{
...
...
@@ -371,9 +371,9 @@ func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeSt
}
if
types
.
IsContractAddr
(
to
)
{
return
t
oHex
(
core
.
AddressFromMessage
(
tx
)),
nil
return
common
.
T
oHex
(
core
.
AddressFromMessage
(
tx
)),
nil
}
return
t
oHex
(
tx
.
Hash
()),
nil
return
common
.
T
oHex
(
tx
.
Hash
()),
nil
}
func
(
self
*
XEth
)
sign
(
tx
*
types
.
Transaction
,
from
[]
byte
,
didUnlock
bool
)
error
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment