-
Notifications
You must be signed in to change notification settings - Fork 34
/
receipt_provider.go
63 lines (51 loc) · 1.56 KB
/
receipt_provider.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
package data
import (
"context"
"github.com/omni-network/omni/explorer/db/ent/receipt"
"github.com/omni-network/omni/explorer/graphql/resolvers"
"github.com/omni-network/omni/explorer/graphql/utils"
"github.com/omni-network/omni/lib/errors"
"github.com/omni-network/omni/lib/log"
"github.com/ethereum/go-ethereum/common/hexutil"
)
func (p Provider) XReceiptCount(ctx context.Context) (*hexutil.Big, bool, error) {
query, err := p.EntClient.Receipt.Query().Count(ctx)
if err != nil {
log.Error(ctx, "Graphql provider err", err)
return nil, false, err
}
hex, err := utils.Uint2Hex(uint64(query))
if err != nil {
return nil, false, errors.Wrap(err, "decoding block count")
}
return &hex, true, nil
}
func (p Provider) XReceipt(ctx context.Context, sourceChainID, destChainID, offset uint64) (*resolvers.XReceipt, bool, error) {
query, err := p.EntClient.Receipt.Query().
Where(
receipt.SourceChainID(sourceChainID),
receipt.DestChainID(destChainID),
receipt.StreamOffset(offset),
).
First(ctx)
if err != nil {
log.Error(ctx, "Receipt query", err)
return nil, false, err
}
block := query.QueryBlock().OnlyX(ctx)
messages := query.QueryMsgs().AllX(ctx)
res, err := EntReceiptToGraphQLXReceipt(ctx, query, block)
if err != nil {
return nil, false, errors.Wrap(err, "decoding message")
}
var msgs []resolvers.XMsg
for _, m := range messages {
msg, err := EntMsgToGraphQLXMsg(m)
if err != nil {
return nil, false, errors.Wrap(err, "decoding message")
}
msgs = append(msgs, *msg)
}
res.Messages = msgs
return res, true, nil
}