-
Notifications
You must be signed in to change notification settings - Fork 14
/
types.go
73 lines (51 loc) · 2.86 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
package storage
import (
"context"
"fmt"
"github.com/oasisprotocol/emerald-web3-gateway/db/model"
)
// ErrNoRoundsIndexed is the error returned by last indexed round when no rounds
// are indexed.
var ErrNoRoundsIndexed = fmt.Errorf("no rounds indexed")
type Storage interface {
// Insert inserts a record. On conflict the insert errors.
Insert(ctx context.Context, value interface{}) error
// InsertIfNotExists inserts a record if a record with same primary key does not exist.
InsertIfNotExists(ctx context.Context, value interface{}) error
// Upsert upserts a record.
Upsert(ctx context.Context, value interface{}) error
// Delete deletes all records with round less than the given round.
Delete(ctx context.Context, table interface{}, round uint64) error
// GetBlockRound returns block round by block hash.
GetBlockRound(ctx context.Context, hash string) (uint64, error)
// GetBlockHash returns block hash by block round.
GetBlockHash(ctx context.Context, round uint64) (string, error)
// GetLatestBlockHash returns the block hash of the latest indexed round.
GetLatestBlockHash(ctx context.Context) (string, error)
// GetLastIndexedRound query the last indexed round.
GetLastIndexedRound(ctx context.Context) (uint64, error)
// GetLastRetainedRound query the minimum round not pruned.
GetLastRetainedRound(ctx context.Context) (uint64, error)
// GetTransaction queries ethereum transaction by hash.
GetTransaction(ctx context.Context, hash string) (*model.Transaction, error)
// GetLatestBlockNumber returns the latest block round.
GetLatestBlockNumber(ctx context.Context) (uint64, error)
// GetBlockByHash returns the block for the given hash.
GetBlockByHash(ctx context.Context, hash string) (*model.Block, error)
// GetBlockByNumber returns the block for the given round.
GetBlockByNumber(ctx context.Context, round uint64) (*model.Block, error)
// GetBlockTransactionCountByNumber returns the transaction count of the block.
GetBlockTransactionCountByNumber(ctx context.Context, round uint64) (int, error)
// GetBlockTransactionCountByHash returns the transaction count of the block.
GetBlockTransactionCountByHash(ctx context.Context, hash string) (int, error)
// GetBlockTransaction returns the transaction of the block for the given index.
GetBlockTransaction(ctx context.Context, blockHash string, txIndex int) (*model.Transaction, error)
// GetTransactionReceipt returns the receipt of the transaction.
GetTransactionReceipt(ctx context.Context, txHash string) (*model.Receipt, error)
// GetLogs returns all logs between start and end rounds.
GetLogs(ctx context.Context, startRound, endRound uint64) ([]*model.Log, error)
// RunInTransaction runs a function in a transaction. If function
// returns an error transaction is rolled back, otherwise transaction
// is committed.
RunInTransaction(ctx context.Context, fn func(Storage) error) error
}