-
Notifications
You must be signed in to change notification settings - Fork 0
/
pvm_reader.go
50 lines (42 loc) · 1.42 KB
/
pvm_reader.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
// Copyright (C) 2022, Chain4Travel AG. All rights reserved.
//
// This file is a derived work, based on ava-labs code whose
// original notices appear below.
//
// It is distributed under the same license conditions as the
// original code from which it is derived.
//
// Much love to the original authors for their work.
// **********************************************************
// (c) 2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package djtx
import (
"context"
"github.com/lasthyphen/dijetsnodego/ids"
"github.com/lasthyphen/mages/cfg"
"github.com/lasthyphen/mages/models"
"github.com/lasthyphen/mages/services/indexes/params"
)
func (r *Reader) ListBlocks(ctx context.Context, params *params.ListBlocksParams) (*models.BlockList, error) {
dbRunner, err := r.conns.DB().NewSession("list_blocks", cfg.RequestTimeout)
if err != nil {
return nil, err
}
blocks := []*models.Block{}
_, err = params.Apply(dbRunner.
Select("id", "type", "parent_id", "chain_id", "created_at").
From("pvm_blocks")).
LoadContext(ctx, &blocks)
if err != nil {
return nil, err
}
return &models.BlockList{Blocks: blocks}, nil
}
func (r *Reader) GetBlock(ctx context.Context, id ids.ID) (*models.Block, error) {
list, err := r.ListBlocks(ctx, ¶ms.ListBlocksParams{ListParams: params.ListParams{ID: &id}})
if err != nil || len(list.Blocks) == 0 {
return nil, err
}
return list.Blocks[0], nil
}