aboutsummaryrefslogtreecommitdiffstats
path: root/xeth
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-03-18 20:39:01 +0800
committerFelix Lange <fjl@twurst.com>2015-03-18 20:39:01 +0800
commitd15f90645d5b2e90c441140972d9fe6ecd753643 (patch)
treeb1f024c3c01f25b67bc25ed0452a9b584dad984f /xeth
parenta59dd393e71cc52b1f96973aef884af619166f38 (diff)
parent0a1eeca41e6ba5920ba65d9b41654768299bc7e3 (diff)
downloadgo-tangerine-d15f90645d5b2e90c441140972d9fe6ecd753643.tar.gz
go-tangerine-d15f90645d5b2e90c441140972d9fe6ecd753643.tar.zst
go-tangerine-d15f90645d5b2e90c441140972d9fe6ecd753643.zip
Merge remote-tracking branch 'ethereum/conversion' into conversion
Diffstat (limited to 'xeth')
-rw-r--r--xeth/state.go6
-rw-r--r--xeth/types.go44
-rw-r--r--xeth/whisper.go6
-rw-r--r--xeth/xeth.go50
4 files changed, 53 insertions, 53 deletions
diff --git a/xeth/state.go b/xeth/state.go
index 7d9ceab1b..f645a9cac 100644
--- a/xeth/state.go
+++ b/xeth/state.go
@@ -19,7 +19,7 @@ func (self *State) State() *state.StateDB {
}
func (self *State) Get(addr string) *Object {
- return &Object{self.state.GetStateObject(common.FromHex(addr))}
+ return &Object{self.state.GetStateObject(common.HexToAddress(addr))}
}
func (self *State) SafeGet(addr string) *Object {
@@ -27,9 +27,9 @@ func (self *State) SafeGet(addr string) *Object {
}
func (self *State) safeGet(addr string) *state.StateObject {
- object := self.state.GetStateObject(common.FromHex(addr))
+ object := self.state.GetStateObject(common.HexToAddress(addr))
if object == nil {
- object = state.NewStateObject(common.FromHex(addr), self.xeth.eth.StateDb())
+ object = state.NewStateObject(common.HexToAddress(addr), self.xeth.eth.StateDb())
}
return object
diff --git a/xeth/types.go b/xeth/types.go
index e15305481..d8d6ff19f 100644
--- a/xeth/types.go
+++ b/xeth/types.go
@@ -5,10 +5,10 @@ import (
"fmt"
"strings"
+ "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/state"
@@ -59,19 +59,19 @@ func (self *Object) Storage() (storage map[string]string) {
type Block struct {
//Transactions string `json:"transactions"`
ref *types.Block
- Size string `json:"size"`
- Number int `json:"number"`
- Hash string `json:"hash"`
+ Size string `json:"size"`
+ Number int `json:"number"`
+ Hash string `json:"hash"`
Transactions *common.List `json:"transactions"`
Uncles *common.List `json:"uncles"`
- Time int64 `json:"time"`
- Coinbase string `json:"coinbase"`
- Name string `json:"name"`
- GasLimit string `json:"gasLimit"`
- GasUsed string `json:"gasUsed"`
- PrevHash string `json:"prevHash"`
- Bloom string `json:"bloom"`
- Raw string `json:"raw"`
+ Time int64 `json:"time"`
+ Coinbase string `json:"coinbase"`
+ Name string `json:"name"`
+ GasLimit string `json:"gasLimit"`
+ GasUsed string `json:"gasUsed"`
+ PrevHash string `json:"prevHash"`
+ Bloom string `json:"bloom"`
+ Raw string `json:"raw"`
}
// Creates a new QML Block from a chain block
@@ -95,12 +95,12 @@ func NewBlock(block *types.Block) *Block {
return &Block{
ref: block, Size: block.Size().String(),
Number: int(block.NumberU64()), GasUsed: block.GasUsed().String(),
- GasLimit: block.GasLimit().String(), Hash: toHex(block.Hash()),
+ GasLimit: block.GasLimit().String(), Hash: toHex(block.Hash().Bytes()),
Transactions: txlist, Uncles: ulist,
Time: block.Time(),
- Coinbase: toHex(block.Coinbase()),
- PrevHash: toHex(block.ParentHash()),
- Bloom: toHex(block.Bloom()),
+ Coinbase: toHex(block.Coinbase().Bytes()),
+ PrevHash: toHex(block.ParentHash().Bytes()),
+ Bloom: toHex(block.Bloom().Bytes()),
Raw: block.String(),
}
}
@@ -114,7 +114,7 @@ func (self *Block) ToString() string {
}
func (self *Block) GetTransaction(hash string) *Transaction {
- tx := self.ref.Transaction(common.FromHex(hash))
+ tx := self.ref.Transaction(common.HexToHash(hash))
if tx == nil {
return nil
}
@@ -139,12 +139,12 @@ type Transaction struct {
}
func NewTx(tx *types.Transaction) *Transaction {
- hash := toHex(tx.Hash())
- receiver := toHex(tx.To())
+ hash := tx.Hash().Hex()
+ receiver := tx.To().Hex()
if len(receiver) == 0 {
- receiver = toHex(core.AddressFromMessage(tx))
+ receiver = core.AddressFromMessage(tx).Hex()
}
- sender := toHex(tx.From())
+ sender, _ := tx.From()
createsContract := core.MessageCreatesContract(tx)
var data string
@@ -154,7 +154,7 @@ func NewTx(tx *types.Transaction) *Transaction {
data = toHex(tx.Data())
}
- return &Transaction{ref: tx, Hash: hash, Value: common.CurrencyToString(tx.Value()), Address: receiver, Contract: createsContract, Gas: tx.Gas().String(), GasPrice: tx.GasPrice().String(), Data: data, Sender: sender, CreatesContract: createsContract, RawData: toHex(tx.Data())}
+ return &Transaction{ref: tx, Hash: hash, Value: common.CurrencyToString(tx.Value()), Address: receiver, Contract: createsContract, Gas: tx.Gas().String(), GasPrice: tx.GasPrice().String(), Data: data, Sender: sender.Hex(), CreatesContract: createsContract, RawData: toHex(tx.Data())}
}
func (self *Transaction) ToString() string {
diff --git a/xeth/whisper.go b/xeth/whisper.go
index 76bf8012a..c0be4c392 100644
--- a/xeth/whisper.go
+++ b/xeth/whisper.go
@@ -4,8 +4,8 @@ import (
"errors"
"time"
- "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/whisper"
)
@@ -63,6 +63,10 @@ func (self *Whisper) HasIdentity(key string) bool {
return self.Whisper.HasIdentity(crypto.ToECDSAPub(common.FromHex(key)))
}
+// func (self *Whisper) RemoveIdentity(key string) bool {
+// return self.Whisper.RemoveIdentity(crypto.ToECDSAPub(common.FromHex(key)))
+// }
+
func (self *Whisper) Watch(opts *Options) int {
filter := whisper.Filter{
To: crypto.ToECDSAPub(common.FromHex(opts.To)),
diff --git a/xeth/xeth.go b/xeth/xeth.go
index 6c7a26c04..672b83332 100644
--- a/xeth/xeth.go
+++ b/xeth/xeth.go
@@ -8,10 +8,10 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/accounts"
+ "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/p2p"
@@ -116,14 +116,14 @@ func (self *XEth) State() *State { return self.state }
func (self *XEth) Whisper() *Whisper { return self.whisper }
func (self *XEth) BlockByHash(strHash string) *Block {
- hash := common.FromHex(strHash)
+ hash := common.HexToHash(strHash)
block := self.chainManager.GetBlock(hash)
return NewBlock(block)
}
func (self *XEth) EthBlockByHash(strHash string) *types.Block {
- hash := common.FromHex(strHash)
+ hash := common.HexToHash(strHash)
block := self.chainManager.GetBlock(hash)
return block
@@ -293,9 +293,9 @@ func (self *XEth) PushTx(encodedTx string) (string, error) {
if tx.To() == nil {
addr := core.AddressFromMessage(tx)
- return toHex(addr), nil
+ return addr.Hex(), nil
}
- return toHex(tx.Hash()), nil
+ return tx.Hash().Hex(), nil
}
var (
@@ -306,8 +306,8 @@ var (
func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) {
statedb := self.State().State() //self.chainManager.TransState()
msg := callmsg{
- from: statedb.GetOrNewStateObject(common.FromHex(fromStr)),
- to: common.FromHex(toStr),
+ from: statedb.GetOrNewStateObject(common.HexToAddress(fromStr)),
+ to: common.HexToAddress(toStr),
gas: common.Big(gasStr),
gasPrice: common.Big(gasPriceStr),
value: common.Big(valueStr),
@@ -330,8 +330,8 @@ func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr st
func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
var (
- from []byte
- to []byte
+ from = common.HexToAddress(fromStr)
+ to = common.HexToAddress(toStr)
value = common.NewValue(valueStr)
gas = common.NewValue(gasStr)
price = common.NewValue(gasPriceStr)
@@ -339,10 +339,8 @@ func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeSt
contractCreation bool
)
- from = common.FromHex(fromStr)
data = common.FromHex(codeStr)
- to = common.FromHex(toStr)
- if len(to) == 0 {
+ if len(toStr) == 0 {
contractCreation = true
}
@@ -368,21 +366,19 @@ func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeSt
if contractCreation {
addr := core.AddressFromMessage(tx)
pipelogger.Infof("Contract addr %x\n", addr)
- }
- if types.IsContractAddr(to) {
- return toHex(core.AddressFromMessage(tx)), nil
+ return core.AddressFromMessage(tx).Hex(), nil
}
- return toHex(tx.Hash()), nil
+ return tx.Hash().Hex(), nil
}
-func (self *XEth) sign(tx *types.Transaction, from []byte, didUnlock bool) error {
- sig, err := self.accountManager.Sign(accounts.Account{Address: from}, tx.Hash())
+func (self *XEth) sign(tx *types.Transaction, from common.Address, didUnlock bool) error {
+ sig, err := self.accountManager.Sign(accounts.Account{Address: from.Bytes()}, tx.Hash().Bytes())
if err == accounts.ErrLocked {
if didUnlock {
return fmt.Errorf("sender account still locked after successful unlock")
}
- if !self.frontend.UnlockAccount(from) {
+ if !self.frontend.UnlockAccount(from.Bytes()) {
return fmt.Errorf("could not unlock sender account")
}
// retry signing, the account should now be unlocked.
@@ -397,17 +393,17 @@ func (self *XEth) sign(tx *types.Transaction, from []byte, didUnlock bool) error
// callmsg is the message type used for call transations.
type callmsg struct {
from *state.StateObject
- to []byte
+ to common.Address
gas, gasPrice *big.Int
value *big.Int
data []byte
}
// accessor boilerplate to implement core.Message
-func (m callmsg) From() []byte { return m.from.Address() }
-func (m callmsg) Nonce() uint64 { return m.from.Nonce() }
-func (m callmsg) To() []byte { return m.to }
-func (m callmsg) GasPrice() *big.Int { return m.gasPrice }
-func (m callmsg) Gas() *big.Int { return m.gas }
-func (m callmsg) Value() *big.Int { return m.value }
-func (m callmsg) Data() []byte { return m.data }
+func (m callmsg) From() (common.Address, error) { return m.from.Address(), nil }
+func (m callmsg) Nonce() uint64 { return m.from.Nonce() }
+func (m callmsg) To() *common.Address { return &m.to }
+func (m callmsg) GasPrice() *big.Int { return m.gasPrice }
+func (m callmsg) Gas() *big.Int { return m.gas }
+func (m callmsg) Value() *big.Int { return m.value }
+func (m callmsg) Data() []byte { return m.data }