Merge branch 'frontier/js' into frontier/nodeadmin.js
This commit is contained in:
commit
b3e133dd15
6
Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go
generated
vendored
6
Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go
generated
vendored
@ -32,7 +32,7 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/pow"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
)
|
)
|
||||||
@ -337,7 +337,7 @@ func (pow *Ethash) Search(block pow.Block, stop <-chan struct{}) (uint64, []byte
|
|||||||
pow.HashRate = int64(hashes)
|
pow.HashRate = int64(hashes)
|
||||||
|
|
||||||
C.ethash_full(&ret, pow.dag.dag, pow.dag.paramsAndCache.params, cMiningHash, C.uint64_t(nonce))
|
C.ethash_full(&ret, pow.dag.dag, pow.dag.paramsAndCache.params, cMiningHash, C.uint64_t(nonce))
|
||||||
result := ethutil.Bytes2Big(C.GoBytes(unsafe.Pointer(&ret.result[0]), C.int(32)))
|
result := common.Bytes2Big(C.GoBytes(unsafe.Pointer(&ret.result[0]), C.int(32)))
|
||||||
|
|
||||||
// TODO: disagrees with the spec https://github.com/ethereum/wiki/wiki/Ethash#mining
|
// TODO: disagrees with the spec https://github.com/ethereum/wiki/wiki/Ethash#mining
|
||||||
if result.Cmp(target) <= 0 {
|
if result.Cmp(target) <= 0 {
|
||||||
@ -402,7 +402,7 @@ func (pow *Ethash) verify(hash []byte, mixDigest []byte, difficulty *big.Int, bl
|
|||||||
|
|
||||||
C.ethash_light(ret, pAc.cache, pAc.params, chash, cnonce)
|
C.ethash_light(ret, pAc.cache, pAc.params, chash, cnonce)
|
||||||
|
|
||||||
result := ethutil.Bytes2Big(C.GoBytes(unsafe.Pointer(&ret.result[0]), C.int(32)))
|
result := common.Bytes2Big(C.GoBytes(unsafe.Pointer(&ret.result[0]), C.int(32)))
|
||||||
return result.Cmp(target) <= 0
|
return result.Cmp(target) <= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var big_t = reflect.TypeOf(&big.Int{})
|
var big_t = reflect.TypeOf(&big.Int{})
|
||||||
@ -38,13 +38,13 @@ var big_ts = reflect.TypeOf([]*big.Int(nil))
|
|||||||
|
|
||||||
// U256 will ensure unsigned 256bit on big nums
|
// U256 will ensure unsigned 256bit on big nums
|
||||||
func U256(n *big.Int) []byte {
|
func U256(n *big.Int) []byte {
|
||||||
return ethutil.LeftPadBytes(ethutil.U256(n).Bytes(), 32)
|
return common.LeftPadBytes(common.U256(n).Bytes(), 32)
|
||||||
}
|
}
|
||||||
|
|
||||||
func S256(n *big.Int) []byte {
|
func S256(n *big.Int) []byte {
|
||||||
sint := ethutil.S256(n)
|
sint := common.S256(n)
|
||||||
ret := ethutil.LeftPadBytes(sint.Bytes(), 32)
|
ret := common.LeftPadBytes(sint.Bytes(), 32)
|
||||||
if sint.Cmp(ethutil.Big0) < 0 {
|
if sint.Cmp(common.Big0) < 0 {
|
||||||
for i, b := range ret {
|
for i, b := range ret {
|
||||||
if b == 0 {
|
if b == 0 {
|
||||||
ret[i] = 1
|
ret[i] = 1
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -157,7 +157,7 @@ func (t Type) pack(v interface{}) ([]byte, error) {
|
|||||||
if t.Size > -1 && value.Len() > t.Size {
|
if t.Size > -1 && value.Len() > t.Size {
|
||||||
return nil, fmt.Errorf("%v out of bound. %d for %d", value.Kind(), value.Len(), t.Size)
|
return nil, fmt.Errorf("%v out of bound. %d for %d", value.Kind(), value.Len(), t.Size)
|
||||||
}
|
}
|
||||||
return []byte(ethutil.LeftPadString(t.String(), 32)), nil
|
return []byte(common.LeftPadString(t.String(), 32)), nil
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
if t.Size > -1 && value.Len() > t.Size {
|
if t.Size > -1 && value.Len() > t.Size {
|
||||||
return nil, fmt.Errorf("%v out of bound. %d for %d", value.Kind(), value.Len(), t.Size)
|
return nil, fmt.Errorf("%v out of bound. %d for %d", value.Kind(), value.Len(), t.Size)
|
||||||
@ -165,7 +165,7 @@ func (t Type) pack(v interface{}) ([]byte, error) {
|
|||||||
|
|
||||||
// Address is a special slice. The slice acts as one rather than a list of elements.
|
// Address is a special slice. The slice acts as one rather than a list of elements.
|
||||||
if t.T == AddressTy {
|
if t.T == AddressTy {
|
||||||
return ethutil.LeftPadBytes(v.([]byte), 32), nil
|
return common.LeftPadBytes(v.([]byte), 32), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signed / Unsigned check
|
// Signed / Unsigned check
|
||||||
@ -180,9 +180,9 @@ func (t Type) pack(v interface{}) ([]byte, error) {
|
|||||||
return packed, nil
|
return packed, nil
|
||||||
case reflect.Bool:
|
case reflect.Bool:
|
||||||
if value.Bool() {
|
if value.Bool() {
|
||||||
return ethutil.LeftPadBytes(ethutil.Big1.Bytes(), 32), nil
|
return common.LeftPadBytes(common.Big1.Bytes(), 32), nil
|
||||||
} else {
|
} else {
|
||||||
return ethutil.LeftPadBytes(ethutil.Big0.Bytes(), 32), nil
|
return common.LeftPadBytes(common.Big0.Bytes(), 32), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ethereum/go-ethereum/blockpool/test"
|
"github.com/ethereum/go-ethereum/blockpool/test"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPeerWithKnownBlock(t *testing.T) {
|
func TestPeerWithKnownBlock(t *testing.T) {
|
||||||
@ -69,9 +69,9 @@ func TestPeerPromotionByOptionalTdOnBlock(t *testing.T) {
|
|||||||
hashes := blockPoolTester.hashPool.IndexesToHashes([]int{2, 3})
|
hashes := blockPoolTester.hashPool.IndexesToHashes([]int{2, 3})
|
||||||
peer1.waitBlocksRequests(3)
|
peer1.waitBlocksRequests(3)
|
||||||
blockPool.AddBlock(&types.Block{
|
blockPool.AddBlock(&types.Block{
|
||||||
HeaderHash: ethutil.Bytes(hashes[1]),
|
HeaderHash: common.Bytes(hashes[1]),
|
||||||
ParentHeaderHash: ethutil.Bytes(hashes[0]),
|
ParentHeaderHash: common.Bytes(hashes[0]),
|
||||||
Td: ethutil.Big3,
|
Td: common.Big3,
|
||||||
}, "peer1")
|
}, "peer1")
|
||||||
|
|
||||||
blockPool.RemovePeer("peer2")
|
blockPool.RemovePeer("peer2")
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/blockpool/test"
|
"github.com/ethereum/go-ethereum/blockpool/test"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/errs"
|
"github.com/ethereum/go-ethereum/errs"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/pow"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -315,7 +315,7 @@ func (self *peerTester) sendBlocks(indexes ...int) {
|
|||||||
hashes := self.hashPool.IndexesToHashes(indexes)
|
hashes := self.hashPool.IndexesToHashes(indexes)
|
||||||
for i := 1; i < len(hashes); i++ {
|
for i := 1; i < len(hashes); i++ {
|
||||||
fmt.Printf("adding block %v %x\n", indexes[i], hashes[i][:4])
|
fmt.Printf("adding block %v %x\n", indexes[i], hashes[i][:4])
|
||||||
self.blockPool.AddBlock(&types.Block{HeaderHash: ethutil.Bytes(hashes[i]), ParentHeaderHash: ethutil.Bytes(hashes[i-1])}, self.id)
|
self.blockPool.AddBlock(&types.Block{HeaderHash: common.Bytes(hashes[i]), ParentHeaderHash: common.Bytes(hashes[i-1])}, self.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/errs"
|
"github.com/ethereum/go-ethereum/errs"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type peer struct {
|
type peer struct {
|
||||||
@ -230,7 +230,7 @@ func (self *peers) addPeer(
|
|||||||
}
|
}
|
||||||
best = true
|
best = true
|
||||||
} else {
|
} else {
|
||||||
currentTD := ethutil.Big0
|
currentTD := common.Big0
|
||||||
if self.best != nil {
|
if self.best != nil {
|
||||||
currentTD = self.best.td
|
currentTD = self.best.td
|
||||||
}
|
}
|
||||||
@ -264,7 +264,7 @@ func (self *peers) removePeer(id string) {
|
|||||||
if self.best == p {
|
if self.best == p {
|
||||||
var newp *peer
|
var newp *peer
|
||||||
// FIXME: own TD
|
// FIXME: own TD
|
||||||
max := ethutil.Big0
|
max := common.Big0
|
||||||
// peer with the highest self-acclaimed TD is chosen
|
// peer with the highest self-acclaimed TD is chosen
|
||||||
for _, pp := range self.peers {
|
for _, pp := range self.peers {
|
||||||
if pp.td.Cmp(max) > 0 {
|
if pp.td.Cmp(max) > 0 {
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/vm"
|
"github.com/ethereum/go-ethereum/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ func main() {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
code = ethutil.Hex2Bytes(string(code[:len(code)-1]))
|
code = common.Hex2Bytes(string(code[:len(code)-1]))
|
||||||
fmt.Printf("%x\n", code)
|
fmt.Printf("%x\n", code)
|
||||||
|
|
||||||
for pc := uint64(0); pc < uint64(len(code)); pc++ {
|
for pc := uint64(0); pc < uint64(len(code)); pc++ {
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/tests"
|
"github.com/ethereum/go-ethereum/tests"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ func runblocktest(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
|
cfg := utils.MakeEthConfig(ClientIdentifier, Version, ctx)
|
||||||
cfg.NewDB = func(path string) (ethutil.Database, error) { return ethdb.NewMemDatabase() }
|
cfg.NewDB = func(path string) (common.Database, error) { return ethdb.NewMemDatabase() }
|
||||||
ethereum, err := eth.New(cfg)
|
ethereum, err := eth.New(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("%v", err)
|
utils.Fatalf("%v", err)
|
||||||
|
@ -31,9 +31,9 @@ import (
|
|||||||
|
|
||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"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/ethutil"
|
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
"github.com/peterh/liner"
|
"github.com/peterh/liner"
|
||||||
@ -91,9 +91,9 @@ Use "ethereum dump 0" to dump the genesis block.
|
|||||||
{
|
{
|
||||||
Action: console,
|
Action: console,
|
||||||
Name: "console",
|
Name: "console",
|
||||||
Usage: `Ethereum Frontier Console: interactive JavaScript environment`,
|
Usage: `Ethereum Console: interactive JavaScript environment`,
|
||||||
Description: `
|
Description: `
|
||||||
Frontier Console is an interactive shell for the Ethereum Frontier JavaScript runtime environment which exposes a node admin interface as well as the DAPP JavaScript API.
|
Console is an interactive shell for the Ethereum JavaScript runtime environment which exposes a node admin interface as well as the DAPP JavaScript API.
|
||||||
See https://github.com/ethereum/go-ethereum/wiki/Frontier-Console
|
See https://github.com/ethereum/go-ethereum/wiki/Frontier-Console
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
@ -102,7 +102,7 @@ See https://github.com/ethereum/go-ethereum/wiki/Frontier-Console
|
|||||||
Name: "js",
|
Name: "js",
|
||||||
Usage: `executes the given JavaScript files in the Ethereum Frontier JavaScript VM`,
|
Usage: `executes the given JavaScript files in the Ethereum Frontier JavaScript VM`,
|
||||||
Description: `
|
Description: `
|
||||||
The Ethereum Frontier JavaScript VM exposes a node admin interface as well as the DAPP JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Frontier-Console
|
The Ethereum JavaScript VM exposes a node admin interface as well as the DAPP JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Frontier-Console
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -218,7 +218,7 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
|
|||||||
}
|
}
|
||||||
am := eth.AccountManager()
|
am := eth.AccountManager()
|
||||||
// Attempt to unlock the account
|
// Attempt to unlock the account
|
||||||
err := am.Unlock(ethutil.FromHex(split[0]), split[1])
|
err := am.Unlock(common.FromHex(split[0]), split[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("Unlock account failed '%v'", err)
|
utils.Fatalf("Unlock account failed '%v'", err)
|
||||||
}
|
}
|
||||||
@ -302,7 +302,7 @@ func dump(ctx *cli.Context) {
|
|||||||
for _, arg := range ctx.Args() {
|
for _, arg := range ctx.Args() {
|
||||||
var block *types.Block
|
var block *types.Block
|
||||||
if hashish(arg) {
|
if hashish(arg) {
|
||||||
block = chainmgr.GetBlock(ethutil.Hex2Bytes(arg))
|
block = chainmgr.GetBlock(common.Hex2Bytes(arg))
|
||||||
} else {
|
} else {
|
||||||
num, _ := strconv.Atoi(arg)
|
num, _ := strconv.Atoi(arg)
|
||||||
block = chainmgr.GetBlockByNumber(uint64(num))
|
block = chainmgr.GetBlockByNumber(uint64(num))
|
||||||
|
@ -34,7 +34,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
"github.com/ethereum/go-ethereum/tests/helper"
|
"github.com/ethereum/go-ethereum/tests/helper"
|
||||||
@ -48,13 +48,13 @@ type Log struct {
|
|||||||
BloomF string `json:"bloom"`
|
BloomF string `json:"bloom"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self Log) Address() []byte { return ethutil.Hex2Bytes(self.AddressF) }
|
func (self Log) Address() []byte { return common.Hex2Bytes(self.AddressF) }
|
||||||
func (self Log) Data() []byte { return ethutil.Hex2Bytes(self.DataF) }
|
func (self Log) Data() []byte { return common.Hex2Bytes(self.DataF) }
|
||||||
func (self Log) RlpData() interface{} { return nil }
|
func (self Log) RlpData() interface{} { return nil }
|
||||||
func (self Log) Topics() [][]byte {
|
func (self Log) Topics() [][]byte {
|
||||||
t := make([][]byte, len(self.TopicsF))
|
t := make([][]byte, len(self.TopicsF))
|
||||||
for i, topic := range self.TopicsF {
|
for i, topic := range self.TopicsF {
|
||||||
t[i] = ethutil.Hex2Bytes(topic)
|
t[i] = common.Hex2Bytes(topic)
|
||||||
}
|
}
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
@ -66,15 +66,15 @@ type Account struct {
|
|||||||
Storage map[string]string
|
Storage map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func StateObjectFromAccount(db ethutil.Database, addr string, account Account) *state.StateObject {
|
func StateObjectFromAccount(db common.Database, addr string, account Account) *state.StateObject {
|
||||||
obj := state.NewStateObject(ethutil.Hex2Bytes(addr), db)
|
obj := state.NewStateObject(common.Hex2Bytes(addr), db)
|
||||||
obj.SetBalance(ethutil.Big(account.Balance))
|
obj.SetBalance(common.Big(account.Balance))
|
||||||
|
|
||||||
if ethutil.IsHex(account.Code) {
|
if common.IsHex(account.Code) {
|
||||||
account.Code = account.Code[2:]
|
account.Code = account.Code[2:]
|
||||||
}
|
}
|
||||||
obj.SetCode(ethutil.Hex2Bytes(account.Code))
|
obj.SetCode(common.Hex2Bytes(account.Code))
|
||||||
obj.SetNonce(ethutil.Big(account.Nonce).Uint64())
|
obj.SetNonce(common.Big(account.Nonce).Uint64())
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
@ -147,8 +147,8 @@ func RunVmTest(r io.Reader) (failed int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(test.Exec) == 0 {
|
if len(test.Exec) == 0 {
|
||||||
if obj.Balance().Cmp(ethutil.Big(account.Balance)) != 0 {
|
if obj.Balance().Cmp(common.Big(account.Balance)) != 0 {
|
||||||
fmt.Printf("FAIL: %s's : (%x) balance failed. Expected %v, got %v => %v\n", name, obj.Address()[:4], account.Balance, obj.Balance(), new(big.Int).Sub(ethutil.Big(account.Balance), obj.Balance()))
|
fmt.Printf("FAIL: %s's : (%x) balance failed. Expected %v, got %v => %v\n", name, obj.Address()[:4], account.Balance, obj.Balance(), new(big.Int).Sub(common.Big(account.Balance), obj.Balance()))
|
||||||
failed = 1
|
failed = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -158,13 +158,13 @@ func RunVmTest(r io.Reader) (failed int) {
|
|||||||
vexp := helper.FromHex(value)
|
vexp := helper.FromHex(value)
|
||||||
|
|
||||||
if bytes.Compare(v, vexp) != 0 {
|
if bytes.Compare(v, vexp) != 0 {
|
||||||
fmt.Printf("FAIL: %s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)\n", name, obj.Address()[0:4], addr, vexp, v, ethutil.BigD(vexp), ethutil.BigD(v))
|
fmt.Printf("FAIL: %s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)\n", name, obj.Address()[0:4], addr, vexp, v, common.BigD(vexp), common.BigD(v))
|
||||||
failed = 1
|
failed = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !bytes.Equal(ethutil.Hex2Bytes(test.PostStateRoot), statedb.Root()) {
|
if !bytes.Equal(common.Hex2Bytes(test.PostStateRoot), statedb.Root()) {
|
||||||
fmt.Printf("FAIL: %s's : Post state root error. Expected %s, got %x\n", name, test.PostStateRoot, statedb.Root())
|
fmt.Printf("FAIL: %s's : Post state root error. Expected %s, got %x\n", name, test.PostStateRoot, statedb.Root())
|
||||||
failed = 1
|
failed = 1
|
||||||
}
|
}
|
||||||
@ -178,8 +178,8 @@ func RunVmTest(r io.Reader) (failed int) {
|
|||||||
fmt.Println("A", test.Logs)
|
fmt.Println("A", test.Logs)
|
||||||
fmt.Println("B", logs)
|
fmt.Println("B", logs)
|
||||||
for i, log := range test.Logs {
|
for i, log := range test.Logs {
|
||||||
genBloom := ethutil.LeftPadBytes(types.LogsBloom(state.Logs{logs[i]}).Bytes(), 256)
|
genBloom := common.LeftPadBytes(types.LogsBloom(state.Logs{logs[i]}).Bytes(), 256)
|
||||||
if !bytes.Equal(genBloom, ethutil.Hex2Bytes(log.BloomF)) {
|
if !bytes.Equal(genBloom, common.Hex2Bytes(log.BloomF)) {
|
||||||
t.Errorf("bloom mismatch")
|
t.Errorf("bloom mismatch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
"github.com/ethereum/go-ethereum/vm"
|
"github.com/ethereum/go-ethereum/vm"
|
||||||
@ -63,13 +63,13 @@ func main() {
|
|||||||
statedb := state.New(nil, db)
|
statedb := state.New(nil, db)
|
||||||
sender := statedb.NewStateObject([]byte("sender"))
|
sender := statedb.NewStateObject([]byte("sender"))
|
||||||
receiver := statedb.NewStateObject([]byte("receiver"))
|
receiver := statedb.NewStateObject([]byte("receiver"))
|
||||||
receiver.SetCode(ethutil.Hex2Bytes(*code))
|
receiver.SetCode(common.Hex2Bytes(*code))
|
||||||
|
|
||||||
vmenv := NewEnv(statedb, []byte("evmuser"), ethutil.Big(*value))
|
vmenv := NewEnv(statedb, []byte("evmuser"), common.Big(*value))
|
||||||
|
|
||||||
tstart := time.Now()
|
tstart := time.Now()
|
||||||
|
|
||||||
ret, e := vmenv.Call(sender, receiver.Address(), ethutil.Hex2Bytes(*data), ethutil.Big(*gas), ethutil.Big(*price), ethutil.Big(*value))
|
ret, e := vmenv.Call(sender, receiver.Address(), common.Hex2Bytes(*data), common.Big(*gas), common.Big(*price), common.Big(*value))
|
||||||
|
|
||||||
logger.Flush()
|
logger.Flush()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
@ -117,11 +117,11 @@ func NewEnv(state *state.StateDB, transactor []byte, value *big.Int) *VMEnv {
|
|||||||
|
|
||||||
func (self *VMEnv) State() *state.StateDB { return self.state }
|
func (self *VMEnv) State() *state.StateDB { return self.state }
|
||||||
func (self *VMEnv) Origin() []byte { return self.transactor }
|
func (self *VMEnv) Origin() []byte { return self.transactor }
|
||||||
func (self *VMEnv) BlockNumber() *big.Int { return ethutil.Big0 }
|
func (self *VMEnv) BlockNumber() *big.Int { return common.Big0 }
|
||||||
func (self *VMEnv) PrevHash() []byte { return make([]byte, 32) }
|
func (self *VMEnv) PrevHash() []byte { return make([]byte, 32) }
|
||||||
func (self *VMEnv) Coinbase() []byte { return self.transactor }
|
func (self *VMEnv) Coinbase() []byte { return self.transactor }
|
||||||
func (self *VMEnv) Time() int64 { return self.time }
|
func (self *VMEnv) Time() int64 { return self.time }
|
||||||
func (self *VMEnv) Difficulty() *big.Int { return ethutil.Big1 }
|
func (self *VMEnv) Difficulty() *big.Int { return common.Big1 }
|
||||||
func (self *VMEnv) BlockHash() []byte { return make([]byte, 32) }
|
func (self *VMEnv) BlockHash() []byte { return make([]byte, 32) }
|
||||||
func (self *VMEnv) Value() *big.Int { return self.value }
|
func (self *VMEnv) Value() *big.Int { return self.value }
|
||||||
func (self *VMEnv) GasLimit() *big.Int { return big.NewInt(1000000000) }
|
func (self *VMEnv) GasLimit() *big.Int { return big.NewInt(1000000000) }
|
||||||
|
@ -26,8 +26,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,32 +37,23 @@ type plugin struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) Transact(from, recipient, value, gas, gasPrice, d string) (string, error) {
|
func (gui *Gui) Transact(from, recipient, value, gas, gasPrice, d string) (string, error) {
|
||||||
var data string
|
d = common.Bytes2Hex(utils.FormatTransactionData(d))
|
||||||
if len(recipient) == 0 {
|
|
||||||
code, err := ethutil.Compile(d, false)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
data = ethutil.Bytes2Hex(code)
|
|
||||||
} else {
|
|
||||||
data = ethutil.Bytes2Hex(utils.FormatTransactionData(d))
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.xeth.Transact(from, recipient, value, gas, gasPrice, data)
|
return gui.xeth.Transact(from, recipient, value, gas, gasPrice, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Gui) AddPlugin(pluginPath string) {
|
func (self *Gui) AddPlugin(pluginPath string) {
|
||||||
self.plugins[pluginPath] = plugin{Name: pluginPath, Path: pluginPath}
|
self.plugins[pluginPath] = plugin{Name: pluginPath, Path: pluginPath}
|
||||||
|
|
||||||
json, _ := json.MarshalIndent(self.plugins, "", " ")
|
json, _ := json.MarshalIndent(self.plugins, "", " ")
|
||||||
ethutil.WriteFile(self.eth.DataDir+"/plugins.json", json)
|
common.WriteFile(self.eth.DataDir+"/plugins.json", json)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Gui) RemovePlugin(pluginPath string) {
|
func (self *Gui) RemovePlugin(pluginPath string) {
|
||||||
delete(self.plugins, pluginPath)
|
delete(self.plugins, pluginPath)
|
||||||
|
|
||||||
json, _ := json.MarshalIndent(self.plugins, "", " ")
|
json, _ := json.MarshalIndent(self.plugins, "", " ")
|
||||||
ethutil.WriteFile(self.eth.DataDir+"/plugins.json", json)
|
common.WriteFile(self.eth.DataDir+"/plugins.json", json)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Gui) DumpState(hash, path string) {
|
func (self *Gui) DumpState(hash, path string) {
|
||||||
@ -76,7 +67,7 @@ func (self *Gui) DumpState(hash, path string) {
|
|||||||
i, _ := strconv.Atoi(hash[1:])
|
i, _ := strconv.Atoi(hash[1:])
|
||||||
block = self.eth.ChainManager().GetBlockByNumber(uint64(i))
|
block = self.eth.ChainManager().GetBlockByNumber(uint64(i))
|
||||||
} else {
|
} else {
|
||||||
block = self.eth.ChainManager().GetBlock(ethutil.Hex2Bytes(hash))
|
block = self.eth.ChainManager().GetBlock(common.Hex2Bytes(hash))
|
||||||
}
|
}
|
||||||
|
|
||||||
if block == nil {
|
if block == nil {
|
||||||
|
@ -35,7 +35,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/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/ui/qt/qwhisper"
|
"github.com/ethereum/go-ethereum/ui/qt/qwhisper"
|
||||||
"github.com/ethereum/go-ethereum/xeth"
|
"github.com/ethereum/go-ethereum/xeth"
|
||||||
@ -91,7 +91,7 @@ func NewWindow(ethereum *eth.Ethereum) *Gui {
|
|||||||
plugins: make(map[string]plugin),
|
plugins: make(map[string]plugin),
|
||||||
serviceEvents: make(chan ServEv, 1),
|
serviceEvents: make(chan ServEv, 1),
|
||||||
}
|
}
|
||||||
data, _ := ethutil.ReadAllFile(path.Join(ethereum.DataDir, "plugins.json"))
|
data, _ := common.ReadAllFile(path.Join(ethereum.DataDir, "plugins.json"))
|
||||||
json.Unmarshal([]byte(data), &gui.plugins)
|
json.Unmarshal([]byte(data), &gui.plugins)
|
||||||
|
|
||||||
return gui
|
return gui
|
||||||
@ -198,7 +198,7 @@ func (gui *Gui) loadAddressBook() {
|
|||||||
it := nameReg.Trie().Iterator()
|
it := nameReg.Trie().Iterator()
|
||||||
for it.Next() {
|
for it.Next() {
|
||||||
if it.Key[0] != 0 {
|
if it.Key[0] != 0 {
|
||||||
view.Call("addAddress", struct{ Name, Address string }{string(it.Key), ethutil.Bytes2Hex(it.Value)})
|
view.Call("addAddress", struct{ Name, Address string }{string(it.Key), common.Bytes2Hex(it.Value)})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -219,7 +219,7 @@ func (self *Gui) loadMergedMiningOptions() {
|
|||||||
Checked bool
|
Checked bool
|
||||||
Name, Address string
|
Name, Address string
|
||||||
Id, ItemId int
|
Id, ItemId int
|
||||||
}{false, string(it.Key), ethutil.Bytes2Hex(it.Value), 0, i})
|
}{false, string(it.Key), common.Bytes2Hex(it.Value), 0, i})
|
||||||
|
|
||||||
i++
|
i++
|
||||||
|
|
||||||
@ -238,8 +238,8 @@ func (gui *Gui) insertTransaction(window string, tx *types.Transaction) {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ptx = xeth.NewTx(tx)
|
ptx = xeth.NewTx(tx)
|
||||||
send = ethutil.Bytes2Hex(tx.From())
|
send = common.Bytes2Hex(tx.From())
|
||||||
rec = ethutil.Bytes2Hex(tx.To())
|
rec = common.Bytes2Hex(tx.To())
|
||||||
)
|
)
|
||||||
ptx.Sender = send
|
ptx.Sender = send
|
||||||
ptx.Address = rec
|
ptx.Address = rec
|
||||||
@ -263,7 +263,7 @@ func (gui *Gui) readPreviousTransactions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) processBlock(block *types.Block, initial bool) {
|
func (gui *Gui) processBlock(block *types.Block, initial bool) {
|
||||||
name := ethutil.Bytes2Hex(block.Coinbase())
|
name := common.Bytes2Hex(block.Coinbase())
|
||||||
b := xeth.NewBlock(block)
|
b := xeth.NewBlock(block)
|
||||||
b.Name = name
|
b.Name = name
|
||||||
|
|
||||||
@ -277,10 +277,10 @@ func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) {
|
|||||||
if unconfirmedFunds.Cmp(big.NewInt(0)) < 0 {
|
if unconfirmedFunds.Cmp(big.NewInt(0)) < 0 {
|
||||||
pos = "-"
|
pos = "-"
|
||||||
}
|
}
|
||||||
val := ethutil.CurrencyToString(new(big.Int).Abs(ethutil.BigCopy(unconfirmedFunds)))
|
val := common.CurrencyToString(new(big.Int).Abs(common.BigCopy(unconfirmedFunds)))
|
||||||
str = fmt.Sprintf("%v (%s %v)", ethutil.CurrencyToString(amount), pos, val)
|
str = fmt.Sprintf("%v (%s %v)", common.CurrencyToString(amount), pos, val)
|
||||||
} else {
|
} else {
|
||||||
str = fmt.Sprintf("%v", ethutil.CurrencyToString(amount))
|
str = fmt.Sprintf("%v", common.CurrencyToString(amount))
|
||||||
}
|
}
|
||||||
|
|
||||||
gui.win.Root().Call("setWalletValue", str)
|
gui.win.Root().Call("setWalletValue", str)
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/xeth"
|
"github.com/ethereum/go-ethereum/xeth"
|
||||||
"github.com/howeyc/fsnotify"
|
"github.com/howeyc/fsnotify"
|
||||||
"github.com/obscuren/qml"
|
"github.com/obscuren/qml"
|
||||||
@ -62,7 +62,7 @@ func (app *HtmlApplication) Create() error {
|
|||||||
return errors.New("Ethereum package not yet supported")
|
return errors.New("Ethereum package not yet supported")
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
//ethutil.OpenPackage(app.path)
|
//common.OpenPackage(app.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
win := component.CreateWindow(nil)
|
win := component.CreateWindow(nil)
|
||||||
@ -80,7 +80,7 @@ func (app *HtmlApplication) RootFolder() string {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return path.Dir(ethutil.WindonizePath(folder.RequestURI()))
|
return path.Dir(common.WindonizePath(folder.RequestURI()))
|
||||||
}
|
}
|
||||||
func (app *HtmlApplication) RecursiveFolders() []os.FileInfo {
|
func (app *HtmlApplication) RecursiveFolders() []os.FileInfo {
|
||||||
files, _ := ioutil.ReadDir(app.RootFolder())
|
files, _ := ioutil.ReadDir(app.RootFolder())
|
||||||
@ -139,7 +139,7 @@ func (app *HtmlApplication) Window() *qml.Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *HtmlApplication) NewBlock(block *types.Block) {
|
func (app *HtmlApplication) NewBlock(block *types.Block) {
|
||||||
b := &xeth.Block{Number: int(block.NumberU64()), Hash: ethutil.Bytes2Hex(block.Hash())}
|
b := &xeth.Block{Number: int(block.NumberU64()), Hash: common.Bytes2Hex(block.Hash())}
|
||||||
app.webView.Call("onNewBlockCb", b)
|
app.webView.Call("onNewBlockCb", b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ import (
|
|||||||
"github.com/codegangsta/cli"
|
"github.com/codegangsta/cli"
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/ui/qt/webengine"
|
"github.com/ethereum/go-ethereum/ui/qt/webengine"
|
||||||
"github.com/obscuren/qml"
|
"github.com/obscuren/qml"
|
||||||
@ -45,7 +45,7 @@ var (
|
|||||||
assetPathFlag = cli.StringFlag{
|
assetPathFlag = cli.StringFlag{
|
||||||
Name: "asset_path",
|
Name: "asset_path",
|
||||||
Usage: "absolute path to GUI assets directory",
|
Usage: "absolute path to GUI assets directory",
|
||||||
Value: ethutil.DefaultAssetPath(),
|
Value: common.DefaultAssetPath(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/xeth"
|
"github.com/ethereum/go-ethereum/xeth"
|
||||||
"github.com/obscuren/qml"
|
"github.com/obscuren/qml"
|
||||||
)
|
)
|
||||||
@ -68,7 +68,7 @@ func (app *QmlApplication) NewWatcher(quitChan chan bool) {
|
|||||||
|
|
||||||
// Events
|
// Events
|
||||||
func (app *QmlApplication) NewBlock(block *types.Block) {
|
func (app *QmlApplication) NewBlock(block *types.Block) {
|
||||||
pblock := &xeth.Block{Number: int(block.NumberU64()), Hash: ethutil.Bytes2Hex(block.Hash())}
|
pblock := &xeth.Block{Number: int(block.NumberU64()), Hash: common.Bytes2Hex(block.Hash())}
|
||||||
app.win.Call("onNewBlockCb", pblock)
|
app.win.Call("onNewBlockCb", pblock)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
|
||||||
"github.com/ethereum/go-ethereum/event/filter"
|
"github.com/ethereum/go-ethereum/event/filter"
|
||||||
"github.com/ethereum/go-ethereum/xeth"
|
"github.com/ethereum/go-ethereum/xeth"
|
||||||
"github.com/obscuren/qml"
|
"github.com/obscuren/qml"
|
||||||
@ -71,7 +71,7 @@ func (self *UiLib) Notef(args []interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *UiLib) ImportTx(rlpTx string) {
|
func (self *UiLib) ImportTx(rlpTx string) {
|
||||||
tx := types.NewTransactionFromBytes(ethutil.Hex2Bytes(rlpTx))
|
tx := types.NewTransactionFromBytes(common.Hex2Bytes(rlpTx))
|
||||||
err := self.eth.TxPool().Add(tx)
|
err := self.eth.TxPool().Add(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guilogger.Infoln("import tx failed ", err)
|
guilogger.Infoln("import tx failed ", err)
|
||||||
@ -126,15 +126,6 @@ func (self *UiLib) Transact(params map[string]interface{}) (string, error) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *UiLib) Compile(code string) (string, error) {
|
|
||||||
bcode, err := ethutil.Compile(code, false)
|
|
||||||
if err != nil {
|
|
||||||
return err.Error(), err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ethutil.Bytes2Hex(bcode), err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *UiLib) Call(params map[string]interface{}) (string, error) {
|
func (self *UiLib) Call(params map[string]interface{}) (string, error) {
|
||||||
object := mapToTxParams(params)
|
object := mapToTxParams(params)
|
||||||
|
|
||||||
@ -152,8 +143,8 @@ func (self *UiLib) AddLocalTransaction(to, data, gas, gasPrice, value string) in
|
|||||||
return 0
|
return 0
|
||||||
/*
|
/*
|
||||||
return self.miner.AddLocalTx(&miner.LocalTx{
|
return self.miner.AddLocalTx(&miner.LocalTx{
|
||||||
To: ethutil.Hex2Bytes(to),
|
To: common.Hex2Bytes(to),
|
||||||
Data: ethutil.Hex2Bytes(data),
|
Data: common.Hex2Bytes(data),
|
||||||
Gas: gas,
|
Gas: gas,
|
||||||
GasPrice: gasPrice,
|
GasPrice: gasPrice,
|
||||||
Value: value,
|
Value: value,
|
||||||
@ -176,7 +167,7 @@ func (self *UiLib) ToggleMining() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *UiLib) ToHex(data string) string {
|
func (self *UiLib) ToHex(data string) string {
|
||||||
return "0x" + ethutil.Bytes2Hex([]byte(data))
|
return "0x" + common.Bytes2Hex([]byte(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *UiLib) ToAscii(data string) string {
|
func (self *UiLib) ToAscii(data string) string {
|
||||||
@ -184,7 +175,7 @@ func (self *UiLib) ToAscii(data string) string {
|
|||||||
if len(data) > 1 && data[0:2] == "0x" {
|
if len(data) > 1 && data[0:2] == "0x" {
|
||||||
start = 2
|
start = 2
|
||||||
}
|
}
|
||||||
return string(ethutil.Hex2Bytes(data[start:]))
|
return string(common.Hex2Bytes(data[start:]))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ethereum filter methods
|
/// Ethereum filter methods
|
||||||
@ -212,7 +203,7 @@ func (self *UiLib) NewFilterString(typ string, view *qml.Common) (id int) {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *UiLib) Messages(id int) *ethutil.List {
|
func (self *UiLib) Messages(id int) *common.List {
|
||||||
/* TODO remove me
|
/* TODO remove me
|
||||||
filter := self.filterManager.GetFilter(id)
|
filter := self.filterManager.GetFilter(id)
|
||||||
if filter != nil {
|
if filter != nil {
|
||||||
@ -222,7 +213,7 @@ func (self *UiLib) Messages(id int) *ethutil.List {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return ethutil.EmptyList()
|
return common.EmptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *UiLib) ReadFile(p string) string {
|
func (self *UiLib) ReadFile(p string) string {
|
||||||
@ -264,14 +255,14 @@ func mapToTxParams(object map[string]interface{}) map[string]string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, str := range data {
|
for _, str := range data {
|
||||||
if ethutil.IsHex(str) {
|
if common.IsHex(str) {
|
||||||
str = str[2:]
|
str = str[2:]
|
||||||
|
|
||||||
if len(str) != 64 {
|
if len(str) != 64 {
|
||||||
str = ethutil.LeftPadString(str, 64)
|
str = common.LeftPadString(str, 64)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
str = ethutil.Bytes2Hex(ethutil.LeftPadBytes(ethutil.Big(str).Bytes(), 32))
|
str = common.Bytes2Hex(common.LeftPadBytes(common.Big(str).Bytes(), 32))
|
||||||
}
|
}
|
||||||
|
|
||||||
dataStr += str
|
dataStr += str
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
@ -62,7 +62,7 @@ func RunInterruptCallbacks(sig os.Signal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func openLogFile(Datadir string, filename string) *os.File {
|
func openLogFile(Datadir string, filename string) *os.File {
|
||||||
path := ethutil.AbsolutePath(Datadir, filename)
|
path := common.AbsolutePath(Datadir, filename)
|
||||||
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("error opening log file '%s': %v", filename, err))
|
panic(fmt.Sprintf("error opening log file '%s': %v", filename, err))
|
||||||
@ -132,10 +132,10 @@ func StartEthereumForTest(ethereum *eth.Ethereum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FormatTransactionData(data string) []byte {
|
func FormatTransactionData(data string) []byte {
|
||||||
d := ethutil.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)
|
||||||
for _, dataItem := range slice {
|
for _, dataItem := range slice {
|
||||||
d := ethutil.FormatData(dataItem)
|
d := common.FormatData(dataItem)
|
||||||
ret = append(ret, d...)
|
ret = append(ret, d...)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -171,7 +171,7 @@ func ExportChain(chainmgr *core.ChainManager, fn string) error {
|
|||||||
|
|
||||||
data := chainmgr.Export()
|
data := chainmgr.Export()
|
||||||
|
|
||||||
if err := ethutil.WriteFile(fn, data); err != nil {
|
if err := common.WriteFile(fn, data); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("exported blockchain\n")
|
fmt.Printf("exported blockchain\n")
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/p2p/nat"
|
"github.com/ethereum/go-ethereum/p2p/nat"
|
||||||
@ -87,7 +87,7 @@ var (
|
|||||||
DataDirFlag = cli.StringFlag{
|
DataDirFlag = cli.StringFlag{
|
||||||
Name: "datadir",
|
Name: "datadir",
|
||||||
Usage: "Data directory to be used",
|
Usage: "Data directory to be used",
|
||||||
Value: ethutil.DefaultDataDir(),
|
Value: common.DefaultDataDir(),
|
||||||
}
|
}
|
||||||
MinerThreadsFlag = cli.IntFlag{
|
MinerThreadsFlag = cli.IntFlag{
|
||||||
Name: "minerthreads",
|
Name: "minerthreads",
|
||||||
@ -198,7 +198,7 @@ func GetNodeKey(ctx *cli.Context) (key *ecdsa.PrivateKey) {
|
|||||||
|
|
||||||
func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
|
func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
|
||||||
return ð.Config{
|
return ð.Config{
|
||||||
Name: ethutil.MakeName(clientID, version),
|
Name: common.MakeName(clientID, version),
|
||||||
DataDir: ctx.GlobalString(DataDirFlag.Name),
|
DataDir: ctx.GlobalString(DataDirFlag.Name),
|
||||||
LogFile: ctx.GlobalString(LogFileFlag.Name),
|
LogFile: ctx.GlobalString(LogFileFlag.Name),
|
||||||
LogLevel: ctx.GlobalInt(LogLevelFlag.Name),
|
LogLevel: ctx.GlobalInt(LogLevelFlag.Name),
|
||||||
@ -216,7 +216,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetChain(ctx *cli.Context) (*core.ChainManager, ethutil.Database, ethutil.Database) {
|
func GetChain(ctx *cli.Context) (*core.ChainManager, common.Database, common.Database) {
|
||||||
dataDir := ctx.GlobalString(DataDirFlag.Name)
|
dataDir := ctx.GlobalString(DataDirFlag.Name)
|
||||||
blockDb, err := ethdb.NewLDBDatabase(path.Join(dataDir, "blockchain"))
|
blockDb, err := ethdb.NewLDBDatabase(path.Join(dataDir, "blockchain"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
0
ethutil/.gitignore → common/.gitignore
vendored
0
ethutil/.gitignore → common/.gitignore
vendored
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import "math/big"
|
import "math/big"
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
checker "gopkg.in/check.v1"
|
checker "gopkg.in/check.v1"
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
// Database interface
|
// Database interface
|
||||||
type Database interface {
|
type Database interface {
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
@ -4,7 +4,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Summer interface {
|
type Summer interface {
|
||||||
@ -67,7 +67,7 @@ func (v vectorSummer) Sum(i int) *big.Int { return v.by(v.vectors[i]) }
|
|||||||
|
|
||||||
func GasSum(v Vector) *big.Int { return v.Gas }
|
func GasSum(v Vector) *big.Int { return v.Gas }
|
||||||
|
|
||||||
var etherInWei = new(big.Rat).SetInt(ethutil.String2Big("1000000000000000000"))
|
var etherInWei = new(big.Rat).SetInt(common.String2Big("1000000000000000000"))
|
||||||
|
|
||||||
func GasPrice(bp, gl, ep *big.Int) *big.Int {
|
func GasPrice(bp, gl, ep *big.Int) *big.Int {
|
||||||
BP := new(big.Rat).SetInt(bp)
|
BP := new(big.Rat).SetInt(bp)
|
@ -3,7 +3,7 @@ package number
|
|||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var tt256 = new(big.Int).Lsh(big.NewInt(1), 256)
|
var tt256 = new(big.Int).Lsh(big.NewInt(1), 256)
|
||||||
@ -171,7 +171,7 @@ var (
|
|||||||
Zero = Uint(0)
|
Zero = Uint(0)
|
||||||
One = Uint(1)
|
One = Uint(1)
|
||||||
Two = Uint(2)
|
Two = Uint(2)
|
||||||
MaxUint256 = Uint(0).SetBytes(ethutil.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))
|
MaxUint256 = Uint(0).SetBytes(common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))
|
||||||
|
|
||||||
MinOne = Int(-1)
|
MinOne = Int(-1)
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSet(t *testing.T) {
|
func TestSet(t *testing.T) {
|
||||||
@ -15,7 +15,7 @@ func TestSet(t *testing.T) {
|
|||||||
t.Error("didn't compare", a, b)
|
t.Error("didn't compare", a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
c := Uint(0).SetBytes(ethutil.Hex2Bytes("0a"))
|
c := Uint(0).SetBytes(common.Hex2Bytes("0a"))
|
||||||
if c.num.Cmp(big.NewInt(10)) != 0 {
|
if c.num.Cmp(big.NewInt(10)) != 0 {
|
||||||
t.Error("c set bytes failed.")
|
t.Error("c set bytes failed.")
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
"archive/zip"
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "os"
|
// "os"
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
checker "gopkg.in/check.v1"
|
checker "gopkg.in/check.v1"
|
6
common/types.go
Normal file
6
common/types.go
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
type (
|
||||||
|
uHash [32]byte
|
||||||
|
uAddress [20]byte
|
||||||
|
)
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -1,4 +1,4 @@
|
|||||||
package ethutil
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
@ -4,7 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/vm"
|
"github.com/ethereum/go-ethereum/vm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ func Disassemble(script []byte) (asm []string) {
|
|||||||
vm.PUSH16, vm.PUSH17, vm.PUSH18, vm.PUSH19, vm.PUSH20, vm.PUSH21, vm.PUSH22,
|
vm.PUSH16, vm.PUSH17, vm.PUSH18, vm.PUSH19, vm.PUSH20, vm.PUSH21, vm.PUSH22,
|
||||||
vm.PUSH23, vm.PUSH24, vm.PUSH25, vm.PUSH26, vm.PUSH27, vm.PUSH28, vm.PUSH29,
|
vm.PUSH23, vm.PUSH24, vm.PUSH25, vm.PUSH26, vm.PUSH27, vm.PUSH28, vm.PUSH29,
|
||||||
vm.PUSH30, vm.PUSH31, vm.PUSH32:
|
vm.PUSH30, vm.PUSH31, vm.PUSH32:
|
||||||
pc.Add(pc, ethutil.Big1)
|
pc.Add(pc, common.Big1)
|
||||||
a := int64(op) - int64(vm.PUSH1) + 1
|
a := int64(op) - int64(vm.PUSH1) + 1
|
||||||
if int(pc.Int64()+a) > len(script) {
|
if int(pc.Int64()+a) > len(script) {
|
||||||
return
|
return
|
||||||
@ -43,7 +43,7 @@ func Disassemble(script []byte) (asm []string) {
|
|||||||
pc.Add(pc, big.NewInt(a-1))
|
pc.Add(pc, big.NewInt(a-1))
|
||||||
}
|
}
|
||||||
|
|
||||||
pc.Add(pc, ethutil.Big1)
|
pc.Add(pc, common.Big1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return asm
|
return asm
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/pow"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
@ -24,8 +24,8 @@ type PendingBlockEvent struct {
|
|||||||
var statelogger = logger.NewLogger("BLOCK")
|
var statelogger = logger.NewLogger("BLOCK")
|
||||||
|
|
||||||
type BlockProcessor struct {
|
type BlockProcessor struct {
|
||||||
db ethutil.Database
|
db common.Database
|
||||||
extraDb ethutil.Database
|
extraDb common.Database
|
||||||
// Mutex for locking the block processor. Blocks can only be handled one at a time
|
// Mutex for locking the block processor. Blocks can only be handled one at a time
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
// Canonical block chain
|
// Canonical block chain
|
||||||
@ -47,7 +47,7 @@ type BlockProcessor struct {
|
|||||||
eventMux *event.TypeMux
|
eventMux *event.TypeMux
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlockProcessor(db, extra ethutil.Database, pow pow.PoW, txpool *TxPool, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
|
func NewBlockProcessor(db, extra common.Database, pow pow.PoW, txpool *TxPool, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
|
||||||
sm := &BlockProcessor{
|
sm := &BlockProcessor{
|
||||||
db: db,
|
db: db,
|
||||||
extraDb: extra,
|
extraDb: extra,
|
||||||
@ -217,7 +217,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (td *big
|
|||||||
|
|
||||||
// Commit state objects/accounts to a temporary trie (does not save)
|
// Commit state objects/accounts to a temporary trie (does not save)
|
||||||
// used to calculate the state root.
|
// used to calculate the state root.
|
||||||
state.Update(ethutil.Big0)
|
state.Update(common.Big0)
|
||||||
if !bytes.Equal(header.Root, state.Root()) {
|
if !bytes.Equal(header.Root, state.Root()) {
|
||||||
err = fmt.Errorf("invalid merkle root. received=%x got=%x", header.Root, state.Root())
|
err = fmt.Errorf("invalid merkle root. received=%x got=%x", header.Root, state.Root())
|
||||||
return
|
return
|
||||||
@ -352,7 +352,7 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err erro
|
|||||||
return state.Logs(), nil
|
return state.Logs(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func putTx(db ethutil.Database, tx *types.Transaction) {
|
func putTx(db common.Database, tx *types.Transaction) {
|
||||||
rlpEnc, err := rlp.EncodeToBytes(tx)
|
rlpEnc, err := rlp.EncodeToBytes(tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
statelogger.Infoln("Failed encoding tx", err)
|
statelogger.Infoln("Failed encoding tx", err)
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/pow"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
@ -33,36 +33,36 @@ func NewBlockFromParent(addr []byte, parent *types.Block) *types.Block {
|
|||||||
return newBlockFromParent(addr, parent)
|
return newBlockFromParent(addr, parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeBlock(bman *BlockProcessor, parent *types.Block, i int, db ethutil.Database, seed int) *types.Block {
|
func MakeBlock(bman *BlockProcessor, parent *types.Block, i int, db common.Database, seed int) *types.Block {
|
||||||
return makeBlock(bman, parent, i, db, seed)
|
return makeBlock(bman, parent, i, db, seed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MakeChain(bman *BlockProcessor, parent *types.Block, max int, db ethutil.Database, seed int) types.Blocks {
|
func MakeChain(bman *BlockProcessor, parent *types.Block, max int, db common.Database, seed int) types.Blocks {
|
||||||
return makeChain(bman, parent, max, db, seed)
|
return makeChain(bman, parent, max, db, seed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChainMan(block *types.Block, eventMux *event.TypeMux, db ethutil.Database) *ChainManager {
|
func NewChainMan(block *types.Block, eventMux *event.TypeMux, db common.Database) *ChainManager {
|
||||||
return newChainManager(block, eventMux, db)
|
return newChainManager(block, eventMux, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlockProc(db ethutil.Database, txpool *TxPool, cman *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
|
func NewBlockProc(db common.Database, txpool *TxPool, cman *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
|
||||||
return newBlockProcessor(db, txpool, cman, eventMux)
|
return newBlockProcessor(db, txpool, cman, eventMux)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCanonical(n int, db ethutil.Database) (*BlockProcessor, error) {
|
func NewCanonical(n int, db common.Database) (*BlockProcessor, error) {
|
||||||
return newCanonical(n, db)
|
return newCanonical(n, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
// block time is fixed at 10 seconds
|
// block time is fixed at 10 seconds
|
||||||
func newBlockFromParent(addr []byte, parent *types.Block) *types.Block {
|
func newBlockFromParent(addr []byte, parent *types.Block) *types.Block {
|
||||||
block := types.NewBlock(parent.Hash(), addr, parent.Root(), ethutil.BigPow(2, 32), 0, "")
|
block := types.NewBlock(parent.Hash(), addr, parent.Root(), common.BigPow(2, 32), 0, "")
|
||||||
block.SetUncles(nil)
|
block.SetUncles(nil)
|
||||||
block.SetTransactions(nil)
|
block.SetTransactions(nil)
|
||||||
block.SetReceipts(nil)
|
block.SetReceipts(nil)
|
||||||
|
|
||||||
header := block.Header()
|
header := block.Header()
|
||||||
header.Difficulty = CalcDifficulty(block.Header(), parent.Header())
|
header.Difficulty = CalcDifficulty(block.Header(), parent.Header())
|
||||||
header.Number = new(big.Int).Add(parent.Header().Number, ethutil.Big1)
|
header.Number = new(big.Int).Add(parent.Header().Number, common.Big1)
|
||||||
header.Time = parent.Header().Time + 10
|
header.Time = parent.Header().Time + 10
|
||||||
header.GasLimit = CalcGasLimit(parent, block)
|
header.GasLimit = CalcGasLimit(parent, block)
|
||||||
|
|
||||||
@ -73,22 +73,22 @@ func newBlockFromParent(addr []byte, parent *types.Block) *types.Block {
|
|||||||
|
|
||||||
// Actually make a block by simulating what miner would do
|
// Actually make a block by simulating what miner would do
|
||||||
// we seed chains by the first byte of the coinbase
|
// we seed chains by the first byte of the coinbase
|
||||||
func makeBlock(bman *BlockProcessor, parent *types.Block, i int, db ethutil.Database, seed int) *types.Block {
|
func makeBlock(bman *BlockProcessor, parent *types.Block, i int, db common.Database, seed int) *types.Block {
|
||||||
addr := ethutil.LeftPadBytes([]byte{byte(i)}, 20)
|
addr := common.LeftPadBytes([]byte{byte(i)}, 20)
|
||||||
addr[0] = byte(seed)
|
addr[0] = byte(seed)
|
||||||
block := newBlockFromParent(addr, parent)
|
block := newBlockFromParent(addr, parent)
|
||||||
state := state.New(block.Root(), db)
|
state := state.New(block.Root(), db)
|
||||||
cbase := state.GetOrNewStateObject(addr)
|
cbase := state.GetOrNewStateObject(addr)
|
||||||
cbase.SetGasPool(CalcGasLimit(parent, block))
|
cbase.SetGasPool(CalcGasLimit(parent, block))
|
||||||
cbase.AddBalance(BlockReward)
|
cbase.AddBalance(BlockReward)
|
||||||
state.Update(ethutil.Big0)
|
state.Update(common.Big0)
|
||||||
block.SetRoot(state.Root())
|
block.SetRoot(state.Root())
|
||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a chain with real blocks
|
// Make a chain with real blocks
|
||||||
// Runs ProcessWithParent to get proper state roots
|
// Runs ProcessWithParent to get proper state roots
|
||||||
func makeChain(bman *BlockProcessor, parent *types.Block, max int, db ethutil.Database, seed int) types.Blocks {
|
func makeChain(bman *BlockProcessor, parent *types.Block, max int, db common.Database, seed int) types.Blocks {
|
||||||
bman.bc.currentBlock = parent
|
bman.bc.currentBlock = parent
|
||||||
blocks := make(types.Blocks, max)
|
blocks := make(types.Blocks, max)
|
||||||
for i := 0; i < max; i++ {
|
for i := 0; i < max; i++ {
|
||||||
@ -107,7 +107,7 @@ func makeChain(bman *BlockProcessor, parent *types.Block, max int, db ethutil.Da
|
|||||||
|
|
||||||
// Create a new chain manager starting from given block
|
// Create a new chain manager starting from given block
|
||||||
// Effectively a fork factory
|
// Effectively a fork factory
|
||||||
func newChainManager(block *types.Block, eventMux *event.TypeMux, db ethutil.Database) *ChainManager {
|
func newChainManager(block *types.Block, eventMux *event.TypeMux, db common.Database) *ChainManager {
|
||||||
bc := &ChainManager{blockDb: db, stateDb: db, genesisBlock: GenesisBlock(db), eventMux: eventMux}
|
bc := &ChainManager{blockDb: db, stateDb: db, genesisBlock: GenesisBlock(db), eventMux: eventMux}
|
||||||
if block == nil {
|
if block == nil {
|
||||||
bc.Reset()
|
bc.Reset()
|
||||||
@ -119,14 +119,14 @@ func newChainManager(block *types.Block, eventMux *event.TypeMux, db ethutil.Dat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// block processor with fake pow
|
// block processor with fake pow
|
||||||
func newBlockProcessor(db ethutil.Database, txpool *TxPool, cman *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
|
func newBlockProcessor(db common.Database, txpool *TxPool, cman *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
|
||||||
bman := NewBlockProcessor(db, db, FakePow{}, txpool, newChainManager(nil, eventMux, db), eventMux)
|
bman := NewBlockProcessor(db, db, FakePow{}, txpool, newChainManager(nil, eventMux, db), eventMux)
|
||||||
return bman
|
return bman
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a new, deterministic canonical chain by running InsertChain
|
// Make a new, deterministic canonical chain by running InsertChain
|
||||||
// on result of makeChain
|
// on result of makeChain
|
||||||
func newCanonical(n int, db ethutil.Database) (*BlockProcessor, error) {
|
func newCanonical(n int, db common.Database) (*BlockProcessor, error) {
|
||||||
eventMux := &event.TypeMux{}
|
eventMux := &event.TypeMux{}
|
||||||
txpool := NewTxPool(eventMux)
|
txpool := NewTxPool(eventMux)
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
@ -60,7 +60,7 @@ func CalculateTD(block, parent *types.Block) *big.Int {
|
|||||||
|
|
||||||
func CalcGasLimit(parent, block *types.Block) *big.Int {
|
func CalcGasLimit(parent, block *types.Block) *big.Int {
|
||||||
if block.Number().Cmp(big.NewInt(0)) == 0 {
|
if block.Number().Cmp(big.NewInt(0)) == 0 {
|
||||||
return ethutil.BigPow(10, 6)
|
return common.BigPow(10, 6)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ((1024-1) * parent.gasLimit + (gasUsed * 6 / 5)) / 1024
|
// ((1024-1) * parent.gasLimit + (gasUsed * 6 / 5)) / 1024
|
||||||
@ -71,13 +71,13 @@ func CalcGasLimit(parent, block *types.Block) *big.Int {
|
|||||||
result := new(big.Int).Add(previous, curInt)
|
result := new(big.Int).Add(previous, curInt)
|
||||||
result.Div(result, big.NewInt(1024))
|
result.Div(result, big.NewInt(1024))
|
||||||
|
|
||||||
return ethutil.BigMax(GenesisGasLimit, result)
|
return common.BigMax(GenesisGasLimit, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChainManager struct {
|
type ChainManager struct {
|
||||||
//eth EthManager
|
//eth EthManager
|
||||||
blockDb ethutil.Database
|
blockDb common.Database
|
||||||
stateDb ethutil.Database
|
stateDb common.Database
|
||||||
processor types.BlockProcessor
|
processor types.BlockProcessor
|
||||||
eventMux *event.TypeMux
|
eventMux *event.TypeMux
|
||||||
genesisBlock *types.Block
|
genesisBlock *types.Block
|
||||||
@ -94,7 +94,7 @@ type ChainManager struct {
|
|||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewChainManager(blockDb, stateDb ethutil.Database, mux *event.TypeMux) *ChainManager {
|
func NewChainManager(blockDb, stateDb common.Database, mux *event.TypeMux) *ChainManager {
|
||||||
bc := &ChainManager{blockDb: blockDb, stateDb: stateDb, genesisBlock: GenesisBlock(stateDb), eventMux: mux, quit: make(chan struct{})}
|
bc := &ChainManager{blockDb: blockDb, stateDb: stateDb, genesisBlock: GenesisBlock(stateDb), eventMux: mux, quit: make(chan struct{})}
|
||||||
bc.setLastBlock()
|
bc.setLastBlock()
|
||||||
bc.transState = bc.State().Copy()
|
bc.transState = bc.State().Copy()
|
||||||
@ -173,7 +173,7 @@ func (bc *ChainManager) setLastBlock() {
|
|||||||
bc.lastBlockHash = block.Hash()
|
bc.lastBlockHash = block.Hash()
|
||||||
|
|
||||||
// Set the last know difficulty (might be 0x0 as initial value, Genesis)
|
// Set the last know difficulty (might be 0x0 as initial value, Genesis)
|
||||||
bc.td = ethutil.BigD(bc.blockDb.LastKnownTD())
|
bc.td = common.BigD(bc.blockDb.LastKnownTD())
|
||||||
} else {
|
} else {
|
||||||
bc.Reset()
|
bc.Reset()
|
||||||
}
|
}
|
||||||
@ -198,7 +198,7 @@ func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block {
|
|||||||
parentHash,
|
parentHash,
|
||||||
coinbase,
|
coinbase,
|
||||||
root,
|
root,
|
||||||
ethutil.BigPow(2, 32),
|
common.BigPow(2, 32),
|
||||||
0,
|
0,
|
||||||
"")
|
"")
|
||||||
block.SetUncles(nil)
|
block.SetUncles(nil)
|
||||||
@ -209,7 +209,7 @@ func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block {
|
|||||||
if parent != nil {
|
if parent != nil {
|
||||||
header := block.Header()
|
header := block.Header()
|
||||||
header.Difficulty = CalcDifficulty(block.Header(), parent.Header())
|
header.Difficulty = CalcDifficulty(block.Header(), parent.Header())
|
||||||
header.Number = new(big.Int).Add(parent.Header().Number, ethutil.Big1)
|
header.Number = new(big.Int).Add(parent.Header().Number, common.Big1)
|
||||||
header.GasLimit = CalcGasLimit(parent, block)
|
header.GasLimit = CalcGasLimit(parent, block)
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -230,7 +230,7 @@ func (bc *ChainManager) Reset() {
|
|||||||
bc.insert(bc.genesisBlock)
|
bc.insert(bc.genesisBlock)
|
||||||
bc.currentBlock = bc.genesisBlock
|
bc.currentBlock = bc.genesisBlock
|
||||||
|
|
||||||
bc.setTotalDifficulty(ethutil.Big("0"))
|
bc.setTotalDifficulty(common.Big("0"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *ChainManager) removeBlock(block *types.Block) {
|
func (bc *ChainManager) removeBlock(block *types.Block) {
|
||||||
@ -263,11 +263,11 @@ func (self *ChainManager) Export() []byte {
|
|||||||
blocks[block.NumberU64()] = block
|
blocks[block.NumberU64()] = block
|
||||||
}
|
}
|
||||||
|
|
||||||
return ethutil.Encode(blocks)
|
return common.Encode(blocks)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bc *ChainManager) insert(block *types.Block) {
|
func (bc *ChainManager) insert(block *types.Block) {
|
||||||
//encodedBlock := ethutil.Encode(block)
|
//encodedBlock := common.Encode(block)
|
||||||
bc.blockDb.Put([]byte("LastBlock"), block.Hash())
|
bc.blockDb.Put([]byte("LastBlock"), block.Hash())
|
||||||
bc.currentBlock = block
|
bc.currentBlock = block
|
||||||
bc.lastBlockHash = block.Hash()
|
bc.lastBlockHash = block.Hash()
|
||||||
@ -277,7 +277,7 @@ func (bc *ChainManager) insert(block *types.Block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (bc *ChainManager) write(block *types.Block) {
|
func (bc *ChainManager) write(block *types.Block) {
|
||||||
encodedBlock := ethutil.Encode(block.RlpDataForStorage())
|
encodedBlock := common.Encode(block.RlpDataForStorage())
|
||||||
|
|
||||||
key := append(blockHashPre, block.Hash()...)
|
key := append(blockHashPre, block.Hash()...)
|
||||||
bc.blockDb.Put(key, encodedBlock)
|
bc.blockDb.Put(key, encodedBlock)
|
||||||
@ -309,7 +309,7 @@ func (self *ChainManager) GetBlockHashesFromHash(hash []byte, max uint64) (chain
|
|||||||
}
|
}
|
||||||
|
|
||||||
chain = append(chain, block.Hash())
|
chain = append(chain, block.Hash())
|
||||||
if block.Header().Number.Cmp(ethutil.Big0) <= 0 {
|
if block.Header().Number.Cmp(common.Big0) <= 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -434,7 +434,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
|||||||
// Compare the TD of the last known block in the canonical chain to make sure it's greater.
|
// Compare the TD of the last known block in the canonical chain to make sure it's greater.
|
||||||
// At this point it's possible that a different chain (fork) becomes the new canonical chain.
|
// At this point it's possible that a different chain (fork) becomes the new canonical chain.
|
||||||
if td.Cmp(self.td) > 0 {
|
if td.Cmp(self.td) > 0 {
|
||||||
if block.Header().Number.Cmp(new(big.Int).Add(cblock.Header().Number, ethutil.Big1)) < 0 {
|
if block.Header().Number.Cmp(new(big.Int).Add(cblock.Header().Number, common.Big1)) < 0 {
|
||||||
chainlogger.Infof("Split detected. New head #%v (%x) TD=%v, was #%v (%x) TD=%v\n", block.Header().Number, block.Hash()[:4], td, cblock.Header().Number, cblock.Hash()[:4], self.td)
|
chainlogger.Infof("Split detected. New head #%v (%x) TD=%v, was #%v (%x) TD=%v\n", block.Header().Number, block.Hash()[:4], td, cblock.Header().Number, cblock.Hash()[:4], self.td)
|
||||||
|
|
||||||
queue[i] = ChainSplitEvent{block}
|
queue[i] = ChainSplitEvent{block}
|
||||||
@ -446,10 +446,10 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
|
|||||||
|
|
||||||
/* XXX crashes
|
/* XXX crashes
|
||||||
jsonlogger.LogJson(&logger.EthChainNewHead{
|
jsonlogger.LogJson(&logger.EthChainNewHead{
|
||||||
BlockHash: ethutil.Bytes2Hex(block.Hash()),
|
BlockHash: common.Bytes2Hex(block.Hash()),
|
||||||
BlockNumber: block.Number(),
|
BlockNumber: block.Number(),
|
||||||
ChainHeadHash: ethutil.Bytes2Hex(cblock.Hash()),
|
ChainHeadHash: common.Bytes2Hex(cblock.Hash()),
|
||||||
BlockPrevHash: ethutil.Bytes2Hex(block.ParentHash()),
|
BlockPrevHash: common.Bytes2Hex(block.ParentHash()),
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -19,21 +19,21 @@ import (
|
|||||||
var ZeroHash256 = make([]byte, 32)
|
var ZeroHash256 = make([]byte, 32)
|
||||||
var ZeroHash160 = make([]byte, 20)
|
var ZeroHash160 = make([]byte, 20)
|
||||||
var ZeroHash512 = make([]byte, 64)
|
var ZeroHash512 = make([]byte, 64)
|
||||||
var EmptyShaList = crypto.Sha3(ethutil.Encode([]interface{}{}))
|
var EmptyShaList = crypto.Sha3(common.Encode([]interface{}{}))
|
||||||
var EmptyListRoot = crypto.Sha3(ethutil.Encode(""))
|
var EmptyListRoot = crypto.Sha3(common.Encode(""))
|
||||||
|
|
||||||
var GenesisDiff = big.NewInt(131072)
|
var GenesisDiff = big.NewInt(131072)
|
||||||
var GenesisGasLimit = big.NewInt(3141592)
|
var GenesisGasLimit = big.NewInt(3141592)
|
||||||
|
|
||||||
func GenesisBlock(db ethutil.Database) *types.Block {
|
func GenesisBlock(db common.Database) *types.Block {
|
||||||
genesis := types.NewBlock(ZeroHash256, ZeroHash160, nil, GenesisDiff, 42, "")
|
genesis := types.NewBlock(ZeroHash256, ZeroHash160, nil, GenesisDiff, 42, "")
|
||||||
genesis.Header().Number = ethutil.Big0
|
genesis.Header().Number = common.Big0
|
||||||
genesis.Header().GasLimit = GenesisGasLimit
|
genesis.Header().GasLimit = GenesisGasLimit
|
||||||
genesis.Header().GasUsed = ethutil.Big0
|
genesis.Header().GasUsed = common.Big0
|
||||||
genesis.Header().Time = 0
|
genesis.Header().Time = 0
|
||||||
genesis.Header().MixDigest = make([]byte, 32)
|
genesis.Header().MixDigest = make([]byte, 32)
|
||||||
|
|
||||||
genesis.Td = ethutil.Big0
|
genesis.Td = common.Big0
|
||||||
|
|
||||||
genesis.SetUncles([]*types.Header{})
|
genesis.SetUncles([]*types.Header{})
|
||||||
genesis.SetTransactions(types.Transactions{})
|
genesis.SetTransactions(types.Transactions{})
|
||||||
@ -48,9 +48,9 @@ func GenesisBlock(db ethutil.Database) *types.Block {
|
|||||||
|
|
||||||
statedb := state.New(genesis.Root(), db)
|
statedb := state.New(genesis.Root(), db)
|
||||||
for addr, account := range accounts {
|
for addr, account := range accounts {
|
||||||
codedAddr := ethutil.Hex2Bytes(addr)
|
codedAddr := common.Hex2Bytes(addr)
|
||||||
accountState := statedb.GetAccount(codedAddr)
|
accountState := statedb.GetAccount(codedAddr)
|
||||||
accountState.SetBalance(ethutil.Big(account.Balance))
|
accountState.SetBalance(common.Big(account.Balance))
|
||||||
statedb.UpdateStateObject(accountState)
|
statedb.UpdateStateObject(accountState)
|
||||||
}
|
}
|
||||||
statedb.Sync()
|
statedb.Sync()
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
// "github.com/ethereum/go-ethereum/crypto"
|
// "github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ type TestManager struct {
|
|||||||
// stateManager *StateManager
|
// stateManager *StateManager
|
||||||
eventMux *event.TypeMux
|
eventMux *event.TypeMux
|
||||||
|
|
||||||
db ethutil.Database
|
db common.Database
|
||||||
txPool *TxPool
|
txPool *TxPool
|
||||||
blockChain *ChainManager
|
blockChain *ChainManager
|
||||||
Blocks []*types.Block
|
Blocks []*types.Block
|
||||||
@ -58,7 +58,7 @@ func (tm *TestManager) EventMux() *event.TypeMux {
|
|||||||
// return nil
|
// return nil
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func (tm *TestManager) Db() ethutil.Database {
|
func (tm *TestManager) Db() common.Database {
|
||||||
return tm.db
|
return tm.db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
)
|
)
|
||||||
@ -13,7 +13,7 @@ type Backend interface {
|
|||||||
PeerCount() int
|
PeerCount() int
|
||||||
IsListening() bool
|
IsListening() bool
|
||||||
Peers() []*p2p.Peer
|
Peers() []*p2p.Peer
|
||||||
BlockDb() ethutil.Database
|
BlockDb() common.Database
|
||||||
StateDb() ethutil.Database
|
StateDb() common.Database
|
||||||
EventMux() *event.TypeMux
|
EventMux() *event.TypeMux
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
"github.com/ethereum/go-ethereum/vm"
|
"github.com/ethereum/go-ethereum/vm"
|
||||||
)
|
)
|
||||||
@ -58,7 +58,7 @@ type Message interface {
|
|||||||
|
|
||||||
func AddressFromMessage(msg Message) []byte {
|
func AddressFromMessage(msg Message) []byte {
|
||||||
// Generate a new address
|
// Generate a new address
|
||||||
return crypto.Sha3(ethutil.NewValue([]interface{}{msg.From(), msg.Nonce()}).Encode())[12:]
|
return crypto.Sha3(common.NewValue([]interface{}{msg.From(), msg.Nonce()}).Encode())[12:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func MessageCreatesContract(msg Message) bool {
|
func MessageCreatesContract(msg Message) bool {
|
||||||
@ -226,9 +226,9 @@ func (self *StateTransition) refundGas() {
|
|||||||
remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice())
|
remaining := new(big.Int).Mul(self.gas, self.msg.GasPrice())
|
||||||
sender.AddBalance(remaining)
|
sender.AddBalance(remaining)
|
||||||
|
|
||||||
uhalf := new(big.Int).Div(self.gasUsed(), ethutil.Big2)
|
uhalf := new(big.Int).Div(self.gasUsed(), common.Big2)
|
||||||
for addr, ref := range self.state.Refunds() {
|
for addr, ref := range self.state.Refunds() {
|
||||||
refund := ethutil.BigMin(uhalf, ref)
|
refund := common.BigMin(uhalf, ref)
|
||||||
self.gas.Add(self.gas, refund)
|
self.gas.Add(self.gas, refund)
|
||||||
self.state.AddBalance([]byte(addr), refund.Mul(refund, self.msg.GasPrice()))
|
self.state.AddBalance([]byte(addr), refund.Mul(refund, self.msg.GasPrice()))
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
@ -113,13 +113,13 @@ func (self *TxPool) add(tx *types.Transaction) error {
|
|||||||
|
|
||||||
var to string
|
var to string
|
||||||
if len(tx.To()) > 0 {
|
if len(tx.To()) > 0 {
|
||||||
to = ethutil.Bytes2Hex(tx.To()[:4])
|
to = common.Bytes2Hex(tx.To()[:4])
|
||||||
} else {
|
} else {
|
||||||
to = "[NEW_CONTRACT]"
|
to = "[NEW_CONTRACT]"
|
||||||
}
|
}
|
||||||
var from string
|
var from string
|
||||||
if len(tx.From()) > 0 {
|
if len(tx.From()) > 0 {
|
||||||
from = ethutil.Bytes2Hex(tx.From()[:4])
|
from = common.Bytes2Hex(tx.From()[:4])
|
||||||
} else {
|
} else {
|
||||||
return errors.New(fmt.Sprintf("FROM ADDRESS MUST BE POSITIVE (was %v)", tx.From()))
|
return errors.New(fmt.Sprintf("FROM ADDRESS MUST BE POSITIVE (was %v)", tx.From()))
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,13 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
// State query interface
|
// State query interface
|
||||||
type stateQuery struct{ db ethutil.Database }
|
type stateQuery struct{ db common.Database }
|
||||||
|
|
||||||
func SQ() stateQuery {
|
func SQ() stateQuery {
|
||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
@ -25,7 +25,7 @@ func (self stateQuery) GetAccount(addr []byte) *state.StateObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func transaction() *types.Transaction {
|
func transaction() *types.Transaction {
|
||||||
return types.NewTransactionMessage(make([]byte, 20), ethutil.Big0, ethutil.Big0, ethutil.Big0, nil)
|
return types.NewTransactionMessage(make([]byte, 20), common.Big0, common.Big0, common.Big0, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setup() (*TxPool, *ecdsa.PrivateKey) {
|
func setup() (*TxPool, *ecdsa.PrivateKey) {
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -74,11 +74,11 @@ func (self *Header) RlpData() interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *Header) Hash() []byte {
|
func (self *Header) Hash() []byte {
|
||||||
return crypto.Sha3(ethutil.Encode(self.rlpData(true)))
|
return crypto.Sha3(common.Encode(self.rlpData(true)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Header) HashNoNonce() []byte {
|
func (self *Header) HashNoNonce() []byte {
|
||||||
return crypto.Sha3(ethutil.Encode(self.rlpData(false)))
|
return crypto.Sha3(common.Encode(self.rlpData(false)))
|
||||||
}
|
}
|
||||||
|
|
||||||
type Block struct {
|
type Block struct {
|
||||||
@ -148,7 +148,7 @@ func (self *Block) Uncles() []*Header {
|
|||||||
|
|
||||||
func (self *Block) SetUncles(uncleHeaders []*Header) {
|
func (self *Block) SetUncles(uncleHeaders []*Header) {
|
||||||
self.uncles = uncleHeaders
|
self.uncles = uncleHeaders
|
||||||
self.header.UncleHash = crypto.Sha3(ethutil.Encode(uncleHeaders))
|
self.header.UncleHash = crypto.Sha3(common.Encode(uncleHeaders))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Block) Transactions() Transactions {
|
func (self *Block) Transactions() Transactions {
|
||||||
@ -213,7 +213,7 @@ func (self *Block) GasLimit() *big.Int { return self.header.GasLimit }
|
|||||||
func (self *Block) GasUsed() *big.Int { return self.header.GasUsed }
|
func (self *Block) GasUsed() *big.Int { return self.header.GasUsed }
|
||||||
func (self *Block) Root() []byte { return self.header.Root }
|
func (self *Block) Root() []byte { return self.header.Root }
|
||||||
func (self *Block) SetRoot(root []byte) { self.header.Root = root }
|
func (self *Block) SetRoot(root []byte) { self.header.Root = root }
|
||||||
func (self *Block) Size() ethutil.StorageSize { return ethutil.StorageSize(len(ethutil.Encode(self))) }
|
func (self *Block) Size() common.StorageSize { return common.StorageSize(len(common.Encode(self))) }
|
||||||
func (self *Block) GetTransaction(i int) *Transaction {
|
func (self *Block) GetTransaction(i int) *Transaction {
|
||||||
if len(self.transactions) > i {
|
if len(self.transactions) > i {
|
||||||
return self.transactions[i]
|
return self.transactions[i]
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ func CreateBloom(receipts Receipts) []byte {
|
|||||||
bin.Or(bin, LogsBloom(receipt.logs))
|
bin.Or(bin, LogsBloom(receipt.logs))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ethutil.LeftPadBytes(bin.Bytes(), 256)
|
return common.LeftPadBytes(bin.Bytes(), 256)
|
||||||
}
|
}
|
||||||
|
|
||||||
func LogsBloom(logs state.Logs) *big.Int {
|
func LogsBloom(logs state.Logs) *big.Int {
|
||||||
@ -28,7 +28,7 @@ func LogsBloom(logs state.Logs) *big.Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, b := range data {
|
for _, b := range data {
|
||||||
bin.Or(bin, ethutil.BigD(bloom9(crypto.Sha3(b)).Bytes()))
|
bin.Or(bin, common.BigD(bloom9(crypto.Sha3(b)).Bytes()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ func bloom9(b []byte) *big.Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func BloomLookup(bin, topic []byte) bool {
|
func BloomLookup(bin, topic []byte) bool {
|
||||||
bloom := ethutil.BigD(bin)
|
bloom := common.BigD(bin)
|
||||||
cmp := bloom9(crypto.Sha3(topic))
|
cmp := bloom9(crypto.Sha3(topic))
|
||||||
|
|
||||||
return bloom.And(bloom, cmp).Cmp(cmp) == 0
|
return bloom.And(bloom, cmp).Cmp(cmp) == 0
|
||||||
|
@ -22,10 +22,10 @@ func TestBloom9(t *testing.T) {
|
|||||||
|
|
||||||
func TestAddress(t *testing.T) {
|
func TestAddress(t *testing.T) {
|
||||||
block := &Block{}
|
block := &Block{}
|
||||||
block.Coinbase = ethutil.Hex2Bytes("22341ae42d6dd7384bc8584e50419ea3ac75b83f")
|
block.Coinbase = common.Hex2Bytes("22341ae42d6dd7384bc8584e50419ea3ac75b83f")
|
||||||
fmt.Printf("%x\n", crypto.Sha3(block.Coinbase))
|
fmt.Printf("%x\n", crypto.Sha3(block.Coinbase))
|
||||||
|
|
||||||
bin := CreateBloom(block)
|
bin := CreateBloom(block)
|
||||||
fmt.Printf("bin = %x\n", ethutil.LeftPadBytes(bin, 64))
|
fmt.Printf("bin = %x\n", common.LeftPadBytes(bin, 64))
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
@ -2,7 +2,7 @@ package types
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ func DeriveSha(list DerivableList) []byte {
|
|||||||
db, _ := ethdb.NewMemDatabase()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
trie := trie.New(nil, db)
|
trie := trie.New(nil, db)
|
||||||
for i := 0; i < list.Len(); i++ {
|
for i := 0; i < list.Len(); i++ {
|
||||||
trie.Update(ethutil.Encode(i), list.GetRlp(i))
|
trie.Update(common.Encode(i), list.GetRlp(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
return trie.Root()
|
return trie.Root()
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,10 +17,10 @@ type Receipt struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewReceipt(root []byte, cumalativeGasUsed *big.Int) *Receipt {
|
func NewReceipt(root []byte, cumalativeGasUsed *big.Int) *Receipt {
|
||||||
return &Receipt{PostState: ethutil.CopyBytes(root), CumulativeGasUsed: new(big.Int).Set(cumalativeGasUsed)}
|
return &Receipt{PostState: common.CopyBytes(root), CumulativeGasUsed: new(big.Int).Set(cumalativeGasUsed)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRecieptFromValue(val *ethutil.Value) *Receipt {
|
func NewRecieptFromValue(val *common.Value) *Receipt {
|
||||||
r := &Receipt{}
|
r := &Receipt{}
|
||||||
r.RlpValueDecode(val)
|
r.RlpValueDecode(val)
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ func (self *Receipt) SetLogs(logs state.Logs) {
|
|||||||
self.logs = logs
|
self.logs = logs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Receipt) RlpValueDecode(decoder *ethutil.Value) {
|
func (self *Receipt) RlpValueDecode(decoder *common.Value) {
|
||||||
self.PostState = decoder.Get(0).Bytes()
|
self.PostState = decoder.Get(0).Bytes()
|
||||||
self.CumulativeGasUsed = decoder.Get(1).BigInt()
|
self.CumulativeGasUsed = decoder.Get(1).BigInt()
|
||||||
self.Bloom = decoder.Get(2).Bytes()
|
self.Bloom = decoder.Get(2).Bytes()
|
||||||
@ -47,7 +47,7 @@ func (self *Receipt) RlpData() interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *Receipt) RlpEncode() []byte {
|
func (self *Receipt) RlpEncode() []byte {
|
||||||
return ethutil.Encode(self.RlpData())
|
return common.Encode(self.RlpData())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Receipt) Cmp(other *Receipt) bool {
|
func (self *Receipt) Cmp(other *Receipt) bool {
|
||||||
@ -74,8 +74,8 @@ func (self Receipts) RlpData() interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self Receipts) RlpEncode() []byte {
|
func (self Receipts) RlpEncode() []byte {
|
||||||
return ethutil.Encode(self.RlpData())
|
return common.Encode(self.RlpData())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self Receipts) Len() int { return len(self) }
|
func (self Receipts) Len() int { return len(self) }
|
||||||
func (self Receipts) GetRlp(i int) []byte { return ethutil.Rlp(self[i]) }
|
func (self Receipts) GetRlp(i int) []byte { return common.Rlp(self[i]) }
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ func NewTransactionFromBytes(data []byte) *Transaction {
|
|||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTransactionFromAmount(val *ethutil.Value) *Transaction {
|
func NewTransactionFromAmount(val *common.Value) *Transaction {
|
||||||
tx := &Transaction{}
|
tx := &Transaction{}
|
||||||
tx.RlpValueDecode(val)
|
tx.RlpValueDecode(val)
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ func NewTransactionFromAmount(val *ethutil.Value) *Transaction {
|
|||||||
func (tx *Transaction) Hash() []byte {
|
func (tx *Transaction) Hash() []byte {
|
||||||
data := []interface{}{tx.AccountNonce, tx.Price, tx.GasLimit, tx.Recipient, tx.Amount, tx.Payload}
|
data := []interface{}{tx.AccountNonce, tx.Price, tx.GasLimit, tx.Recipient, tx.Amount, tx.Payload}
|
||||||
|
|
||||||
return crypto.Sha3(ethutil.Encode(data))
|
return crypto.Sha3(common.Encode(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Transaction) Data() []byte {
|
func (self *Transaction) Data() []byte {
|
||||||
@ -89,8 +89,8 @@ func (self *Transaction) To() []byte {
|
|||||||
|
|
||||||
func (tx *Transaction) Curve() (v byte, r []byte, s []byte) {
|
func (tx *Transaction) Curve() (v byte, r []byte, s []byte) {
|
||||||
v = byte(tx.V)
|
v = byte(tx.V)
|
||||||
r = ethutil.LeftPadBytes(tx.R, 32)
|
r = common.LeftPadBytes(tx.R, 32)
|
||||||
s = ethutil.LeftPadBytes(tx.S, 32)
|
s = common.LeftPadBytes(tx.S, 32)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -159,14 +159,14 @@ func (tx *Transaction) RlpData() interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) RlpEncode() []byte {
|
func (tx *Transaction) RlpEncode() []byte {
|
||||||
return ethutil.Encode(tx)
|
return common.Encode(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) RlpDecode(data []byte) {
|
func (tx *Transaction) RlpDecode(data []byte) {
|
||||||
rlp.Decode(bytes.NewReader(data), tx)
|
rlp.Decode(bytes.NewReader(data), tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value) {
|
func (tx *Transaction) RlpValueDecode(decoder *common.Value) {
|
||||||
tx.AccountNonce = decoder.Get(0).Uint()
|
tx.AccountNonce = decoder.Get(0).Uint()
|
||||||
tx.Price = decoder.Get(1).BigInt()
|
tx.Price = decoder.Get(1).BigInt()
|
||||||
tx.GasLimit = decoder.Get(2).BigInt()
|
tx.GasLimit = decoder.Get(2).BigInt()
|
||||||
@ -206,7 +206,7 @@ func (tx *Transaction) String() string {
|
|||||||
tx.V,
|
tx.V,
|
||||||
tx.R,
|
tx.R,
|
||||||
tx.S,
|
tx.S,
|
||||||
ethutil.Encode(tx),
|
common.Encode(tx),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ func (self Transactions) RlpData() interface{} {
|
|||||||
}
|
}
|
||||||
func (s Transactions) Len() int { return len(s) }
|
func (s Transactions) Len() int { return len(s) }
|
||||||
func (s Transactions) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
func (s Transactions) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||||
func (s Transactions) GetRlp(i int) []byte { return ethutil.Rlp(s[i]) }
|
func (s Transactions) GetRlp(i int) []byte { return common.Rlp(s[i]) }
|
||||||
|
|
||||||
type TxByNonce struct{ Transactions }
|
type TxByNonce struct{ Transactions }
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/crypto/ecies"
|
"github.com/ethereum/go-ethereum/crypto/ecies"
|
||||||
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
||||||
"github.com/ethereum/go-ethereum/crypto/sha3"
|
"github.com/ethereum/go-ethereum/crypto/sha3"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"golang.org/x/crypto/pbkdf2"
|
"golang.org/x/crypto/pbkdf2"
|
||||||
"golang.org/x/crypto/ripemd160"
|
"golang.org/x/crypto/ripemd160"
|
||||||
)
|
)
|
||||||
@ -39,7 +39,7 @@ func Sha3(data ...[]byte) []byte {
|
|||||||
|
|
||||||
// Creates an ethereum address given the bytes and the nonce
|
// Creates an ethereum address given the bytes and the nonce
|
||||||
func CreateAddress(b []byte, nonce uint64) []byte {
|
func CreateAddress(b []byte, nonce uint64) []byte {
|
||||||
return Sha3(ethutil.NewValue([]interface{}{b, nonce}).Encode())[12:]
|
return Sha3(common.NewValue([]interface{}{b, nonce}).Encode())[12:]
|
||||||
}
|
}
|
||||||
|
|
||||||
func Sha256(data []byte) []byte {
|
func Sha256(data []byte) []byte {
|
||||||
@ -74,7 +74,7 @@ func ToECDSA(prv []byte) *ecdsa.PrivateKey {
|
|||||||
|
|
||||||
priv := new(ecdsa.PrivateKey)
|
priv := new(ecdsa.PrivateKey)
|
||||||
priv.PublicKey.Curve = S256()
|
priv.PublicKey.Curve = S256()
|
||||||
priv.D = ethutil.BigD(prv)
|
priv.D = common.BigD(prv)
|
||||||
priv.PublicKey.X, priv.PublicKey.Y = S256().ScalarBaseMult(prv)
|
priv.PublicKey.X, priv.PublicKey.Y = S256().ScalarBaseMult(prv)
|
||||||
return priv
|
return priv
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ func Sign(hash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error) {
|
|||||||
return nil, fmt.Errorf("hash is required to be exactly 32 bytes (%d)", len(hash))
|
return nil, fmt.Errorf("hash is required to be exactly 32 bytes (%d)", len(hash))
|
||||||
}
|
}
|
||||||
|
|
||||||
sig, err = secp256k1.Sign(hash, ethutil.LeftPadBytes(prv.D.Bytes(), prv.Params().BitSize/8))
|
sig, err = secp256k1.Sign(hash, common.LeftPadBytes(prv.D.Bytes(), prv.Params().BitSize/8))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error
|
|||||||
Address: PubkeyToAddress(ecKey.PublicKey),
|
Address: PubkeyToAddress(ecKey.PublicKey),
|
||||||
PrivateKey: ecKey,
|
PrivateKey: ecKey,
|
||||||
}
|
}
|
||||||
derivedAddr := ethutil.Bytes2Hex(key.Address)
|
derivedAddr := common.Bytes2Hex(key.Address)
|
||||||
expectedAddr := preSaleKeyStruct.EthAddr
|
expectedAddr := preSaleKeyStruct.EthAddr
|
||||||
if derivedAddr != expectedAddr {
|
if derivedAddr != expectedAddr {
|
||||||
err = errors.New("decrypted addr not equal to expected addr")
|
err = errors.New("decrypted addr not equal to expected addr")
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
// These tests are sanity checks.
|
// These tests are sanity checks.
|
||||||
@ -53,7 +53,7 @@ func BenchmarkSha3(b *testing.B) {
|
|||||||
|
|
||||||
func Test0Key(t *testing.T) {
|
func Test0Key(t *testing.T) {
|
||||||
t.Skip()
|
t.Skip()
|
||||||
key := ethutil.Hex2Bytes("1111111111111111111111111111111111111111111111111111111111111111")
|
key := common.Hex2Bytes("1111111111111111111111111111111111111111111111111111111111111111")
|
||||||
|
|
||||||
p, err := secp256k1.GeneratePubKey(key)
|
p, err := secp256k1.GeneratePubKey(key)
|
||||||
addr := Sha3(p[1:])[12:]
|
addr := Sha3(p[1:])[12:]
|
||||||
|
@ -5,13 +5,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBox(t *testing.T) {
|
func TestBox(t *testing.T) {
|
||||||
prv1 := ToECDSA(ethutil.Hex2Bytes("4b50fa71f5c3eeb8fdc452224b2395af2fcc3d125e06c32c82e048c0559db03f"))
|
prv1 := ToECDSA(common.Hex2Bytes("4b50fa71f5c3eeb8fdc452224b2395af2fcc3d125e06c32c82e048c0559db03f"))
|
||||||
prv2 := ToECDSA(ethutil.Hex2Bytes("d0b043b4c5d657670778242d82d68a29d25d7d711127d17b8e299f156dad361a"))
|
prv2 := ToECDSA(common.Hex2Bytes("d0b043b4c5d657670778242d82d68a29d25d7d711127d17b8e299f156dad361a"))
|
||||||
pub2 := ToECDSAPub(ethutil.Hex2Bytes("04bd27a63c91fe3233c5777e6d3d7b39204d398c8f92655947eb5a373d46e1688f022a1632d264725cbc7dc43ee1cfebde42fa0a86d08b55d2acfbb5e9b3b48dc5"))
|
pub2 := ToECDSAPub(common.Hex2Bytes("04bd27a63c91fe3233c5777e6d3d7b39204d398c8f92655947eb5a373d46e1688f022a1632d264725cbc7dc43ee1cfebde42fa0a86d08b55d2acfbb5e9b3b48dc5"))
|
||||||
|
|
||||||
message := []byte("Hello, world.")
|
message := []byte("Hello, world.")
|
||||||
ct, err := Encrypt(pub2, message)
|
ct, err := Encrypt(pub2, message)
|
||||||
|
@ -2,13 +2,13 @@ package crypto
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/crypto/randentropy"
|
"github.com/ethereum/go-ethereum/crypto/randentropy"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestKeyStorePlain(t *testing.T) {
|
func TestKeyStorePlain(t *testing.T) {
|
||||||
ks := NewKeyStorePlain(ethutil.DefaultDataDir())
|
ks := NewKeyStorePlain(common.DefaultDataDir())
|
||||||
pass := "" // not used but required by API
|
pass := "" // not used but required by API
|
||||||
k1, err := ks.GenerateNewKey(randentropy.Reader, pass)
|
k1, err := ks.GenerateNewKey(randentropy.Reader, pass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -36,7 +36,7 @@ func TestKeyStorePlain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestKeyStorePassphrase(t *testing.T) {
|
func TestKeyStorePassphrase(t *testing.T) {
|
||||||
ks := NewKeyStorePassphrase(ethutil.DefaultDataDir())
|
ks := NewKeyStorePassphrase(common.DefaultDataDir())
|
||||||
pass := "foo"
|
pass := "foo"
|
||||||
k1, err := ks.GenerateNewKey(randentropy.Reader, pass)
|
k1, err := ks.GenerateNewKey(randentropy.Reader, pass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -62,7 +62,7 @@ func TestKeyStorePassphrase(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestKeyStorePassphraseDecryptionFail(t *testing.T) {
|
func TestKeyStorePassphraseDecryptionFail(t *testing.T) {
|
||||||
ks := NewKeyStorePassphrase(ethutil.DefaultDataDir())
|
ks := NewKeyStorePassphrase(common.DefaultDataDir())
|
||||||
pass := "foo"
|
pass := "foo"
|
||||||
k1, err := ks.GenerateNewKey(randentropy.Reader, pass)
|
k1, err := ks.GenerateNewKey(randentropy.Reader, pass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -90,7 +90,7 @@ func TestImportPreSaleKey(t *testing.T) {
|
|||||||
// python pyethsaletool.py genwallet
|
// python pyethsaletool.py genwallet
|
||||||
// with password "foo"
|
// with password "foo"
|
||||||
fileContent := "{\"encseed\": \"26d87f5f2bf9835f9a47eefae571bc09f9107bb13d54ff12a4ec095d01f83897494cf34f7bed2ed34126ecba9db7b62de56c9d7cd136520a0427bfb11b8954ba7ac39b90d4650d3448e31185affcd74226a68f1e94b1108e6e0a4a91cdd83eba\", \"ethaddr\": \"d4584b5f6229b7be90727b0fc8c6b91bb427821f\", \"email\": \"gustav.simonsson@gmail.com\", \"btcaddr\": \"1EVknXyFC68kKNLkh6YnKzW41svSRoaAcx\"}"
|
fileContent := "{\"encseed\": \"26d87f5f2bf9835f9a47eefae571bc09f9107bb13d54ff12a4ec095d01f83897494cf34f7bed2ed34126ecba9db7b62de56c9d7cd136520a0427bfb11b8954ba7ac39b90d4650d3448e31185affcd74226a68f1e94b1108e6e0a4a91cdd83eba\", \"ethaddr\": \"d4584b5f6229b7be90727b0fc8c6b91bb427821f\", \"email\": \"gustav.simonsson@gmail.com\", \"btcaddr\": \"1EVknXyFC68kKNLkh6YnKzW41svSRoaAcx\"}"
|
||||||
ks := NewKeyStorePassphrase(ethutil.DefaultDataDir())
|
ks := NewKeyStorePassphrase(common.DefaultDataDir())
|
||||||
pass := "foo"
|
pass := "foo"
|
||||||
_, err := ImportPreSaleKey(ks, []byte(fileContent), pass)
|
_, err := ImportPreSaleKey(ks, []byte(fileContent), pass)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
"github.com/ethereum/go-ethereum/crypto/secp256k1"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type KeyPair struct {
|
type KeyPair struct {
|
||||||
@ -40,19 +40,19 @@ func (k *KeyPair) Address() []byte {
|
|||||||
|
|
||||||
func (k *KeyPair) Mnemonic() string {
|
func (k *KeyPair) Mnemonic() string {
|
||||||
if k.mnemonic == "" {
|
if k.mnemonic == "" {
|
||||||
k.mnemonic = strings.Join(MnemonicEncode(ethutil.Bytes2Hex(k.PrivateKey)), " ")
|
k.mnemonic = strings.Join(MnemonicEncode(common.Bytes2Hex(k.PrivateKey)), " ")
|
||||||
}
|
}
|
||||||
return k.mnemonic
|
return k.mnemonic
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *KeyPair) AsStrings() (string, string, string, string) {
|
func (k *KeyPair) AsStrings() (string, string, string, string) {
|
||||||
return k.Mnemonic(), ethutil.Bytes2Hex(k.Address()), ethutil.Bytes2Hex(k.PrivateKey), ethutil.Bytes2Hex(k.PublicKey)
|
return k.Mnemonic(), common.Bytes2Hex(k.Address()), common.Bytes2Hex(k.PrivateKey), common.Bytes2Hex(k.PublicKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *KeyPair) RlpEncode() []byte {
|
func (k *KeyPair) RlpEncode() []byte {
|
||||||
return k.RlpValue().Encode()
|
return k.RlpValue().Encode()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *KeyPair) RlpValue() *ethutil.Value {
|
func (k *KeyPair) RlpValue() *common.Value {
|
||||||
return ethutil.NewValue(k.PrivateKey)
|
return common.NewValue(k.PrivateKey)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/miner"
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
@ -65,7 +65,7 @@ type Config struct {
|
|||||||
|
|
||||||
// NewDB is used to create databases.
|
// NewDB is used to create databases.
|
||||||
// If nil, the default is to create leveldb databases on disk.
|
// If nil, the default is to create leveldb databases on disk.
|
||||||
NewDB func(path string) (ethutil.Database, error)
|
NewDB func(path string) (common.Database, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *Config) parseBootNodes() []*discover.Node {
|
func (cfg *Config) parseBootNodes() []*discover.Node {
|
||||||
@ -113,9 +113,9 @@ type Ethereum struct {
|
|||||||
shutdownChan chan bool
|
shutdownChan chan bool
|
||||||
|
|
||||||
// DB interfaces
|
// DB interfaces
|
||||||
blockDb ethutil.Database // Block chain database
|
blockDb common.Database // Block chain database
|
||||||
stateDb ethutil.Database // State changes database
|
stateDb common.Database // State changes database
|
||||||
extraDb ethutil.Database // Extra database (txs, etc)
|
extraDb common.Database // Extra database (txs, etc)
|
||||||
|
|
||||||
//*** SERVICES ***
|
//*** SERVICES ***
|
||||||
// State manager for processing new blocks and managing the over all states
|
// State manager for processing new blocks and managing the over all states
|
||||||
@ -146,7 +146,7 @@ func New(config *Config) (*Ethereum, error) {
|
|||||||
|
|
||||||
newdb := config.NewDB
|
newdb := config.NewDB
|
||||||
if newdb == nil {
|
if newdb == nil {
|
||||||
newdb = func(path string) (ethutil.Database, error) { return ethdb.NewLDBDatabase(path) }
|
newdb = func(path string) (common.Database, error) { return ethdb.NewLDBDatabase(path) }
|
||||||
}
|
}
|
||||||
blockDb, err := newdb(path.Join(config.DataDir, "blockchain"))
|
blockDb, err := newdb(path.Join(config.DataDir, "blockchain"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -160,7 +160,7 @@ func New(config *Config) (*Ethereum, error) {
|
|||||||
|
|
||||||
// Perform database sanity checks
|
// Perform database sanity checks
|
||||||
d, _ := blockDb.Get([]byte("ProtocolVersion"))
|
d, _ := blockDb.Get([]byte("ProtocolVersion"))
|
||||||
protov := ethutil.NewValue(d).Uint()
|
protov := common.NewValue(d).Uint()
|
||||||
if protov != ProtocolVersion && protov != 0 {
|
if protov != ProtocolVersion && protov != 0 {
|
||||||
path := path.Join(config.DataDir, "blockchain")
|
path := path.Join(config.DataDir, "blockchain")
|
||||||
return nil, fmt.Errorf("Database version mismatch. Protocol(%d / %d). `rm -rf %s`", protov, ProtocolVersion, path)
|
return nil, fmt.Errorf("Database version mismatch. Protocol(%d / %d). `rm -rf %s`", protov, ProtocolVersion, path)
|
||||||
@ -304,9 +304,9 @@ func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
|
|||||||
func (s *Ethereum) BlockPool() *blockpool.BlockPool { return s.blockPool }
|
func (s *Ethereum) BlockPool() *blockpool.BlockPool { return s.blockPool }
|
||||||
func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper }
|
func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper }
|
||||||
func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux }
|
func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux }
|
||||||
func (s *Ethereum) BlockDb() ethutil.Database { return s.blockDb }
|
func (s *Ethereum) BlockDb() common.Database { return s.blockDb }
|
||||||
func (s *Ethereum) StateDb() ethutil.Database { return s.stateDb }
|
func (s *Ethereum) StateDb() common.Database { return s.stateDb }
|
||||||
func (s *Ethereum) ExtraDb() ethutil.Database { return s.extraDb }
|
func (s *Ethereum) ExtraDb() common.Database { return s.extraDb }
|
||||||
func (s *Ethereum) IsListening() bool { return true } // Always listening
|
func (s *Ethereum) IsListening() bool { return true } // Always listening
|
||||||
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() }
|
func (s *Ethereum) PeerCount() int { return s.net.PeerCount() }
|
||||||
func (s *Ethereum) PeerInfo() int { return s.net.PeerCount() }
|
func (s *Ethereum) PeerInfo() int { return s.net.PeerCount() }
|
||||||
@ -413,11 +413,11 @@ func (self *Ethereum) blockBroadcastLoop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveProtocolVersion(db ethutil.Database) {
|
func saveProtocolVersion(db common.Database) {
|
||||||
d, _ := db.Get([]byte("ProtocolVersion"))
|
d, _ := db.Get([]byte("ProtocolVersion"))
|
||||||
protocolVersion := ethutil.NewValue(d).Uint()
|
protocolVersion := common.NewValue(d).Uint()
|
||||||
|
|
||||||
if protocolVersion == 0 {
|
if protocolVersion == 0 {
|
||||||
db.Put([]byte("ProtocolVersion"), ethutil.NewValue(ProtocolVersion).Bytes())
|
db.Put([]byte("ProtocolVersion"), common.NewValue(ProtocolVersion).Bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,19 @@ package eth
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WritePeers(path string, addresses []string) {
|
func WritePeers(path string, addresses []string) {
|
||||||
if len(addresses) > 0 {
|
if len(addresses) > 0 {
|
||||||
data, _ := json.MarshalIndent(addresses, "", " ")
|
data, _ := json.MarshalIndent(addresses, "", " ")
|
||||||
ethutil.WriteFile(path, data)
|
common.WriteFile(path, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadPeers(path string) (ips []string, err error) {
|
func ReadPeers(path string) (ips []string, err error) {
|
||||||
var data string
|
var data string
|
||||||
data, err = ethutil.ReadAllFile(path)
|
data, err = common.ReadAllFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
json.Unmarshal([]byte(data), &ips)
|
json.Unmarshal([]byte(data), &ips)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/errs"
|
"github.com/ethereum/go-ethereum/errs"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
@ -167,7 +167,7 @@ func (self *ethProtocol) handle() error {
|
|||||||
}
|
}
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
jsonlogger.LogJson(&logger.EthTxReceived{
|
jsonlogger.LogJson(&logger.EthTxReceived{
|
||||||
TxHash: ethutil.Bytes2Hex(tx.Hash()),
|
TxHash: common.Bytes2Hex(tx.Hash()),
|
||||||
RemoteId: self.peer.ID().String(),
|
RemoteId: self.peer.ID().String(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -183,7 +183,7 @@ func (self *ethProtocol) handle() error {
|
|||||||
request.Amount = maxHashes
|
request.Amount = maxHashes
|
||||||
}
|
}
|
||||||
hashes := self.chainManager.GetBlockHashesFromHash(request.Hash, request.Amount)
|
hashes := self.chainManager.GetBlockHashesFromHash(request.Hash, request.Amount)
|
||||||
return p2p.EncodeMsg(self.rw, BlockHashesMsg, ethutil.ByteSliceToInterface(hashes)...)
|
return p2p.EncodeMsg(self.rw, BlockHashesMsg, common.ByteSliceToInterface(hashes)...)
|
||||||
|
|
||||||
case BlockHashesMsg:
|
case BlockHashesMsg:
|
||||||
msgStream := rlp.NewStream(msg.Payload)
|
msgStream := rlp.NewStream(msg.Payload)
|
||||||
@ -259,10 +259,10 @@ func (self *ethProtocol) handle() error {
|
|||||||
_, chainHead, _ := self.chainManager.Status()
|
_, chainHead, _ := self.chainManager.Status()
|
||||||
|
|
||||||
jsonlogger.LogJson(&logger.EthChainReceivedNewBlock{
|
jsonlogger.LogJson(&logger.EthChainReceivedNewBlock{
|
||||||
BlockHash: ethutil.Bytes2Hex(hash),
|
BlockHash: common.Bytes2Hex(hash),
|
||||||
BlockNumber: request.Block.Number(), // this surely must be zero
|
BlockNumber: request.Block.Number(), // this surely must be zero
|
||||||
ChainHeadHash: ethutil.Bytes2Hex(chainHead),
|
ChainHeadHash: common.Bytes2Hex(chainHead),
|
||||||
BlockPrevHash: ethutil.Bytes2Hex(request.Block.ParentHash()),
|
BlockPrevHash: common.Bytes2Hex(request.Block.ParentHash()),
|
||||||
RemoteId: self.peer.ID().String(),
|
RemoteId: self.peer.ID().String(),
|
||||||
})
|
})
|
||||||
// to simplify backend interface adding a new block
|
// to simplify backend interface adding a new block
|
||||||
@ -351,7 +351,7 @@ func (self *ethProtocol) requestBlockHashes(from []byte) error {
|
|||||||
|
|
||||||
func (self *ethProtocol) requestBlocks(hashes [][]byte) error {
|
func (self *ethProtocol) requestBlocks(hashes [][]byte) error {
|
||||||
self.peer.Debugf("fetching %v blocks", len(hashes))
|
self.peer.Debugf("fetching %v blocks", len(hashes))
|
||||||
return p2p.EncodeMsg(self.rw, GetBlocksMsg, ethutil.ByteSliceToInterface(hashes)...)
|
return p2p.EncodeMsg(self.rw, GetBlocksMsg, common.ByteSliceToInterface(hashes)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ethProtocol) protoError(code int, format string, params ...interface{}) (err *errs.Error) {
|
func (self *ethProtocol) protoError(code int, format string, params ...interface{}) (err *errs.Error) {
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/errs"
|
"github.com/ethereum/go-ethereum/errs"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
ethlogger "github.com/ethereum/go-ethereum/logger"
|
ethlogger "github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
@ -223,7 +223,7 @@ func (self *ethProtocolTester) run() {
|
|||||||
func TestStatusMsgErrors(t *testing.T) {
|
func TestStatusMsgErrors(t *testing.T) {
|
||||||
logInit()
|
logInit()
|
||||||
eth := newEth(t)
|
eth := newEth(t)
|
||||||
td := ethutil.Big1
|
td := common.Big1
|
||||||
currentBlock := []byte{1}
|
currentBlock := []byte{1}
|
||||||
genesis := []byte{2}
|
genesis := []byte{2}
|
||||||
eth.chainManager.status = func() (*big.Int, []byte, []byte) { return td, currentBlock, genesis }
|
eth.chainManager.status = func() (*big.Int, []byte, []byte) { return td, currentBlock, genesis }
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/compression/rle"
|
"github.com/ethereum/go-ethereum/compression/rle"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
"github.com/syndtr/goleveldb/leveldb/iterator"
|
"github.com/syndtr/goleveldb/leveldb/iterator"
|
||||||
)
|
)
|
||||||
@ -82,7 +82,7 @@ func (self *LDBDatabase) Print() {
|
|||||||
value := iter.Value()
|
value := iter.Value()
|
||||||
|
|
||||||
fmt.Printf("%x(%d): ", key, len(key))
|
fmt.Printf("%x(%d): ", key, len(key))
|
||||||
node := ethutil.NewValueFromBytes(value)
|
node := common.NewValueFromBytes(value)
|
||||||
fmt.Printf("%v\n", node)
|
fmt.Printf("%v\n", node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package ethdb
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -32,10 +32,10 @@ func (db *MemDatabase) Get(key []byte) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
func (db *MemDatabase) GetKeys() []*ethutil.Key {
|
func (db *MemDatabase) GetKeys() []*common.Key {
|
||||||
data, _ := db.Get([]byte("KeyRing"))
|
data, _ := db.Get([]byte("KeyRing"))
|
||||||
|
|
||||||
return []*ethutil.Key{ethutil.NewKeyFromBytes(data)}
|
return []*common.Key{common.NewKeyFromBytes(data)}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ func (db *MemDatabase) Delete(key []byte) error {
|
|||||||
func (db *MemDatabase) Print() {
|
func (db *MemDatabase) Print() {
|
||||||
for key, val := range db.db {
|
for key, val := range db.db {
|
||||||
fmt.Printf("%x(%d): ", key, len(key))
|
fmt.Printf("%x(%d): ", key, len(key))
|
||||||
node := ethutil.NewValueFromBytes(val)
|
node := common.NewValueFromBytes(val)
|
||||||
fmt.Printf("%q\n", node.Interface())
|
fmt.Printf("%q\n", node.Interface())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/obscuren/otto"
|
"github.com/obscuren/otto"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -37,7 +37,7 @@ func New(assetPath string) *JSRE {
|
|||||||
// Exec(file) loads and runs the contents of a file
|
// Exec(file) loads and runs the contents of a file
|
||||||
// if a relative path is given, the jsre's assetPath is used
|
// if a relative path is given, the jsre's assetPath is used
|
||||||
func (self *JSRE) Exec(file string) error {
|
func (self *JSRE) Exec(file string) error {
|
||||||
return self.exec(ethutil.AbsolutePath(self.assetPath, file))
|
return self.exec(common.AbsolutePath(self.assetPath, file))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *JSRE) exec(path string) error {
|
func (self *JSRE) exec(path string) error {
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/obscuren/otto"
|
"github.com/obscuren/otto"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testNativeObjectBinding struct {
|
type testNativeObjectBinding struct {
|
||||||
@ -26,7 +26,7 @@ func (no *testNativeObjectBinding) TestMethod(call otto.FunctionCall) otto.Value
|
|||||||
func TestExec(t *testing.T) {
|
func TestExec(t *testing.T) {
|
||||||
jsre := New("/tmp")
|
jsre := New("/tmp")
|
||||||
|
|
||||||
ethutil.WriteFile("/tmp/test.js", []byte(`msg = "testMsg"`))
|
common.WriteFile("/tmp/test.js", []byte(`msg = "testMsg"`))
|
||||||
err := jsre.Exec("test.js")
|
err := jsre.Exec("test.js")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected no error, got %v", err)
|
t.Errorf("expected no error, got %v", err)
|
||||||
@ -64,7 +64,7 @@ func TestBind(t *testing.T) {
|
|||||||
func TestLoadScript(t *testing.T) {
|
func TestLoadScript(t *testing.T) {
|
||||||
jsre := New("/tmp")
|
jsre := New("/tmp")
|
||||||
|
|
||||||
ethutil.WriteFile("/tmp/test.js", []byte(`msg = "testMsg"`))
|
common.WriteFile("/tmp/test.js", []byte(`msg = "testMsg"`))
|
||||||
_, err := jsre.Run(`loadScript("test.js")`)
|
_, err := jsre.Run(`loadScript("test.js")`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("expected no error, got %v", err)
|
t.Errorf("expected no error, got %v", err)
|
||||||
|
@ -6,11 +6,11 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func openLogFile(datadir string, filename string) *os.File {
|
func openLogFile(datadir string, filename string) *os.File {
|
||||||
path := ethutil.AbsolutePath(datadir, filename)
|
path := common.AbsolutePath(datadir, filename)
|
||||||
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("error opening log file '%s': %v", filename, err))
|
panic(fmt.Sprintf("error opening log file '%s': %v", filename, err))
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/pow"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
@ -155,10 +155,10 @@ func (self *worker) wait() {
|
|||||||
self.current.block.Header().MixDigest = work.MixDigest
|
self.current.block.Header().MixDigest = work.MixDigest
|
||||||
|
|
||||||
jsonlogger.LogJson(&logger.EthMinerNewBlock{
|
jsonlogger.LogJson(&logger.EthMinerNewBlock{
|
||||||
BlockHash: ethutil.Bytes2Hex(block.Hash()),
|
BlockHash: common.Bytes2Hex(block.Hash()),
|
||||||
BlockNumber: block.Number(),
|
BlockNumber: block.Number(),
|
||||||
ChainHeadHash: ethutil.Bytes2Hex(block.ParentHeaderHash),
|
ChainHeadHash: common.Bytes2Hex(block.ParentHeaderHash),
|
||||||
BlockPrevHash: ethutil.Bytes2Hex(block.ParentHeaderHash),
|
BlockPrevHash: common.Bytes2Hex(block.ParentHeaderHash),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := self.chain.InsertChain(types.Blocks{self.current.block}); err == nil {
|
if err := self.chain.InsertChain(types.Blocks{self.current.block}); err == nil {
|
||||||
@ -221,7 +221,7 @@ gasLimit:
|
|||||||
|
|
||||||
self.current.state.AddBalance(self.coinbase, core.BlockReward)
|
self.current.state.AddBalance(self.coinbase, core.BlockReward)
|
||||||
|
|
||||||
self.current.state.Update(ethutil.Big0)
|
self.current.state.Update(common.Big0)
|
||||||
self.push()
|
self.push()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ type Msg struct {
|
|||||||
|
|
||||||
// NewMsg creates an RLP-encoded message with the given code.
|
// NewMsg creates an RLP-encoded message with the given code.
|
||||||
func NewMsg(code uint64, params ...interface{}) Msg {
|
func NewMsg(code uint64, params ...interface{}) Msg {
|
||||||
p := bytes.NewReader(ethutil.Encode(params))
|
p := bytes.NewReader(common.Encode(params))
|
||||||
return Msg{Code: code, Size: uint32(p.Len()), Payload: p}
|
return Msg{Code: code, Size: uint32(p.Len()), Payload: p}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
"github.com/ethereum/go-ethereum/p2p/nat"
|
"github.com/ethereum/go-ethereum/p2p/nat"
|
||||||
@ -46,7 +46,7 @@ type Server struct {
|
|||||||
MaxPeers int
|
MaxPeers int
|
||||||
|
|
||||||
// Name sets the node name of this server.
|
// Name sets the node name of this server.
|
||||||
// Use ethutil.MakeName to create a name that follows existing conventions.
|
// Use common.MakeName to create a name that follows existing conventions.
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
// Bootstrap nodes are used to establish connectivity
|
// Bootstrap nodes are used to establish connectivity
|
||||||
@ -132,7 +132,7 @@ func (srv *Server) SuggestPeer(n *discover.Node) {
|
|||||||
func (srv *Server) Broadcast(protocol string, code uint64, data ...interface{}) {
|
func (srv *Server) Broadcast(protocol string, code uint64, data ...interface{}) {
|
||||||
var payload []byte
|
var payload []byte
|
||||||
if data != nil {
|
if data != nil {
|
||||||
payload = ethutil.Encode(data)
|
payload = common.Encode(data)
|
||||||
}
|
}
|
||||||
srv.lock.RLock()
|
srv.lock.RLock()
|
||||||
defer srv.lock.RUnlock()
|
defer srv.lock.RUnlock()
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto/sha3"
|
"github.com/ethereum/go-ethereum/crypto/sha3"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ func (dag *Dagger) Search(hash, diff *big.Int) ([]byte, []byte, []byte) {
|
|||||||
|
|
||||||
dag.hash = hash
|
dag.hash = hash
|
||||||
|
|
||||||
obj := ethutil.BigPow(2, 256)
|
obj := common.BigPow(2, 256)
|
||||||
obj = obj.Div(obj, diff)
|
obj = obj.Div(obj, diff)
|
||||||
|
|
||||||
Found = false
|
Found = false
|
||||||
@ -75,7 +75,7 @@ func (dag *Dagger) Search(hash, diff *big.Int) ([]byte, []byte, []byte) {
|
|||||||
func (dag *Dagger) Verify(hash, diff, nonce *big.Int) bool {
|
func (dag *Dagger) Verify(hash, diff, nonce *big.Int) bool {
|
||||||
dag.hash = hash
|
dag.hash = hash
|
||||||
|
|
||||||
obj := ethutil.BigPow(2, 256)
|
obj := common.BigPow(2, 256)
|
||||||
obj = obj.Div(obj, diff)
|
obj = obj.Div(obj, diff)
|
||||||
|
|
||||||
return dag.Eval(nonce).Cmp(obj) < 0
|
return dag.Eval(nonce).Cmp(obj) < 0
|
||||||
@ -85,7 +85,7 @@ func DaggerVerify(hash, diff, nonce *big.Int) bool {
|
|||||||
dagger := &Dagger{}
|
dagger := &Dagger{}
|
||||||
dagger.hash = hash
|
dagger.hash = hash
|
||||||
|
|
||||||
obj := ethutil.BigPow(2, 256)
|
obj := common.BigPow(2, 256)
|
||||||
obj = obj.Div(obj, diff)
|
obj = obj.Div(obj, diff)
|
||||||
|
|
||||||
return dagger.Eval(nonce).Cmp(obj) < 0
|
return dagger.Eval(nonce).Cmp(obj) < 0
|
||||||
@ -133,7 +133,7 @@ func Sum(sha hash.Hash) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (dag *Dagger) Eval(N *big.Int) *big.Int {
|
func (dag *Dagger) Eval(N *big.Int) *big.Int {
|
||||||
pow := ethutil.BigPow(2, 26)
|
pow := common.BigPow(2, 26)
|
||||||
dag.xn = pow.Div(N, pow)
|
dag.xn = pow.Div(N, pow)
|
||||||
|
|
||||||
sha := sha3.NewKeccak256()
|
sha := sha3.NewKeccak256()
|
||||||
|
@ -4,12 +4,12 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkDaggerSearch(b *testing.B) {
|
func BenchmarkDaggerSearch(b *testing.B) {
|
||||||
hash := big.NewInt(0)
|
hash := big.NewInt(0)
|
||||||
diff := ethutil.BigPow(2, 36)
|
diff := common.BigPow(2, 36)
|
||||||
o := big.NewInt(0) // nonce doesn't matter. We're only testing against speed, not validity
|
o := big.NewInt(0) // nonce doesn't matter. We're only testing against speed, not validity
|
||||||
|
|
||||||
// Reset timer so the big generation isn't included in the benchmark
|
// Reset timer so the big generation isn't included in the benchmark
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto/sha3"
|
"github.com/ethereum/go-ethereum/crypto/sha3"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/pow"
|
"github.com/ethereum/go-ethereum/pow"
|
||||||
)
|
)
|
||||||
@ -91,8 +91,8 @@ func verify(hash []byte, diff *big.Int, nonce uint64) bool {
|
|||||||
d := append(hash, n...)
|
d := append(hash, n...)
|
||||||
sha.Write(d)
|
sha.Write(d)
|
||||||
|
|
||||||
verification := new(big.Int).Div(ethutil.BigPow(2, 256), diff)
|
verification := new(big.Int).Div(common.BigPow(2, 256), diff)
|
||||||
res := ethutil.BigD(sha.Sum(nil))
|
res := common.BigD(sha.Sum(nil))
|
||||||
|
|
||||||
return res.Cmp(verification) <= 0
|
return res.Cmp(verification) <= 0
|
||||||
}
|
}
|
||||||
|
22
rpc/api.go
22
rpc/api.go
@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/event/filter"
|
"github.com/ethereum/go-ethereum/event/filter"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
@ -43,7 +43,7 @@ type EthereumApi struct {
|
|||||||
regmut sync.Mutex
|
regmut sync.Mutex
|
||||||
register map[string][]*NewTxArgs
|
register map[string][]*NewTxArgs
|
||||||
|
|
||||||
db ethutil.Database
|
db common.Database
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEthereumApi(eth *xeth.XEth, dataDir string) *EthereumApi {
|
func NewEthereumApi(eth *xeth.XEth, dataDir string) *EthereumApi {
|
||||||
@ -241,7 +241,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error)
|
|||||||
// p.register[args.From] = append(p.register[args.From], args)
|
// p.register[args.From] = append(p.register[args.From], args)
|
||||||
//} else {
|
//} else {
|
||||||
/*
|
/*
|
||||||
account := accounts.Get(ethutil.FromHex(args.From))
|
account := accounts.Get(common.FromHex(args.From))
|
||||||
if account != nil {
|
if account != nil {
|
||||||
if account.Unlocked() {
|
if account.Unlocked() {
|
||||||
if !unlockAccount(account) {
|
if !unlockAccount(account) {
|
||||||
@ -249,7 +249,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result, _ := account.Transact(ethutil.FromHex(args.To), ethutil.FromHex(args.Value), ethutil.FromHex(args.Gas), ethutil.FromHex(args.GasPrice), ethutil.FromHex(args.Data))
|
result, _ := account.Transact(common.FromHex(args.To), common.FromHex(args.Value), common.FromHex(args.Gas), common.FromHex(args.GasPrice), common.FromHex(args.Data))
|
||||||
if len(result) > 0 {
|
if len(result) > 0 {
|
||||||
*reply = toHex(result)
|
*reply = toHex(result)
|
||||||
}
|
}
|
||||||
@ -258,7 +258,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error)
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
// TODO: align default values to have the same type, e.g. not depend on
|
// TODO: align default values to have the same type, e.g. not depend on
|
||||||
// ethutil.Value conversions later on
|
// common.Value conversions later on
|
||||||
if args.Gas.Cmp(big.NewInt(0)) == 0 {
|
if args.Gas.Cmp(big.NewInt(0)) == 0 {
|
||||||
args.Gas = defaultGas
|
args.Gas = defaultGas
|
||||||
}
|
}
|
||||||
@ -316,7 +316,7 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e
|
|||||||
} else {
|
} else {
|
||||||
// Convert the incoming string (which is a bigint) into hex
|
// Convert the incoming string (which is a bigint) into hex
|
||||||
i, _ := new(big.Int).SetString(args.Key, 10)
|
i, _ := new(big.Int).SetString(args.Key, 10)
|
||||||
hx = ethutil.Bytes2Hex(i.Bytes())
|
hx = common.Bytes2Hex(i.Bytes())
|
||||||
}
|
}
|
||||||
rpclogger.Debugf("GetStateAt(%s, %s)\n", args.Address, hx)
|
rpclogger.Debugf("GetStateAt(%s, %s)\n", args.Address, hx)
|
||||||
*reply = map[string]string{args.Key: value.Str()}
|
*reply = map[string]string{args.Key: value.Str()}
|
||||||
@ -480,7 +480,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
|||||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*reply = toHex(crypto.Sha3(ethutil.FromHex(args.Data)))
|
*reply = toHex(crypto.Sha3(common.FromHex(args.Data)))
|
||||||
case "web3_clientVersion":
|
case "web3_clientVersion":
|
||||||
*reply = p.xeth().Backend().Version()
|
*reply = p.xeth().Backend().Version()
|
||||||
case "net_version":
|
case "net_version":
|
||||||
@ -821,12 +821,12 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions {
|
|||||||
|
|
||||||
// Convert optional address slice/string to byte slice
|
// Convert optional address slice/string to byte slice
|
||||||
if str, ok := options.Address.(string); ok {
|
if str, ok := options.Address.(string); ok {
|
||||||
opts.Address = [][]byte{ethutil.FromHex(str)}
|
opts.Address = [][]byte{common.FromHex(str)}
|
||||||
} else if slice, ok := options.Address.([]interface{}); ok {
|
} else if slice, ok := options.Address.([]interface{}); ok {
|
||||||
bslice := make([][]byte, len(slice))
|
bslice := make([][]byte, len(slice))
|
||||||
for i, addr := range slice {
|
for i, addr := range slice {
|
||||||
if saddr, ok := addr.(string); ok {
|
if saddr, ok := addr.(string); ok {
|
||||||
bslice[i] = ethutil.FromHex(saddr)
|
bslice[i] = common.FromHex(saddr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
opts.Address = bslice
|
opts.Address = bslice
|
||||||
@ -840,11 +840,11 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions {
|
|||||||
if slice, ok := topicDat.([]interface{}); ok {
|
if slice, ok := topicDat.([]interface{}); ok {
|
||||||
topics[i] = make([][]byte, len(slice))
|
topics[i] = make([][]byte, len(slice))
|
||||||
for j, topic := range slice {
|
for j, topic := range slice {
|
||||||
topics[i][j] = ethutil.FromHex(topic.(string))
|
topics[i][j] = common.FromHex(topic.(string))
|
||||||
}
|
}
|
||||||
} else if str, ok := topicDat.(string); ok {
|
} else if str, ok := topicDat.(string); ok {
|
||||||
topics[i] = make([][]byte, 1)
|
topics[i] = make([][]byte, 1)
|
||||||
topics[i][0] = ethutil.FromHex(str)
|
topics[i][0] = common.FromHex(str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
opts.Topics = topics
|
opts.Topics = topics
|
||||||
|
42
rpc/args.go
42
rpc/args.go
@ -5,7 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func blockNumber(raw json.RawMessage, number *int64) (err error) {
|
func blockNumber(raw json.RawMessage, number *int64) (err error) {
|
||||||
@ -20,7 +20,7 @@ func blockNumber(raw json.RawMessage, number *int64) (err error) {
|
|||||||
case "pending":
|
case "pending":
|
||||||
*number = 0
|
*number = 0
|
||||||
default:
|
default:
|
||||||
*number = ethutil.String2Big(str).Int64()
|
*number = common.String2Big(str).Int64()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
|
|||||||
if v, ok := obj[0].(float64); ok {
|
if v, ok := obj[0].(float64); ok {
|
||||||
args.BlockNumber = int64(v)
|
args.BlockNumber = int64(v)
|
||||||
} else {
|
} else {
|
||||||
args.BlockNumber = ethutil.Big(obj[0].(string)).Int64()
|
args.BlockNumber = common.Big(obj[0].(string)).Int64()
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(obj) > 1 {
|
if len(obj) > 1 {
|
||||||
@ -102,9 +102,9 @@ func (args *NewTxArgs) UnmarshalJSON(b []byte) (err error) {
|
|||||||
|
|
||||||
args.From = obj.From
|
args.From = obj.From
|
||||||
args.To = obj.To
|
args.To = obj.To
|
||||||
args.Value = ethutil.Big(obj.Value)
|
args.Value = common.Big(obj.Value)
|
||||||
args.Gas = ethutil.Big(obj.Gas)
|
args.Gas = common.Big(obj.Gas)
|
||||||
args.GasPrice = ethutil.Big(obj.GasPrice)
|
args.GasPrice = common.Big(obj.GasPrice)
|
||||||
args.Data = obj.Data
|
args.Data = obj.Data
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -208,7 +208,7 @@ func (args *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) {
|
|||||||
if obj[1].(string) == "latest" {
|
if obj[1].(string) == "latest" {
|
||||||
args.BlockNumber = -1
|
args.BlockNumber = -1
|
||||||
} else {
|
} else {
|
||||||
args.BlockNumber = ethutil.Big(obj[1].(string)).Int64()
|
args.BlockNumber = common.Big(obj[1].(string)).Int64()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,14 +266,14 @@ func (args *BlockNumIndexArgs) UnmarshalJSON(b []byte) (err error) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return NewDecodeParamError("BlockNumber is not string")
|
return NewDecodeParamError("BlockNumber is not string")
|
||||||
}
|
}
|
||||||
args.BlockNumber = ethutil.Big(arg0).Int64()
|
args.BlockNumber = common.Big(arg0).Int64()
|
||||||
|
|
||||||
if len(obj) > 1 {
|
if len(obj) > 1 {
|
||||||
arg1, ok := obj[1].(string)
|
arg1, ok := obj[1].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return NewDecodeParamError("Index not a string")
|
return NewDecodeParamError("Index not a string")
|
||||||
}
|
}
|
||||||
args.Index = ethutil.Big(arg1).Int64()
|
args.Index = common.Big(arg1).Int64()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -306,7 +306,7 @@ func (args *HashIndexArgs) UnmarshalJSON(b []byte) (err error) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return NewDecodeParamError("Index not a string")
|
return NewDecodeParamError("Index not a string")
|
||||||
}
|
}
|
||||||
args.Index = ethutil.Big(arg1).Int64()
|
args.Index = common.Big(arg1).Int64()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -357,10 +357,10 @@ func (args *Sha3Args) UnmarshalJSON(b []byte) (err error) {
|
|||||||
// if len(obj) < 1 {
|
// if len(obj) < 1 {
|
||||||
// return errArguments
|
// return errArguments
|
||||||
// }
|
// }
|
||||||
// args.FromBlock = uint64(ethutil.Big(obj[0].FromBlock).Int64())
|
// args.FromBlock = uint64(common.Big(obj[0].FromBlock).Int64())
|
||||||
// args.ToBlock = uint64(ethutil.Big(obj[0].ToBlock).Int64())
|
// args.ToBlock = uint64(common.Big(obj[0].ToBlock).Int64())
|
||||||
// args.Limit = uint64(ethutil.Big(obj[0].Limit).Int64())
|
// args.Limit = uint64(common.Big(obj[0].Limit).Int64())
|
||||||
// args.Offset = uint64(ethutil.Big(obj[0].Offset).Int64())
|
// args.Offset = uint64(common.Big(obj[0].Offset).Int64())
|
||||||
// args.Address = obj[0].Address
|
// args.Address = obj[0].Address
|
||||||
// args.Topics = obj[0].Topics
|
// args.Topics = obj[0].Topics
|
||||||
|
|
||||||
@ -394,10 +394,10 @@ func (args *FilterOptions) UnmarshalJSON(b []byte) (err error) {
|
|||||||
return NewInsufficientParamsError(len(obj), 1)
|
return NewInsufficientParamsError(len(obj), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
args.Earliest = int64(ethutil.Big(obj[0].FromBlock).Int64())
|
args.Earliest = int64(common.Big(obj[0].FromBlock).Int64())
|
||||||
args.Latest = int64(ethutil.Big(obj[0].ToBlock).Int64())
|
args.Latest = int64(common.Big(obj[0].ToBlock).Int64())
|
||||||
args.Max = int(ethutil.Big(obj[0].Limit).Int64())
|
args.Max = int(common.Big(obj[0].Limit).Int64())
|
||||||
args.Skip = int(ethutil.Big(obj[0].Offset).Int64())
|
args.Skip = int(common.Big(obj[0].Offset).Int64())
|
||||||
args.Address = obj[0].Address
|
args.Address = obj[0].Address
|
||||||
args.Topics = obj[0].Topics
|
args.Topics = obj[0].Topics
|
||||||
|
|
||||||
@ -474,8 +474,8 @@ func (args *WhisperMessageArgs) UnmarshalJSON(b []byte) (err error) {
|
|||||||
args.To = obj[0].To
|
args.To = obj[0].To
|
||||||
args.From = obj[0].From
|
args.From = obj[0].From
|
||||||
args.Topics = obj[0].Topics
|
args.Topics = obj[0].Topics
|
||||||
args.Priority = uint32(ethutil.Big(obj[0].Priority).Int64())
|
args.Priority = uint32(common.Big(obj[0].Priority).Int64())
|
||||||
args.Ttl = uint32(ethutil.Big(obj[0].Ttl).Int64())
|
args.Ttl = uint32(common.Big(obj[0].Ttl).Int64())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -538,7 +538,7 @@ func (args *FilterIdArgs) UnmarshalJSON(b []byte) (err error) {
|
|||||||
return NewInsufficientParamsError(len(obj), 1)
|
return NewInsufficientParamsError(len(obj), 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
args.Id = int(ethutil.Big(obj[0]).Int64())
|
args.Id = int(common.Big(obj[0]).Int64())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
"github.com/ethereum/go-ethereum/xeth"
|
"github.com/ethereum/go-ethereum/xeth"
|
||||||
@ -120,7 +120,7 @@ func (self JsonWrapper) ParseRequestBody(req *http.Request) (RpcRequest, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func toHex(b []byte) string {
|
func toHex(b []byte) string {
|
||||||
hex := ethutil.Bytes2Hex(b)
|
hex := common.Bytes2Hex(b)
|
||||||
// Prefer output of "0x0" instead of "0x"
|
// Prefer output of "0x0" instead of "0x"
|
||||||
if len(hex) == 0 {
|
if len(hex) == 0 {
|
||||||
hex = "0"
|
hex = "0"
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Account struct {
|
type Account struct {
|
||||||
@ -22,7 +22,7 @@ type World struct {
|
|||||||
|
|
||||||
func (self *StateDB) RawDump() World {
|
func (self *StateDB) RawDump() World {
|
||||||
world := World{
|
world := World{
|
||||||
Root: ethutil.Bytes2Hex(self.trie.Root()),
|
Root: common.Bytes2Hex(self.trie.Root()),
|
||||||
Accounts: make(map[string]Account),
|
Accounts: make(map[string]Account),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,14 +30,14 @@ func (self *StateDB) RawDump() World {
|
|||||||
for it.Next() {
|
for it.Next() {
|
||||||
stateObject := NewStateObjectFromBytes(it.Key, it.Value, self.db)
|
stateObject := NewStateObjectFromBytes(it.Key, it.Value, self.db)
|
||||||
|
|
||||||
account := Account{Balance: stateObject.balance.String(), Nonce: stateObject.nonce, Root: ethutil.Bytes2Hex(stateObject.Root()), CodeHash: ethutil.Bytes2Hex(stateObject.codeHash)}
|
account := Account{Balance: stateObject.balance.String(), Nonce: stateObject.nonce, Root: common.Bytes2Hex(stateObject.Root()), CodeHash: common.Bytes2Hex(stateObject.codeHash)}
|
||||||
account.Storage = make(map[string]string)
|
account.Storage = make(map[string]string)
|
||||||
|
|
||||||
storageIt := stateObject.State.trie.Iterator()
|
storageIt := stateObject.State.trie.Iterator()
|
||||||
for storageIt.Next() {
|
for storageIt.Next() {
|
||||||
account.Storage[ethutil.Bytes2Hex(storageIt.Key)] = ethutil.Bytes2Hex(storageIt.Value)
|
account.Storage[common.Bytes2Hex(storageIt.Key)] = common.Bytes2Hex(storageIt.Value)
|
||||||
}
|
}
|
||||||
world.Accounts[ethutil.Bytes2Hex(it.Key)] = account
|
world.Accounts[common.Bytes2Hex(it.Key)] = account
|
||||||
}
|
}
|
||||||
return world
|
return world
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,11 @@ package state
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Log interface {
|
type Log interface {
|
||||||
ethutil.RlpEncodable
|
common.RlpEncodable
|
||||||
|
|
||||||
Address() []byte
|
Address() []byte
|
||||||
Topics() [][]byte
|
Topics() [][]byte
|
||||||
@ -43,7 +43,7 @@ func (self *StateLog) Number() uint64 {
|
|||||||
return self.number
|
return self.number
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLogFromValue(decoder *ethutil.Value) *StateLog {
|
func NewLogFromValue(decoder *common.Value) *StateLog {
|
||||||
log := &StateLog{
|
log := &StateLog{
|
||||||
address: decoder.Get(0).Bytes(),
|
address: decoder.Get(0).Bytes(),
|
||||||
data: decoder.Get(2).Bytes(),
|
data: decoder.Get(2).Bytes(),
|
||||||
@ -58,7 +58,7 @@ func NewLogFromValue(decoder *ethutil.Value) *StateLog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateLog) RlpData() interface{} {
|
func (self *StateLog) RlpData() interface{} {
|
||||||
return []interface{}{self.address, ethutil.ByteSliceToInterface(self.topics), self.data}
|
return []interface{}{self.address, common.ByteSliceToInterface(self.topics), self.data}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateLog) String() string {
|
func (self *StateLog) String() string {
|
||||||
|
@ -3,10 +3,10 @@ package state
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
var addr = ethutil.Address([]byte("test"))
|
var addr = common.Address([]byte("test"))
|
||||||
|
|
||||||
func create() (*ManagedState, *account) {
|
func create() (*ManagedState, *account) {
|
||||||
ms := ManageState(&StateDB{stateObjects: make(map[string]*StateObject)})
|
ms := ManageState(&StateDB{stateObjects: make(map[string]*StateObject)})
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
)
|
)
|
||||||
@ -17,7 +17,7 @@ func (self Code) String() string {
|
|||||||
return string(self) //strings.Join(Disassemble(self), " ")
|
return string(self) //strings.Join(Disassemble(self), " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
type Storage map[string]*ethutil.Value
|
type Storage map[string]*common.Value
|
||||||
|
|
||||||
func (self Storage) String() (str string) {
|
func (self Storage) String() (str string) {
|
||||||
for key, value := range self {
|
for key, value := range self {
|
||||||
@ -39,7 +39,7 @@ func (self Storage) Copy() Storage {
|
|||||||
|
|
||||||
type StateObject struct {
|
type StateObject struct {
|
||||||
// State database for storing state changes
|
// State database for storing state changes
|
||||||
db ethutil.Database
|
db common.Database
|
||||||
// The state object
|
// The state object
|
||||||
State *StateDB
|
State *StateDB
|
||||||
|
|
||||||
@ -77,12 +77,12 @@ func (self *StateObject) Reset() {
|
|||||||
self.State.Reset()
|
self.State.Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStateObject(addr []byte, db ethutil.Database) *StateObject {
|
func NewStateObject(addr []byte, db common.Database) *StateObject {
|
||||||
// This to ensure that it has 20 bytes (and not 0 bytes), thus left or right pad doesn't matter.
|
// This to ensure that it has 20 bytes (and not 0 bytes), thus left or right pad doesn't matter.
|
||||||
address := ethutil.Address(addr)
|
address := common.Address(addr)
|
||||||
|
|
||||||
object := &StateObject{db: db, address: address, balance: new(big.Int), gasPool: new(big.Int), dirty: true}
|
object := &StateObject{db: db, address: address, balance: new(big.Int), gasPool: new(big.Int), dirty: true}
|
||||||
object.State = New(nil, db) //New(trie.New(ethutil.Config.Db, ""))
|
object.State = New(nil, db) //New(trie.New(common.Config.Db, ""))
|
||||||
object.storage = make(Storage)
|
object.storage = make(Storage)
|
||||||
object.gasPool = new(big.Int)
|
object.gasPool = new(big.Int)
|
||||||
object.prepaid = new(big.Int)
|
object.prepaid = new(big.Int)
|
||||||
@ -90,7 +90,7 @@ func NewStateObject(addr []byte, db ethutil.Database) *StateObject {
|
|||||||
return object
|
return object
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStateObjectFromBytes(address, data []byte, db ethutil.Database) *StateObject {
|
func NewStateObjectFromBytes(address, data []byte, db common.Database) *StateObject {
|
||||||
// TODO clean me up
|
// TODO clean me up
|
||||||
var extobject struct {
|
var extobject struct {
|
||||||
Nonce uint64
|
Nonce uint64
|
||||||
@ -110,7 +110,7 @@ func NewStateObjectFromBytes(address, data []byte, db ethutil.Database) *StateOb
|
|||||||
object.balance = extobject.Balance
|
object.balance = extobject.Balance
|
||||||
object.codeHash = extobject.CodeHash
|
object.codeHash = extobject.CodeHash
|
||||||
object.State = New(extobject.Root, db)
|
object.State = New(extobject.Root, db)
|
||||||
object.storage = make(map[string]*ethutil.Value)
|
object.storage = make(map[string]*common.Value)
|
||||||
object.gasPool = new(big.Int)
|
object.gasPool = new(big.Int)
|
||||||
object.prepaid = new(big.Int)
|
object.prepaid = new(big.Int)
|
||||||
object.code, _ = db.Get(extobject.CodeHash)
|
object.code, _ = db.Get(extobject.CodeHash)
|
||||||
@ -124,18 +124,18 @@ func (self *StateObject) MarkForDeletion() {
|
|||||||
statelogger.Debugf("%x: #%d %v X\n", self.Address(), self.nonce, self.balance)
|
statelogger.Debugf("%x: #%d %v X\n", self.Address(), self.nonce, self.balance)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *StateObject) getAddr(addr []byte) *ethutil.Value {
|
func (c *StateObject) getAddr(addr []byte) *common.Value {
|
||||||
return ethutil.NewValueFromBytes([]byte(c.State.trie.Get(addr)))
|
return common.NewValueFromBytes([]byte(c.State.trie.Get(addr)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *StateObject) setAddr(addr []byte, value interface{}) {
|
func (c *StateObject) setAddr(addr []byte, value interface{}) {
|
||||||
c.State.trie.Update(addr, ethutil.Encode(value))
|
c.State.trie.Update(addr, common.Encode(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateObject) GetStorage(key *big.Int) *ethutil.Value {
|
func (self *StateObject) GetStorage(key *big.Int) *common.Value {
|
||||||
return self.GetState(key.Bytes())
|
return self.GetState(key.Bytes())
|
||||||
}
|
}
|
||||||
func (self *StateObject) SetStorage(key *big.Int, value *ethutil.Value) {
|
func (self *StateObject) SetStorage(key *big.Int, value *common.Value) {
|
||||||
self.SetState(key.Bytes(), value)
|
self.SetState(key.Bytes(), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,8 +143,8 @@ func (self *StateObject) Storage() Storage {
|
|||||||
return self.storage
|
return self.storage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateObject) GetState(k []byte) *ethutil.Value {
|
func (self *StateObject) GetState(k []byte) *common.Value {
|
||||||
key := ethutil.LeftPadBytes(k, 32)
|
key := common.LeftPadBytes(k, 32)
|
||||||
|
|
||||||
value := self.storage[string(key)]
|
value := self.storage[string(key)]
|
||||||
if value == nil {
|
if value == nil {
|
||||||
@ -158,8 +158,8 @@ func (self *StateObject) GetState(k []byte) *ethutil.Value {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateObject) SetState(k []byte, value *ethutil.Value) {
|
func (self *StateObject) SetState(k []byte, value *common.Value) {
|
||||||
key := ethutil.LeftPadBytes(k, 32)
|
key := common.LeftPadBytes(k, 32)
|
||||||
self.storage[string(key)] = value.Copy()
|
self.storage[string(key)] = value.Copy()
|
||||||
self.dirty = true
|
self.dirty = true
|
||||||
}
|
}
|
||||||
@ -176,12 +176,12 @@ func (self *StateObject) Sync() {
|
|||||||
self.storage = make(Storage)
|
self.storage = make(Storage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *StateObject) GetInstr(pc *big.Int) *ethutil.Value {
|
func (c *StateObject) GetInstr(pc *big.Int) *common.Value {
|
||||||
if int64(len(c.code)-1) < pc.Int64() {
|
if int64(len(c.code)-1) < pc.Int64() {
|
||||||
return ethutil.NewValue(0)
|
return common.NewValue(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ethutil.NewValueFromBytes([]byte{c.code[pc.Int64()]})
|
return common.NewValueFromBytes([]byte{c.code[pc.Int64()]})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *StateObject) AddBalance(amount *big.Int) {
|
func (c *StateObject) AddBalance(amount *big.Int) {
|
||||||
@ -252,13 +252,13 @@ func (self *StateObject) RefundGas(gas, price *big.Int) {
|
|||||||
func (self *StateObject) Copy() *StateObject {
|
func (self *StateObject) Copy() *StateObject {
|
||||||
stateObject := NewStateObject(self.Address(), self.db)
|
stateObject := NewStateObject(self.Address(), self.db)
|
||||||
stateObject.balance.Set(self.balance)
|
stateObject.balance.Set(self.balance)
|
||||||
stateObject.codeHash = ethutil.CopyBytes(self.codeHash)
|
stateObject.codeHash = common.CopyBytes(self.codeHash)
|
||||||
stateObject.nonce = self.nonce
|
stateObject.nonce = self.nonce
|
||||||
if self.State != nil {
|
if self.State != nil {
|
||||||
stateObject.State = self.State.Copy()
|
stateObject.State = self.State.Copy()
|
||||||
}
|
}
|
||||||
stateObject.code = ethutil.CopyBytes(self.code)
|
stateObject.code = common.CopyBytes(self.code)
|
||||||
stateObject.initCode = ethutil.CopyBytes(self.initCode)
|
stateObject.initCode = common.CopyBytes(self.initCode)
|
||||||
stateObject.storage = self.storage.Copy()
|
stateObject.storage = self.storage.Copy()
|
||||||
stateObject.gasPool.Set(self.gasPool)
|
stateObject.gasPool.Set(self.gasPool)
|
||||||
stateObject.remove = self.remove
|
stateObject.remove = self.remove
|
||||||
@ -330,19 +330,19 @@ func (self *StateObject) Nonce() uint64 {
|
|||||||
|
|
||||||
// State object encoding methods
|
// State object encoding methods
|
||||||
func (c *StateObject) RlpEncode() []byte {
|
func (c *StateObject) RlpEncode() []byte {
|
||||||
return ethutil.Encode([]interface{}{c.nonce, c.balance, c.Root(), c.CodeHash()})
|
return common.Encode([]interface{}{c.nonce, c.balance, c.Root(), c.CodeHash()})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *StateObject) CodeHash() ethutil.Bytes {
|
func (c *StateObject) CodeHash() common.Bytes {
|
||||||
return crypto.Sha3(c.code)
|
return crypto.Sha3(c.code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *StateObject) RlpDecode(data []byte) {
|
func (c *StateObject) RlpDecode(data []byte) {
|
||||||
decoder := ethutil.NewValueFromBytes(data)
|
decoder := common.NewValueFromBytes(data)
|
||||||
c.nonce = decoder.Get(0).Uint()
|
c.nonce = decoder.Get(0).Uint()
|
||||||
c.balance = decoder.Get(1).BigInt()
|
c.balance = decoder.Get(1).BigInt()
|
||||||
c.State = New(decoder.Get(2).Bytes(), c.db) //New(trie.New(ethutil.Config.Db, decoder.Get(2).Interface()))
|
c.State = New(decoder.Get(2).Bytes(), c.db) //New(trie.New(common.Config.Db, decoder.Get(2).Interface()))
|
||||||
c.storage = make(map[string]*ethutil.Value)
|
c.storage = make(map[string]*common.Value)
|
||||||
c.gasPool = new(big.Int)
|
c.gasPool = new(big.Int)
|
||||||
|
|
||||||
c.codeHash = decoder.Get(3).Bytes()
|
c.codeHash = decoder.Get(3).Bytes()
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
checker "gopkg.in/check.v1"
|
checker "gopkg.in/check.v1"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StateSuite struct {
|
type StateSuite struct {
|
||||||
@ -63,9 +63,9 @@ func (s *StateSuite) SetUpTest(c *checker.C) {
|
|||||||
|
|
||||||
func (s *StateSuite) TestSnapshot(c *checker.C) {
|
func (s *StateSuite) TestSnapshot(c *checker.C) {
|
||||||
stateobjaddr := []byte("aa")
|
stateobjaddr := []byte("aa")
|
||||||
storageaddr := ethutil.Big("0")
|
storageaddr := common.Big("0")
|
||||||
data1 := ethutil.NewValue(42)
|
data1 := common.NewValue(42)
|
||||||
data2 := ethutil.NewValue(43)
|
data2 := common.NewValue(43)
|
||||||
|
|
||||||
// get state object
|
// get state object
|
||||||
stateObject := s.state.GetOrNewStateObject(stateobjaddr)
|
stateObject := s.state.GetOrNewStateObject(stateobjaddr)
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
)
|
)
|
||||||
@ -17,7 +17,7 @@ var statelogger = logger.NewLogger("STATE")
|
|||||||
// * Contracts
|
// * Contracts
|
||||||
// * Accounts
|
// * Accounts
|
||||||
type StateDB struct {
|
type StateDB struct {
|
||||||
db ethutil.Database
|
db common.Database
|
||||||
trie *trie.SecureTrie
|
trie *trie.SecureTrie
|
||||||
|
|
||||||
stateObjects map[string]*StateObject
|
stateObjects map[string]*StateObject
|
||||||
@ -28,8 +28,8 @@ type StateDB struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a new state from a given trie
|
// Create a new state from a given trie
|
||||||
func New(root []byte, db ethutil.Database) *StateDB {
|
func New(root []byte, db common.Database) *StateDB {
|
||||||
trie := trie.NewSecure(ethutil.CopyBytes(root), db)
|
trie := trie.NewSecure(common.CopyBytes(root), db)
|
||||||
return &StateDB{db: db, trie: trie, stateObjects: make(map[string]*StateObject), refund: make(map[string]*big.Int)}
|
return &StateDB{db: db, trie: trie, stateObjects: make(map[string]*StateObject), refund: make(map[string]*big.Int)}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int {
|
|||||||
return stateObject.balance
|
return stateObject.balance
|
||||||
}
|
}
|
||||||
|
|
||||||
return ethutil.Big0
|
return common.Big0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateDB) AddBalance(addr []byte, amount *big.Int) {
|
func (self *StateDB) AddBalance(addr []byte, amount *big.Int) {
|
||||||
@ -113,7 +113,7 @@ func (self *StateDB) SetCode(addr, code []byte) {
|
|||||||
func (self *StateDB) SetState(addr, key []byte, value interface{}) {
|
func (self *StateDB) SetState(addr, key []byte, value interface{}) {
|
||||||
stateObject := self.GetStateObject(addr)
|
stateObject := self.GetStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
stateObject.SetState(key, ethutil.NewValue(value))
|
stateObject.SetState(key, common.NewValue(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ func (self *StateDB) DeleteStateObject(stateObject *StateObject) {
|
|||||||
|
|
||||||
// Retrieve a state object given my the address. Nil if not found
|
// Retrieve a state object given my the address. Nil if not found
|
||||||
func (self *StateDB) GetStateObject(addr []byte) *StateObject {
|
func (self *StateDB) GetStateObject(addr []byte) *StateObject {
|
||||||
addr = ethutil.Address(addr)
|
addr = common.Address(addr)
|
||||||
|
|
||||||
stateObject := self.stateObjects[string(addr)]
|
stateObject := self.stateObjects[string(addr)]
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
@ -195,7 +195,7 @@ func (self *StateDB) GetOrNewStateObject(addr []byte) *StateObject {
|
|||||||
|
|
||||||
// Create a state object whether it exist in the trie or not
|
// Create a state object whether it exist in the trie or not
|
||||||
func (self *StateDB) NewStateObject(addr []byte) *StateObject {
|
func (self *StateDB) NewStateObject(addr []byte) *StateObject {
|
||||||
addr = ethutil.Address(addr)
|
addr = common.Address(addr)
|
||||||
|
|
||||||
statelogger.Debugf("(+) %x\n", addr)
|
statelogger.Debugf("(+) %x\n", addr)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
)
|
)
|
||||||
@ -97,7 +97,7 @@ func LoadBlockTests(file string) (map[string]*BlockTest, error) {
|
|||||||
|
|
||||||
// InsertPreState populates the given database with the genesis
|
// InsertPreState populates the given database with the genesis
|
||||||
// accounts defined by the test.
|
// accounts defined by the test.
|
||||||
func (t *BlockTest) InsertPreState(db ethutil.Database) error {
|
func (t *BlockTest) InsertPreState(db common.Database) error {
|
||||||
statedb := state.New(nil, db)
|
statedb := state.New(nil, db)
|
||||||
for addrString, acct := range t.preAccounts {
|
for addrString, acct := range t.preAccounts {
|
||||||
// XXX: is is worth it checking for errors here?
|
// XXX: is is worth it checking for errors here?
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package helper
|
package helper
|
||||||
|
|
||||||
import "github.com/ethereum/go-ethereum/ethutil"
|
import "github.com/ethereum/go-ethereum/common"
|
||||||
|
|
||||||
func FromHex(h string) []byte {
|
func FromHex(h string) []byte {
|
||||||
if ethutil.IsHex(h) {
|
if common.IsHex(h) {
|
||||||
h = h[2:]
|
h = h[2:]
|
||||||
}
|
}
|
||||||
|
|
||||||
return ethutil.Hex2Bytes(h)
|
return common.Hex2Bytes(h)
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,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/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
"github.com/ethereum/go-ethereum/vm"
|
"github.com/ethereum/go-ethereum/vm"
|
||||||
)
|
)
|
||||||
@ -41,13 +41,13 @@ func NewEnv(state *state.StateDB) *Env {
|
|||||||
func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues map[string]string) *Env {
|
func NewEnvFromMap(state *state.StateDB, envValues map[string]string, exeValues map[string]string) *Env {
|
||||||
env := NewEnv(state)
|
env := NewEnv(state)
|
||||||
|
|
||||||
env.origin = ethutil.Hex2Bytes(exeValues["caller"])
|
env.origin = common.Hex2Bytes(exeValues["caller"])
|
||||||
env.parent = ethutil.Hex2Bytes(envValues["previousHash"])
|
env.parent = common.Hex2Bytes(envValues["previousHash"])
|
||||||
env.coinbase = ethutil.Hex2Bytes(envValues["currentCoinbase"])
|
env.coinbase = common.Hex2Bytes(envValues["currentCoinbase"])
|
||||||
env.number = ethutil.Big(envValues["currentNumber"])
|
env.number = common.Big(envValues["currentNumber"])
|
||||||
env.time = ethutil.Big(envValues["currentTimestamp"]).Int64()
|
env.time = common.Big(envValues["currentTimestamp"]).Int64()
|
||||||
env.difficulty = ethutil.Big(envValues["currentDifficulty"])
|
env.difficulty = common.Big(envValues["currentDifficulty"])
|
||||||
env.gasLimit = ethutil.Big(envValues["currentGasLimit"])
|
env.gasLimit = common.Big(envValues["currentGasLimit"])
|
||||||
env.Gas = new(big.Int)
|
env.Gas = new(big.Int)
|
||||||
|
|
||||||
return env
|
return env
|
||||||
@ -135,9 +135,9 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Log
|
|||||||
to = FromHex(exec["address"])
|
to = FromHex(exec["address"])
|
||||||
from = FromHex(exec["caller"])
|
from = FromHex(exec["caller"])
|
||||||
data = FromHex(exec["data"])
|
data = FromHex(exec["data"])
|
||||||
gas = ethutil.Big(exec["gas"])
|
gas = common.Big(exec["gas"])
|
||||||
price = ethutil.Big(exec["gasPrice"])
|
price = common.Big(exec["gasPrice"])
|
||||||
value = ethutil.Big(exec["value"])
|
value = common.Big(exec["value"])
|
||||||
)
|
)
|
||||||
// Reset the pre-compiled contracts for VM tests.
|
// Reset the pre-compiled contracts for VM tests.
|
||||||
vm.Precompiled = make(map[string]*vm.PrecompiledAccount)
|
vm.Precompiled = make(map[string]*vm.PrecompiledAccount)
|
||||||
@ -155,12 +155,12 @@ func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Log
|
|||||||
|
|
||||||
func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state.Logs, *big.Int, error) {
|
func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state.Logs, *big.Int, error) {
|
||||||
var (
|
var (
|
||||||
keyPair, _ = crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(tx["secretKey"])))
|
keyPair, _ = crypto.NewKeyPairFromSec([]byte(common.Hex2Bytes(tx["secretKey"])))
|
||||||
to = FromHex(tx["to"])
|
to = FromHex(tx["to"])
|
||||||
data = FromHex(tx["data"])
|
data = FromHex(tx["data"])
|
||||||
gas = ethutil.Big(tx["gasLimit"])
|
gas = common.Big(tx["gasLimit"])
|
||||||
price = ethutil.Big(tx["gasPrice"])
|
price = common.Big(tx["gasPrice"])
|
||||||
value = ethutil.Big(tx["value"])
|
value = common.Big(tx["value"])
|
||||||
caddr = FromHex(env["currentCoinbase"])
|
caddr = FromHex(env["currentCoinbase"])
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state.
|
|||||||
|
|
||||||
snapshot := statedb.Copy()
|
snapshot := statedb.Copy()
|
||||||
coinbase := statedb.GetOrNewStateObject(caddr)
|
coinbase := statedb.GetOrNewStateObject(caddr)
|
||||||
coinbase.SetGasPool(ethutil.Big(env["currentGasLimit"]))
|
coinbase.SetGasPool(common.Big(env["currentGasLimit"]))
|
||||||
|
|
||||||
message := NewMessage(keyPair.Address(), to, data, value, gas, price)
|
message := NewMessage(keyPair.Address(), to, data, value, gas, price)
|
||||||
vmenv := NewEnvFromMap(statedb, env, tx)
|
vmenv := NewEnvFromMap(statedb, env, tx)
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/ethutil"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/state"
|
"github.com/ethereum/go-ethereum/state"
|
||||||
"github.com/ethereum/go-ethereum/tests/helper"
|
"github.com/ethereum/go-ethereum/tests/helper"
|
||||||
@ -27,26 +27,26 @@ type Log struct {
|
|||||||
BloomF string `json:"bloom"`
|
BloomF string `json:"bloom"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self Log) Address() []byte { return ethutil.Hex2Bytes(self.AddressF) }
|
func (self Log) Address() []byte { return common.Hex2Bytes(self.AddressF) }
|
||||||
func (self Log) Data() []byte { return ethutil.Hex2Bytes(self.DataF) }
|
func (self Log) Data() []byte { return common.Hex2Bytes(self.DataF) }
|
||||||
func (self Log) RlpData() interface{} { return nil }
|
func (self Log) RlpData() interface{} { return nil }
|
||||||
func (self Log) Topics() [][]byte {
|
func (self Log) Topics() [][]byte {
|
||||||
t := make([][]byte, len(self.TopicsF))
|
t := make([][]byte, len(self.TopicsF))
|
||||||
for i, topic := range self.TopicsF {
|
for i, topic := range self.TopicsF {
|
||||||
t[i] = ethutil.Hex2Bytes(topic)
|
t[i] = common.Hex2Bytes(topic)
|
||||||
}
|
}
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func StateObjectFromAccount(db ethutil.Database, addr string, account Account) *state.StateObject {
|
func StateObjectFromAccount(db common.Database, addr string, account Account) *state.StateObject {
|
||||||
obj := state.NewStateObject(ethutil.Hex2Bytes(addr), db)
|
obj := state.NewStateObject(common.Hex2Bytes(addr), db)
|
||||||
obj.SetBalance(ethutil.Big(account.Balance))
|
obj.SetBalance(common.Big(account.Balance))
|
||||||
|
|
||||||
if ethutil.IsHex(account.Code) {
|
if common.IsHex(account.Code) {
|
||||||
account.Code = account.Code[2:]
|
account.Code = account.Code[2:]
|
||||||
}
|
}
|
||||||
obj.SetCode(ethutil.Hex2Bytes(account.Code))
|
obj.SetCode(common.Hex2Bytes(account.Code))
|
||||||
obj.SetNonce(ethutil.Big(account.Nonce).Uint64())
|
obj.SetNonce(common.Big(account.Nonce).Uint64())
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ func RunVmTest(p string, t *testing.T) {
|
|||||||
obj := StateObjectFromAccount(db, addr, account)
|
obj := StateObjectFromAccount(db, addr, account)
|
||||||
statedb.SetStateObject(obj)
|
statedb.SetStateObject(obj)
|
||||||
for a, v := range account.Storage {
|
for a, v := range account.Storage {
|
||||||
obj.SetState(helper.FromHex(a), ethutil.NewValue(helper.FromHex(v)))
|
obj.SetState(helper.FromHex(a), common.NewValue(helper.FromHex(v)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ func RunVmTest(p string, t *testing.T) {
|
|||||||
if len(test.Gas) == 0 && err == nil {
|
if len(test.Gas) == 0 && err == nil {
|
||||||
t.Errorf("%s's gas unspecified, indicating an error. VM returned (incorrectly) successfull", name)
|
t.Errorf("%s's gas unspecified, indicating an error. VM returned (incorrectly) successfull", name)
|
||||||
} else {
|
} else {
|
||||||
gexp := ethutil.Big(test.Gas)
|
gexp := common.Big(test.Gas)
|
||||||
if gexp.Cmp(gas) != 0 {
|
if gexp.Cmp(gas) != 0 {
|
||||||
t.Errorf("%s's gas failed. Expected %v, got %v\n", name, gexp, gas)
|
t.Errorf("%s's gas failed. Expected %v, got %v\n", name, gexp, gas)
|
||||||
}
|
}
|
||||||
@ -140,8 +140,8 @@ func RunVmTest(p string, t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(test.Exec) == 0 {
|
if len(test.Exec) == 0 {
|
||||||
if obj.Balance().Cmp(ethutil.Big(account.Balance)) != 0 {
|
if obj.Balance().Cmp(common.Big(account.Balance)) != 0 {
|
||||||
t.Errorf("%s's : (%x) balance failed. Expected %v, got %v => %v\n", name, obj.Address()[:4], account.Balance, obj.Balance(), new(big.Int).Sub(ethutil.Big(account.Balance), obj.Balance()))
|
t.Errorf("%s's : (%x) balance failed. Expected %v, got %v => %v\n", name, obj.Address()[:4], account.Balance, obj.Balance(), new(big.Int).Sub(common.Big(account.Balance), obj.Balance()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,14 +150,14 @@ func RunVmTest(p string, t *testing.T) {
|
|||||||
vexp := helper.FromHex(value)
|
vexp := helper.FromHex(value)
|
||||||
|
|
||||||
if bytes.Compare(v, vexp) != 0 {
|
if bytes.Compare(v, vexp) != 0 {
|
||||||
t.Errorf("%s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)\n", name, obj.Address()[0:4], addr, vexp, v, ethutil.BigD(vexp), ethutil.BigD(v))
|
t.Errorf("%s's : (%x: %s) storage failed. Expected %x, got %x (%v %v)\n", name, obj.Address()[0:4], addr, vexp, v, common.BigD(vexp), common.BigD(v))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isVmTest {
|
if !isVmTest {
|
||||||
statedb.Sync()
|
statedb.Sync()
|
||||||
if !bytes.Equal(ethutil.Hex2Bytes(test.PostStateRoot), statedb.Root()) {
|
if !bytes.Equal(common.Hex2Bytes(test.PostStateRoot), statedb.Root()) {
|
||||||
t.Errorf("%s's : Post state root error. Expected %s, got %x", name, test.PostStateRoot, statedb.Root())
|
t.Errorf("%s's : Post state root error. Expected %s, got %x", name, test.PostStateRoot, statedb.Root())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,8 +170,8 @@ func RunVmTest(p string, t *testing.T) {
|
|||||||
fmt.Println("A", test.Logs)
|
fmt.Println("A", test.Logs)
|
||||||
fmt.Println("B", logs)
|
fmt.Println("B", logs)
|
||||||
for i, log := range test.Logs {
|
for i, log := range test.Logs {
|
||||||
genBloom := ethutil.LeftPadBytes(types.LogsBloom(state.Logs{logs[i]}).Bytes(), 256)
|
genBloom := common.LeftPadBytes(types.LogsBloom(state.Logs{logs[i]}).Bytes(), 256)
|
||||||
if !bytes.Equal(genBloom, ethutil.Hex2Bytes(log.BloomF)) {
|
if !bytes.Equal(genBloom, common.Hex2Bytes(log.BloomF)) {
|
||||||
t.Errorf("bloom mismatch")
|
t.Errorf("bloom mismatch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package trie
|
package trie
|
||||||
|
|
||||||
import "github.com/ethereum/go-ethereum/ethutil"
|
import "github.com/ethereum/go-ethereum/common"
|
||||||
|
|
||||||
type HashNode struct {
|
type HashNode struct {
|
||||||
key []byte
|
key []byte
|
||||||
@ -22,4 +22,4 @@ func (self *HashNode) Hash() interface{} {
|
|||||||
// These methods will never be called but we have to satisfy Node interface
|
// These methods will never be called but we have to satisfy Node interface
|
||||||
func (self *HashNode) Value() Node { return nil }
|
func (self *HashNode) Value() Node { return nil }
|
||||||
func (self *HashNode) Dirty() bool { return true }
|
func (self *HashNode) Dirty() bool { return true }
|
||||||
func (self *HashNode) Copy(t *Trie) Node { return NewHash(ethutil.CopyBytes(self.key), t) }
|
func (self *HashNode) Copy(t *Trie) Node { return NewHash(common.CopyBytes(self.key), t) }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package trie
|
package trie
|
||||||
|
|
||||||
import "github.com/ethereum/go-ethereum/ethutil"
|
import "github.com/ethereum/go-ethereum/common"
|
||||||
|
|
||||||
type ShortNode struct {
|
type ShortNode struct {
|
||||||
trie *Trie
|
trie *Trie
|
||||||
@ -19,7 +19,7 @@ func (self *ShortNode) Value() Node {
|
|||||||
func (self *ShortNode) Dirty() bool { return true }
|
func (self *ShortNode) Dirty() bool { return true }
|
||||||
func (self *ShortNode) Copy(t *Trie) Node {
|
func (self *ShortNode) Copy(t *Trie) Node {
|
||||||
node := &ShortNode{t, nil, self.value.Copy(t)}
|
node := &ShortNode{t, nil, self.value.Copy(t)}
|
||||||
node.key = ethutil.CopyBytes(self.key)
|
node.key = common.CopyBytes(self.key)
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user