forked from EOS-Nation/dfuse-leap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
78 lines (62 loc) · 1.91 KB
/
types.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package search
import (
"strings"
"github.com/dfuse-io/bstream"
pbcodec "github.com/dfuse-io/dfuse-eosio/pb/dfuse/eosio/codec/v1"
pbsearcheos "github.com/dfuse-io/dfuse-eosio/pb/dfuse/eosio/search/v1"
pbsearch "github.com/dfuse-io/pbgo/dfuse/search/v1"
"github.com/golang/protobuf/ptypes"
)
type SearchMatch struct {
TrxIDPrefix string `json:"prefix"` // ID prefix
ActionIndexes []uint16 `json:"acts"` // Action indexes within the transactions
BlockNumber uint64 `json:"blk"` // Current block for this trx
Index uint64 `json:"idx"` // Index of the matching transaction within a block (depends on order of sort)
}
func (m *SearchMatch) BlockNum() uint64 {
return m.BlockNumber
}
func (m *SearchMatch) GetIndex() uint64 {
return m.Index
}
func (m *SearchMatch) TransactionIDPrefix() string {
return m.TrxIDPrefix
}
func (m *SearchMatch) SetIndex(index uint64) {
m.Index = index
}
func (m *SearchMatch) FillProtoSpecific(match *pbsearch.SearchMatch, block *bstream.Block) (err error) {
eosMatch := &pbsearcheos.Match{}
if block != nil {
eosMatch.Block = m.buildBlockTrxPayload(block)
if m.TrxIDPrefix == "" {
match.ChainSpecific, err = ptypes.MarshalAny(eosMatch)
return err
}
}
eosMatch.ActionIndexes = uint16to32s(m.ActionIndexes)
match.ChainSpecific, err = ptypes.MarshalAny(eosMatch)
return err
}
func (m *SearchMatch) buildBlockTrxPayload(block *bstream.Block) *pbsearcheos.BlockTrxPayload {
blk := block.ToNative().(*pbcodec.Block)
if m.TrxIDPrefix == "" {
return &pbsearcheos.BlockTrxPayload{
BlockHeader: blk.Header,
BlockID: blk.ID(),
}
}
for _, trx := range blk.TransactionTraces() {
fullTrxID := trx.Id
if !strings.HasPrefix(fullTrxID, m.TrxIDPrefix) {
continue
}
out := &pbsearcheos.BlockTrxPayload{}
out.BlockHeader = blk.Header
out.BlockID = blk.Id
out.Trace = trx
return out
}
// FIXME (MATT): Is this even possible?
return nil
}