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
51df765e
Commit
51df765e
authored
Mar 14, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #481 from maran/feature/fromHexDry
DRY-up the use of fromHex in the project
parents
b927c294
9754e7ac
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
76 additions
and
91 deletions
+76
-91
main.go
cmd/ethereum/main.go
+1
-1
common.go
ethutil/common.go
+13
-0
common_test.go
ethutil/common_test.go
+21
-0
api.go
rpc/api.go
+7
-7
util.go
rpc/util.go
+0
-13
util_test.go
rpc/util_test.go
+0
-25
whisper.go
ui/qt/qwhisper/whisper.go
+6
-12
state.go
xeth/state.go
+7
-4
types.go
xeth/types.go
+1
-10
whisper.go
xeth/whisper.go
+7
-6
xeth.go
xeth/xeth.go
+13
-13
No files found.
cmd/ethereum/main.go
View file @
51df765e
...
@@ -197,7 +197,7 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
...
@@ -197,7 +197,7 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
}
}
am
:=
eth
.
AccountManager
()
am
:=
eth
.
AccountManager
()
// Attempt to unlock the account
// Attempt to unlock the account
err
:=
am
.
Unlock
(
ethutil
.
Hex2Bytes
(
split
[
0
]),
split
[
1
])
err
:=
am
.
Unlock
(
ethutil
.
FromHex
(
split
[
0
]),
split
[
1
])
if
err
!=
nil
{
if
err
!=
nil
{
utils
.
Fatalf
(
"Unlock account failed '%v'"
,
err
)
utils
.
Fatalf
(
"Unlock account failed '%v'"
,
err
)
}
}
...
...
ethutil/common.go
View file @
51df765e
...
@@ -64,6 +64,19 @@ func DefaultDataDir() string {
...
@@ -64,6 +64,19 @@ func DefaultDataDir() string {
return
path
.
Join
(
usr
.
HomeDir
,
".ethereum"
)
return
path
.
Join
(
usr
.
HomeDir
,
".ethereum"
)
}
}
}
}
func
FromHex
(
s
string
)
[]
byte
{
if
len
(
s
)
>
1
{
if
s
[
0
:
2
]
==
"0x"
{
s
=
s
[
2
:
]
}
if
len
(
s
)
%
2
==
1
{
s
=
"0"
+
s
}
return
Hex2Bytes
(
s
)
}
return
nil
}
func
IsWindows
()
bool
{
func
IsWindows
()
bool
{
return
runtime
.
GOOS
==
"windows"
return
runtime
.
GOOS
==
"windows"
}
}
...
...
ethutil/common_test.go
View file @
51df765e
package
ethutil
package
ethutil
import
(
import
(
"bytes"
"math/big"
"math/big"
"os"
"os"
"testing"
checker
"gopkg.in/check.v1"
checker
"gopkg.in/check.v1"
)
)
...
@@ -66,3 +68,22 @@ func (s *CommonSuite) TestLarge(c *checker.C) {
...
@@ -66,3 +68,22 @@ func (s *CommonSuite) TestLarge(c *checker.C) {
c
.
Assert
(
adalarge
,
checker
.
Equals
,
"10000E7 Einstein"
)
c
.
Assert
(
adalarge
,
checker
.
Equals
,
"10000E7 Einstein"
)
c
.
Assert
(
weilarge
,
checker
.
Equals
,
"100 Babbage"
)
c
.
Assert
(
weilarge
,
checker
.
Equals
,
"100 Babbage"
)
}
}
//fromHex
func
TestFromHex
(
t
*
testing
.
T
)
{
input
:=
"0x01"
expected
:=
[]
byte
{
1
}
result
:=
FromHex
(
input
)
if
bytes
.
Compare
(
expected
,
result
)
!=
0
{
t
.
Errorf
(
"Expected % x got % x"
,
expected
,
result
)
}
}
func
TestFromHexOddLength
(
t
*
testing
.
T
)
{
input
:=
"0x1"
expected
:=
[]
byte
{
1
}
result
:=
FromHex
(
input
)
if
bytes
.
Compare
(
expected
,
result
)
!=
0
{
t
.
Errorf
(
"Expected % x got % x"
,
expected
,
result
)
}
}
rpc/api.go
View file @
51df765e
...
@@ -241,7 +241,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error)
...
@@ -241,7 +241,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error)
// p.register[args.From] = append(p.register[args.From], args)
// p.register[args.From] = append(p.register[args.From], args)
//} else {
//} else {
/*
/*
account := accounts.Get(
f
romHex(args.From))
account := accounts.Get(
ethutil.F
romHex(args.From))
if account != nil {
if account != nil {
if account.Unlocked() {
if account.Unlocked() {
if !unlockAccount(account) {
if !unlockAccount(account) {
...
@@ -249,7 +249,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error)
...
@@ -249,7 +249,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error)
}
}
}
}
result, _ := account.Transact(
fromHex(args.To), fromHex(args.Value), fromHex(args.Gas), fromHex(args.GasPrice), f
romHex(args.Data))
result, _ := account.Transact(
ethutil.FromHex(args.To), ethutil.FromHex(args.Value), ethutil.FromHex(args.Gas), ethutil.FromHex(args.GasPrice), ethutil.F
romHex(args.Data))
if len(result) > 0 {
if len(result) > 0 {
*reply = toHex(result)
*reply = toHex(result)
}
}
...
@@ -480,7 +480,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
...
@@ -480,7 +480,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
*
reply
=
toHex
(
crypto
.
Sha3
(
f
romHex
(
args
.
Data
)))
*
reply
=
toHex
(
crypto
.
Sha3
(
ethutil
.
F
romHex
(
args
.
Data
)))
case
"web3_clientVersion"
:
case
"web3_clientVersion"
:
*
reply
=
p
.
xeth
()
.
Backend
()
.
Version
()
*
reply
=
p
.
xeth
()
.
Backend
()
.
Version
()
case
"net_version"
:
case
"net_version"
:
...
@@ -815,12 +815,12 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions {
...
@@ -815,12 +815,12 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions {
// Convert optional address slice/string to byte slice
// Convert optional address slice/string to byte slice
if
str
,
ok
:=
options
.
Address
.
(
string
);
ok
{
if
str
,
ok
:=
options
.
Address
.
(
string
);
ok
{
opts
.
Address
=
[][]
byte
{
f
romHex
(
str
)}
opts
.
Address
=
[][]
byte
{
ethutil
.
F
romHex
(
str
)}
}
else
if
slice
,
ok
:=
options
.
Address
.
([]
interface
{});
ok
{
}
else
if
slice
,
ok
:=
options
.
Address
.
([]
interface
{});
ok
{
bslice
:=
make
([][]
byte
,
len
(
slice
))
bslice
:=
make
([][]
byte
,
len
(
slice
))
for
i
,
addr
:=
range
slice
{
for
i
,
addr
:=
range
slice
{
if
saddr
,
ok
:=
addr
.
(
string
);
ok
{
if
saddr
,
ok
:=
addr
.
(
string
);
ok
{
bslice
[
i
]
=
f
romHex
(
saddr
)
bslice
[
i
]
=
ethutil
.
F
romHex
(
saddr
)
}
}
}
}
opts
.
Address
=
bslice
opts
.
Address
=
bslice
...
@@ -834,11 +834,11 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions {
...
@@ -834,11 +834,11 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions {
if
slice
,
ok
:=
topicDat
.
([]
interface
{});
ok
{
if
slice
,
ok
:=
topicDat
.
([]
interface
{});
ok
{
topics
[
i
]
=
make
([][]
byte
,
len
(
slice
))
topics
[
i
]
=
make
([][]
byte
,
len
(
slice
))
for
j
,
topic
:=
range
slice
{
for
j
,
topic
:=
range
slice
{
topics
[
i
][
j
]
=
f
romHex
(
topic
.
(
string
))
topics
[
i
][
j
]
=
ethutil
.
F
romHex
(
topic
.
(
string
))
}
}
}
else
if
str
,
ok
:=
topicDat
.
(
string
);
ok
{
}
else
if
str
,
ok
:=
topicDat
.
(
string
);
ok
{
topics
[
i
]
=
make
([][]
byte
,
1
)
topics
[
i
]
=
make
([][]
byte
,
1
)
topics
[
i
][
0
]
=
f
romHex
(
str
)
topics
[
i
][
0
]
=
ethutil
.
F
romHex
(
str
)
}
}
}
}
opts
.
Topics
=
topics
opts
.
Topics
=
topics
...
...
rpc/util.go
View file @
51df765e
...
@@ -128,19 +128,6 @@ func toHex(b []byte) string {
...
@@ -128,19 +128,6 @@ func toHex(b []byte) string {
return
"0x"
+
hex
return
"0x"
+
hex
}
}
func
fromHex
(
s
string
)
[]
byte
{
if
len
(
s
)
>
1
{
if
s
[
0
:
2
]
==
"0x"
{
s
=
s
[
2
:
]
}
if
len
(
s
)
%
2
==
1
{
s
=
"0"
+
s
}
return
ethutil
.
Hex2Bytes
(
s
)
}
return
nil
}
func
i2hex
(
n
int
)
string
{
func
i2hex
(
n
int
)
string
{
return
toHex
(
big
.
NewInt
(
int64
(
n
))
.
Bytes
())
return
toHex
(
big
.
NewInt
(
int64
(
n
))
.
Bytes
())
}
}
...
...
rpc/util_test.go
deleted
100644 → 0
View file @
b927c294
package
rpc
import
(
"bytes"
"testing"
)
//fromHex
func
TestFromHex
(
t
*
testing
.
T
)
{
input
:=
"0x01"
expected
:=
[]
byte
{
1
}
result
:=
fromHex
(
input
)
if
bytes
.
Compare
(
expected
,
result
)
!=
0
{
t
.
Errorf
(
"Expected % x got % x"
,
expected
,
result
)
}
}
func
TestFromHexOddLength
(
t
*
testing
.
T
)
{
input
:=
"0x1"
expected
:=
[]
byte
{
1
}
result
:=
fromHex
(
input
)
if
bytes
.
Compare
(
expected
,
result
)
!=
0
{
t
.
Errorf
(
"Expected % x got % x"
,
expected
,
result
)
}
}
ui/qt/qwhisper/whisper.go
View file @
51df765e
...
@@ -13,12 +13,6 @@ import (
...
@@ -13,12 +13,6 @@ import (
var
qlogger
=
logger
.
NewLogger
(
"QSHH"
)
var
qlogger
=
logger
.
NewLogger
(
"QSHH"
)
func
fromHex
(
s
string
)
[]
byte
{
if
len
(
s
)
>
1
{
return
ethutil
.
Hex2Bytes
(
s
[
2
:
])
}
return
nil
}
func
toHex
(
b
[]
byte
)
string
{
return
"0x"
+
ethutil
.
Bytes2Hex
(
b
)
}
func
toHex
(
b
[]
byte
)
string
{
return
"0x"
+
ethutil
.
Bytes2Hex
(
b
)
}
type
Whisper
struct
{
type
Whisper
struct
{
...
@@ -39,15 +33,15 @@ func (self *Whisper) SetView(view qml.Object) {
...
@@ -39,15 +33,15 @@ func (self *Whisper) SetView(view qml.Object) {
func
(
self
*
Whisper
)
Post
(
payload
[]
string
,
to
,
from
string
,
topics
[]
string
,
priority
,
ttl
uint32
)
{
func
(
self
*
Whisper
)
Post
(
payload
[]
string
,
to
,
from
string
,
topics
[]
string
,
priority
,
ttl
uint32
)
{
var
data
[]
byte
var
data
[]
byte
for
_
,
d
:=
range
payload
{
for
_
,
d
:=
range
payload
{
data
=
append
(
data
,
f
romHex
(
d
)
...
)
data
=
append
(
data
,
ethutil
.
F
romHex
(
d
)
...
)
}
}
pk
:=
crypto
.
ToECDSAPub
(
f
romHex
(
from
))
pk
:=
crypto
.
ToECDSAPub
(
ethutil
.
F
romHex
(
from
))
if
key
:=
self
.
Whisper
.
GetIdentity
(
pk
);
key
!=
nil
{
if
key
:=
self
.
Whisper
.
GetIdentity
(
pk
);
key
!=
nil
{
msg
:=
whisper
.
NewMessage
(
data
)
msg
:=
whisper
.
NewMessage
(
data
)
envelope
,
err
:=
msg
.
Seal
(
time
.
Duration
(
priority
*
100000
),
whisper
.
Opts
{
envelope
,
err
:=
msg
.
Seal
(
time
.
Duration
(
priority
*
100000
),
whisper
.
Opts
{
Ttl
:
time
.
Duration
(
ttl
)
*
time
.
Second
,
Ttl
:
time
.
Duration
(
ttl
)
*
time
.
Second
,
To
:
crypto
.
ToECDSAPub
(
f
romHex
(
to
)),
To
:
crypto
.
ToECDSAPub
(
ethutil
.
F
romHex
(
to
)),
From
:
key
,
From
:
key
,
Topics
:
whisper
.
TopicsFromString
(
topics
...
),
Topics
:
whisper
.
TopicsFromString
(
topics
...
),
})
})
...
@@ -76,7 +70,7 @@ func (self *Whisper) NewIdentity() string {
...
@@ -76,7 +70,7 @@ func (self *Whisper) NewIdentity() string {
}
}
func
(
self
*
Whisper
)
HasIdentity
(
key
string
)
bool
{
func
(
self
*
Whisper
)
HasIdentity
(
key
string
)
bool
{
return
self
.
Whisper
.
HasIdentity
(
crypto
.
ToECDSAPub
(
f
romHex
(
key
)))
return
self
.
Whisper
.
HasIdentity
(
crypto
.
ToECDSAPub
(
ethutil
.
F
romHex
(
key
)))
}
}
func
(
self
*
Whisper
)
Watch
(
opts
map
[
string
]
interface
{},
view
*
qml
.
Common
)
int
{
func
(
self
*
Whisper
)
Watch
(
opts
map
[
string
]
interface
{},
view
*
qml
.
Common
)
int
{
...
@@ -106,10 +100,10 @@ func (self *Whisper) Messages(id int) (messages *ethutil.List) {
...
@@ -106,10 +100,10 @@ func (self *Whisper) Messages(id int) (messages *ethutil.List) {
func
filterFromMap
(
opts
map
[
string
]
interface
{})
(
f
whisper
.
Filter
)
{
func
filterFromMap
(
opts
map
[
string
]
interface
{})
(
f
whisper
.
Filter
)
{
if
to
,
ok
:=
opts
[
"to"
]
.
(
string
);
ok
{
if
to
,
ok
:=
opts
[
"to"
]
.
(
string
);
ok
{
f
.
To
=
crypto
.
ToECDSAPub
(
f
romHex
(
to
))
f
.
To
=
crypto
.
ToECDSAPub
(
ethutil
.
F
romHex
(
to
))
}
}
if
from
,
ok
:=
opts
[
"from"
]
.
(
string
);
ok
{
if
from
,
ok
:=
opts
[
"from"
]
.
(
string
);
ok
{
f
.
From
=
crypto
.
ToECDSAPub
(
f
romHex
(
from
))
f
.
From
=
crypto
.
ToECDSAPub
(
ethutil
.
F
romHex
(
from
))
}
}
if
topicList
,
ok
:=
opts
[
"topics"
]
.
(
*
qml
.
List
);
ok
{
if
topicList
,
ok
:=
opts
[
"topics"
]
.
(
*
qml
.
List
);
ok
{
var
topics
[]
string
var
topics
[]
string
...
...
xeth/state.go
View file @
51df765e
package
xeth
package
xeth
import
"github.com/ethereum/go-ethereum/state"
import
(
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
)
type
State
struct
{
type
State
struct
{
xeth
*
XEth
xeth
*
XEth
...
@@ -16,7 +19,7 @@ func (self *State) State() *state.StateDB {
...
@@ -16,7 +19,7 @@ func (self *State) State() *state.StateDB {
}
}
func
(
self
*
State
)
Get
(
addr
string
)
*
Object
{
func
(
self
*
State
)
Get
(
addr
string
)
*
Object
{
return
&
Object
{
self
.
state
.
GetStateObject
(
f
romHex
(
addr
))}
return
&
Object
{
self
.
state
.
GetStateObject
(
ethutil
.
F
romHex
(
addr
))}
}
}
func
(
self
*
State
)
SafeGet
(
addr
string
)
*
Object
{
func
(
self
*
State
)
SafeGet
(
addr
string
)
*
Object
{
...
@@ -24,9 +27,9 @@ func (self *State) SafeGet(addr string) *Object {
...
@@ -24,9 +27,9 @@ func (self *State) SafeGet(addr string) *Object {
}
}
func
(
self
*
State
)
safeGet
(
addr
string
)
*
state
.
StateObject
{
func
(
self
*
State
)
safeGet
(
addr
string
)
*
state
.
StateObject
{
object
:=
self
.
state
.
GetStateObject
(
f
romHex
(
addr
))
object
:=
self
.
state
.
GetStateObject
(
ethutil
.
F
romHex
(
addr
))
if
object
==
nil
{
if
object
==
nil
{
object
=
state
.
NewStateObject
(
f
romHex
(
addr
),
self
.
xeth
.
eth
.
StateDb
())
object
=
state
.
NewStateObject
(
ethutil
.
F
romHex
(
addr
),
self
.
xeth
.
eth
.
StateDb
())
}
}
return
object
return
object
...
...
xeth/types.go
View file @
51df765e
...
@@ -17,15 +17,6 @@ import (
...
@@ -17,15 +17,6 @@ import (
func
toHex
(
b
[]
byte
)
string
{
func
toHex
(
b
[]
byte
)
string
{
return
"0x"
+
ethutil
.
Bytes2Hex
(
b
)
return
"0x"
+
ethutil
.
Bytes2Hex
(
b
)
}
}
func
fromHex
(
s
string
)
[]
byte
{
if
len
(
s
)
>
1
{
if
s
[
0
:
2
]
==
"0x"
{
s
=
s
[
2
:
]
}
return
ethutil
.
Hex2Bytes
(
s
)
}
return
nil
}
type
Object
struct
{
type
Object
struct
{
*
state
.
StateObject
*
state
.
StateObject
...
@@ -123,7 +114,7 @@ func (self *Block) ToString() string {
...
@@ -123,7 +114,7 @@ func (self *Block) ToString() string {
}
}
func
(
self
*
Block
)
GetTransaction
(
hash
string
)
*
Transaction
{
func
(
self
*
Block
)
GetTransaction
(
hash
string
)
*
Transaction
{
tx
:=
self
.
ref
.
Transaction
(
f
romHex
(
hash
))
tx
:=
self
.
ref
.
Transaction
(
ethutil
.
F
romHex
(
hash
))
if
tx
==
nil
{
if
tx
==
nil
{
return
nil
return
nil
}
}
...
...
xeth/whisper.go
View file @
51df765e
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"time"
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/whisper"
"github.com/ethereum/go-ethereum/whisper"
)
)
...
@@ -28,12 +29,12 @@ func (self *Whisper) Post(payload string, to, from string, topics []string, prio
...
@@ -28,12 +29,12 @@ func (self *Whisper) Post(payload string, to, from string, topics []string, prio
ttl
=
100
ttl
=
100
}
}
pk
:=
crypto
.
ToECDSAPub
(
f
romHex
(
from
))
pk
:=
crypto
.
ToECDSAPub
(
ethutil
.
F
romHex
(
from
))
if
key
:=
self
.
Whisper
.
GetIdentity
(
pk
);
key
!=
nil
||
len
(
from
)
==
0
{
if
key
:=
self
.
Whisper
.
GetIdentity
(
pk
);
key
!=
nil
||
len
(
from
)
==
0
{
msg
:=
whisper
.
NewMessage
(
f
romHex
(
payload
))
msg
:=
whisper
.
NewMessage
(
ethutil
.
F
romHex
(
payload
))
envelope
,
err
:=
msg
.
Seal
(
time
.
Duration
(
priority
*
100000
),
whisper
.
Opts
{
envelope
,
err
:=
msg
.
Seal
(
time
.
Duration
(
priority
*
100000
),
whisper
.
Opts
{
Ttl
:
time
.
Duration
(
ttl
)
*
time
.
Second
,
Ttl
:
time
.
Duration
(
ttl
)
*
time
.
Second
,
To
:
crypto
.
ToECDSAPub
(
f
romHex
(
to
)),
To
:
crypto
.
ToECDSAPub
(
ethutil
.
F
romHex
(
to
)),
From
:
key
,
From
:
key
,
Topics
:
whisper
.
TopicsFromString
(
topics
...
),
Topics
:
whisper
.
TopicsFromString
(
topics
...
),
})
})
...
@@ -59,13 +60,13 @@ func (self *Whisper) NewIdentity() string {
...
@@ -59,13 +60,13 @@ func (self *Whisper) NewIdentity() string {
}
}
func
(
self
*
Whisper
)
HasIdentity
(
key
string
)
bool
{
func
(
self
*
Whisper
)
HasIdentity
(
key
string
)
bool
{
return
self
.
Whisper
.
HasIdentity
(
crypto
.
ToECDSAPub
(
f
romHex
(
key
)))
return
self
.
Whisper
.
HasIdentity
(
crypto
.
ToECDSAPub
(
ethutil
.
F
romHex
(
key
)))
}
}
func
(
self
*
Whisper
)
Watch
(
opts
*
Options
)
int
{
func
(
self
*
Whisper
)
Watch
(
opts
*
Options
)
int
{
filter
:=
whisper
.
Filter
{
filter
:=
whisper
.
Filter
{
To
:
crypto
.
ToECDSAPub
(
f
romHex
(
opts
.
To
)),
To
:
crypto
.
ToECDSAPub
(
ethutil
.
F
romHex
(
opts
.
To
)),
From
:
crypto
.
ToECDSAPub
(
f
romHex
(
opts
.
From
)),
From
:
crypto
.
ToECDSAPub
(
ethutil
.
F
romHex
(
opts
.
From
)),
Topics
:
whisper
.
TopicsFromString
(
opts
.
Topics
...
),
Topics
:
whisper
.
TopicsFromString
(
opts
.
Topics
...
),
}
}
...
...
xeth/xeth.go
View file @
51df765e
...
@@ -116,21 +116,21 @@ func (self *XEth) State() *State { return self.state }
...
@@ -116,21 +116,21 @@ func (self *XEth) State() *State { return self.state }
func
(
self
*
XEth
)
Whisper
()
*
Whisper
{
return
self
.
whisper
}
func
(
self
*
XEth
)
Whisper
()
*
Whisper
{
return
self
.
whisper
}
func
(
self
*
XEth
)
BlockByHash
(
strHash
string
)
*
Block
{
func
(
self
*
XEth
)
BlockByHash
(
strHash
string
)
*
Block
{
hash
:=
f
romHex
(
strHash
)
hash
:=
ethutil
.
F
romHex
(
strHash
)
block
:=
self
.
chainManager
.
GetBlock
(
hash
)
block
:=
self
.
chainManager
.
GetBlock
(
hash
)
return
NewBlock
(
block
)
return
NewBlock
(
block
)
}
}
func
(
self
*
XEth
)
EthBlockByHash
(
strHash
string
)
*
types
.
Block
{
func
(
self
*
XEth
)
EthBlockByHash
(
strHash
string
)
*
types
.
Block
{
hash
:=
f
romHex
(
strHash
)
hash
:=
ethutil
.
F
romHex
(
strHash
)
block
:=
self
.
chainManager
.
GetBlock
(
hash
)
block
:=
self
.
chainManager
.
GetBlock
(
hash
)
return
block
return
block
}
}
func
(
self
*
XEth
)
EthTransactionByHash
(
hash
string
)
*
types
.
Transaction
{
func
(
self
*
XEth
)
EthTransactionByHash
(
hash
string
)
*
types
.
Transaction
{
data
,
_
:=
self
.
eth
.
ExtraDb
()
.
Get
(
f
romHex
(
hash
))
data
,
_
:=
self
.
eth
.
ExtraDb
()
.
Get
(
ethutil
.
F
romHex
(
hash
))
if
len
(
data
)
!=
0
{
if
len
(
data
)
!=
0
{
return
types
.
NewTransactionFromBytes
(
data
)
return
types
.
NewTransactionFromBytes
(
data
)
}
}
...
@@ -233,7 +233,7 @@ func (self *XEth) IsContract(address string) bool {
...
@@ -233,7 +233,7 @@ func (self *XEth) IsContract(address string) bool {
}
}
func
(
self
*
XEth
)
SecretToAddress
(
key
string
)
string
{
func
(
self
*
XEth
)
SecretToAddress
(
key
string
)
string
{
pair
,
err
:=
crypto
.
NewKeyPairFromSec
(
f
romHex
(
key
))
pair
,
err
:=
crypto
.
NewKeyPairFromSec
(
ethutil
.
F
romHex
(
key
))
if
err
!=
nil
{
if
err
!=
nil
{
return
""
return
""
}
}
...
@@ -273,7 +273,7 @@ func (self *XEth) FromAscii(str string) string {
...
@@ -273,7 +273,7 @@ func (self *XEth) FromAscii(str string) string {
str
=
str
[
2
:
]
str
=
str
[
2
:
]
}
}
return
string
(
bytes
.
Trim
(
f
romHex
(
str
),
"
\x00
"
))
return
string
(
bytes
.
Trim
(
ethutil
.
F
romHex
(
str
),
"
\x00
"
))
}
}
func
(
self
*
XEth
)
FromNumber
(
str
string
)
string
{
func
(
self
*
XEth
)
FromNumber
(
str
string
)
string
{
...
@@ -281,11 +281,11 @@ func (self *XEth) FromNumber(str string) string {
...
@@ -281,11 +281,11 @@ func (self *XEth) FromNumber(str string) string {
str
=
str
[
2
:
]
str
=
str
[
2
:
]
}
}
return
ethutil
.
BigD
(
f
romHex
(
str
))
.
String
()
return
ethutil
.
BigD
(
ethutil
.
F
romHex
(
str
))
.
String
()
}
}
func
(
self
*
XEth
)
PushTx
(
encodedTx
string
)
(
string
,
error
)
{
func
(
self
*
XEth
)
PushTx
(
encodedTx
string
)
(
string
,
error
)
{
tx
:=
types
.
NewTransactionFromBytes
(
f
romHex
(
encodedTx
))
tx
:=
types
.
NewTransactionFromBytes
(
ethutil
.
F
romHex
(
encodedTx
))
err
:=
self
.
eth
.
TxPool
()
.
Add
(
tx
)
err
:=
self
.
eth
.
TxPool
()
.
Add
(
tx
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
...
@@ -306,12 +306,12 @@ var (
...
@@ -306,12 +306,12 @@ var (
func
(
self
*
XEth
)
Call
(
fromStr
,
toStr
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
(
string
,
error
)
{
func
(
self
*
XEth
)
Call
(
fromStr
,
toStr
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
(
string
,
error
)
{
statedb
:=
self
.
State
()
.
State
()
//self.chainManager.TransState()
statedb
:=
self
.
State
()
.
State
()
//self.chainManager.TransState()
msg
:=
callmsg
{
msg
:=
callmsg
{
from
:
statedb
.
GetOrNewStateObject
(
f
romHex
(
fromStr
)),
from
:
statedb
.
GetOrNewStateObject
(
ethutil
.
F
romHex
(
fromStr
)),
to
:
f
romHex
(
toStr
),
to
:
ethutil
.
F
romHex
(
toStr
),
gas
:
ethutil
.
Big
(
gasStr
),
gas
:
ethutil
.
Big
(
gasStr
),
gasPrice
:
ethutil
.
Big
(
gasPriceStr
),
gasPrice
:
ethutil
.
Big
(
gasPriceStr
),
value
:
ethutil
.
Big
(
valueStr
),
value
:
ethutil
.
Big
(
valueStr
),
data
:
f
romHex
(
dataStr
),
data
:
ethutil
.
F
romHex
(
dataStr
),
}
}
if
msg
.
gas
.
Cmp
(
big
.
NewInt
(
0
))
==
0
{
if
msg
.
gas
.
Cmp
(
big
.
NewInt
(
0
))
==
0
{
msg
.
gas
=
defaultGas
msg
.
gas
=
defaultGas
...
@@ -339,9 +339,9 @@ func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeSt
...
@@ -339,9 +339,9 @@ func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeSt
contractCreation
bool
contractCreation
bool
)
)
from
=
f
romHex
(
fromStr
)
from
=
ethutil
.
F
romHex
(
fromStr
)
data
=
f
romHex
(
codeStr
)
data
=
ethutil
.
F
romHex
(
codeStr
)
to
=
f
romHex
(
toStr
)
to
=
ethutil
.
F
romHex
(
toStr
)
if
len
(
to
)
==
0
{
if
len
(
to
)
==
0
{
contractCreation
=
true
contractCreation
=
true
}
}
...
...
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