local storage signal
This commit is contained in:
parent
0d5a6911ce
commit
c1d2cfde08
|
@ -0,0 +1,16 @@
|
|||
package geth
|
||||
|
||||
/*
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
extern bool StatusServiceSignalEvent( const char *jsonEvent );
|
||||
*/
|
||||
import "C"
|
||||
|
||||
const (
|
||||
EventLocalStorageSet = "local_storage.set"
|
||||
)
|
||||
|
||||
func SendSignal(data []byte) {
|
||||
C.StatusServiceSignalEvent(C.CString(string(data)))
|
||||
}
|
|
@ -41,6 +41,10 @@ type SendTransactionEvent struct {
|
|||
MessageId string `json:"message_id"`
|
||||
}
|
||||
|
||||
type LocalStorageEvent struct {
|
||||
Data string `json:"data"`
|
||||
}
|
||||
|
||||
type ReturnSendTransactionEvent struct {
|
||||
Id string `json:"id"`
|
||||
Args status.SendTxArgs `json:"args"`
|
||||
|
|
22
jail/jail.go
22
jail/jail.go
|
@ -69,6 +69,22 @@ func NewJailedRuntime(id string) *JailedRuntime {
|
|||
}
|
||||
}
|
||||
|
||||
func localStorageSetData(call otto.FunctionCall) otto.Value {
|
||||
data := call.Argument(0).String()
|
||||
|
||||
event := geth.GethEvent{
|
||||
Type: geth.EventLocalStorageSet,
|
||||
Event: geth.LocalStorageEvent{
|
||||
Data: data,
|
||||
},
|
||||
}
|
||||
|
||||
body, _ := json.Marshal(&event)
|
||||
geth.SendSignal(body)
|
||||
|
||||
return otto.Value{}
|
||||
}
|
||||
|
||||
func (jail *Jail) Parse(chatId string, js string) string {
|
||||
if jail == nil {
|
||||
return printError(ErrInvalidJail.Error())
|
||||
|
@ -95,6 +111,10 @@ func (jail *Jail) Parse(chatId string, js string) string {
|
|||
return jail.IsConnected(call)
|
||||
})
|
||||
|
||||
vm.Set("localStorage", struct{}{})
|
||||
localStorage, _ := vm.Get("localStorage")
|
||||
localStorage.Object().Set("set", localStorageSetData)
|
||||
|
||||
jjs := Web3_JS + `
|
||||
var Web3 = require('web3');
|
||||
var web3 = new Web3(jeth);
|
||||
|
@ -187,7 +207,7 @@ func (jail *Jail) Send(chatId string, call otto.FunctionCall) (response otto.Val
|
|||
var (
|
||||
rawReq = []byte(reqVal.String())
|
||||
reqs []geth.RPCCall
|
||||
batch bool
|
||||
batch bool
|
||||
)
|
||||
if rawReq[0] == '[' {
|
||||
batch = true
|
||||
|
|
Loading…
Reference in New Issue