-
Notifications
You must be signed in to change notification settings - Fork 5
/
intrinsics.go
57 lines (45 loc) · 1.27 KB
/
intrinsics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package subgraph
import (
"fmt"
"time"
"github.com/streamingfast/sparkle/entity"
)
// Intrinsics is per subgraph and should be unique for each subgraph. The underlying implementation
// should know about its surrounding context to know when to close when at which block it's currently
// at.
//
// It's expected that the implementation will be called by one go routine at a time.
type Intrinsics interface {
/// Entities
Save(entity entity.Interface) error
Load(entity entity.Interface) error
LoadAllDistinct(model entity.Interface, blockNum uint64) ([]entity.Interface, error)
Remove(entity entity.Interface) error
/// Block
// Block returns the current block being processed by your subgraph handler.
Block() BlockRef
/// Reproc
Step() int
StepBelow(step int) bool
StepAbove(step int) bool
/// JSON-RPC
RPC(calls []*RPCCall) ([]*RPCResponse, error)
}
type BlockRef interface {
ID() string
Number() uint64
Timestamp() time.Time
}
type RPCCall struct {
ToAddr string
MethodSignature string // ex: "name() (string)"
}
func (c *RPCCall) ToString() string {
return fmt.Sprintf("%s:%s", c.ToAddr, c.MethodSignature)
}
type RPCResponse struct {
Decoded []interface{}
Raw string
DecodingError error
CallError error // always deterministic
}