good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
b97ea0e4
Commit
b97ea0e4
authored
10 years ago
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
Added JSFilter type
parent
b0ae61c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ethpipe/js_pipe.go
+83
-3
83 additions, 3 deletions
ethpipe/js_pipe.go
with
83 additions
and
3 deletions
ethpipe/js_pipe.go
+
83
−
3
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
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment