Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
b97ea0e4
Commit
b97ea0e4
authored
Aug 20, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added JSFilter type
parent
b0ae61c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
3 deletions
+83
-3
js_pipe.go
ethpipe/js_pipe.go
+83
-3
No files found.
ethpipe/js_pipe.go
View file @
b97ea0e4
...
@@ -2,10 +2,13 @@ package ethpipe
...
@@ -2,10 +2,13 @@ package ethpipe
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"sync/atomic"
"sync/atomic"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethreact"
"github.com/ethereum/eth-go/ethstate"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
)
)
...
@@ -74,7 +77,8 @@ func (self *JSPipe) NumberToHuman(balance string) string {
...
@@ -74,7 +77,8 @@ func (self *JSPipe) NumberToHuman(balance string) string {
}
}
func
(
self
*
JSPipe
)
StorageAt
(
addr
,
storageAddr
string
)
string
{
func
(
self
*
JSPipe
)
StorageAt
(
addr
,
storageAddr
string
)
string
{
return
self
.
World
()
.
SafeGet
(
ethutil
.
Hex2Bytes
(
addr
))
.
Storage
(
ethutil
.
Hex2Bytes
(
storageAddr
))
.
Str
()
storage
:=
self
.
World
()
.
SafeGet
(
ethutil
.
Hex2Bytes
(
addr
))
.
Storage
(
ethutil
.
Hex2Bytes
(
storageAddr
))
return
storage
.
BigInt
()
.
String
()
}
}
func
(
self
*
JSPipe
)
TxCountAt
(
address
string
)
int
{
func
(
self
*
JSPipe
)
TxCountAt
(
address
string
)
int
{
...
@@ -186,10 +190,45 @@ func (self *JSPipe) CompileMutan(code string) string {
...
@@ -186,10 +190,45 @@ func (self *JSPipe) CompileMutan(code string) string {
return
ethutil
.
Bytes2Hex
(
data
)
return
ethutil
.
Bytes2Hex
(
data
)
}
}
func
(
self
*
JSPipe
)
Watch
(
object
map
[
string
]
interface
{})
*
JSFilter
{
return
NewJSFilterFromMap
(
object
,
self
.
Pipe
.
obj
)
/*} else if str, ok := object.(string); ok {
println("str")
return NewJSFilterFromString(str, self.Pipe.obj)
*/
}
func
(
self
*
JSPipe
)
Messages
(
object
map
[
string
]
interface
{})
string
{
func
(
self
*
JSPipe
)
Messages
(
object
map
[
string
]
interface
{})
string
{
filter
:=
ethchain
.
NewFilterFromMap
(
object
,
self
.
obj
)
filter
:=
self
.
Watch
(
object
)
defer
filter
.
Uninstall
()
return
filter
.
Messages
()
}
type
JSFilter
struct
{
eth
ethchain
.
EthManager
*
ethchain
.
Filter
quit
chan
bool
BlockCallback
func
(
*
ethchain
.
Block
)
MessageCallback
func
(
ethstate
.
Messages
)
}
func
NewJSFilterFromMap
(
object
map
[
string
]
interface
{},
eth
ethchain
.
EthManager
)
*
JSFilter
{
filter
:=
&
JSFilter
{
eth
,
ethchain
.
NewFilterFromMap
(
object
,
eth
),
make
(
chan
bool
),
nil
,
nil
}
go
filter
.
mainLoop
()
return
filter
}
messages
:=
filter
.
Find
()
func
NewJSFilterFromString
(
str
string
,
eth
ethchain
.
EthManager
)
*
JSFilter
{
return
nil
}
func
(
self
*
JSFilter
)
MessagesToJson
(
messages
ethstate
.
Messages
)
string
{
var
msgs
[]
JSMessage
var
msgs
[]
JSMessage
for
_
,
m
:=
range
messages
{
for
_
,
m
:=
range
messages
{
msgs
=
append
(
msgs
,
NewJSMessage
(
m
))
msgs
=
append
(
msgs
,
NewJSMessage
(
m
))
...
@@ -202,3 +241,44 @@ func (self *JSPipe) Messages(object map[string]interface{}) string {
...
@@ -202,3 +241,44 @@ func (self *JSPipe) Messages(object map[string]interface{}) string {
return
string
(
b
)
return
string
(
b
)
}
}
func
(
self
*
JSFilter
)
Messages
()
string
{
return
self
.
MessagesToJson
(
self
.
Find
())
}
func
(
self
*
JSFilter
)
mainLoop
()
{
blockChan
:=
make
(
chan
ethreact
.
Event
,
1
)
messageChan
:=
make
(
chan
ethreact
.
Event
,
1
)
// Subscribe to events
reactor
:=
self
.
eth
.
Reactor
()
reactor
.
Subscribe
(
"newBlock"
,
blockChan
)
reactor
.
Subscribe
(
"messages"
,
messageChan
)
out
:
for
{
select
{
case
<-
self
.
quit
:
break
out
case
block
:=
<-
blockChan
:
if
block
,
ok
:=
block
.
Resource
.
(
*
ethchain
.
Block
);
ok
{
if
self
.
BlockCallback
!=
nil
{
self
.
BlockCallback
(
block
)
}
}
case
msg
:=
<-
messageChan
:
if
messages
,
ok
:=
msg
.
Resource
.
(
ethstate
.
Messages
);
ok
{
if
self
.
MessageCallback
!=
nil
{
msgs
:=
self
.
FilterMessages
(
messages
)
self
.
MessageCallback
(
msgs
)
}
}
}
}
}
func
(
self
*
JSFilter
)
Changed
(
object
interface
{})
{
fmt
.
Printf
(
"%T
\n
"
,
object
)
}
func
(
self
*
JSFilter
)
Uninstall
()
{
self
.
quit
<-
true
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment