Merge branch 'develop'
This commit is contained in:
commit
80e5f50713
|
@ -1,9 +1,6 @@
|
||||||
language: go
|
language: go
|
||||||
go:
|
go:
|
||||||
- 1.4.2
|
- 1.4.2
|
||||||
before_install:
|
|
||||||
- sudo apt-get update -qq
|
|
||||||
- sudo apt-get install -yqq libgmp3-dev
|
|
||||||
install:
|
install:
|
||||||
# - go get code.google.com/p/go.tools/cmd/goimports
|
# - go get code.google.com/p/go.tools/cmd/goimports
|
||||||
# - go get github.com/golang/lint/golint
|
# - go get github.com/golang/lint/golint
|
||||||
|
@ -22,7 +19,11 @@ after_success:
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- secure: "U2U1AmkU4NJBgKR/uUAebQY87cNL0+1JHjnLOmmXwxYYyj5ralWb1aSuSH3qSXiT93qLBmtaUkuv9fberHVqrbAeVlztVdUsKAq7JMQH+M99iFkC9UiRMqHmtjWJ0ok4COD1sRYixxi21wb/JrMe3M1iL4QJVS61iltjHhVdM64="
|
- secure: "U2U1AmkU4NJBgKR/uUAebQY87cNL0+1JHjnLOmmXwxYYyj5ralWb1aSuSH3qSXiT93qLBmtaUkuv9fberHVqrbAeVlztVdUsKAq7JMQH+M99iFkC9UiRMqHmtjWJ0ok4COD1sRYixxi21wb/JrMe3M1iL4QJVS61iltjHhVdM64="
|
||||||
|
sudo: false
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- libgmp3-dev
|
||||||
notifications:
|
notifications:
|
||||||
webhooks:
|
webhooks:
|
||||||
urls:
|
urls:
|
||||||
|
|
|
@ -66,14 +66,6 @@
|
||||||
"ImportPath": "github.com/peterh/liner",
|
"ImportPath": "github.com/peterh/liner",
|
||||||
"Rev": "29f6a646557d83e2b6e9ba05c45fbea9c006dbe8"
|
"Rev": "29f6a646557d83e2b6e9ba05c45fbea9c006dbe8"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"ImportPath": "github.com/rakyll/globalconf",
|
|
||||||
"Rev": "415abc325023f1a00cd2d9fa512e0e71745791a2"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"ImportPath": "github.com/rakyll/goini",
|
|
||||||
"Rev": "907cca0f578a5316fb864ec6992dc3d9730ec58c"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/rcrowley/go-metrics",
|
"ImportPath": "github.com/rcrowley/go-metrics",
|
||||||
"Rev": "a5cfc242a56ba7fa70b785f678d6214837bf93b9"
|
"Rev": "a5cfc242a56ba7fa70b785f678d6214837bf93b9"
|
||||||
|
@ -129,7 +121,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "gopkg.in/karalabe/cookiejar.v2/collections/prque",
|
"ImportPath": "gopkg.in/karalabe/cookiejar.v2/collections/prque",
|
||||||
"Rev": "0b2e270613f5d7ba262a5749b9e32270131497a2"
|
"Rev": "8dcd6a7f4951f6ff3ee9cbb919a06d8925822e57"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/fdtrack"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTPUClient is a client for dealing with HTTPU (HTTP over UDP). Its typical
|
// HTTPUClient is a client for dealing with HTTPU (HTTP over UDP). Its typical
|
||||||
|
@ -25,6 +27,7 @@ func NewHTTPUClient() (*HTTPUClient, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
fdtrack.Open("upnp")
|
||||||
return &HTTPUClient{conn: conn}, nil
|
return &HTTPUClient{conn: conn}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +36,7 @@ func NewHTTPUClient() (*HTTPUClient, error) {
|
||||||
func (httpu *HTTPUClient) Close() error {
|
func (httpu *HTTPUClient) Close() error {
|
||||||
httpu.connLock.Lock()
|
httpu.connLock.Lock()
|
||||||
defer httpu.connLock.Unlock()
|
defer httpu.connLock.Unlock()
|
||||||
|
fdtrack.Close("upnp")
|
||||||
return httpu.conn.Close()
|
return httpu.conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,12 @@ import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/fdtrack"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -26,6 +29,17 @@ type SOAPClient struct {
|
||||||
func NewSOAPClient(endpointURL url.URL) *SOAPClient {
|
func NewSOAPClient(endpointURL url.URL) *SOAPClient {
|
||||||
return &SOAPClient{
|
return &SOAPClient{
|
||||||
EndpointURL: endpointURL,
|
EndpointURL: endpointURL,
|
||||||
|
HTTPClient: http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
Dial: func(network, addr string) (net.Conn, error) {
|
||||||
|
c, err := net.Dial(network, addr)
|
||||||
|
if c != nil {
|
||||||
|
c = fdtrack.WrapConn("upnp", c)
|
||||||
|
}
|
||||||
|
return c, err
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/fdtrack"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Implement the NAT-PMP protocol, typically supported by Apple routers and open source
|
// Implement the NAT-PMP protocol, typically supported by Apple routers and open source
|
||||||
|
@ -102,6 +104,8 @@ func (n *Client) rpc(msg []byte, resultSize int) (result []byte, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
fdtrack.Open("natpmp")
|
||||||
|
defer fdtrack.Close("natpmp")
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
result = make([]byte, resultSize)
|
result = make([]byte, resultSize)
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
language: go
|
|
||||||
go: 1.2
|
|
|
@ -1,144 +0,0 @@
|
||||||
# globalconf
|
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/rakyll/globalconf.png?branch=master)](https://travis-ci.org/rakyll/globalconf)
|
|
||||||
|
|
||||||
Effortlessly persist/retrieve flags of your Golang programs. If you need global configuration instead of requiring user always to set command line flags, you are looking at the right package. `globalconf` allows your users to not only provide flags, but config files and environment variables as well.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
~~~ go
|
|
||||||
import "github.com/rakyll/globalconf"
|
|
||||||
~~~
|
|
||||||
|
|
||||||
### Loading a config file
|
|
||||||
|
|
||||||
By default, globalconf provides you a config file under `~/.config/<yourappname>/config.ini`.
|
|
||||||
|
|
||||||
~~~ go
|
|
||||||
globalconf.New("appname") // loads from ~/.config/<appname>/config.ini
|
|
||||||
~~~
|
|
||||||
|
|
||||||
If you don't prefer the default location you can load from a specified path as well.
|
|
||||||
|
|
||||||
~~~ go
|
|
||||||
globalconf.NewWithOptions(&globalconf.Options{
|
|
||||||
Filename: "/path/to/config/file",
|
|
||||||
})
|
|
||||||
~~~
|
|
||||||
|
|
||||||
You may like to override configuration with env variables. See "Environment variables" header to see how to it works.
|
|
||||||
|
|
||||||
~~~ go
|
|
||||||
globalconf.NewWithOptions(&globalconf.Options{
|
|
||||||
Filename: "/path/to/config/file",
|
|
||||||
EnvPrefix: "APPCONF_",
|
|
||||||
})
|
|
||||||
~~~
|
|
||||||
|
|
||||||
### Parsing flag values
|
|
||||||
|
|
||||||
`globalconf` populates flags with data in the config file if they are not already set.
|
|
||||||
|
|
||||||
~~~ go
|
|
||||||
var (
|
|
||||||
flagName = flag.String("name", "", "Name of the person.")
|
|
||||||
flagAddress = flag.String("addr", "", "Address of the person.")
|
|
||||||
)
|
|
||||||
~~~
|
|
||||||
|
|
||||||
Assume the configuration file to be loaded contains the following lines.
|
|
||||||
|
|
||||||
name = Burcu
|
|
||||||
addr = Brandschenkestrasse 110, 8002
|
|
||||||
|
|
||||||
And your program is being started, `$ myapp -name=Jane`
|
|
||||||
~~~ go
|
|
||||||
conf, err := globalconf.New("myapp")
|
|
||||||
conf.ParseAll()
|
|
||||||
~~~
|
|
||||||
|
|
||||||
`*flagName` is going to be equal to `Jane`, whereas `*flagAddress` is `Brandschenkestrasse 110, 8002`, what is provided in the configuration file.
|
|
||||||
|
|
||||||
### Custom flag sets
|
|
||||||
|
|
||||||
Custom flagsets are supported, but required registration before parse is done. The default flagset `flag.CommandLine` is automatically registered.
|
|
||||||
|
|
||||||
~~~ go
|
|
||||||
globalconf.Register("termopts", termOptsFlagSet)
|
|
||||||
conf.ParseAll() // parses command line and all registered flag sets
|
|
||||||
~~~
|
|
||||||
|
|
||||||
Custom flagset values should be provided in their own segment. Getting back to the sample ini config file, termopts values will have their own segment.
|
|
||||||
|
|
||||||
name = Burcu
|
|
||||||
addr = Brandschenkestrasse 110, 8002
|
|
||||||
|
|
||||||
[termopts]
|
|
||||||
color = true
|
|
||||||
background = ff0000
|
|
||||||
|
|
||||||
### Environment variables
|
|
||||||
|
|
||||||
If an EnvPrefix is provided, environment variables will take precedence over values in the configuration file.
|
|
||||||
Set the `EnvPrefix` option when calling `globalconf.NewWithOptions`.
|
|
||||||
An `EnvPrefix` will only be used if it is a non-empty string.
|
|
||||||
Command line flags will override the environment variables.
|
|
||||||
|
|
||||||
~~~ go
|
|
||||||
opts := globalconf.Options{
|
|
||||||
EnvPrefix: "MYAPP_",
|
|
||||||
Filename: "/path/to/config",
|
|
||||||
}
|
|
||||||
conf, err := globalconf.NewWithOptions(&opts)
|
|
||||||
conf.ParseAll()
|
|
||||||
~~~
|
|
||||||
|
|
||||||
With environment variables:
|
|
||||||
|
|
||||||
APPCONF_NAME = Burcu
|
|
||||||
|
|
||||||
and configuration:
|
|
||||||
|
|
||||||
name = Jane
|
|
||||||
addr = Brandschenkestrasse 110, 8002
|
|
||||||
|
|
||||||
`name` will be set to "burcu" and `addr` will be set to "Brandschenkestrasse 110, 8002".
|
|
||||||
|
|
||||||
### Modifying stored flags
|
|
||||||
|
|
||||||
Modifications are persisted as long as you set a new flag and your GlobalConf
|
|
||||||
object was configured with a filename.
|
|
||||||
|
|
||||||
~~~ go
|
|
||||||
f := &flag.Flag{Name: "name", Value: val}
|
|
||||||
conf.Set("", f) // if you are modifying a command line flag
|
|
||||||
|
|
||||||
f := &flag.Flag{Name: "color", Value: val}
|
|
||||||
conf.Set("termopts", color) // if you are modifying a custom flag set flag
|
|
||||||
~~~
|
|
||||||
|
|
||||||
### Deleting stored flags
|
|
||||||
|
|
||||||
Like Set, Deletions are persisted as long as you delete a flag's value and your
|
|
||||||
GlobalConf object was configured with a filename.
|
|
||||||
|
|
||||||
~~~ go
|
|
||||||
conf.Delete("", "name") // removes command line flag "name"s value from config
|
|
||||||
conf.Delete("termopts", "color") // removes "color"s value from the custom flag set
|
|
||||||
~~~
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
Copyright 2014 Google Inc. All Rights Reserved.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License. ![Analytics](https://ga-beacon.appspot.com/UA-46881978-1/globalconf?pixel)
|
|
|
@ -1,179 +0,0 @@
|
||||||
package globalconf
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"os/user"
|
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
ini "github.com/rakyll/goini"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
defaultConfigFileName = "config.ini"
|
|
||||||
)
|
|
||||||
|
|
||||||
var flags map[string]*flag.FlagSet = make(map[string]*flag.FlagSet)
|
|
||||||
|
|
||||||
// Represents a GlobalConf context.
|
|
||||||
type GlobalConf struct {
|
|
||||||
Filename string
|
|
||||||
EnvPrefix string
|
|
||||||
dict *ini.Dict
|
|
||||||
}
|
|
||||||
|
|
||||||
type Options struct {
|
|
||||||
Filename string
|
|
||||||
EnvPrefix string
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewWithOptions creates a GlobalConf from the provided
|
|
||||||
// Options. The caller is responsible for creating any
|
|
||||||
// referenced config files.
|
|
||||||
func NewWithOptions(opts *Options) (g *GlobalConf, err error) {
|
|
||||||
Register("", flag.CommandLine)
|
|
||||||
|
|
||||||
var dict ini.Dict
|
|
||||||
if opts.Filename != "" {
|
|
||||||
dict, err = ini.Load(opts.Filename)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
dict = make(ini.Dict, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &GlobalConf{
|
|
||||||
Filename: opts.Filename,
|
|
||||||
EnvPrefix: opts.EnvPrefix,
|
|
||||||
dict: &dict,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Opens/creates a config file for the specified appName.
|
|
||||||
// The path to config file is ~/.config/appName/config.ini.
|
|
||||||
func New(appName string) (g *GlobalConf, err error) {
|
|
||||||
var u *user.User
|
|
||||||
if u, err = user.Current(); u == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Create config file's directory.
|
|
||||||
dirPath := path.Join(u.HomeDir, ".config", appName)
|
|
||||||
if err = os.MkdirAll(dirPath, 0755); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Touch a config file if it doesn't exit.
|
|
||||||
filePath := path.Join(dirPath, defaultConfigFileName)
|
|
||||||
if _, err = os.Stat(filePath); err != nil {
|
|
||||||
if !os.IsNotExist(err) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// create file
|
|
||||||
if err = ioutil.WriteFile(filePath, []byte{}, 0644); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
opts := Options{Filename: filePath}
|
|
||||||
return NewWithOptions(&opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sets a flag's value and persists the changes to the disk.
|
|
||||||
func (g *GlobalConf) Set(flagSetName string, f *flag.Flag) error {
|
|
||||||
g.dict.SetString(flagSetName, f.Name, f.Value.String())
|
|
||||||
if g.Filename != "" {
|
|
||||||
return ini.Write(g.Filename, g.dict)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deletes a flag from config file and persists the changes
|
|
||||||
// to the disk.
|
|
||||||
func (g *GlobalConf) Delete(flagSetName, flagName string) error {
|
|
||||||
g.dict.Delete(flagSetName, flagName)
|
|
||||||
if g.Filename != "" {
|
|
||||||
return ini.Write(g.Filename, g.dict)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parses the config file for the provided flag set.
|
|
||||||
// If the flags are already set, values are overwritten
|
|
||||||
// by the values in the config file. Defaults are not set
|
|
||||||
// if the flag is not in the file.
|
|
||||||
func (g *GlobalConf) ParseSet(flagSetName string, set *flag.FlagSet) {
|
|
||||||
set.VisitAll(func(f *flag.Flag) {
|
|
||||||
val := getEnv(g.EnvPrefix, flagSetName, f.Name)
|
|
||||||
if val != "" {
|
|
||||||
set.Set(f.Name, val)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val, found := g.dict.GetString(flagSetName, f.Name)
|
|
||||||
if found {
|
|
||||||
set.Set(f.Name, val)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parses all the registered flag sets, including the command
|
|
||||||
// line set and sets values from the config file if they are
|
|
||||||
// not already set.
|
|
||||||
func (g *GlobalConf) Parse() {
|
|
||||||
for name, set := range flags {
|
|
||||||
alreadySet := make(map[string]bool)
|
|
||||||
set.Visit(func(f *flag.Flag) {
|
|
||||||
alreadySet[f.Name] = true
|
|
||||||
})
|
|
||||||
set.VisitAll(func(f *flag.Flag) {
|
|
||||||
// if not already set, set it from dict if exists
|
|
||||||
if alreadySet[f.Name] {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val := getEnv(g.EnvPrefix, name, f.Name)
|
|
||||||
if val != "" {
|
|
||||||
set.Set(f.Name, val)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val, found := g.dict.GetString(name, f.Name)
|
|
||||||
if found {
|
|
||||||
set.Set(f.Name, val)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parses command line flags and then, all of the registered
|
|
||||||
// flag sets with the values provided in the config file.
|
|
||||||
func (g *GlobalConf) ParseAll() {
|
|
||||||
if !flag.Parsed() {
|
|
||||||
flag.Parse()
|
|
||||||
}
|
|
||||||
g.Parse()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Looks up variable in environment
|
|
||||||
func getEnv(envPrefix, flagSetName, flagName string) string {
|
|
||||||
// If we haven't set an EnvPrefix, don't lookup vals in the ENV
|
|
||||||
if envPrefix == "" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
// Append a _ to flagSetName if it exists.
|
|
||||||
if flagSetName != "" {
|
|
||||||
flagSetName += "_"
|
|
||||||
}
|
|
||||||
flagName = strings.Replace(flagName, ".", "_", -1)
|
|
||||||
flagName = strings.Replace(flagName, "-", "_", -1)
|
|
||||||
envKey := strings.ToUpper(envPrefix + flagSetName + flagName)
|
|
||||||
return os.Getenv(envKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Registers a flag set to be parsed. Register all flag sets
|
|
||||||
// before calling this function. flag.CommandLine is automatically
|
|
||||||
// registered.
|
|
||||||
func Register(flagSetName string, set *flag.FlagSet) {
|
|
||||||
flags[flagSetName] = set
|
|
||||||
}
|
|
|
@ -1,267 +0,0 @@
|
||||||
package globalconf
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
const envTestPrefix = "CONFTEST_"
|
|
||||||
|
|
||||||
func TestNewWithOptionsNoFilename(t *testing.T) {
|
|
||||||
opts := Options{EnvPrefix: envTestPrefix}
|
|
||||||
|
|
||||||
os.Setenv(envTestPrefix+"D", "EnvD")
|
|
||||||
|
|
||||||
flagD := flag.String("d", "default", "")
|
|
||||||
flagE := flag.Bool("e", true, "")
|
|
||||||
|
|
||||||
conf, err := NewWithOptions(&opts)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
conf.ParseAll()
|
|
||||||
|
|
||||||
if *flagD != "EnvD" {
|
|
||||||
t.Errorf("flagD found %v, expected 'EnvD'", *flagD)
|
|
||||||
}
|
|
||||||
if !*flagE {
|
|
||||||
t.Errorf("flagE found %v, expected true", *flagE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParse_Global(t *testing.T) {
|
|
||||||
resetForTesting("")
|
|
||||||
|
|
||||||
os.Setenv(envTestPrefix+"D", "EnvD")
|
|
||||||
os.Setenv(envTestPrefix+"E", "true")
|
|
||||||
os.Setenv(envTestPrefix+"F", "5.5")
|
|
||||||
|
|
||||||
flagA := flag.Bool("a", false, "")
|
|
||||||
flagB := flag.Float64("b", 0.0, "")
|
|
||||||
flagC := flag.String("c", "", "")
|
|
||||||
|
|
||||||
flagD := flag.String("d", "", "")
|
|
||||||
flagE := flag.Bool("e", false, "")
|
|
||||||
flagF := flag.Float64("f", 0.0, "")
|
|
||||||
|
|
||||||
parse(t, "./testdata/global.ini", envTestPrefix)
|
|
||||||
if !*flagA {
|
|
||||||
t.Errorf("flagA found %v, expected true", *flagA)
|
|
||||||
}
|
|
||||||
if *flagB != 5.6 {
|
|
||||||
t.Errorf("flagB found %v, expected 5.6", *flagB)
|
|
||||||
}
|
|
||||||
if *flagC != "Hello world" {
|
|
||||||
t.Errorf("flagC found %v, expected 'Hello world'", *flagC)
|
|
||||||
}
|
|
||||||
if *flagD != "EnvD" {
|
|
||||||
t.Errorf("flagD found %v, expected 'EnvD'", *flagD)
|
|
||||||
}
|
|
||||||
if !*flagE {
|
|
||||||
t.Errorf("flagE found %v, expected true", *flagE)
|
|
||||||
}
|
|
||||||
if *flagF != 5.5 {
|
|
||||||
t.Errorf("flagF found %v, expected 5.5", *flagF)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParse_DashConversion(t *testing.T) {
|
|
||||||
resetForTesting("")
|
|
||||||
|
|
||||||
flagFooBar := flag.String("foo-bar", "", "")
|
|
||||||
os.Setenv("PREFIX_FOO_BAR", "baz")
|
|
||||||
|
|
||||||
opts := Options{EnvPrefix: "PREFIX_"}
|
|
||||||
conf, err := NewWithOptions(&opts)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
conf.ParseAll()
|
|
||||||
|
|
||||||
if *flagFooBar != "baz" {
|
|
||||||
t.Errorf("flagFooBar found %v, expected 5.5", *flagFooBar)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParse_GlobalWithDottedFlagname(t *testing.T) {
|
|
||||||
resetForTesting("")
|
|
||||||
os.Setenv(envTestPrefix+"SOME_VALUE", "some-value")
|
|
||||||
flagSomeValue := flag.String("some.value", "", "")
|
|
||||||
|
|
||||||
parse(t, "./testdata/global.ini", envTestPrefix)
|
|
||||||
if *flagSomeValue != "some-value" {
|
|
||||||
t.Errorf("flagSomeValue found %v, some-value expected", *flagSomeValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParse_GlobalOverwrite(t *testing.T) {
|
|
||||||
resetForTesting("-b=7.6")
|
|
||||||
flagB := flag.Float64("b", 0.0, "")
|
|
||||||
|
|
||||||
parse(t, "./testdata/global.ini", "")
|
|
||||||
if *flagB != 7.6 {
|
|
||||||
t.Errorf("flagB found %v, expected 7.6", *flagB)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParse_Custom(t *testing.T) {
|
|
||||||
resetForTesting("")
|
|
||||||
|
|
||||||
os.Setenv(envTestPrefix+"CUSTOM_E", "Hello Env")
|
|
||||||
|
|
||||||
flagB := flag.Float64("b", 5.0, "")
|
|
||||||
|
|
||||||
name := "custom"
|
|
||||||
custom := flag.NewFlagSet(name, flag.ExitOnError)
|
|
||||||
flagD := custom.String("d", "dd", "")
|
|
||||||
flagE := custom.String("e", "ee", "")
|
|
||||||
|
|
||||||
Register(name, custom)
|
|
||||||
parse(t, "./testdata/custom.ini", envTestPrefix)
|
|
||||||
if *flagB != 5.0 {
|
|
||||||
t.Errorf("flagB found %v, expected 5.0", *flagB)
|
|
||||||
}
|
|
||||||
if *flagD != "Hello d" {
|
|
||||||
t.Errorf("flagD found %v, expected 'Hello d'", *flagD)
|
|
||||||
}
|
|
||||||
if *flagE != "Hello Env" {
|
|
||||||
t.Errorf("flagE found %v, expected 'Hello Env'", *flagE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParse_CustomOverwrite(t *testing.T) {
|
|
||||||
resetForTesting("-b=6")
|
|
||||||
flagB := flag.Float64("b", 5.0, "")
|
|
||||||
|
|
||||||
name := "custom"
|
|
||||||
custom := flag.NewFlagSet(name, flag.ExitOnError)
|
|
||||||
flagD := custom.String("d", "dd", "")
|
|
||||||
|
|
||||||
Register(name, custom)
|
|
||||||
parse(t, "./testdata/custom.ini", "")
|
|
||||||
if *flagB != 6.0 {
|
|
||||||
t.Errorf("flagB found %v, expected 6.0", *flagB)
|
|
||||||
}
|
|
||||||
if *flagD != "Hello d" {
|
|
||||||
t.Errorf("flagD found %v, expected 'Hello d'", *flagD)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParse_GlobalAndCustom(t *testing.T) {
|
|
||||||
resetForTesting("")
|
|
||||||
flagA := flag.Bool("a", false, "")
|
|
||||||
flagB := flag.Float64("b", 0.0, "")
|
|
||||||
flagC := flag.String("c", "", "")
|
|
||||||
|
|
||||||
name := "custom"
|
|
||||||
custom := flag.NewFlagSet(name, flag.ExitOnError)
|
|
||||||
flagD := custom.String("d", "", "")
|
|
||||||
|
|
||||||
Register(name, custom)
|
|
||||||
parse(t, "./testdata/globalandcustom.ini", "")
|
|
||||||
if !*flagA {
|
|
||||||
t.Errorf("flagA found %v, expected true", *flagA)
|
|
||||||
}
|
|
||||||
if *flagB != 5.6 {
|
|
||||||
t.Errorf("flagB found %v, expected 5.6", *flagB)
|
|
||||||
}
|
|
||||||
if *flagC != "Hello world" {
|
|
||||||
t.Errorf("flagC found %v, expected 'Hello world'", *flagC)
|
|
||||||
}
|
|
||||||
if *flagD != "Hello d" {
|
|
||||||
t.Errorf("flagD found %v, expected 'Hello d'", *flagD)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParse_GlobalAndCustomOverwrite(t *testing.T) {
|
|
||||||
resetForTesting("-a=true", "-b=5", "-c=Hello")
|
|
||||||
flagA := flag.Bool("a", false, "")
|
|
||||||
flagB := flag.Float64("b", 0.0, "")
|
|
||||||
flagC := flag.String("c", "", "")
|
|
||||||
|
|
||||||
name := "custom"
|
|
||||||
custom := flag.NewFlagSet(name, flag.ExitOnError)
|
|
||||||
flagD := custom.String("d", "", "")
|
|
||||||
|
|
||||||
Register(name, custom)
|
|
||||||
parse(t, "./testdata/globalandcustom.ini", "")
|
|
||||||
if !*flagA {
|
|
||||||
t.Errorf("flagA found %v, expected true", *flagA)
|
|
||||||
}
|
|
||||||
if *flagB != 5.0 {
|
|
||||||
t.Errorf("flagB found %v, expected 5.0", *flagB)
|
|
||||||
}
|
|
||||||
if *flagC != "Hello" {
|
|
||||||
t.Errorf("flagC found %v, expected 'Hello'", *flagC)
|
|
||||||
}
|
|
||||||
if *flagD != "Hello d" {
|
|
||||||
t.Errorf("flagD found %v, expected 'Hello d'", *flagD)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSet(t *testing.T) {
|
|
||||||
resetForTesting()
|
|
||||||
file, _ := ioutil.TempFile("", "")
|
|
||||||
conf := parse(t, file.Name(), "")
|
|
||||||
conf.Set("", &flag.Flag{Name: "a", Value: newFlagValue("test")})
|
|
||||||
|
|
||||||
flagA := flag.String("a", "", "")
|
|
||||||
parse(t, file.Name(), "")
|
|
||||||
if *flagA != "test" {
|
|
||||||
t.Errorf("flagA found %v, expected 'test'", *flagA)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDelete(t *testing.T) {
|
|
||||||
resetForTesting()
|
|
||||||
file, _ := ioutil.TempFile("", "")
|
|
||||||
conf := parse(t, file.Name(), "")
|
|
||||||
conf.Set("", &flag.Flag{Name: "a", Value: newFlagValue("test")})
|
|
||||||
conf.Delete("", "a")
|
|
||||||
|
|
||||||
flagA := flag.String("a", "", "")
|
|
||||||
parse(t, file.Name(), "")
|
|
||||||
if *flagA != "" {
|
|
||||||
t.Errorf("flagNewA found %v, expected ''", *flagA)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func parse(t *testing.T, filename, envPrefix string) *GlobalConf {
|
|
||||||
opts := Options{
|
|
||||||
Filename: filename,
|
|
||||||
EnvPrefix: envPrefix,
|
|
||||||
}
|
|
||||||
conf, err := NewWithOptions(&opts)
|
|
||||||
if err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
conf.ParseAll()
|
|
||||||
return conf
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resets os.Args and the default flag set.
|
|
||||||
func resetForTesting(args ...string) {
|
|
||||||
os.Clearenv()
|
|
||||||
|
|
||||||
os.Args = append([]string{"cmd"}, args...)
|
|
||||||
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
|
||||||
}
|
|
||||||
|
|
||||||
type flagValue struct {
|
|
||||||
str string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *flagValue) String() string {
|
|
||||||
return f.str
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *flagValue) Set(value string) error {
|
|
||||||
f.str = value
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func newFlagValue(val string) *flagValue {
|
|
||||||
return &flagValue{str: val}
|
|
||||||
}
|
|
|
@ -1,2 +0,0 @@
|
||||||
[custom]
|
|
||||||
d = Hello d
|
|
|
@ -1,3 +0,0 @@
|
||||||
a = true
|
|
||||||
b = 5.6
|
|
||||||
c = Hello world
|
|
6
Godeps/_workspace/src/github.com/rakyll/globalconf/testdata/globalandcustom.ini
generated
vendored
6
Godeps/_workspace/src/github.com/rakyll/globalconf/testdata/globalandcustom.ini
generated
vendored
|
@ -1,6 +0,0 @@
|
||||||
a = true
|
|
||||||
b = 5.6
|
|
||||||
c = Hello world
|
|
||||||
|
|
||||||
[custom]
|
|
||||||
d = Hello d
|
|
|
@ -1,8 +0,0 @@
|
||||||
.*.swp
|
|
||||||
|
|
||||||
*.[689]
|
|
||||||
[689].out
|
|
||||||
|
|
||||||
_obj
|
|
||||||
_test
|
|
||||||
_testmain.go
|
|
|
@ -1,7 +0,0 @@
|
||||||
test:
|
|
||||||
go test
|
|
||||||
|
|
||||||
format:
|
|
||||||
gofmt -w *.go
|
|
||||||
|
|
||||||
.PHONY: format test
|
|
|
@ -1,18 +0,0 @@
|
||||||
#
|
|
||||||
# This is an example of ini file
|
|
||||||
#
|
|
||||||
|
|
||||||
[Pizza]
|
|
||||||
|
|
||||||
Ham = yes;
|
|
||||||
Mushrooms = TRUE;
|
|
||||||
Capres = 0;
|
|
||||||
Cheese = Non;
|
|
||||||
|
|
||||||
|
|
||||||
[Wine]
|
|
||||||
|
|
||||||
Grape = Cabernet Sauvignon;
|
|
||||||
Year = 1989;
|
|
||||||
Country = Spain;
|
|
||||||
Alcohol = 12.5;
|
|
|
@ -1,241 +0,0 @@
|
||||||
package ini
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"unicode"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Dict map[string]map[string]string
|
|
||||||
|
|
||||||
type Error string
|
|
||||||
|
|
||||||
var (
|
|
||||||
regDoubleQuote = regexp.MustCompile("^([^= \t]+)[ \t]*=[ \t]*\"([^\"]*)\"$")
|
|
||||||
regSingleQuote = regexp.MustCompile("^([^= \t]+)[ \t]*=[ \t]*'([^']*)'$")
|
|
||||||
regNoQuote = regexp.MustCompile("^([^= \t]+)[ \t]*=[ \t]*([^#;]+)")
|
|
||||||
regNoValue = regexp.MustCompile("^([^= \t]+)[ \t]*=[ \t]*([#;].*)?")
|
|
||||||
)
|
|
||||||
|
|
||||||
func Load(filename string) (dict Dict, err error) {
|
|
||||||
file, err := os.Open(filename)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
dict = make(map[string]map[string]string)
|
|
||||||
reader := bufio.NewReader(file)
|
|
||||||
lineno := 0
|
|
||||||
section := ""
|
|
||||||
dict[section] = make(map[string]string)
|
|
||||||
|
|
||||||
for err == nil {
|
|
||||||
l, _, err := reader.ReadLine()
|
|
||||||
if err != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
lineno++
|
|
||||||
if len(l) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
line := strings.TrimFunc(string(l), unicode.IsSpace)
|
|
||||||
|
|
||||||
for line[len(line)-1] == '\\' {
|
|
||||||
line = line[:len(line)-1]
|
|
||||||
l, _, err := reader.ReadLine()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
line += strings.TrimFunc(string(l), unicode.IsSpace)
|
|
||||||
}
|
|
||||||
|
|
||||||
section, err = dict.parseLine(section, line)
|
|
||||||
if err != nil {
|
|
||||||
return nil, newError(
|
|
||||||
err.Error() + fmt.Sprintf("'%s:%d'.", filename, lineno))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func Write(filename string, dict *Dict) error {
|
|
||||||
buffer := dict.format()
|
|
||||||
return ioutil.WriteFile(filename, buffer.Bytes(), 0644)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e Error) Error() string {
|
|
||||||
return string(e)
|
|
||||||
}
|
|
||||||
func (dict Dict) parseLine(section, line string) (string, error) {
|
|
||||||
// commets
|
|
||||||
if line[0] == '#' || line[0] == ';' {
|
|
||||||
return section, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// section name
|
|
||||||
if line[0] == '[' && line[len(line)-1] == ']' {
|
|
||||||
section := strings.TrimFunc(line[1:len(line)-1], unicode.IsSpace)
|
|
||||||
section = strings.ToLower(section)
|
|
||||||
dict[section] = make(map[string]string)
|
|
||||||
return section, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// key = value
|
|
||||||
if m := regDoubleQuote.FindAllStringSubmatch(line, 1); m != nil {
|
|
||||||
dict.add(section, m[0][1], m[0][2])
|
|
||||||
return section, nil
|
|
||||||
} else if m = regSingleQuote.FindAllStringSubmatch(line, 1); m != nil {
|
|
||||||
dict.add(section, m[0][1], m[0][2])
|
|
||||||
return section, nil
|
|
||||||
} else if m = regNoQuote.FindAllStringSubmatch(line, 1); m != nil {
|
|
||||||
dict.add(section, m[0][1], strings.TrimFunc(m[0][2], unicode.IsSpace))
|
|
||||||
return section, nil
|
|
||||||
} else if m = regNoValue.FindAllStringSubmatch(line, 1); m != nil {
|
|
||||||
dict.add(section, m[0][1], "")
|
|
||||||
return section, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return section, newError("iniparser: syntax error at ")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dict Dict) add(section, key, value string) {
|
|
||||||
key = strings.ToLower(key)
|
|
||||||
dict[section][key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dict Dict) GetBool(section, key string) (bool, bool) {
|
|
||||||
sec, ok := dict[section]
|
|
||||||
if !ok {
|
|
||||||
return false, false
|
|
||||||
}
|
|
||||||
value, ok := sec[key]
|
|
||||||
if !ok {
|
|
||||||
return false, false
|
|
||||||
}
|
|
||||||
v := value[0]
|
|
||||||
if v == 'y' || v == 'Y' || v == '1' || v == 't' || v == 'T' {
|
|
||||||
return true, true
|
|
||||||
}
|
|
||||||
if v == 'n' || v == 'N' || v == '0' || v == 'f' || v == 'F' {
|
|
||||||
return false, true
|
|
||||||
}
|
|
||||||
return false, false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dict Dict) SetBool(section, key string, value bool) {
|
|
||||||
dict.SetString(section, key, strconv.FormatBool(value))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dict Dict) GetString(section, key string) (string, bool) {
|
|
||||||
sec, ok := dict[section]
|
|
||||||
if !ok {
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
value, ok := sec[key]
|
|
||||||
if !ok {
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
return value, true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dict Dict) SetString(section, key, value string) {
|
|
||||||
_, ok := dict[section]
|
|
||||||
if !ok {
|
|
||||||
dict[section] = make(map[string]string)
|
|
||||||
}
|
|
||||||
dict[section][key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dict Dict) GetInt(section, key string) (int, bool) {
|
|
||||||
sec, ok := dict[section]
|
|
||||||
if !ok {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
value, ok := sec[key]
|
|
||||||
if !ok {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
i, err := strconv.Atoi(value)
|
|
||||||
if err != nil {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
return i, true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dict Dict) SetInt(section, key string, value int) {
|
|
||||||
dict.SetString(section, key, strconv.FormatInt(int64(value), 10))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dict Dict) GetDouble(section, key string) (float64, bool) {
|
|
||||||
sec, ok := dict[section]
|
|
||||||
if !ok {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
value, ok := sec[key]
|
|
||||||
if !ok {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
d, err := strconv.ParseFloat(value, 64)
|
|
||||||
if err != nil {
|
|
||||||
return 0, false
|
|
||||||
}
|
|
||||||
return d, true
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dict Dict) SetDouble(section, key string, value float64) {
|
|
||||||
dict.SetString(section, key, strconv.FormatFloat(value, 'f', -1, 64))
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dict Dict) Delete(section, key string) {
|
|
||||||
_, ok := dict[section]
|
|
||||||
if !ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
delete(dict[section], key)
|
|
||||||
// If there are no items left in the section,
|
|
||||||
// delete the section.
|
|
||||||
if len(dict[section]) == 0 {
|
|
||||||
delete(dict, section)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dict Dict) GetSections() []string {
|
|
||||||
size := len(dict)
|
|
||||||
sections := make([]string, size)
|
|
||||||
i := 0
|
|
||||||
for section, _ := range dict {
|
|
||||||
sections[i] = section
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
return sections
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dict Dict) String() string {
|
|
||||||
return (*dict.format()).String()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dict Dict) format() *bytes.Buffer {
|
|
||||||
var buffer bytes.Buffer
|
|
||||||
for section, vals := range dict {
|
|
||||||
if section != "" {
|
|
||||||
buffer.WriteString(fmt.Sprintf("[%s]\n", section))
|
|
||||||
}
|
|
||||||
for key, val := range vals {
|
|
||||||
buffer.WriteString(fmt.Sprintf("%s = %s\n", key, val))
|
|
||||||
}
|
|
||||||
buffer.WriteString("\n")
|
|
||||||
}
|
|
||||||
return &buffer
|
|
||||||
}
|
|
||||||
|
|
||||||
func newError(message string) (e error) {
|
|
||||||
return Error(message)
|
|
||||||
}
|
|
|
@ -1,169 +0,0 @@
|
||||||
package ini
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io/ioutil"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
exampleStr = `key1 = true
|
|
||||||
|
|
||||||
[section1]
|
|
||||||
key1 = value2
|
|
||||||
key2 = 5
|
|
||||||
key3 = 1.3
|
|
||||||
|
|
||||||
[section2]
|
|
||||||
key1 = 5
|
|
||||||
|
|
||||||
`
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
dict Dict
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
dict, err = Load("example.ini")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoad(t *testing.T) {
|
|
||||||
if err != nil {
|
|
||||||
t.Error("Example: load error:", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestWrite(t *testing.T) {
|
|
||||||
d, err := Load("empty.ini")
|
|
||||||
if err != nil {
|
|
||||||
t.Error("Example: load error:", err)
|
|
||||||
}
|
|
||||||
d.SetString("", "key", "value")
|
|
||||||
tempFile, err := ioutil.TempFile("", "")
|
|
||||||
if err != nil {
|
|
||||||
t.Error("Write: Couldn't create temp file.", err)
|
|
||||||
}
|
|
||||||
err = Write(tempFile.Name(), &d)
|
|
||||||
if err != nil {
|
|
||||||
t.Error("Write: Couldn't write to temp config file.", err)
|
|
||||||
}
|
|
||||||
contents, err := ioutil.ReadFile(tempFile.Name())
|
|
||||||
if err != nil {
|
|
||||||
t.Error("Write: Couldn't read from the temp config file.", err)
|
|
||||||
}
|
|
||||||
if string(contents) != "key = value\n\n" {
|
|
||||||
t.Error("Write: Contents of the config file doesn't match the expected.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetBool(t *testing.T) {
|
|
||||||
b, found := dict.GetBool("pizza", "ham")
|
|
||||||
if !found || !b {
|
|
||||||
t.Error("Example: parse error for key ham of section pizza.")
|
|
||||||
}
|
|
||||||
b, found = dict.GetBool("pizza", "mushrooms")
|
|
||||||
if !found || !b {
|
|
||||||
t.Error("Example: parse error for key mushrooms of section pizza.")
|
|
||||||
}
|
|
||||||
b, found = dict.GetBool("pizza", "capres")
|
|
||||||
if !found || b {
|
|
||||||
t.Error("Example: parse error for key capres of section pizza.")
|
|
||||||
}
|
|
||||||
b, found = dict.GetBool("pizza", "cheese")
|
|
||||||
if !found || b {
|
|
||||||
t.Error("Example: parse error for key cheese of section pizza.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetStringIntAndDouble(t *testing.T) {
|
|
||||||
str, found := dict.GetString("wine", "grape")
|
|
||||||
if !found || str != "Cabernet Sauvignon" {
|
|
||||||
t.Error("Example: parse error for key grape of section wine.")
|
|
||||||
}
|
|
||||||
i, found := dict.GetInt("wine", "year")
|
|
||||||
if !found || i != 1989 {
|
|
||||||
t.Error("Example: parse error for key year of section wine.")
|
|
||||||
}
|
|
||||||
str, found = dict.GetString("wine", "country")
|
|
||||||
if !found || str != "Spain" {
|
|
||||||
t.Error("Example: parse error for key grape of section wine.")
|
|
||||||
}
|
|
||||||
d, found := dict.GetDouble("wine", "alcohol")
|
|
||||||
if !found || d != 12.5 {
|
|
||||||
t.Error("Example: parse error for key grape of section wine.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSetBoolAndStringAndIntAndDouble(t *testing.T) {
|
|
||||||
dict.SetBool("pizza", "ham", false)
|
|
||||||
b, found := dict.GetBool("pizza", "ham")
|
|
||||||
if !found || b {
|
|
||||||
t.Error("Example: bool set error for key ham of section pizza.")
|
|
||||||
}
|
|
||||||
dict.SetString("pizza", "ham", "no")
|
|
||||||
n, found := dict.GetString("pizza", "ham")
|
|
||||||
if !found || n != "no" {
|
|
||||||
t.Error("Example: string set error for key ham of section pizza.")
|
|
||||||
}
|
|
||||||
dict.SetInt("wine", "year", 1978)
|
|
||||||
i, found := dict.GetInt("wine", "year")
|
|
||||||
if !found || i != 1978 {
|
|
||||||
t.Error("Example: int set error for key year of section wine.")
|
|
||||||
}
|
|
||||||
dict.SetDouble("wine", "not-exists", 5.6)
|
|
||||||
d, found := dict.GetDouble("wine", "not-exists")
|
|
||||||
if !found || d != 5.6 {
|
|
||||||
t.Error("Example: float set error for not existing key for wine.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDelete(t *testing.T) {
|
|
||||||
d, err := Load("empty.ini")
|
|
||||||
if err != nil {
|
|
||||||
t.Error("Example: load error:", err)
|
|
||||||
}
|
|
||||||
d.SetString("pizza", "ham", "yes")
|
|
||||||
d.Delete("pizza", "ham")
|
|
||||||
_, found := d.GetString("pizza", "ham")
|
|
||||||
if found {
|
|
||||||
t.Error("Example: delete error for key ham of section pizza.")
|
|
||||||
}
|
|
||||||
if len(d.GetSections()) > 1 {
|
|
||||||
t.Error("Only a single section should exist after deletion.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetNotExist(t *testing.T) {
|
|
||||||
_, found := dict.GetString("not", "exist")
|
|
||||||
if found {
|
|
||||||
t.Error("There is no key exist of section not.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetSections(t *testing.T) {
|
|
||||||
sections := dict.GetSections()
|
|
||||||
if len(sections) != 3 {
|
|
||||||
t.Error("The number of sections is wrong:", len(sections))
|
|
||||||
}
|
|
||||||
for _, section := range sections {
|
|
||||||
if section != "" && section != "pizza" && section != "wine" {
|
|
||||||
t.Errorf("Section '%s' should not be exist.", section)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestString(t *testing.T) {
|
|
||||||
d, err := Load("empty.ini")
|
|
||||||
if err != nil {
|
|
||||||
t.Error("Example: load error:", err)
|
|
||||||
}
|
|
||||||
d.SetBool("", "key1", true)
|
|
||||||
d.SetString("section1", "key1", "value2")
|
|
||||||
d.SetInt("section1", "key2", 5)
|
|
||||||
d.SetDouble("section1", "key3", 1.3)
|
|
||||||
d.SetDouble("section2", "key1", 5.0)
|
|
||||||
if d.String() != exampleStr {
|
|
||||||
t.Errorf("Dict cannot be stringified as expected.")
|
|
||||||
}
|
|
||||||
}
|
|
5
Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/file_storage.go
generated
vendored
5
Godeps/_workspace/src/github.com/syndtr/goleveldb/leveldb/storage/file_storage.go
generated
vendored
|
@ -18,6 +18,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/fdtrack"
|
||||||
"github.com/syndtr/goleveldb/leveldb/util"
|
"github.com/syndtr/goleveldb/leveldb/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -369,6 +370,8 @@ func (fw fileWrap) Close() error {
|
||||||
err := fw.File.Close()
|
err := fw.File.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.fs.log(fmt.Sprintf("close %s.%d: %v", f.Type(), f.Num(), err))
|
f.fs.log(fmt.Sprintf("close %s.%d: %v", f.Type(), f.Num(), err))
|
||||||
|
} else {
|
||||||
|
fdtrack.Close("leveldb")
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -400,6 +403,7 @@ func (f *file) Open() (Reader, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ok:
|
ok:
|
||||||
|
fdtrack.Open("leveldb")
|
||||||
f.open = true
|
f.open = true
|
||||||
f.fs.open++
|
f.fs.open++
|
||||||
return fileWrap{of, f}, nil
|
return fileWrap{of, f}, nil
|
||||||
|
@ -418,6 +422,7 @@ func (f *file) Create() (Writer, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
fdtrack.Open("leveldb")
|
||||||
f.open = true
|
f.open = true
|
||||||
f.fs.open++
|
f.fs.open++
|
||||||
return fileWrap{of, f}, nil
|
return fileWrap{of, f}, nil
|
||||||
|
|
17
Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/prque.go
generated
vendored
17
Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/prque.go
generated
vendored
|
@ -1,19 +1,10 @@
|
||||||
// CookieJar - A contestant's algorithm toolbox
|
// CookieJar - A contestant's algorithm toolbox
|
||||||
// Copyright (c) 2013 Peter Szilagyi. All rights reserved.
|
// Copyright (c) 2013 Peter Szilagyi. All rights reserved.
|
||||||
//
|
//
|
||||||
// CookieJar is dual licensed: you can redistribute it and/or modify it under
|
// CookieJar is dual licensed: use of this source code is governed by a BSD
|
||||||
// the terms of the GNU General Public License as published by the Free Software
|
// license that can be found in the LICENSE file. Alternatively, the CookieJar
|
||||||
// Foundation, either version 3 of the License, or (at your option) any later
|
// toolbox may be used in accordance with the terms and conditions contained
|
||||||
// version.
|
// in a signed written agreement between you and the author(s).
|
||||||
//
|
|
||||||
// The toolbox 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.
|
|
||||||
//
|
|
||||||
// Alternatively, the CookieJar toolbox may be used in accordance with the terms
|
|
||||||
// and conditions contained in a signed written agreement between you and the
|
|
||||||
// author(s).
|
|
||||||
|
|
||||||
// Package prque implements a priority queue data structure supporting arbitrary
|
// Package prque implements a priority queue data structure supporting arbitrary
|
||||||
// value types and float priorities.
|
// value types and float priorities.
|
||||||
|
|
17
Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/prque_test.go
generated
vendored
17
Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/prque_test.go
generated
vendored
|
@ -1,19 +1,10 @@
|
||||||
// CookieJar - A contestant's algorithm toolbox
|
// CookieJar - A contestant's algorithm toolbox
|
||||||
// Copyright (c) 2013 Peter Szilagyi. All rights reserved.
|
// Copyright (c) 2013 Peter Szilagyi. All rights reserved.
|
||||||
//
|
//
|
||||||
// CookieJar is dual licensed: you can redistribute it and/or modify it under
|
// CookieJar is dual licensed: use of this source code is governed by a BSD
|
||||||
// the terms of the GNU General Public License as published by the Free Software
|
// license that can be found in the LICENSE file. Alternatively, the CookieJar
|
||||||
// Foundation, either version 3 of the License, or (at your option) any later
|
// toolbox may be used in accordance with the terms and conditions contained
|
||||||
// version.
|
// in a signed written agreement between you and the author(s).
|
||||||
//
|
|
||||||
// The toolbox 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.
|
|
||||||
//
|
|
||||||
// Alternatively, the CookieJar toolbox may be used in accordance with the terms
|
|
||||||
// and conditions contained in a signed written agreement between you and the
|
|
||||||
// author(s).
|
|
||||||
|
|
||||||
package prque
|
package prque
|
||||||
|
|
||||||
|
|
17
Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/sstack.go
generated
vendored
17
Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/sstack.go
generated
vendored
|
@ -1,19 +1,10 @@
|
||||||
// CookieJar - A contestant's algorithm toolbox
|
// CookieJar - A contestant's algorithm toolbox
|
||||||
// Copyright (c) 2013 Peter Szilagyi. All rights reserved.
|
// Copyright (c) 2013 Peter Szilagyi. All rights reserved.
|
||||||
//
|
//
|
||||||
// CookieJar is dual licensed: you can redistribute it and/or modify it under
|
// CookieJar is dual licensed: use of this source code is governed by a BSD
|
||||||
// the terms of the GNU General Public License as published by the Free Software
|
// license that can be found in the LICENSE file. Alternatively, the CookieJar
|
||||||
// Foundation, either version 3 of the License, or (at your option) any later
|
// toolbox may be used in accordance with the terms and conditions contained
|
||||||
// version.
|
// in a signed written agreement between you and the author(s).
|
||||||
//
|
|
||||||
// The toolbox 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.
|
|
||||||
//
|
|
||||||
// Alternatively, the CookieJar toolbox may be used in accordance with the terms
|
|
||||||
// and conditions contained in a signed written agreement between you and the
|
|
||||||
// author(s).
|
|
||||||
|
|
||||||
package prque
|
package prque
|
||||||
|
|
||||||
|
|
17
Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/sstack_test.go
generated
vendored
17
Godeps/_workspace/src/gopkg.in/karalabe/cookiejar.v2/collections/prque/sstack_test.go
generated
vendored
|
@ -1,19 +1,10 @@
|
||||||
// CookieJar - A contestant's algorithm toolbox
|
// CookieJar - A contestant's algorithm toolbox
|
||||||
// Copyright (c) 2013 Peter Szilagyi. All rights reserved.
|
// Copyright (c) 2013 Peter Szilagyi. All rights reserved.
|
||||||
//
|
//
|
||||||
// CookieJar is dual licensed: you can redistribute it and/or modify it under
|
// CookieJar is dual licensed: use of this source code is governed by a BSD
|
||||||
// the terms of the GNU General Public License as published by the Free Software
|
// license that can be found in the LICENSE file. Alternatively, the CookieJar
|
||||||
// Foundation, either version 3 of the License, or (at your option) any later
|
// toolbox may be used in accordance with the terms and conditions contained
|
||||||
// version.
|
// in a signed written agreement between you and the author(s).
|
||||||
//
|
|
||||||
// The toolbox 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.
|
|
||||||
//
|
|
||||||
// Alternatively, the CookieJar toolbox may be used in accordance with the terms
|
|
||||||
// and conditions contained in a signed written agreement between you and the
|
|
||||||
// author(s).
|
|
||||||
|
|
||||||
package prque
|
package prque
|
||||||
|
|
||||||
|
|
16
LICENSE
16
LICENSE
|
@ -1,16 +0,0 @@
|
||||||
Copyright (c) 2013-2015, The go-ethereum Authors. All rights reserved.
|
|
||||||
|
|
||||||
This library is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU Lesser General Public
|
|
||||||
License as published by the Free Software Foundation; either
|
|
||||||
version 2.1 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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
|
|
||||||
Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public
|
|
||||||
License along with this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
MA 02110-1301 USA
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package abi
|
package abi
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package abi
|
package abi
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// Package abi implements the Ethereum ABI (Application Binary
|
// Package abi implements the Ethereum ABI (Application Binary
|
||||||
// Interface).
|
// Interface).
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package abi
|
package abi
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package abi
|
package abi
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package abi
|
package abi
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// Package implements a private key management facility.
|
// Package implements a private key management facility.
|
||||||
//
|
//
|
||||||
|
@ -78,8 +78,8 @@ func (am *Manager) DeleteAccount(address common.Address, auth string) error {
|
||||||
|
|
||||||
func (am *Manager) Sign(a Account, toSign []byte) (signature []byte, err error) {
|
func (am *Manager) Sign(a Account, toSign []byte) (signature []byte, err error) {
|
||||||
am.mutex.RLock()
|
am.mutex.RLock()
|
||||||
|
defer am.mutex.RUnlock()
|
||||||
unlockedKey, found := am.unlocked[a.Address]
|
unlockedKey, found := am.unlocked[a.Address]
|
||||||
am.mutex.RUnlock()
|
|
||||||
if !found {
|
if !found {
|
||||||
return nil, ErrLocked
|
return nil, ErrLocked
|
||||||
}
|
}
|
||||||
|
@ -87,14 +87,17 @@ func (am *Manager) Sign(a Account, toSign []byte) (signature []byte, err error)
|
||||||
return signature, err
|
return signature, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// unlock indefinitely
|
// Unlock unlocks the given account indefinitely.
|
||||||
func (am *Manager) Unlock(addr common.Address, keyAuth string) error {
|
func (am *Manager) Unlock(addr common.Address, keyAuth string) error {
|
||||||
return am.TimedUnlock(addr, keyAuth, 0)
|
return am.TimedUnlock(addr, keyAuth, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unlock unlocks the account with the given address. The account
|
// TimedUnlock unlocks the account with the given address. The account
|
||||||
// stays unlocked for the duration of timeout
|
// stays unlocked for the duration of timeout. A timeout of 0 unlocks the account
|
||||||
// it timeout is 0 the account is unlocked for the entire session
|
// until the program exits.
|
||||||
|
//
|
||||||
|
// If the accout is already unlocked, TimedUnlock extends or shortens
|
||||||
|
// the active unlock timeout.
|
||||||
func (am *Manager) TimedUnlock(addr common.Address, keyAuth string, timeout time.Duration) error {
|
func (am *Manager) TimedUnlock(addr common.Address, keyAuth string, timeout time.Duration) error {
|
||||||
key, err := am.keyStore.GetKey(addr, keyAuth)
|
key, err := am.keyStore.GetKey(addr, keyAuth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package accounts
|
package accounts
|
||||||
|
|
||||||
|
@ -23,9 +23,10 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/crypto/randentropy"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var testSigData = make([]byte, 32)
|
||||||
|
|
||||||
func TestSign(t *testing.T) {
|
func TestSign(t *testing.T) {
|
||||||
dir, ks := tmpKeyStore(t, crypto.NewKeyStorePlain)
|
dir, ks := tmpKeyStore(t, crypto.NewKeyStorePlain)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
@ -33,26 +34,24 @@ func TestSign(t *testing.T) {
|
||||||
am := NewManager(ks)
|
am := NewManager(ks)
|
||||||
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)
|
|
||||||
am.Unlock(a1.Address, "")
|
am.Unlock(a1.Address, "")
|
||||||
|
|
||||||
_, err = am.Sign(a1, toSign)
|
_, err = am.Sign(a1, testSigData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTimedUnlock(t *testing.T) {
|
func TestTimedUnlock(t *testing.T) {
|
||||||
dir, ks := tmpKeyStore(t, crypto.NewKeyStorePassphrase)
|
dir, ks := tmpKeyStore(t, crypto.NewKeyStorePlain)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
am := NewManager(ks)
|
am := NewManager(ks)
|
||||||
pass := "foo"
|
pass := "foo"
|
||||||
a1, err := am.NewAccount(pass)
|
a1, err := am.NewAccount(pass)
|
||||||
toSign := randentropy.GetEntropyCSPRNG(32)
|
|
||||||
|
|
||||||
// Signing without passphrase fails because account is locked
|
// Signing without passphrase fails because account is locked
|
||||||
_, err = am.Sign(a1, toSign)
|
_, err = am.Sign(a1, testSigData)
|
||||||
if err != ErrLocked {
|
if err != ErrLocked {
|
||||||
t.Fatal("Signing should've failed with ErrLocked before unlocking, got ", err)
|
t.Fatal("Signing should've failed with ErrLocked before unlocking, got ", err)
|
||||||
}
|
}
|
||||||
|
@ -63,28 +62,26 @@ func TestTimedUnlock(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signing without passphrase works because account is temp unlocked
|
// Signing without passphrase works because account is temp unlocked
|
||||||
_, err = am.Sign(a1, toSign)
|
_, err = am.Sign(a1, testSigData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Signing shouldn't return an error after unlocking, got ", err)
|
t.Fatal("Signing shouldn't return an error after unlocking, got ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signing fails again after automatic locking
|
// Signing fails again after automatic locking
|
||||||
time.Sleep(150 * time.Millisecond)
|
time.Sleep(150 * time.Millisecond)
|
||||||
_, err = am.Sign(a1, toSign)
|
_, err = am.Sign(a1, testSigData)
|
||||||
if err != ErrLocked {
|
if err != ErrLocked {
|
||||||
t.Fatal("Signing should've failed with ErrLocked timeout expired, got ", err)
|
t.Fatal("Signing should've failed with ErrLocked timeout expired, got ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOverrideUnlock(t *testing.T) {
|
func TestOverrideUnlock(t *testing.T) {
|
||||||
dir, ks := tmpKeyStore(t, crypto.NewKeyStorePassphrase)
|
dir, ks := tmpKeyStore(t, crypto.NewKeyStorePlain)
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
am := NewManager(ks)
|
am := NewManager(ks)
|
||||||
pass := "foo"
|
pass := "foo"
|
||||||
a1, err := am.NewAccount(pass)
|
a1, err := am.NewAccount(pass)
|
||||||
toSign := randentropy.GetEntropyCSPRNG(32)
|
|
||||||
|
|
||||||
// Unlock indefinitely
|
// Unlock indefinitely
|
||||||
if err = am.Unlock(a1.Address, pass); err != nil {
|
if err = am.Unlock(a1.Address, pass); err != nil {
|
||||||
|
@ -92,7 +89,7 @@ func TestOverrideUnlock(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signing without passphrase works because account is temp unlocked
|
// Signing without passphrase works because account is temp unlocked
|
||||||
_, err = am.Sign(a1, toSign)
|
_, err = am.Sign(a1, testSigData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Signing shouldn't return an error after unlocking, got ", err)
|
t.Fatal("Signing shouldn't return an error after unlocking, got ", err)
|
||||||
}
|
}
|
||||||
|
@ -103,20 +100,46 @@ func TestOverrideUnlock(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signing without passphrase still works because account is temp unlocked
|
// Signing without passphrase still works because account is temp unlocked
|
||||||
_, err = am.Sign(a1, toSign)
|
_, err = am.Sign(a1, testSigData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Signing shouldn't return an error after unlocking, got ", err)
|
t.Fatal("Signing shouldn't return an error after unlocking, got ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signing fails again after automatic locking
|
// Signing fails again after automatic locking
|
||||||
time.Sleep(150 * time.Millisecond)
|
time.Sleep(150 * time.Millisecond)
|
||||||
_, err = am.Sign(a1, toSign)
|
_, err = am.Sign(a1, testSigData)
|
||||||
if err != ErrLocked {
|
if err != ErrLocked {
|
||||||
t.Fatal("Signing should've failed with ErrLocked timeout expired, got ", err)
|
t.Fatal("Signing should've failed with ErrLocked timeout expired, got ", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
// This test should fail under -race if signing races the expiration goroutine.
|
||||||
|
func TestSignRace(t *testing.T) {
|
||||||
|
dir, ks := tmpKeyStore(t, crypto.NewKeyStorePlain)
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
|
// Create a test account.
|
||||||
|
am := NewManager(ks)
|
||||||
|
a1, err := am.NewAccount("")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("could not create the test account", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := am.TimedUnlock(a1.Address, "", 15*time.Millisecond); err != nil {
|
||||||
|
t.Fatalf("could not unlock the test account", err)
|
||||||
|
}
|
||||||
|
end := time.Now().Add(500 * time.Millisecond)
|
||||||
|
for time.Now().Before(end) {
|
||||||
|
if _, err := am.Sign(a1, testSigData); err == ErrLocked {
|
||||||
|
return
|
||||||
|
} else if err != nil {
|
||||||
|
t.Errorf("Sign error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Millisecond)
|
||||||
|
}
|
||||||
|
t.Errorf("Account did not lock within the timeout")
|
||||||
|
}
|
||||||
|
|
||||||
func tmpKeyStore(t *testing.T, new func(string) crypto.KeyStore) (string, crypto.KeyStore) {
|
func tmpKeyStore(t *testing.T, new func(string) crypto.KeyStore) (string, crypto.KeyStore) {
|
||||||
d, err := ioutil.TempDir("", "eth-keystore-test")
|
d, err := ioutil.TempDir("", "eth-keystore-test")
|
||||||
|
|
|
@ -48,6 +48,7 @@ var (
|
||||||
"Godeps/", "tests/files/", "build/",
|
"Godeps/", "tests/files/", "build/",
|
||||||
// don't relicense vendored packages
|
// don't relicense vendored packages
|
||||||
"crypto/sha3/", "crypto/ecies/", "logger/glog/",
|
"crypto/sha3/", "crypto/ecies/", "logger/glog/",
|
||||||
|
"crypto/curve.go",
|
||||||
}
|
}
|
||||||
|
|
||||||
// paths with this prefix are licensed as GPL. all other files are LGPL.
|
// paths with this prefix are licensed as GPL. all other files are LGPL.
|
||||||
|
@ -65,20 +66,20 @@ var (
|
||||||
// its input is an info structure.
|
// its input is an info structure.
|
||||||
var licenseT = template.Must(template.New("").Parse(`
|
var licenseT = template.Must(template.New("").Parse(`
|
||||||
// Copyright {{.Year}} The go-ethereum Authors
|
// Copyright {{.Year}} The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of {{.Whole false}}.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// {{.Whole true}} is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU {{.License}} as published by
|
// it under the terms of the GNU {{.License}} as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// {{.Whole true}} is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU {{.License}} for more details.
|
// GNU {{.License}} for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU {{.License}}
|
// You should have received a copy of the GNU {{.License}}
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with {{.Whole false}}. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
`[1:]))
|
`[1:]))
|
||||||
|
|
||||||
|
@ -90,17 +91,25 @@ type info struct {
|
||||||
func (i info) License() string {
|
func (i info) License() string {
|
||||||
if i.gpl() {
|
if i.gpl() {
|
||||||
return "General Public License"
|
return "General Public License"
|
||||||
} else {
|
|
||||||
return "Lesser General Public License"
|
|
||||||
}
|
}
|
||||||
|
return "Lesser General Public License"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i info) ShortLicense() string {
|
func (i info) ShortLicense() string {
|
||||||
if i.gpl() {
|
if i.gpl() {
|
||||||
return "GPL"
|
return "GPL"
|
||||||
} else {
|
}
|
||||||
return "LGPL"
|
return "LGPL"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i info) Whole(startOfSentence bool) string {
|
||||||
|
if i.gpl() {
|
||||||
|
return "go-ethereum"
|
||||||
|
}
|
||||||
|
if startOfSentence {
|
||||||
|
return "The go-ethereum library"
|
||||||
|
}
|
||||||
|
return "the go-ethereum library"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i info) gpl() bool {
|
func (i info) gpl() bool {
|
||||||
|
|
16
cmd/LICENSE
16
cmd/LICENSE
|
@ -1,16 +0,0 @@
|
||||||
Copyright (c) 2013-2015, The go-ethereum Authors. All rights reserved.
|
|
||||||
|
|
||||||
This library 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 2.1 of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This library 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 this library; if not, write to the Free Software
|
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
||||||
MA 02110-1301 USA
|
|
|
@ -35,7 +35,8 @@ var (
|
||||||
testExtension = ".json"
|
testExtension = ".json"
|
||||||
defaultTest = "all"
|
defaultTest = "all"
|
||||||
defaultDir = "."
|
defaultDir = "."
|
||||||
allTests = []string{"BlockTests", "StateTests", "TransactionTests", "VMTests"}
|
allTests = []string{"BlockTests", "StateTests", "TransactionTests", "VMTests", "RLPTests"}
|
||||||
|
testDirMapping = map[string]string{"BlockTests": "BlockchainTests"}
|
||||||
skipTests = []string{}
|
skipTests = []string{}
|
||||||
|
|
||||||
TestFlag = cli.StringFlag{
|
TestFlag = cli.StringFlag{
|
||||||
|
@ -75,6 +76,8 @@ func runTestWithReader(test string, r io.Reader) error {
|
||||||
err = tests.RunTransactionTestsWithReader(r, skipTests)
|
err = tests.RunTransactionTestsWithReader(r, skipTests)
|
||||||
case "vm", "vmtest", "vmtests":
|
case "vm", "vmtest", "vmtests":
|
||||||
err = tests.RunVmTestWithReader(r, skipTests)
|
err = tests.RunVmTestWithReader(r, skipTests)
|
||||||
|
case "rlp", "rlptest", "rlptests":
|
||||||
|
err = tests.RunRLPTestWithReader(r, skipTests)
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("Invalid test type specified: %v", test)
|
err = fmt.Errorf("Invalid test type specified: %v", test)
|
||||||
}
|
}
|
||||||
|
@ -133,8 +136,13 @@ func runSuite(test, file string) {
|
||||||
var err error
|
var err error
|
||||||
var files []string
|
var files []string
|
||||||
if test == defaultTest {
|
if test == defaultTest {
|
||||||
|
// check if we have an explicit directory mapping for the test
|
||||||
|
if _, ok := testDirMapping[curTest]; ok {
|
||||||
|
files, err = getFiles(filepath.Join(file, testDirMapping[curTest]))
|
||||||
|
} else {
|
||||||
|
// otherwise assume test name
|
||||||
files, err = getFiles(filepath.Join(file, curTest))
|
files, err = getFiles(filepath.Join(file, curTest))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
files, err = getFiles(file)
|
files, err = getFiles(file)
|
||||||
}
|
}
|
||||||
|
|
106
cmd/evm/main.go
106
cmd/evm/main.go
|
@ -18,70 +18,112 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/codegangsta/cli"
|
||||||
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
code = flag.String("code", "", "evm code")
|
app *cli.App
|
||||||
loglevel = flag.Int("log", 4, "log level")
|
DebugFlag = cli.BoolFlag{
|
||||||
gas = flag.String("gas", "1000000000", "gas amount")
|
Name: "debug",
|
||||||
price = flag.String("price", "0", "gas price")
|
Usage: "output full trace logs",
|
||||||
value = flag.String("value", "0", "tx value")
|
}
|
||||||
dump = flag.Bool("dump", false, "dump state after run")
|
CodeFlag = cli.StringFlag{
|
||||||
data = flag.String("data", "", "data")
|
Name: "code",
|
||||||
|
Usage: "EVM code",
|
||||||
|
}
|
||||||
|
GasFlag = cli.StringFlag{
|
||||||
|
Name: "gas",
|
||||||
|
Usage: "gas limit for the evm",
|
||||||
|
Value: "10000000000",
|
||||||
|
}
|
||||||
|
PriceFlag = cli.StringFlag{
|
||||||
|
Name: "price",
|
||||||
|
Usage: "price set for the evm",
|
||||||
|
Value: "0",
|
||||||
|
}
|
||||||
|
ValueFlag = cli.StringFlag{
|
||||||
|
Name: "value",
|
||||||
|
Usage: "value set for the evm",
|
||||||
|
Value: "0",
|
||||||
|
}
|
||||||
|
DumpFlag = cli.BoolFlag{
|
||||||
|
Name: "dump",
|
||||||
|
Usage: "dumps the state after the run",
|
||||||
|
}
|
||||||
|
InputFlag = cli.StringFlag{
|
||||||
|
Name: "input",
|
||||||
|
Usage: "input for the EVM",
|
||||||
|
}
|
||||||
|
SysStatFlag = cli.BoolFlag{
|
||||||
|
Name: "sysstat",
|
||||||
|
Usage: "display system stats",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func perr(v ...interface{}) {
|
func init() {
|
||||||
fmt.Println(v...)
|
app = utils.NewApp("0.2", "the evm command line interface")
|
||||||
//os.Exit(1)
|
app.Flags = []cli.Flag{
|
||||||
|
DebugFlag,
|
||||||
|
SysStatFlag,
|
||||||
|
CodeFlag,
|
||||||
|
GasFlag,
|
||||||
|
PriceFlag,
|
||||||
|
ValueFlag,
|
||||||
|
DumpFlag,
|
||||||
|
InputFlag,
|
||||||
|
}
|
||||||
|
app.Action = run
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func run(ctx *cli.Context) {
|
||||||
flag.Parse()
|
vm.Debug = ctx.GlobalBool(DebugFlag.Name)
|
||||||
|
|
||||||
logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.LogLevel(*loglevel)))
|
|
||||||
|
|
||||||
vm.Debug = true
|
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
statedb := state.New(common.Hash{}, db)
|
statedb := state.New(common.Hash{}, db)
|
||||||
sender := statedb.CreateAccount(common.StringToAddress("sender"))
|
sender := statedb.CreateAccount(common.StringToAddress("sender"))
|
||||||
receiver := statedb.CreateAccount(common.StringToAddress("receiver"))
|
receiver := statedb.CreateAccount(common.StringToAddress("receiver"))
|
||||||
receiver.SetCode(common.Hex2Bytes(*code))
|
receiver.SetCode(common.Hex2Bytes(ctx.GlobalString(CodeFlag.Name)))
|
||||||
|
|
||||||
vmenv := NewEnv(statedb, common.StringToAddress("evmuser"), common.Big(*value))
|
vmenv := NewEnv(statedb, common.StringToAddress("evmuser"), common.Big(ctx.GlobalString(ValueFlag.Name)))
|
||||||
|
|
||||||
tstart := time.Now()
|
tstart := time.Now()
|
||||||
|
ret, e := vmenv.Call(
|
||||||
|
sender,
|
||||||
|
receiver.Address(),
|
||||||
|
common.Hex2Bytes(ctx.GlobalString(InputFlag.Name)),
|
||||||
|
common.Big(ctx.GlobalString(GasFlag.Name)),
|
||||||
|
common.Big(ctx.GlobalString(PriceFlag.Name)),
|
||||||
|
common.Big(ctx.GlobalString(ValueFlag.Name)),
|
||||||
|
)
|
||||||
|
vmdone := time.Since(tstart)
|
||||||
|
|
||||||
ret, e := vmenv.Call(sender, receiver.Address(), common.Hex2Bytes(*data), common.Big(*gas), common.Big(*price), common.Big(*value))
|
|
||||||
|
|
||||||
logger.Flush()
|
|
||||||
if e != nil {
|
if e != nil {
|
||||||
perr(e)
|
fmt.Println(e)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *dump {
|
if ctx.GlobalBool(DumpFlag.Name) {
|
||||||
fmt.Println(string(statedb.Dump()))
|
fmt.Println(string(statedb.Dump()))
|
||||||
}
|
}
|
||||||
|
|
||||||
vm.StdErrFormat(vmenv.StructLogs())
|
vm.StdErrFormat(vmenv.StructLogs())
|
||||||
|
|
||||||
|
if ctx.GlobalBool(SysStatFlag.Name) {
|
||||||
var mem runtime.MemStats
|
var mem runtime.MemStats
|
||||||
runtime.ReadMemStats(&mem)
|
runtime.ReadMemStats(&mem)
|
||||||
fmt.Printf("vm took %v\n", time.Since(tstart))
|
fmt.Printf("vm took %v\n", vmdone)
|
||||||
fmt.Printf(`alloc: %d
|
fmt.Printf(`alloc: %d
|
||||||
tot alloc: %d
|
tot alloc: %d
|
||||||
no. malloc: %d
|
no. malloc: %d
|
||||||
|
@ -89,8 +131,16 @@ heap alloc: %d
|
||||||
heap objs: %d
|
heap objs: %d
|
||||||
num gc: %d
|
num gc: %d
|
||||||
`, mem.Alloc, mem.TotalAlloc, mem.Mallocs, mem.HeapAlloc, mem.HeapObjects, mem.NumGC)
|
`, mem.Alloc, mem.TotalAlloc, mem.Mallocs, mem.HeapAlloc, mem.HeapObjects, mem.NumGC)
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("%x\n", ret)
|
fmt.Printf("OUT: 0x%x\n", ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if err := app.Run(os.Args); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type VMEnv struct {
|
type VMEnv struct {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -44,6 +45,10 @@ import (
|
||||||
"github.com/robertkrimen/otto"
|
"github.com/robertkrimen/otto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var passwordRegexp = regexp.MustCompile("personal.[nu]")
|
||||||
|
|
||||||
|
const passwordRepl = ""
|
||||||
|
|
||||||
type prompter interface {
|
type prompter interface {
|
||||||
AppendHistory(string)
|
AppendHistory(string)
|
||||||
Prompt(p string) (string, error)
|
Prompt(p string) (string, error)
|
||||||
|
@ -413,8 +418,10 @@ func (self *jsre) interactive() {
|
||||||
str += input + "\n"
|
str += input + "\n"
|
||||||
self.setIndent()
|
self.setIndent()
|
||||||
if indentCount <= 0 {
|
if indentCount <= 0 {
|
||||||
hist := str[:len(str)-1]
|
hist := hidepassword(str[:len(str)-1])
|
||||||
|
if len(hist) > 0 {
|
||||||
self.AppendHistory(hist)
|
self.AppendHistory(hist)
|
||||||
|
}
|
||||||
self.parseInput(str)
|
self.parseInput(str)
|
||||||
str = ""
|
str = ""
|
||||||
}
|
}
|
||||||
|
@ -422,6 +429,14 @@ func (self *jsre) interactive() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hidepassword(input string) string {
|
||||||
|
if passwordRegexp.MatchString(input) {
|
||||||
|
return passwordRepl
|
||||||
|
} else {
|
||||||
|
return input
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *jsre) withHistory(op func(*os.File)) {
|
func (self *jsre) withHistory(op func(*os.File)) {
|
||||||
datadir := common.DefaultDataDir()
|
datadir := common.DefaultDataDir()
|
||||||
if self.ethereum != nil {
|
if self.ethereum != nil {
|
||||||
|
|
|
@ -37,6 +37,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/rpc/codec"
|
"github.com/ethereum/go-ethereum/rpc/codec"
|
||||||
"github.com/ethereum/go-ethereum/rpc/comms"
|
"github.com/ethereum/go-ethereum/rpc/comms"
|
||||||
)
|
)
|
||||||
|
@ -89,9 +90,9 @@ func testREPL(t *testing.T, config func(*eth.Config)) (string, *testjethre, *eth
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up mock genesis with balance on the testAddress
|
db, _ := ethdb.NewMemDatabase()
|
||||||
core.GenesisAccounts = []byte(testGenesis)
|
|
||||||
|
|
||||||
|
core.WriteGenesisBlockForTesting(db, common.HexToAddress(testAddress), common.String2Big(testBalance))
|
||||||
ks := crypto.NewKeyStorePlain(filepath.Join(tmp, "keystore"))
|
ks := crypto.NewKeyStorePlain(filepath.Join(tmp, "keystore"))
|
||||||
am := accounts.NewManager(ks)
|
am := accounts.NewManager(ks)
|
||||||
conf := ð.Config{
|
conf := ð.Config{
|
||||||
|
@ -102,6 +103,7 @@ func testREPL(t *testing.T, config func(*eth.Config)) (string, *testjethre, *eth
|
||||||
Name: "test",
|
Name: "test",
|
||||||
SolcPath: testSolcPath,
|
SolcPath: testSolcPath,
|
||||||
PowTest: true,
|
PowTest: true,
|
||||||
|
NewDB: func(path string) (common.Database, error) { return db, nil },
|
||||||
}
|
}
|
||||||
if config != nil {
|
if config != nil {
|
||||||
config(conf)
|
config(conf)
|
||||||
|
@ -157,7 +159,7 @@ func TestAccounts(t *testing.T) {
|
||||||
defer os.RemoveAll(tmp)
|
defer os.RemoveAll(tmp)
|
||||||
|
|
||||||
checkEvalJSON(t, repl, `eth.accounts`, `["`+testAddress+`"]`)
|
checkEvalJSON(t, repl, `eth.accounts`, `["`+testAddress+`"]`)
|
||||||
checkEvalJSON(t, repl, `eth.coinbase`, `null`)
|
checkEvalJSON(t, repl, `eth.coinbase`, `"`+testAddress+`"`)
|
||||||
val, err := repl.re.Run(`personal.newAccount("password")`)
|
val, err := repl.re.Run(`personal.newAccount("password")`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected no error, got %v", err)
|
t.Errorf("expected no error, got %v", err)
|
||||||
|
@ -168,6 +170,7 @@ func TestAccounts(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
checkEvalJSON(t, repl, `eth.accounts`, `["`+testAddress+`","`+addr+`"]`)
|
checkEvalJSON(t, repl, `eth.accounts`, `["`+testAddress+`","`+addr+`"]`)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBlockChain(t *testing.T) {
|
func TestBlockChain(t *testing.T) {
|
||||||
|
|
|
@ -38,6 +38,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
|
"github.com/ethereum/go-ethereum/fdtrack"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
|
@ -49,7 +50,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ClientIdentifier = "Geth"
|
ClientIdentifier = "Geth"
|
||||||
Version = "0.9.38"
|
Version = "1.0.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -276,10 +277,12 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
|
||||||
utils.IdentityFlag,
|
utils.IdentityFlag,
|
||||||
utils.UnlockedAccountFlag,
|
utils.UnlockedAccountFlag,
|
||||||
utils.PasswordFileFlag,
|
utils.PasswordFileFlag,
|
||||||
utils.GenesisNonceFlag,
|
utils.GenesisFileFlag,
|
||||||
utils.BootnodesFlag,
|
utils.BootnodesFlag,
|
||||||
utils.DataDirFlag,
|
utils.DataDirFlag,
|
||||||
utils.BlockchainVersionFlag,
|
utils.BlockchainVersionFlag,
|
||||||
|
utils.OlympicFlag,
|
||||||
|
utils.CacheFlag,
|
||||||
utils.JSpathFlag,
|
utils.JSpathFlag,
|
||||||
utils.ListenPortFlag,
|
utils.ListenPortFlag,
|
||||||
utils.MaxPeersFlag,
|
utils.MaxPeersFlag,
|
||||||
|
@ -344,6 +347,11 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func run(ctx *cli.Context) {
|
func run(ctx *cli.Context) {
|
||||||
|
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
|
||||||
|
if ctx.GlobalBool(utils.OlympicFlag.Name) {
|
||||||
|
utils.InitOlympic()
|
||||||
|
}
|
||||||
|
|
||||||
cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
|
cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
|
||||||
ethereum, err := eth.New(cfg)
|
ethereum, err := eth.New(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -356,6 +364,8 @@ func run(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func attach(ctx *cli.Context) {
|
func attach(ctx *cli.Context) {
|
||||||
|
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
|
||||||
|
|
||||||
// Wrap the standard output with a colorified stream (windows)
|
// Wrap the standard output with a colorified stream (windows)
|
||||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||||
if pr, pw, err := os.Pipe(); err == nil {
|
if pr, pw, err := os.Pipe(); err == nil {
|
||||||
|
@ -394,6 +404,8 @@ func attach(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func console(ctx *cli.Context) {
|
func console(ctx *cli.Context) {
|
||||||
|
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
|
||||||
|
|
||||||
// Wrap the standard output with a colorified stream (windows)
|
// Wrap the standard output with a colorified stream (windows)
|
||||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||||
if pr, pw, err := os.Pipe(); err == nil {
|
if pr, pw, err := os.Pipe(); err == nil {
|
||||||
|
@ -432,6 +444,8 @@ func console(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func execJSFiles(ctx *cli.Context) {
|
func execJSFiles(ctx *cli.Context) {
|
||||||
|
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
|
||||||
|
|
||||||
cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
|
cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
|
||||||
ethereum, err := eth.New(cfg)
|
ethereum, err := eth.New(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -457,6 +471,8 @@ func execJSFiles(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func unlockAccount(ctx *cli.Context, am *accounts.Manager, addr string, i int) (addrHex, auth string) {
|
func unlockAccount(ctx *cli.Context, am *accounts.Manager, addr string, i int) (addrHex, auth string) {
|
||||||
|
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
addrHex, err = utils.ParamToAddress(addr, am)
|
addrHex, err = utils.ParamToAddress(addr, am)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -480,13 +496,17 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, addr string, i int) (
|
||||||
}
|
}
|
||||||
|
|
||||||
func blockRecovery(ctx *cli.Context) {
|
func blockRecovery(ctx *cli.Context) {
|
||||||
|
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
|
||||||
|
|
||||||
arg := ctx.Args().First()
|
arg := ctx.Args().First()
|
||||||
if len(ctx.Args()) < 1 && len(arg) > 0 {
|
if len(ctx.Args()) < 1 && len(arg) > 0 {
|
||||||
glog.Fatal("recover requires block number or hash")
|
glog.Fatal("recover requires block number or hash")
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
|
cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
|
||||||
blockDb, err := ethdb.NewLDBDatabase(filepath.Join(cfg.DataDir, "blockchain"))
|
utils.CheckLegalese(cfg.DataDir)
|
||||||
|
|
||||||
|
blockDb, err := ethdb.NewLDBDatabase(filepath.Join(cfg.DataDir, "blockchain"), cfg.DatabaseCache)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalln("could not open db:", err)
|
glog.Fatalln("could not open db:", err)
|
||||||
}
|
}
|
||||||
|
@ -513,6 +533,9 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
|
||||||
// Start Ethereum itself
|
// Start Ethereum itself
|
||||||
utils.StartEthereum(eth)
|
utils.StartEthereum(eth)
|
||||||
|
|
||||||
|
// Start logging file descriptor stats.
|
||||||
|
fdtrack.Start()
|
||||||
|
|
||||||
am := eth.AccountManager()
|
am := eth.AccountManager()
|
||||||
account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
|
account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
|
||||||
accounts := strings.Split(account, " ")
|
accounts := strings.Split(account, " ")
|
||||||
|
@ -543,6 +566,8 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func accountList(ctx *cli.Context) {
|
func accountList(ctx *cli.Context) {
|
||||||
|
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
|
||||||
|
|
||||||
am := utils.MakeAccountManager(ctx)
|
am := utils.MakeAccountManager(ctx)
|
||||||
accts, err := am.Accounts()
|
accts, err := am.Accounts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -591,6 +616,8 @@ func getPassPhrase(ctx *cli.Context, desc string, confirmation bool, i int) (pas
|
||||||
}
|
}
|
||||||
|
|
||||||
func accountCreate(ctx *cli.Context) {
|
func accountCreate(ctx *cli.Context) {
|
||||||
|
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
|
||||||
|
|
||||||
am := utils.MakeAccountManager(ctx)
|
am := utils.MakeAccountManager(ctx)
|
||||||
passphrase := getPassPhrase(ctx, "Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0)
|
passphrase := getPassPhrase(ctx, "Your new account is locked with a password. Please give a password. Do not forget this password.", true, 0)
|
||||||
acct, err := am.NewAccount(passphrase)
|
acct, err := am.NewAccount(passphrase)
|
||||||
|
@ -601,6 +628,8 @@ func accountCreate(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func accountUpdate(ctx *cli.Context) {
|
func accountUpdate(ctx *cli.Context) {
|
||||||
|
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
|
||||||
|
|
||||||
am := utils.MakeAccountManager(ctx)
|
am := utils.MakeAccountManager(ctx)
|
||||||
arg := ctx.Args().First()
|
arg := ctx.Args().First()
|
||||||
if len(arg) == 0 {
|
if len(arg) == 0 {
|
||||||
|
@ -616,6 +645,8 @@ func accountUpdate(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func importWallet(ctx *cli.Context) {
|
func importWallet(ctx *cli.Context) {
|
||||||
|
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
|
||||||
|
|
||||||
keyfile := ctx.Args().First()
|
keyfile := ctx.Args().First()
|
||||||
if len(keyfile) == 0 {
|
if len(keyfile) == 0 {
|
||||||
utils.Fatalf("keyfile must be given as argument")
|
utils.Fatalf("keyfile must be given as argument")
|
||||||
|
@ -636,6 +667,8 @@ func importWallet(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func accountImport(ctx *cli.Context) {
|
func accountImport(ctx *cli.Context) {
|
||||||
|
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
|
||||||
|
|
||||||
keyfile := ctx.Args().First()
|
keyfile := ctx.Args().First()
|
||||||
if len(keyfile) == 0 {
|
if len(keyfile) == 0 {
|
||||||
utils.Fatalf("keyfile must be given as argument")
|
utils.Fatalf("keyfile must be given as argument")
|
||||||
|
@ -650,6 +683,8 @@ func accountImport(ctx *cli.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func makedag(ctx *cli.Context) {
|
func makedag(ctx *cli.Context) {
|
||||||
|
utils.CheckLegalese(ctx.GlobalString(utils.DataDirFlag.Name))
|
||||||
|
|
||||||
args := ctx.Args()
|
args := ctx.Args()
|
||||||
wrongArgs := func() {
|
wrongArgs := func() {
|
||||||
utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
|
utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -32,6 +33,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/peterh/liner"
|
"github.com/peterh/liner"
|
||||||
)
|
)
|
||||||
|
@ -58,15 +60,16 @@ func PromptConfirm(prompt string) (bool, error) {
|
||||||
)
|
)
|
||||||
prompt = prompt + " [y/N] "
|
prompt = prompt + " [y/N] "
|
||||||
|
|
||||||
if liner.TerminalSupported() {
|
// if liner.TerminalSupported() {
|
||||||
lr := liner.NewLiner()
|
// fmt.Println("term")
|
||||||
defer lr.Close()
|
// lr := liner.NewLiner()
|
||||||
input, err = lr.Prompt(prompt)
|
// defer lr.Close()
|
||||||
} else {
|
// input, err = lr.Prompt(prompt)
|
||||||
|
// } else {
|
||||||
fmt.Print(prompt)
|
fmt.Print(prompt)
|
||||||
input, err = bufio.NewReader(os.Stdin).ReadString('\n')
|
input, err = bufio.NewReader(os.Stdin).ReadString('\n')
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
// }
|
||||||
|
|
||||||
if len(input) > 0 && strings.ToUpper(input[:1]) == "Y" {
|
if len(input) > 0 && strings.ToUpper(input[:1]) == "Y" {
|
||||||
return true, nil
|
return true, nil
|
||||||
|
@ -92,12 +95,12 @@ func PromptPassword(prompt string, warnTerm bool) (string, error) {
|
||||||
return input, err
|
return input, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func initDataDir(Datadir string) {
|
func CheckLegalese(datadir string) {
|
||||||
_, err := os.Stat(Datadir)
|
// check "first run"
|
||||||
if err != nil {
|
if !common.FileExist(datadir) {
|
||||||
if os.IsNotExist(err) {
|
r, _ := PromptConfirm(legalese)
|
||||||
fmt.Printf("Data directory '%s' doesn't exist, creating it\n", Datadir)
|
if !r {
|
||||||
os.Mkdir(Datadir, 0777)
|
Fatalf("Must accept to continue. Shutting down...\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,6 +145,15 @@ func StartEthereum(ethereum *eth.Ethereum) {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InitOlympic() {
|
||||||
|
params.DurationLimit = big.NewInt(8)
|
||||||
|
params.GenesisGasLimit = big.NewInt(3141592)
|
||||||
|
params.MinGasLimit = big.NewInt(125000)
|
||||||
|
params.MaximumExtraDataSize = big.NewInt(1024)
|
||||||
|
NetworkIdFlag.Value = 0
|
||||||
|
core.BlockReward = big.NewInt(1.5e+18)
|
||||||
|
}
|
||||||
|
|
||||||
func FormatTransactionData(data string) []byte {
|
func FormatTransactionData(data string) []byte {
|
||||||
d := common.StringToByteFunc(data, func(s string) (ret []byte) {
|
d := common.StringToByteFunc(data, func(s string) (ret []byte) {
|
||||||
slice := regexp.MustCompile("\\n|\\s").Split(s, 1000000000)
|
slice := regexp.MustCompile("\\n|\\s").Split(s, 1000000000)
|
||||||
|
@ -202,6 +214,11 @@ func ImportChain(chain *core.ChainManager, fn string) error {
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return fmt.Errorf("at block %d: %v", n, err)
|
return fmt.Errorf("at block %d: %v", n, err)
|
||||||
}
|
}
|
||||||
|
// don't import first block
|
||||||
|
if b.NumberU64() == 0 {
|
||||||
|
i--
|
||||||
|
continue
|
||||||
|
}
|
||||||
blocks[i] = &b
|
blocks[i] = &b
|
||||||
n++
|
n++
|
||||||
}
|
}
|
||||||
|
@ -217,6 +234,7 @@ func ImportChain(chain *core.ChainManager, fn string) error {
|
||||||
batch, blocks[0].Hash().Bytes()[:4], blocks[i-1].Hash().Bytes()[:4])
|
batch, blocks[0].Hash().Bytes()[:4], blocks[i-1].Hash().Bytes()[:4])
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := chain.InsertChain(blocks[:i]); err != nil {
|
if _, err := chain.InsertChain(blocks[:i]); err != nil {
|
||||||
return fmt.Errorf("invalid block %d: %v", n, err)
|
return fmt.Errorf("invalid block %d: %v", n, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,10 @@ var (
|
||||||
Usage: "Sets the genesis nonce",
|
Usage: "Sets the genesis nonce",
|
||||||
Value: 42,
|
Value: 42,
|
||||||
}
|
}
|
||||||
|
GenesisFileFlag = cli.StringFlag{
|
||||||
|
Name: "genesis",
|
||||||
|
Usage: "Inserts/Overwrites the genesis block (json format)",
|
||||||
|
}
|
||||||
IdentityFlag = cli.StringFlag{
|
IdentityFlag = cli.StringFlag{
|
||||||
Name: "identity",
|
Name: "identity",
|
||||||
Usage: "Custom node name",
|
Usage: "Custom node name",
|
||||||
|
@ -122,6 +126,15 @@ var (
|
||||||
Name: "natspec",
|
Name: "natspec",
|
||||||
Usage: "Enable NatSpec confirmation notice",
|
Usage: "Enable NatSpec confirmation notice",
|
||||||
}
|
}
|
||||||
|
CacheFlag = cli.IntFlag{
|
||||||
|
Name: "cache",
|
||||||
|
Usage: "Megabytes of memory allocated to internal caching",
|
||||||
|
Value: 0,
|
||||||
|
}
|
||||||
|
OlympicFlag = cli.BoolFlag{
|
||||||
|
Name: "olympic",
|
||||||
|
Usage: "Use olympic style protocol",
|
||||||
|
}
|
||||||
|
|
||||||
// miner settings
|
// miner settings
|
||||||
MinerThreadsFlag = cli.IntFlag{
|
MinerThreadsFlag = cli.IntFlag{
|
||||||
|
@ -145,7 +158,7 @@ var (
|
||||||
GasPriceFlag = cli.StringFlag{
|
GasPriceFlag = cli.StringFlag{
|
||||||
Name: "gasprice",
|
Name: "gasprice",
|
||||||
Usage: "Sets the minimal gasprice when mining transactions",
|
Usage: "Sets the minimal gasprice when mining transactions",
|
||||||
Value: new(big.Int).Mul(big.NewInt(1), common.Szabo).String(),
|
Value: new(big.Int).Mul(big.NewInt(50), common.Shannon).String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
UnlockedAccountFlag = cli.StringFlag{
|
UnlockedAccountFlag = cli.StringFlag{
|
||||||
|
@ -305,12 +318,12 @@ var (
|
||||||
GpoMinGasPriceFlag = cli.StringFlag{
|
GpoMinGasPriceFlag = cli.StringFlag{
|
||||||
Name: "gpomin",
|
Name: "gpomin",
|
||||||
Usage: "Minimum suggested gas price",
|
Usage: "Minimum suggested gas price",
|
||||||
Value: new(big.Int).Mul(big.NewInt(1), common.Szabo).String(),
|
Value: new(big.Int).Mul(big.NewInt(50), common.Shannon).String(),
|
||||||
}
|
}
|
||||||
GpoMaxGasPriceFlag = cli.StringFlag{
|
GpoMaxGasPriceFlag = cli.StringFlag{
|
||||||
Name: "gpomax",
|
Name: "gpomax",
|
||||||
Usage: "Maximum suggested gas price",
|
Usage: "Maximum suggested gas price",
|
||||||
Value: new(big.Int).Mul(big.NewInt(100), common.Szabo).String(),
|
Value: new(big.Int).Mul(big.NewInt(500), common.Shannon).String(),
|
||||||
}
|
}
|
||||||
GpoFullBlockRatioFlag = cli.IntFlag{
|
GpoFullBlockRatioFlag = cli.IntFlag{
|
||||||
Name: "gpofull",
|
Name: "gpofull",
|
||||||
|
@ -378,7 +391,9 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
|
||||||
Name: common.MakeName(clientID, version),
|
Name: common.MakeName(clientID, version),
|
||||||
DataDir: ctx.GlobalString(DataDirFlag.Name),
|
DataDir: ctx.GlobalString(DataDirFlag.Name),
|
||||||
GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name),
|
GenesisNonce: ctx.GlobalInt(GenesisNonceFlag.Name),
|
||||||
|
GenesisFile: ctx.GlobalString(GenesisFileFlag.Name),
|
||||||
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
|
BlockChainVersion: ctx.GlobalInt(BlockchainVersionFlag.Name),
|
||||||
|
DatabaseCache: ctx.GlobalInt(CacheFlag.Name),
|
||||||
SkipBcVersionCheck: false,
|
SkipBcVersionCheck: false,
|
||||||
NetworkId: ctx.GlobalInt(NetworkIdFlag.Name),
|
NetworkId: ctx.GlobalInt(NetworkIdFlag.Name),
|
||||||
LogFile: ctx.GlobalString(LogFileFlag.Name),
|
LogFile: ctx.GlobalString(LogFileFlag.Name),
|
||||||
|
@ -391,6 +406,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
|
||||||
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
|
MaxPeers: ctx.GlobalInt(MaxPeersFlag.Name),
|
||||||
MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name),
|
MaxPendingPeers: ctx.GlobalInt(MaxPendingPeersFlag.Name),
|
||||||
Port: ctx.GlobalString(ListenPortFlag.Name),
|
Port: ctx.GlobalString(ListenPortFlag.Name),
|
||||||
|
Olympic: ctx.GlobalBool(OlympicFlag.Name),
|
||||||
NAT: MakeNAT(ctx),
|
NAT: MakeNAT(ctx),
|
||||||
NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name),
|
NatSpec: ctx.GlobalBool(NatspecEnabledFlag.Name),
|
||||||
Discovery: !ctx.GlobalBool(NoDiscoverFlag.Name),
|
Discovery: !ctx.GlobalBool(NoDiscoverFlag.Name),
|
||||||
|
@ -420,22 +436,31 @@ func SetupLogger(ctx *cli.Context) {
|
||||||
|
|
||||||
// MakeChain creates a chain manager from set command line flags.
|
// MakeChain creates a chain manager from set command line flags.
|
||||||
func MakeChain(ctx *cli.Context) (chain *core.ChainManager, blockDB, stateDB, extraDB common.Database) {
|
func MakeChain(ctx *cli.Context) (chain *core.ChainManager, blockDB, stateDB, extraDB common.Database) {
|
||||||
dd := ctx.GlobalString(DataDirFlag.Name)
|
datadir := ctx.GlobalString(DataDirFlag.Name)
|
||||||
|
cache := ctx.GlobalInt(CacheFlag.Name)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
if blockDB, err = ethdb.NewLDBDatabase(filepath.Join(dd, "blockchain")); err != nil {
|
if blockDB, err = ethdb.NewLDBDatabase(filepath.Join(datadir, "blockchain"), cache); err != nil {
|
||||||
Fatalf("Could not open database: %v", err)
|
Fatalf("Could not open database: %v", err)
|
||||||
}
|
}
|
||||||
if stateDB, err = ethdb.NewLDBDatabase(filepath.Join(dd, "state")); err != nil {
|
if stateDB, err = ethdb.NewLDBDatabase(filepath.Join(datadir, "state"), cache); err != nil {
|
||||||
Fatalf("Could not open database: %v", err)
|
Fatalf("Could not open database: %v", err)
|
||||||
}
|
}
|
||||||
if extraDB, err = ethdb.NewLDBDatabase(filepath.Join(dd, "extra")); err != nil {
|
if extraDB, err = ethdb.NewLDBDatabase(filepath.Join(datadir, "extra"), cache); err != nil {
|
||||||
Fatalf("Could not open database: %v", err)
|
Fatalf("Could not open database: %v", err)
|
||||||
}
|
}
|
||||||
|
if ctx.GlobalBool(OlympicFlag.Name) {
|
||||||
|
InitOlympic()
|
||||||
|
_, err := core.WriteTestNetGenesisBlock(stateDB, blockDB, 42)
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatalln(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
eventMux := new(event.TypeMux)
|
eventMux := new(event.TypeMux)
|
||||||
pow := ethash.New()
|
pow := ethash.New()
|
||||||
genesis := core.GenesisBlock(uint64(ctx.GlobalInt(GenesisNonceFlag.Name)), blockDB)
|
//genesis := core.GenesisBlock(uint64(ctx.GlobalInt(GenesisNonceFlag.Name)), blockDB)
|
||||||
chain, err = core.NewChainManager(genesis, blockDB, stateDB, extraDB, pow, eventMux)
|
chain, err = core.NewChainManager(blockDB, stateDB, extraDB, pow, eventMux)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("Could not start chainmanager: %v", err)
|
Fatalf("Could not start chainmanager: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
// Copyright 2015 The go-ethereum Authors
|
||||||
|
// 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 utils
|
||||||
|
|
||||||
|
const (
|
||||||
|
legalese = `
|
||||||
|
=======================================
|
||||||
|
Disclaimer of Liabilites and Warranties
|
||||||
|
=======================================
|
||||||
|
|
||||||
|
THE USER EXPRESSLY KNOWS AND AGREES THAT THE USER IS USING THE ETHEREUM PLATFORM AT THE USER’S SOLE
|
||||||
|
RISK. THE USER REPRESENTS THAT THE USER HAS AN ADEQUATE UNDERSTANDING OF THE RISKS, USAGE AND
|
||||||
|
INTRICACIES OF CRYPTOGRAPHIC TOKENS AND BLOCKCHAIN-BASED OPEN SOURCE SOFTWARE, ETH PLATFORM AND ETH.
|
||||||
|
THE USER ACKNOWLEDGES AND AGREES THAT, TO THE FULLEST EXTENT PERMITTED BY ANY APPLICABLE LAW, THE
|
||||||
|
DISCLAIMERS OF LIABILITY CONTAINED HEREIN APPLY TO ANY AND ALL DAMAGES OR INJURY WHATSOEVER CAUSED
|
||||||
|
BY OR RELATED TO RISKS OF, USE OF, OR INABILITY TO USE, ETH OR THE ETHEREUM PLATFORM UNDER ANY CAUSE
|
||||||
|
OR ACTION WHATSOEVER OF ANY KIND IN ANY JURISDICTION, INCLUDING, WITHOUT LIMITATION, ACTIONS FOR
|
||||||
|
BREACH OF WARRANTY, BREACH OF CONTRACT OR TORT (INCLUDING NEGLIGENCE) AND THAT NEITHER STIFTUNG
|
||||||
|
ETHEREUM NOR ETHEREUM TEAM SHALL BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR
|
||||||
|
CONSEQUENTIAL DAMAGES, INCLUDING FOR LOSS OF PROFITS, GOODWILL OR DATA. SOME JURISDICTIONS DO NOT
|
||||||
|
ALLOW THE EXCLUSION OF CERTAIN WARRANTIES OR THE LIMITATION OR EXCLUSION OF LIABILITY FOR CERTAIN
|
||||||
|
TYPES OF DAMAGES. THEREFORE, SOME OF THE ABOVE LIMITATIONS IN THIS SECTION MAY NOT APPLY TO A USER.
|
||||||
|
IN PARTICULAR, NOTHING IN THESE TERMS SHALL AFFECT THE STATUTORY RIGHTS OF ANY USER OR EXCLUDE
|
||||||
|
INJURY ARISING FROM ANY WILLFUL MISCONDUCT OR FRAUD OF STIFTUNG ETHEREUM.
|
||||||
|
|
||||||
|
Do you accept this agreement?`
|
||||||
|
)
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// Package common contains various helper functions.
|
// Package common contains various helper functions.
|
||||||
package common
|
package common
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package compiler
|
package compiler
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package compiler
|
package compiler
|
||||||
|
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
|
||||||
// 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 Lesser 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 Lesser General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/rakyll/globalconf"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Config struct
|
|
||||||
type ConfigManager struct {
|
|
||||||
ExecPath string
|
|
||||||
Debug bool
|
|
||||||
Diff bool
|
|
||||||
DiffType string
|
|
||||||
Paranoia bool
|
|
||||||
VmType int
|
|
||||||
|
|
||||||
conf *globalconf.GlobalConf
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read config
|
|
||||||
//
|
|
||||||
// Initialize Config from Config File
|
|
||||||
func ReadConfig(ConfigFile string, Datadir string, EnvPrefix string) *ConfigManager {
|
|
||||||
if !FileExist(ConfigFile) {
|
|
||||||
// create ConfigFile if it does not exist, otherwise
|
|
||||||
// globalconf will panic when trying to persist flags.
|
|
||||||
fmt.Printf("config file '%s' doesn't exist, creating it\n", ConfigFile)
|
|
||||||
os.Create(ConfigFile)
|
|
||||||
}
|
|
||||||
g, err := globalconf.NewWithOptions(&globalconf.Options{
|
|
||||||
Filename: ConfigFile,
|
|
||||||
EnvPrefix: EnvPrefix,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
} else {
|
|
||||||
g.ParseAll()
|
|
||||||
}
|
|
||||||
cfg := &ConfigManager{ExecPath: Datadir, Debug: true, conf: g, Paranoia: true}
|
|
||||||
return cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
// provides persistence for flags
|
|
||||||
func (c *ConfigManager) Save(key string, value interface{}) {
|
|
||||||
f := &flag.Flag{Name: key, Value: newConfValue(value)}
|
|
||||||
c.conf.Set("", f)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ConfigManager) Delete(key string) {
|
|
||||||
c.conf.Delete("", key)
|
|
||||||
}
|
|
||||||
|
|
||||||
// private type implementing flag.Value
|
|
||||||
type confValue struct {
|
|
||||||
value string
|
|
||||||
}
|
|
||||||
|
|
||||||
// generic constructor to allow persising non-string values directly
|
|
||||||
func newConfValue(value interface{}) *confValue {
|
|
||||||
return &confValue{fmt.Sprintf("%v", value)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self confValue) String() string { return self.value }
|
|
||||||
func (self confValue) Set(s string) error { self.value = s; return nil }
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package docserver
|
package docserver
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package docserver
|
package docserver
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package math
|
package math
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package math
|
package math
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package natspec
|
package natspec
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package natspec
|
package natspec
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
xe "github.com/ethereum/go-ethereum/xeth"
|
xe "github.com/ethereum/go-ethereum/xeth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -128,12 +129,12 @@ func testEth(t *testing.T) (ethereum *eth.Ethereum, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
testAddress := strings.TrimPrefix(testAccount.Address.Hex(), "0x")
|
testAddress := strings.TrimPrefix(testAccount.Address.Hex(), "0x")
|
||||||
|
|
||||||
|
db, _ := ethdb.NewMemDatabase()
|
||||||
// set up mock genesis with balance on the testAddress
|
// set up mock genesis with balance on the testAddress
|
||||||
core.GenesisAccounts = []byte(`{
|
core.WriteGenesisBlockForTesting(db, common.HexToAddress(testAddress), common.String2Big(testBalance))
|
||||||
"` + testAddress + `": {"balance": "` + testBalance + `"}
|
|
||||||
}`)
|
|
||||||
|
|
||||||
// only use minimalistic stack with no networking
|
// only use minimalistic stack with no networking
|
||||||
ethereum, err = eth.New(ð.Config{
|
ethereum, err = eth.New(ð.Config{
|
||||||
|
@ -142,6 +143,7 @@ func testEth(t *testing.T) (ethereum *eth.Ethereum, err error) {
|
||||||
MaxPeers: 0,
|
MaxPeers: 0,
|
||||||
PowTest: true,
|
PowTest: true,
|
||||||
Etherbase: common.HexToAddress(testAddress),
|
Etherbase: common.HexToAddress(testAddress),
|
||||||
|
NewDB: func(path string) (common.Database, error) { return db, nil },
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package natspec
|
package natspec
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package natspec
|
package natspec
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package number
|
package number
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package number
|
package number
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package registrar
|
package registrar
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package ethreg
|
package ethreg
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package registrar
|
package registrar
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package registrar
|
package registrar
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// +build none
|
// +build none
|
||||||
//sed -e 's/_N_/Hash/g' -e 's/_S_/32/g' -e '1d' types_template.go | gofmt -w hash.go
|
//sed -e 's/_N_/Hash/g' -e 's/_S_/32/g' -e '1d' types_template.go | gofmt -w hash.go
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// Package rle implements the run-length encoding used for Ethereum data.
|
// Package rle implements the run-length encoding used for Ethereum data.
|
||||||
package rle
|
package rle
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package rle
|
package rle
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
|
||||||
b.Fatalf("cannot create temporary directory: %v", err)
|
b.Fatalf("cannot create temporary directory: %v", err)
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
db, err = ethdb.NewLDBDatabase(dir)
|
db, err = ethdb.NewLDBDatabase(dir, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatalf("cannot create temporary database: %v", err)
|
b.Fatalf("cannot create temporary database: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -162,13 +162,13 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
|
||||||
|
|
||||||
// Generate a chain of b.N blocks using the supplied block
|
// Generate a chain of b.N blocks using the supplied block
|
||||||
// generator function.
|
// generator function.
|
||||||
genesis := GenesisBlockForTesting(db, benchRootAddr, benchRootFunds)
|
genesis := WriteGenesisBlockForTesting(db, benchRootAddr, benchRootFunds)
|
||||||
chain := GenerateChain(genesis, db, b.N, gen)
|
chain := GenerateChain(genesis, db, b.N, gen)
|
||||||
|
|
||||||
// Time the insertion of the new chain.
|
// Time the insertion of the new chain.
|
||||||
// State and blocks are stored in the same DB.
|
// State and blocks are stored in the same DB.
|
||||||
evmux := new(event.TypeMux)
|
evmux := new(event.TypeMux)
|
||||||
chainman, _ := NewChainManager(genesis, db, db, db, FakePow{}, evmux)
|
chainman, _ := NewChainManager(db, db, db, FakePow{}, evmux)
|
||||||
chainman.SetProcessor(NewBlockProcessor(db, db, FakePow{}, chainman, evmux))
|
chainman.SetProcessor(NewBlockProcessor(db, db, FakePow{}, chainman, evmux))
|
||||||
defer chainman.Stop()
|
defer chainman.Stop()
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty
|
||||||
// GetBlockReceipts returns the receipts beloniging to the block hash
|
// GetBlockReceipts returns the receipts beloniging to the block hash
|
||||||
func (sm *BlockProcessor) GetBlockReceipts(bhash common.Hash) types.Receipts {
|
func (sm *BlockProcessor) GetBlockReceipts(bhash common.Hash) types.Receipts {
|
||||||
if block := sm.ChainManager().GetBlock(bhash); block != nil {
|
if block := sm.ChainManager().GetBlock(bhash); block != nil {
|
||||||
return GetReceiptsFromBlock(sm.extraDb, block)
|
return GetBlockReceipts(sm.extraDb, block.Hash())
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -352,7 +352,7 @@ func (sm *BlockProcessor) GetBlockReceipts(bhash common.Hash) types.Receipts {
|
||||||
// where it tries to get it from the (updated) method which gets them from the receipts or
|
// where it tries to get it from the (updated) method which gets them from the receipts or
|
||||||
// the depricated way by re-processing the block.
|
// the depricated way by re-processing the block.
|
||||||
func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err error) {
|
func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err error) {
|
||||||
receipts := GetReceiptsFromBlock(sm.extraDb, block)
|
receipts := GetBlockReceipts(sm.extraDb, block.Hash())
|
||||||
if len(receipts) > 0 {
|
if len(receipts) > 0 {
|
||||||
// coalesce logs
|
// coalesce logs
|
||||||
for _, receipt := range receipts {
|
for _, receipt := range receipts {
|
||||||
|
@ -386,7 +386,7 @@ func ValidateHeader(pow pow.PoW, block *types.Header, parent *types.Block, check
|
||||||
return BlockEqualTSErr
|
return BlockEqualTSErr
|
||||||
}
|
}
|
||||||
|
|
||||||
expd := CalcDifficulty(block.Time, parent.Time(), parent.Difficulty())
|
expd := CalcDifficulty(block.Time, parent.Time(), parent.Number(), parent.Difficulty())
|
||||||
if expd.Cmp(block.Difficulty) != 0 {
|
if expd.Cmp(block.Difficulty) != 0 {
|
||||||
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Difficulty, expd)
|
return fmt.Errorf("Difficulty check failed for block %v, %v", block.Difficulty, expd)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ func proc() (*BlockProcessor, *ChainManager) {
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
var mux event.TypeMux
|
var mux event.TypeMux
|
||||||
|
|
||||||
genesis := GenesisBlock(0, db)
|
WriteTestNetGenesisBlock(db, db, 0)
|
||||||
chainMan, err := NewChainManager(genesis, db, db, db, thePow(), &mux)
|
chainMan, err := NewChainManager(db, db, db, thePow(), &mux)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
@ -34,11 +34,18 @@ var (
|
||||||
// If two or more are set to anything other than a 0 the canary
|
// If two or more are set to anything other than a 0 the canary
|
||||||
// dies a horrible death.
|
// dies a horrible death.
|
||||||
func Canary(statedb *state.StateDB) bool {
|
func Canary(statedb *state.StateDB) bool {
|
||||||
r := new(big.Int)
|
var r int
|
||||||
r.Add(r, statedb.GetState(jeff, common.Hash{}).Big())
|
if (statedb.GetState(jeff, common.Hash{}).Big().Cmp(big.NewInt(0)) > 0) {
|
||||||
r.Add(r, statedb.GetState(vitalik, common.Hash{}).Big())
|
r++
|
||||||
r.Add(r, statedb.GetState(christoph, common.Hash{}).Big())
|
}
|
||||||
r.Add(r, statedb.GetState(gav, common.Hash{}).Big())
|
if (statedb.GetState(gav, common.Hash{}).Big().Cmp(big.NewInt(0)) > 0) {
|
||||||
|
r++
|
||||||
return r.Cmp(big.NewInt(1)) > 0
|
}
|
||||||
|
if (statedb.GetState(christoph, common.Hash{}).Big().Cmp(big.NewInt(0)) > 0) {
|
||||||
|
r++
|
||||||
|
}
|
||||||
|
if (statedb.GetState(vitalik, common.Hash{}).Big().Cmp(big.NewInt(0)) > 0) {
|
||||||
|
r++
|
||||||
|
}
|
||||||
|
return r > 1
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ func makeHeader(parent *types.Block, state *state.StateDB) *types.Header {
|
||||||
Root: state.Root(),
|
Root: state.Root(),
|
||||||
ParentHash: parent.Hash(),
|
ParentHash: parent.Hash(),
|
||||||
Coinbase: parent.Coinbase(),
|
Coinbase: parent.Coinbase(),
|
||||||
Difficulty: CalcDifficulty(time, parent.Time(), parent.Difficulty()),
|
Difficulty: CalcDifficulty(time, parent.Time(), parent.Number(), parent.Difficulty()),
|
||||||
GasLimit: CalcGasLimit(parent),
|
GasLimit: CalcGasLimit(parent),
|
||||||
GasUsed: new(big.Int),
|
GasUsed: new(big.Int),
|
||||||
Number: new(big.Int).Add(parent.Number(), common.Big1),
|
Number: new(big.Int).Add(parent.Number(), common.Big1),
|
||||||
|
@ -183,7 +183,9 @@ func makeHeader(parent *types.Block, state *state.StateDB) *types.Header {
|
||||||
// InsertChain on the result of makeChain.
|
// InsertChain on the result of makeChain.
|
||||||
func newCanonical(n int, db common.Database) (*BlockProcessor, error) {
|
func newCanonical(n int, db common.Database) (*BlockProcessor, error) {
|
||||||
evmux := &event.TypeMux{}
|
evmux := &event.TypeMux{}
|
||||||
chainman, _ := NewChainManager(GenesisBlock(0, db), db, db, db, FakePow{}, evmux)
|
|
||||||
|
WriteTestNetGenesisBlock(db, db, 0)
|
||||||
|
chainman, _ := NewChainManager(db, db, db, FakePow{}, evmux)
|
||||||
bman := NewBlockProcessor(db, db, FakePow{}, chainman, evmux)
|
bman := NewBlockProcessor(db, db, FakePow{}, chainman, evmux)
|
||||||
bman.bc.SetProcessor(bman)
|
bman.bc.SetProcessor(bman)
|
||||||
parent := bman.bc.CurrentBlock()
|
parent := bman.bc.CurrentBlock()
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
@ -28,6 +28,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleGenerateChain() {
|
func ExampleGenerateChain() {
|
||||||
|
params.MinGasLimit = big.NewInt(125000) // Minimum the gas limit may ever be.
|
||||||
|
params.GenesisGasLimit = big.NewInt(3141592) // Gas limit of the Genesis block.
|
||||||
|
|
||||||
var (
|
var (
|
||||||
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||||
key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
|
key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
|
||||||
|
@ -39,7 +42,7 @@ func ExampleGenerateChain() {
|
||||||
)
|
)
|
||||||
|
|
||||||
// Ensure that key1 has some funds in the genesis block.
|
// Ensure that key1 has some funds in the genesis block.
|
||||||
genesis := GenesisBlockForTesting(db, addr1, big.NewInt(1000000))
|
genesis := WriteGenesisBlockForTesting(db, addr1, big.NewInt(1000000))
|
||||||
|
|
||||||
// This call generates a chain of 5 blocks. The function runs for
|
// This call generates a chain of 5 blocks. The function runs for
|
||||||
// each block and adds different features to gen based on the
|
// each block and adds different features to gen based on the
|
||||||
|
@ -74,7 +77,7 @@ func ExampleGenerateChain() {
|
||||||
|
|
||||||
// Import the chain. This runs all block validation rules.
|
// Import the chain. This runs all block validation rules.
|
||||||
evmux := &event.TypeMux{}
|
evmux := &event.TypeMux{}
|
||||||
chainman, _ := NewChainManager(genesis, db, db, db, FakePow{}, evmux)
|
chainman, _ := NewChainManager(db, db, db, FakePow{}, evmux)
|
||||||
chainman.SetProcessor(NewBlockProcessor(db, db, FakePow{}, chainman, evmux))
|
chainman.SetProcessor(NewBlockProcessor(db, db, FakePow{}, chainman, evmux))
|
||||||
if i, err := chainman.InsertChain(chain); err != nil {
|
if i, err := chainman.InsertChain(chain); err != nil {
|
||||||
fmt.Printf("insert error (block %d): %v\n", i, err)
|
fmt.Printf("insert error (block %d): %v\n", i, err)
|
||||||
|
@ -90,5 +93,5 @@ func ExampleGenerateChain() {
|
||||||
// last block: #5
|
// last block: #5
|
||||||
// balance of addr1: 989000
|
// balance of addr1: 989000
|
||||||
// balance of addr2: 10000
|
// balance of addr2: 10000
|
||||||
// balance of addr3: 5906250000000001000
|
// balance of addr3: 19687500000000001000
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// Package core implements the Ethereum consensus protocol.
|
// Package core implements the Ethereum consensus protocol.
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
@ -34,7 +35,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/pow"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
|
||||||
"github.com/hashicorp/golang-lru"
|
"github.com/hashicorp/golang-lru"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,10 +42,9 @@ var (
|
||||||
chainlogger = logger.NewLogger("CHAIN")
|
chainlogger = logger.NewLogger("CHAIN")
|
||||||
jsonlogger = logger.NewJsonLogger()
|
jsonlogger = logger.NewJsonLogger()
|
||||||
|
|
||||||
blockHashPre = []byte("block-hash-")
|
|
||||||
blockNumPre = []byte("block-num-")
|
|
||||||
|
|
||||||
blockInsertTimer = metrics.NewTimer("chain/inserts")
|
blockInsertTimer = metrics.NewTimer("chain/inserts")
|
||||||
|
|
||||||
|
ErrNoGenesis = errors.New("Genesis not found in chain")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -74,13 +73,11 @@ type ChainManager struct {
|
||||||
lastBlockHash common.Hash
|
lastBlockHash common.Hash
|
||||||
currentGasLimit *big.Int
|
currentGasLimit *big.Int
|
||||||
|
|
||||||
transState *state.StateDB
|
|
||||||
txState *state.ManagedState
|
|
||||||
|
|
||||||
cache *lru.Cache // cache is the LRU caching
|
cache *lru.Cache // cache is the LRU caching
|
||||||
futureBlocks *lru.Cache // future blocks are blocks added for later processing
|
futureBlocks *lru.Cache // future blocks are blocks added for later processing
|
||||||
|
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
|
running int32 // running must be called automically
|
||||||
// procInterrupt must be atomically called
|
// procInterrupt must be atomically called
|
||||||
procInterrupt int32 // interrupt signaler for block processing
|
procInterrupt int32 // interrupt signaler for block processing
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
|
@ -88,25 +85,34 @@ type ChainManager struct {
|
||||||
pow pow.PoW
|
pow pow.PoW
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChainManager(genesis *types.Block, blockDb, stateDb, extraDb common.Database, pow pow.PoW, mux *event.TypeMux) (*ChainManager, error) {
|
func NewChainManager(blockDb, stateDb, extraDb common.Database, pow pow.PoW, mux *event.TypeMux) (*ChainManager, error) {
|
||||||
cache, _ := lru.New(blockCacheLimit)
|
cache, _ := lru.New(blockCacheLimit)
|
||||||
bc := &ChainManager{
|
bc := &ChainManager{
|
||||||
blockDb: blockDb,
|
blockDb: blockDb,
|
||||||
stateDb: stateDb,
|
stateDb: stateDb,
|
||||||
extraDb: extraDb,
|
extraDb: extraDb,
|
||||||
genesisBlock: GenesisBlock(42, stateDb),
|
|
||||||
eventMux: mux,
|
eventMux: mux,
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
cache: cache,
|
cache: cache,
|
||||||
pow: pow,
|
pow: pow,
|
||||||
}
|
}
|
||||||
// Check the genesis block given to the chain manager. If the genesis block mismatches block number 0
|
|
||||||
// throw an error. If no block or the same block's found continue.
|
bc.genesisBlock = bc.GetBlockByNumber(0)
|
||||||
if g := bc.GetBlockByNumber(0); g != nil && g.Hash() != genesis.Hash() {
|
if bc.genesisBlock == nil {
|
||||||
return nil, fmt.Errorf("Genesis mismatch. Maybe different nonce (%d vs %d)? %x / %x", g.Nonce(), genesis.Nonce(), g.Hash().Bytes()[:4], genesis.Hash().Bytes()[:4])
|
reader, err := NewDefaultGenesisReader()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
bc.genesisBlock, err = WriteGenesisBlock(stateDb, blockDb, reader)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
glog.V(logger.Info).Infoln("WARNING: Wrote default ethereum genesis block")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := bc.setLastState(); err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
bc.genesisBlock = genesis
|
|
||||||
bc.setLastState()
|
|
||||||
|
|
||||||
// Check the current state of the block hashes and make sure that we do not have any of the bad blocks in our chain
|
// Check the current state of the block hashes and make sure that we do not have any of the bad blocks in our chain
|
||||||
for hash, _ := range BadHashes {
|
for hash, _ := range BadHashes {
|
||||||
|
@ -122,9 +128,7 @@ func NewChainManager(genesis *types.Block, blockDb, stateDb, extraDb common.Data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bc.transState = bc.State().Copy()
|
|
||||||
// Take ownership of this particular state
|
// Take ownership of this particular state
|
||||||
bc.txState = state.ManageState(bc.State().Copy())
|
|
||||||
|
|
||||||
bc.futureBlocks, _ = lru.New(maxFutureBlocks)
|
bc.futureBlocks, _ = lru.New(maxFutureBlocks)
|
||||||
bc.makeCache()
|
bc.makeCache()
|
||||||
|
@ -146,9 +150,6 @@ func (bc *ChainManager) SetHead(head *types.Block) {
|
||||||
bc.currentBlock = head
|
bc.currentBlock = head
|
||||||
bc.makeCache()
|
bc.makeCache()
|
||||||
|
|
||||||
statedb := state.New(head.Root(), bc.stateDb)
|
|
||||||
bc.txState = state.ManageState(statedb)
|
|
||||||
bc.transState = statedb.Copy()
|
|
||||||
bc.setTotalDifficulty(head.Td)
|
bc.setTotalDifficulty(head.Td)
|
||||||
bc.insert(head)
|
bc.insert(head)
|
||||||
bc.setLastState()
|
bc.setLastState()
|
||||||
|
@ -197,17 +198,6 @@ func (self *ChainManager) State() *state.StateDB {
|
||||||
return state.New(self.CurrentBlock().Root(), self.stateDb)
|
return state.New(self.CurrentBlock().Root(), self.stateDb)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ChainManager) TransState() *state.StateDB {
|
|
||||||
self.tsmu.RLock()
|
|
||||||
defer self.tsmu.RUnlock()
|
|
||||||
|
|
||||||
return self.transState
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *ChainManager) setTransState(statedb *state.StateDB) {
|
|
||||||
self.transState = statedb
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bc *ChainManager) recover() bool {
|
func (bc *ChainManager) recover() bool {
|
||||||
data, _ := bc.blockDb.Get([]byte("checkpoint"))
|
data, _ := bc.blockDb.Get([]byte("checkpoint"))
|
||||||
if len(data) != 0 {
|
if len(data) != 0 {
|
||||||
|
@ -226,7 +216,7 @@ func (bc *ChainManager) recover() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *ChainManager) setLastState() {
|
func (bc *ChainManager) setLastState() error {
|
||||||
data, _ := bc.blockDb.Get([]byte("LastBlock"))
|
data, _ := bc.blockDb.Get([]byte("LastBlock"))
|
||||||
if len(data) != 0 {
|
if len(data) != 0 {
|
||||||
block := bc.GetBlock(common.BytesToHash(data))
|
block := bc.GetBlock(common.BytesToHash(data))
|
||||||
|
@ -250,6 +240,8 @@ func (bc *ChainManager) setLastState() {
|
||||||
if glog.V(logger.Info) {
|
if glog.V(logger.Info) {
|
||||||
glog.Infof("Last block (#%v) %x TD=%v\n", bc.currentBlock.Number(), bc.currentBlock.Hash(), bc.td)
|
glog.Infof("Last block (#%v) %x TD=%v\n", bc.currentBlock.Number(), bc.currentBlock.Hash(), bc.td)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *ChainManager) makeCache() {
|
func (bc *ChainManager) makeCache() {
|
||||||
|
@ -272,7 +264,11 @@ func (bc *ChainManager) Reset() {
|
||||||
bc.cache, _ = lru.New(blockCacheLimit)
|
bc.cache, _ = lru.New(blockCacheLimit)
|
||||||
|
|
||||||
// Prepare the genesis block
|
// Prepare the genesis block
|
||||||
bc.write(bc.genesisBlock)
|
err := WriteBlock(bc.blockDb, bc.genesisBlock)
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatalln("db err:", err)
|
||||||
|
}
|
||||||
|
|
||||||
bc.insert(bc.genesisBlock)
|
bc.insert(bc.genesisBlock)
|
||||||
bc.currentBlock = bc.genesisBlock
|
bc.currentBlock = bc.genesisBlock
|
||||||
bc.makeCache()
|
bc.makeCache()
|
||||||
|
@ -295,7 +291,12 @@ func (bc *ChainManager) ResetWithGenesisBlock(gb *types.Block) {
|
||||||
// Prepare the genesis block
|
// Prepare the genesis block
|
||||||
gb.Td = gb.Difficulty()
|
gb.Td = gb.Difficulty()
|
||||||
bc.genesisBlock = gb
|
bc.genesisBlock = gb
|
||||||
bc.write(bc.genesisBlock)
|
|
||||||
|
err := WriteBlock(bc.blockDb, bc.genesisBlock)
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatalln("db err:", err)
|
||||||
|
}
|
||||||
|
|
||||||
bc.insert(bc.genesisBlock)
|
bc.insert(bc.genesisBlock)
|
||||||
bc.currentBlock = bc.genesisBlock
|
bc.currentBlock = bc.genesisBlock
|
||||||
bc.makeCache()
|
bc.makeCache()
|
||||||
|
@ -357,21 +358,6 @@ func (bc *ChainManager) insert(block *types.Block) {
|
||||||
bc.lastBlockHash = block.Hash()
|
bc.lastBlockHash = block.Hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *ChainManager) write(block *types.Block) {
|
|
||||||
tstart := time.Now()
|
|
||||||
|
|
||||||
enc, _ := rlp.EncodeToBytes((*types.StorageBlock)(block))
|
|
||||||
key := append(blockHashPre, block.Hash().Bytes()...)
|
|
||||||
err := bc.blockDb.Put(key, enc)
|
|
||||||
if err != nil {
|
|
||||||
glog.Fatal("db write fail:", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if glog.V(logger.Debug) {
|
|
||||||
glog.Infof("wrote block #%v %s. Took %v\n", block.Number(), common.PP(block.Hash().Bytes()), time.Since(tstart))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Accessors
|
// Accessors
|
||||||
func (bc *ChainManager) Genesis() *types.Block {
|
func (bc *ChainManager) Genesis() *types.Block {
|
||||||
return bc.genesisBlock
|
return bc.genesisBlock
|
||||||
|
@ -466,6 +452,9 @@ func (bc *ChainManager) setTotalDifficulty(td *big.Int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *ChainManager) Stop() {
|
func (bc *ChainManager) Stop() {
|
||||||
|
if !atomic.CompareAndSwapInt32(&bc.running, 0, 1) {
|
||||||
|
return
|
||||||
|
}
|
||||||
close(bc.quit)
|
close(bc.quit)
|
||||||
atomic.StoreInt32(&bc.procInterrupt, 1)
|
atomic.StoreInt32(&bc.procInterrupt, 1)
|
||||||
|
|
||||||
|
@ -527,15 +516,15 @@ func (self *ChainManager) WriteBlock(block *types.Block, queued bool) (status wr
|
||||||
self.insert(block)
|
self.insert(block)
|
||||||
self.mu.Unlock()
|
self.mu.Unlock()
|
||||||
|
|
||||||
self.setTransState(state.New(block.Root(), self.stateDb))
|
|
||||||
self.txState.SetState(state.New(block.Root(), self.stateDb))
|
|
||||||
|
|
||||||
status = CanonStatTy
|
status = CanonStatTy
|
||||||
} else {
|
} else {
|
||||||
status = SideStatTy
|
status = SideStatTy
|
||||||
}
|
}
|
||||||
|
|
||||||
self.write(block)
|
err = WriteBlock(self.blockDb, block)
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatalln("db err:", err)
|
||||||
|
}
|
||||||
// Delete from future blocks
|
// Delete from future blocks
|
||||||
self.futureBlocks.Remove(block.Hash())
|
self.futureBlocks.Remove(block.Hash())
|
||||||
|
|
||||||
|
@ -662,6 +651,8 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
|
||||||
queue[i] = ChainSplitEvent{block, logs}
|
queue[i] = ChainSplitEvent{block, logs}
|
||||||
queueEvent.splitCount++
|
queueEvent.splitCount++
|
||||||
}
|
}
|
||||||
|
PutBlockReceipts(self.extraDb, block, receipts)
|
||||||
|
|
||||||
stats.processed++
|
stats.processed++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -739,7 +730,12 @@ func (self *ChainManager) merge(oldBlock, newBlock *types.Block) error {
|
||||||
// insert blocks. Order does not matter. Last block will be written in ImportChain itself which creates the new head properly
|
// insert blocks. Order does not matter. Last block will be written in ImportChain itself which creates the new head properly
|
||||||
self.mu.Lock()
|
self.mu.Lock()
|
||||||
for _, block := range newChain {
|
for _, block := range newChain {
|
||||||
|
// insert the block in the canonical way, re-writing history
|
||||||
self.insert(block)
|
self.insert(block)
|
||||||
|
// write canonical receipts and transactions
|
||||||
|
PutTransactions(self.extraDb, block, block.Transactions())
|
||||||
|
PutReceipts(self.extraDb, GetBlockReceipts(self.extraDb, block.Hash()))
|
||||||
|
|
||||||
}
|
}
|
||||||
self.mu.Unlock()
|
self.mu.Unlock()
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
@ -48,8 +48,8 @@ func thePow() pow.PoW {
|
||||||
|
|
||||||
func theChainManager(db common.Database, t *testing.T) *ChainManager {
|
func theChainManager(db common.Database, t *testing.T) *ChainManager {
|
||||||
var eventMux event.TypeMux
|
var eventMux event.TypeMux
|
||||||
genesis := GenesisBlock(0, db)
|
WriteTestNetGenesisBlock(db, db, 0)
|
||||||
chainMan, err := NewChainManager(genesis, db, db, db, thePow(), &eventMux)
|
chainMan, err := NewChainManager(db, db, db, thePow(), &eventMux)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("failed creating chainmanager:", err)
|
t.Error("failed creating chainmanager:", err)
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
|
@ -125,7 +125,7 @@ func testChain(chainB types.Blocks, bman *BlockProcessor) (*big.Int, error) {
|
||||||
|
|
||||||
bman.bc.mu.Lock()
|
bman.bc.mu.Lock()
|
||||||
{
|
{
|
||||||
bman.bc.write(block)
|
WriteBlock(bman.bc.blockDb, block)
|
||||||
}
|
}
|
||||||
bman.bc.mu.Unlock()
|
bman.bc.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -362,25 +362,6 @@ func TestChainMultipleInsertions(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetBlocksFromHash(t *testing.T) {
|
|
||||||
t.Skip("Skipped: outdated test files")
|
|
||||||
|
|
||||||
db, _ := ethdb.NewMemDatabase()
|
|
||||||
chainMan := theChainManager(db, t)
|
|
||||||
chain, err := loadChain("valid1", t)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
t.FailNow()
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, block := range chain {
|
|
||||||
chainMan.write(block)
|
|
||||||
}
|
|
||||||
|
|
||||||
blocks := chainMan.GetBlocksFromHash(chain[len(chain)-1].Hash(), 4)
|
|
||||||
fmt.Println(blocks)
|
|
||||||
}
|
|
||||||
|
|
||||||
type bproc struct{}
|
type bproc struct{}
|
||||||
|
|
||||||
func (bproc) Process(*types.Block) (state.Logs, types.Receipts, error) { return nil, nil, nil }
|
func (bproc) Process(*types.Block) (state.Logs, types.Receipts, error) { return nil, nil, nil }
|
||||||
|
@ -411,14 +392,18 @@ func chm(genesis *types.Block, db common.Database) *ChainManager {
|
||||||
bc.futureBlocks, _ = lru.New(100)
|
bc.futureBlocks, _ = lru.New(100)
|
||||||
bc.processor = bproc{}
|
bc.processor = bproc{}
|
||||||
bc.ResetWithGenesisBlock(genesis)
|
bc.ResetWithGenesisBlock(genesis)
|
||||||
bc.txState = state.ManageState(bc.State())
|
|
||||||
|
|
||||||
return bc
|
return bc
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReorgLongest(t *testing.T) {
|
func TestReorgLongest(t *testing.T) {
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
genesis := GenesisBlock(0, db)
|
|
||||||
|
genesis, err := WriteTestNetGenesisBlock(db, db, 0)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
bc := chm(genesis, db)
|
bc := chm(genesis, db)
|
||||||
|
|
||||||
chain1 := makeChainWithDiff(genesis, []int{1, 2, 4}, 10)
|
chain1 := makeChainWithDiff(genesis, []int{1, 2, 4}, 10)
|
||||||
|
@ -437,7 +422,11 @@ func TestReorgLongest(t *testing.T) {
|
||||||
|
|
||||||
func TestReorgShortest(t *testing.T) {
|
func TestReorgShortest(t *testing.T) {
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
genesis := GenesisBlock(0, db)
|
genesis, err := WriteTestNetGenesisBlock(db, db, 0)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
bc := chm(genesis, db)
|
bc := chm(genesis, db)
|
||||||
|
|
||||||
chain1 := makeChainWithDiff(genesis, []int{1, 2, 3, 4}, 10)
|
chain1 := makeChainWithDiff(genesis, []int{1, 2, 3, 4}, 10)
|
||||||
|
@ -457,7 +446,11 @@ func TestReorgShortest(t *testing.T) {
|
||||||
func TestInsertNonceError(t *testing.T) {
|
func TestInsertNonceError(t *testing.T) {
|
||||||
for i := 1; i < 25 && !t.Failed(); i++ {
|
for i := 1; i < 25 && !t.Failed(); i++ {
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
genesis := GenesisBlock(0, db)
|
genesis, err := WriteTestNetGenesisBlock(db, db, 0)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
bc := chm(genesis, db)
|
bc := chm(genesis, db)
|
||||||
bc.processor = NewBlockProcessor(db, db, bc.pow, bc, bc.eventMux)
|
bc.processor = NewBlockProcessor(db, db, bc.pow, bc, bc.eventMux)
|
||||||
blocks := makeChain(bc.currentBlock, i, db, 0)
|
blocks := makeChain(bc.currentBlock, i, db, 0)
|
||||||
|
@ -491,6 +484,7 @@ func TestInsertNonceError(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func TestGenesisMismatch(t *testing.T) {
|
func TestGenesisMismatch(t *testing.T) {
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
var mux event.TypeMux
|
var mux event.TypeMux
|
||||||
|
@ -505,6 +499,7 @@ func TestGenesisMismatch(t *testing.T) {
|
||||||
t.Error("expected genesis mismatch error")
|
t.Error("expected genesis mismatch error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// failpow returns false from Verify for a certain block number.
|
// failpow returns false from Verify for a certain block number.
|
||||||
type failpow struct{ num uint64 }
|
type failpow struct{ num uint64 }
|
||||||
|
|
|
@ -1,24 +1,25 @@
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
@ -28,10 +29,16 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
blockHashPre = []byte("block-hash-")
|
||||||
|
blockNumPre = []byte("block-num-")
|
||||||
|
expDiffPeriod = big.NewInt(100000)
|
||||||
|
)
|
||||||
|
|
||||||
// CalcDifficulty is the difficulty adjustment algorithm. It returns
|
// CalcDifficulty is the difficulty adjustment algorithm. It returns
|
||||||
// the difficulty that a new block b should have when created at time
|
// the difficulty that a new block b should have when created at time
|
||||||
// given the parent block's time and difficulty.
|
// given the parent block's time and difficulty.
|
||||||
func CalcDifficulty(time, parentTime uint64, parentDiff *big.Int) *big.Int {
|
func CalcDifficulty(time, parentTime uint64, parentNumber, parentDiff *big.Int) *big.Int {
|
||||||
diff := new(big.Int)
|
diff := new(big.Int)
|
||||||
adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor)
|
adjust := new(big.Int).Div(parentDiff, params.DifficultyBoundDivisor)
|
||||||
bigTime := new(big.Int)
|
bigTime := new(big.Int)
|
||||||
|
@ -46,8 +53,19 @@ func CalcDifficulty(time, parentTime uint64, parentDiff *big.Int) *big.Int {
|
||||||
diff.Sub(parentDiff, adjust)
|
diff.Sub(parentDiff, adjust)
|
||||||
}
|
}
|
||||||
if diff.Cmp(params.MinimumDifficulty) < 0 {
|
if diff.Cmp(params.MinimumDifficulty) < 0 {
|
||||||
return params.MinimumDifficulty
|
diff = params.MinimumDifficulty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
periodCount := new(big.Int).Add(parentNumber, common.Big1)
|
||||||
|
periodCount.Div(periodCount, expDiffPeriod)
|
||||||
|
if periodCount.Cmp(common.Big1) > 0 {
|
||||||
|
// diff = diff + 2^(periodCount - 2)
|
||||||
|
expDiff := periodCount.Sub(periodCount, common.Big2)
|
||||||
|
expDiff.Exp(common.Big2, expDiff, nil)
|
||||||
|
diff.Add(diff, expDiff)
|
||||||
|
diff = common.BigMax(diff, params.MinimumDifficulty)
|
||||||
|
}
|
||||||
|
|
||||||
return diff
|
return diff
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,17 +81,30 @@ func CalcTD(block, parent *types.Block) *big.Int {
|
||||||
|
|
||||||
// CalcGasLimit computes the gas limit of the next block after parent.
|
// CalcGasLimit computes the gas limit of the next block after parent.
|
||||||
// The result may be modified by the caller.
|
// The result may be modified by the caller.
|
||||||
|
// This is miner strategy, not consensus protocol.
|
||||||
func CalcGasLimit(parent *types.Block) *big.Int {
|
func CalcGasLimit(parent *types.Block) *big.Int {
|
||||||
decay := new(big.Int).Div(parent.GasLimit(), params.GasLimitBoundDivisor)
|
// contrib = (parentGasUsed * 3 / 2) / 1024
|
||||||
contrib := new(big.Int).Mul(parent.GasUsed(), big.NewInt(3))
|
contrib := new(big.Int).Mul(parent.GasUsed(), big.NewInt(3))
|
||||||
contrib = contrib.Div(contrib, big.NewInt(2))
|
contrib = contrib.Div(contrib, big.NewInt(2))
|
||||||
contrib = contrib.Div(contrib, params.GasLimitBoundDivisor)
|
contrib = contrib.Div(contrib, params.GasLimitBoundDivisor)
|
||||||
|
|
||||||
|
// decay = parentGasLimit / 1024 -1
|
||||||
|
decay := new(big.Int).Div(parent.GasLimit(), params.GasLimitBoundDivisor)
|
||||||
|
decay.Sub(decay, big.NewInt(1))
|
||||||
|
|
||||||
|
/*
|
||||||
|
strategy: gasLimit of block-to-mine is set based on parent's
|
||||||
|
gasUsed value. if parentGasUsed > parentGasLimit * (2/3) then we
|
||||||
|
increase it, otherwise lower it (or leave it unchanged if it's right
|
||||||
|
at that usage) the amount increased/decreased depends on how far away
|
||||||
|
from parentGasLimit * (2/3) parentGasUsed is.
|
||||||
|
*/
|
||||||
gl := new(big.Int).Sub(parent.GasLimit(), decay)
|
gl := new(big.Int).Sub(parent.GasLimit(), decay)
|
||||||
gl = gl.Add(gl, contrib)
|
gl = gl.Add(gl, contrib)
|
||||||
gl = gl.Add(gl, big.NewInt(1))
|
|
||||||
gl.Set(common.BigMax(gl, params.MinGasLimit))
|
gl.Set(common.BigMax(gl, params.MinGasLimit))
|
||||||
|
|
||||||
|
// however, if we're now below the target (GenesisGasLimit) we increase the
|
||||||
|
// limit as much as we can (parentGasLimit / 1024 -1)
|
||||||
if gl.Cmp(params.GenesisGasLimit) < 0 {
|
if gl.Cmp(params.GenesisGasLimit) < 0 {
|
||||||
gl.Add(parent.GasLimit(), decay)
|
gl.Add(parent.GasLimit(), decay)
|
||||||
gl.Set(common.BigMin(gl, params.GenesisGasLimit))
|
gl.Set(common.BigMin(gl, params.GenesisGasLimit))
|
||||||
|
@ -105,16 +136,44 @@ func GetBlockByNumber(db common.Database, number uint64) *types.Block {
|
||||||
return GetBlockByHash(db, common.BytesToHash(key))
|
return GetBlockByHash(db, common.BytesToHash(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteHead force writes the current head
|
// WriteCanonNumber writes the canonical hash for the given block
|
||||||
func WriteHead(db common.Database, block *types.Block) error {
|
func WriteCanonNumber(db common.Database, block *types.Block) error {
|
||||||
key := append(blockNumPre, block.Number().Bytes()...)
|
key := append(blockNumPre, block.Number().Bytes()...)
|
||||||
err := db.Put(key, block.Hash().Bytes())
|
err := db.Put(key, block.Hash().Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteHead force writes the current head
|
||||||
|
func WriteHead(db common.Database, block *types.Block) error {
|
||||||
|
err := WriteCanonNumber(db, block)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
err = db.Put([]byte("LastBlock"), block.Hash().Bytes())
|
err = db.Put([]byte("LastBlock"), block.Hash().Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteBlock writes a block to the database
|
||||||
|
func WriteBlock(db common.Database, block *types.Block) error {
|
||||||
|
tstart := time.Now()
|
||||||
|
|
||||||
|
enc, _ := rlp.EncodeToBytes((*types.StorageBlock)(block))
|
||||||
|
key := append(blockHashPre, block.Hash().Bytes()...)
|
||||||
|
err := db.Put(key, enc)
|
||||||
|
if err != nil {
|
||||||
|
glog.Fatal("db write fail:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if glog.V(logger.Debug) {
|
||||||
|
glog.Infof("wrote block #%v %s. Took %v\n", block.Number(), common.PP(block.Hash().Bytes()), time.Since(tstart))
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
// Copyright 2015 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library 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 Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"math/big"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
type diffTest struct {
|
||||||
|
ParentTimestamp uint64
|
||||||
|
ParentDifficulty *big.Int
|
||||||
|
CurrentTimestamp uint64
|
||||||
|
CurrentBlocknumber *big.Int
|
||||||
|
CurrentDifficulty *big.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *diffTest) UnmarshalJSON(b []byte) (err error) {
|
||||||
|
var ext struct {
|
||||||
|
ParentTimestamp string
|
||||||
|
ParentDifficulty string
|
||||||
|
CurrentTimestamp string
|
||||||
|
CurrentBlocknumber string
|
||||||
|
CurrentDifficulty string
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(b, &ext); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
d.ParentTimestamp = common.String2Big(ext.ParentTimestamp).Uint64()
|
||||||
|
d.ParentDifficulty = common.String2Big(ext.ParentDifficulty)
|
||||||
|
d.CurrentTimestamp = common.String2Big(ext.CurrentTimestamp).Uint64()
|
||||||
|
d.CurrentBlocknumber = common.String2Big(ext.CurrentBlocknumber)
|
||||||
|
d.CurrentDifficulty = common.String2Big(ext.CurrentDifficulty)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDifficulty(t *testing.T) {
|
||||||
|
file, err := os.Open("../tests/files/BasicTests/difficulty.json")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
tests := make(map[string]diffTest)
|
||||||
|
err = json.NewDecoder(file).Decode(&tests)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, test := range tests {
|
||||||
|
number := new(big.Int).Sub(test.CurrentBlocknumber, big.NewInt(1))
|
||||||
|
diff := CalcDifficulty(test.CurrentTimestamp, test.ParentTimestamp, number, test.ParentDifficulty)
|
||||||
|
if diff.Cmp(test.CurrentDifficulty) != 0 {
|
||||||
|
t.Error(name, "failed. Expected", test.CurrentDifficulty, "and calculated", diff)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2014 The go-ethereum Authors
|
// Copyright 2014 The go-ethereum Authors
|
||||||
// This file is part of go-ethereum.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// go-ethereum is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as published by
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
//
|
//
|
||||||
// go-ethereum is distributed in the hope that it will be useful,
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
// GNU Lesser General Public License for more details.
|
// GNU Lesser General Public License for more details.
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue