mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 20:26:41 +00:00
Merge branch 'develop' of github.com:ethereum/go-ethereum into publictests
Conflicts: miner/worker.go
This commit is contained in:
commit
3be1fed721
34 changed files with 308 additions and 632 deletions
12
Dockerfile
12
Dockerfile
|
|
@ -1,4 +1,4 @@
|
|||
FROM ubuntu:14.04.1
|
||||
FROM ubuntu:14.04.2
|
||||
|
||||
## Environment setup
|
||||
ENV HOME /root
|
||||
|
|
@ -12,22 +12,22 @@ ENV DEBIAN_FRONTEND noninteractive
|
|||
RUN apt-get update && apt-get upgrade -y
|
||||
RUN apt-get install -y git mercurial build-essential software-properties-common wget pkg-config libgmp3-dev libreadline6-dev libpcre3-dev libpcre++-dev
|
||||
|
||||
## Install Qt5.4 (not required for CLI)
|
||||
# RUN add-apt-repository ppa:beineri/opt-qt54-trusty -y
|
||||
## Install Qt5.4.1 (not required for CLI)
|
||||
# RUN add-apt-repository ppa:beineri/opt-qt541-trusty -y
|
||||
# RUN apt-get update -y
|
||||
# RUN apt-get install -y qt54quickcontrols qt54webengine mesa-common-dev libglu1-mesa-dev
|
||||
# ENV PKG_CONFIG_PATH /opt/qt54/lib/pkgconfig
|
||||
|
||||
# Install Golang
|
||||
RUN wget https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz
|
||||
RUN wget https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz
|
||||
RUN tar -C /usr/local -xzf go*.tar.gz && go version
|
||||
|
||||
# this is a workaround, to make sure that docker's cache is invalidated whenever the git repo changes
|
||||
ADD https://api.github.com/repos/ethereum/go-ethereum/git/refs/heads/develop file_does_not_exist
|
||||
|
||||
## Fetch and install go-ethereum
|
||||
RUN go get -v github.com/tools/godep
|
||||
RUN go get -v -d github.com/ethereum/go-ethereum/...
|
||||
RUN go get github.com/tools/godep
|
||||
RUN go get -d github.com/ethereum/go-ethereum/...
|
||||
WORKDIR $GOPATH/src/github.com/ethereum/go-ethereum
|
||||
RUN git checkout develop
|
||||
RUN godep restore
|
||||
|
|
|
|||
112
README.md
112
README.md
|
|
@ -24,7 +24,25 @@ Ethereum (CLI):
|
|||
|
||||
`go get github.com/ethereum/go-ethereum/cmd/ethereum`
|
||||
|
||||
For further, detailed, build instruction please see the [Wiki](https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum(Go))
|
||||
As of POC-8, go-ethereum uses [Godep](https://github.com/tools/godep) to manage dependencies. Assuming you have [your environment all set up](https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum(Go)), switch to the go-ethereum repository root folder, and build/install the executable you need:
|
||||
|
||||
Mist (GUI):
|
||||
|
||||
```
|
||||
godep go build -v ./cmd/mist
|
||||
```
|
||||
|
||||
Ethereum (CLI):
|
||||
|
||||
```
|
||||
godep go build -v ./cmd/ethereum
|
||||
```
|
||||
|
||||
Instead of `build`, you can use `install` which will also install the resulting binary.
|
||||
|
||||
For prerequisites and detailed build instructions please see the [Wiki](https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum(Go))
|
||||
|
||||
If you intend to develop on go-ethereum, check the [Developers' Guide](https://github.com/ethereum/go-ethereum/wiki/Developers'-Guide)
|
||||
|
||||
Automated (dev) builds
|
||||
======================
|
||||
|
|
@ -34,97 +52,47 @@ Automated (dev) builds
|
|||
* [Windows] Coming soon™
|
||||
* [Linux] Coming soon™
|
||||
|
||||
Binaries
|
||||
========
|
||||
Executables
|
||||
===========
|
||||
|
||||
Go Ethereum comes with several binaries found in
|
||||
[cmd](https://github.com/ethereum/go-ethereum/tree/master/cmd):
|
||||
Go Ethereum comes with several wrappers/executables found in
|
||||
[the `cmd` directory](https://github.com/ethereum/go-ethereum/tree/develop/cmd):
|
||||
|
||||
* `mist` Official Ethereum Browser
|
||||
* `ethereum` Ethereum CLI
|
||||
* `ethtest` test tool which runs with the [tests](https://github.com/ethereum/testes) suit:
|
||||
* `mist` Official Ethereum Browser (ethereum GUI client)
|
||||
* `ethereum` Ethereum CLI (ethereum command line interface client)
|
||||
* `bootnode` runs a bootstrap node for the Discovery Protocol
|
||||
* `ethtest` test tool which runs with the [tests](https://github.com/ethereum/testes) suite:
|
||||
`cat file | ethtest`.
|
||||
* `evm` is a generic Ethereum Virtual Machine: `evm -code 60ff60ff -gas
|
||||
10000 -price 0 -dump`. See `-h` for a detailed description.
|
||||
* `rlpdump` converts a rlp stream to `interface{}`.
|
||||
* `peerserver` simple P2P (noi-ethereum) peer server.
|
||||
* `disasm` disassembles EVM code: `echo "6001" | disasm`
|
||||
* `rlpdump` converts a rlp stream to `interface{}`.
|
||||
|
||||
General command line options
|
||||
Command line options
|
||||
============================
|
||||
|
||||
Both `mist` and `ethereum` can be configured via command line options, environment variables and config files.
|
||||
|
||||
To get the options available:
|
||||
|
||||
```
|
||||
== Shared between ethereum and Mist ==
|
||||
|
||||
= Settings
|
||||
-id Set the custom identifier of the client (shows up on other clients)
|
||||
-port Port on which the server will accept incomming connections
|
||||
-upnp Enable UPnP
|
||||
-maxpeer Desired amount of peers
|
||||
-rpc Start JSON RPC
|
||||
-dir Data directory used to store configs and databases
|
||||
|
||||
= Utility
|
||||
-h This
|
||||
-import Import a private key
|
||||
-genaddr Generates a new address and private key (destructive action)
|
||||
-dump Dump a specific state of a block to stdout given the -number or -hash
|
||||
-difftool Supress all output and prints VM output to stdout
|
||||
-diff vm=only vm output, all=all output including state storage
|
||||
|
||||
Ethereum only
|
||||
ethereum [options] [filename]
|
||||
-js Start the JavaScript REPL
|
||||
filename Load the given file and interpret as JavaScript
|
||||
-m Start mining blocks
|
||||
|
||||
== Mist only ==
|
||||
|
||||
-asset_path absolute path to GUI assets directory
|
||||
ethereum -help
|
||||
```
|
||||
|
||||
For further details on options, see the [wiki](https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options)
|
||||
|
||||
Contribution
|
||||
============
|
||||
|
||||
If you'd like to contribute to Ethereum please fork, fix, commit and
|
||||
If you'd like to contribute to go-ethereum please fork, fix, commit and
|
||||
send a pull request. Commits who do not comply with the coding standards
|
||||
are ignored (use gofmt!). If you send pull requests make absolute sure that you
|
||||
commit on the `develop` branch and that you do not merge to master.
|
||||
Commits that are directly based on master are simply ignored.
|
||||
|
||||
For dependency management, we use [godep](https://github.com/tools/godep). After installing with `go get github.com/tools/godep`, run `godep restore` to ensure that changes to other repositories do not break the build. To update a dependency version (for example, to include a new upstream fix), run `go get -u <foo/bar>` then `godep update <foo/...>`. To track a new dependency, add it to the project as normal than run `godep save ./...`. Changes to the Godeps folder should be manually verified then commited.
|
||||
For dependency management, we use [godep](https://github.com/tools/godep). After installing with `go get github.com/tools/godep`, run `godep restore` to ensure that changes to other repositories do not break the build. To update a dependency version (for example, to include a new upstream fix), run `go get -u <foo/bar>` then `godep update <foo/...>`. To track a new dependency, add it to the project as normal than run `godep save ./...`. Changes to the [Godeps folder](https://github.com/ethereum/go-ethereum/tree/develop/Godeps): should be manually verified then commited.
|
||||
|
||||
To make life easier try [git flow](http://nvie.com/posts/a-successful-git-branching-model/) it sets
|
||||
this all up and streamlines your work flow.
|
||||
|
||||
Coding standards
|
||||
================
|
||||
|
||||
Sources should be formatted according to the [Go Formatting
|
||||
Style](http://golang.org/doc/effective_go.html#formatting).
|
||||
|
||||
Unless structs fields are supposed to be directly accesible, provide
|
||||
Getters and hide the fields through Go's exporting facility.
|
||||
|
||||
When you comment put meaningful comments. Describe in detail what you
|
||||
want to achieve.
|
||||
|
||||
*wrong*
|
||||
|
||||
```go
|
||||
// Check if the value at x is greater than y
|
||||
if x > y {
|
||||
// It's greater!
|
||||
}
|
||||
```
|
||||
|
||||
Everyone reading the source probably know what you wanted to achieve
|
||||
with above code. Those are **not** meaningful comments.
|
||||
|
||||
While the project isn't 100% tested I want you to write tests non the
|
||||
less. I haven't got time to evaluate everyone's code in detail so I
|
||||
expect you to write tests for me so I don't have to test your code
|
||||
manually. (If you want to contribute by just writing tests that's fine
|
||||
too!)
|
||||
To make life easier try [git flow](http://nvie.com/posts/a-successful-git-branching-model/) it sets this all up and streamlines your work flow.
|
||||
|
||||
See [Developers' Guide](https://github.com/ethereum/go-ethereum/wiki/Developers'-Guide)
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
|
|
@ -36,40 +37,41 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
Identifier string
|
||||
KeyRing string
|
||||
DiffTool bool
|
||||
DiffType string
|
||||
KeyStore string
|
||||
StartRpc bool
|
||||
StartWebSockets bool
|
||||
RpcPort int
|
||||
WsPort int
|
||||
OutboundPort string
|
||||
ShowGenesis bool
|
||||
AddPeer string
|
||||
MaxPeer int
|
||||
GenAddr bool
|
||||
BootNodes string
|
||||
NodeKey *ecdsa.PrivateKey
|
||||
NAT nat.Interface
|
||||
SecretFile string
|
||||
ExportDir string
|
||||
NonInteractive bool
|
||||
Datadir string
|
||||
LogFile string
|
||||
ConfigFile string
|
||||
DebugFile string
|
||||
LogLevel int
|
||||
LogFormat string
|
||||
Dump bool
|
||||
DumpHash string
|
||||
DumpNumber int
|
||||
VmType int
|
||||
ImportChain string
|
||||
SHH bool
|
||||
Dial bool
|
||||
PrintVersion bool
|
||||
Identifier string
|
||||
KeyRing string
|
||||
DiffTool bool
|
||||
DiffType string
|
||||
KeyStore string
|
||||
StartRpc bool
|
||||
StartWebSockets bool
|
||||
RpcListenAddress string
|
||||
RpcPort int
|
||||
OutboundPort string
|
||||
ShowGenesis bool
|
||||
AddPeer string
|
||||
MaxPeer int
|
||||
GenAddr bool
|
||||
BootNodes string
|
||||
NodeKey *ecdsa.PrivateKey
|
||||
NAT nat.Interface
|
||||
SecretFile string
|
||||
ExportDir string
|
||||
NonInteractive bool
|
||||
Datadir string
|
||||
LogFile string
|
||||
ConfigFile string
|
||||
DebugFile string
|
||||
LogLevel int
|
||||
LogFormat string
|
||||
Dump bool
|
||||
DumpHash string
|
||||
DumpNumber int
|
||||
VmType int
|
||||
ImportChain string
|
||||
SHH bool
|
||||
Dial bool
|
||||
PrintVersion bool
|
||||
MinerThreads int
|
||||
)
|
||||
|
||||
// flags specific to cli client
|
||||
|
|
@ -91,12 +93,11 @@ func Init() {
|
|||
flag.IntVar(&VmType, "vm", 0, "Virtual Machine type: 0-1: standard, debug")
|
||||
flag.StringVar(&Identifier, "id", "", "Custom client identifier")
|
||||
flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
|
||||
flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
|
||||
flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file")
|
||||
|
||||
flag.StringVar(&RpcListenAddress, "rpcaddr", "127.0.0.1", "address for json-rpc server to listen on")
|
||||
flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on")
|
||||
flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on")
|
||||
flag.BoolVar(&StartRpc, "rpc", false, "start rpc server")
|
||||
flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
|
||||
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
||||
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
||||
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
|
||||
|
|
@ -105,8 +106,8 @@ func Init() {
|
|||
flag.StringVar(&Datadir, "datadir", ethutil.DefaultDataDir(), "specifies the datadir to use")
|
||||
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
||||
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
|
||||
flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
|
||||
flag.StringVar(&LogFormat, "logformat", "std", "logformat: std,raw)")
|
||||
flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5 (= silent,error,warn,info,debug,debug detail)")
|
||||
flag.StringVar(&LogFormat, "logformat", "std", "logformat: std,raw")
|
||||
flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
|
||||
flag.StringVar(&DiffType, "diff", "all", "sets the level of diff output [vm, all]. Has no effect if difftool=false")
|
||||
flag.BoolVar(&ShowGenesis, "genesis", false, "Dump the genesis block")
|
||||
|
|
@ -116,9 +117,10 @@ func Init() {
|
|||
flag.StringVar(&DumpHash, "hash", "", "specify arg in hex")
|
||||
flag.IntVar(&DumpNumber, "number", -1, "specify arg in number")
|
||||
|
||||
flag.BoolVar(&StartMining, "mine", false, "start dagger mining")
|
||||
flag.BoolVar(&StartMining, "mine", false, "start mining")
|
||||
flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console")
|
||||
flag.BoolVar(&PrintVersion, "version", false, "prints version number")
|
||||
flag.IntVar(&MinerThreads, "minerthreads", runtime.NumCPU(), "number of miner threads")
|
||||
|
||||
// Network stuff
|
||||
var (
|
||||
|
|
@ -135,6 +137,12 @@ func Init() {
|
|||
|
||||
flag.Parse()
|
||||
|
||||
// When the javascript console is started log to a file instead
|
||||
// of stdout
|
||||
if StartJsConsole {
|
||||
LogFile = path.Join(Datadir, "ethereum.log")
|
||||
}
|
||||
|
||||
var err error
|
||||
if NAT, err = nat.Parse(*natstr); err != nil {
|
||||
log.Fatalf("-nat: %v", err)
|
||||
|
|
|
|||
|
|
@ -62,20 +62,21 @@ func main() {
|
|||
utils.InitConfig(VmType, ConfigFile, Datadir, "ETH")
|
||||
|
||||
ethereum, err := eth.New(ð.Config{
|
||||
Name: p2p.MakeName(ClientIdentifier, Version),
|
||||
KeyStore: KeyStore,
|
||||
DataDir: Datadir,
|
||||
LogFile: LogFile,
|
||||
LogLevel: LogLevel,
|
||||
LogFormat: LogFormat,
|
||||
MaxPeers: MaxPeer,
|
||||
Port: OutboundPort,
|
||||
NAT: NAT,
|
||||
KeyRing: KeyRing,
|
||||
Shh: true,
|
||||
Dial: Dial,
|
||||
BootNodes: BootNodes,
|
||||
NodeKey: NodeKey,
|
||||
Name: p2p.MakeName(ClientIdentifier, Version),
|
||||
KeyStore: KeyStore,
|
||||
DataDir: Datadir,
|
||||
LogFile: LogFile,
|
||||
LogLevel: LogLevel,
|
||||
LogFormat: LogFormat,
|
||||
MaxPeers: MaxPeer,
|
||||
Port: OutboundPort,
|
||||
NAT: NAT,
|
||||
KeyRing: KeyRing,
|
||||
Shh: true,
|
||||
Dial: Dial,
|
||||
BootNodes: BootNodes,
|
||||
NodeKey: NodeKey,
|
||||
MinerThreads: MinerThreads,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
@ -113,10 +114,6 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
if StartMining {
|
||||
utils.StartMining(ethereum)
|
||||
}
|
||||
|
||||
if len(ImportChain) > 0 {
|
||||
start := time.Now()
|
||||
err := utils.ImportChain(ethereum, ImportChain)
|
||||
|
|
@ -128,15 +125,17 @@ func main() {
|
|||
}
|
||||
|
||||
if StartRpc {
|
||||
utils.StartRpc(ethereum, RpcPort)
|
||||
}
|
||||
|
||||
if StartWebSockets {
|
||||
utils.StartWebSockets(ethereum, WsPort)
|
||||
utils.StartRpc(ethereum, RpcListenAddress, RpcPort)
|
||||
}
|
||||
|
||||
utils.StartEthereum(ethereum)
|
||||
|
||||
fmt.Printf("Welcome to the FRONTIER\n")
|
||||
|
||||
if StartMining {
|
||||
ethereum.Miner().Start()
|
||||
}
|
||||
|
||||
if StartJsConsole {
|
||||
InitJsConsole(ethereum)
|
||||
} else if len(InputFile) > 0 {
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ func (self *JSRepl) Start() {
|
|||
if !self.running {
|
||||
self.running = true
|
||||
repllogger.Infoln("init JS Console")
|
||||
|
||||
reader := bufio.NewReader(self.history)
|
||||
for {
|
||||
line, err := reader.ReadString('\n')
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/ui/qt"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
"github.com/obscuren/qml"
|
||||
)
|
||||
|
|
@ -116,7 +115,3 @@ func (app *ExtApplication) mainLoop() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *ExtApplication) Watch(filterOptions map[string]interface{}, identifier string) {
|
||||
self.filters[identifier] = qt.NewFilterFromMap(filterOptions, self.eth)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,31 +37,30 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
Identifier string
|
||||
KeyRing string
|
||||
KeyStore string
|
||||
StartRpc bool
|
||||
StartWebSockets bool
|
||||
RpcPort int
|
||||
WsPort int
|
||||
OutboundPort string
|
||||
ShowGenesis bool
|
||||
AddPeer string
|
||||
MaxPeer int
|
||||
GenAddr bool
|
||||
BootNodes string
|
||||
NodeKey *ecdsa.PrivateKey
|
||||
NAT nat.Interface
|
||||
SecretFile string
|
||||
ExportDir string
|
||||
NonInteractive bool
|
||||
Datadir string
|
||||
LogFile string
|
||||
ConfigFile string
|
||||
DebugFile string
|
||||
LogLevel int
|
||||
VmType int
|
||||
MinerThreads int
|
||||
Identifier string
|
||||
KeyRing string
|
||||
KeyStore string
|
||||
StartRpc bool
|
||||
RpcListenAddress string
|
||||
RpcPort int
|
||||
OutboundPort string
|
||||
ShowGenesis bool
|
||||
AddPeer string
|
||||
MaxPeer int
|
||||
GenAddr bool
|
||||
BootNodes string
|
||||
NodeKey *ecdsa.PrivateKey
|
||||
NAT nat.Interface
|
||||
SecretFile string
|
||||
ExportDir string
|
||||
NonInteractive bool
|
||||
Datadir string
|
||||
LogFile string
|
||||
ConfigFile string
|
||||
DebugFile string
|
||||
LogLevel int
|
||||
VmType int
|
||||
MinerThreads int
|
||||
)
|
||||
|
||||
// flags specific to gui client
|
||||
|
|
@ -78,11 +77,10 @@ func Init() {
|
|||
flag.IntVar(&VmType, "vm", 0, "Virtual Machine type: 0-1: standard, debug")
|
||||
flag.StringVar(&Identifier, "id", "", "Custom client identifier")
|
||||
flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
|
||||
flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
|
||||
flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file")
|
||||
flag.StringVar(&RpcListenAddress, "rpcaddr", "127.0.0.1", "address for json-rpc server to listen on")
|
||||
flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on")
|
||||
flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on")
|
||||
flag.BoolVar(&StartRpc, "rpc", true, "start rpc server")
|
||||
flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
|
||||
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
||||
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
||||
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
|
||||
|
|
@ -91,7 +89,7 @@ func Init() {
|
|||
flag.StringVar(&Datadir, "datadir", ethutil.DefaultDataDir(), "specifies the datadir to use")
|
||||
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
||||
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
|
||||
flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)")
|
||||
flag.IntVar(&LogLevel, "loglevel", int(logger.InfoLevel), "loglevel: 0-5 (= silent,error,warn,info,debug,debug detail)")
|
||||
|
||||
flag.StringVar(&AssetPath, "asset_path", ethutil.DefaultAssetPath(), "absolute path to GUI assets directory")
|
||||
|
||||
|
|
|
|||
|
|
@ -73,11 +73,7 @@ func run() error {
|
|||
utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
|
||||
|
||||
if StartRpc {
|
||||
utils.StartRpc(ethereum, RpcPort)
|
||||
}
|
||||
|
||||
if StartWebSockets {
|
||||
utils.StartWebSockets(ethereum, WsPort)
|
||||
utils.StartRpc(ethereum, RpcListenAddress, RpcPort)
|
||||
}
|
||||
|
||||
gui := NewWindow(ethereum, config, KeyRing, LogLevel)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/miner"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
rpchttp "github.com/ethereum/go-ethereum/rpc/http"
|
||||
rpcws "github.com/ethereum/go-ethereum/rpc/ws"
|
||||
"github.com/ethereum/go-ethereum/state"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
)
|
||||
|
|
@ -160,9 +159,9 @@ func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, Secre
|
|||
clilogger.Infof("Main address %x\n", keyManager.Address())
|
||||
}
|
||||
|
||||
func StartRpc(ethereum *eth.Ethereum, RpcPort int) {
|
||||
func StartRpc(ethereum *eth.Ethereum, RpcListenAddress string, RpcPort int) {
|
||||
var err error
|
||||
ethereum.RpcServer, err = rpchttp.NewRpcHttpServer(xeth.New(ethereum), RpcPort)
|
||||
ethereum.RpcServer, err = rpchttp.NewRpcHttpServer(xeth.New(ethereum), RpcListenAddress, RpcPort)
|
||||
if err != nil {
|
||||
clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
|
||||
} else {
|
||||
|
|
@ -170,18 +169,6 @@ func StartRpc(ethereum *eth.Ethereum, RpcPort int) {
|
|||
}
|
||||
}
|
||||
|
||||
func StartWebSockets(eth *eth.Ethereum, wsPort int) {
|
||||
clilogger.Infoln("Starting WebSockets")
|
||||
|
||||
var err error
|
||||
eth.WsServer, err = rpcws.NewWebSocketServer(xeth.New(eth), wsPort)
|
||||
if err != nil {
|
||||
clilogger.Errorf("Could not start RPC interface (port %v): %v", wsPort, err)
|
||||
} else {
|
||||
go eth.WsServer.Start()
|
||||
}
|
||||
}
|
||||
|
||||
var gminer *miner.Miner
|
||||
|
||||
func GetMiner() *miner.Miner {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ type FilterOptions struct {
|
|||
Latest int64
|
||||
|
||||
Address [][]byte
|
||||
Topics [][]byte
|
||||
Topics [][][]byte
|
||||
|
||||
Skip int
|
||||
Max int
|
||||
|
|
@ -31,7 +31,7 @@ type Filter struct {
|
|||
skip int
|
||||
address [][]byte
|
||||
max int
|
||||
topics [][]byte
|
||||
topics [][][]byte
|
||||
|
||||
BlockCallback func(*types.Block)
|
||||
PendingCallback func(*types.Block)
|
||||
|
|
@ -44,6 +44,8 @@ func NewFilter(eth Backend) *Filter {
|
|||
return &Filter{eth: eth}
|
||||
}
|
||||
|
||||
// SetOptions copies the filter options to the filter it self. The reason for this "silly" copy
|
||||
// is simply because named arguments in this case is extremely nice and readable.
|
||||
func (self *Filter) SetOptions(options FilterOptions) {
|
||||
self.earliest = options.Earliest
|
||||
self.latest = options.Latest
|
||||
|
|
@ -69,7 +71,7 @@ func (self *Filter) SetAddress(addr [][]byte) {
|
|||
self.address = addr
|
||||
}
|
||||
|
||||
func (self *Filter) SetTopics(topics [][]byte) {
|
||||
func (self *Filter) SetTopics(topics [][][]byte) {
|
||||
self.topics = topics
|
||||
}
|
||||
|
||||
|
|
@ -149,10 +151,18 @@ Logs:
|
|||
continue
|
||||
}
|
||||
|
||||
max := int(math.Min(float64(len(self.topics)), float64(len(log.Topics()))))
|
||||
for i := 0; i < max; i++ {
|
||||
if !bytes.Equal(log.Topics()[i], self.topics[i]) {
|
||||
continue Logs
|
||||
logTopics := make([][]byte, len(self.topics))
|
||||
copy(logTopics, log.Topics())
|
||||
|
||||
for i, topics := range self.topics {
|
||||
for _, topic := range topics {
|
||||
var match bool
|
||||
if bytes.Equal(log.Topics()[i], topic) {
|
||||
match = true
|
||||
}
|
||||
if !match {
|
||||
continue Logs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -177,8 +187,15 @@ func (self *Filter) bloomFilter(block *types.Block) bool {
|
|||
}
|
||||
}
|
||||
|
||||
for _, topic := range self.topics {
|
||||
if !types.BloomLookup(block.Bloom(), topic) {
|
||||
for _, sub := range self.topics {
|
||||
var included bool
|
||||
for _, topic := range sub {
|
||||
if types.BloomLookup(block.Bloom(), topic) {
|
||||
included = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !included {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,8 +51,6 @@ func GenesisBlock(db ethutil.Database) *types.Block {
|
|||
statedb.Sync()
|
||||
genesis.Header().Root = statedb.Root()
|
||||
|
||||
fmt.Printf("+++ genesis +++\nRoot: %x\nHash: %x\n", genesis.Header().Root, genesis.Hash())
|
||||
|
||||
return genesis
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
ethlogger "github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/miner"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
|
|
@ -23,8 +23,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
logger = ethlogger.NewLogger("SERV")
|
||||
jsonlogger = ethlogger.NewJsonLogger()
|
||||
ethlogger = logger.NewLogger("SERV")
|
||||
jsonlogger = logger.NewJsonLogger()
|
||||
|
||||
defaultBootNodes = []*discover.Node{
|
||||
// ETH/DEV cmd/bootnode
|
||||
|
|
@ -74,7 +74,7 @@ func (cfg *Config) parseBootNodes() []*discover.Node {
|
|||
}
|
||||
n, err := discover.ParseNode(url)
|
||||
if err != nil {
|
||||
logger.Errorf("Bootstrap URL %s: %v\n", url, err)
|
||||
ethlogger.Errorf("Bootstrap URL %s: %v\n", url, err)
|
||||
continue
|
||||
}
|
||||
ns = append(ns, n)
|
||||
|
|
@ -98,7 +98,7 @@ func (cfg *Config) nodeKey() (*ecdsa.PrivateKey, error) {
|
|||
return nil, fmt.Errorf("could not generate server key: %v", err)
|
||||
}
|
||||
if err := ioutil.WriteFile(keyfile, crypto.FromECDSA(key), 0600); err != nil {
|
||||
logger.Errorln("could not persist nodekey: ", err)
|
||||
ethlogger.Errorln("could not persist nodekey: ", err)
|
||||
}
|
||||
return key, nil
|
||||
}
|
||||
|
|
@ -127,17 +127,16 @@ type Ethereum struct {
|
|||
miner *miner.Miner
|
||||
|
||||
RpcServer rpc.RpcServer
|
||||
WsServer rpc.RpcServer
|
||||
keyManager *crypto.KeyManager
|
||||
|
||||
logger ethlogger.LogSystem
|
||||
logger logger.LogSystem
|
||||
|
||||
Mining bool
|
||||
}
|
||||
|
||||
func New(config *Config) (*Ethereum, error) {
|
||||
// Boostrap database
|
||||
logger := ethlogger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat)
|
||||
ethlogger := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat)
|
||||
db, err := ethdb.NewLDBDatabase("blockchain")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -147,7 +146,7 @@ func New(config *Config) (*Ethereum, error) {
|
|||
d, _ := db.Get([]byte("ProtocolVersion"))
|
||||
protov := ethutil.NewValue(d).Uint()
|
||||
if protov != ProtocolVersion && protov != 0 {
|
||||
path := path.Join(config.DataDir, "database")
|
||||
path := path.Join(config.DataDir, "blockchain")
|
||||
return nil, fmt.Errorf("Database version mismatch. Protocol(%d / %d). `rm -rf %s`", protov, ProtocolVersion, path)
|
||||
}
|
||||
|
||||
|
|
@ -174,7 +173,7 @@ func New(config *Config) (*Ethereum, error) {
|
|||
keyManager: keyManager,
|
||||
blacklist: p2p.NewBlacklist(),
|
||||
eventMux: &event.TypeMux{},
|
||||
logger: logger,
|
||||
logger: ethlogger,
|
||||
}
|
||||
|
||||
eth.chainManager = core.NewChainManager(db, eth.EventMux())
|
||||
|
|
@ -216,7 +215,7 @@ func New(config *Config) (*Ethereum, error) {
|
|||
}
|
||||
|
||||
func (s *Ethereum) KeyManager() *crypto.KeyManager { return s.keyManager }
|
||||
func (s *Ethereum) Logger() ethlogger.LogSystem { return s.logger }
|
||||
func (s *Ethereum) Logger() logger.LogSystem { return s.logger }
|
||||
func (s *Ethereum) Name() string { return s.net.Name }
|
||||
func (s *Ethereum) ChainManager() *core.ChainManager { return s.chainManager }
|
||||
func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcessor }
|
||||
|
|
@ -234,7 +233,7 @@ func (s *Ethereum) Coinbase() []byte { return nil } // TODO
|
|||
|
||||
// Start the ethereum
|
||||
func (s *Ethereum) Start() error {
|
||||
jsonlogger.LogJson(ðlogger.LogStarting{
|
||||
jsonlogger.LogJson(&logger.LogStarting{
|
||||
ClientString: s.net.Name,
|
||||
ProtocolVersion: ProtocolVersion,
|
||||
})
|
||||
|
|
@ -260,7 +259,7 @@ func (s *Ethereum) Start() error {
|
|||
s.blockSub = s.eventMux.Subscribe(core.NewMinedBlockEvent{})
|
||||
go s.blockBroadcastLoop()
|
||||
|
||||
logger.Infoln("Server started")
|
||||
ethlogger.Infoln("Server started")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -285,9 +284,7 @@ func (s *Ethereum) Stop() {
|
|||
if s.RpcServer != nil {
|
||||
s.RpcServer.Stop()
|
||||
}
|
||||
if s.WsServer != nil {
|
||||
s.WsServer.Stop()
|
||||
}
|
||||
|
||||
s.txPool.Stop()
|
||||
s.eventMux.Stop()
|
||||
s.blockPool.Stop()
|
||||
|
|
@ -295,7 +292,7 @@ func (s *Ethereum) Stop() {
|
|||
s.whisper.Stop()
|
||||
}
|
||||
|
||||
logger.Infoln("Server stopped")
|
||||
ethlogger.Infoln("Server stopped")
|
||||
close(s.shutdownChan)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
ethlogger "github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/pow"
|
||||
)
|
||||
|
||||
var poolLogger = ethlogger.NewLogger("Blockpool")
|
||||
var poolLogger = logger.NewLogger("Blockpool")
|
||||
|
||||
const (
|
||||
blockHashesBatchSize = 256
|
||||
|
|
|
|||
|
|
@ -12,19 +12,19 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
ethlogger "github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/pow"
|
||||
)
|
||||
|
||||
const waitTimeout = 60 // seconds
|
||||
|
||||
var logsys = ethlogger.NewStdLogSystem(os.Stdout, log.LstdFlags, ethlogger.LogLevel(ethlogger.DebugDetailLevel))
|
||||
var logsys = logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.LogLevel(logger.DebugDetailLevel))
|
||||
|
||||
var ini = false
|
||||
|
||||
func logInit() {
|
||||
if !ini {
|
||||
ethlogger.AddLogSystem(logsys)
|
||||
logger.AddLogSystem(logsys)
|
||||
ini = true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
)
|
||||
|
|
@ -137,6 +138,12 @@ func (self *ethProtocol) handle() error {
|
|||
if err := msg.Decode(&txs); err != nil {
|
||||
return self.protoError(ErrDecode, "msg %v: %v", msg, err)
|
||||
}
|
||||
for _, tx := range txs {
|
||||
jsonlogger.LogJson(&logger.EthTxReceived{
|
||||
TxHash: ethutil.Bytes2Hex(tx.Hash()),
|
||||
RemoteId: self.peer.ID().String(),
|
||||
})
|
||||
}
|
||||
self.txPool.AddTransactions(txs)
|
||||
|
||||
case GetBlockHashesMsg:
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
ethlogger "github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
)
|
||||
|
||||
var sys = ethlogger.NewStdLogSystem(os.Stdout, log.LstdFlags, ethlogger.LogLevel(ethlogger.DebugDetailLevel))
|
||||
var sys = logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.LogLevel(logger.DebugDetailLevel))
|
||||
|
||||
type testMsgReadWriter struct {
|
||||
in chan p2p.Msg
|
||||
|
|
|
|||
|
|
@ -15,11 +15,13 @@ import (
|
|||
|
||||
func DefaultAssetPath() string {
|
||||
var assetPath string
|
||||
pwd, _ := os.Getwd()
|
||||
srcdir := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist")
|
||||
|
||||
// If the current working directory is the go-ethereum dir
|
||||
// assume a debug build and use the source directory as
|
||||
// asset directory.
|
||||
pwd, _ := os.Getwd()
|
||||
if pwd == path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist") {
|
||||
if pwd == srcdir {
|
||||
assetPath = path.Join(pwd, "assets")
|
||||
} else {
|
||||
switch runtime.GOOS {
|
||||
|
|
@ -35,6 +37,13 @@ func DefaultAssetPath() string {
|
|||
assetPath = "."
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the assetPath exists. If not, try the source directory
|
||||
// This happens when binary is run from outside cmd/mist directory
|
||||
if _, err := os.Stat(assetPath); os.IsNotExist(err) {
|
||||
assetPath = path.Join(srcdir, "assets")
|
||||
}
|
||||
|
||||
return assetPath
|
||||
}
|
||||
|
||||
|
|
|
|||
53
install.sh
53
install.sh
|
|
@ -1,53 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
if [ "$1" == "" ]; then
|
||||
echo "Usage $0 executable branch"
|
||||
echo "executable ethereum | mist"
|
||||
echo "branch develop | master"
|
||||
exit
|
||||
fi
|
||||
|
||||
exe=$1
|
||||
path=$exe
|
||||
branch=$2
|
||||
|
||||
if [ "$branch" == "develop" ]; then
|
||||
path="cmd/$exe"
|
||||
fi
|
||||
|
||||
# Test if go is installed
|
||||
command -v go >/dev/null 2>&1 || { echo >&2 "Unable to find 'go'. This script requires go."; exit 1; }
|
||||
|
||||
# Test if $GOPATH is set
|
||||
if [ "$GOPATH" == "" ]; then
|
||||
echo "\$GOPATH not set"
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "changing branch to $branch"
|
||||
cd $GOPATH/src/github.com/ethereum/go-ethereum
|
||||
git checkout $branch
|
||||
|
||||
# installing package dependencies doesn't work for develop
|
||||
# branch as go get always pulls from master head
|
||||
# so build will continue to fail, but this installs locally
|
||||
# for people who git clone since go install will manage deps
|
||||
|
||||
#echo "go get -u -d github.com/ethereum/go-ethereum/$path"
|
||||
#go get -v -u -d github.com/ethereum/go-ethereum/$path
|
||||
#if [ $? != 0 ]; then
|
||||
# echo "go get failed"
|
||||
# exit
|
||||
#fi
|
||||
|
||||
cd $GOPATH/src/github.com/ethereum/go-ethereum/$path
|
||||
|
||||
if [ "$exe" == "mist" ]; then
|
||||
echo "Building Mist GUI. Assuming Qt is installed. If this step"
|
||||
echo "fails; please refer to: https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum(Go)"
|
||||
else
|
||||
echo "Building ethereum CLI."
|
||||
fi
|
||||
|
||||
go install
|
||||
echo "done. Please run $exe :-)"
|
||||
|
|
@ -24,7 +24,7 @@ var jsrelogger = logger.NewLogger("JSRE")
|
|||
type JSRE struct {
|
||||
ethereum *eth.Ethereum
|
||||
Vm *otto.Otto
|
||||
pipe *xeth.XEth
|
||||
xeth *xeth.XEth
|
||||
|
||||
events event.Subscription
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
|
|||
// We have to make sure that, whoever calls this, calls "Stop"
|
||||
go re.mainLoop()
|
||||
|
||||
re.Bind("eth", &JSEthereum{re.pipe, re.Vm, ethereum})
|
||||
re.Bind("eth", &JSEthereum{re.xeth, re.Vm, ethereum})
|
||||
|
||||
re.initStdFuncs()
|
||||
|
||||
|
|
@ -113,12 +113,10 @@ func (self *JSRE) mainLoop() {
|
|||
func (self *JSRE) initStdFuncs() {
|
||||
t, _ := self.Vm.Get("eth")
|
||||
eth := t.Object()
|
||||
eth.Set("watch", self.watch)
|
||||
eth.Set("addPeer", self.addPeer)
|
||||
eth.Set("connect", self.connect)
|
||||
eth.Set("require", self.require)
|
||||
eth.Set("stopMining", self.stopMining)
|
||||
eth.Set("startMining", self.startMining)
|
||||
eth.Set("execBlock", self.execBlock)
|
||||
eth.Set("dump", self.dump)
|
||||
eth.Set("export", self.export)
|
||||
}
|
||||
|
|
@ -152,7 +150,8 @@ func (self *JSRE) dump(call otto.FunctionCall) otto.Value {
|
|||
}
|
||||
|
||||
statedb := state.New(block.Root(), self.ethereum.Db())
|
||||
v, _ := self.Vm.ToValue(statedb.Dump())
|
||||
|
||||
v, _ := self.Vm.ToValue(statedb.RawDump())
|
||||
|
||||
return v
|
||||
}
|
||||
|
|
@ -167,36 +166,7 @@ func (self *JSRE) startMining(call otto.FunctionCall) otto.Value {
|
|||
return v
|
||||
}
|
||||
|
||||
// eth.watch
|
||||
func (self *JSRE) watch(call otto.FunctionCall) otto.Value {
|
||||
addr, _ := call.Argument(0).ToString()
|
||||
var storageAddr string
|
||||
var cb otto.Value
|
||||
var storageCallback bool
|
||||
if len(call.ArgumentList) > 2 {
|
||||
storageCallback = true
|
||||
storageAddr, _ = call.Argument(1).ToString()
|
||||
cb = call.Argument(2)
|
||||
} else {
|
||||
cb = call.Argument(1)
|
||||
}
|
||||
|
||||
if storageCallback {
|
||||
self.objectCb[addr+storageAddr] = append(self.objectCb[addr+storageAddr], cb)
|
||||
|
||||
// event := "storage:" + string(ethutil.Hex2Bytes(addr)) + ":" + string(ethutil.Hex2Bytes(storageAddr))
|
||||
// self.ethereum.EventMux().Subscribe(event, self.changeChan)
|
||||
} else {
|
||||
self.objectCb[addr] = append(self.objectCb[addr], cb)
|
||||
|
||||
// event := "object:" + string(ethutil.Hex2Bytes(addr))
|
||||
// self.ethereum.EventMux().Subscribe(event, self.changeChan)
|
||||
}
|
||||
|
||||
return otto.UndefinedValue()
|
||||
}
|
||||
|
||||
func (self *JSRE) addPeer(call otto.FunctionCall) otto.Value {
|
||||
func (self *JSRE) connect(call otto.FunctionCall) otto.Value {
|
||||
nodeURL, err := call.Argument(0).ToString()
|
||||
if err != nil {
|
||||
return otto.FalseValue()
|
||||
|
|
@ -222,22 +192,12 @@ func (self *JSRE) require(call otto.FunctionCall) otto.Value {
|
|||
return t
|
||||
}
|
||||
|
||||
func (self *JSRE) execBlock(call otto.FunctionCall) otto.Value {
|
||||
hash, err := call.Argument(0).ToString()
|
||||
if err != nil {
|
||||
return otto.UndefinedValue()
|
||||
}
|
||||
|
||||
err = utils.BlockDo(self.ethereum, ethutil.Hex2Bytes(hash))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
func (self *JSRE) export(call otto.FunctionCall) otto.Value {
|
||||
if len(call.ArgumentList) == 0 {
|
||||
fmt.Println("err: require file name")
|
||||
return otto.FalseValue()
|
||||
}
|
||||
|
||||
return otto.TrueValue()
|
||||
}
|
||||
|
||||
func (self *JSRE) export(call otto.FunctionCall) otto.Value {
|
||||
fn, err := call.Argument(0).ToString()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ function pp(object) {
|
|||
str += " ]";
|
||||
} else if(typeof(object) === "object") {
|
||||
str += "{ ";
|
||||
var last = Object.keys(object).sort().pop()
|
||||
var last = Object.keys(object).pop()
|
||||
for(var k in object) {
|
||||
str += k + ": " + pp(object[k]);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/eth"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/state"
|
||||
"github.com/ethereum/go-ethereum/ui"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
"github.com/obscuren/otto"
|
||||
)
|
||||
|
|
@ -96,17 +95,3 @@ func (self *JSEthereum) toVal(v interface{}) otto.Value {
|
|||
|
||||
return result
|
||||
}
|
||||
|
||||
func (self *JSEthereum) Messages(object map[string]interface{}) otto.Value {
|
||||
filter := ui.NewFilterFromMap(object, self.ethereum)
|
||||
|
||||
logs := filter.Find()
|
||||
var jslogs []JSLog
|
||||
for _, m := range logs {
|
||||
jslogs = append(jslogs, NewJSLog(m))
|
||||
}
|
||||
|
||||
v, _ := self.vm.ToValue(jslogs)
|
||||
|
||||
return v
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package logger
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -53,10 +54,10 @@ func (l *P2PDisconnected) EventName() string {
|
|||
}
|
||||
|
||||
type EthMinerNewBlock struct {
|
||||
BlockHash string `json:"block_hash"`
|
||||
BlockNumber int `json:"block_number"`
|
||||
ChainHeadHash string `json:"chain_head_hash"`
|
||||
BlockPrevHash string `json:"block_prev_hash"`
|
||||
BlockHash string `json:"block_hash"`
|
||||
BlockNumber *big.Int `json:"block_number"`
|
||||
ChainHeadHash string `json:"chain_head_hash"`
|
||||
BlockPrevHash string `json:"block_prev_hash"`
|
||||
LogEvent
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,10 +52,5 @@ func (self *Miner) Stop() {
|
|||
}
|
||||
|
||||
func (self *Miner) HashRate() int64 {
|
||||
var tot int64
|
||||
for _, agent := range self.worker.agents {
|
||||
tot += agent.Pow().GetHashrate()
|
||||
}
|
||||
|
||||
return tot
|
||||
return self.worker.HashRate()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,16 +5,20 @@ import (
|
|||
"math/big"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
"github.com/ethereum/go-ethereum/event"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/pow"
|
||||
"github.com/ethereum/go-ethereum/state"
|
||||
"gopkg.in/fatih/set.v0"
|
||||
)
|
||||
|
||||
var jsonlogger = logger.NewJsonLogger()
|
||||
|
||||
type environment struct {
|
||||
totalUsedGas *big.Int
|
||||
state *state.StateDB
|
||||
|
|
@ -113,6 +117,8 @@ func (self *worker) register(agent Agent) {
|
|||
func (self *worker) update() {
|
||||
events := self.mux.Subscribe(core.ChainEvent{}, core.NewMinedBlockEvent{})
|
||||
|
||||
timer := time.NewTicker(2 * time.Second)
|
||||
|
||||
out:
|
||||
for {
|
||||
select {
|
||||
|
|
@ -131,6 +137,8 @@ out:
|
|||
agent.Stop()
|
||||
}
|
||||
break out
|
||||
case <-timer.C:
|
||||
minerlogger.Debugln("Hash rate:", self.HashRate(), "Khash")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -146,7 +154,12 @@ func (self *worker) wait() {
|
|||
self.current.block.Header().Nonce = work.Nonce
|
||||
self.current.block.Header().MixDigest = work.MixDigest
|
||||
self.current.block.Header().SeedHash = work.SeedHash
|
||||
|
||||
jsonlogger.LogJson(&logger.EthMinerNewBlock{
|
||||
BlockHash: ethutil.Bytes2Hex(block.Hash()),
|
||||
BlockNumber: block.Number(),
|
||||
ChainHeadHash: ethutil.Bytes2Hex(block.ParentHeaderHash),
|
||||
BlockPrevHash: ethutil.Bytes2Hex(block.ParentHeaderHash),
|
||||
})
|
||||
if err := self.chain.InsertChain(types.Blocks{self.current.block}); err == nil {
|
||||
self.mux.Post(core.NewMinedBlockEvent{self.current.block})
|
||||
} else {
|
||||
|
|
@ -249,3 +262,12 @@ func (self *worker) commitTransaction(tx *types.Transaction) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *worker) HashRate() int64 {
|
||||
var tot int64
|
||||
for _, agent := range self.agents {
|
||||
tot += agent.Pow().GetHashrate()
|
||||
}
|
||||
|
||||
return tot
|
||||
}
|
||||
|
|
|
|||
18
rpc/args.go
18
rpc/args.go
|
|
@ -197,7 +197,7 @@ type FilterOptions struct {
|
|||
Earliest int64
|
||||
Latest int64
|
||||
Address interface{}
|
||||
Topic []string
|
||||
Topic []interface{}
|
||||
Skip int
|
||||
Max int
|
||||
}
|
||||
|
|
@ -220,10 +220,20 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions {
|
|||
|
||||
opts.Earliest = options.Earliest
|
||||
opts.Latest = options.Latest
|
||||
opts.Topics = make([][]byte, len(options.Topic))
|
||||
for i, topic := range options.Topic {
|
||||
opts.Topics[i] = fromHex(topic)
|
||||
|
||||
topics := make([][][]byte, len(options.Topic))
|
||||
for i, topicDat := range options.Topic {
|
||||
if slice, ok := topicDat.([]interface{}); ok {
|
||||
topics[i] = make([][]byte, len(slice))
|
||||
for j, topic := range slice {
|
||||
topics[i][j] = fromHex(topic.(string))
|
||||
}
|
||||
} else if str, ok := topicDat.(string); ok {
|
||||
topics[i] = make([][]byte, 1)
|
||||
topics[i][0] = fromHex(str)
|
||||
}
|
||||
}
|
||||
opts.Topics = topics
|
||||
|
||||
return opts
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ import (
|
|||
var rpchttplogger = logger.NewLogger("RPC-HTTP")
|
||||
var JSON rpc.JsonWrapper
|
||||
|
||||
func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) {
|
||||
sport := fmt.Sprintf("127.0.0.1:%d", port)
|
||||
func NewRpcHttpServer(pipe *xeth.XEth, address string, port int) (*RpcHttpServer, error) {
|
||||
sport := fmt.Sprintf("%s:%d", address, port)
|
||||
l, err := net.Listen("tcp", sport)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -41,6 +41,7 @@ func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) {
|
|||
quit: make(chan bool),
|
||||
pipe: pipe,
|
||||
port: port,
|
||||
addr: address,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +50,7 @@ type RpcHttpServer struct {
|
|||
listener net.Listener
|
||||
pipe *xeth.XEth
|
||||
port int
|
||||
addr string
|
||||
}
|
||||
|
||||
func (s *RpcHttpServer) exitHandler() {
|
||||
|
|
@ -69,7 +71,7 @@ func (s *RpcHttpServer) Stop() {
|
|||
}
|
||||
|
||||
func (s *RpcHttpServer) Start() {
|
||||
rpchttplogger.Infof("Starting RPC-HTTP server on port %d", s.port)
|
||||
rpchttplogger.Infof("Starting RPC-HTTP server on %s:%d", s.addr, s.port)
|
||||
go s.exitHandler()
|
||||
|
||||
api := rpc.NewEthereumApi(s.pipe)
|
||||
|
|
|
|||
121
rpc/ws/server.go
121
rpc/ws/server.go
|
|
@ -1,121 +0,0 @@
|
|||
/*
|
||||
This file is part of go-ethereum
|
||||
|
||||
go-ethereum is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
go-ethereum is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package rpcws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
"golang.org/x/net/websocket"
|
||||
)
|
||||
|
||||
var wslogger = logger.NewLogger("RPC-WS")
|
||||
var JSON rpc.JsonWrapper
|
||||
|
||||
type WebSocketServer struct {
|
||||
pipe *xeth.XEth
|
||||
port int
|
||||
doneCh chan bool
|
||||
listener net.Listener
|
||||
}
|
||||
|
||||
func NewWebSocketServer(pipe *xeth.XEth, port int) (*WebSocketServer, error) {
|
||||
sport := fmt.Sprintf(":%d", port)
|
||||
l, err := net.Listen("tcp", sport)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &WebSocketServer{
|
||||
pipe,
|
||||
port,
|
||||
make(chan bool),
|
||||
l,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (self *WebSocketServer) handlerLoop() {
|
||||
for {
|
||||
select {
|
||||
case <-self.doneCh:
|
||||
wslogger.Infoln("Shutdown RPC-WS server")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *WebSocketServer) Stop() {
|
||||
close(self.doneCh)
|
||||
}
|
||||
|
||||
func (self *WebSocketServer) Start() {
|
||||
wslogger.Infof("Starting RPC-WS server on port %d", self.port)
|
||||
go self.handlerLoop()
|
||||
|
||||
api := rpc.NewEthereumApi(self.pipe)
|
||||
h := self.apiHandler(api)
|
||||
http.Handle("/ws", h)
|
||||
|
||||
err := http.Serve(self.listener, nil)
|
||||
if err != nil {
|
||||
wslogger.Errorln("Error on RPC-WS interface:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *WebSocketServer) apiHandler(api *rpc.EthereumApi) http.Handler {
|
||||
fn := func(w http.ResponseWriter, req *http.Request) {
|
||||
h := sockHandler(api)
|
||||
s := websocket.Server{Handler: h}
|
||||
s.ServeHTTP(w, req)
|
||||
}
|
||||
|
||||
return http.HandlerFunc(fn)
|
||||
}
|
||||
|
||||
func sockHandler(api *rpc.EthereumApi) websocket.Handler {
|
||||
var jsonrpcver string = "2.0"
|
||||
fn := func(conn *websocket.Conn) {
|
||||
for {
|
||||
wslogger.Debugln("Handling connection")
|
||||
var reqParsed rpc.RpcRequest
|
||||
|
||||
// reqParsed, reqerr := JSON.ParseRequestBody(conn.Request())
|
||||
if err := websocket.JSON.Receive(conn, &reqParsed); err != nil {
|
||||
jsonerr := &rpc.RpcErrorObject{-32700, "Error: Could not parse request"}
|
||||
JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr})
|
||||
continue
|
||||
}
|
||||
|
||||
var response interface{}
|
||||
reserr := api.GetRequestReply(&reqParsed, &response)
|
||||
if reserr != nil {
|
||||
wslogger.Warnln(reserr)
|
||||
jsonerr := &rpc.RpcErrorObject{-32603, reserr.Error()}
|
||||
JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Error: jsonerr})
|
||||
continue
|
||||
}
|
||||
|
||||
wslogger.Debugf("Generated response: %T %s", response, response)
|
||||
JSON.Send(conn, &rpc.RpcSuccessResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Result: response})
|
||||
}
|
||||
}
|
||||
return websocket.Handler(fn)
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ type World struct {
|
|||
Accounts map[string]Account `json:"accounts"`
|
||||
}
|
||||
|
||||
func (self *StateDB) Dump() []byte {
|
||||
func (self *StateDB) RawDump() World {
|
||||
world := World{
|
||||
Root: ethutil.Bytes2Hex(self.trie.Root()),
|
||||
Accounts: make(map[string]Account),
|
||||
|
|
@ -39,8 +39,11 @@ func (self *StateDB) Dump() []byte {
|
|||
}
|
||||
world.Accounts[ethutil.Bytes2Hex(it.Key)] = account
|
||||
}
|
||||
return world
|
||||
}
|
||||
|
||||
json, err := json.MarshalIndent(world, "", " ")
|
||||
func (self *StateDB) Dump() []byte {
|
||||
json, err := json.MarshalIndent(self.RawDump(), "", " ")
|
||||
if err != nil {
|
||||
fmt.Println("dump err", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func (self *StateDB) Refund(addr []byte, gas *big.Int) {
|
|||
|
||||
// Retrieve the balance from the given address or 0 if object not found
|
||||
func (self *StateDB) GetBalance(addr []byte) *big.Int {
|
||||
stateObject := self.GetStateObject(addr)
|
||||
stateObject := self.GetOrNewStateObject(addr)
|
||||
if stateObject != nil {
|
||||
return stateObject.balance
|
||||
}
|
||||
|
|
@ -63,14 +63,14 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int {
|
|||
}
|
||||
|
||||
func (self *StateDB) AddBalance(addr []byte, amount *big.Int) {
|
||||
stateObject := self.GetStateObject(addr)
|
||||
stateObject := self.GetOrNewStateObject(addr)
|
||||
if stateObject != nil {
|
||||
stateObject.AddBalance(amount)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *StateDB) GetNonce(addr []byte) uint64 {
|
||||
stateObject := self.GetStateObject(addr)
|
||||
stateObject := self.GetOrNewStateObject(addr)
|
||||
if stateObject != nil {
|
||||
return stateObject.nonce
|
||||
}
|
||||
|
|
@ -79,7 +79,7 @@ func (self *StateDB) GetNonce(addr []byte) uint64 {
|
|||
}
|
||||
|
||||
func (self *StateDB) GetCode(addr []byte) []byte {
|
||||
stateObject := self.GetStateObject(addr)
|
||||
stateObject := self.GetOrNewStateObject(addr)
|
||||
if stateObject != nil {
|
||||
return stateObject.code
|
||||
}
|
||||
|
|
@ -88,7 +88,7 @@ func (self *StateDB) GetCode(addr []byte) []byte {
|
|||
}
|
||||
|
||||
func (self *StateDB) GetState(a, b []byte) []byte {
|
||||
stateObject := self.GetStateObject(a)
|
||||
stateObject := self.GetOrNewStateObject(a)
|
||||
if stateObject != nil {
|
||||
return stateObject.GetState(b).Bytes()
|
||||
}
|
||||
|
|
@ -97,28 +97,28 @@ func (self *StateDB) GetState(a, b []byte) []byte {
|
|||
}
|
||||
|
||||
func (self *StateDB) SetNonce(addr []byte, nonce uint64) {
|
||||
stateObject := self.GetStateObject(addr)
|
||||
stateObject := self.GetOrNewStateObject(addr)
|
||||
if stateObject != nil {
|
||||
stateObject.SetNonce(nonce)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *StateDB) SetCode(addr, code []byte) {
|
||||
stateObject := self.GetStateObject(addr)
|
||||
stateObject := self.GetOrNewStateObject(addr)
|
||||
if stateObject != nil {
|
||||
stateObject.SetCode(code)
|
||||
}
|
||||
}
|
||||
|
||||
func (self *StateDB) SetState(addr, key []byte, value interface{}) {
|
||||
stateObject := self.GetStateObject(addr)
|
||||
stateObject := self.GetOrNewStateObject(addr)
|
||||
if stateObject != nil {
|
||||
stateObject.SetState(key, ethutil.NewValue(value))
|
||||
}
|
||||
}
|
||||
|
||||
func (self *StateDB) Delete(addr []byte) bool {
|
||||
stateObject := self.GetStateObject(addr)
|
||||
stateObject := self.GetOrNewStateObject(addr)
|
||||
if stateObject != nil {
|
||||
stateObject.MarkForDeletion()
|
||||
|
||||
|
|
|
|||
76
ui/filter.go
76
ui/filter.go
|
|
@ -1,77 +1 @@
|
|||
package ui
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/ethutil"
|
||||
)
|
||||
|
||||
func fromHex(s string) []byte {
|
||||
if len(s) > 1 {
|
||||
if s[0:2] == "0x" {
|
||||
s = s[2:]
|
||||
}
|
||||
return ethutil.Hex2Bytes(s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewFilterFromMap(object map[string]interface{}, eth core.Backend) *core.Filter {
|
||||
filter := core.NewFilter(eth)
|
||||
|
||||
if object["earliest"] != nil {
|
||||
val := ethutil.NewValue(object["earliest"])
|
||||
filter.SetEarliestBlock(val.Int())
|
||||
}
|
||||
|
||||
if object["latest"] != nil {
|
||||
val := ethutil.NewValue(object["latest"])
|
||||
filter.SetLatestBlock(val.Int())
|
||||
}
|
||||
|
||||
if object["address"] != nil {
|
||||
//val := ethutil.NewValue(object["address"])
|
||||
//filter.SetAddress(fromHex(val.Str()))
|
||||
}
|
||||
|
||||
if object["max"] != nil {
|
||||
val := ethutil.NewValue(object["max"])
|
||||
filter.SetMax(int(val.Uint()))
|
||||
}
|
||||
|
||||
if object["skip"] != nil {
|
||||
val := ethutil.NewValue(object["skip"])
|
||||
filter.SetSkip(int(val.Uint()))
|
||||
}
|
||||
|
||||
if object["topics"] != nil {
|
||||
filter.SetTopics(MakeTopics(object["topics"]))
|
||||
}
|
||||
|
||||
return filter
|
||||
}
|
||||
|
||||
// Conversion methodn
|
||||
func mapToAccountChange(m map[string]interface{}) (d core.AccountChange) {
|
||||
if str, ok := m["id"].(string); ok {
|
||||
d.Address = fromHex(str)
|
||||
}
|
||||
|
||||
if str, ok := m["at"].(string); ok {
|
||||
d.StateAddress = fromHex(str)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// data can come in in the following formats:
|
||||
// ["aabbccdd", {id: "ccddee", at: "11223344"}], "aabbcc", {id: "ccddee", at: "1122"}
|
||||
func MakeTopics(v interface{}) (d [][]byte) {
|
||||
if str, ok := v.(string); ok {
|
||||
d = append(d, fromHex(str))
|
||||
} else if slice, ok := v.([]string); ok {
|
||||
for _, item := range slice {
|
||||
d = append(d, fromHex(item))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1 @@
|
|||
package qt
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/ui"
|
||||
"github.com/obscuren/qml"
|
||||
)
|
||||
|
||||
func NewFilterFromMap(object map[string]interface{}, eth core.Backend) *core.Filter {
|
||||
filter := ui.NewFilterFromMap(object, eth)
|
||||
|
||||
if object["topics"] != nil {
|
||||
filter.SetTopics(makeTopics(object["topics"]))
|
||||
}
|
||||
|
||||
return filter
|
||||
}
|
||||
|
||||
func makeTopics(v interface{}) (d [][]byte) {
|
||||
if qList, ok := v.(*qml.List); ok {
|
||||
var s []string
|
||||
qList.Convert(&s)
|
||||
|
||||
d = ui.MakeTopics(s)
|
||||
} else if str, ok := v.(string); ok {
|
||||
d = ui.MakeTopics(str)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
|||
18
vm/vm.go
18
vm/vm.go
|
|
@ -16,6 +16,8 @@ type Vm struct {
|
|||
logStr string
|
||||
|
||||
err error
|
||||
// For logging
|
||||
debug bool
|
||||
|
||||
Dbg Debugger
|
||||
|
||||
|
|
@ -32,7 +34,7 @@ func New(env Environment) *Vm {
|
|||
lt = LogTyDiff
|
||||
}
|
||||
|
||||
return &Vm{env: env, logTy: lt, Recoverable: true}
|
||||
return &Vm{debug: false, env: env, logTy: lt, Recoverable: true}
|
||||
}
|
||||
|
||||
func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.Int, callData []byte) (ret []byte, err error) {
|
||||
|
|
@ -938,17 +940,21 @@ func (self *Vm) RunPrecompiled(p *PrecompiledAccount, callData []byte, context *
|
|||
}
|
||||
|
||||
func (self *Vm) Printf(format string, v ...interface{}) VirtualMachine {
|
||||
if self.logTy == LogTyPretty {
|
||||
self.logStr += fmt.Sprintf(format, v...)
|
||||
if self.debug {
|
||||
if self.logTy == LogTyPretty {
|
||||
self.logStr += fmt.Sprintf(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Vm) Endl() VirtualMachine {
|
||||
if self.logTy == LogTyPretty {
|
||||
vmlogger.Debugln(self.logStr)
|
||||
self.logStr = ""
|
||||
if self.debug {
|
||||
if self.logTy == LogTyPretty {
|
||||
vmlogger.Debugln(self.logStr)
|
||||
self.logStr = ""
|
||||
}
|
||||
}
|
||||
|
||||
return self
|
||||
|
|
|
|||
25
vm/vm_jit.go
25
vm/vm_jit.go
|
|
@ -50,6 +50,7 @@ type RuntimeData struct {
|
|||
timestamp int64
|
||||
code *byte
|
||||
codeSize uint64
|
||||
codeHash i256
|
||||
}
|
||||
|
||||
func hash2llvm(h []byte) i256 {
|
||||
|
|
@ -180,6 +181,7 @@ func (self *JitVm) Run(me, caller ContextRef, code []byte, value, gas, price *bi
|
|||
self.data.timestamp = self.env.Time()
|
||||
self.data.code = getDataPtr(code)
|
||||
self.data.codeSize = uint64(len(code))
|
||||
self.data.codeHash = hash2llvm(crypto.Sha3(code)) // TODO: Get already computed hash?
|
||||
|
||||
jit := C.evmjit_create()
|
||||
retCode := C.evmjit_run(jit, unsafe.Pointer(&self.data), unsafe.Pointer(self))
|
||||
|
|
@ -197,12 +199,12 @@ func (self *JitVm) Run(me, caller ContextRef, code []byte, value, gas, price *bi
|
|||
receiverAddr := llvm2hashRef(bswap(&self.data.address))
|
||||
receiver := state.GetOrNewStateObject(receiverAddr)
|
||||
balance := state.GetBalance(me.Address())
|
||||
receiver.AddAmount(balance)
|
||||
receiver.AddBalance(balance)
|
||||
state.Delete(me.Address())
|
||||
}
|
||||
}
|
||||
|
||||
C.evmjit_destroy(jit);
|
||||
|
||||
C.evmjit_destroy(jit)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -278,7 +280,7 @@ func env_blockhash(_vm unsafe.Pointer, _number unsafe.Pointer, _result unsafe.Po
|
|||
}
|
||||
|
||||
//export env_call
|
||||
func env_call(_vm unsafe.Pointer, _gas unsafe.Pointer, _receiveAddr unsafe.Pointer, _value unsafe.Pointer, inDataPtr unsafe.Pointer, inDataLen uint64, outDataPtr *byte, outDataLen uint64, _codeAddr unsafe.Pointer) bool {
|
||||
func env_call(_vm unsafe.Pointer, _gas *int64, _receiveAddr unsafe.Pointer, _value unsafe.Pointer, inDataPtr unsafe.Pointer, inDataLen uint64, outDataPtr *byte, outDataLen uint64, _codeAddr unsafe.Pointer) bool {
|
||||
vm := (*JitVm)(_vm)
|
||||
|
||||
//fmt.Printf("env_call (depth %d)\n", vm.Env().Depth())
|
||||
|
|
@ -297,8 +299,7 @@ func env_call(_vm unsafe.Pointer, _gas unsafe.Pointer, _receiveAddr unsafe.Point
|
|||
inData := C.GoBytes(inDataPtr, C.int(inDataLen))
|
||||
outData := llvm2bytesRef(outDataPtr, outDataLen)
|
||||
codeAddr := llvm2hash((*i256)(_codeAddr))
|
||||
llvmGas := (*i256)(_gas)
|
||||
gas := llvm2big(llvmGas)
|
||||
gas := big.NewInt(*_gas)
|
||||
var out []byte
|
||||
var err error
|
||||
if bytes.Equal(codeAddr, receiveAddr) {
|
||||
|
|
@ -306,7 +307,7 @@ func env_call(_vm unsafe.Pointer, _gas unsafe.Pointer, _receiveAddr unsafe.Point
|
|||
} else {
|
||||
out, err = vm.env.CallCode(vm.me, codeAddr, inData, gas, vm.price, value)
|
||||
}
|
||||
*llvmGas = big2llvm(gas)
|
||||
*_gas = gas.Int64()
|
||||
if err == nil {
|
||||
copy(outData, out)
|
||||
return true
|
||||
|
|
@ -317,7 +318,7 @@ func env_call(_vm unsafe.Pointer, _gas unsafe.Pointer, _receiveAddr unsafe.Point
|
|||
}
|
||||
|
||||
//export env_create
|
||||
func env_create(_vm unsafe.Pointer, _gas unsafe.Pointer, _value unsafe.Pointer, initDataPtr unsafe.Pointer, initDataLen uint64, _result unsafe.Pointer) {
|
||||
func env_create(_vm unsafe.Pointer, _gas *int64, _value unsafe.Pointer, initDataPtr unsafe.Pointer, initDataLen uint64, _result unsafe.Pointer) {
|
||||
vm := (*JitVm)(_vm)
|
||||
|
||||
value := llvm2big((*i256)(_value))
|
||||
|
|
@ -325,9 +326,7 @@ func env_create(_vm unsafe.Pointer, _gas unsafe.Pointer, _value unsafe.Pointer,
|
|||
result := (*i256)(_result)
|
||||
*result = i256{}
|
||||
|
||||
llvmGas := (*i256)(_gas)
|
||||
gas := llvm2big(llvmGas)
|
||||
|
||||
gas := big.NewInt(*_gas)
|
||||
ret, suberr, ref := vm.env.Create(vm.me, nil, initData, gas, vm.price, value)
|
||||
if suberr == nil {
|
||||
dataGas := big.NewInt(int64(len(ret))) // TODO: Nto the best design. env.Create can do it, it has the reference to gas counter
|
||||
|
|
@ -335,7 +334,7 @@ func env_create(_vm unsafe.Pointer, _gas unsafe.Pointer, _value unsafe.Pointer,
|
|||
gas.Sub(gas, dataGas)
|
||||
*result = hash2llvm(ref.Address())
|
||||
}
|
||||
*llvmGas = big2llvm(gas)
|
||||
*_gas = gas.Int64()
|
||||
}
|
||||
|
||||
//export env_log
|
||||
|
|
@ -358,7 +357,7 @@ func env_log(_vm unsafe.Pointer, dataPtr unsafe.Pointer, dataLen uint64, _topic1
|
|||
topics = append(topics, llvm2hash((*i256)(_topic4)))
|
||||
}
|
||||
|
||||
vm.Env().AddLog(state.NewLog(vm.me.Address(), topics, data))
|
||||
vm.Env().AddLog(state.NewLog(vm.me.Address(), topics, data, vm.env.BlockNumber().Uint64()))
|
||||
}
|
||||
|
||||
//export env_extcode
|
||||
|
|
|
|||
|
|
@ -300,14 +300,6 @@ func (self *XEth) Transact(toStr, valueStr, gasStr, gasPriceStr, codeStr string)
|
|||
tx.SetNonce(nonce)
|
||||
tx.Sign(key.PrivateKey)
|
||||
|
||||
//fmt.Printf("create tx: %x %v\n", tx.Hash()[:4], tx.Nonce())
|
||||
|
||||
// Do some pre processing for our "pre" events and hooks
|
||||
//block := self.chainManager.NewBlock(key.Address())
|
||||
//coinbase := state.GetOrNewStateObject(key.Address())
|
||||
//coinbase.SetGasPool(block.GasLimit())
|
||||
//self.blockProcessor.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true)
|
||||
|
||||
err = self.eth.TxPool().Add(tx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
|||
Loading…
Reference in a new issue