diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/filter.go | 76 | ||||
-rw-r--r-- | ui/frontend.go | 18 | ||||
-rw-r--r-- | ui/qt/filter.go | 29 | ||||
-rw-r--r-- | ui/qt/qwhisper/message.go | 6 | ||||
-rw-r--r-- | ui/qt/qwhisper/whisper.go | 28 |
5 files changed, 13 insertions, 144 deletions
diff --git a/ui/filter.go b/ui/filter.go index 0d1746915..5b1faa293 100644 --- a/ui/filter.go +++ b/ui/filter.go @@ -1,77 +1 @@ package ui - -import ( - "github.com/ethereum/go-ethereum/core" - "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.Backend) *core.Filter { - filter := core.NewFilter(eth) - - if object["earliest"] != nil { - val := ethutil.NewValue(object["earliest"]) - filter.SetEarliestBlock(val.Int()) - } - - if object["latest"] != nil { - val := ethutil.NewValue(object["latest"]) - filter.SetLatestBlock(val.Int()) - } - - if object["address"] != nil { - //val := ethutil.NewValue(object["address"]) - //filter.SetAddress(fromHex(val.Str())) - } - - if object["max"] != nil { - val := ethutil.NewValue(object["max"]) - filter.SetMax(int(val.Uint())) - } - - if object["skip"] != nil { - val := ethutil.NewValue(object["skip"]) - filter.SetSkip(int(val.Uint())) - } - - if object["topics"] != nil { - filter.SetTopics(MakeTopics(object["topics"])) - } - - return filter -} - -// Conversion methodn -func mapToAccountChange(m map[string]interface{}) (d core.AccountChange) { - if str, ok := m["id"].(string); ok { - d.Address = fromHex(str) - } - - if str, ok := m["at"].(string); ok { - d.StateAddress = fromHex(str) - } - - return -} - -// data can come in in the following formats: -// ["aabbccdd", {id: "ccddee", at: "11223344"}], "aabbcc", {id: "ccddee", at: "1122"} -func MakeTopics(v interface{}) (d [][]byte) { - if str, ok := v.(string); ok { - d = append(d, fromHex(str)) - } else if slice, ok := v.([]string); ok { - for _, item := range slice { - d = append(d, fromHex(item)) - } - } - return -} diff --git a/ui/frontend.go b/ui/frontend.go deleted file mode 100644 index 22dc64fdf..000000000 --- a/ui/frontend.go +++ /dev/null @@ -1,18 +0,0 @@ -package ui - -// ReturnInterface is returned by the Intercom interface when a method is called -type ReturnInterface interface { - Get(i int) (interface{}, error) - Size() int -} - -// Frontend is the basic interface for calling arbitrary methods on something that -// implements a front end (GUI, CLI, etc) -type Frontend interface { - // Checks whether a specific method is implemented - Supports(method string) bool - // Call calls the given method on interface it implements. This will return - // an error with errNotImplemented if the method hasn't been implemented - // and will return a ReturnInterface if it does. - Call(method string) (ReturnInterface, error) -} diff --git a/ui/qt/filter.go b/ui/qt/filter.go index 48e8a7fae..090260e4e 100644 --- a/ui/qt/filter.go +++ b/ui/qt/filter.go @@ -1,30 +1 @@ package qt - -import ( - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/ui" - "github.com/obscuren/qml" -) - -func NewFilterFromMap(object map[string]interface{}, eth core.Backend) *core.Filter { - filter := ui.NewFilterFromMap(object, eth) - - if object["topics"] != nil { - filter.SetTopics(makeTopics(object["topics"])) - } - - return filter -} - -func makeTopics(v interface{}) (d [][]byte) { - if qList, ok := v.(*qml.List); ok { - var s []string - qList.Convert(&s) - - d = ui.MakeTopics(s) - } else if str, ok := v.(string); ok { - d = ui.MakeTopics(str) - } - - return -} diff --git a/ui/qt/qwhisper/message.go b/ui/qt/qwhisper/message.go index 26e72ac93..f8bed8a2d 100644 --- a/ui/qt/qwhisper/message.go +++ b/ui/qt/qwhisper/message.go @@ -2,7 +2,7 @@ package qwhisper import ( "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/whisper" ) @@ -17,7 +17,7 @@ func ToQMessage(msg *whisper.Message) *Message { return &Message{ ref: msg, Flags: int32(msg.Flags), - Payload: "0x" + ethutil.Bytes2Hex(msg.Payload), - From: "0x" + ethutil.Bytes2Hex(crypto.FromECDSAPub(msg.Recover())), + Payload: "0x" + common.Bytes2Hex(msg.Payload), + From: "0x" + common.Bytes2Hex(crypto.FromECDSAPub(msg.Recover())), } } diff --git a/ui/qt/qwhisper/whisper.go b/ui/qt/qwhisper/whisper.go index 2bc455b0b..bf165bbcc 100644 --- a/ui/qt/qwhisper/whisper.go +++ b/ui/qt/qwhisper/whisper.go @@ -4,8 +4,8 @@ package qwhisper import ( "time" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/whisper" "github.com/obscuren/qml" @@ -13,14 +13,6 @@ import ( var qlogger = logger.NewLogger("QSHH") -func fromHex(s string) []byte { - if len(s) > 1 { - return ethutil.Hex2Bytes(s[2:]) - } - return nil -} -func toHex(b []byte) string { return "0x" + ethutil.Bytes2Hex(b) } - type Whisper struct { *whisper.Whisper view qml.Object @@ -39,15 +31,15 @@ func (self *Whisper) SetView(view qml.Object) { func (self *Whisper) Post(payload []string, to, from string, topics []string, priority, ttl uint32) { var data []byte for _, d := range payload { - data = append(data, fromHex(d)...) + data = append(data, common.FromHex(d)...) } - pk := crypto.ToECDSAPub(fromHex(from)) + pk := crypto.ToECDSAPub(common.FromHex(from)) if key := self.Whisper.GetIdentity(pk); key != nil { msg := whisper.NewMessage(data) envelope, err := msg.Seal(time.Duration(priority*100000), whisper.Opts{ Ttl: time.Duration(ttl) * time.Second, - To: crypto.ToECDSAPub(fromHex(to)), + To: crypto.ToECDSAPub(common.FromHex(to)), From: key, Topics: whisper.TopicsFromString(topics...), }) @@ -72,11 +64,11 @@ func (self *Whisper) Post(payload []string, to, from string, topics []string, pr 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 { - return self.Whisper.HasIdentity(crypto.ToECDSAPub(fromHex(key))) + return self.Whisper.HasIdentity(crypto.ToECDSAPub(common.FromHex(key))) } func (self *Whisper) Watch(opts map[string]interface{}, view *qml.Common) int { @@ -94,9 +86,9 @@ func (self *Whisper) Watch(opts map[string]interface{}, view *qml.Common) int { return i } -func (self *Whisper) Messages(id int) (messages *ethutil.List) { +func (self *Whisper) Messages(id int) (messages *common.List) { msgs := self.Whisper.Messages(id) - messages = ethutil.EmptyList() + messages = common.EmptyList() for _, message := range msgs { messages.Append(ToQMessage(message)) } @@ -106,10 +98,10 @@ func (self *Whisper) Messages(id int) (messages *ethutil.List) { func filterFromMap(opts map[string]interface{}) (f whisper.Filter) { if to, ok := opts["to"].(string); ok { - f.To = crypto.ToECDSAPub(fromHex(to)) + f.To = crypto.ToECDSAPub(common.FromHex(to)) } if from, ok := opts["from"].(string); ok { - f.From = crypto.ToECDSAPub(fromHex(from)) + f.From = crypto.ToECDSAPub(common.FromHex(from)) } if topicList, ok := opts["topics"].(*qml.List); ok { var topics []string |