aboutsummaryrefslogtreecommitdiffstats
path: root/ethereal/ext_app.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-08-14 23:01:37 +0800
committerobscuren <geffobscura@gmail.com>2014-08-14 23:01:37 +0800
commit1fd69e956949671806b23b7ec1feec4f6c416a81 (patch)
treee807a5564dd81c75b550aeb12405d51f3704d125 /ethereal/ext_app.go
parent612b631823c0cb80f0e559c533b32b6890349761 (diff)
downloadgo-tangerine-1fd69e956949671806b23b7ec1feec4f6c416a81.tar
go-tangerine-1fd69e956949671806b23b7ec1feec4f6c416a81.tar.gz
go-tangerine-1fd69e956949671806b23b7ec1feec4f6c416a81.tar.bz2
go-tangerine-1fd69e956949671806b23b7ec1feec4f6c416a81.tar.lz
go-tangerine-1fd69e956949671806b23b7ec1feec4f6c416a81.tar.xz
go-tangerine-1fd69e956949671806b23b7ec1feec4f6c416a81.tar.zst
go-tangerine-1fd69e956949671806b23b7ec1feec4f6c416a81.zip
Implemented "messages"
Diffstat (limited to 'ethereal/ext_app.go')
-rw-r--r--ethereal/ext_app.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/ethereal/ext_app.go b/ethereal/ext_app.go
index 697630504..4533b2438 100644
--- a/ethereal/ext_app.go
+++ b/ethereal/ext_app.go
@@ -1,11 +1,14 @@
package main
import (
+ "encoding/json"
+
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethreact"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
+ "github.com/ethereum/go-ethereum/javascript"
"github.com/go-qml/qml"
)
@@ -24,6 +27,7 @@ type AppContainer interface {
type ExtApplication struct {
*ethpub.PEthereum
+ eth ethchain.EthManager
blockChan chan ethreact.Event
changeChan chan ethreact.Event
@@ -38,6 +42,7 @@ type ExtApplication struct {
func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication {
app := &ExtApplication{
ethpub.NewPEthereum(lib.eth),
+ lib.eth,
make(chan ethreact.Event, 100),
make(chan ethreact.Event, 100),
make(chan bool),
@@ -130,3 +135,50 @@ func (app *ExtApplication) Watch(addr, storageAddr string) {
app.registeredEvents = append(app.registeredEvents, event)
}
+
+func (self *ExtApplication) GetMessages(object map[string]interface{}) string {
+ filter := ethchain.NewFilter(self.eth)
+
+ if object["earliest"] != nil {
+ earliest := object["earliest"]
+ if e, ok := earliest.(string); ok {
+ filter.SetEarliestBlock(ethutil.Hex2Bytes(e))
+ } else {
+ filter.SetEarliestBlock(earliest)
+ }
+ }
+
+ if object["latest"] != nil {
+ latest := object["latest"]
+ if l, ok := latest.(string); ok {
+ filter.SetLatestBlock(ethutil.Hex2Bytes(l))
+ } else {
+ filter.SetLatestBlock(latest)
+ }
+ }
+ if object["to"] != nil {
+ filter.AddTo(ethutil.Hex2Bytes(object["to"].(string)))
+ }
+ if object["from"] != nil {
+ filter.AddFrom(ethutil.Hex2Bytes(object["from"].(string)))
+ }
+ if object["max"] != nil {
+ filter.SetMax(object["max"].(int))
+ }
+ if object["skip"] != nil {
+ filter.SetSkip(object["skip"].(int))
+ }
+
+ messages := filter.Find()
+ var msgs []javascript.JSMessage
+ for _, m := range messages {
+ msgs = append(msgs, javascript.NewJSMessage(m))
+ }
+
+ b, err := json.Marshal(msgs)
+ if err != nil {
+ return "{\"error\":" + err.Error() + "}"
+ }
+
+ return string(b)
+}