This commit is contained in:
obscuren
2015-03-18 18:23:37 +01:00
10 changed files with 92 additions and 78 deletions

View File

@ -14,10 +14,6 @@ import (
"github.com/ethereum/go-ethereum/state"
)
func toHex(b []byte) string {
return "0x" + common.Bytes2Hex(b)
}
type Object struct {
*state.StateObject
}
@ -49,7 +45,7 @@ func (self *Object) Storage() (storage map[string]string) {
for it.Next() {
var data []byte
rlp.Decode(bytes.NewReader(it.Value), &data)
storage[toHex(it.Key)] = toHex(data)
storage[common.ToHex(it.Key)] = common.ToHex(data)
}
return
@ -95,12 +91,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().Bytes()),
GasLimit: block.GasLimit().String(), Hash: block.Hash().Hex(),
Transactions: txlist, Uncles: ulist,
Time: block.Time(),
Coinbase: toHex(block.Coinbase().Bytes()),
PrevHash: toHex(block.ParentHash().Bytes()),
Bloom: toHex(block.Bloom().Bytes()),
Coinbase: block.Coinbase().Hex(),
PrevHash: block.ParentHash().Hex(),
Bloom: common.ToHex(block.Bloom().Bytes()),
Raw: block.String(),
}
}
@ -151,10 +147,10 @@ func NewTx(tx *types.Transaction) *Transaction {
if createsContract {
data = strings.Join(core.Disassemble(tx.Data()), "\n")
} else {
data = toHex(tx.Data())
data = common.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())}
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: common.ToHex(tx.Data())}
}
func (self *Transaction) ToString() string {
@ -168,7 +164,7 @@ type Key struct {
}
func NewKey(key *crypto.KeyPair) *Key {
return &Key{toHex(key.Address()), toHex(key.PrivateKey), toHex(key.PublicKey)}
return &Key{common.ToHex(key.Address()), common.ToHex(key.PrivateKey), common.ToHex(key.PublicKey)}
}
type PReceipt struct {
@ -181,9 +177,9 @@ type PReceipt struct {
func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) *PReceipt {
return &PReceipt{
contractCreation,
toHex(creationAddress),
toHex(hash),
toHex(address),
common.ToHex(creationAddress),
common.ToHex(hash),
common.ToHex(address),
}
}
@ -220,8 +216,8 @@ type Receipt struct {
func NewReciept(contractCreation bool, creationAddress, hash, address []byte) *Receipt {
return &Receipt{
contractCreation,
toHex(creationAddress),
toHex(hash),
toHex(address),
common.ToHex(creationAddress),
common.ToHex(hash),
common.ToHex(address),
}
}

View File

@ -56,7 +56,7 @@ func (self *Whisper) Post(payload string, to, from string, topics []string, prio
func (self *Whisper) NewIdentity() string {
key := self.Whisper.NewIdentity()
return toHex(crypto.FromECDSAPub(&key.PublicKey))
return common.ToHex(crypto.FromECDSAPub(&key.PublicKey))
}
func (self *Whisper) HasIdentity(key string) bool {
@ -112,9 +112,9 @@ type WhisperMessage struct {
func NewWhisperMessage(msg *whisper.Message) WhisperMessage {
return WhisperMessage{
ref: msg,
Payload: toHex(msg.Payload),
From: toHex(crypto.FromECDSAPub(msg.Recover())),
To: toHex(crypto.FromECDSAPub(msg.To)),
Payload: common.ToHex(msg.Payload),
From: common.ToHex(crypto.FromECDSAPub(msg.Recover())),
To: common.ToHex(crypto.FromECDSAPub(msg.To)),
Sent: msg.Sent,
}
}

View File

@ -170,7 +170,7 @@ func (self *XEth) Accounts() []string {
accounts, _ := self.eth.AccountManager().Accounts()
accountAddresses := make([]string, len(accounts))
for i, ac := range accounts {
accountAddresses[i] = toHex(ac.Address)
accountAddresses[i] = common.ToHex(ac.Address)
}
return accountAddresses
}
@ -201,7 +201,7 @@ func (self *XEth) IsListening() bool {
func (self *XEth) Coinbase() string {
cb, _ := self.eth.AccountManager().Coinbase()
return toHex(cb)
return common.ToHex(cb)
}
func (self *XEth) NumberToHuman(balance string) string {
@ -213,7 +213,7 @@ func (self *XEth) NumberToHuman(balance string) string {
func (self *XEth) StorageAt(addr, storageAddr string) string {
storage := self.State().SafeGet(addr).StorageString(storageAddr)
return toHex(storage.Bytes())
return common.ToHex(storage.Bytes())
}
func (self *XEth) BalanceAt(addr string) string {
@ -225,7 +225,7 @@ func (self *XEth) TxCountAt(address string) int {
}
func (self *XEth) CodeAt(address string) string {
return toHex(self.State().SafeGet(address).Code())
return common.ToHex(self.State().SafeGet(address).Code())
}
func (self *XEth) IsContract(address string) bool {
@ -238,7 +238,7 @@ func (self *XEth) SecretToAddress(key string) string {
return ""
}
return toHex(pair.Address())
return common.ToHex(pair.Address())
}
type KeyVal struct {
@ -251,7 +251,7 @@ func (self *XEth) EachStorage(addr string) string {
object := self.State().SafeGet(addr)
it := object.Trie().Iterator()
for it.Next() {
values = append(values, KeyVal{toHex(it.Key), toHex(it.Value)})
values = append(values, KeyVal{common.ToHex(it.Key), common.ToHex(it.Value)})
}
valuesJson, err := json.Marshal(values)
@ -265,7 +265,7 @@ func (self *XEth) EachStorage(addr string) string {
func (self *XEth) ToAscii(str string) string {
padded := common.RightPadBytes([]byte(str), 32)
return "0x" + toHex(padded)
return "0x" + common.ToHex(padded)
}
func (self *XEth) FromAscii(str string) string {
@ -325,7 +325,7 @@ func (self *XEth) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr st
vmenv := core.NewEnv(statedb, self.chainManager, msg, block)
res, err := vmenv.Call(msg.from, msg.to, msg.data, msg.gas, msg.gasPrice, msg.value)
return toHex(res), err
return common.ToHex(res), err
}
func (self *XEth) Transact(fromStr, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {