Skip to content

Commit 9429806

Browse files
committed
conversions
1 parent cd52ef3 commit 9429806

4 files changed

Lines changed: 30 additions & 27 deletions

File tree

‎core/types/common.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ func (b *Bloom) SetBytes(d []byte) {
3535
func (b Bloom) Big() *big.Int {
3636
return common.Bytes2Big(b[:])
3737
}
38+
39+
func (b Bloom) Bytes() []byte {
40+
return b[:]
41+
}

‎tests/blocktest.go‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"strings"
1414

1515
"github.com/ethereum/go-ethereum/common"
16-
"github.com/ethereum/go-ethereum/core"
1716
"github.com/ethereum/go-ethereum/core/types"
1817
"github.com/ethereum/go-ethereum/rlp"
1918
"github.com/ethereum/go-ethereum/state"
@@ -99,7 +98,7 @@ func LoadBlockTests(file string) (map[string]*BlockTest, error) {
9998
// InsertPreState populates the given database with the genesis
10099
// accounts defined by the test.
101100
func (t *BlockTest) InsertPreState(db common.Database) error {
102-
statedb := state.New(nil, db)
101+
statedb := state.New(common.Hash{}, db)
103102
for addrString, acct := range t.preAccounts {
104103
// XXX: is is worth it checking for errors here?
105104
//addr, _ := hex.DecodeString(addrString)
@@ -120,7 +119,7 @@ func (t *BlockTest) InsertPreState(db common.Database) error {
120119
// sync trie to disk
121120
statedb.Sync()
122121

123-
if !bytes.Equal(t.Genesis.Root().Bytes(), statedb.Root()) {
122+
if t.Genesis.Root() != statedb.Root() {
124123
return errors.New("computed state root does not match genesis block")
125124
}
126125
return nil
@@ -212,12 +211,12 @@ func mustConvertAddress(in string) common.Address {
212211
return common.BytesToAddress(out)
213212
}
214213

215-
func mustConvertBloom(in string) core.Bloom {
214+
func mustConvertBloom(in string) types.Bloom {
216215
out, err := hex.DecodeString(strings.TrimPrefix(in, "0x"))
217216
if err != nil {
218217
panic(fmt.Errorf("invalid hex: %q", in))
219218
}
220-
return core.BytesToBloom(out)
219+
return types.BytesToBloom(out)
221220
}
222221

223222
func mustConvertBigInt10(in string) *big.Int {

‎xeth/state.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ func (self *State) State() *state.StateDB {
1919
}
2020

2121
func (self *State) Get(addr string) *Object {
22-
return &Object{self.state.GetStateObject(common.FromHex(addr))}
22+
return &Object{self.state.GetStateObject(common.HexToAddress(addr))}
2323
}
2424

2525
func (self *State) SafeGet(addr string) *Object {
2626
return &Object{self.safeGet(addr)}
2727
}
2828

2929
func (self *State) safeGet(addr string) *state.StateObject {
30-
object := self.state.GetStateObject(common.FromHex(addr))
30+
object := self.state.GetStateObject(common.HexToAddress(addr))
3131
if object == nil {
32-
object = state.NewStateObject(common.FromHex(addr), self.xeth.eth.StateDb())
32+
object = state.NewStateObject(common.HexToAddress(addr), self.xeth.eth.StateDb())
3333
}
3434

3535
return object

‎xeth/types.go‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"fmt"
66
"strings"
77

8+
"github.com/ethereum/go-ethereum/common"
89
"github.com/ethereum/go-ethereum/core"
910
"github.com/ethereum/go-ethereum/core/types"
1011
"github.com/ethereum/go-ethereum/crypto"
11-
"github.com/ethereum/go-ethereum/common"
1212
"github.com/ethereum/go-ethereum/p2p"
1313
"github.com/ethereum/go-ethereum/rlp"
1414
"github.com/ethereum/go-ethereum/state"
@@ -59,19 +59,19 @@ func (self *Object) Storage() (storage map[string]string) {
5959
type Block struct {
6060
//Transactions string `json:"transactions"`
6161
ref *types.Block
62-
Size string `json:"size"`
63-
Number int `json:"number"`
64-
Hash string `json:"hash"`
62+
Size string `json:"size"`
63+
Number int `json:"number"`
64+
Hash string `json:"hash"`
6565
Transactions *common.List `json:"transactions"`
6666
Uncles *common.List `json:"uncles"`
67-
Time int64 `json:"time"`
68-
Coinbase string `json:"coinbase"`
69-
Name string `json:"name"`
70-
GasLimit string `json:"gasLimit"`
71-
GasUsed string `json:"gasUsed"`
72-
PrevHash string `json:"prevHash"`
73-
Bloom string `json:"bloom"`
74-
Raw string `json:"raw"`
67+
Time int64 `json:"time"`
68+
Coinbase string `json:"coinbase"`
69+
Name string `json:"name"`
70+
GasLimit string `json:"gasLimit"`
71+
GasUsed string `json:"gasUsed"`
72+
PrevHash string `json:"prevHash"`
73+
Bloom string `json:"bloom"`
74+
Raw string `json:"raw"`
7575
}
7676

7777
// Creates a new QML Block from a chain block
@@ -95,12 +95,12 @@ func NewBlock(block *types.Block) *Block {
9595
return &Block{
9696
ref: block, Size: block.Size().String(),
9797
Number: int(block.NumberU64()), GasUsed: block.GasUsed().String(),
98-
GasLimit: block.GasLimit().String(), Hash: toHex(block.Hash()),
98+
GasLimit: block.GasLimit().String(), Hash: toHex(block.Hash().Bytes()),
9999
Transactions: txlist, Uncles: ulist,
100100
Time: block.Time(),
101-
Coinbase: toHex(block.Coinbase()),
102-
PrevHash: toHex(block.ParentHash()),
103-
Bloom: toHex(block.Bloom()),
101+
Coinbase: toHex(block.Coinbase().Bytes()),
102+
PrevHash: toHex(block.ParentHash().Bytes()),
103+
Bloom: toHex(block.Bloom().Bytes()),
104104
Raw: block.String(),
105105
}
106106
}
@@ -114,7 +114,7 @@ func (self *Block) ToString() string {
114114
}
115115

116116
func (self *Block) GetTransaction(hash string) *Transaction {
117-
tx := self.ref.Transaction(common.FromHex(hash))
117+
tx := self.ref.Transaction(common.HexToHash(hash))
118118
if tx == nil {
119119
return nil
120120
}
@@ -139,8 +139,8 @@ type Transaction struct {
139139
}
140140

141141
func NewTx(tx *types.Transaction) *Transaction {
142-
hash := toHex(tx.Hash())
143-
receiver := toHex(tx.To())
142+
hash := tx.Hash().Hex()
143+
receiver := tx.To().Hex()
144144
if len(receiver) == 0 {
145145
receiver = toHex(core.AddressFromMessage(tx))
146146
}

0 commit comments

Comments
 (0)