aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/utils
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-04 21:39:15 +0800
committerobscuren <geffobscura@gmail.com>2015-01-04 21:39:15 +0800
commit987119cd4adcdbc7ebfd0bbb027a0c9e2a7487e9 (patch)
tree32ff13edca8c3d9b61b303f7d314291d0f216574 /cmd/utils
parent1b905675465d96227f1a8144fe592e76f646f559 (diff)
parent08b03afa4bb3a40d2faf6543bc884a8ece5be2a1 (diff)
downloadgo-tangerine-987119cd4adcdbc7ebfd0bbb027a0c9e2a7487e9.tar
go-tangerine-987119cd4adcdbc7ebfd0bbb027a0c9e2a7487e9.tar.gz
go-tangerine-987119cd4adcdbc7ebfd0bbb027a0c9e2a7487e9.tar.bz2
go-tangerine-987119cd4adcdbc7ebfd0bbb027a0c9e2a7487e9.tar.lz
go-tangerine-987119cd4adcdbc7ebfd0bbb027a0c9e2a7487e9.tar.xz
go-tangerine-987119cd4adcdbc7ebfd0bbb027a0c9e2a7487e9.tar.zst
go-tangerine-987119cd4adcdbc7ebfd0bbb027a0c9e2a7487e9.zip
Merge branch 'poc8' into docbranch
Diffstat (limited to 'cmd/utils')
-rw-r--r--cmd/utils/cmd.go103
-rw-r--r--cmd/utils/vm_env.go12
2 files changed, 14 insertions, 101 deletions
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index 466c51383..6b1cf3726 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -2,9 +2,6 @@ package utils
import (
"fmt"
- "io"
- "log"
- "net"
"os"
"os/signal"
"path"
@@ -16,11 +13,9 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
- "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/miner"
- "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/xeth"
@@ -52,15 +47,8 @@ func RunInterruptCallbacks(sig os.Signal) {
}
}
-func AbsolutePath(Datadir string, filename string) string {
- if path.IsAbs(filename) {
- return filename
- }
- return path.Join(Datadir, filename)
-}
-
func openLogFile(Datadir string, filename string) *os.File {
- path := AbsolutePath(Datadir, filename)
+ path := ethutil.AbsolutePath(Datadir, filename)
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
panic(fmt.Sprintf("error opening log file '%s': %v", filename, err))
@@ -76,23 +64,13 @@ func confirm(message string) bool {
if r == "n" || r == "y" {
break
} else {
- fmt.Printf("Yes or no?", r)
+ fmt.Printf("Yes or no? (%s)", r)
}
}
return r == "y"
}
-func DBSanityCheck(db ethutil.Database) error {
- d, _ := db.Get([]byte("ProtocolVersion"))
- protov := ethutil.NewValue(d).Uint()
- if protov != eth.ProtocolVersion && protov != 0 {
- return fmt.Errorf("Database version mismatch. Protocol(%d / %d). `rm -rf %s`", protov, eth.ProtocolVersion, ethutil.Config.ExecPath+"/database")
- }
-
- return nil
-}
-
-func InitDataDir(Datadir string) {
+func initDataDir(Datadir string) {
_, err := os.Stat(Datadir)
if err != nil {
if os.IsNotExist(err) {
@@ -102,26 +80,8 @@ func InitDataDir(Datadir string) {
}
}
-func InitLogging(Datadir string, LogFile string, LogLevel int, DebugFile string) logger.LogSystem {
- var writer io.Writer
- if LogFile == "" {
- writer = os.Stdout
- } else {
- writer = openLogFile(Datadir, LogFile)
- }
-
- sys := logger.NewStdLogSystem(writer, log.LstdFlags, logger.LogLevel(LogLevel))
- logger.AddLogSystem(sys)
- if DebugFile != "" {
- writer = openLogFile(Datadir, DebugFile)
- logger.AddLogSystem(logger.NewStdLogSystem(writer, log.LstdFlags, logger.DebugLevel))
- }
-
- return sys
-}
-
func InitConfig(vmType int, ConfigFile string, Datadir string, EnvPrefix string) *ethutil.ConfigManager {
- InitDataDir(Datadir)
+ initDataDir(Datadir)
cfg := ethutil.ReadConfig(ConfigFile, Datadir, EnvPrefix)
cfg.VmType = vmType
@@ -138,43 +98,6 @@ func exit(err error) {
os.Exit(status)
}
-func NewDatabase() ethutil.Database {
- db, err := ethdb.NewLDBDatabase("database")
- if err != nil {
- exit(err)
- }
- return db
-}
-
-func NewClientIdentity(clientIdentifier, version, customIdentifier string, pubkey string) *p2p.SimpleClientIdentity {
- return p2p.NewSimpleClientIdentity(clientIdentifier, version, customIdentifier, pubkey)
-}
-
-func NatType(natType string, gateway string) (nat p2p.NAT) {
- switch natType {
- case "UPNP":
- nat = p2p.UPNP()
- case "PMP":
- ip := net.ParseIP(gateway)
- if ip == nil {
- clilogger.Fatalf("cannot resolve PMP gateway IP %s", gateway)
- }
- nat = p2p.PMP(ip)
- case "":
- default:
- clilogger.Fatalf("unrecognised NAT type '%s'", natType)
- }
- return
-}
-
-func NewEthereum(db ethutil.Database, clientIdentity p2p.ClientIdentity, keyManager *crypto.KeyManager, nat p2p.NAT, OutboundPort string, MaxPeer int) *eth.Ethereum {
- ethereum, err := eth.New(db, clientIdentity, keyManager, nat, OutboundPort, MaxPeer)
- if err != nil {
- clilogger.Fatalln("eth start err:", err)
- }
- return ethereum
-}
-
func StartEthereum(ethereum *eth.Ethereum, UseSeed bool) {
clilogger.Infof("Starting %s", ethereum.ClientIdentity())
ethereum.Start(UseSeed)
@@ -184,24 +107,6 @@ func StartEthereum(ethereum *eth.Ethereum, UseSeed bool) {
})
}
-func ShowGenesis(ethereum *eth.Ethereum) {
- clilogger.Infoln(ethereum.ChainManager().Genesis())
- exit(nil)
-}
-
-func NewKeyManager(KeyStore string, Datadir string, db ethutil.Database) *crypto.KeyManager {
- var keyManager *crypto.KeyManager
- switch {
- case KeyStore == "db":
- keyManager = crypto.NewDBKeyManager(db)
- case KeyStore == "file":
- keyManager = crypto.NewFileKeyManager(Datadir)
- default:
- exit(fmt.Errorf("unknown keystore type: %s", KeyStore))
- }
- return keyManager
-}
-
func DefaultAssetPath() string {
var assetPath string
// If the current working directory is the go-ethereum dir
diff --git a/cmd/utils/vm_env.go b/cmd/utils/vm_env.go
index 19091bdc5..acc2ffad9 100644
--- a/cmd/utils/vm_env.go
+++ b/cmd/utils/vm_env.go
@@ -10,6 +10,7 @@ import (
)
type VMEnv struct {
+ chain *core.ChainManager
state *state.StateDB
block *types.Block
@@ -20,8 +21,9 @@ type VMEnv struct {
Gas *big.Int
}
-func NewEnv(state *state.StateDB, block *types.Block, transactor []byte, value *big.Int) *VMEnv {
+func NewEnv(chain *core.ChainManager, state *state.StateDB, block *types.Block, transactor []byte, value *big.Int) *VMEnv {
return &VMEnv{
+ chain: chain,
state: state,
block: block,
transactor: transactor,
@@ -35,12 +37,18 @@ func (self *VMEnv) PrevHash() []byte { return self.block.ParentHash() }
func (self *VMEnv) Coinbase() []byte { return self.block.Coinbase() }
func (self *VMEnv) Time() int64 { return self.block.Time() }
func (self *VMEnv) Difficulty() *big.Int { return self.block.Difficulty() }
-func (self *VMEnv) BlockHash() []byte { return self.block.Hash() }
func (self *VMEnv) GasLimit() *big.Int { return self.block.GasLimit() }
func (self *VMEnv) Value() *big.Int { return self.value }
func (self *VMEnv) State() *state.StateDB { return self.state }
func (self *VMEnv) Depth() int { return self.depth }
func (self *VMEnv) SetDepth(i int) { self.depth = i }
+func (self *VMEnv) GetHash(n uint64) []byte {
+ if block := self.chain.GetBlockByNumber(n); block != nil {
+ return block.Hash()
+ }
+
+ return nil
+}
func (self *VMEnv) AddLog(log state.Log) {
self.state.AddLog(log)
}