forked from cerc-io/plugeth
Reworked filters
This commit is contained in:
parent
893e9256a0
commit
91ca5d724e
@ -1,31 +1,49 @@
|
||||
var ethx = {
|
||||
prototype: Object,
|
||||
|
||||
watch: function(options) {
|
||||
return new Filter(options);
|
||||
},
|
||||
|
||||
note: function() {
|
||||
var args = Array.prototype.slice.call(arguments, 0);
|
||||
var o = []
|
||||
for(var i = 0; i < args.length; i++) {
|
||||
o.push(args[i].toString())
|
||||
}
|
||||
|
||||
eth.notef(o);
|
||||
},
|
||||
};
|
||||
|
||||
var Filter = function(options) {
|
||||
this.callbacks = {};
|
||||
this.seed = Math.floor(Math.random() * 1000000);
|
||||
this.callbacks = [];
|
||||
this.options = options;
|
||||
|
||||
if(options === "chain") {
|
||||
eth.registerFilterString(options, this.seed);
|
||||
this.id = eth.newFilterString(options);
|
||||
} else if(typeof options === "object") {
|
||||
eth.registerFilter(options, this.seed);
|
||||
this.id = eth.newFilter(options);
|
||||
}
|
||||
};
|
||||
|
||||
Filter.prototype.changed = function(callback) {
|
||||
var cbseed = Math.floor(Math.random() * 1000000);
|
||||
eth.registerFilterCallback(this.seed, cbseed);
|
||||
this.callbacks.push(callback);
|
||||
|
||||
var self = this;
|
||||
message.connect(function(messages, seed, callbackSeed) {
|
||||
if(seed == self.seed && callbackSeed == cbseed) {
|
||||
callback.call(self, messages);
|
||||
message.connect(function(messages, id) {
|
||||
if(id == self.id) {
|
||||
for(var i = 0; i < self.callbacks.length; i++) {
|
||||
self.callbacks[i].call(self, messages);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Filter.prototype.uninstall = function() {
|
||||
eth.uninstallFilter(this.seed)
|
||||
eth.uninstallFilter(this.id)
|
||||
}
|
||||
|
||||
Filter.prototype.messages = function() {
|
||||
return JSON.parse(eth.messages(this.options))
|
||||
return eth.messages(this.id)
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import QtQuick.Dialogs 1.0;
|
||||
import QtQuick.Window 2.1;
|
||||
import QtQuick.Controls.Styles 1.1
|
||||
import Ethereum 1.0
|
||||
import "../../ext/filter.js" as Eth
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
@ -152,7 +151,7 @@ Rectangle {
|
||||
model: ListModel {
|
||||
id: txModel
|
||||
Component.onCompleted: {
|
||||
var filter = new Eth.Filter({latest: -1, from: eth.key().address})
|
||||
var filter = ethx.watch({latest: -1, from: eth.key().address});
|
||||
filter.changed(addTxs)
|
||||
|
||||
addTxs(filter.messages())
|
||||
@ -160,7 +159,7 @@ Rectangle {
|
||||
|
||||
function addTxs(messages) {
|
||||
for(var i = 0; i < messages.length; i++) {
|
||||
var message = messages[i];
|
||||
var message = messages.get(i);
|
||||
txModel.insert(0, {num: txModel.count, from: message.from, to: message.to, value: eth.numberToHuman(message.value)})
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,8 @@
|
||||
package main
|
||||
|
||||
// #include "/Users/jeffrey/go/src/github.com/go-qml/qml/cpp/capi.h"
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
@ -10,7 +13,9 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"bitbucket.org/binet/go-ffi/pkg/ffi"
|
||||
"github.com/ethereum/eth-go"
|
||||
"github.com/ethereum/eth-go/ethchain"
|
||||
"github.com/ethereum/eth-go/ethdb"
|
||||
@ -23,6 +28,29 @@ import (
|
||||
"gopkg.in/qml.v1"
|
||||
)
|
||||
|
||||
func LoadExtension(path string) (uintptr, error) {
|
||||
lib, err := ffi.NewLibrary(path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
so, err := lib.Fct("sharedObject", ffi.Pointer, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
ptr := so()
|
||||
|
||||
/*
|
||||
err = lib.Close()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
*/
|
||||
|
||||
return ptr.Interface().(uintptr), nil
|
||||
}
|
||||
|
||||
var logger = ethlog.NewLogger("GUI")
|
||||
|
||||
type Gui struct {
|
||||
@ -91,6 +119,14 @@ func (gui *Gui) Start(assetPath string) {
|
||||
context.SetVar("gui", gui)
|
||||
context.SetVar("eth", gui.uiLib)
|
||||
|
||||
vec, errr := LoadExtension("/Users/jeffrey/Desktop/build-libqmltest-Desktop_Qt_5_2_1_clang_64bit-Debug/liblibqmltest_debug.dylib")
|
||||
fmt.Printf("Fetched vec with addr: %#x\n", vec)
|
||||
if errr != nil {
|
||||
fmt.Println(errr)
|
||||
} else {
|
||||
context.SetVar("vec", (unsafe.Pointer)(vec))
|
||||
}
|
||||
|
||||
// Load the main QML interface
|
||||
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
|
||||
|
||||
|
@ -37,15 +37,15 @@ type UiLib struct {
|
||||
jsEngine *javascript.JSRE
|
||||
|
||||
filterCallbacks map[int][]int
|
||||
filters map[int]*GuiFilter
|
||||
//filters map[int]*ethpipe.JSFilter
|
||||
}
|
||||
|
||||
func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib {
|
||||
return &UiLib{JSPipe: ethpipe.NewJSPipe(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int), filters: make(map[int]*GuiFilter)}
|
||||
return &UiLib{JSPipe: ethpipe.NewJSPipe(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*ethpipe.JSFilter)}
|
||||
}
|
||||
|
||||
func (self *UiLib) Note(msg string) {
|
||||
logger.Infoln(msg)
|
||||
func (self *UiLib) Notef(args []interface{}) {
|
||||
logger.Infoln(args...)
|
||||
}
|
||||
|
||||
func (self *UiLib) LookupDomain(domain string) string {
|
||||
@ -164,46 +164,37 @@ func (self *UiLib) StartDebugger() {
|
||||
dbWindow.Show()
|
||||
}
|
||||
|
||||
func (self *UiLib) RegisterFilter(object map[string]interface{}, seed int) {
|
||||
filter := &GuiFilter{ethpipe.NewJSFilterFromMap(object, self.eth), seed}
|
||||
self.filters[seed] = filter
|
||||
|
||||
func (self *UiLib) NewFilter(object map[string]interface{}) int {
|
||||
filter, id := self.eth.InstallFilter(object)
|
||||
filter.MessageCallback = func(messages ethstate.Messages) {
|
||||
for _, callbackSeed := range self.filterCallbacks[seed] {
|
||||
self.win.Root().Call("invokeFilterCallback", filter.MessagesToJson(messages), seed, callbackSeed)
|
||||
}
|
||||
self.win.Root().Call("invokeFilterCallback", ethpipe.ToJSMessages(messages), id)
|
||||
}
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
func (self *UiLib) RegisterFilterString(typ string, seed int) {
|
||||
filter := &GuiFilter{ethpipe.NewJSFilterFromMap(nil, self.eth), seed}
|
||||
self.filters[seed] = filter
|
||||
|
||||
if typ == "chain" {
|
||||
filter.BlockCallback = func(block *ethchain.Block) {
|
||||
for _, callbackSeed := range self.filterCallbacks[seed] {
|
||||
self.win.Root().Call("invokeFilterCallback", "{}", seed, callbackSeed)
|
||||
}
|
||||
}
|
||||
func (self *UiLib) NewFilterString(typ string) int {
|
||||
filter, id := self.eth.InstallFilter(nil)
|
||||
filter.BlockCallback = func(block *ethchain.Block) {
|
||||
self.win.Root().Call("invokeFilterCallback", "{}", id)
|
||||
}
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
func (self *UiLib) RegisterFilterCallback(seed, cbSeed int) {
|
||||
self.filterCallbacks[seed] = append(self.filterCallbacks[seed], cbSeed)
|
||||
}
|
||||
|
||||
func (self *UiLib) UninstallFilter(seed int) {
|
||||
filter := self.filters[seed]
|
||||
func (self *UiLib) Messages(id int) *ethutil.List {
|
||||
filter := self.eth.GetFilter(id)
|
||||
if filter != nil {
|
||||
filter.Uninstall()
|
||||
delete(self.filters, seed)
|
||||
messages := filter.Find()
|
||||
|
||||
return ethpipe.ToJSMessages(messages)
|
||||
}
|
||||
|
||||
return ethutil.EmptyList()
|
||||
}
|
||||
|
||||
type GuiFilter struct {
|
||||
*ethpipe.JSFilter
|
||||
seed int
|
||||
func (self *UiLib) UninstallFilter(id int) {
|
||||
self.eth.UninstallFilter(id)
|
||||
}
|
||||
|
||||
func (self *UiLib) Transact(object map[string]interface{}) (*ethpipe.JSReceipt, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user