/
ledger_backend.go
80 lines (70 loc) · 3.11 KB
/
ledger_backend.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
79
80
package ledgerbackend
import (
"context"
"github.com/sanjayhashcash/go/xdr"
)
// LedgerBackend represents the interface to a ledger data store.
type LedgerBackend interface {
// GetLatestLedgerSequence returns the sequence of the latest ledger available
// in the backend.
GetLatestLedgerSequence(ctx context.Context) (sequence uint32, err error)
// GetLedger will block until the ledger is available.
GetLedger(ctx context.Context, sequence uint32) (xdr.LedgerCloseMeta, error)
// PrepareRange prepares the given range (including from and to) to be loaded.
// Some backends (like captive hcnet-core) need to initalize data to be
// able to stream ledgers. Blocks until the first ledger is available.
PrepareRange(ctx context.Context, ledgerRange Range) error
// IsPrepared returns true if a given ledgerRange is prepared.
IsPrepared(ctx context.Context, ledgerRange Range) (bool, error)
Close() error
}
// session is the interface needed to access a persistent database session.
// TODO can't use this until we add Close() to the existing db.Session object
type session interface {
GetRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) error
SelectRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) error
Close() error
}
// ledgerHeaderHistory is a helper struct used to unmarshall header fields from a hcnet-core DB.
type ledgerHeaderHistory struct {
Hash xdr.Hash `db:"ledgerhash"`
Header xdr.LedgerHeader `db:"data"`
}
// ledgerHeader holds a row of data from the hcnet-core `ledgerheaders` table.
type ledgerHeader struct {
LedgerHash string `db:"ledgerhash"`
PrevHash string `db:"prevhash"`
BucketListHash string `db:"bucketlisthash"`
CloseTime int64 `db:"closetime"`
LedgerSeq uint32 `db:"ledgerseq"`
Data xdr.LedgerHeader `db:"data"`
}
// txHistory holds a row of data from the hcnet-core `txhistory` table.
type txHistory struct {
TXID string `db:"txid"`
LedgerSeq uint32 `db:"ledgerseq"`
TXIndex uint32 `db:"txindex"`
TXBody xdr.TransactionEnvelope `db:"txbody"`
TXResult xdr.TransactionResultPair `db:"txresult"`
TXMeta xdr.TransactionMeta `db:"txmeta"`
}
// txFeeHistory holds a row of data from the hcnet-core `txfeehistory` table.
type txFeeHistory struct {
TXID string `db:"txid"`
LedgerSeq uint32 `db:"ledgerseq"`
TXIndex uint32 `db:"txindex"`
TXChanges xdr.LedgerEntryChanges `db:"txchanges"`
}
// scpHistory holds a row of data from the hcnet-core `scphistory` table.
// type scpHistory struct {
// NodeID string `db:"nodeid"`
// LedgerSeq uint32 `db:"ledgerseq"`
// Envelope string `db:"envelope"`
// }
// upgradeHistory holds a row of data from the hcnet-core `upgradehistory` table.
type upgradeHistory struct {
LedgerSeq uint32 `db:"ledgerseq"`
UpgradeIndex uint32 `db:"upgradeindex"`
Upgrade xdr.LedgerUpgrade `db:"upgrade"`
Changes xdr.LedgerEntryChanges `db:"changes"`
}