Implemented filter for ws + fixes

* proper 0xhex
* filters fixed
* start of filter manager
* accounts for ws. Closes #246
pull/254/head
obscuren 10 years ago
parent 491c23a728
commit e3da85faed
  1. 2
      cmd/mist/assets/qml/browser.qml
  2. 1
      cmd/mist/ui_lib.go
  3. 54
      cmd/utils/websockets.go
  4. 2
      event/filter/old_filter.go
  5. 20
      ui/filter.go
  6. 5
      ui/qt/filter.go
  7. 8
      websocket/client.go
  8. 9
      websocket/message.go
  9. 73
      xeth/hexface.go
  10. 63
      xeth/js_types.go

@ -66,7 +66,7 @@ Rectangle {
onMessages: { onMessages: {
// Bit of a cheat to get proper JSON // Bit of a cheat to get proper JSON
var m = JSON.parse(JSON.parse(JSON.stringify(messages))) var m = JSON.parse(JSON.parse(JSON.stringify(messages)))
webview.postEvent("messages", id, m); webview.postEvent("eth_changed", id, m);
} }
function onShhMessage(message, id) { function onShhMessage(message, id) {

@ -70,6 +70,7 @@ func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib {
lib := &UiLib{JSXEth: xeth.NewJSXEth(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)} lib := &UiLib{JSXEth: xeth.NewJSXEth(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)}
lib.miner = miner.New(eth.KeyManager().Address(), eth) lib.miner = miner.New(eth.KeyManager().Address(), eth)
lib.filterManager = filter.NewFilterManager(eth.EventMux()) lib.filterManager = filter.NewFilterManager(eth.EventMux())
go lib.filterManager.Start()
return lib return lib
} }

@ -21,9 +21,14 @@
package utils package utils
import ( import (
"github.com/ethereum/go-ethereum/core"
"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/ethutil"
"github.com/ethereum/go-ethereum/event/filter"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/ui/qt"
"github.com/ethereum/go-ethereum/websocket" "github.com/ethereum/go-ethereum/websocket"
"github.com/ethereum/go-ethereum/xeth" "github.com/ethereum/go-ethereum/xeth"
) )
@ -35,16 +40,19 @@ func args(v ...interface{}) []interface{} {
} }
type WebSocketServer struct { type WebSocketServer struct {
ethereum *eth.Ethereum eth *eth.Ethereum
filterCallbacks map[int][]int filterManager *filter.FilterManager
} }
func NewWebSocketServer(eth *eth.Ethereum) *WebSocketServer { func NewWebSocketServer(eth *eth.Ethereum) *WebSocketServer {
return &WebSocketServer{eth, make(map[int][]int)} filterManager := filter.NewFilterManager(eth.EventMux())
go filterManager.Start()
return &WebSocketServer{eth, filterManager}
} }
func (self *WebSocketServer) Serv() { func (self *WebSocketServer) Serv() {
pipe := xeth.NewJSXEth(self.ethereum) pipe := xeth.NewJSXEth(self.eth)
wsServ := websocket.NewServer("/eth", ":40404") wsServ := websocket.NewServer("/eth", ":40404")
wsServ.MessageFunc(func(c *websocket.Client, msg *websocket.Message) { wsServ.MessageFunc(func(c *websocket.Client, msg *websocket.Message) {
@ -112,15 +120,32 @@ func (self *WebSocketServer) Serv() {
c.Write(pipe.BalanceAt(args.Get(0).Str()), msg.Id) c.Write(pipe.BalanceAt(args.Get(0).Str()), msg.Id)
case "eth_secretToAddress": case "eth_accounts":
args := msg.Arguments() c.Write(pipe.Accounts(), msg.Id)
c.Write(pipe.SecretToAddress(args.Get(0).Str()), msg.Id)
case "eth_newFilter": case "eth_newFilter":
if mp, ok := msg.Args[0].(map[string]interface{}); ok {
var id int
filter := qt.NewFilterFromMap(mp, self.eth)
filter.MessageCallback = func(messages state.Messages) {
c.Event(toMessages(messages), "eth_changed", id)
}
id = self.filterManager.InstallFilter(filter)
c.Write(id, msg.Id)
}
case "eth_newFilterString": case "eth_newFilterString":
case "eth_messages": var id int
// TODO filter := core.NewFilter(self.eth)
filter.BlockCallback = func(block *types.Block) {
c.Event(nil, "eth_changed", id)
}
id = self.filterManager.InstallFilter(filter)
c.Write(id, msg.Id)
case "eth_filterLogs":
filter := self.filterManager.GetFilter(int(msg.Arguments().Get(0).Uint()))
if filter != nil {
c.Write(toMessages(filter.Find()), msg.Id)
}
} }
}) })
@ -128,6 +153,15 @@ func (self *WebSocketServer) Serv() {
wsServ.Listen() wsServ.Listen()
} }
func toMessages(messages state.Messages) (msgs []xeth.JSMessage) {
msgs = make([]xeth.JSMessage, len(messages))
for i, msg := range messages {
msgs[i] = xeth.NewJSMessage(msg)
}
return
}
func StartWebSockets(eth *eth.Ethereum) { func StartWebSockets(eth *eth.Ethereum) {
wslogger.Infoln("Starting WebSockets") wslogger.Infoln("Starting WebSockets")

@ -2,6 +2,7 @@
package filter package filter
import ( import (
"fmt"
"sync" "sync"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
@ -78,6 +79,7 @@ out:
self.filterMu.RUnlock() self.filterMu.RUnlock()
case state.Messages: case state.Messages:
fmt.Println("got messages")
self.filterMu.RLock() self.filterMu.RLock()
for _, filter := range self.filters { for _, filter := range self.filters {
if filter.MessageCallback != nil { if filter.MessageCallback != nil {

@ -5,6 +5,16 @@ import (
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
) )
func fromHex(s string) []byte {
if len(s) > 1 {
if s[0:2] == "0x" {
s = s[2:]
}
return ethutil.Hex2Bytes(s)
}
return nil
}
func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core.Filter { func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core.Filter {
filter := core.NewFilter(eth) filter := core.NewFilter(eth)
@ -20,12 +30,12 @@ func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core.
if object["to"] != nil { if object["to"] != nil {
val := ethutil.NewValue(object["to"]) val := ethutil.NewValue(object["to"])
filter.AddTo(ethutil.Hex2Bytes(val.Str())) filter.AddTo(fromHex(val.Str()))
} }
if object["from"] != nil { if object["from"] != nil {
val := ethutil.NewValue(object["from"]) val := ethutil.NewValue(object["from"])
filter.AddFrom(ethutil.Hex2Bytes(val.Str())) filter.AddFrom(fromHex(val.Str()))
} }
if object["max"] != nil { if object["max"] != nil {
@ -48,11 +58,11 @@ func NewFilterFromMap(object map[string]interface{}, eth core.EthManager) *core.
// Conversion methodn // Conversion methodn
func mapToAccountChange(m map[string]interface{}) (d core.AccountChange) { func mapToAccountChange(m map[string]interface{}) (d core.AccountChange) {
if str, ok := m["id"].(string); ok { if str, ok := m["id"].(string); ok {
d.Address = ethutil.Hex2Bytes(str) d.Address = fromHex(str)
} }
if str, ok := m["at"].(string); ok { if str, ok := m["at"].(string); ok {
d.StateAddress = ethutil.Hex2Bytes(str) d.StateAddress = fromHex(str)
} }
return return
@ -62,7 +72,7 @@ func mapToAccountChange(m map[string]interface{}) (d core.AccountChange) {
// ["aabbccdd", {id: "ccddee", at: "11223344"}], "aabbcc", {id: "ccddee", at: "1122"} // ["aabbccdd", {id: "ccddee", at: "11223344"}], "aabbcc", {id: "ccddee", at: "1122"}
func makeAltered(v interface{}) (d []core.AccountChange) { func makeAltered(v interface{}) (d []core.AccountChange) {
if str, ok := v.(string); ok { if str, ok := v.(string); ok {
d = append(d, core.AccountChange{ethutil.Hex2Bytes(str), nil}) d = append(d, core.AccountChange{fromHex(str), nil})
} else if obj, ok := v.(map[string]interface{}); ok { } else if obj, ok := v.(map[string]interface{}); ok {
d = append(d, mapToAccountChange(obj)) d = append(d, mapToAccountChange(obj))
} else if slice, ok := v.([]interface{}); ok { } else if slice, ok := v.([]interface{}); ok {

@ -1,8 +1,6 @@
package qt package qt
import ( import (
"fmt"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/ui" "github.com/ethereum/go-ethereum/ui"
"gopkg.in/qml.v1" "gopkg.in/qml.v1"
@ -23,13 +21,10 @@ func makeAltered(v interface{}) (d []core.AccountChange) {
var s []interface{} var s []interface{}
qList.Convert(&s) qList.Convert(&s)
fmt.Println(s)
d = makeAltered(s) d = makeAltered(s)
} else if qMap, ok := v.(*qml.Map); ok { } else if qMap, ok := v.(*qml.Map); ok {
var m map[string]interface{} var m map[string]interface{}
qMap.Convert(&m) qMap.Convert(&m)
fmt.Println(m)
d = makeAltered(m) d = makeAltered(m)
} }

@ -51,7 +51,13 @@ func (c *Client) Conn() *ws.Conn {
} }
func (c *Client) Write(data interface{}, id int) { func (c *Client) Write(data interface{}, id int) {
msg := &Message{Id: id, Data: data} c.write(&Message{Id: id, Data: data})
}
func (c *Client) Event(data interface{}, ev string, id int) {
c.write(&Message{Id: id, Data: data, Event: ev})
}
func (c *Client) write(msg *Message) {
select { select {
case c.ch <- msg: case c.ch <- msg:
default: default:

@ -3,10 +3,11 @@ package websocket
import "github.com/ethereum/go-ethereum/ethutil" import "github.com/ethereum/go-ethereum/ethutil"
type Message struct { type Message struct {
Call string `json:"call"` Call string `json:"call"`
Args []interface{} `json:"args"` Args []interface{} `json:"args"`
Id int `json:"_id"` Id int `json:"_id"`
Data interface{} `json:"data"` Data interface{} `json:"data"`
Event string `json:"_event"`
} }
func (self *Message) Arguments() *ethutil.Value { func (self *Message) Arguments() *ethutil.Value {

@ -20,7 +20,7 @@ func NewJSXEth(eth core.EthManager) *JSXEth {
} }
func (self *JSXEth) BlockByHash(strHash string) *JSBlock { func (self *JSXEth) BlockByHash(strHash string) *JSBlock {
hash := ethutil.Hex2Bytes(strHash) hash := fromHex(strHash)
block := self.obj.ChainManager().GetBlock(hash) block := self.obj.ChainManager().GetBlock(hash)
return NewJSBlock(block) return NewJSBlock(block)
@ -50,8 +50,12 @@ func (self *JSXEth) Key() *JSKey {
return NewJSKey(self.obj.KeyManager().KeyPair()) return NewJSKey(self.obj.KeyManager().KeyPair())
} }
func (self *JSXEth) Accounts() []string {
return []string{toHex(self.obj.KeyManager().Address())}
}
func (self *JSXEth) StateObject(addr string) *JSObject { func (self *JSXEth) StateObject(addr string) *JSObject {
object := &Object{self.World().safeGet(ethutil.Hex2Bytes(addr))} object := &Object{self.World().safeGet(fromHex(addr))}
return NewJSObject(object) return NewJSObject(object)
} }
@ -78,7 +82,7 @@ func (self *JSXEth) IsListening() bool {
} }
func (self *JSXEth) CoinBase() string { func (self *JSXEth) CoinBase() string {
return ethutil.Bytes2Hex(self.obj.KeyManager().Address()) return toHex(self.obj.KeyManager().Address())
} }
func (self *JSXEth) NumberToHuman(balance string) string { func (self *JSXEth) NumberToHuman(balance string) string {
@ -88,46 +92,46 @@ func (self *JSXEth) NumberToHuman(balance string) string {
} }
func (self *JSXEth) StorageAt(addr, storageAddr string) string { func (self *JSXEth) StorageAt(addr, storageAddr string) string {
storage := self.World().SafeGet(ethutil.Hex2Bytes(addr)).Storage(ethutil.Hex2Bytes(storageAddr)) storage := self.World().SafeGet(fromHex(addr)).Storage(fromHex(storageAddr))
return ethutil.Bytes2Hex(storage.Bytes()) return toHex(storage.Bytes())
} }
func (self *JSXEth) BalanceAt(addr string) string { func (self *JSXEth) BalanceAt(addr string) string {
return self.World().SafeGet(ethutil.Hex2Bytes(addr)).Balance().String() return self.World().SafeGet(fromHex(addr)).Balance().String()
} }
func (self *JSXEth) TxCountAt(address string) int { func (self *JSXEth) TxCountAt(address string) int {
return int(self.World().SafeGet(ethutil.Hex2Bytes(address)).Nonce) return int(self.World().SafeGet(fromHex(address)).Nonce)
} }
func (self *JSXEth) CodeAt(address string) string { func (self *JSXEth) CodeAt(address string) string {
return ethutil.Bytes2Hex(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code) return toHex(self.World().SafeGet(fromHex(address)).Code)
} }
func (self *JSXEth) IsContract(address string) bool { func (self *JSXEth) IsContract(address string) bool {
return len(self.World().SafeGet(ethutil.Hex2Bytes(address)).Code) > 0 return len(self.World().SafeGet(fromHex(address)).Code) > 0
} }
func (self *JSXEth) SecretToAddress(key string) string { func (self *JSXEth) SecretToAddress(key string) string {
pair, err := crypto.NewKeyPairFromSec(ethutil.Hex2Bytes(key)) pair, err := crypto.NewKeyPairFromSec(fromHex(key))
if err != nil { if err != nil {
return "" return ""
} }
return ethutil.Bytes2Hex(pair.Address()) return toHex(pair.Address())
} }
func (self *JSXEth) Execute(addr, value, gas, price, data string) (string, error) { func (self *JSXEth) Execute(addr, value, gas, price, data string) (string, error) {
ret, err := self.ExecuteObject(&Object{ ret, err := self.ExecuteObject(&Object{
self.World().safeGet(ethutil.Hex2Bytes(addr))}, self.World().safeGet(fromHex(addr))},
ethutil.Hex2Bytes(data), fromHex(data),
ethutil.NewValue(value), ethutil.NewValue(value),
ethutil.NewValue(gas), ethutil.NewValue(gas),
ethutil.NewValue(price), ethutil.NewValue(price),
) )
return ethutil.Bytes2Hex(ret), err return toHex(ret), err
} }
type KeyVal struct { type KeyVal struct {
@ -137,10 +141,10 @@ type KeyVal struct {
func (self *JSXEth) EachStorage(addr string) string { func (self *JSXEth) EachStorage(addr string) string {
var values []KeyVal var values []KeyVal
object := self.World().SafeGet(ethutil.Hex2Bytes(addr)) object := self.World().SafeGet(fromHex(addr))
it := object.Trie().Iterator() it := object.Trie().Iterator()
for it.Next() { for it.Next() {
values = append(values, KeyVal{ethutil.Bytes2Hex(it.Key), ethutil.Bytes2Hex(it.Value)}) values = append(values, KeyVal{toHex(it.Key), toHex(it.Value)})
} }
valuesJson, err := json.Marshal(values) valuesJson, err := json.Marshal(values)
@ -154,7 +158,7 @@ func (self *JSXEth) EachStorage(addr string) string {
func (self *JSXEth) ToAscii(str string) string { func (self *JSXEth) ToAscii(str string) string {
padded := ethutil.RightPadBytes([]byte(str), 32) padded := ethutil.RightPadBytes([]byte(str), 32)
return "0x" + ethutil.Bytes2Hex(padded) return "0x" + toHex(padded)
} }
func (self *JSXEth) FromAscii(str string) string { func (self *JSXEth) FromAscii(str string) string {
@ -162,7 +166,7 @@ func (self *JSXEth) FromAscii(str string) string {
str = str[2:] str = str[2:]
} }
return string(bytes.Trim(ethutil.Hex2Bytes(str), "\x00")) return string(bytes.Trim(fromHex(str), "\x00"))
} }
func (self *JSXEth) FromNumber(str string) string { func (self *JSXEth) FromNumber(str string) string {
@ -170,7 +174,7 @@ func (self *JSXEth) FromNumber(str string) string {
str = str[2:] str = str[2:]
} }
return ethutil.BigD(ethutil.Hex2Bytes(str)).String() return ethutil.BigD(fromHex(str)).String()
} }
func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
@ -182,26 +186,11 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
data []byte data []byte
) )
if ethutil.IsHex(codeStr) { data = fromHex(codeStr)
data = ethutil.Hex2Bytes(codeStr[2:])
} else {
data = ethutil.Hex2Bytes(codeStr)
}
if ethutil.IsHex(toStr) {
to = ethutil.Hex2Bytes(toStr[2:])
} else {
to = ethutil.Hex2Bytes(toStr)
}
var keyPair *crypto.KeyPair to = fromHex(toStr)
var err error
if ethutil.IsHex(key) {
keyPair, err = crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(key[2:])))
} else {
keyPair, err = crypto.NewKeyPairFromSec([]byte(ethutil.Hex2Bytes(key)))
}
keyPair, err := crypto.NewKeyPairFromSec([]byte(fromHex(key)))
if err != nil { if err != nil {
return "", err return "", err
} }
@ -211,14 +200,14 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
return "", err return "", err
} }
if types.IsContractAddr(to) { if types.IsContractAddr(to) {
return ethutil.Bytes2Hex(core.AddressFromMessage(tx)), nil return toHex(core.AddressFromMessage(tx)), nil
} }
return ethutil.Bytes2Hex(tx.Hash()), nil return toHex(tx.Hash()), nil
} }
func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) { func (self *JSXEth) PushTx(txStr string) (*JSReceipt, error) {
tx := types.NewTransactionFromBytes(ethutil.Hex2Bytes(txStr)) tx := types.NewTransactionFromBytes(fromHex(txStr))
err := self.obj.TxPool().Add(tx) err := self.obj.TxPool().Add(tx)
if err != nil { if err != nil {
return nil, err return nil, err
@ -233,11 +222,11 @@ func (self *JSXEth) CompileMutan(code string) string {
return err.Error() return err.Error()
} }
return ethutil.Bytes2Hex(data) return toHex(data)
} }
func (self *JSXEth) FindInConfig(str string) string { func (self *JSXEth) FindInConfig(str string) string {
return ethutil.Bytes2Hex(self.World().Config().Get(str).Address()) return toHex(self.World().Config().Get(str).Address())
} }
func ToJSMessages(messages state.Messages) *ethutil.List { func ToJSMessages(messages state.Messages) *ethutil.List {

@ -12,6 +12,19 @@ import (
"github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/state"
) )
func toHex(b []byte) string {
return "0x" + ethutil.Bytes2Hex(b)
}
func fromHex(s string) []byte {
if len(s) > 1 {
if s[0:2] == "0x" {
s = s[2:]
}
return ethutil.Hex2Bytes(s)
}
return nil
}
// Block interface exposed to QML // Block interface exposed to QML
type JSBlock struct { type JSBlock struct {
//Transactions string `json:"transactions"` //Transactions string `json:"transactions"`
@ -52,12 +65,12 @@ func NewJSBlock(block *types.Block) *JSBlock {
return &JSBlock{ return &JSBlock{
ref: block, Size: block.Size().String(), ref: block, Size: block.Size().String(),
Number: int(block.NumberU64()), GasUsed: block.GasUsed().String(), Number: int(block.NumberU64()), GasUsed: block.GasUsed().String(),
GasLimit: block.GasLimit().String(), Hash: ethutil.Bytes2Hex(block.Hash()), GasLimit: block.GasLimit().String(), Hash: toHex(block.Hash()),
Transactions: txlist, Uncles: ulist, Transactions: txlist, Uncles: ulist,
Time: block.Time(), Time: block.Time(),
Coinbase: ethutil.Bytes2Hex(block.Coinbase()), Coinbase: toHex(block.Coinbase()),
PrevHash: ethutil.Bytes2Hex(block.ParentHash()), PrevHash: toHex(block.ParentHash()),
Bloom: ethutil.Bytes2Hex(block.Bloom()), Bloom: toHex(block.Bloom()),
Raw: block.String(), Raw: block.String(),
} }
} }
@ -71,7 +84,7 @@ func (self *JSBlock) ToString() string {
} }
func (self *JSBlock) GetTransaction(hash string) *JSTransaction { func (self *JSBlock) GetTransaction(hash string) *JSTransaction {
tx := self.ref.Transaction(ethutil.Hex2Bytes(hash)) tx := self.ref.Transaction(fromHex(hash))
if tx == nil { if tx == nil {
return nil return nil
} }
@ -96,22 +109,22 @@ type JSTransaction struct {
} }
func NewJSTx(tx *types.Transaction) *JSTransaction { func NewJSTx(tx *types.Transaction) *JSTransaction {
hash := ethutil.Bytes2Hex(tx.Hash()) hash := toHex(tx.Hash())
receiver := ethutil.Bytes2Hex(tx.To()) receiver := toHex(tx.To())
if receiver == "0000000000000000000000000000000000000000" { if receiver == "0000000000000000000000000000000000000000" {
receiver = ethutil.Bytes2Hex(core.AddressFromMessage(tx)) receiver = toHex(core.AddressFromMessage(tx))
} }
sender := ethutil.Bytes2Hex(tx.From()) sender := toHex(tx.From())
createsContract := core.MessageCreatesContract(tx) createsContract := core.MessageCreatesContract(tx)
var data string var data string
if createsContract { if createsContract {
data = strings.Join(core.Disassemble(tx.Data()), "\n") data = strings.Join(core.Disassemble(tx.Data()), "\n")
} else { } else {
data = ethutil.Bytes2Hex(tx.Data()) data = toHex(tx.Data())
} }
return &JSTransaction{ref: tx, Hash: hash, Value: ethutil.CurrencyToString(tx.Value()), Address: receiver, Contract: createsContract, Gas: tx.Gas().String(), GasPrice: tx.GasPrice().String(), Data: data, Sender: sender, CreatesContract: createsContract, RawData: ethutil.Bytes2Hex(tx.Data())} return &JSTransaction{ref: tx, Hash: hash, Value: ethutil.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())}
} }
func (self *JSTransaction) ToString() string { func (self *JSTransaction) ToString() string {
@ -125,7 +138,7 @@ type JSKey struct {
} }
func NewJSKey(key *crypto.KeyPair) *JSKey { func NewJSKey(key *crypto.KeyPair) *JSKey {
return &JSKey{ethutil.Bytes2Hex(key.Address()), ethutil.Bytes2Hex(key.PrivateKey), ethutil.Bytes2Hex(key.PublicKey)} return &JSKey{toHex(key.Address()), toHex(key.PrivateKey), toHex(key.PublicKey)}
} }
type JSObject struct { type JSObject struct {
@ -146,9 +159,9 @@ type PReceipt struct {
func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) *PReceipt { func NewPReciept(contractCreation bool, creationAddress, hash, address []byte) *PReceipt {
return &PReceipt{ return &PReceipt{
contractCreation, contractCreation,
ethutil.Bytes2Hex(creationAddress), toHex(creationAddress),
ethutil.Bytes2Hex(hash), toHex(hash),
ethutil.Bytes2Hex(address), toHex(address),
} }
} }
@ -185,9 +198,9 @@ type JSReceipt struct {
func NewJSReciept(contractCreation bool, creationAddress, hash, address []byte) *JSReceipt { func NewJSReciept(contractCreation bool, creationAddress, hash, address []byte) *JSReceipt {
return &JSReceipt{ return &JSReceipt{
contractCreation, contractCreation,
ethutil.Bytes2Hex(creationAddress), toHex(creationAddress),
ethutil.Bytes2Hex(hash), toHex(hash),
ethutil.Bytes2Hex(address), toHex(address),
} }
} }
@ -207,15 +220,15 @@ type JSMessage struct {
func NewJSMessage(message *state.Message) JSMessage { func NewJSMessage(message *state.Message) JSMessage {
return JSMessage{ return JSMessage{
To: ethutil.Bytes2Hex(message.To), To: toHex(message.To),
From: ethutil.Bytes2Hex(message.From), From: toHex(message.From),
Input: ethutil.Bytes2Hex(message.Input), Input: toHex(message.Input),
Output: ethutil.Bytes2Hex(message.Output), Output: toHex(message.Output),
Path: int32(message.Path), Path: int32(message.Path),
Origin: ethutil.Bytes2Hex(message.Origin), Origin: toHex(message.Origin),
Timestamp: int32(message.Timestamp), Timestamp: int32(message.Timestamp),
Coinbase: ethutil.Bytes2Hex(message.Origin), Coinbase: toHex(message.Origin),
Block: ethutil.Bytes2Hex(message.Block), Block: toHex(message.Block),
Number: int32(message.Number.Int64()), Number: int32(message.Number.Int64()),
Value: message.Value.String(), Value: message.Value.String(),
} }

Loading…
Cancel
Save