mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
Merge branch 'develop' into bzz
Conflicts: cmd/ethereum/flags.go eth/backend.go
This commit is contained in:
commit
420344ca21
87 changed files with 1813 additions and 1259 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
language: go
|
language: go
|
||||||
go:
|
go:
|
||||||
- 1.4.1
|
- 1.4.2
|
||||||
before_install:
|
before_install:
|
||||||
- sudo add-apt-repository ppa:beineri/opt-qt54 -y
|
- sudo add-apt-repository ppa:beineri/opt-qt541 -y
|
||||||
- sudo apt-get update -qq
|
- sudo apt-get update -qq
|
||||||
- sudo apt-get install -yqq libgmp3-dev libreadline6-dev qt54quickcontrols qt54webengine
|
- sudo apt-get install -yqq libgmp3-dev libreadline6-dev qt54quickcontrols qt54webengine
|
||||||
install:
|
install:
|
||||||
|
|
|
||||||
12
Dockerfile
12
Dockerfile
|
|
@ -1,4 +1,4 @@
|
||||||
FROM ubuntu:14.04.1
|
FROM ubuntu:14.04.2
|
||||||
|
|
||||||
## Environment setup
|
## Environment setup
|
||||||
ENV HOME /root
|
ENV HOME /root
|
||||||
|
|
@ -12,22 +12,22 @@ ENV DEBIAN_FRONTEND noninteractive
|
||||||
RUN apt-get update && apt-get upgrade -y
|
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
|
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)
|
## Install Qt5.4.1 (not required for CLI)
|
||||||
# RUN add-apt-repository ppa:beineri/opt-qt54-trusty -y
|
# RUN add-apt-repository ppa:beineri/opt-qt541-trusty -y
|
||||||
# RUN apt-get update -y
|
# RUN apt-get update -y
|
||||||
# RUN apt-get install -y qt54quickcontrols qt54webengine mesa-common-dev libglu1-mesa-dev
|
# RUN apt-get install -y qt54quickcontrols qt54webengine mesa-common-dev libglu1-mesa-dev
|
||||||
# ENV PKG_CONFIG_PATH /opt/qt54/lib/pkgconfig
|
# ENV PKG_CONFIG_PATH /opt/qt54/lib/pkgconfig
|
||||||
|
|
||||||
# Install Golang
|
# 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
|
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
|
# 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
|
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 -v github.com/tools/godep
|
RUN go get github.com/tools/godep
|
||||||
RUN go get -v -d github.com/ethereum/go-ethereum/...
|
RUN go get -d 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 godep restore
|
||||||
|
|
|
||||||
11
Godeps/Godeps.json
generated
11
Godeps/Godeps.json
generated
|
|
@ -1,15 +1,10 @@
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/ethereum/go-ethereum",
|
"ImportPath": "github.com/ethereum/go-ethereum",
|
||||||
"GoVersion": "go1.4.1",
|
"GoVersion": "go1.4.2",
|
||||||
"Packages": [
|
"Packages": [
|
||||||
"./..."
|
"./..."
|
||||||
],
|
],
|
||||||
"Deps": [
|
"Deps": [
|
||||||
{
|
|
||||||
"ImportPath": "bitbucket.org/kardianos/osext",
|
|
||||||
"Comment": "null-13",
|
|
||||||
"Rev": "5d3ddcf53a508cc2f7404eaebf546ef2cb5cdb6e"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "code.google.com/p/go-uuid/uuid",
|
"ImportPath": "code.google.com/p/go-uuid/uuid",
|
||||||
"Comment": "null-12",
|
"Comment": "null-12",
|
||||||
|
|
@ -37,6 +32,10 @@
|
||||||
"ImportPath": "github.com/jackpal/go-nat-pmp",
|
"ImportPath": "github.com/jackpal/go-nat-pmp",
|
||||||
"Rev": "a45aa3d54aef73b504e15eb71bea0e5565b5e6e1"
|
"Rev": "a45aa3d54aef73b504e15eb71bea0e5565b5e6e1"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"ImportPath": "github.com/kardianos/osext",
|
||||||
|
"Rev": "ccfcd0245381f0c94c68f50626665eed3c6b726a"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/obscuren/otto",
|
"ImportPath": "github.com/obscuren/otto",
|
||||||
"Rev": "cf13cc4228c5e5ce0fe27a7aea90bc10091c4f19"
|
"Rev": "cf13cc4228c5e5ce0fe27a7aea90bc10091c4f19"
|
||||||
|
|
|
||||||
20
Godeps/_workspace/src/bitbucket.org/kardianos/osext/LICENSE
generated
vendored
20
Godeps/_workspace/src/bitbucket.org/kardianos/osext/LICENSE
generated
vendored
|
|
@ -1,20 +0,0 @@
|
||||||
Copyright (c) 2012 Daniel Theophanes
|
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
|
||||||
warranty. In no event will the authors be held liable for any damages
|
|
||||||
arising from the use of this software.
|
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
|
||||||
including commercial applications, and to alter it and redistribute it
|
|
||||||
freely, subject to the following restrictions:
|
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
|
||||||
claim that you wrote the original software. If you use this software
|
|
||||||
in a product, an acknowledgment in the product documentation would be
|
|
||||||
appreciated but is not required.
|
|
||||||
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
misrepresented as being the original software.
|
|
||||||
|
|
||||||
3. This notice may not be removed or altered from any source
|
|
||||||
distribution.
|
|
||||||
27
Godeps/_workspace/src/github.com/kardianos/osext/LICENSE
generated
vendored
Normal file
27
Godeps/_workspace/src/github.com/kardianos/osext/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
Copyright (c) 2012 The Go Authors. All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are
|
||||||
|
met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above
|
||||||
|
copyright notice, this list of conditions and the following disclaimer
|
||||||
|
in the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name of Google Inc. nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
14
Godeps/_workspace/src/github.com/kardianos/osext/README.md
generated
vendored
Normal file
14
Godeps/_workspace/src/github.com/kardianos/osext/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
### Extensions to the "os" package.
|
||||||
|
|
||||||
|
## Find the current Executable and ExecutableFolder.
|
||||||
|
|
||||||
|
There is sometimes utility in finding the current executable file
|
||||||
|
that is running. This can be used for upgrading the current executable
|
||||||
|
or finding resources located relative to the executable file.
|
||||||
|
|
||||||
|
Multi-platform and supports:
|
||||||
|
* Linux
|
||||||
|
* OS X
|
||||||
|
* Windows
|
||||||
|
* Plan 9
|
||||||
|
* BSDs.
|
||||||
|
|
@ -25,8 +25,3 @@ func ExecutableFolder() (string, error) {
|
||||||
folder, _ := filepath.Split(p)
|
folder, _ := filepath.Split(p)
|
||||||
return folder, nil
|
return folder, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Depricated. Same as Executable().
|
|
||||||
func GetExePath() (exePath string, err error) {
|
|
||||||
return Executable()
|
|
||||||
}
|
|
||||||
|
|
@ -5,9 +5,9 @@
|
||||||
package osext
|
package osext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func executable() (string, error) {
|
func executable() (string, error) {
|
||||||
|
|
@ -2,12 +2,13 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// +build linux netbsd openbsd
|
// +build linux netbsd openbsd solaris dragonfly
|
||||||
|
|
||||||
package osext
|
package osext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
@ -18,8 +19,10 @@ func executable() (string, error) {
|
||||||
return os.Readlink("/proc/self/exe")
|
return os.Readlink("/proc/self/exe")
|
||||||
case "netbsd":
|
case "netbsd":
|
||||||
return os.Readlink("/proc/curproc/exe")
|
return os.Readlink("/proc/curproc/exe")
|
||||||
case "openbsd":
|
case "openbsd", "dragonfly":
|
||||||
return os.Readlink("/proc/curproc/file")
|
return os.Readlink("/proc/curproc/file")
|
||||||
|
case "solaris":
|
||||||
|
return os.Readlink(fmt.Sprintf("/proc/%d/path/a.out", os.Getpid()))
|
||||||
}
|
}
|
||||||
return "", errors.New("ExecPath not implemented for " + runtime.GOOS)
|
return "", errors.New("ExecPath not implemented for " + runtime.GOOS)
|
||||||
}
|
}
|
||||||
112
README.md
112
README.md
|
|
@ -24,7 +24,25 @@ Ethereum (CLI):
|
||||||
|
|
||||||
`go get github.com/ethereum/go-ethereum/cmd/ethereum`
|
`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
|
Automated (dev) builds
|
||||||
======================
|
======================
|
||||||
|
|
@ -34,97 +52,47 @@ Automated (dev) builds
|
||||||
* [Windows] Coming soon™
|
* [Windows] Coming soon™
|
||||||
* [Linux] Coming soon™
|
* [Linux] Coming soon™
|
||||||
|
|
||||||
Binaries
|
Executables
|
||||||
========
|
===========
|
||||||
|
|
||||||
Go Ethereum comes with several binaries found in
|
Go Ethereum comes with several wrappers/executables found in
|
||||||
[cmd](https://github.com/ethereum/go-ethereum/tree/master/cmd):
|
[the `cmd` directory](https://github.com/ethereum/go-ethereum/tree/develop/cmd):
|
||||||
|
|
||||||
* `mist` Official Ethereum Browser
|
* `mist` Official Ethereum Browser (ethereum GUI client)
|
||||||
* `ethereum` Ethereum CLI
|
* `ethereum` Ethereum CLI (ethereum command line interface client)
|
||||||
* `ethtest` test tool which runs with the [tests](https://github.com/ethereum/testes) suit:
|
* `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`.
|
`cat file | ethtest`.
|
||||||
* `evm` is a generic Ethereum Virtual Machine: `evm -code 60ff60ff -gas
|
* `evm` is a generic Ethereum Virtual Machine: `evm -code 60ff60ff -gas
|
||||||
10000 -price 0 -dump`. See `-h` for a detailed description.
|
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`
|
* `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 ==
|
ethereum -help
|
||||||
|
|
||||||
= 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
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For further details on options, see the [wiki](https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options)
|
||||||
|
|
||||||
Contribution
|
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
|
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
|
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.
|
commit on the `develop` branch and that you do not merge to master.
|
||||||
Commits that are directly based on master are simply ignored.
|
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
|
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.
|
||||||
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!)
|
|
||||||
|
|
||||||
|
See [Developers' Guide](https://github.com/ethereum/go-ethereum/wiki/Developers'-Guide)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,16 @@ package accounts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
crand "crypto/rand"
|
crand "crypto/rand"
|
||||||
|
|
||||||
|
"errors"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrLocked = errors.New("account is locked; please request passphrase")
|
||||||
|
|
||||||
// TODO: better name for this struct?
|
// TODO: better name for this struct?
|
||||||
type Account struct {
|
type Account struct {
|
||||||
Address []byte
|
Address []byte
|
||||||
|
|
@ -44,14 +51,17 @@ type Account struct {
|
||||||
|
|
||||||
type AccountManager struct {
|
type AccountManager struct {
|
||||||
keyStore crypto.KeyStore2
|
keyStore crypto.KeyStore2
|
||||||
|
unlockedKeys map[string]crypto.Key
|
||||||
|
unlockMilliseconds time.Duration
|
||||||
|
mutex sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: get key by addr - modify KeyStore2 GetKey to work with addr
|
func NewAccountManager(keyStore crypto.KeyStore2, unlockMilliseconds time.Duration) AccountManager {
|
||||||
|
keysMap := make(map[string]crypto.Key)
|
||||||
// TODO: pass through passphrase for APIs which require access to private key?
|
|
||||||
func NewAccountManager(keyStore crypto.KeyStore2) AccountManager {
|
|
||||||
am := &AccountManager{
|
am := &AccountManager{
|
||||||
keyStore: keyStore,
|
keyStore: keyStore,
|
||||||
|
unlockedKeys: keysMap,
|
||||||
|
unlockMilliseconds: unlockMilliseconds,
|
||||||
}
|
}
|
||||||
return *am
|
return *am
|
||||||
}
|
}
|
||||||
|
|
@ -60,11 +70,26 @@ func (am AccountManager) DeleteAccount(address []byte, auth string) error {
|
||||||
return am.keyStore.DeleteKey(address, auth)
|
return am.keyStore.DeleteKey(address, auth)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (am *AccountManager) Sign(fromAccount *Account, keyAuth string, toSign []byte) (signature []byte, err error) {
|
func (am *AccountManager) Sign(fromAccount *Account, toSign []byte) (signature []byte, err error) {
|
||||||
|
am.mutex.RLock()
|
||||||
|
unlockedKey := am.unlockedKeys[string(fromAccount.Address)]
|
||||||
|
am.mutex.RUnlock()
|
||||||
|
if unlockedKey.Address == nil {
|
||||||
|
return nil, ErrLocked
|
||||||
|
}
|
||||||
|
signature, err = crypto.Sign(toSign, unlockedKey.PrivateKey)
|
||||||
|
return signature, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (am *AccountManager) SignLocked(fromAccount *Account, keyAuth string, toSign []byte) (signature []byte, err error) {
|
||||||
key, err := am.keyStore.GetKey(fromAccount.Address, keyAuth)
|
key, err := am.keyStore.GetKey(fromAccount.Address, keyAuth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
am.mutex.RLock()
|
||||||
|
am.unlockedKeys[string(fromAccount.Address)] = *key
|
||||||
|
am.mutex.RUnlock()
|
||||||
|
go unlockLater(am, fromAccount.Address)
|
||||||
signature, err = crypto.Sign(toSign, key.PrivateKey)
|
signature, err = crypto.Sign(toSign, key.PrivateKey)
|
||||||
return signature, err
|
return signature, err
|
||||||
}
|
}
|
||||||
|
|
@ -80,8 +105,6 @@ func (am AccountManager) NewAccount(auth string) (*Account, error) {
|
||||||
return ua, err
|
return ua, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// set of accounts == set of keys in given key store
|
|
||||||
// TODO: do we need persistence of accounts as well?
|
|
||||||
func (am *AccountManager) Accounts() ([]Account, error) {
|
func (am *AccountManager) Accounts() ([]Account, error) {
|
||||||
addresses, err := am.keyStore.GetKeyAddresses()
|
addresses, err := am.keyStore.GetKeyAddresses()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -97,3 +120,13 @@ func (am *AccountManager) Accounts() ([]Account, error) {
|
||||||
}
|
}
|
||||||
return accounts, err
|
return accounts, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func unlockLater(am *AccountManager, addr []byte) {
|
||||||
|
select {
|
||||||
|
case <-time.After(time.Millisecond * am.unlockMilliseconds):
|
||||||
|
}
|
||||||
|
am.mutex.RLock()
|
||||||
|
// TODO: how do we know the key is actually gone from memory?
|
||||||
|
delete(am.unlockedKeys, string(addr))
|
||||||
|
am.mutex.RUnlock()
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,68 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/crypto/randentropy"
|
"github.com/ethereum/go-ethereum/crypto/randentropy"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccountManager(t *testing.T) {
|
func TestAccountManager(t *testing.T) {
|
||||||
ks := crypto.NewKeyStorePlain(ethutil.DefaultDataDir() + "/testaccounts")
|
ks := crypto.NewKeyStorePlain(ethutil.DefaultDataDir() + "/testaccounts")
|
||||||
am := NewAccountManager(ks)
|
am := NewAccountManager(ks, 100)
|
||||||
pass := "" // not used but required by API
|
pass := "" // not used but required by API
|
||||||
a1, err := am.NewAccount(pass)
|
a1, err := am.NewAccount(pass)
|
||||||
toSign := randentropy.GetEntropyCSPRNG(32)
|
toSign := randentropy.GetEntropyCSPRNG(32)
|
||||||
_, err = am.Sign(a1, pass, toSign)
|
_, err = am.SignLocked(a1, pass, toSign)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
time.Sleep(time.Millisecond * 150) // wait for locking
|
||||||
|
|
||||||
|
accounts, err := am.Accounts()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, account := range accounts {
|
||||||
|
err := am.DeleteAccount(account.Address, pass)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAccountManagerLocking(t *testing.T) {
|
||||||
|
ks := crypto.NewKeyStorePassphrase(ethutil.DefaultDataDir() + "/testaccounts")
|
||||||
|
am := NewAccountManager(ks, 200)
|
||||||
|
pass := "foo"
|
||||||
|
a1, err := am.NewAccount(pass)
|
||||||
|
toSign := randentropy.GetEntropyCSPRNG(32)
|
||||||
|
|
||||||
|
// Signing without passphrase fails because account is locked
|
||||||
|
_, err = am.Sign(a1, toSign)
|
||||||
|
if err != ErrLocked {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signing with passphrase works
|
||||||
|
_, err = am.SignLocked(a1, pass, toSign)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signing without passphrase works because account is temp unlocked
|
||||||
|
_, err = am.Sign(a1, toSign)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signing without passphrase fails after automatic locking
|
||||||
|
time.Sleep(time.Millisecond * time.Duration(250))
|
||||||
|
|
||||||
|
_, err = am.Sign(a1, toSign)
|
||||||
|
if err != ErrLocked {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
accounts, err := am.Accounts()
|
accounts, err := am.Accounts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
|
@ -43,8 +44,8 @@ var (
|
||||||
KeyStore string
|
KeyStore string
|
||||||
StartRpc bool
|
StartRpc bool
|
||||||
StartWebSockets bool
|
StartWebSockets bool
|
||||||
|
RpcListenAddress string
|
||||||
RpcPort int
|
RpcPort int
|
||||||
WsPort int
|
|
||||||
OutboundPort string
|
OutboundPort string
|
||||||
ShowGenesis bool
|
ShowGenesis bool
|
||||||
AddPeer string
|
AddPeer string
|
||||||
|
|
@ -70,8 +71,7 @@ var (
|
||||||
SHH bool
|
SHH bool
|
||||||
Dial bool
|
Dial bool
|
||||||
PrintVersion bool
|
PrintVersion bool
|
||||||
Peers string
|
MinerThreads int
|
||||||
Pull string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// flags specific to cli client
|
// flags specific to cli client
|
||||||
|
|
@ -93,24 +93,21 @@ func Init() {
|
||||||
flag.IntVar(&VmType, "vm", 0, "Virtual Machine type: 0-1: standard, debug")
|
flag.IntVar(&VmType, "vm", 0, "Virtual Machine type: 0-1: standard, debug")
|
||||||
flag.StringVar(&Identifier, "id", "", "Custom client identifier")
|
flag.StringVar(&Identifier, "id", "", "Custom client identifier")
|
||||||
flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
|
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(&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(&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(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
||||||
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
||||||
flag.StringVar(&Peers, "peers", "", "imports the file given (hex or mnemonic formats)")
|
|
||||||
flag.StringVar(&Pull, "pull", "", "swarm pull key")
|
|
||||||
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
|
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
|
||||||
flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
|
flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
|
||||||
flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
|
flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
|
||||||
flag.StringVar(&Datadir, "datadir", ethutil.DefaultDataDir(), "specifies the datadir to use")
|
flag.StringVar(&Datadir, "datadir", ethutil.DefaultDataDir(), "specifies the datadir to use")
|
||||||
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
||||||
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
|
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(&LogFormat, "logformat", "std", "logformat: std,raw)")
|
flag.StringVar(&LogFormat, "logformat", "std", "logformat: std,raw")
|
||||||
flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0")
|
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.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")
|
flag.BoolVar(&ShowGenesis, "genesis", false, "Dump the genesis block")
|
||||||
|
|
@ -120,9 +117,10 @@ func Init() {
|
||||||
flag.StringVar(&DumpHash, "hash", "", "specify arg in hex")
|
flag.StringVar(&DumpHash, "hash", "", "specify arg in hex")
|
||||||
flag.IntVar(&DumpNumber, "number", -1, "specify arg in number")
|
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(&StartJsConsole, "js", false, "launches javascript console")
|
||||||
flag.BoolVar(&PrintVersion, "version", false, "prints version number")
|
flag.BoolVar(&PrintVersion, "version", false, "prints version number")
|
||||||
|
flag.IntVar(&MinerThreads, "minerthreads", runtime.NumCPU(), "number of miner threads")
|
||||||
|
|
||||||
// Network stuff
|
// Network stuff
|
||||||
var (
|
var (
|
||||||
|
|
@ -139,6 +137,12 @@ func Init() {
|
||||||
|
|
||||||
flag.Parse()
|
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
|
var err error
|
||||||
if NAT, err = nat.Parse(*natstr); err != nil {
|
if NAT, err = nat.Parse(*natstr); err != nil {
|
||||||
log.Fatalf("-nat: %v", err)
|
log.Fatalf("-nat: %v", err)
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ClientIdentifier = "Ethereum(G)"
|
ClientIdentifier = "Ethereum(G)"
|
||||||
Version = "0.8.5"
|
Version = "0.8.6"
|
||||||
)
|
)
|
||||||
|
|
||||||
var clilogger = logger.NewLogger("CLI")
|
var clilogger = logger.NewLogger("CLI")
|
||||||
|
|
@ -76,6 +76,7 @@ func main() {
|
||||||
Dial: Dial,
|
Dial: Dial,
|
||||||
BootNodes: BootNodes,
|
BootNodes: BootNodes,
|
||||||
NodeKey: NodeKey,
|
NodeKey: NodeKey,
|
||||||
|
MinerThreads: MinerThreads,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -113,10 +114,6 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if StartMining {
|
|
||||||
utils.StartMining(ethereum)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(ImportChain) > 0 {
|
if len(ImportChain) > 0 {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
err := utils.ImportChain(ethereum, ImportChain)
|
err := utils.ImportChain(ethereum, ImportChain)
|
||||||
|
|
@ -128,15 +125,17 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if StartRpc {
|
if StartRpc {
|
||||||
utils.StartRpc(ethereum, RpcPort)
|
utils.StartRpc(ethereum, RpcListenAddress, RpcPort)
|
||||||
}
|
|
||||||
|
|
||||||
if StartWebSockets {
|
|
||||||
utils.StartWebSockets(ethereum, WsPort)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.StartEthereum(ethereum, Peers, Pull)
|
utils.StartEthereum(ethereum, Peers, Pull)
|
||||||
|
|
||||||
|
fmt.Printf("Welcome to the FRONTIER\n")
|
||||||
|
|
||||||
|
if StartMining {
|
||||||
|
ethereum.Miner().Start()
|
||||||
|
}
|
||||||
|
|
||||||
if StartJsConsole {
|
if StartJsConsole {
|
||||||
InitJsConsole(ethereum)
|
InitJsConsole(ethereum)
|
||||||
} else if len(InputFile) > 0 {
|
} else if len(InputFile) > 0 {
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ func (self *JSRepl) Start() {
|
||||||
if !self.running {
|
if !self.running {
|
||||||
self.running = true
|
self.running = true
|
||||||
repllogger.Infoln("init JS Console")
|
repllogger.Infoln("init JS Console")
|
||||||
|
|
||||||
reader := bufio.NewReader(self.history)
|
reader := bufio.NewReader(self.history)
|
||||||
for {
|
for {
|
||||||
line, err := reader.ReadString('\n')
|
line, err := reader.ReadString('\n')
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,8 @@
|
||||||
|
|
||||||
web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8545'));
|
web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8545'));
|
||||||
|
|
||||||
|
eth.defaultBlock = -2
|
||||||
|
|
||||||
document.querySelector("#number").innerHTML = eth.number;
|
document.querySelector("#number").innerHTML = eth.number;
|
||||||
document.querySelector("#coinbase").innerHTML = eth.coinbase
|
document.querySelector("#coinbase").innerHTML = eth.coinbase
|
||||||
document.querySelector("#peer_count").innerHTML = eth.peerCount;
|
document.querySelector("#peer_count").innerHTML = eth.peerCount;
|
||||||
|
|
@ -75,6 +77,7 @@
|
||||||
document.querySelector("#number").innerHTML = eth.number;
|
document.querySelector("#number").innerHTML = eth.number;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
788
cmd/mist/assets/ext/ethereum.js/dist/ethereum.js
vendored
788
cmd/mist/assets/ext/ethereum.js/dist/ethereum.js
vendored
File diff suppressed because it is too large
Load diff
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
// this function is included locally, but you can also include separately via a header definition
|
// this function is included locally, but you can also include separately via a header definition
|
||||||
|
|
||||||
console.log("loaded?");
|
|
||||||
|
|
||||||
document.onkeydown = function(evt) {
|
document.onkeydown = function(evt) {
|
||||||
// This functions keeps track of keyboard inputs in order to allow copy, paste and other features
|
// This functions keeps track of keyboard inputs in order to allow copy, paste and other features
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,14 @@ ApplicationWindow {
|
||||||
walletWeb.view.url = "http://ethereum-dapp-wallet.meteor.com/";
|
walletWeb.view.url = "http://ethereum-dapp-wallet.meteor.com/";
|
||||||
walletWeb.menuItem.title = "Wallet";
|
walletWeb.menuItem.title = "Wallet";
|
||||||
|
|
||||||
addPlugin("./views/miner.qml", {noAdd: true, close: false, section: "ethereum", active: false});
|
addPlugin("./views/miner.qml", {noAdd: true, close: false, section: "legacy", active: false});
|
||||||
|
addPlugin("./views/network.qml", {noAdd: true, close: false, section: "ethereum", active: false});
|
||||||
|
|
||||||
|
/* var whisperTab = addPlugin("./views/browser.qml", {noAdd: true, close: true, section: "ethereum", active: false});
|
||||||
|
whisperTab.view.url = "http://ethereum-dapp-whisper-client.meteor.com/";
|
||||||
|
whisperTab.menuItem.title = "Whisper Chat";
|
||||||
|
*/
|
||||||
|
addPlugin("./views/wallet.qml", {noAdd: true, close: false, section: "legacy"});
|
||||||
addPlugin("./views/transaction.qml", {noAdd: true, close: false, section: "legacy"});
|
addPlugin("./views/transaction.qml", {noAdd: true, close: false, section: "legacy"});
|
||||||
addPlugin("./views/whisper.qml", {noAdd: true, close: false, section: "legacy"});
|
addPlugin("./views/whisper.qml", {noAdd: true, close: false, section: "legacy"});
|
||||||
addPlugin("./views/chain.qml", {noAdd: true, close: false, section: "legacy"});
|
addPlugin("./views/chain.qml", {noAdd: true, close: false, section: "legacy"});
|
||||||
|
|
@ -530,6 +537,8 @@ ApplicationWindow {
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: secondary
|
id: secondary
|
||||||
|
//only shows secondary title if there's no badge
|
||||||
|
visible: (badgeContent == "icon" || badgeContent == "number" )? false : true
|
||||||
font.family: sourceSansPro.name
|
font.family: sourceSansPro.name
|
||||||
font.weight: Font.Light
|
font.weight: Font.Light
|
||||||
anchors {
|
anchors {
|
||||||
|
|
@ -691,17 +700,22 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
height: 55
|
height: 19
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
Text {
|
Text {
|
||||||
text: "ETHEREUM"
|
text: "ETHEREUM"
|
||||||
font.family: sourceSansPro.name
|
font.family: sourceSansPro.name
|
||||||
font.weight: Font.DemiBold
|
font.weight: Font.Regular
|
||||||
|
// anchors.top: 20
|
||||||
|
// anchors.left: 16
|
||||||
anchors {
|
anchors {
|
||||||
left: parent.left
|
leftMargin: 12
|
||||||
top: parent.verticalCenter
|
topMargin: 4
|
||||||
leftMargin: 16
|
fill: parent
|
||||||
}
|
}
|
||||||
|
// anchors.leftMargin: 16
|
||||||
|
// anchors.topMargin: 16
|
||||||
|
// anchors.verticalCenterOffset: 50
|
||||||
color: "#AAA0A0"
|
color: "#AAA0A0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -717,17 +731,16 @@ ApplicationWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
height: 55
|
height: 19
|
||||||
color: "transparent"
|
color: "#00ff00"
|
||||||
|
visible: (menuApps.children.length > 0)
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
text: "APPS"
|
text: "APPS"
|
||||||
font.family: sourceSansPro.name
|
font.family: sourceSansPro.name
|
||||||
font.weight: Font.DemiBold
|
font.weight: Font.Regular
|
||||||
anchors {
|
anchors.fill: parent
|
||||||
left: parent.left
|
anchors.leftMargin: 16
|
||||||
top: parent.verticalCenter
|
|
||||||
leftMargin: 16
|
|
||||||
}
|
|
||||||
color: "#AAA0A0"
|
color: "#AAA0A0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -735,6 +748,8 @@ ApplicationWindow {
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: menuApps
|
id: menuApps
|
||||||
spacing: 3
|
spacing: 3
|
||||||
|
|
||||||
|
|
||||||
anchors {
|
anchors {
|
||||||
left: parent.left
|
left: parent.left
|
||||||
right: parent.right
|
right: parent.right
|
||||||
|
|
@ -744,6 +759,7 @@ ApplicationWindow {
|
||||||
Rectangle {
|
Rectangle {
|
||||||
height: 55
|
height: 55
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
|
visible: true
|
||||||
Text {
|
Text {
|
||||||
text: "DEBUG"
|
text: "DEBUG"
|
||||||
font.family: sourceSansPro.name
|
font.family: sourceSansPro.name
|
||||||
|
|
@ -760,6 +776,7 @@ ApplicationWindow {
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
id: menuLegacy
|
id: menuLegacy
|
||||||
|
visible: true
|
||||||
spacing: 3
|
spacing: 3
|
||||||
anchors {
|
anchors {
|
||||||
left: parent.left
|
left: parent.left
|
||||||
|
|
@ -964,7 +981,7 @@ ApplicationWindow {
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.topMargin: 30
|
anchors.topMargin: 30
|
||||||
font.pointSize: 12
|
font.pointSize: 12
|
||||||
text: "<h2>Mist (0.8.5)</h2><br><h3>Development</h3>Jeffrey Wilcke<br>Viktor Trón<br>Felix Lange<br>Taylor Gerring<br>Daniel Nagy<br>Gustav Simonsson<br><h3>UX/UI</h3>Alex van de Sande<br>Fabian Vogelsteller"
|
text: "<h2>Mist (0.8.6)</h2><br><h3>Development</h3>Jeffrey Wilcke<br>Viktor Trón<br>Felix Lange<br>Taylor Gerring<br>Daniel Nagy<br>Gustav Simonsson<br><h3>UX/UI</h3>Alex van de Sande<br>Fabian Vogelsteller"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,17 +24,6 @@ Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Label {
|
|
||||||
objectName: "miningLabel"
|
|
||||||
visible: false
|
|
||||||
font.pixelSize: 10
|
|
||||||
anchors.right: lastBlockLabel.left
|
|
||||||
anchors.rightMargin: 5
|
|
||||||
onTextChanged: {
|
|
||||||
menuItem.secondaryTitle = text
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
spacing: 10
|
spacing: 10
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,43 @@
|
||||||
|
Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries.
|
||||||
|
|
||||||
|
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||||
|
This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||||
|
-----------------------------------------------------------
|
||||||
|
|
||||||
|
PREAMBLE
|
||||||
|
The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
|
||||||
|
|
||||||
|
The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
|
||||||
|
|
||||||
|
DEFINITIONS
|
||||||
|
"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
|
||||||
|
|
||||||
|
"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
|
||||||
|
|
||||||
|
"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
|
||||||
|
|
||||||
|
"Modified Version" refers to any derivative made by adding to, deleting, or substituting -- in part or in whole -- any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
|
||||||
|
|
||||||
|
"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
|
||||||
|
|
||||||
|
PERMISSION & CONDITIONS
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
|
||||||
|
|
||||||
|
1) Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
|
||||||
|
|
||||||
|
2) Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
|
||||||
|
|
||||||
|
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
|
||||||
|
|
||||||
|
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
|
||||||
|
|
||||||
|
5) The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
|
||||||
|
|
||||||
|
TERMINATION
|
||||||
|
This license becomes null and void if any of the above conditions are not met.
|
||||||
|
|
||||||
|
DISCLAIMER
|
||||||
|
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
30
cmd/mist/assets/qml/views/network-health/index.html
Executable file
30
cmd/mist/assets/qml/views/network-health/index.html
Executable file
|
|
@ -0,0 +1,30 @@
|
||||||
|
<html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Network</title>
|
||||||
|
|
||||||
|
<!-- <base href="/"> -->
|
||||||
|
|
||||||
|
<meta name="description" content="">
|
||||||
|
<meta name="keywords" content="dapp, ethereum">
|
||||||
|
|
||||||
|
<!-- <link rel="icon" href="/favicon.ico" type="image/x-icon"> -->
|
||||||
|
<!-- <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"> -->
|
||||||
|
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||||
|
|
||||||
|
<!-- <link rel="apple-touch-icon" href="/apple-touch-icon-precomposed.png"> -->
|
||||||
|
<!-- <link rel="apple-touch-startup-image" href="/startup.png"> -->
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" class="__meteor-css__" href="529f30ee0ee386c5143b4ccb62073179ca8253c3.css?meteor_css_resource=true">
|
||||||
|
<body>
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">__meteor_runtime_config__ = {"meteorRelease":"METEOR@1.0.3.1","ROOT_URL":"http://localhost:3000/","ROOT_URL_PATH_PREFIX":"","appId":"e350zy16p3kznipbx5o","autoupdateVersion":"df83a37bd2952ddbb9ba6c5f2a59e9caba02642b","autoupdateVersionRefreshable":"81118ed5fac9ef5f8d55835426179e1e058da42b","autoupdateVersionCordova":"none"};</script>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="205f39107b64acf34cb35d7edb57f47893187a12.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
92
cmd/mist/assets/qml/views/network-health/loading.css
Normal file
92
cmd/mist/assets/qml/views/network-health/loading.css
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
body {
|
||||||
|
background-color: #000;
|
||||||
|
font: 16px solid 'Helvetica Neue', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inject-loading-container {
|
||||||
|
position: relative;
|
||||||
|
padding-top: 20%;
|
||||||
|
/*left: 50%;*/
|
||||||
|
margin: 0 auto;
|
||||||
|
/*max-width: 600px;*/
|
||||||
|
/*margin-left: -300px;*/
|
||||||
|
text-align: center;
|
||||||
|
|
||||||
|
}
|
||||||
|
.inject-loading-container h1 {
|
||||||
|
text-align: center;
|
||||||
|
font-weight: 300;
|
||||||
|
font-size: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
img.loading-circle {
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
|
||||||
|
animation: rotate 1s linear infinite;
|
||||||
|
-moz-animation: rotate 1s linear infinite;
|
||||||
|
-webkit-animation: rotate 1s linear infinite;
|
||||||
|
-ms-animation: rotate 1s linear infinite;
|
||||||
|
|
||||||
|
transform-origin:50% 49.5%;
|
||||||
|
-ms-transform-origin:50% 49.5%; /* IE 9 */
|
||||||
|
-moz-transform-origin:50% 49.5%; /* Chrome, Safari, Opera */
|
||||||
|
-webkit-transform-origin:50% 49.5%; /* Chrome, Safari, Opera */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Keyframes */
|
||||||
|
@-webkit-keyframes rotate {
|
||||||
|
0% {
|
||||||
|
-webkit-transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 0.2;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
-webkit-transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@-moz-keyframes rotate {
|
||||||
|
0% {
|
||||||
|
-moz-transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 0.2;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
-moz-transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@-o-keyframes rotate {
|
||||||
|
0% {
|
||||||
|
-o-transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 0.2;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
-o-transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@-ms-keyframes rotate {
|
||||||
|
0% {
|
||||||
|
-ms-transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 0.2;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
-ms-transform-origin: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@keyframes rotate {
|
||||||
|
0% {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: 0.2;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
160
cmd/mist/assets/qml/views/network.qml
Normal file
160
cmd/mist/assets/qml/views/network.qml
Normal file
|
|
@ -0,0 +1,160 @@
|
||||||
|
import QtQuick 2.0
|
||||||
|
import QtQuick.Controls 1.0;
|
||||||
|
import QtQuick.Controls.Styles 1.0
|
||||||
|
import QtQuick.Layouts 1.0;
|
||||||
|
import QtWebEngine 1.0
|
||||||
|
import QtWebEngine.experimental 1.0
|
||||||
|
import QtQuick.Window 2.0;
|
||||||
|
import Ethereum 1.0
|
||||||
|
import Qt.WebSockets 1.0
|
||||||
|
//import "qwebchannel.js" as WebChannel
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: window
|
||||||
|
anchors.fill: parent
|
||||||
|
color: "#00000000"
|
||||||
|
|
||||||
|
property var title: "Network"
|
||||||
|
property var iconSource: "../mining-icon.png"
|
||||||
|
property var menuItem
|
||||||
|
property var hideUrl: true
|
||||||
|
|
||||||
|
property alias url: webview.url
|
||||||
|
property alias windowTitle: webview.title
|
||||||
|
property alias webView: webview
|
||||||
|
|
||||||
|
property var cleanPath: false
|
||||||
|
property var open: function(url) {
|
||||||
|
if(!window.cleanPath) {
|
||||||
|
var uri = url;
|
||||||
|
if(!/.*\:\/\/.*/.test(uri)) {
|
||||||
|
uri = "http://" + uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
var reg = /(^https?\:\/\/(?:www\.)?)([a-zA-Z0-9_\-]*\.eth)(.*)/
|
||||||
|
|
||||||
|
if(reg.test(uri)) {
|
||||||
|
uri.replace(reg, function(match, pre, domain, path) {
|
||||||
|
uri = pre;
|
||||||
|
|
||||||
|
var lookup = eth.lookupDomain(domain.substring(0, domain.length - 4));
|
||||||
|
var ip = [];
|
||||||
|
for(var i = 0, l = lookup.length; i < l; i++) {
|
||||||
|
ip.push(lookup.charCodeAt(i))
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ip.length != 0) {
|
||||||
|
uri += lookup;
|
||||||
|
} else {
|
||||||
|
uri += domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
uri += path;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
window.cleanPath = true;
|
||||||
|
|
||||||
|
webview.url = uri;
|
||||||
|
|
||||||
|
//uriNav.text = uri.text.replace(/(^https?\:\/\/(?:www\.)?)([a-zA-Z0-9_\-]*\.\w{2,3})(.*)/, "$1$2<span style='color:#CCC'>$3</span>");
|
||||||
|
uriNav.text = uri;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Prevent inf loop.
|
||||||
|
window.cleanPath = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
objectName: "miningLabel"
|
||||||
|
visible: false
|
||||||
|
font.pixelSize: 10
|
||||||
|
anchors.right: lastBlockLabel.left
|
||||||
|
anchors.rightMargin: 5
|
||||||
|
onTextChanged: {
|
||||||
|
menuItem.secondaryTitle = eth.miner().mining()? eth.miner().hashRate() + " Khash" : ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
objectName: "root"
|
||||||
|
id: root
|
||||||
|
anchors.fill: parent
|
||||||
|
state: "inspectorShown"
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
interval: 1000; running: true; repeat: true
|
||||||
|
onTriggered: {
|
||||||
|
webview.runJavaScript("Miner.mining", function(miningSliderValue) {
|
||||||
|
|
||||||
|
// Check if it's mining and set it accordingly
|
||||||
|
if (miningSliderValue > 0 && !eth.miner().mining()) {
|
||||||
|
// If the
|
||||||
|
eth.setGasPrice("10000000000000");
|
||||||
|
eth.miner().start();
|
||||||
|
} else if (miningSliderValue == 0 && eth.miner().mining()) {
|
||||||
|
eth.miner().stop();
|
||||||
|
} else if (eth.miner().mining()) {
|
||||||
|
|
||||||
|
webview.runJavaScript('var miningData = MiningData.findOne(); MiningData.update(miningData._id, {$inc: {totalTimeSpent: 1}}); Miner.hashrate = ' + eth.miner().hashRate() );
|
||||||
|
|
||||||
|
//var miningData = MiningData.findOne(); MiningData.update(miningData._id, {$inc: {totalTimeSpent: 1}});
|
||||||
|
|
||||||
|
} else if (miningSliderValue == "undefined") {
|
||||||
|
|
||||||
|
webview.runJavaScript('Miner.mining = 0' );
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WebEngineView {
|
||||||
|
objectName: "webView"
|
||||||
|
id: webview
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
url: "network-health/index.html"
|
||||||
|
//url: "http://localhost:3000/"
|
||||||
|
|
||||||
|
experimental.settings.javascriptCanAccessClipboard: true
|
||||||
|
|
||||||
|
|
||||||
|
onJavaScriptConsoleMessage: {
|
||||||
|
console.log(sourceID + ":" + lineNumber + ":" + JSON.stringify(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
onLoadingChanged: {
|
||||||
|
if (loadRequest.status == WebEngineView.LoadSucceededStatus) {
|
||||||
|
webview.runJavaScript(eth.readFile("mist.js"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WebEngineView {
|
||||||
|
id: inspector
|
||||||
|
visible: false
|
||||||
|
z:10
|
||||||
|
anchors {
|
||||||
|
left: root.left
|
||||||
|
right: root.right
|
||||||
|
top: root.top
|
||||||
|
bottom: root.bottom
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
states: [
|
||||||
|
State {
|
||||||
|
name: "inspectorShown"
|
||||||
|
PropertyChanges {
|
||||||
|
target: inspector
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -24,7 +24,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/ui/qt"
|
|
||||||
"github.com/ethereum/go-ethereum/xeth"
|
"github.com/ethereum/go-ethereum/xeth"
|
||||||
"github.com/obscuren/qml"
|
"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)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,8 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"bitbucket.org/kardianos/osext"
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
|
|
@ -43,9 +41,8 @@ var (
|
||||||
KeyRing string
|
KeyRing string
|
||||||
KeyStore string
|
KeyStore string
|
||||||
StartRpc bool
|
StartRpc bool
|
||||||
StartWebSockets bool
|
RpcListenAddress string
|
||||||
RpcPort int
|
RpcPort int
|
||||||
WsPort int
|
|
||||||
OutboundPort string
|
OutboundPort string
|
||||||
ShowGenesis bool
|
ShowGenesis bool
|
||||||
AddPeer string
|
AddPeer string
|
||||||
|
|
@ -68,33 +65,6 @@ var (
|
||||||
|
|
||||||
// flags specific to gui client
|
// flags specific to gui client
|
||||||
var AssetPath string
|
var AssetPath string
|
||||||
|
|
||||||
//TODO: If we re-use the one defined in cmd.go the binary osx image crashes. If somebody finds out why we can dry this up.
|
|
||||||
func defaultAssetPath() string {
|
|
||||||
var assetPath string
|
|
||||||
// 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") {
|
|
||||||
assetPath = path.Join(pwd, "assets")
|
|
||||||
} else {
|
|
||||||
switch runtime.GOOS {
|
|
||||||
case "darwin":
|
|
||||||
// Get Binary Directory
|
|
||||||
exedir, _ := osext.ExecutableFolder()
|
|
||||||
assetPath = filepath.Join(exedir, "../Resources")
|
|
||||||
case "linux":
|
|
||||||
assetPath = "/usr/share/mist"
|
|
||||||
case "windows":
|
|
||||||
assetPath = "./assets"
|
|
||||||
default:
|
|
||||||
assetPath = "."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return assetPath
|
|
||||||
}
|
|
||||||
|
|
||||||
var defaultConfigFile = path.Join(ethutil.DefaultDataDir(), "conf.ini")
|
var defaultConfigFile = path.Join(ethutil.DefaultDataDir(), "conf.ini")
|
||||||
|
|
||||||
func Init() {
|
func Init() {
|
||||||
|
|
@ -107,11 +77,10 @@ func Init() {
|
||||||
flag.IntVar(&VmType, "vm", 0, "Virtual Machine type: 0-1: standard, debug")
|
flag.IntVar(&VmType, "vm", 0, "Virtual Machine type: 0-1: standard, debug")
|
||||||
flag.StringVar(&Identifier, "id", "", "Custom client identifier")
|
flag.StringVar(&Identifier, "id", "", "Custom client identifier")
|
||||||
flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
|
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(&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(&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(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
|
||||||
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
||||||
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
|
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
|
||||||
|
|
@ -120,9 +89,9 @@ func Init() {
|
||||||
flag.StringVar(&Datadir, "datadir", ethutil.DefaultDataDir(), "specifies the datadir to use")
|
flag.StringVar(&Datadir, "datadir", ethutil.DefaultDataDir(), "specifies the datadir to use")
|
||||||
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file")
|
||||||
flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)")
|
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", defaultAssetPath(), "absolute path to GUI assets directory")
|
flag.StringVar(&AssetPath, "asset_path", ethutil.DefaultAssetPath(), "absolute path to GUI assets directory")
|
||||||
|
|
||||||
// Network stuff
|
// Network stuff
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
|
@ -388,7 +387,7 @@ func (gui *Gui) update() {
|
||||||
statsUpdateTicker := time.NewTicker(5 * time.Second)
|
statsUpdateTicker := time.NewTicker(5 * time.Second)
|
||||||
|
|
||||||
lastBlockLabel := gui.getObjectByName("lastBlockLabel")
|
lastBlockLabel := gui.getObjectByName("lastBlockLabel")
|
||||||
miningLabel := gui.getObjectByName("miningLabel")
|
//miningLabel := gui.getObjectByName("miningLabel")
|
||||||
|
|
||||||
events := gui.eth.EventMux().Subscribe(
|
events := gui.eth.EventMux().Subscribe(
|
||||||
core.ChainEvent{},
|
core.ChainEvent{},
|
||||||
|
|
@ -419,8 +418,7 @@ func (gui *Gui) update() {
|
||||||
case <-generalUpdateTicker.C:
|
case <-generalUpdateTicker.C:
|
||||||
statusText := "#" + gui.eth.ChainManager().CurrentBlock().Number().String()
|
statusText := "#" + gui.eth.ChainManager().CurrentBlock().Number().String()
|
||||||
lastBlockLabel.Set("text", statusText)
|
lastBlockLabel.Set("text", statusText)
|
||||||
miningLabel.Set("text", "Mining @ "+strconv.FormatInt(gui.uiLib.Miner().HashRate(), 10)+"/Khash")
|
//miningLabel.Set("text", strconv.FormatInt(gui.uiLib.Miner().HashRate(), 10))
|
||||||
|
|
||||||
case <-statsUpdateTicker.C:
|
case <-statsUpdateTicker.C:
|
||||||
gui.setStatsPane()
|
gui.setStatsPane()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ClientIdentifier = "Mist"
|
ClientIdentifier = "Mist"
|
||||||
Version = "0.8.5"
|
Version = "0.8.6"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ethereum *eth.Ethereum
|
var ethereum *eth.Ethereum
|
||||||
|
|
@ -73,11 +73,7 @@ func run() error {
|
||||||
utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
|
utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
|
||||||
|
|
||||||
if StartRpc {
|
if StartRpc {
|
||||||
utils.StartRpc(ethereum, RpcPort)
|
utils.StartRpc(ethereum, RpcListenAddress, RpcPort)
|
||||||
}
|
|
||||||
|
|
||||||
if StartWebSockets {
|
|
||||||
utils.StartWebSockets(ethereum, WsPort)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gui := NewWindow(ethereum, config, KeyRing, LogLevel)
|
gui := NewWindow(ethereum, config, KeyRing, LogLevel)
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
|
||||||
|
|
||||||
"bitbucket.org/kardianos/osext"
|
|
||||||
"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/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
|
|
@ -39,7 +35,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/miner"
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
rpchttp "github.com/ethereum/go-ethereum/rpc/http"
|
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/state"
|
||||||
"github.com/ethereum/go-ethereum/xeth"
|
"github.com/ethereum/go-ethereum/xeth"
|
||||||
)
|
)
|
||||||
|
|
@ -133,31 +128,6 @@ func StartEthereum(ethereum *eth.Ethereum, Peers string, Pull string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func DefaultAssetPath() string {
|
|
||||||
var assetPath string
|
|
||||||
// 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") {
|
|
||||||
assetPath = path.Join(pwd, "assets")
|
|
||||||
} else {
|
|
||||||
switch runtime.GOOS {
|
|
||||||
case "darwin":
|
|
||||||
// Get Binary Directory
|
|
||||||
exedir, _ := osext.ExecutableFolder()
|
|
||||||
assetPath = filepath.Join(exedir, "../Resources")
|
|
||||||
case "linux":
|
|
||||||
assetPath = "/usr/share/mist"
|
|
||||||
case "windows":
|
|
||||||
assetPath = "./assets"
|
|
||||||
default:
|
|
||||||
assetPath = "."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return assetPath
|
|
||||||
}
|
|
||||||
|
|
||||||
func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, SecretFile string, ExportDir string, NonInteractive bool) {
|
func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, SecretFile string, ExportDir string, NonInteractive bool) {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -190,9 +160,9 @@ func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, Secre
|
||||||
clilogger.Infof("Main address %x\n", keyManager.Address())
|
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
|
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 {
|
if err != nil {
|
||||||
clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
|
clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -200,18 +170,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
|
var gminer *miner.Miner
|
||||||
|
|
||||||
func GetMiner() *miner.Miner {
|
func GetMiner() *miner.Miner {
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,6 @@ func NewBlockProcessor(db ethutil.Database, txpool *TxPool, chainManager *ChainM
|
||||||
sm := &BlockProcessor{
|
sm := &BlockProcessor{
|
||||||
db: db,
|
db: db,
|
||||||
mem: make(map[string]*big.Int),
|
mem: make(map[string]*big.Int),
|
||||||
//Pow: ðash.Ethash{},
|
|
||||||
Pow: ezp.New(),
|
Pow: ezp.New(),
|
||||||
bc: chainManager,
|
bc: chainManager,
|
||||||
eventMux: eventMux,
|
eventMux: eventMux,
|
||||||
|
|
@ -62,7 +61,7 @@ func NewBlockProcessor(db ethutil.Database, txpool *TxPool, chainManager *ChainM
|
||||||
|
|
||||||
func (sm *BlockProcessor) TransitionState(statedb *state.StateDB, parent, block *types.Block, transientProcess bool) (receipts types.Receipts, err error) {
|
func (sm *BlockProcessor) TransitionState(statedb *state.StateDB, parent, block *types.Block, transientProcess bool) (receipts types.Receipts, err error) {
|
||||||
coinbase := statedb.GetOrNewStateObject(block.Header().Coinbase)
|
coinbase := statedb.GetOrNewStateObject(block.Header().Coinbase)
|
||||||
coinbase.SetGasPool(CalcGasLimit(parent, block))
|
coinbase.SetGasPool(block.Header().GasLimit)
|
||||||
|
|
||||||
// Process the transactions on to parent state
|
// Process the transactions on to parent state
|
||||||
receipts, _, _, _, err = sm.ApplyTransactions(coinbase, statedb, block, block.Transactions(), transientProcess)
|
receipts, _, _, _, err = sm.ApplyTransactions(coinbase, statedb, block, block.Transactions(), transientProcess)
|
||||||
|
|
@ -100,7 +99,8 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, stated
|
||||||
// Notify all subscribers
|
// Notify all subscribers
|
||||||
if !transientProcess {
|
if !transientProcess {
|
||||||
go self.eventMux.Post(TxPostEvent{tx})
|
go self.eventMux.Post(TxPostEvent{tx})
|
||||||
go self.eventMux.Post(statedb.Logs())
|
logs := statedb.Logs()
|
||||||
|
go self.eventMux.Post(logs)
|
||||||
}
|
}
|
||||||
|
|
||||||
return receipt, txGas, err
|
return receipt, txGas, err
|
||||||
|
|
@ -247,6 +247,11 @@ func (sm *BlockProcessor) ValidateBlock(block, parent *types.Block) error {
|
||||||
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Header().Difficulty, expd)
|
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Header().Difficulty, expd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expl := CalcGasLimit(parent, block)
|
||||||
|
if expl.Cmp(block.Header().GasLimit) != 0 {
|
||||||
|
return fmt.Errorf("GasLimit check failed for block %v, %v", block.Header().GasLimit, expl)
|
||||||
|
}
|
||||||
|
|
||||||
if block.Time() < parent.Time() {
|
if block.Time() < parent.Time() {
|
||||||
return ValidationError("Block timestamp not after prev block (%v - %v)", block.Header().Time, parent.Header().Time)
|
return ValidationError("Block timestamp not after prev block (%v - %v)", block.Header().Time, parent.Header().Time)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var chainlogger = logger.NewLogger("CHAIN")
|
var chainlogger = logger.NewLogger("CHAIN")
|
||||||
|
var jsonlogger = logger.NewJsonLogger()
|
||||||
|
|
||||||
type ChainEvent struct {
|
type ChainEvent struct {
|
||||||
Block *types.Block
|
Block *types.Block
|
||||||
|
|
@ -122,7 +123,7 @@ func (self *ChainManager) Status() (td *big.Int, currentBlock []byte, genesisBlo
|
||||||
self.mu.RLock()
|
self.mu.RLock()
|
||||||
defer self.mu.RUnlock()
|
defer self.mu.RUnlock()
|
||||||
|
|
||||||
return self.td, self.currentBlock.Hash(), self.Genesis().Hash()
|
return self.td, self.currentBlock.Hash(), self.genesisBlock.Hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ChainManager) SetProcessor(proc types.BlockProcessor) {
|
func (self *ChainManager) SetProcessor(proc types.BlockProcessor) {
|
||||||
|
|
@ -395,11 +396,11 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
||||||
|
|
||||||
var canonical, split bool
|
var canonical, split bool
|
||||||
self.mu.Lock()
|
self.mu.Lock()
|
||||||
|
cblock := self.currentBlock
|
||||||
{
|
{
|
||||||
// Write block to database. Eventually we'll have to improve on this and throw away blocks that are
|
// Write block to database. Eventually we'll have to improve on this and throw away blocks that are
|
||||||
// not in the canonical chain.
|
// not in the canonical chain.
|
||||||
self.write(block)
|
self.write(block)
|
||||||
cblock := self.currentBlock
|
|
||||||
// Compare the TD of the last known block in the canonical chain to make sure it's greater.
|
// Compare the TD of the last known block in the canonical chain to make sure it's greater.
|
||||||
// At this point it's possible that a different chain (fork) becomes the new canonical chain.
|
// At this point it's possible that a different chain (fork) becomes the new canonical chain.
|
||||||
if td.Cmp(self.td) > 0 {
|
if td.Cmp(self.td) > 0 {
|
||||||
|
|
@ -417,6 +418,12 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
||||||
self.mu.Unlock()
|
self.mu.Unlock()
|
||||||
|
|
||||||
if canonical {
|
if canonical {
|
||||||
|
jsonlogger.LogJson(&logger.EthChainNewHead{
|
||||||
|
BlockHash: ethutil.Bytes2Hex(block.Hash()),
|
||||||
|
BlockNumber: block.Number(),
|
||||||
|
ChainHeadHash: ethutil.Bytes2Hex(cblock.Hash()),
|
||||||
|
BlockPrevHash: ethutil.Bytes2Hex(block.ParentHash()),
|
||||||
|
})
|
||||||
self.setTransState(state.New(block.Root(), self.db))
|
self.setTransState(state.New(block.Root(), self.db))
|
||||||
self.eventMux.Post(ChainEvent{block, td})
|
self.eventMux.Post(ChainEvent{block, td})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ type FilterOptions struct {
|
||||||
Latest int64
|
Latest int64
|
||||||
|
|
||||||
Address [][]byte
|
Address [][]byte
|
||||||
Topics [][]byte
|
Topics [][][]byte
|
||||||
|
|
||||||
Skip int
|
Skip int
|
||||||
Max int
|
Max int
|
||||||
|
|
@ -31,7 +31,7 @@ type Filter struct {
|
||||||
skip int
|
skip int
|
||||||
address [][]byte
|
address [][]byte
|
||||||
max int
|
max int
|
||||||
topics [][]byte
|
topics [][][]byte
|
||||||
|
|
||||||
BlockCallback func(*types.Block)
|
BlockCallback func(*types.Block)
|
||||||
PendingCallback func(*types.Block)
|
PendingCallback func(*types.Block)
|
||||||
|
|
@ -44,6 +44,8 @@ func NewFilter(eth Backend) *Filter {
|
||||||
return &Filter{eth: eth}
|
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) {
|
func (self *Filter) SetOptions(options FilterOptions) {
|
||||||
self.earliest = options.Earliest
|
self.earliest = options.Earliest
|
||||||
self.latest = options.Latest
|
self.latest = options.Latest
|
||||||
|
|
@ -69,7 +71,7 @@ func (self *Filter) SetAddress(addr [][]byte) {
|
||||||
self.address = addr
|
self.address = addr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Filter) SetTopics(topics [][]byte) {
|
func (self *Filter) SetTopics(topics [][][]byte) {
|
||||||
self.topics = topics
|
self.topics = topics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,12 +151,20 @@ Logs:
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
max := int(math.Min(float64(len(self.topics)), float64(len(log.Topics()))))
|
logTopics := make([][]byte, len(self.topics))
|
||||||
for i := 0; i < max; i++ {
|
copy(logTopics, log.Topics())
|
||||||
if !bytes.Equal(log.Topics()[i], self.topics[i]) {
|
|
||||||
|
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
|
continue Logs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = append(ret, log)
|
ret = append(ret, log)
|
||||||
}
|
}
|
||||||
|
|
@ -177,8 +187,15 @@ func (self *Filter) bloomFilter(block *types.Block) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, topic := range self.topics {
|
for _, sub := range self.topics {
|
||||||
if !types.BloomLookup(block.Bloom(), topic) {
|
var included bool
|
||||||
|
for _, topic := range sub {
|
||||||
|
if types.BloomLookup(block.Bloom(), topic) {
|
||||||
|
included = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !included {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,6 @@ func GenesisBlock(db ethutil.Database) *types.Block {
|
||||||
statedb.Sync()
|
statedb.Sync()
|
||||||
genesis.Header().Root = statedb.Root()
|
genesis.Header().Root = statedb.Root()
|
||||||
|
|
||||||
fmt.Printf("+++ genesis +++\nRoot: %x\nHash: %x\n", genesis.Header().Root, genesis.Hash())
|
|
||||||
|
|
||||||
return genesis
|
return genesis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ func (self *StateTransition) BuyGas() error {
|
||||||
|
|
||||||
self.AddGas(self.msg.Gas())
|
self.AddGas(self.msg.Gas())
|
||||||
self.initialGas.Set(self.msg.Gas())
|
self.initialGas.Set(self.msg.Gas())
|
||||||
sender.SubAmount(MessageGasValue(self.msg))
|
sender.SubBalance(MessageGasValue(self.msg))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -251,7 +251,7 @@ func (self *StateTransition) RefundGas() {
|
||||||
coinbase, sender := self.Coinbase(), self.From()
|
coinbase, sender := self.Coinbase(), self.From()
|
||||||
// Return remaining gas
|
// Return remaining gas
|
||||||
remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice())
|
remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice())
|
||||||
sender.AddAmount(remaining)
|
sender.AddBalance(remaining)
|
||||||
|
|
||||||
uhalf := new(big.Int).Div(self.GasUsed(), ethutil.Big2)
|
uhalf := new(big.Int).Div(self.GasUsed(), ethutil.Big2)
|
||||||
for addr, ref := range self.state.Refunds() {
|
for addr, ref := range self.state.Refunds() {
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,16 @@ package eth
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/bzz"
|
|
||||||
"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/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"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/miner"
|
||||||
"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"
|
||||||
|
|
@ -26,8 +23,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logger = ethlogger.NewLogger("SERV")
|
ethlogger = logger.NewLogger("SERV")
|
||||||
jsonlogger = ethlogger.NewJsonLogger()
|
jsonlogger = logger.NewJsonLogger()
|
||||||
|
|
||||||
defaultBootNodes = []*discover.Node{
|
defaultBootNodes = []*discover.Node{
|
||||||
// ETH/DEV cmd/bootnode
|
// ETH/DEV cmd/bootnode
|
||||||
|
|
@ -77,7 +74,7 @@ func (cfg *Config) parseBootNodes() []*discover.Node {
|
||||||
}
|
}
|
||||||
n, err := discover.ParseNode(url)
|
n, err := discover.ParseNode(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Bootstrap URL %s: %v\n", url, err)
|
ethlogger.Errorf("Bootstrap URL %s: %v\n", url, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ns = append(ns, n)
|
ns = append(ns, n)
|
||||||
|
|
@ -101,7 +98,7 @@ func (cfg *Config) nodeKey() (*ecdsa.PrivateKey, error) {
|
||||||
return nil, fmt.Errorf("could not generate server key: %v", err)
|
return nil, fmt.Errorf("could not generate server key: %v", err)
|
||||||
}
|
}
|
||||||
if err := ioutil.WriteFile(keyfile, crypto.FromECDSA(key), 0600); err != nil {
|
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
|
return key, nil
|
||||||
}
|
}
|
||||||
|
|
@ -130,19 +127,17 @@ type Ethereum struct {
|
||||||
miner *miner.Miner
|
miner *miner.Miner
|
||||||
|
|
||||||
RpcServer rpc.RpcServer
|
RpcServer rpc.RpcServer
|
||||||
WsServer rpc.RpcServer
|
|
||||||
keyManager *crypto.KeyManager
|
keyManager *crypto.KeyManager
|
||||||
dpa *bzz.DPA
|
|
||||||
|
|
||||||
logger ethlogger.LogSystem
|
logger logger.LogSystem
|
||||||
|
|
||||||
Mining bool
|
Mining bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(config *Config) (*Ethereum, error) {
|
func New(config *Config) (*Ethereum, error) {
|
||||||
// Boostrap database
|
// 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(config.DataDir + "/blockchain")
|
db, err := ethdb.NewLDBDatabase("blockchain")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -151,7 +146,8 @@ func New(config *Config) (*Ethereum, error) {
|
||||||
d, _ := db.Get([]byte("ProtocolVersion"))
|
d, _ := db.Get([]byte("ProtocolVersion"))
|
||||||
protov := ethutil.NewValue(d).Uint()
|
protov := ethutil.NewValue(d).Uint()
|
||||||
if protov != ProtocolVersion && protov != 0 {
|
if protov != ProtocolVersion && protov != 0 {
|
||||||
return nil, fmt.Errorf("Database version mismatch. Protocol(%d / %d). `rm -rf %s`", protov, ProtocolVersion, 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new keymanager
|
// Create new keymanager
|
||||||
|
|
@ -177,7 +173,7 @@ func New(config *Config) (*Ethereum, error) {
|
||||||
keyManager: keyManager,
|
keyManager: keyManager,
|
||||||
blacklist: p2p.NewBlacklist(),
|
blacklist: p2p.NewBlacklist(),
|
||||||
eventMux: &event.TypeMux{},
|
eventMux: &event.TypeMux{},
|
||||||
logger: logger,
|
logger: ethlogger,
|
||||||
}
|
}
|
||||||
|
|
||||||
eth.chainManager = core.NewChainManager(db, eth.EventMux())
|
eth.chainManager = core.NewChainManager(db, eth.EventMux())
|
||||||
|
|
@ -196,27 +192,10 @@ func New(config *Config) (*Ethereum, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ethProto := EthProtocol(eth.txPool, eth.chainManager, eth.blockPool)
|
ethProto := EthProtocol(eth.txPool, eth.chainManager, eth.blockPool)
|
||||||
netStore := bzz.NewNetStore(config.DataDir + "/bzz")
|
protocols := []p2p.Protocol{ethProto}
|
||||||
protocols := []p2p.Protocol{
|
|
||||||
ethProto,
|
|
||||||
bzz.BzzProtocol(netStore),
|
|
||||||
}
|
|
||||||
if config.Shh {
|
if config.Shh {
|
||||||
protocols = append(protocols, eth.whisper.Protocol())
|
protocols = append(protocols, eth.whisper.Protocol())
|
||||||
}
|
}
|
||||||
// TODO: if config.Bzz ...
|
|
||||||
chunker := &bzz.TreeChunker{}
|
|
||||||
chunker.Init()
|
|
||||||
eth.dpa = &bzz.DPA{
|
|
||||||
Chunker: chunker,
|
|
||||||
ChunkStore: netStore,
|
|
||||||
}
|
|
||||||
|
|
||||||
if netprv == nil {
|
|
||||||
if netprv, err = crypto.GenerateKey(); err != nil {
|
|
||||||
return nil, fmt.Errorf("could not generate server key: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
eth.net = &p2p.Server{
|
eth.net = &p2p.Server{
|
||||||
PrivateKey: netprv,
|
PrivateKey: netprv,
|
||||||
|
|
@ -236,7 +215,7 @@ func New(config *Config) (*Ethereum, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Ethereum) KeyManager() *crypto.KeyManager { return s.keyManager }
|
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) Name() string { return s.net.Name }
|
||||||
func (s *Ethereum) ChainManager() *core.ChainManager { return s.chainManager }
|
func (s *Ethereum) ChainManager() *core.ChainManager { return s.chainManager }
|
||||||
func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcessor }
|
func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcessor }
|
||||||
|
|
@ -253,8 +232,8 @@ func (s *Ethereum) MaxPeers() int { return s.net.MaxPeers
|
||||||
func (s *Ethereum) Coinbase() []byte { return nil } // TODO
|
func (s *Ethereum) Coinbase() []byte { return nil } // TODO
|
||||||
|
|
||||||
// Start the ethereum
|
// Start the ethereum
|
||||||
func (s *Ethereum) Start(p string, pull string) error {
|
func (s *Ethereum) Start() error {
|
||||||
jsonlogger.LogJson(ðlogger.LogStarting{
|
jsonlogger.LogJson(&logger.LogStarting{
|
||||||
ClientString: s.net.Name,
|
ClientString: s.net.Name,
|
||||||
ProtocolVersion: ProtocolVersion,
|
ProtocolVersion: ProtocolVersion,
|
||||||
})
|
})
|
||||||
|
|
@ -272,9 +251,6 @@ func (s *Ethereum) Start(p string, pull string) error {
|
||||||
s.whisper.Start()
|
s.whisper.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
s.dpa.Start()
|
|
||||||
bzz.StartHttpServer(s.dpa)
|
|
||||||
|
|
||||||
// broadcast transactions
|
// broadcast transactions
|
||||||
s.txSub = s.eventMux.Subscribe(core.TxPreEvent{})
|
s.txSub = s.eventMux.Subscribe(core.TxPreEvent{})
|
||||||
go s.txBroadcastLoop()
|
go s.txBroadcastLoop()
|
||||||
|
|
@ -283,37 +259,7 @@ func (s *Ethereum) Start(p string, pull string) error {
|
||||||
s.blockSub = s.eventMux.Subscribe(core.NewMinedBlockEvent{})
|
s.blockSub = s.eventMux.Subscribe(core.NewMinedBlockEvent{})
|
||||||
go s.blockBroadcastLoop()
|
go s.blockBroadcastLoop()
|
||||||
|
|
||||||
if len(p) > 0 {
|
ethlogger.Infoln("Server started")
|
||||||
for _, peer := range strings.Split(p, ",") {
|
|
||||||
if err := s.SuggestPeer(peer); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(pull) > 0 {
|
|
||||||
go func() {
|
|
||||||
time.Sleep(30 * time.Second)
|
|
||||||
key := ethutil.Hex2Bytes(pull)
|
|
||||||
reader := s.dpa.Retrieve(key)
|
|
||||||
logger.Debugf("retrieved reader for %064x", key)
|
|
||||||
b := make([]byte, 0x1000)
|
|
||||||
var length int64
|
|
||||||
for {
|
|
||||||
n, err := reader.Read(b)
|
|
||||||
if err != nil {
|
|
||||||
if err != io.EOF {
|
|
||||||
logger.Debugf("read %v bytes. read error for %064x: %v", n, key, err)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
length += int64(n)
|
|
||||||
}
|
|
||||||
logger.Debugf("read %v bytes from %064x: %v", length, key)
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.Infoln("Server started")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -338,9 +284,7 @@ func (s *Ethereum) Stop() {
|
||||||
if s.RpcServer != nil {
|
if s.RpcServer != nil {
|
||||||
s.RpcServer.Stop()
|
s.RpcServer.Stop()
|
||||||
}
|
}
|
||||||
if s.WsServer != nil {
|
|
||||||
s.WsServer.Stop()
|
|
||||||
}
|
|
||||||
s.txPool.Stop()
|
s.txPool.Stop()
|
||||||
s.eventMux.Stop()
|
s.eventMux.Stop()
|
||||||
s.blockPool.Stop()
|
s.blockPool.Stop()
|
||||||
|
|
@ -348,7 +292,7 @@ func (s *Ethereum) Stop() {
|
||||||
s.whisper.Stop()
|
s.whisper.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Infoln("Server stopped")
|
ethlogger.Infoln("Server stopped")
|
||||||
close(s.shutdownChan)
|
close(s.shutdownChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"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"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
)
|
)
|
||||||
|
|
||||||
var poolLogger = ethlogger.NewLogger("Blockpool")
|
var poolLogger = logger.NewLogger("Blockpool")
|
||||||
|
|
||||||
const (
|
const (
|
||||||
blockHashesBatchSize = 256
|
blockHashesBatchSize = 256
|
||||||
|
|
|
||||||
|
|
@ -12,19 +12,19 @@ import (
|
||||||
"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/ethutil"
|
"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"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
)
|
)
|
||||||
|
|
||||||
const waitTimeout = 60 // seconds
|
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
|
var ini = false
|
||||||
|
|
||||||
func logInit() {
|
func logInit() {
|
||||||
if !ini {
|
if !ini {
|
||||||
ethlogger.AddLogSystem(logsys)
|
logger.AddLogSystem(logsys)
|
||||||
ini = true
|
ini = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
@ -137,6 +138,12 @@ func (self *ethProtocol) handle() error {
|
||||||
if err := msg.Decode(&txs); err != nil {
|
if err := msg.Decode(&txs); err != nil {
|
||||||
return self.protoError(ErrDecode, "msg %v: %v", msg, err)
|
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)
|
self.txPool.AddTransactions(txs)
|
||||||
|
|
||||||
case GetBlockHashesMsg:
|
case GetBlockHashesMsg:
|
||||||
|
|
@ -217,6 +224,14 @@ func (self *ethProtocol) handle() error {
|
||||||
return self.protoError(ErrDecode, "msg %v: %v", msg, err)
|
return self.protoError(ErrDecode, "msg %v: %v", msg, err)
|
||||||
}
|
}
|
||||||
hash := request.Block.Hash()
|
hash := request.Block.Hash()
|
||||||
|
_, chainHead, _ := self.chainManager.Status()
|
||||||
|
jsonlogger.LogJson(&logger.EthChainReceivedNewBlock{
|
||||||
|
BlockHash: ethutil.Bytes2Hex(hash),
|
||||||
|
BlockNumber: request.Block.Number(), // this surely must be zero
|
||||||
|
ChainHeadHash: ethutil.Bytes2Hex(chainHead),
|
||||||
|
BlockPrevHash: ethutil.Bytes2Hex(request.Block.ParentHash()),
|
||||||
|
RemoteId: self.peer.ID().String(),
|
||||||
|
})
|
||||||
// to simplify backend interface adding a new block
|
// to simplify backend interface adding a new block
|
||||||
// uses AddPeer followed by AddHashes, AddBlock only if peer is the best peer
|
// uses AddPeer followed by AddHashes, AddBlock only if peer is the best peer
|
||||||
// (or selected as new best peer)
|
// (or selected as new best peer)
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,12 @@ import (
|
||||||
"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/ethutil"
|
"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"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"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 {
|
type testMsgReadWriter struct {
|
||||||
in chan p2p.Msg
|
in chan p2p.Msg
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,50 @@ package ethutil
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/kardianos/osext"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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.
|
||||||
|
if pwd == srcdir {
|
||||||
|
assetPath = path.Join(pwd, "assets")
|
||||||
|
} else {
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "darwin":
|
||||||
|
// Get Binary Directory
|
||||||
|
exedir, _ := osext.ExecutableFolder()
|
||||||
|
assetPath = filepath.Join(exedir, "../Resources")
|
||||||
|
case "linux":
|
||||||
|
assetPath = "/usr/share/mist"
|
||||||
|
case "windows":
|
||||||
|
assetPath = "./assets"
|
||||||
|
default:
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
func DefaultDataDir() string {
|
func DefaultDataDir() string {
|
||||||
usr, _ := user.Current()
|
usr, _ := user.Current()
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
|
|
|
||||||
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 {
|
type JSRE struct {
|
||||||
ethereum *eth.Ethereum
|
ethereum *eth.Ethereum
|
||||||
Vm *otto.Otto
|
Vm *otto.Otto
|
||||||
pipe *xeth.XEth
|
xeth *xeth.XEth
|
||||||
|
|
||||||
events event.Subscription
|
events event.Subscription
|
||||||
|
|
||||||
|
|
@ -67,7 +67,7 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
|
||||||
// We have to make sure that, whoever calls this, calls "Stop"
|
// We have to make sure that, whoever calls this, calls "Stop"
|
||||||
go re.mainLoop()
|
go re.mainLoop()
|
||||||
|
|
||||||
re.Bind("eth", &JSEthereum{re.pipe, re.Vm, ethereum})
|
re.Bind("eth", &JSEthereum{re.xeth, re.Vm, ethereum})
|
||||||
|
|
||||||
re.initStdFuncs()
|
re.initStdFuncs()
|
||||||
|
|
||||||
|
|
@ -113,12 +113,10 @@ func (self *JSRE) mainLoop() {
|
||||||
func (self *JSRE) initStdFuncs() {
|
func (self *JSRE) initStdFuncs() {
|
||||||
t, _ := self.Vm.Get("eth")
|
t, _ := self.Vm.Get("eth")
|
||||||
eth := t.Object()
|
eth := t.Object()
|
||||||
eth.Set("watch", self.watch)
|
eth.Set("connect", self.connect)
|
||||||
eth.Set("addPeer", self.addPeer)
|
|
||||||
eth.Set("require", self.require)
|
eth.Set("require", self.require)
|
||||||
eth.Set("stopMining", self.stopMining)
|
eth.Set("stopMining", self.stopMining)
|
||||||
eth.Set("startMining", self.startMining)
|
eth.Set("startMining", self.startMining)
|
||||||
eth.Set("execBlock", self.execBlock)
|
|
||||||
eth.Set("dump", self.dump)
|
eth.Set("dump", self.dump)
|
||||||
eth.Set("export", self.export)
|
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())
|
statedb := state.New(block.Root(), self.ethereum.Db())
|
||||||
v, _ := self.Vm.ToValue(statedb.Dump())
|
|
||||||
|
v, _ := self.Vm.ToValue(statedb.RawDump())
|
||||||
|
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
@ -167,36 +166,7 @@ func (self *JSRE) startMining(call otto.FunctionCall) otto.Value {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
// eth.watch
|
func (self *JSRE) connect(call otto.FunctionCall) otto.Value {
|
||||||
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 {
|
|
||||||
nodeURL, err := call.Argument(0).ToString()
|
nodeURL, err := call.Argument(0).ToString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return otto.FalseValue()
|
return otto.FalseValue()
|
||||||
|
|
@ -222,22 +192,12 @@ func (self *JSRE) require(call otto.FunctionCall) otto.Value {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *JSRE) execBlock(call otto.FunctionCall) otto.Value {
|
func (self *JSRE) export(call otto.FunctionCall) otto.Value {
|
||||||
hash, err := call.Argument(0).ToString()
|
if len(call.ArgumentList) == 0 {
|
||||||
if err != nil {
|
fmt.Println("err: require file name")
|
||||||
return otto.UndefinedValue()
|
|
||||||
}
|
|
||||||
|
|
||||||
err = utils.BlockDo(self.ethereum, ethutil.Hex2Bytes(hash))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
return otto.FalseValue()
|
return otto.FalseValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
return otto.TrueValue()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *JSRE) export(call otto.FunctionCall) otto.Value {
|
|
||||||
fn, err := call.Argument(0).ToString()
|
fn, err := call.Argument(0).ToString()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ function pp(object) {
|
||||||
str += " ]";
|
str += " ]";
|
||||||
} else if(typeof(object) === "object") {
|
} else if(typeof(object) === "object") {
|
||||||
str += "{ ";
|
str += "{ ";
|
||||||
var last = Object.keys(object).sort().pop()
|
var last = Object.keys(object).pop()
|
||||||
for(var k in object) {
|
for(var k in object) {
|
||||||
str += k + ": " + pp(object[k]);
|
str += k + ": " + pp(object[k]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
"github.com/ethereum/go-ethereum/ui"
|
|
||||||
"github.com/ethereum/go-ethereum/xeth"
|
"github.com/ethereum/go-ethereum/xeth"
|
||||||
"github.com/obscuren/otto"
|
"github.com/obscuren/otto"
|
||||||
)
|
)
|
||||||
|
|
@ -96,17 +95,3 @@ func (self *JSEthereum) toVal(v interface{}) otto.Value {
|
||||||
|
|
||||||
return result
|
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
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -54,7 +55,7 @@ func (l *P2PDisconnected) EventName() string {
|
||||||
|
|
||||||
type EthMinerNewBlock struct {
|
type EthMinerNewBlock struct {
|
||||||
BlockHash string `json:"block_hash"`
|
BlockHash string `json:"block_hash"`
|
||||||
BlockNumber int `json:"block_number"`
|
BlockNumber *big.Int `json:"block_number"`
|
||||||
ChainHeadHash string `json:"chain_head_hash"`
|
ChainHeadHash string `json:"chain_head_hash"`
|
||||||
BlockPrevHash string `json:"block_prev_hash"`
|
BlockPrevHash string `json:"block_prev_hash"`
|
||||||
LogEvent
|
LogEvent
|
||||||
|
|
@ -66,10 +67,10 @@ func (l *EthMinerNewBlock) EventName() string {
|
||||||
|
|
||||||
type EthChainReceivedNewBlock struct {
|
type EthChainReceivedNewBlock struct {
|
||||||
BlockHash string `json:"block_hash"`
|
BlockHash string `json:"block_hash"`
|
||||||
BlockNumber int `json:"block_number"`
|
BlockNumber *big.Int `json:"block_number"`
|
||||||
ChainHeadHash string `json:"chain_head_hash"`
|
ChainHeadHash string `json:"chain_head_hash"`
|
||||||
BlockPrevHash string `json:"block_prev_hash"`
|
BlockPrevHash string `json:"block_prev_hash"`
|
||||||
RemoteId int `json:"remote_id"`
|
RemoteId string `json:"remote_id"`
|
||||||
LogEvent
|
LogEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,7 +80,7 @@ func (l *EthChainReceivedNewBlock) EventName() string {
|
||||||
|
|
||||||
type EthChainNewHead struct {
|
type EthChainNewHead struct {
|
||||||
BlockHash string `json:"block_hash"`
|
BlockHash string `json:"block_hash"`
|
||||||
BlockNumber int `json:"block_number"`
|
BlockNumber *big.Int `json:"block_number"`
|
||||||
ChainHeadHash string `json:"chain_head_hash"`
|
ChainHeadHash string `json:"chain_head_hash"`
|
||||||
BlockPrevHash string `json:"block_prev_hash"`
|
BlockPrevHash string `json:"block_prev_hash"`
|
||||||
LogEvent
|
LogEvent
|
||||||
|
|
|
||||||
|
|
@ -52,10 +52,5 @@ func (self *Miner) Stop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Miner) HashRate() int64 {
|
func (self *Miner) HashRate() int64 {
|
||||||
var tot int64
|
return self.worker.HashRate()
|
||||||
for _, agent := range self.worker.agents {
|
|
||||||
tot += agent.Pow().GetHashrate()
|
|
||||||
}
|
|
||||||
|
|
||||||
return tot
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,20 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/pow"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
"gopkg.in/fatih/set.v0"
|
"gopkg.in/fatih/set.v0"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var jsonlogger = logger.NewJsonLogger()
|
||||||
|
|
||||||
type environment struct {
|
type environment struct {
|
||||||
totalUsedGas *big.Int
|
totalUsedGas *big.Int
|
||||||
state *state.StateDB
|
state *state.StateDB
|
||||||
|
|
@ -111,6 +115,8 @@ func (self *worker) register(agent Agent) {
|
||||||
func (self *worker) update() {
|
func (self *worker) update() {
|
||||||
events := self.mux.Subscribe(core.ChainEvent{}, core.NewMinedBlockEvent{})
|
events := self.mux.Subscribe(core.ChainEvent{}, core.NewMinedBlockEvent{})
|
||||||
|
|
||||||
|
timer := time.NewTicker(2 * time.Second)
|
||||||
|
|
||||||
out:
|
out:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
@ -129,6 +135,8 @@ out:
|
||||||
agent.Stop()
|
agent.Stop()
|
||||||
}
|
}
|
||||||
break out
|
break out
|
||||||
|
case <-timer.C:
|
||||||
|
minerlogger.Debugln("Hash rate:", self.HashRate(), "Khash")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,7 +149,12 @@ func (self *worker) wait() {
|
||||||
block := self.current.block
|
block := self.current.block
|
||||||
if block.Number().Uint64() == work.Number && block.Nonce() == nil {
|
if block.Number().Uint64() == work.Number && block.Nonce() == nil {
|
||||||
self.current.block.Header().Nonce = work.Nonce
|
self.current.block.Header().Nonce = work.Nonce
|
||||||
|
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 {
|
if err := self.chain.InsertChain(types.Blocks{self.current.block}); err == nil {
|
||||||
self.mux.Post(core.NewMinedBlockEvent{self.current.block})
|
self.mux.Post(core.NewMinedBlockEvent{self.current.block})
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -197,7 +210,7 @@ gasLimit:
|
||||||
}
|
}
|
||||||
self.eth.TxPool().RemoveSet(remove)
|
self.eth.TxPool().RemoveSet(remove)
|
||||||
|
|
||||||
self.current.coinbase.AddAmount(core.BlockReward)
|
self.current.coinbase.AddBalance(core.BlockReward)
|
||||||
|
|
||||||
self.current.state.Update(ethutil.Big0)
|
self.current.state.Update(ethutil.Big0)
|
||||||
self.push()
|
self.push()
|
||||||
|
|
@ -225,7 +238,7 @@ func (self *worker) commitUncle(uncle *types.Header) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
uncleAccount := self.current.state.GetAccount(uncle.Coinbase)
|
uncleAccount := self.current.state.GetAccount(uncle.Coinbase)
|
||||||
uncleAccount.AddAmount(uncleReward)
|
uncleAccount.AddBalance(uncleReward)
|
||||||
|
|
||||||
self.current.coinbase.AddBalance(uncleReward)
|
self.current.coinbase.AddBalance(uncleReward)
|
||||||
|
|
||||||
|
|
@ -244,3 +257,12 @@ func (self *worker) commitTransaction(tx *types.Transaction) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *worker) HashRate() int64 {
|
||||||
|
var tot int64
|
||||||
|
for _, agent := range self.agents {
|
||||||
|
tot += agent.Pow().GetHashrate()
|
||||||
|
}
|
||||||
|
|
||||||
|
return tot
|
||||||
|
}
|
||||||
|
|
|
||||||
162
rpc/api.go
162
rpc/api.go
|
|
@ -9,6 +9,7 @@ For each request type, define the following:
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
@ -19,8 +20,10 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/ethutil"
|
||||||
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/event/filter"
|
"github.com/ethereum/go-ethereum/event/filter"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
|
"github.com/ethereum/go-ethereum/ui"
|
||||||
"github.com/ethereum/go-ethereum/xeth"
|
"github.com/ethereum/go-ethereum/xeth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -31,7 +34,10 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type EthereumApi struct {
|
type EthereumApi struct {
|
||||||
xeth *xeth.XEth
|
eth *xeth.XEth
|
||||||
|
xethMu sync.RWMutex
|
||||||
|
mux *event.TypeMux
|
||||||
|
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
filterManager *filter.FilterManager
|
filterManager *filter.FilterManager
|
||||||
|
|
||||||
|
|
@ -45,17 +51,21 @@ type EthereumApi struct {
|
||||||
register map[string][]*NewTxArgs
|
register map[string][]*NewTxArgs
|
||||||
|
|
||||||
db ethutil.Database
|
db ethutil.Database
|
||||||
|
|
||||||
|
defaultBlockAge int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEthereumApi(eth *xeth.XEth) *EthereumApi {
|
func NewEthereumApi(eth *xeth.XEth) *EthereumApi {
|
||||||
db, _ := ethdb.NewLDBDatabase("dapps")
|
db, _ := ethdb.NewLDBDatabase("dapps")
|
||||||
api := &EthereumApi{
|
api := &EthereumApi{
|
||||||
xeth: eth,
|
eth: eth,
|
||||||
|
mux: eth.Backend().EventMux(),
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
filterManager: filter.NewFilterManager(eth.Backend().EventMux()),
|
filterManager: filter.NewFilterManager(eth.Backend().EventMux()),
|
||||||
logs: make(map[int]*logFilter),
|
logs: make(map[int]*logFilter),
|
||||||
messages: make(map[int]*whisperFilter),
|
messages: make(map[int]*whisperFilter),
|
||||||
db: db,
|
db: db,
|
||||||
|
defaultBlockAge: -1,
|
||||||
}
|
}
|
||||||
go api.filterManager.Start()
|
go api.filterManager.Start()
|
||||||
go api.start()
|
go api.start()
|
||||||
|
|
@ -63,11 +73,36 @@ func NewEthereumApi(eth *xeth.XEth) *EthereumApi {
|
||||||
return api
|
return api
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *EthereumApi) setStateByBlockNumber(num int64) {
|
||||||
|
chain := self.xeth().Backend().ChainManager()
|
||||||
|
var block *types.Block
|
||||||
|
|
||||||
|
if self.defaultBlockAge < 0 {
|
||||||
|
num = chain.CurrentBlock().Number().Int64() + num + 1
|
||||||
|
}
|
||||||
|
block = chain.GetBlockByNumber(uint64(num))
|
||||||
|
|
||||||
|
if block != nil {
|
||||||
|
self.useState(state.New(block.Root(), self.xeth().Backend().Db()))
|
||||||
|
} else {
|
||||||
|
self.useState(chain.State())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *EthereumApi) start() {
|
func (self *EthereumApi) start() {
|
||||||
timer := time.NewTicker(filterTickerTime)
|
timer := time.NewTicker(filterTickerTime)
|
||||||
|
events := self.mux.Subscribe(core.ChainEvent{})
|
||||||
|
|
||||||
done:
|
done:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
case ev := <-events.Chan():
|
||||||
|
switch ev.(type) {
|
||||||
|
case core.ChainEvent:
|
||||||
|
if self.defaultBlockAge < 0 {
|
||||||
|
self.setStateByBlockNumber(self.defaultBlockAge)
|
||||||
|
}
|
||||||
|
}
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
self.logMut.Lock()
|
self.logMut.Lock()
|
||||||
self.messagesMut.Lock()
|
self.messagesMut.Lock()
|
||||||
|
|
@ -80,7 +115,7 @@ done:
|
||||||
|
|
||||||
for id, filter := range self.messages {
|
for id, filter := range self.messages {
|
||||||
if time.Since(filter.timeout) > 20*time.Second {
|
if time.Since(filter.timeout) > 20*time.Second {
|
||||||
self.xeth.Whisper().Unwatch(id)
|
self.xeth().Whisper().Unwatch(id)
|
||||||
delete(self.messages, id)
|
delete(self.messages, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -128,7 +163,7 @@ func (self *EthereumApi) WatchTx(args string, reply *interface{}) error {
|
||||||
|
|
||||||
func (self *EthereumApi) NewFilter(args *FilterOptions, reply *interface{}) error {
|
func (self *EthereumApi) NewFilter(args *FilterOptions, reply *interface{}) error {
|
||||||
var id int
|
var id int
|
||||||
filter := core.NewFilter(self.xeth.Backend())
|
filter := core.NewFilter(self.xeth().Backend())
|
||||||
filter.SetOptions(toFilterOptions(args))
|
filter.SetOptions(toFilterOptions(args))
|
||||||
filter.LogsCallback = func(logs state.Logs) {
|
filter.LogsCallback = func(logs state.Logs) {
|
||||||
self.logMut.Lock()
|
self.logMut.Lock()
|
||||||
|
|
@ -153,7 +188,7 @@ func (self *EthereumApi) UninstallFilter(id int, reply *interface{}) error {
|
||||||
|
|
||||||
func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error {
|
func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error {
|
||||||
var id int
|
var id int
|
||||||
filter := core.NewFilter(self.xeth.Backend())
|
filter := core.NewFilter(self.xeth().Backend())
|
||||||
|
|
||||||
callback := func(block *types.Block) {
|
callback := func(block *types.Block) {
|
||||||
self.logMut.Lock()
|
self.logMut.Lock()
|
||||||
|
|
@ -198,7 +233,7 @@ func (self *EthereumApi) Logs(id int, reply *interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *EthereumApi) AllLogs(args *FilterOptions, reply *interface{}) error {
|
func (self *EthereumApi) AllLogs(args *FilterOptions, reply *interface{}) error {
|
||||||
filter := core.NewFilter(self.xeth.Backend())
|
filter := core.NewFilter(self.xeth().Backend())
|
||||||
filter.SetOptions(toFilterOptions(args))
|
filter.SetOptions(toFilterOptions(args))
|
||||||
|
|
||||||
*reply = toLogs(filter.Find())
|
*reply = toLogs(filter.Find())
|
||||||
|
|
@ -209,9 +244,9 @@ func (self *EthereumApi) AllLogs(args *FilterOptions, reply *interface{}) error
|
||||||
func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *interface{}) error {
|
func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *interface{}) error {
|
||||||
// This seems a bit precarious Maybe worth splitting to discrete functions
|
// This seems a bit precarious Maybe worth splitting to discrete functions
|
||||||
if len(args.Hash) > 0 {
|
if len(args.Hash) > 0 {
|
||||||
*reply = p.xeth.BlockByHash(args.Hash)
|
*reply = p.xeth().BlockByHash(args.Hash)
|
||||||
} else {
|
} else {
|
||||||
*reply = p.xeth.BlockByNumber(args.BlockNumber)
|
*reply = p.xeth().BlockByNumber(args.BlockNumber)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -226,18 +261,35 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO if no_private_key then
|
// TODO if no_private_key then
|
||||||
if _, exists := p.register[args.From]; exists {
|
//if _, exists := p.register[args.From]; exists {
|
||||||
p.register[args.From] = append(p.register[args.From], args)
|
// p.register[args.From] = append(p.register[args.From], args)
|
||||||
} else {
|
//} else {
|
||||||
result, _ := p.xeth.Transact( /* TODO specify account */ args.To, args.Value, args.Gas, args.GasPrice, args.Data)
|
/*
|
||||||
*reply = result
|
account := accounts.Get(fromHex(args.From))
|
||||||
|
if account != nil {
|
||||||
|
if account.Unlocked() {
|
||||||
|
if !unlockAccount(account) {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result, _ := account.Transact(fromHex(args.To), fromHex(args.Value), fromHex(args.Gas), fromHex(args.GasPrice), fromHex(args.Data))
|
||||||
|
if len(result) > 0 {
|
||||||
|
*reply = toHex(result)
|
||||||
|
}
|
||||||
|
} else if _, exists := p.register[args.From]; exists {
|
||||||
|
p.register[ags.From] = append(p.register[args.From], args)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
result, _ := p.xeth().Transact( /* TODO specify account */ args.To, args.Value, args.Gas, args.GasPrice, args.Data)
|
||||||
|
*reply = result
|
||||||
|
//}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) Call(args *NewTxArgs, reply *interface{}) error {
|
func (p *EthereumApi) Call(args *NewTxArgs, reply *interface{}) error {
|
||||||
result, err := p.xeth.Call( /* TODO specify account */ args.To, args.Value, args.Gas, args.GasPrice, args.Data)
|
result, err := p.xeth().Call( /* TODO specify account */ args.To, args.Value, args.Gas, args.GasPrice, args.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -251,7 +303,7 @@ func (p *EthereumApi) PushTx(args *PushTxArgs, reply *interface{}) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
result, _ := p.xeth.PushTx(args.Tx)
|
result, _ := p.xeth().PushTx(args.Tx)
|
||||||
*reply = result
|
*reply = result
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -262,7 +314,7 @@ func (p *EthereumApi) GetStateAt(args *GetStateArgs, reply *interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
state := p.xeth.State().SafeGet(args.Address)
|
state := p.xeth().State().SafeGet(args.Address)
|
||||||
|
|
||||||
value := state.StorageString(args.Key)
|
value := state.StorageString(args.Key)
|
||||||
var hx string
|
var hx string
|
||||||
|
|
@ -284,42 +336,55 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *interface{}) err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
*reply = p.xeth.State().SafeGet(args.Address).Storage()
|
*reply = p.xeth().State().SafeGet(args.Address).Storage()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) GetPeerCount(reply *interface{}) error {
|
func (p *EthereumApi) GetPeerCount(reply *interface{}) error {
|
||||||
*reply = p.xeth.PeerCount()
|
*reply = p.xeth().PeerCount()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) GetIsListening(reply *interface{}) error {
|
func (p *EthereumApi) GetIsListening(reply *interface{}) error {
|
||||||
*reply = p.xeth.IsListening()
|
*reply = p.xeth().IsListening()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) GetCoinbase(reply *interface{}) error {
|
func (p *EthereumApi) GetCoinbase(reply *interface{}) error {
|
||||||
*reply = p.xeth.Coinbase()
|
*reply = p.xeth().Coinbase()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) Accounts(reply *interface{}) error {
|
func (p *EthereumApi) Accounts(reply *interface{}) error {
|
||||||
*reply = p.xeth.Accounts()
|
*reply = p.xeth().Accounts()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) GetIsMining(reply *interface{}) error {
|
func (p *EthereumApi) GetIsMining(reply *interface{}) error {
|
||||||
*reply = p.xeth.IsMining()
|
*reply = p.xeth().IsMining()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) SetMining(shouldmine bool, reply *interface{}) error {
|
func (p *EthereumApi) SetMining(shouldmine bool, reply *interface{}) error {
|
||||||
*reply = p.xeth.SetMining(shouldmine)
|
*reply = p.xeth().SetMining(shouldmine)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *EthereumApi) GetDefaultBlockAge(reply *interface{}) error {
|
||||||
|
*reply = p.defaultBlockAge
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *EthereumApi) SetDefaultBlockAge(defaultBlockAge int64, reply *interface{}) error {
|
||||||
|
p.defaultBlockAge = defaultBlockAge
|
||||||
|
p.setStateByBlockNumber(p.defaultBlockAge)
|
||||||
|
|
||||||
|
*reply = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) BlockNumber(reply *interface{}) error {
|
func (p *EthereumApi) BlockNumber(reply *interface{}) error {
|
||||||
*reply = p.xeth.Backend().ChainManager().CurrentBlock().Number()
|
*reply = p.xeth().Backend().ChainManager().CurrentBlock().Number()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -328,7 +393,7 @@ func (p *EthereumApi) GetTxCountAt(args *GetTxCountArgs, reply *interface{}) err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*reply = p.xeth.TxCountAt(args.Address)
|
*reply = p.xeth().TxCountAt(args.Address)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -337,7 +402,7 @@ func (p *EthereumApi) GetBalanceAt(args *GetBalanceArgs, reply *interface{}) err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
state := p.xeth.State().SafeGet(args.Address)
|
state := p.xeth().State().SafeGet(args.Address)
|
||||||
*reply = toHex(state.Balance().Bytes())
|
*reply = toHex(state.Balance().Bytes())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -347,7 +412,7 @@ func (p *EthereumApi) GetCodeAt(args *GetCodeAtArgs, reply *interface{}) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*reply = p.xeth.CodeAt(args.Address)
|
*reply = p.xeth().CodeAt(args.Address)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -394,7 +459,7 @@ func (p *EthereumApi) DbGet(args *DbArgs, reply *interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) NewWhisperIdentity(reply *interface{}) error {
|
func (p *EthereumApi) NewWhisperIdentity(reply *interface{}) error {
|
||||||
*reply = p.xeth.Whisper().NewIdentity()
|
*reply = p.xeth().Whisper().NewIdentity()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -405,7 +470,7 @@ func (p *EthereumApi) NewWhisperFilter(args *xeth.Options, reply *interface{}) e
|
||||||
defer p.messagesMut.Unlock()
|
defer p.messagesMut.Unlock()
|
||||||
p.messages[id].add(msg) // = append(p.messages[id], msg)
|
p.messages[id].add(msg) // = append(p.messages[id], msg)
|
||||||
}
|
}
|
||||||
id = p.xeth.Whisper().Watch(args)
|
id = p.xeth().Whisper().Watch(args)
|
||||||
p.messages[id] = &whisperFilter{timeout: time.Now()}
|
p.messages[id] = &whisperFilter{timeout: time.Now()}
|
||||||
*reply = id
|
*reply = id
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -423,7 +488,7 @@ func (self *EthereumApi) MessagesChanged(id int, reply *interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) WhisperPost(args *WhisperMessageArgs, reply *interface{}) error {
|
func (p *EthereumApi) WhisperPost(args *WhisperMessageArgs, reply *interface{}) error {
|
||||||
err := p.xeth.Whisper().Post(args.Payload, args.To, args.From, args.Topic, args.Priority, args.Ttl)
|
err := p.xeth().Whisper().Post(args.Payload, args.To, args.From, args.Topic, args.Priority, args.Ttl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -433,12 +498,12 @@ func (p *EthereumApi) WhisperPost(args *WhisperMessageArgs, reply *interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) HasWhisperIdentity(args string, reply *interface{}) error {
|
func (p *EthereumApi) HasWhisperIdentity(args string, reply *interface{}) error {
|
||||||
*reply = p.xeth.Whisper().HasIdentity(args)
|
*reply = p.xeth().Whisper().HasIdentity(args)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EthereumApi) WhisperMessages(id int, reply *interface{}) error {
|
func (p *EthereumApi) WhisperMessages(id int, reply *interface{}) error {
|
||||||
*reply = p.xeth.Whisper().Messages(id)
|
*reply = p.xeth().Whisper().Messages(id)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -458,6 +523,14 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return p.SetMining(args, reply)
|
return p.SetMining(args, reply)
|
||||||
|
case "eth_defaultBlock":
|
||||||
|
return p.GetDefaultBlockAge(reply)
|
||||||
|
case "eth_setDefaultBlock":
|
||||||
|
args, err := req.ToIntArgs()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return p.SetDefaultBlockAge(int64(args), reply)
|
||||||
case "eth_peerCount":
|
case "eth_peerCount":
|
||||||
return p.GetPeerCount(reply)
|
return p.GetPeerCount(reply)
|
||||||
case "eth_number":
|
case "eth_number":
|
||||||
|
|
@ -634,3 +707,28 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||||
rpclogger.DebugDetailf("Reply: %T %s", reply, reply)
|
rpclogger.DebugDetailf("Reply: %T %s", reply, reply)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *EthereumApi) xeth() *xeth.XEth {
|
||||||
|
self.xethMu.RLock()
|
||||||
|
defer self.xethMu.RUnlock()
|
||||||
|
|
||||||
|
return self.eth
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *EthereumApi) useState(statedb *state.StateDB) {
|
||||||
|
self.xethMu.Lock()
|
||||||
|
defer self.xethMu.Unlock()
|
||||||
|
|
||||||
|
self.eth = self.eth.UseState(statedb)
|
||||||
|
}
|
||||||
|
|
||||||
|
func t(f ui.Frontend) {
|
||||||
|
// Call the password dialog
|
||||||
|
ret, err := f.Call("PasswordDialog")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
// Get the first argument
|
||||||
|
t, _ := ret.Get(0)
|
||||||
|
fmt.Println("return:", t)
|
||||||
|
}
|
||||||
|
|
|
||||||
18
rpc/args.go
18
rpc/args.go
|
|
@ -197,7 +197,7 @@ type FilterOptions struct {
|
||||||
Earliest int64
|
Earliest int64
|
||||||
Latest int64
|
Latest int64
|
||||||
Address interface{}
|
Address interface{}
|
||||||
Topic []string
|
Topic []interface{}
|
||||||
Skip int
|
Skip int
|
||||||
Max int
|
Max int
|
||||||
}
|
}
|
||||||
|
|
@ -220,10 +220,20 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions {
|
||||||
|
|
||||||
opts.Earliest = options.Earliest
|
opts.Earliest = options.Earliest
|
||||||
opts.Latest = options.Latest
|
opts.Latest = options.Latest
|
||||||
opts.Topics = make([][]byte, len(options.Topic))
|
|
||||||
for i, topic := range options.Topic {
|
topics := make([][][]byte, len(options.Topic))
|
||||||
opts.Topics[i] = fromHex(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
|
return opts
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ import (
|
||||||
var rpchttplogger = logger.NewLogger("RPC-HTTP")
|
var rpchttplogger = logger.NewLogger("RPC-HTTP")
|
||||||
var JSON rpc.JsonWrapper
|
var JSON rpc.JsonWrapper
|
||||||
|
|
||||||
func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) {
|
func NewRpcHttpServer(pipe *xeth.XEth, address string, port int) (*RpcHttpServer, error) {
|
||||||
sport := fmt.Sprintf("127.0.0.1:%d", port)
|
sport := fmt.Sprintf("%s:%d", address, port)
|
||||||
l, err := net.Listen("tcp", sport)
|
l, err := net.Listen("tcp", sport)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -41,6 +41,7 @@ func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) {
|
||||||
quit: make(chan bool),
|
quit: make(chan bool),
|
||||||
pipe: pipe,
|
pipe: pipe,
|
||||||
port: port,
|
port: port,
|
||||||
|
addr: address,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,6 +50,7 @@ type RpcHttpServer struct {
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
pipe *xeth.XEth
|
pipe *xeth.XEth
|
||||||
port int
|
port int
|
||||||
|
addr string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RpcHttpServer) exitHandler() {
|
func (s *RpcHttpServer) exitHandler() {
|
||||||
|
|
@ -69,7 +71,7 @@ func (s *RpcHttpServer) Stop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RpcHttpServer) Start() {
|
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()
|
go s.exitHandler()
|
||||||
|
|
||||||
api := rpc.NewEthereumApi(s.pipe)
|
api := rpc.NewEthereumApi(s.pipe)
|
||||||
|
|
|
||||||
|
|
@ -210,6 +210,19 @@ func (req *RpcRequest) ToBoolArgs() (bool, error) {
|
||||||
return args, nil
|
return args, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (req *RpcRequest) ToIntArgs() (int, error) {
|
||||||
|
if len(req.Params) < 1 {
|
||||||
|
return 0, errArguments
|
||||||
|
}
|
||||||
|
|
||||||
|
var args int
|
||||||
|
if err := json.Unmarshal(req.Params[0], &args); err != nil {
|
||||||
|
return 0, errArguments
|
||||||
|
}
|
||||||
|
|
||||||
|
return args, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (req *RpcRequest) ToCompileArgs() (string, error) {
|
func (req *RpcRequest) ToCompileArgs() (string, error) {
|
||||||
if len(req.Params) < 1 {
|
if len(req.Params) < 1 {
|
||||||
return "", errArguments
|
return "", errArguments
|
||||||
|
|
|
||||||
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"`
|
Accounts map[string]Account `json:"accounts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateDB) Dump() []byte {
|
func (self *StateDB) RawDump() World {
|
||||||
world := World{
|
world := World{
|
||||||
Root: ethutil.Bytes2Hex(self.trie.Root()),
|
Root: ethutil.Bytes2Hex(self.trie.Root()),
|
||||||
Accounts: make(map[string]Account),
|
Accounts: make(map[string]Account),
|
||||||
|
|
@ -35,12 +35,15 @@ func (self *StateDB) Dump() []byte {
|
||||||
|
|
||||||
storageIt := stateObject.State.trie.Iterator()
|
storageIt := stateObject.State.trie.Iterator()
|
||||||
for storageIt.Next() {
|
for storageIt.Next() {
|
||||||
account.Storage[ethutil.Bytes2Hex(it.Key)] = ethutil.Bytes2Hex(it.Value)
|
account.Storage[ethutil.Bytes2Hex(storageIt.Key)] = ethutil.Bytes2Hex(storageIt.Value)
|
||||||
}
|
}
|
||||||
world.Accounts[ethutil.Bytes2Hex(it.Key)] = account
|
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 {
|
if err != nil {
|
||||||
fmt.Println("dump err", err)
|
fmt.Println("dump err", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,14 @@ func (self Code) String() string {
|
||||||
|
|
||||||
type Storage map[string]*ethutil.Value
|
type Storage map[string]*ethutil.Value
|
||||||
|
|
||||||
|
func (self Storage) String() (str string) {
|
||||||
|
for key, value := range self {
|
||||||
|
str += fmt.Sprintf("%X : %X\n", key, value.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (self Storage) Copy() Storage {
|
func (self Storage) Copy() Storage {
|
||||||
cpy := make(Storage)
|
cpy := make(Storage)
|
||||||
for key, value := range self {
|
for key, value := range self {
|
||||||
|
|
@ -119,10 +127,9 @@ func (self *StateObject) GetStorage(key *big.Int) *ethutil.Value {
|
||||||
}
|
}
|
||||||
func (self *StateObject) SetStorage(key *big.Int, value *ethutil.Value) {
|
func (self *StateObject) SetStorage(key *big.Int, value *ethutil.Value) {
|
||||||
self.SetState(key.Bytes(), value)
|
self.SetState(key.Bytes(), value)
|
||||||
self.dirty = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateObject) Storage() map[string]*ethutil.Value {
|
func (self *StateObject) Storage() Storage {
|
||||||
return self.storage
|
return self.storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -172,20 +179,22 @@ func (c *StateObject) AddBalance(amount *big.Int) {
|
||||||
|
|
||||||
statelogger.Debugf("%x: #%d %v (+ %v)\n", c.Address(), c.nonce, c.balance, amount)
|
statelogger.Debugf("%x: #%d %v (+ %v)\n", c.Address(), c.nonce, c.balance, amount)
|
||||||
}
|
}
|
||||||
func (c *StateObject) AddAmount(amount *big.Int) { c.AddBalance(amount) }
|
|
||||||
|
|
||||||
func (c *StateObject) SubBalance(amount *big.Int) {
|
func (c *StateObject) SubBalance(amount *big.Int) {
|
||||||
c.SetBalance(new(big.Int).Sub(c.balance, amount))
|
c.SetBalance(new(big.Int).Sub(c.balance, amount))
|
||||||
|
|
||||||
statelogger.Debugf("%x: #%d %v (- %v)\n", c.Address(), c.nonce, c.balance, amount)
|
statelogger.Debugf("%x: #%d %v (- %v)\n", c.Address(), c.nonce, c.balance, amount)
|
||||||
}
|
}
|
||||||
func (c *StateObject) SubAmount(amount *big.Int) { c.SubBalance(amount) }
|
|
||||||
|
|
||||||
func (c *StateObject) SetBalance(amount *big.Int) {
|
func (c *StateObject) SetBalance(amount *big.Int) {
|
||||||
c.balance = amount
|
c.balance = amount
|
||||||
c.dirty = true
|
c.dirty = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *StateObject) St() Storage {
|
||||||
|
return c.storage
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Gas setters and getters
|
// Gas setters and getters
|
||||||
//
|
//
|
||||||
|
|
@ -198,7 +207,7 @@ func (c *StateObject) ConvertGas(gas, price *big.Int) error {
|
||||||
return fmt.Errorf("insufficient amount: %v, %v", c.balance, total)
|
return fmt.Errorf("insufficient amount: %v, %v", c.balance, total)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.SubAmount(total)
|
c.SubBalance(total)
|
||||||
|
|
||||||
c.dirty = true
|
c.dirty = true
|
||||||
|
|
||||||
|
|
@ -221,7 +230,7 @@ func (self *StateObject) BuyGas(gas, price *big.Int) error {
|
||||||
rGas := new(big.Int).Set(gas)
|
rGas := new(big.Int).Set(gas)
|
||||||
rGas.Mul(rGas, price)
|
rGas.Mul(rGas, price)
|
||||||
|
|
||||||
self.AddAmount(rGas)
|
self.AddBalance(rGas)
|
||||||
|
|
||||||
self.dirty = true
|
self.dirty = true
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
// Retrieve the balance from the given address or 0 if object not found
|
||||||
func (self *StateDB) GetBalance(addr []byte) *big.Int {
|
func (self *StateDB) GetBalance(addr []byte) *big.Int {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetOrNewStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
return stateObject.balance
|
return stateObject.balance
|
||||||
}
|
}
|
||||||
|
|
@ -63,14 +63,14 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateDB) AddBalance(addr []byte, amount *big.Int) {
|
func (self *StateDB) AddBalance(addr []byte, amount *big.Int) {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetOrNewStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
stateObject.AddBalance(amount)
|
stateObject.AddBalance(amount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateDB) GetNonce(addr []byte) uint64 {
|
func (self *StateDB) GetNonce(addr []byte) uint64 {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetOrNewStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
return stateObject.nonce
|
return stateObject.nonce
|
||||||
}
|
}
|
||||||
|
|
@ -79,7 +79,7 @@ func (self *StateDB) GetNonce(addr []byte) uint64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateDB) GetCode(addr []byte) []byte {
|
func (self *StateDB) GetCode(addr []byte) []byte {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetOrNewStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
return stateObject.code
|
return stateObject.code
|
||||||
}
|
}
|
||||||
|
|
@ -88,7 +88,7 @@ func (self *StateDB) GetCode(addr []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateDB) GetState(a, b []byte) []byte {
|
func (self *StateDB) GetState(a, b []byte) []byte {
|
||||||
stateObject := self.GetStateObject(a)
|
stateObject := self.GetOrNewStateObject(a)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
return stateObject.GetState(b).Bytes()
|
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) {
|
func (self *StateDB) SetNonce(addr []byte, nonce uint64) {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetOrNewStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
stateObject.SetNonce(nonce)
|
stateObject.SetNonce(nonce)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateDB) SetCode(addr, code []byte) {
|
func (self *StateDB) SetCode(addr, code []byte) {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetOrNewStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
stateObject.SetCode(code)
|
stateObject.SetCode(code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateDB) SetState(addr, key []byte, value interface{}) {
|
func (self *StateDB) SetState(addr, key []byte, value interface{}) {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetOrNewStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
stateObject.SetState(key, ethutil.NewValue(value))
|
stateObject.SetState(key, ethutil.NewValue(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateDB) Delete(addr []byte) bool {
|
func (self *StateDB) Delete(addr []byte) bool {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetOrNewStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
stateObject.MarkForDeletion()
|
stateObject.MarkForDeletion()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,10 +79,6 @@ func RunVmTest(p string, t *testing.T) {
|
||||||
helper.CreateFileTests(t, p, &tests)
|
helper.CreateFileTests(t, p, &tests)
|
||||||
|
|
||||||
for name, test := range tests {
|
for name, test := range tests {
|
||||||
helper.Logger.SetLogLevel(4)
|
|
||||||
if name != "TransactionNonceCheck2" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
statedb := state.New(nil, db)
|
statedb := state.New(nil, db)
|
||||||
for addr, account := range test.Pre {
|
for addr, account := range test.Pre {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package trie
|
package trie
|
||||||
|
|
||||||
import "bytes"
|
import (
|
||||||
|
"bytes"
|
||||||
|
)
|
||||||
|
|
||||||
type Iterator struct {
|
type Iterator struct {
|
||||||
trie *Trie
|
trie *Trie
|
||||||
|
|
@ -10,22 +12,28 @@ type Iterator struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIterator(trie *Trie) *Iterator {
|
func NewIterator(trie *Trie) *Iterator {
|
||||||
return &Iterator{trie: trie, Key: make([]byte, 32)}
|
return &Iterator{trie: trie, Key: nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Iterator) Next() bool {
|
func (self *Iterator) Next() bool {
|
||||||
self.trie.mu.Lock()
|
self.trie.mu.Lock()
|
||||||
defer self.trie.mu.Unlock()
|
defer self.trie.mu.Unlock()
|
||||||
|
|
||||||
|
isIterStart := false
|
||||||
|
if self.Key == nil {
|
||||||
|
isIterStart = true
|
||||||
|
self.Key = make([]byte, 32)
|
||||||
|
}
|
||||||
|
|
||||||
key := RemTerm(CompactHexDecode(string(self.Key)))
|
key := RemTerm(CompactHexDecode(string(self.Key)))
|
||||||
k := self.next(self.trie.root, key)
|
k := self.next(self.trie.root, key, isIterStart)
|
||||||
|
|
||||||
self.Key = []byte(DecodeCompact(k))
|
self.Key = []byte(DecodeCompact(k))
|
||||||
|
|
||||||
return len(k) > 0
|
return len(k) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Iterator) next(node Node, key []byte) []byte {
|
func (self *Iterator) next(node Node, key []byte, isIterStart bool) []byte {
|
||||||
if node == nil {
|
if node == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -33,7 +41,7 @@ func (self *Iterator) next(node Node, key []byte) []byte {
|
||||||
switch node := node.(type) {
|
switch node := node.(type) {
|
||||||
case *FullNode:
|
case *FullNode:
|
||||||
if len(key) > 0 {
|
if len(key) > 0 {
|
||||||
k := self.next(node.branch(key[0]), key[1:])
|
k := self.next(node.branch(key[0]), key[1:], isIterStart)
|
||||||
if k != nil {
|
if k != nil {
|
||||||
return append([]byte{key[0]}, k...)
|
return append([]byte{key[0]}, k...)
|
||||||
}
|
}
|
||||||
|
|
@ -54,7 +62,13 @@ func (self *Iterator) next(node Node, key []byte) []byte {
|
||||||
case *ShortNode:
|
case *ShortNode:
|
||||||
k := RemTerm(node.Key())
|
k := RemTerm(node.Key())
|
||||||
if vnode, ok := node.Value().(*ValueNode); ok {
|
if vnode, ok := node.Value().(*ValueNode); ok {
|
||||||
if bytes.Compare([]byte(k), key) > 0 {
|
switch bytes.Compare([]byte(k), key) {
|
||||||
|
case 0:
|
||||||
|
if isIterStart {
|
||||||
|
self.Value = vnode.Val()
|
||||||
|
return k
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
self.Value = vnode.Val()
|
self.Value = vnode.Val()
|
||||||
return k
|
return k
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +78,7 @@ func (self *Iterator) next(node Node, key []byte) []byte {
|
||||||
var ret []byte
|
var ret []byte
|
||||||
skey := key[len(k):]
|
skey := key[len(k):]
|
||||||
if BeginsWith(key, k) {
|
if BeginsWith(key, k) {
|
||||||
ret = self.next(cnode, skey)
|
ret = self.next(cnode, skey, isIterStart)
|
||||||
} else if bytes.Compare(k, key[:len(k)]) > 0 {
|
} else if bytes.Compare(k, key[:len(k)]) > 0 {
|
||||||
return self.key(node)
|
return self.key(node)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -267,14 +267,13 @@ func TestLargeData(t *testing.T) {
|
||||||
trie := NewEmpty()
|
trie := NewEmpty()
|
||||||
vals := make(map[string]*kv)
|
vals := make(map[string]*kv)
|
||||||
|
|
||||||
for i := byte(1); i < 255; i++ {
|
for i := byte(0); i < 255; i++ {
|
||||||
value := &kv{ethutil.LeftPadBytes([]byte{i}, 32), []byte{i}, false}
|
value := &kv{ethutil.LeftPadBytes([]byte{i}, 32), []byte{i}, false}
|
||||||
value2 := &kv{ethutil.LeftPadBytes([]byte{10, i}, 32), []byte{i}, false}
|
value2 := &kv{ethutil.LeftPadBytes([]byte{10, i}, 32), []byte{i}, false}
|
||||||
trie.Update(value.k, value.v)
|
trie.Update(value.k, value.v)
|
||||||
trie.Update(value2.k, value2.v)
|
trie.Update(value2.k, value2.v)
|
||||||
vals[string(value.k)] = value
|
vals[string(value.k)] = value
|
||||||
vals[string(value2.k)] = value2
|
vals[string(value2.k)] = value2
|
||||||
fmt.Println(value, "\n", value2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
it := trie.Iterator()
|
it := trie.Iterator()
|
||||||
|
|
|
||||||
76
ui/filter.go
76
ui/filter.go
|
|
@ -1,77 +1 @@
|
||||||
package ui
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
18
ui/frontend.go
Normal file
18
ui/frontend.go
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
package ui
|
||||||
|
|
||||||
|
// ReturnInterface is returned by the Intercom interface when a method is called
|
||||||
|
type ReturnInterface interface {
|
||||||
|
Get(i int) (interface{}, error)
|
||||||
|
Size() int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Frontend is the basic interface for calling arbitrary methods on something that
|
||||||
|
// implements a front end (GUI, CLI, etc)
|
||||||
|
type Frontend interface {
|
||||||
|
// Checks whether a specific method is implemented
|
||||||
|
Supports(method string) bool
|
||||||
|
// Call calls the given method on interface it implements. This will return
|
||||||
|
// an error with errNotImplemented if the method hasn't been implemented
|
||||||
|
// and will return a ReturnInterface if it does.
|
||||||
|
Call(method string) (ReturnInterface, error)
|
||||||
|
}
|
||||||
|
|
@ -1,30 +1 @@
|
||||||
package qt
|
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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
13
vm/vm.go
13
vm/vm.go
|
|
@ -16,6 +16,8 @@ type Vm struct {
|
||||||
logStr string
|
logStr string
|
||||||
|
|
||||||
err error
|
err error
|
||||||
|
// For logging
|
||||||
|
debug bool
|
||||||
|
|
||||||
Dbg Debugger
|
Dbg Debugger
|
||||||
|
|
||||||
|
|
@ -32,7 +34,7 @@ func New(env Environment) *Vm {
|
||||||
lt = LogTyDiff
|
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) {
|
func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.Int, callData []byte) (ret []byte, err error) {
|
||||||
|
|
@ -664,6 +666,7 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
|
||||||
}
|
}
|
||||||
addr = ref.Address()
|
addr = ref.Address()
|
||||||
|
|
||||||
|
fmt.Printf("CREATE %X\n", addr)
|
||||||
stack.Push(ethutil.BigD(addr))
|
stack.Push(ethutil.BigD(addr))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -727,7 +730,7 @@ func (self *Vm) Run(me, caller ContextRef, code []byte, value, gas, price *big.I
|
||||||
|
|
||||||
self.Printf(" => (%x) %v", receiver.Address()[:4], balance)
|
self.Printf(" => (%x) %v", receiver.Address()[:4], balance)
|
||||||
|
|
||||||
receiver.AddAmount(balance)
|
receiver.AddBalance(balance)
|
||||||
statedb.Delete(context.Address())
|
statedb.Delete(context.Address())
|
||||||
|
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
@ -828,7 +831,7 @@ func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCo
|
||||||
// 0 => non 0
|
// 0 => non 0
|
||||||
mult = ethutil.Big3
|
mult = ethutil.Big3
|
||||||
} else if len(val) > 0 && len(y.Bytes()) == 0 {
|
} else if len(val) > 0 && len(y.Bytes()) == 0 {
|
||||||
statedb.Refund(caller.Address(), GasSStoreRefund)
|
statedb.Refund(self.env.Origin(), GasSStoreRefund)
|
||||||
|
|
||||||
mult = ethutil.Big0
|
mult = ethutil.Big0
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -937,18 +940,22 @@ func (self *Vm) RunPrecompiled(p *PrecompiledAccount, callData []byte, context *
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Vm) Printf(format string, v ...interface{}) VirtualMachine {
|
func (self *Vm) Printf(format string, v ...interface{}) VirtualMachine {
|
||||||
|
if self.debug {
|
||||||
if self.logTy == LogTyPretty {
|
if self.logTy == LogTyPretty {
|
||||||
self.logStr += fmt.Sprintf(format, v...)
|
self.logStr += fmt.Sprintf(format, v...)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Vm) Endl() VirtualMachine {
|
func (self *Vm) Endl() VirtualMachine {
|
||||||
|
if self.debug {
|
||||||
if self.logTy == LogTyPretty {
|
if self.logTy == LogTyPretty {
|
||||||
vmlogger.Debugln(self.logStr)
|
vmlogger.Debugln(self.logStr)
|
||||||
self.logStr = ""
|
self.logStr = ""
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
vm/vm_jit.go
23
vm/vm_jit.go
|
|
@ -50,6 +50,7 @@ type RuntimeData struct {
|
||||||
timestamp int64
|
timestamp int64
|
||||||
code *byte
|
code *byte
|
||||||
codeSize uint64
|
codeSize uint64
|
||||||
|
codeHash i256
|
||||||
}
|
}
|
||||||
|
|
||||||
func hash2llvm(h []byte) 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.timestamp = self.env.Time()
|
||||||
self.data.code = getDataPtr(code)
|
self.data.code = getDataPtr(code)
|
||||||
self.data.codeSize = uint64(len(code))
|
self.data.codeSize = uint64(len(code))
|
||||||
|
self.data.codeHash = hash2llvm(crypto.Sha3(code)) // TODO: Get already computed hash?
|
||||||
|
|
||||||
jit := C.evmjit_create()
|
jit := C.evmjit_create()
|
||||||
retCode := C.evmjit_run(jit, unsafe.Pointer(&self.data), unsafe.Pointer(self))
|
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))
|
receiverAddr := llvm2hashRef(bswap(&self.data.address))
|
||||||
receiver := state.GetOrNewStateObject(receiverAddr)
|
receiver := state.GetOrNewStateObject(receiverAddr)
|
||||||
balance := state.GetBalance(me.Address())
|
balance := state.GetBalance(me.Address())
|
||||||
receiver.AddAmount(balance)
|
receiver.AddBalance(balance)
|
||||||
state.Delete(me.Address())
|
state.Delete(me.Address())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
C.evmjit_destroy(jit);
|
C.evmjit_destroy(jit)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -278,7 +280,7 @@ func env_blockhash(_vm unsafe.Pointer, _number unsafe.Pointer, _result unsafe.Po
|
||||||
}
|
}
|
||||||
|
|
||||||
//export env_call
|
//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)
|
vm := (*JitVm)(_vm)
|
||||||
|
|
||||||
//fmt.Printf("env_call (depth %d)\n", vm.Env().Depth())
|
//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))
|
inData := C.GoBytes(inDataPtr, C.int(inDataLen))
|
||||||
outData := llvm2bytesRef(outDataPtr, outDataLen)
|
outData := llvm2bytesRef(outDataPtr, outDataLen)
|
||||||
codeAddr := llvm2hash((*i256)(_codeAddr))
|
codeAddr := llvm2hash((*i256)(_codeAddr))
|
||||||
llvmGas := (*i256)(_gas)
|
gas := big.NewInt(*_gas)
|
||||||
gas := llvm2big(llvmGas)
|
|
||||||
var out []byte
|
var out []byte
|
||||||
var err error
|
var err error
|
||||||
if bytes.Equal(codeAddr, receiveAddr) {
|
if bytes.Equal(codeAddr, receiveAddr) {
|
||||||
|
|
@ -306,7 +307,7 @@ func env_call(_vm unsafe.Pointer, _gas unsafe.Pointer, _receiveAddr unsafe.Point
|
||||||
} else {
|
} else {
|
||||||
out, err = vm.env.CallCode(vm.me, codeAddr, inData, gas, vm.price, value)
|
out, err = vm.env.CallCode(vm.me, codeAddr, inData, gas, vm.price, value)
|
||||||
}
|
}
|
||||||
*llvmGas = big2llvm(gas)
|
*_gas = gas.Int64()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
copy(outData, out)
|
copy(outData, out)
|
||||||
return true
|
return true
|
||||||
|
|
@ -317,7 +318,7 @@ func env_call(_vm unsafe.Pointer, _gas unsafe.Pointer, _receiveAddr unsafe.Point
|
||||||
}
|
}
|
||||||
|
|
||||||
//export env_create
|
//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)
|
vm := (*JitVm)(_vm)
|
||||||
|
|
||||||
value := llvm2big((*i256)(_value))
|
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)(_result)
|
||||||
*result = i256{}
|
*result = i256{}
|
||||||
|
|
||||||
llvmGas := (*i256)(_gas)
|
gas := big.NewInt(*_gas)
|
||||||
gas := llvm2big(llvmGas)
|
|
||||||
|
|
||||||
ret, suberr, ref := vm.env.Create(vm.me, nil, initData, gas, vm.price, value)
|
ret, suberr, ref := vm.env.Create(vm.me, nil, initData, gas, vm.price, value)
|
||||||
if suberr == nil {
|
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
|
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)
|
gas.Sub(gas, dataGas)
|
||||||
*result = hash2llvm(ref.Address())
|
*result = hash2llvm(ref.Address())
|
||||||
}
|
}
|
||||||
*llvmGas = big2llvm(gas)
|
*_gas = gas.Int64()
|
||||||
}
|
}
|
||||||
|
|
||||||
//export env_log
|
//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)))
|
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
|
//export env_extcode
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,19 @@ import "github.com/ethereum/go-ethereum/state"
|
||||||
|
|
||||||
type State struct {
|
type State struct {
|
||||||
xeth *XEth
|
xeth *XEth
|
||||||
|
state *state.StateDB
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewState(xeth *XEth) *State {
|
func NewState(xeth *XEth, statedb *state.StateDB) *State {
|
||||||
return &State{xeth}
|
return &State{xeth, statedb}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) State() *state.StateDB {
|
func (self *State) State() *state.StateDB {
|
||||||
return self.xeth.chainManager.TransState()
|
return self.state
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) Get(addr string) *Object {
|
func (self *State) Get(addr string) *Object {
|
||||||
return &Object{self.State().GetStateObject(fromHex(addr))}
|
return &Object{self.state.GetStateObject(fromHex(addr))}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) SafeGet(addr string) *Object {
|
func (self *State) SafeGet(addr string) *Object {
|
||||||
|
|
@ -23,7 +24,7 @@ func (self *State) SafeGet(addr string) *Object {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) safeGet(addr string) *state.StateObject {
|
func (self *State) safeGet(addr string) *state.StateObject {
|
||||||
object := self.State().GetStateObject(fromHex(addr))
|
object := self.state.GetStateObject(fromHex(addr))
|
||||||
if object == nil {
|
if object == nil {
|
||||||
object = state.NewStateObject(fromHex(addr), self.xeth.eth.Db())
|
object = state.NewStateObject(fromHex(addr), self.xeth.eth.Db())
|
||||||
}
|
}
|
||||||
26
xeth/xeth.go
26
xeth/xeth.go
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/miner"
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
|
"github.com/ethereum/go-ethereum/state"
|
||||||
"github.com/ethereum/go-ethereum/whisper"
|
"github.com/ethereum/go-ethereum/whisper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -54,13 +55,26 @@ func New(eth Backend) *XEth {
|
||||||
whisper: NewWhisper(eth.Whisper()),
|
whisper: NewWhisper(eth.Whisper()),
|
||||||
miner: eth.Miner(),
|
miner: eth.Miner(),
|
||||||
}
|
}
|
||||||
xeth.state = NewState(xeth)
|
xeth.state = NewState(xeth, xeth.chainManager.TransState())
|
||||||
|
|
||||||
return xeth
|
return xeth
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *XEth) Backend() Backend { return self.eth }
|
func (self *XEth) Backend() Backend { return self.eth }
|
||||||
|
func (self *XEth) UseState(statedb *state.StateDB) *XEth {
|
||||||
|
xeth := &XEth{
|
||||||
|
eth: self.eth,
|
||||||
|
blockProcessor: self.blockProcessor,
|
||||||
|
chainManager: self.chainManager,
|
||||||
|
whisper: self.whisper,
|
||||||
|
miner: self.miner,
|
||||||
|
}
|
||||||
|
|
||||||
|
xeth.state = NewState(xeth, statedb)
|
||||||
|
return xeth
|
||||||
|
}
|
||||||
func (self *XEth) State() *State { return self.state }
|
func (self *XEth) State() *State { return self.state }
|
||||||
|
|
||||||
func (self *XEth) Whisper() *Whisper { return self.whisper }
|
func (self *XEth) Whisper() *Whisper { return self.whisper }
|
||||||
func (self *XEth) Miner() *miner.Miner { return self.miner }
|
func (self *XEth) Miner() *miner.Miner { return self.miner }
|
||||||
|
|
||||||
|
|
@ -229,7 +243,7 @@ func (self *XEth) Call(toStr, valueStr, gasStr, gasPriceStr, dataStr string) (st
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
statedb = self.chainManager.TransState()
|
statedb = self.State().State() //self.chainManager.TransState()
|
||||||
key = self.eth.KeyManager().KeyPair()
|
key = self.eth.KeyManager().KeyPair()
|
||||||
from = statedb.GetOrNewStateObject(key.Address())
|
from = statedb.GetOrNewStateObject(key.Address())
|
||||||
block = self.chainManager.CurrentBlock()
|
block = self.chainManager.CurrentBlock()
|
||||||
|
|
@ -286,14 +300,6 @@ func (self *XEth) Transact(toStr, valueStr, gasStr, gasPriceStr, codeStr string)
|
||||||
tx.SetNonce(nonce)
|
tx.SetNonce(nonce)
|
||||||
tx.Sign(key.PrivateKey)
|
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)
|
err = self.eth.TxPool().Add(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue