Skip to content

Commit

Permalink
Moved ethutil => common
Browse files Browse the repository at this point in the history
  • Loading branch information
obscuren committed Mar 16, 2015
1 parent 0b8f66e commit b523441
Show file tree
Hide file tree
Showing 116 changed files with 610 additions and 604 deletions.
6 changes: 3 additions & 3 deletions Godeps/_workspace/src/github.com/ethereum/ethash/ethash.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions accounts/abi/numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math/big"
"reflect"

"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/common"
)

var big_t = reflect.TypeOf(&big.Int{})
Expand Down Expand Up @@ -38,13 +38,13 @@ var big_ts = reflect.TypeOf([]*big.Int(nil))

// U256 will ensure unsigned 256bit on big nums
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 {
sint := ethutil.S256(n)
ret := ethutil.LeftPadBytes(sint.Bytes(), 32)
if sint.Cmp(ethutil.Big0) < 0 {
sint := common.S256(n)
ret := common.LeftPadBytes(sint.Bytes(), 32)
if sint.Cmp(common.Big0) < 0 {
for i, b := range ret {
if b == 0 {
ret[i] = 1
Expand Down
10 changes: 5 additions & 5 deletions accounts/abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"strconv"

"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/common"
)

const (
Expand Down Expand Up @@ -157,15 +157,15 @@ func (t Type) pack(v interface{}) ([]byte, error) {
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 []byte(ethutil.LeftPadString(t.String(), 32)), nil
return []byte(common.LeftPadString(t.String(), 32)), nil
case reflect.Slice:
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)
}

// Address is a special slice. The slice acts as one rather than a list of elements.
if t.T == AddressTy {
return ethutil.LeftPadBytes(v.([]byte), 32), nil
return common.LeftPadBytes(v.([]byte), 32), nil
}

// Signed / Unsigned check
Expand All @@ -180,9 +180,9 @@ func (t Type) pack(v interface{}) ([]byte, error) {
return packed, nil
case reflect.Bool:
if value.Bool() {
return ethutil.LeftPadBytes(ethutil.Big1.Bytes(), 32), nil
return common.LeftPadBytes(common.Big1.Bytes(), 32), nil
} else {
return ethutil.LeftPadBytes(ethutil.Big0.Bytes(), 32), nil
return common.LeftPadBytes(common.Big0.Bytes(), 32), nil
}
}

Expand Down
8 changes: 4 additions & 4 deletions blockpool/blockpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/ethereum/go-ethereum/blockpool/test"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/common"
)

func TestPeerWithKnownBlock(t *testing.T) {
Expand Down Expand Up @@ -69,9 +69,9 @@ func TestPeerPromotionByOptionalTdOnBlock(t *testing.T) {
hashes := blockPoolTester.hashPool.IndexesToHashes([]int{2, 3})
peer1.waitBlocksRequests(3)
blockPool.AddBlock(&types.Block{
HeaderHash: ethutil.Bytes(hashes[1]),
ParentHeaderHash: ethutil.Bytes(hashes[0]),
Td: ethutil.Big3,
HeaderHash: common.Bytes(hashes[1]),
ParentHeaderHash: common.Bytes(hashes[0]),
Td: common.Big3,
}, "peer1")

blockPool.RemovePeer("peer2")
Expand Down
4 changes: 2 additions & 2 deletions blockpool/blockpool_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/ethereum/go-ethereum/blockpool/test"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/errs"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/pow"
)

Expand Down Expand Up @@ -315,7 +315,7 @@ func (self *peerTester) sendBlocks(indexes ...int) {
hashes := self.hashPool.IndexesToHashes(indexes)
for i := 1; i < len(hashes); i++ {
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)
}
}

Expand Down
6 changes: 3 additions & 3 deletions blockpool/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/errs"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/common"
)

type peer struct {
Expand Down Expand Up @@ -230,7 +230,7 @@ func (self *peers) addPeer(
}
best = true
} else {
currentTD := ethutil.Big0
currentTD := common.Big0
if self.best != nil {
currentTD = self.best.td
}
Expand Down Expand Up @@ -264,7 +264,7 @@ func (self *peers) removePeer(id string) {
if self.best == p {
var newp *peer
// FIXME: own TD
max := ethutil.Big0
max := common.Big0
// peer with the highest self-acclaimed TD is chosen
for _, pp := range self.peers {
if pp.td.Cmp(max) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/disasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"io/ioutil"
"os"

"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/vm"
)

Expand All @@ -15,7 +15,7 @@ func main() {
fmt.Println(err)
os.Exit(1)
}
code = ethutil.Hex2Bytes(string(code[:len(code)-1]))
code = common.Hex2Bytes(string(code[:len(code)-1]))
fmt.Printf("%x\n", code)

for pc := uint64(0); pc < uint64(len(code)); pc++ {
Expand Down
4 changes: 2 additions & 2 deletions cmd/ethereum/blocktest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/tests"
)

Expand Down Expand Up @@ -41,7 +41,7 @@ func runblocktest(ctx *cli.Context) {
}

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)
if err != nil {
utils.Fatalf("%v", err)
Expand Down
6 changes: 3 additions & 3 deletions cmd/ethereum/js.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/javascript"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/xeth"
Expand Down Expand Up @@ -226,7 +226,7 @@ func (self *jsre) dump(call otto.FunctionCall) otto.Value {
block = self.ethereum.ChainManager().GetBlockByNumber(uint64(num))
} else if call.Argument(0).IsString() {
hash, _ := call.Argument(0).ToString()
block = self.ethereum.ChainManager().GetBlock(ethutil.Hex2Bytes(hash))
block = self.ethereum.ChainManager().GetBlock(common.Hex2Bytes(hash))
} else {
fmt.Println("invalid argument for dump. Either hex string or number")
}
Expand Down Expand Up @@ -285,7 +285,7 @@ func (self *jsre) export(call otto.FunctionCall) otto.Value {

data := self.ethereum.ChainManager().Export()

if err := ethutil.WriteFile(fn, data); err != nil {
if err := common.WriteFile(fn, data); err != nil {
fmt.Println(err)
return otto.FalseValue()
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/ethereum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/core/types"
"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/state"
"github.com/peterh/liner"
Expand Down Expand Up @@ -200,7 +200,7 @@ func startEth(ctx *cli.Context, eth *eth.Ethereum) {
}
am := eth.AccountManager()
// 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 {
utils.Fatalf("Unlock account failed '%v'", err)
}
Expand Down Expand Up @@ -284,7 +284,7 @@ func dump(ctx *cli.Context) {
for _, arg := range ctx.Args() {
var block *types.Block
if hashish(arg) {
block = chainmgr.GetBlock(ethutil.Hex2Bytes(arg))
block = chainmgr.GetBlock(common.Hex2Bytes(arg))
} else {
num, _ := strconv.Atoi(arg)
block = chainmgr.GetBlockByNumber(uint64(num))
Expand Down
32 changes: 16 additions & 16 deletions cmd/ethtest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"strings"

"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/state"
"github.com/ethereum/go-ethereum/tests/helper"
Expand All @@ -48,13 +48,13 @@ type Log struct {
BloomF string `json:"bloom"`
}

func (self Log) Address() []byte { return ethutil.Hex2Bytes(self.AddressF) }
func (self Log) Data() []byte { return ethutil.Hex2Bytes(self.DataF) }
func (self Log) Address() []byte { return common.Hex2Bytes(self.AddressF) }
func (self Log) Data() []byte { return common.Hex2Bytes(self.DataF) }
func (self Log) RlpData() interface{} { return nil }
func (self Log) Topics() [][]byte {
t := make([][]byte, len(self.TopicsF))
for i, topic := range self.TopicsF {
t[i] = ethutil.Hex2Bytes(topic)
t[i] = common.Hex2Bytes(topic)
}
return t
}
Expand All @@ -66,15 +66,15 @@ type Account struct {
Storage map[string]string
}

func StateObjectFromAccount(db ethutil.Database, addr string, account Account) *state.StateObject {
obj := state.NewStateObject(ethutil.Hex2Bytes(addr), db)
obj.SetBalance(ethutil.Big(account.Balance))
func StateObjectFromAccount(db common.Database, addr string, account Account) *state.StateObject {
obj := state.NewStateObject(common.Hex2Bytes(addr), db)
obj.SetBalance(common.Big(account.Balance))

if ethutil.IsHex(account.Code) {
if common.IsHex(account.Code) {
account.Code = account.Code[2:]
}
obj.SetCode(ethutil.Hex2Bytes(account.Code))
obj.SetNonce(ethutil.Big(account.Nonce).Uint64())
obj.SetCode(common.Hex2Bytes(account.Code))
obj.SetNonce(common.Big(account.Nonce).Uint64())

return obj
}
Expand Down Expand Up @@ -147,8 +147,8 @@ func RunVmTest(r io.Reader) (failed int) {
}

if len(test.Exec) == 0 {
if obj.Balance().Cmp(ethutil.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()))
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(common.Big(account.Balance), obj.Balance()))
failed = 1
}
}
Expand All @@ -158,13 +158,13 @@ func RunVmTest(r io.Reader) (failed int) {
vexp := helper.FromHex(value)

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
}
}
}

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())
failed = 1
}
Expand All @@ -178,8 +178,8 @@ func RunVmTest(r io.Reader) (failed int) {
fmt.Println("A", test.Logs)
fmt.Println("B", logs)
for i, log := range test.Logs {
genBloom := ethutil.LeftPadBytes(types.LogsBloom(state.Logs{logs[i]}).Bytes(), 256)
if !bytes.Equal(genBloom, ethutil.Hex2Bytes(log.BloomF)) {
genBloom := common.LeftPadBytes(types.LogsBloom(state.Logs{logs[i]}).Bytes(), 256)
if !bytes.Equal(genBloom, common.Hex2Bytes(log.BloomF)) {
t.Errorf("bloom mismatch")
}
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/evm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"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/state"
"github.com/ethereum/go-ethereum/vm"
Expand Down Expand Up @@ -63,13 +63,13 @@ func main() {
statedb := state.New(nil, db)
sender := statedb.NewStateObject([]byte("sender"))
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()

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()
if e != nil {
Expand Down Expand Up @@ -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) 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) Coinbase() []byte { return self.transactor }
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) Value() *big.Int { return self.value }
func (self *VMEnv) GasLimit() *big.Int { return big.NewInt(1000000000) }
Expand Down
Loading

0 comments on commit b523441

Please sign in to comment.