mirror of https://github.com/status-im/op-geth.git
Merge remote-tracking branch 'ethereum/conversion' into conversion
This commit is contained in:
commit
e13c673980
|
@ -26,12 +26,11 @@ RUN tar -C /usr/local -xzf go*.tar.gz && go version
|
||||||
ADD https://api.github.com/repos/ethereum/go-ethereum/git/refs/heads/develop file_does_not_exist
|
ADD https://api.github.com/repos/ethereum/go-ethereum/git/refs/heads/develop file_does_not_exist
|
||||||
|
|
||||||
## Fetch and install go-ethereum
|
## Fetch and install go-ethereum
|
||||||
RUN go get github.com/tools/godep
|
RUN mkdir -p $GOPATH/src/github.com/ethereum/
|
||||||
RUN go get -d github.com/ethereum/go-ethereum/...
|
RUN git clone https://github.com/ethereum/go-ethereum $GOPATH/src/github.com/ethereum/go-ethereum
|
||||||
WORKDIR $GOPATH/src/github.com/ethereum/go-ethereum
|
WORKDIR $GOPATH/src/github.com/ethereum/go-ethereum
|
||||||
RUN git checkout develop
|
RUN git checkout develop
|
||||||
RUN godep restore
|
RUN GOPATH=$GOPATH:$GOPATH/src/github.com/ethereum/go-ethereum/Godeps/_workspace go install -v ./cmd/ethereum
|
||||||
RUN go install -v ./cmd/ethereum
|
|
||||||
|
|
||||||
## Run & expose JSON RPC
|
## Run & expose JSON RPC
|
||||||
ENTRYPOINT ["ethereum", "-rpc=true", "-rpcport=8545"]
|
ENTRYPOINT ["ethereum", "-rpc=true", "-rpcport=8545"]
|
||||||
|
|
|
@ -30,6 +30,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/ethereum/ethash"
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
@ -41,7 +42,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ClientIdentifier = "Ethereum(G)"
|
ClientIdentifier = "Ethereum(G)"
|
||||||
Version = "0.9.1"
|
Version = "Frontier - 0.9.1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -54,6 +55,17 @@ func init() {
|
||||||
app.HideVersion = true // we have a command to print the version
|
app.HideVersion = true // we have a command to print the version
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []cli.Command{
|
||||||
blocktestCmd,
|
blocktestCmd,
|
||||||
|
{
|
||||||
|
Action: makedag,
|
||||||
|
Name: "makedag",
|
||||||
|
Usage: "generate ethash dag (for testing)",
|
||||||
|
Description: `
|
||||||
|
The makedag command generates an ethash DAG in /tmp/dag.
|
||||||
|
|
||||||
|
This command exists to support the system testing project.
|
||||||
|
Regular users do not need to execute it.
|
||||||
|
`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Action: version,
|
Action: version,
|
||||||
Name: "version",
|
Name: "version",
|
||||||
|
@ -136,8 +148,8 @@ The Ethereum JavaScript VM exposes a node admin interface as well as the DAPP Ja
|
||||||
utils.RPCPortFlag,
|
utils.RPCPortFlag,
|
||||||
utils.UnencryptedKeysFlag,
|
utils.UnencryptedKeysFlag,
|
||||||
utils.VMDebugFlag,
|
utils.VMDebugFlag,
|
||||||
|
utils.ProtocolVersionFlag,
|
||||||
//utils.VMTypeFlag,
|
utils.NetworkIdFlag,
|
||||||
}
|
}
|
||||||
|
|
||||||
// missing:
|
// missing:
|
||||||
|
@ -318,6 +330,15 @@ func dump(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makedag(ctx *cli.Context) {
|
||||||
|
chain, _, _ := utils.GetChain(ctx)
|
||||||
|
pow := ethash.New(chain)
|
||||||
|
fmt.Println("making cache")
|
||||||
|
pow.UpdateCache(true)
|
||||||
|
fmt.Println("making DAG")
|
||||||
|
pow.UpdateDAG()
|
||||||
|
}
|
||||||
|
|
||||||
func version(c *cli.Context) {
|
func version(c *cli.Context) {
|
||||||
fmt.Printf(`%v
|
fmt.Printf(`%v
|
||||||
Version: %v
|
Version: %v
|
||||||
|
@ -327,7 +348,7 @@ GO: %s
|
||||||
OS: %s
|
OS: %s
|
||||||
GOPATH=%s
|
GOPATH=%s
|
||||||
GOROOT=%s
|
GOROOT=%s
|
||||||
`, ClientIdentifier, Version, eth.ProtocolVersion, eth.NetworkId, runtime.Version(), runtime.GOOS, os.Getenv("GOPATH"), runtime.GOROOT())
|
`, ClientIdentifier, Version, c.GlobalInt(utils.ProtocolVersionFlag.Name), c.GlobalInt(utils.NetworkIdFlag.Name), runtime.Version(), runtime.GOOS, os.Getenv("GOPATH"), runtime.GOROOT())
|
||||||
}
|
}
|
||||||
|
|
||||||
// hashish returns true for strings that look like hashes.
|
// hashish returns true for strings that look like hashes.
|
||||||
|
|
|
@ -28,8 +28,8 @@ import (
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/ui/qt/webengine"
|
"github.com/ethereum/go-ethereum/ui/qt/webengine"
|
||||||
"github.com/obscuren/qml"
|
"github.com/obscuren/qml"
|
||||||
|
@ -66,6 +66,8 @@ func init() {
|
||||||
utils.RPCListenAddrFlag,
|
utils.RPCListenAddrFlag,
|
||||||
utils.RPCPortFlag,
|
utils.RPCPortFlag,
|
||||||
utils.JSpathFlag,
|
utils.JSpathFlag,
|
||||||
|
utils.ProtocolVersionFlag,
|
||||||
|
utils.NetworkIdFlag,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,11 @@ import (
|
||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/ethereum/go-ethereum/accounts"
|
"github.com/ethereum/go-ethereum/accounts"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/p2p/nat"
|
"github.com/ethereum/go-ethereum/p2p/nat"
|
||||||
|
@ -70,25 +70,23 @@ func NewApp(version, usage string) *cli.App {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// General settings
|
// General settings
|
||||||
/*
|
|
||||||
VMTypeFlag = cli.IntFlag{
|
|
||||||
Name: "vm",
|
|
||||||
Usage: "Virtual Machine type: 0 is standard VM, 1 is debug VM",
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
UnlockedAccountFlag = cli.StringFlag{
|
|
||||||
Name: "unlock",
|
|
||||||
Usage: "Unlock a given account untill this programs exits (address:password)",
|
|
||||||
}
|
|
||||||
VMDebugFlag = cli.BoolFlag{
|
|
||||||
Name: "vmdebug",
|
|
||||||
Usage: "Virtual Machine debug output",
|
|
||||||
}
|
|
||||||
DataDirFlag = cli.StringFlag{
|
DataDirFlag = cli.StringFlag{
|
||||||
Name: "datadir",
|
Name: "datadir",
|
||||||
Usage: "Data directory to be used",
|
Usage: "Data directory to be used",
|
||||||
Value: common.DefaultDataDir(),
|
Value: common.DefaultDataDir(),
|
||||||
}
|
}
|
||||||
|
ProtocolVersionFlag = cli.IntFlag{
|
||||||
|
Name: "protocolversion",
|
||||||
|
Usage: "ETH protocol version",
|
||||||
|
Value: eth.ProtocolVersion,
|
||||||
|
}
|
||||||
|
NetworkIdFlag = cli.IntFlag{
|
||||||
|
Name: "networkid",
|
||||||
|
Usage: "Network Id",
|
||||||
|
Value: eth.NetworkId,
|
||||||
|
}
|
||||||
|
|
||||||
|
// miner settings
|
||||||
MinerThreadsFlag = cli.IntFlag{
|
MinerThreadsFlag = cli.IntFlag{
|
||||||
Name: "minerthreads",
|
Name: "minerthreads",
|
||||||
Usage: "Number of miner threads",
|
Usage: "Number of miner threads",
|
||||||
|
@ -98,11 +96,18 @@ var (
|
||||||
Name: "mine",
|
Name: "mine",
|
||||||
Usage: "Enable mining",
|
Usage: "Enable mining",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// key settings
|
||||||
UnencryptedKeysFlag = cli.BoolFlag{
|
UnencryptedKeysFlag = cli.BoolFlag{
|
||||||
Name: "unencrypted-keys",
|
Name: "unencrypted-keys",
|
||||||
Usage: "disable private key disk encryption (for testing)",
|
Usage: "disable private key disk encryption (for testing)",
|
||||||
}
|
}
|
||||||
|
UnlockedAccountFlag = cli.StringFlag{
|
||||||
|
Name: "unlock",
|
||||||
|
Usage: "Unlock a given account untill this programs exits (address:password)",
|
||||||
|
}
|
||||||
|
|
||||||
|
// logging and debug settings
|
||||||
LogFileFlag = cli.StringFlag{
|
LogFileFlag = cli.StringFlag{
|
||||||
Name: "logfile",
|
Name: "logfile",
|
||||||
Usage: "Send log output to a file",
|
Usage: "Send log output to a file",
|
||||||
|
@ -117,6 +122,10 @@ var (
|
||||||
Usage: `"std" or "raw"`,
|
Usage: `"std" or "raw"`,
|
||||||
Value: "std",
|
Value: "std",
|
||||||
}
|
}
|
||||||
|
VMDebugFlag = cli.BoolFlag{
|
||||||
|
Name: "vmdebug",
|
||||||
|
Usage: "Virtual Machine debug output",
|
||||||
|
}
|
||||||
|
|
||||||
// RPC settings
|
// RPC settings
|
||||||
RPCEnabledFlag = cli.BoolFlag{
|
RPCEnabledFlag = cli.BoolFlag{
|
||||||
|
@ -198,21 +207,23 @@ func GetNodeKey(ctx *cli.Context) (key *ecdsa.PrivateKey) {
|
||||||
|
|
||||||
func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
|
func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
|
||||||
return ð.Config{
|
return ð.Config{
|
||||||
Name: common.MakeName(clientID, version),
|
Name: common.MakeName(clientID, version),
|
||||||
DataDir: ctx.GlobalString(DataDirFlag.Name),
|
DataDir: ctx.GlobalString(DataDirFlag.Name),
|
||||||
LogFile: ctx.GlobalString(LogFileFlag.Name),
|
ProtocolVersion: ctx.GlobalInt(ProtocolVersionFlag.Name),
|
||||||
LogLevel: ctx.GlobalInt(LogLevelFlag.Name),
|
NetworkId: ctx.GlobalInt(NetworkIdFlag.Name),
|
||||||
LogFormat: ctx.GlobalString(LogFormatFlag.Name),
|
LogFile: ctx.GlobalString(LogFileFlag.Name),
|
||||||
MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name),
|
LogLevel: ctx.GlobalInt(LogLevelFlag.Name),
|
||||||
AccountManager: GetAccountManager(ctx),
|
LogFormat: ctx.GlobalString(LogFormatFlag.Name),
|
||||||
VmDebug: ctx.GlobalBool(VMDebugFlag.Name),
|
MinerThreads: ctx.GlobalInt(MinerThreadsFlag.Name),
|
||||||
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
|
AccountManager: GetAccountManager(ctx),
|
||||||
Port: ctx.GlobalString(ListenPortFlag.Name),
|
VmDebug: ctx.GlobalBool(VMDebugFlag.Name),
|
||||||
NAT: GetNAT(ctx),
|
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
|
||||||
NodeKey: GetNodeKey(ctx),
|
Port: ctx.GlobalString(ListenPortFlag.Name),
|
||||||
Shh: true,
|
NAT: GetNAT(ctx),
|
||||||
Dial: true,
|
NodeKey: GetNodeKey(ctx),
|
||||||
BootNodes: ctx.GlobalString(BootnodesFlag.Name),
|
Shh: true,
|
||||||
|
Dial: true,
|
||||||
|
BootNodes: ctx.GlobalString(BootnodesFlag.Name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
func FromHex(s string) []byte {
|
||||||
if len(s) > 1 {
|
if len(s) > 1 {
|
||||||
if s[0:2] == "0x" {
|
if s[0:2] == "0x" {
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
// +build none
|
||||||
|
//sed -e 's/_N_/Hash/g' -e 's/_S_/32/g' -e '1d' types_template.go | gofmt -w hash.go
|
||||||
|
|
||||||
|
package common
|
||||||
|
|
||||||
|
import "math/big"
|
||||||
|
|
||||||
|
type _N_ [_S_]byte
|
||||||
|
|
||||||
|
func BytesTo_N_(b []byte) _N_ {
|
||||||
|
var h _N_
|
||||||
|
h.SetBytes(b)
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
func StringTo_N_(s string) _N_ { return BytesTo_N_([]byte(s)) }
|
||||||
|
func BigTo_N_(b *big.Int) _N_ { return BytesTo_N_(b.Bytes()) }
|
||||||
|
func HexTo_N_(s string) _N_ { return BytesTo_N_(FromHex(s)) }
|
||||||
|
|
||||||
|
// Don't use the default 'String' method in case we want to overwrite
|
||||||
|
|
||||||
|
// Get the string representation of the underlying hash
|
||||||
|
func (h _N_) Str() string { return string(h[:]) }
|
||||||
|
func (h _N_) Bytes() []byte { return h[:] }
|
||||||
|
func (h _N_) Big() *big.Int { return Bytes2Big(h[:]) }
|
||||||
|
func (h _N_) Hex() string { return "0x" + Bytes2Hex(h[:]) }
|
||||||
|
|
||||||
|
// Sets the hash to the value of b. If b is larger than len(h) it will panic
|
||||||
|
func (h *_N_) SetBytes(b []byte) {
|
||||||
|
// Use the right most bytes
|
||||||
|
if len(b) > len(h) {
|
||||||
|
b = b[len(b)-_S_:]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reverse the loop
|
||||||
|
for i := len(b) - 1; i >= 0; i-- {
|
||||||
|
h[_S_-len(b)+i] = b[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set string `s` to h. If s is larger than len(h) it will panic
|
||||||
|
func (h *_N_) SetString(s string) { h.SetBytes([]byte(s)) }
|
||||||
|
|
||||||
|
// Sets h to other
|
||||||
|
func (h *_N_) Set(other _N_) {
|
||||||
|
for i, v := range other {
|
||||||
|
h[i] = v
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,8 +38,8 @@ func CalcDifficulty(block, parent *types.Header) *big.Int {
|
||||||
diff.Sub(parent.Difficulty, adjust)
|
diff.Sub(parent.Difficulty, adjust)
|
||||||
}
|
}
|
||||||
|
|
||||||
if diff.Cmp(GenesisDiff) < 0 {
|
if diff.Cmp(min) < 0 {
|
||||||
return GenesisDiff
|
return min
|
||||||
}
|
}
|
||||||
|
|
||||||
return diff
|
return diff
|
||||||
|
|
|
@ -38,7 +38,10 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string
|
Name string
|
||||||
|
ProtocolVersion int
|
||||||
|
NetworkId int
|
||||||
|
|
||||||
DataDir string
|
DataDir string
|
||||||
LogFile string
|
LogFile string
|
||||||
LogLevel int
|
LogLevel int
|
||||||
|
@ -135,14 +138,16 @@ type Ethereum struct {
|
||||||
|
|
||||||
logger logger.LogSystem
|
logger logger.LogSystem
|
||||||
|
|
||||||
Mining bool
|
Mining bool
|
||||||
DataDir string
|
DataDir string
|
||||||
version string
|
version string
|
||||||
|
ProtocolVersion int
|
||||||
|
NetworkId int
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(config *Config) (*Ethereum, error) {
|
func New(config *Config) (*Ethereum, error) {
|
||||||
// Boostrap database
|
// Boostrap database
|
||||||
servlogger := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat)
|
servlogsystem := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat)
|
||||||
|
|
||||||
newdb := config.NewDB
|
newdb := config.NewDB
|
||||||
if newdb == nil {
|
if newdb == nil {
|
||||||
|
@ -159,13 +164,14 @@ func New(config *Config) (*Ethereum, error) {
|
||||||
extraDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "extra"))
|
extraDb, err := ethdb.NewLDBDatabase(path.Join(config.DataDir, "extra"))
|
||||||
|
|
||||||
// Perform database sanity checks
|
// Perform database sanity checks
|
||||||
d, _ := blockDb.Get([]byte("ProtocolVersion"))
|
d, _ := extraDb.Get([]byte("ProtocolVersion"))
|
||||||
protov := common.NewValue(d).Uint()
|
protov := int(common.NewValue(d).Uint())
|
||||||
if protov != ProtocolVersion && protov != 0 {
|
if protov != config.ProtocolVersion && protov != 0 {
|
||||||
path := path.Join(config.DataDir, "blockchain")
|
path := path.Join(config.DataDir, "blockchain")
|
||||||
return nil, fmt.Errorf("Database version mismatch. Protocol(%d / %d). `rm -rf %s`", protov, ProtocolVersion, path)
|
return nil, fmt.Errorf("Database version mismatch. Protocol(%d / %d). `rm -rf %s`", protov, config.ProtocolVersion, path)
|
||||||
}
|
}
|
||||||
saveProtocolVersion(extraDb)
|
saveProtocolVersion(extraDb, config.ProtocolVersion)
|
||||||
|
servlogger.Infof("Protocol Version: %v, Network Id: %v", config.ProtocolVersion, config.NetworkId)
|
||||||
|
|
||||||
eth := &Ethereum{
|
eth := &Ethereum{
|
||||||
shutdownChan: make(chan bool),
|
shutdownChan: make(chan bool),
|
||||||
|
@ -173,7 +179,7 @@ func New(config *Config) (*Ethereum, error) {
|
||||||
stateDb: stateDb,
|
stateDb: stateDb,
|
||||||
extraDb: extraDb,
|
extraDb: extraDb,
|
||||||
eventMux: &event.TypeMux{},
|
eventMux: &event.TypeMux{},
|
||||||
logger: servlogger,
|
logger: servlogsystem,
|
||||||
accountManager: config.AccountManager,
|
accountManager: config.AccountManager,
|
||||||
DataDir: config.DataDir,
|
DataDir: config.DataDir,
|
||||||
version: config.Name, // TODO should separate from Name
|
version: config.Name, // TODO should separate from Name
|
||||||
|
@ -195,7 +201,8 @@ func New(config *Config) (*Ethereum, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ethProto := EthProtocol(eth.txPool, eth.chainManager, eth.blockPool)
|
|
||||||
|
ethProto := EthProtocol(config.ProtocolVersion, config.NetworkId, eth.txPool, eth.chainManager, eth.blockPool)
|
||||||
protocols := []p2p.Protocol{ethProto}
|
protocols := []p2p.Protocol{ethProto}
|
||||||
if config.Shh {
|
if config.Shh {
|
||||||
protocols = append(protocols, eth.whisper.Protocol())
|
protocols = append(protocols, eth.whisper.Protocol())
|
||||||
|
@ -309,7 +316,6 @@ func (s *Ethereum) StateDb() common.Database { return s.stateDb }
|
||||||
func (s *Ethereum) ExtraDb() common.Database { return s.extraDb }
|
func (s *Ethereum) ExtraDb() common.Database { return s.extraDb }
|
||||||
func (s *Ethereum) IsListening() bool { return true } // Always listening
|
func (s *Ethereum) IsListening() bool { return true } // Always listening
|
||||||
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() }
|
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() }
|
||||||
func (s *Ethereum) PeerInfo() int { return s.net.PeerCount() }
|
|
||||||
func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() }
|
func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() }
|
||||||
func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers }
|
func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers }
|
||||||
func (s *Ethereum) Version() string { return s.version }
|
func (s *Ethereum) Version() string { return s.version }
|
||||||
|
@ -413,11 +419,11 @@ func (self *Ethereum) blockBroadcastLoop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveProtocolVersion(db common.Database) {
|
func saveProtocolVersion(db common.Database, protov int) {
|
||||||
d, _ := db.Get([]byte("ProtocolVersion"))
|
d, _ := db.Get([]byte("ProtocolVersion"))
|
||||||
protocolVersion := common.NewValue(d).Uint()
|
protocolVersion := common.NewValue(d).Uint()
|
||||||
|
|
||||||
if protocolVersion == 0 {
|
if protocolVersion == 0 {
|
||||||
db.Put([]byte("ProtocolVersion"), common.NewValue(ProtocolVersion).Bytes())
|
db.Put([]byte("ProtocolVersion"), common.NewValue(protov).Bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
package eth
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
)
|
|
||||||
|
|
||||||
func WritePeers(path string, addresses []string) {
|
|
||||||
if len(addresses) > 0 {
|
|
||||||
data, _ := json.MarshalIndent(addresses, "", " ")
|
|
||||||
common.WriteFile(path, data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReadPeers(path string) (ips []string, err error) {
|
|
||||||
var data string
|
|
||||||
data, err = common.ReadAllFile(path)
|
|
||||||
if err != nil {
|
|
||||||
json.Unmarshal([]byte(data), &ips)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -58,13 +58,15 @@ var errorToString = map[int]string{
|
||||||
// ethProtocol represents the ethereum wire protocol
|
// ethProtocol represents the ethereum wire protocol
|
||||||
// instance is running on each peer
|
// instance is running on each peer
|
||||||
type ethProtocol struct {
|
type ethProtocol struct {
|
||||||
txPool txPool
|
txPool txPool
|
||||||
chainManager chainManager
|
chainManager chainManager
|
||||||
blockPool blockPool
|
blockPool blockPool
|
||||||
peer *p2p.Peer
|
peer *p2p.Peer
|
||||||
id string
|
id string
|
||||||
rw p2p.MsgReadWriter
|
rw p2p.MsgReadWriter
|
||||||
errors *errs.Errors
|
errors *errs.Errors
|
||||||
|
protocolVersion int
|
||||||
|
networkId int
|
||||||
}
|
}
|
||||||
|
|
||||||
// backend is the interface the ethereum protocol backend should implement
|
// backend is the interface the ethereum protocol backend should implement
|
||||||
|
@ -101,27 +103,29 @@ type getBlockHashesMsgData struct {
|
||||||
// main entrypoint, wrappers starting a server running the eth protocol
|
// main entrypoint, wrappers starting a server running the eth protocol
|
||||||
// use this constructor to attach the protocol ("class") to server caps
|
// use this constructor to attach the protocol ("class") to server caps
|
||||||
// the Dev p2p layer then runs the protocol instance on each peer
|
// the Dev p2p layer then runs the protocol instance on each peer
|
||||||
func EthProtocol(txPool txPool, chainManager chainManager, blockPool blockPool) p2p.Protocol {
|
func EthProtocol(protocolVersion, networkId int, txPool txPool, chainManager chainManager, blockPool blockPool) p2p.Protocol {
|
||||||
return p2p.Protocol{
|
return p2p.Protocol{
|
||||||
Name: "eth",
|
Name: "eth",
|
||||||
Version: ProtocolVersion,
|
Version: uint(protocolVersion),
|
||||||
Length: ProtocolLength,
|
Length: ProtocolLength,
|
||||||
Run: func(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
|
Run: func(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
|
||||||
return runEthProtocol(txPool, chainManager, blockPool, peer, rw)
|
return runEthProtocol(protocolVersion, networkId, txPool, chainManager, blockPool, peer, rw)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the main loop that handles incoming messages
|
// the main loop that handles incoming messages
|
||||||
// note RemovePeer in the post-disconnect hook
|
// note RemovePeer in the post-disconnect hook
|
||||||
func runEthProtocol(txPool txPool, chainManager chainManager, blockPool blockPool, peer *p2p.Peer, rw p2p.MsgReadWriter) (err error) {
|
func runEthProtocol(protocolVersion, networkId int, txPool txPool, chainManager chainManager, blockPool blockPool, peer *p2p.Peer, rw p2p.MsgReadWriter) (err error) {
|
||||||
id := peer.ID()
|
id := peer.ID()
|
||||||
self := ðProtocol{
|
self := ðProtocol{
|
||||||
txPool: txPool,
|
txPool: txPool,
|
||||||
chainManager: chainManager,
|
chainManager: chainManager,
|
||||||
blockPool: blockPool,
|
blockPool: blockPool,
|
||||||
rw: rw,
|
rw: rw,
|
||||||
peer: peer,
|
peer: peer,
|
||||||
|
protocolVersion: protocolVersion,
|
||||||
|
networkId: networkId,
|
||||||
errors: &errs.Errors{
|
errors: &errs.Errors{
|
||||||
Package: "ETH",
|
Package: "ETH",
|
||||||
Errors: errorToString,
|
Errors: errorToString,
|
||||||
|
@ -291,8 +295,8 @@ func (self *ethProtocol) statusMsg() p2p.Msg {
|
||||||
td, currentBlock, genesisBlock := self.chainManager.Status()
|
td, currentBlock, genesisBlock := self.chainManager.Status()
|
||||||
|
|
||||||
return p2p.NewMsg(StatusMsg,
|
return p2p.NewMsg(StatusMsg,
|
||||||
uint32(ProtocolVersion),
|
uint32(self.protocolVersion),
|
||||||
uint32(NetworkId),
|
uint32(self.networkId),
|
||||||
td,
|
td,
|
||||||
currentBlock,
|
currentBlock,
|
||||||
genesisBlock,
|
genesisBlock,
|
||||||
|
@ -330,12 +334,12 @@ func (self *ethProtocol) handleStatus() error {
|
||||||
return self.protoError(ErrGenesisBlockMismatch, "%x (!= %x)", status.GenesisBlock, genesisBlock)
|
return self.protoError(ErrGenesisBlockMismatch, "%x (!= %x)", status.GenesisBlock, genesisBlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
if status.NetworkId != NetworkId {
|
if int(status.NetworkId) != self.networkId {
|
||||||
return self.protoError(ErrNetworkIdMismatch, "%d (!= %d)", status.NetworkId, NetworkId)
|
return self.protoError(ErrNetworkIdMismatch, "%d (!= %d)", status.NetworkId, self.networkId)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ProtocolVersion != status.ProtocolVersion {
|
if int(status.ProtocolVersion) != self.protocolVersion {
|
||||||
return self.protoError(ErrProtocolVersionMismatch, "%d (!= %d)", status.ProtocolVersion, ProtocolVersion)
|
return self.protoError(ErrProtocolVersionMismatch, "%d (!= %d)", status.ProtocolVersion, self.protocolVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.peer.Infof("Peer is [eth] capable (%d/%d). TD=%v H=%x\n", status.ProtocolVersion, status.NetworkId, status.TD, status.CurrentBlock[:4])
|
self.peer.Infof("Peer is [eth] capable (%d/%d). TD=%v H=%x\n", status.ProtocolVersion, status.NetworkId, status.TD, status.CurrentBlock[:4])
|
||||||
|
|
|
@ -9,10 +9,10 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/errs"
|
"github.com/ethereum/go-ethereum/errs"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
ethlogger "github.com/ethereum/go-ethereum/logger"
|
ethlogger "github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
|
@ -216,7 +216,7 @@ func (self *ethProtocolTester) checkMsg(i int, code uint64, val interface{}) (ms
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ethProtocolTester) run() {
|
func (self *ethProtocolTester) run() {
|
||||||
err := runEthProtocol(self.txPool, self.chainManager, self.blockPool, testPeer(), self.rw)
|
err := runEthProtocol(ProtocolVersion, NetworkId, self.txPool, self.chainManager, self.blockPool, testPeer(), self.rw)
|
||||||
self.quit <- err
|
self.quit <- err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
rpc/api.go
22
rpc/api.go
|
@ -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))
|
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 {
|
if len(result) > 0 {
|
||||||
*reply = toHex(result)
|
*reply = common.ToHex(result)
|
||||||
}
|
}
|
||||||
} else if _, exists := p.register[args.From]; exists {
|
} else if _, exists := p.register[args.From]; exists {
|
||||||
p.register[ags.From] = append(p.register[args.From], args)
|
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
|
return err
|
||||||
}
|
}
|
||||||
state := p.getStateWithNum(args.BlockNumber).SafeGet(args.Address)
|
state := p.getStateWithNum(args.BlockNumber).SafeGet(args.Address)
|
||||||
*reply = toHex(state.Balance().Bytes())
|
*reply = common.ToHex(state.Balance().Bytes())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ func (p *EthereumApi) NewWhisperFilter(args *WhisperFilterArgs, reply *interface
|
||||||
}
|
}
|
||||||
id = p.xeth().Whisper().Watch(opts)
|
id = p.xeth().Whisper().Watch(opts)
|
||||||
p.messages[id] = &whisperFilter{timeout: time.Now()}
|
p.messages[id] = &whisperFilter{timeout: time.Now()}
|
||||||
*reply = toHex(big.NewInt(int64(id)).Bytes())
|
*reply = common.ToHex(big.NewInt(int64(id)).Bytes())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,7 +485,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(common.FromHex(args.Data)))
|
*reply = common.ToHex(crypto.Sha3(common.FromHex(args.Data)))
|
||||||
case "web3_clientVersion":
|
case "web3_clientVersion":
|
||||||
*reply = p.xeth().Backend().Version()
|
*reply = p.xeth().Backend().Version()
|
||||||
case "net_version":
|
case "net_version":
|
||||||
|
@ -493,7 +493,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||||
case "net_listening":
|
case "net_listening":
|
||||||
*reply = p.xeth().IsListening()
|
*reply = p.xeth().IsListening()
|
||||||
case "net_peerCount":
|
case "net_peerCount":
|
||||||
*reply = toHex(big.NewInt(int64(p.xeth().PeerCount())).Bytes())
|
*reply = common.ToHex(big.NewInt(int64(p.xeth().PeerCount())).Bytes())
|
||||||
case "eth_coinbase":
|
case "eth_coinbase":
|
||||||
// TODO handling of empty coinbase due to lack of accounts
|
// TODO handling of empty coinbase due to lack of accounts
|
||||||
res := p.xeth().Coinbase()
|
res := p.xeth().Coinbase()
|
||||||
|
@ -505,11 +505,11 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||||
case "eth_mining":
|
case "eth_mining":
|
||||||
*reply = p.xeth().IsMining()
|
*reply = p.xeth().IsMining()
|
||||||
case "eth_gasPrice":
|
case "eth_gasPrice":
|
||||||
*reply = toHex(defaultGasPrice.Bytes())
|
*reply = common.ToHex(defaultGasPrice.Bytes())
|
||||||
case "eth_accounts":
|
case "eth_accounts":
|
||||||
*reply = p.xeth().Accounts()
|
*reply = p.xeth().Accounts()
|
||||||
case "eth_blockNumber":
|
case "eth_blockNumber":
|
||||||
*reply = toHex(p.xeth().Backend().ChainManager().CurrentBlock().Number().Bytes())
|
*reply = common.ToHex(p.xeth().Backend().ChainManager().CurrentBlock().Number().Bytes())
|
||||||
case "eth_getBalance":
|
case "eth_getBalance":
|
||||||
args := new(GetBalanceArgs)
|
args := new(GetBalanceArgs)
|
||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
|
@ -544,7 +544,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*reply = toHex(big.NewInt(v).Bytes())
|
*reply = common.ToHex(big.NewInt(v).Bytes())
|
||||||
case "eth_getBlockTransactionCountByNumber":
|
case "eth_getBlockTransactionCountByNumber":
|
||||||
args := new(GetBlockByNumberArgs)
|
args := new(GetBlockByNumberArgs)
|
||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
|
@ -555,7 +555,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*reply = toHex(big.NewInt(v).Bytes())
|
*reply = common.ToHex(big.NewInt(v).Bytes())
|
||||||
case "eth_getUncleCountByBlockHash":
|
case "eth_getUncleCountByBlockHash":
|
||||||
args := new(GetBlockByHashArgs)
|
args := new(GetBlockByHashArgs)
|
||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
|
@ -566,7 +566,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*reply = toHex(big.NewInt(v).Bytes())
|
*reply = common.ToHex(big.NewInt(v).Bytes())
|
||||||
case "eth_getUncleCountByBlockNumber":
|
case "eth_getUncleCountByBlockNumber":
|
||||||
args := new(GetBlockByNumberArgs)
|
args := new(GetBlockByNumberArgs)
|
||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
|
@ -577,7 +577,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*reply = toHex(big.NewInt(v).Bytes())
|
*reply = common.ToHex(big.NewInt(v).Bytes())
|
||||||
case "eth_getData", "eth_getCode":
|
case "eth_getData", "eth_getCode":
|
||||||
args := new(GetDataArgs)
|
args := new(GetDataArgs)
|
||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
|
|
98
rpc/http.go
98
rpc/http.go
|
@ -1,6 +1,9 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
|
@ -16,54 +19,83 @@ const (
|
||||||
|
|
||||||
// JSONRPC returns a handler that implements the Ethereum JSON-RPC API.
|
// JSONRPC returns a handler that implements the Ethereum JSON-RPC API.
|
||||||
func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
|
func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
|
||||||
var json JsonWrapper
|
|
||||||
api := NewEthereumApi(pipe, dataDir)
|
api := NewEthereumApi(pipe, dataDir)
|
||||||
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
// TODO this needs to be configurable
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
|
||||||
rpchttplogger.DebugDetailln("Handling request")
|
// Limit request size to resist DoS
|
||||||
|
|
||||||
if req.ContentLength > maxSizeReqLength {
|
if req.ContentLength > maxSizeReqLength {
|
||||||
jsonerr := &RpcErrorObject{-32700, "Request too large"}
|
jsonerr := &RpcErrorObject{-32700, "Request too large"}
|
||||||
json.Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr})
|
Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
reqParsed, reqerr := json.ParseRequestBody(req)
|
// Read request body
|
||||||
switch reqerr.(type) {
|
defer req.Body.Close()
|
||||||
case nil:
|
body, err := ioutil.ReadAll(req.Body)
|
||||||
break
|
if err != nil {
|
||||||
case *DecodeParamError, *InsufficientParamsError, *ValidationError:
|
jsonerr := &RpcErrorObject{-32700, "Could not read request body"}
|
||||||
jsonerr := &RpcErrorObject{-32602, reqerr.Error()}
|
Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr})
|
||||||
json.Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr})
|
}
|
||||||
return
|
|
||||||
default:
|
// Try to parse the request as a single
|
||||||
jsonerr := &RpcErrorObject{-32700, "Could not parse request"}
|
var reqSingle RpcRequest
|
||||||
json.Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr})
|
if err := json.Unmarshal(body, &reqSingle); err == nil {
|
||||||
|
response := RpcResponse(api, &reqSingle)
|
||||||
|
Send(w, &response)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var response interface{}
|
// Try to parse the request to batch
|
||||||
reserr := api.GetRequestReply(&reqParsed, &response)
|
var reqBatch []RpcRequest
|
||||||
switch reserr.(type) {
|
if err := json.Unmarshal(body, &reqBatch); err == nil {
|
||||||
case nil:
|
// Build response batch
|
||||||
break
|
resBatch := make([]*interface{}, len(reqBatch))
|
||||||
case *NotImplementedError:
|
for i, request := range reqBatch {
|
||||||
jsonerr := &RpcErrorObject{-32601, reserr.Error()}
|
response := RpcResponse(api, &request)
|
||||||
json.Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: reqParsed.Id, Error: jsonerr})
|
resBatch[i] = response
|
||||||
return
|
}
|
||||||
case *DecodeParamError, *InsufficientParamsError, *ValidationError:
|
Send(w, resBatch)
|
||||||
jsonerr := &RpcErrorObject{-32602, reserr.Error()}
|
|
||||||
json.Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: reqParsed.Id, Error: jsonerr})
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
jsonerr := &RpcErrorObject{-32603, reserr.Error()}
|
|
||||||
json.Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: reqParsed.Id, Error: jsonerr})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rpchttplogger.DebugDetailf("Generated response: %T %s", response, response)
|
// Not a batch or single request, error
|
||||||
json.Send(w, &RpcSuccessResponse{Jsonrpc: jsonrpcver, Id: reqParsed.Id, Result: response})
|
jsonerr := &RpcErrorObject{-32600, "Could not decode request"}
|
||||||
|
Send(w, &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: nil, Error: jsonerr})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RpcResponse(api *EthereumApi, request *RpcRequest) *interface{} {
|
||||||
|
var reply, response interface{}
|
||||||
|
reserr := api.GetRequestReply(request, &reply)
|
||||||
|
switch reserr.(type) {
|
||||||
|
case nil:
|
||||||
|
response = &RpcSuccessResponse{Jsonrpc: jsonrpcver, Id: request.Id, Result: reply}
|
||||||
|
case *NotImplementedError:
|
||||||
|
jsonerr := &RpcErrorObject{-32601, reserr.Error()}
|
||||||
|
response = &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: request.Id, Error: jsonerr}
|
||||||
|
case *DecodeParamError, *InsufficientParamsError, *ValidationError:
|
||||||
|
jsonerr := &RpcErrorObject{-32602, reserr.Error()}
|
||||||
|
response = &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: request.Id, Error: jsonerr}
|
||||||
|
default:
|
||||||
|
jsonerr := &RpcErrorObject{-32603, reserr.Error()}
|
||||||
|
response = &RpcErrorResponse{Jsonrpc: jsonrpcver, Id: request.Id, Error: jsonerr}
|
||||||
|
}
|
||||||
|
|
||||||
|
rpchttplogger.DebugDetailf("Generated response: %T %s", response, response)
|
||||||
|
return &response
|
||||||
|
}
|
||||||
|
|
||||||
|
func Send(writer io.Writer, v interface{}) (n int, err error) {
|
||||||
|
var payload []byte
|
||||||
|
payload, err = json.MarshalIndent(v, "", "\t")
|
||||||
|
if err != nil {
|
||||||
|
rpclogger.Fatalln("Error marshalling JSON", err)
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
rpclogger.DebugDetailf("Sending payload: %s", payload)
|
||||||
|
|
||||||
|
return writer.Write(payload)
|
||||||
|
}
|
||||||
|
|
|
@ -57,23 +57,23 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert strict types to hexified strings
|
// convert strict types to hexified strings
|
||||||
ext.BlockNumber = toHex(big.NewInt(b.BlockNumber).Bytes())
|
ext.BlockNumber = common.ToHex(big.NewInt(b.BlockNumber).Bytes())
|
||||||
ext.BlockHash = b.BlockHash.Hex()
|
ext.BlockHash = b.BlockHash.Hex()
|
||||||
ext.ParentHash = b.ParentHash.Hex()
|
ext.ParentHash = b.ParentHash.Hex()
|
||||||
ext.Nonce = toHex(b.Nonce[:])
|
ext.Nonce = common.ToHex(b.Nonce[:])
|
||||||
ext.Sha3Uncles = b.Sha3Uncles.Hex()
|
ext.Sha3Uncles = b.Sha3Uncles.Hex()
|
||||||
ext.LogsBloom = toHex(b.LogsBloom[:])
|
ext.LogsBloom = common.ToHex(b.LogsBloom[:])
|
||||||
ext.TransactionRoot = b.TransactionRoot.Hex()
|
ext.TransactionRoot = b.TransactionRoot.Hex()
|
||||||
ext.StateRoot = b.StateRoot.Hex()
|
ext.StateRoot = b.StateRoot.Hex()
|
||||||
ext.Miner = b.Miner.Hex()
|
ext.Miner = b.Miner.Hex()
|
||||||
ext.Difficulty = toHex(big.NewInt(b.Difficulty).Bytes())
|
ext.Difficulty = common.ToHex(big.NewInt(b.Difficulty).Bytes())
|
||||||
ext.TotalDifficulty = toHex(big.NewInt(b.TotalDifficulty).Bytes())
|
ext.TotalDifficulty = common.ToHex(big.NewInt(b.TotalDifficulty).Bytes())
|
||||||
ext.Size = toHex(big.NewInt(b.Size).Bytes())
|
ext.Size = common.ToHex(big.NewInt(b.Size).Bytes())
|
||||||
// ext.ExtraData = toHex(b.ExtraData)
|
// ext.ExtraData = common.ToHex(b.ExtraData)
|
||||||
ext.GasLimit = toHex(big.NewInt(b.GasLimit).Bytes())
|
ext.GasLimit = common.ToHex(big.NewInt(b.GasLimit).Bytes())
|
||||||
// ext.MinGasPrice = toHex(big.NewInt(b.MinGasPrice).Bytes())
|
// ext.MinGasPrice = common.ToHex(big.NewInt(b.MinGasPrice).Bytes())
|
||||||
ext.GasUsed = toHex(big.NewInt(b.GasUsed).Bytes())
|
ext.GasUsed = common.ToHex(big.NewInt(b.GasUsed).Bytes())
|
||||||
ext.UnixTimestamp = toHex(big.NewInt(b.UnixTimestamp).Bytes())
|
ext.UnixTimestamp = common.ToHex(big.NewInt(b.UnixTimestamp).Bytes())
|
||||||
ext.Transactions = make([]interface{}, len(b.Transactions))
|
ext.Transactions = make([]interface{}, len(b.Transactions))
|
||||||
if b.fullTx {
|
if b.fullTx {
|
||||||
for i, tx := range b.Transactions {
|
for i, tx := range b.Transactions {
|
||||||
|
@ -162,20 +162,20 @@ func (t *TransactionRes) MarshalJSON() ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ext.Hash = t.Hash.Hex()
|
ext.Hash = t.Hash.Hex()
|
||||||
ext.Nonce = toHex(big.NewInt(t.Nonce).Bytes())
|
ext.Nonce = common.ToHex(big.NewInt(t.Nonce).Bytes())
|
||||||
ext.BlockHash = t.BlockHash.Hex()
|
ext.BlockHash = t.BlockHash.Hex()
|
||||||
ext.BlockNumber = toHex(big.NewInt(t.BlockNumber).Bytes())
|
ext.BlockNumber = common.ToHex(big.NewInt(t.BlockNumber).Bytes())
|
||||||
ext.TxIndex = toHex(big.NewInt(t.TxIndex).Bytes())
|
ext.TxIndex = common.ToHex(big.NewInt(t.TxIndex).Bytes())
|
||||||
ext.From = t.From.Hex()
|
ext.From = t.From.Hex()
|
||||||
if t.To == nil {
|
if t.To == nil {
|
||||||
ext.To = "0x00"
|
ext.To = "0x00"
|
||||||
} else {
|
} else {
|
||||||
ext.To = t.To.Hex()
|
ext.To = t.To.Hex()
|
||||||
}
|
}
|
||||||
ext.Value = toHex(big.NewInt(t.Value).Bytes())
|
ext.Value = common.ToHex(big.NewInt(t.Value).Bytes())
|
||||||
ext.Gas = toHex(big.NewInt(t.Gas).Bytes())
|
ext.Gas = common.ToHex(big.NewInt(t.Gas).Bytes())
|
||||||
ext.GasPrice = toHex(big.NewInt(t.GasPrice).Bytes())
|
ext.GasPrice = common.ToHex(big.NewInt(t.GasPrice).Bytes())
|
||||||
ext.Input = toHex(t.Input)
|
ext.Input = common.ToHex(t.Input)
|
||||||
|
|
||||||
return json.Marshal(ext)
|
return json.Marshal(ext)
|
||||||
}
|
}
|
||||||
|
|
47
rpc/util.go
47
rpc/util.go
|
@ -19,9 +19,7 @@ package rpc
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"net/http"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -33,8 +31,6 @@ import (
|
||||||
|
|
||||||
var rpclogger = logger.NewLogger("RPC")
|
var rpclogger = logger.NewLogger("RPC")
|
||||||
|
|
||||||
type JsonWrapper struct{}
|
|
||||||
|
|
||||||
// Unmarshal state is a helper method which has the ability to decode messsages
|
// Unmarshal state is a helper method which has the ability to decode messsages
|
||||||
// that use the `defaultBlock` (https://github.com/ethereum/wiki/wiki/JSON-RPC#the-default-block-parameter)
|
// that use the `defaultBlock` (https://github.com/ethereum/wiki/wiki/JSON-RPC#the-default-block-parameter)
|
||||||
// For example a `call`: [{to: "0x....", data:"0x..."}, "latest"]. The first argument is the transaction
|
// For example a `call`: [{to: "0x....", data:"0x..."}, "latest"]. The first argument is the transaction
|
||||||
|
@ -94,47 +90,8 @@ func UnmarshalRawMessages(b []byte, iface interface{}, number *int64) (err error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self JsonWrapper) Send(writer io.Writer, v interface{}) (n int, err error) {
|
|
||||||
var payload []byte
|
|
||||||
payload, err = json.MarshalIndent(v, "", "\t")
|
|
||||||
if err != nil {
|
|
||||||
rpclogger.Fatalln("Error marshalling JSON", err)
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
rpclogger.DebugDetailf("Sending payload: %s", payload)
|
|
||||||
|
|
||||||
return writer.Write(payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self JsonWrapper) ParseRequestBody(req *http.Request) (RpcRequest, error) {
|
|
||||||
var reqParsed RpcRequest
|
|
||||||
|
|
||||||
// Convert JSON to native types
|
|
||||||
d := json.NewDecoder(req.Body)
|
|
||||||
defer req.Body.Close()
|
|
||||||
err := d.Decode(&reqParsed)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
rpclogger.Errorln("Error decoding JSON: ", err)
|
|
||||||
return reqParsed, err
|
|
||||||
}
|
|
||||||
|
|
||||||
rpclogger.DebugDetailf("Parsed request: %s", reqParsed)
|
|
||||||
|
|
||||||
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 {
|
func i2hex(n int) string {
|
||||||
return toHex(big.NewInt(int64(n)).Bytes())
|
return common.ToHex(big.NewInt(int64(n)).Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
type RpcServer interface {
|
type RpcServer interface {
|
||||||
|
@ -156,7 +113,7 @@ func toLogs(logs state.Logs) (ls []Log) {
|
||||||
var l Log
|
var l Log
|
||||||
l.Topic = make([]string, len(log.Topics()))
|
l.Topic = make([]string, len(log.Topics()))
|
||||||
l.Address = log.Address().Hex()
|
l.Address = log.Address().Hex()
|
||||||
l.Data = toHex(log.Data())
|
l.Data = common.ToHex(log.Data())
|
||||||
l.Number = log.Number()
|
l.Number = log.Number()
|
||||||
for j, topic := range log.Topics() {
|
for j, topic := range log.Topics() {
|
||||||
l.Topic[j] = topic.Hex()
|
l.Topic[j] = topic.Hex()
|
||||||
|
|
|
@ -4,8 +4,8 @@ package qwhisper
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/whisper"
|
"github.com/ethereum/go-ethereum/whisper"
|
||||||
"github.com/obscuren/qml"
|
"github.com/obscuren/qml"
|
||||||
|
@ -13,8 +13,6 @@ import (
|
||||||
|
|
||||||
var qlogger = logger.NewLogger("QSHH")
|
var qlogger = logger.NewLogger("QSHH")
|
||||||
|
|
||||||
func toHex(b []byte) string { return "0x" + common.Bytes2Hex(b) }
|
|
||||||
|
|
||||||
type Whisper struct {
|
type Whisper struct {
|
||||||
*whisper.Whisper
|
*whisper.Whisper
|
||||||
view qml.Object
|
view qml.Object
|
||||||
|
@ -66,7 +64,7 @@ func (self *Whisper) Post(payload []string, to, from string, topics []string, pr
|
||||||
func (self *Whisper) NewIdentity() string {
|
func (self *Whisper) NewIdentity() string {
|
||||||
key := self.Whisper.NewIdentity()
|
key := self.Whisper.NewIdentity()
|
||||||
|
|
||||||
return toHex(crypto.FromECDSAPub(&key.PublicKey))
|
return common.ToHex(crypto.FromECDSAPub(&key.PublicKey))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Whisper) HasIdentity(key string) bool {
|
func (self *Whisper) HasIdentity(key string) bool {
|
||||||
|
|
|
@ -14,10 +14,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
func toHex(b []byte) string {
|
|
||||||
return "0x" + common.Bytes2Hex(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Object struct {
|
type Object struct {
|
||||||
*state.StateObject
|
*state.StateObject
|
||||||
}
|
}
|
||||||
|
@ -49,7 +45,7 @@ func (self *Object) Storage() (storage map[string]string) {
|
||||||
for it.Next() {
|
for it.Next() {
|
||||||
var data []byte
|
var data []byte
|
||||||
rlp.Decode(bytes.NewReader(it.Value), &data)
|
rlp.Decode(bytes.NewReader(it.Value), &data)
|
||||||
storage[toHex(it.Key)] = toHex(data)
|
storage[common.ToHex(it.Key)] = common.ToHex(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -95,12 +91,12 @@ func NewBlock(block *types.Block) *Block {
|
||||||
return &Block{
|
return &Block{
|
||||||
ref: block, Size: block.Size().String(),
|
ref: block, Size: block.Size().String(),
|
||||||
Number: int(block.NumberU64()), GasUsed: block.GasUsed().String(),
|
Number: int(block.NumberU64()), GasUsed: block.GasUsed().String(),
|
||||||
GasLimit: block.GasLimit().String(), Hash: toHex(block.Hash().Bytes()),
|
GasLimit: block.GasLimit().String(), Hash: block.Hash().Hex(),
|
||||||
Transactions: txlist, Uncles: ulist,
|
Transactions: txlist, Uncles: ulist,
|
||||||
Time: block.Time(),
|
Time: block.Time(),
|
||||||
Coinbase: toHex(block.Coinbase().Bytes()),
|
Coinbase: block.Coinbase().Hex(),
|
||||||
PrevHash: toHex(block.ParentHash().Bytes()),
|
PrevHash: block.ParentHash().Hex(),
|
||||||
Bloom: toHex(block.Bloom().Bytes()),
|
Bloom: common.ToHex(block.Bloom().Bytes()),
|
||||||
Raw: block.String(),
|
Raw: block.String(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,10 +147,10 @@ func NewTx(tx *types.Transaction) *Transaction {
|
||||||
if createsContract {
|
if createsContract {
|
||||||
data = strings.Join(core.Disassemble(tx.Data()), "\n")
|
data = strings.Join(core.Disassemble(tx.Data()), "\n")
|
||||||
} else {
|
} else {
|
||||||
data = toHex(tx.Data())
|
data = common.ToHex(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.Hex(), CreatesContract: createsContract, RawData: toHex(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.Hex(), CreatesContract: createsContract, RawData: common.ToHex(tx.Data())}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Transaction) ToString() string {
|
func (self *Transaction) ToString() string {
|
||||||
|
@ -168,7 +164,7 @@ type Key struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKey(key *crypto.KeyPair) *Key {
|
func NewKey(key *crypto.KeyPair) *Key {
|
||||||
return &Key{toHex(key.Address()), toHex(key.PrivateKey), toHex(key.PublicKey)}
|
return &Key{common.ToHex(key.Address()), common.ToHex(key.PrivateKey), common.ToHex(key.PublicKey)}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PReceipt struct {
|
type PReceipt struct {
|
||||||
|
@ -181,9 +177,9 @@ type PReceipt struct {
|
||||||
func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) *PReceipt {
|
func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) *PReceipt {
|
||||||
return &PReceipt{
|
return &PReceipt{
|
||||||
contractCreation,
|
contractCreation,
|
||||||
toHex(creationAddress),
|
common.ToHex(creationAddress),
|
||||||
toHex(hash),
|
common.ToHex(hash),
|
||||||
toHex(address),
|
common.ToHex(address),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,8 +216,8 @@ type Receipt struct {
|
||||||
func NewReciept(contractCreation bool, creationAddress, hash, address []byte) *Receipt {
|
func NewReciept(contractCreation bool, creationAddress, hash, address []byte) *Receipt {
|
||||||
return &Receipt{
|
return &Receipt{
|
||||||
contractCreation,
|
contractCreation,
|
||||||
toHex(creationAddress),
|
common.ToHex(creationAddress),
|
||||||
toHex(hash),
|
common.ToHex(hash),
|
||||||
toHex(address),
|
common.ToHex(address),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ func (self *Whisper) Post(payload string, to, from string, topics []string, prio
|
||||||
func (self *Whisper) NewIdentity() string {
|
func (self *Whisper) NewIdentity() string {
|
||||||
key := self.Whisper.NewIdentity()
|
key := self.Whisper.NewIdentity()
|
||||||
|
|
||||||
return toHex(crypto.FromECDSAPub(&key.PublicKey))
|
return common.ToHex(crypto.FromECDSAPub(&key.PublicKey))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Whisper) HasIdentity(key string) bool {
|
func (self *Whisper) HasIdentity(key string) bool {
|
||||||
|
@ -112,9 +112,9 @@ type WhisperMessage struct {
|
||||||
func NewWhisperMessage(msg *whisper.Message) WhisperMessage {
|
func NewWhisperMessage(msg *whisper.Message) WhisperMessage {
|
||||||
return WhisperMessage{
|
return WhisperMessage{
|
||||||
ref: msg,
|
ref: msg,
|
||||||
Payload: toHex(msg.Payload),
|
Payload: common.ToHex(msg.Payload),
|
||||||
From: toHex(crypto.FromECDSAPub(msg.Recover())),
|
From: common.ToHex(crypto.FromECDSAPub(msg.Recover())),
|
||||||
To: toHex(crypto.FromECDSAPub(msg.To)),
|
To: common.ToHex(crypto.FromECDSAPub(msg.To)),
|
||||||
Sent: msg.Sent,
|
Sent: msg.Sent,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
xeth/xeth.go
16
xeth/xeth.go
|
@ -170,7 +170,7 @@ func (self *XEth) Accounts() []string {
|
||||||
accounts, _ := self.eth.AccountManager().Accounts()
|
accounts, _ := self.eth.AccountManager().Accounts()
|
||||||
accountAddresses := make([]string, len(accounts))
|
accountAddresses := make([]string, len(accounts))
|
||||||
for i, ac := range accounts {
|
for i, ac := range accounts {
|
||||||
accountAddresses[i] = toHex(ac.Address)
|
accountAddresses[i] = common.ToHex(ac.Address)
|
||||||
}
|
}
|
||||||
return accountAddresses
|
return accountAddresses
|
||||||
}
|
}
|
||||||
|
@ -201,7 +201,7 @@ func (self *XEth) IsListening() bool {
|
||||||
|
|
||||||
func (self *XEth) Coinbase() string {
|
func (self *XEth) Coinbase() string {
|
||||||
cb, _ := self.eth.AccountManager().Coinbase()
|
cb, _ := self.eth.AccountManager().Coinbase()
|
||||||
return toHex(cb)
|
return common.ToHex(cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *XEth) NumberToHuman(balance string) string {
|
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 {
|
func (self *XEth) StorageAt(addr, storageAddr string) string {
|
||||||
storage := self.State().SafeGet(addr).StorageString(storageAddr)
|
storage := self.State().SafeGet(addr).StorageString(storageAddr)
|
||||||
|
|
||||||
return toHex(storage.Bytes())
|
return common.ToHex(storage.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *XEth) BalanceAt(addr string) string {
|
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 {
|
func (self *XEth) CodeAt(address string) string {
|
||||||
return toHex(self.State().SafeGet(address).Code())
|
return common.ToHex(self.State().SafeGet(address).Code())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *XEth) IsContract(address string) bool {
|
func (self *XEth) IsContract(address string) bool {
|
||||||
|
@ -238,7 +238,7 @@ func (self *XEth) SecretToAddress(key string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return toHex(pair.Address())
|
return common.ToHex(pair.Address())
|
||||||
}
|
}
|
||||||
|
|
||||||
type KeyVal struct {
|
type KeyVal struct {
|
||||||
|
@ -251,7 +251,7 @@ func (self *XEth) EachStorage(addr string) string {
|
||||||
object := self.State().SafeGet(addr)
|
object := self.State().SafeGet(addr)
|
||||||
it := object.Trie().Iterator()
|
it := object.Trie().Iterator()
|
||||||
for it.Next() {
|
for it.Next() {
|
||||||
values = append(values, KeyVal{toHex(it.Key), toHex(it.Value)})
|
values = append(values, KeyVal{common.ToHex(it.Key), common.ToHex(it.Value)})
|
||||||
}
|
}
|
||||||
|
|
||||||
valuesJson, err := json.Marshal(values)
|
valuesJson, err := json.Marshal(values)
|
||||||
|
@ -265,7 +265,7 @@ func (self *XEth) EachStorage(addr string) string {
|
||||||
func (self *XEth) ToAscii(str string) string {
|
func (self *XEth) ToAscii(str string) string {
|
||||||
padded := common.RightPadBytes([]byte(str), 32)
|
padded := common.RightPadBytes([]byte(str), 32)
|
||||||
|
|
||||||
return "0x" + toHex(padded)
|
return "0x" + common.ToHex(padded)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *XEth) FromAscii(str string) string {
|
func (self *XEth) FromAscii(str string) string {
|
||||||
|
@ -325,7 +325,7 @@ func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr st
|
||||||
vmenv := core.NewEnv(statedb, self.chainManager, msg, block)
|
vmenv := core.NewEnv(statedb, self.chainManager, msg, block)
|
||||||
|
|
||||||
res, err := vmenv.Call(msg.from, msg.to, msg.data, msg.gas, msg.gasPrice, msg.value)
|
res, err := vmenv.Call(msg.from, msg.to, msg.data, msg.gas, msg.gasPrice, msg.value)
|
||||||
return toHex(res), err
|
return common.ToHex(res), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
|
func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
|
||||||
|
|
Loading…
Reference in New Issue