-
Notifications
You must be signed in to change notification settings - Fork 499
/
history_archive_backend.go
51 lines (41 loc) · 1.22 KB
/
history_archive_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
package ledgerbackend
import (
"context"
"fmt"
"github.com/stellar/go/metaarchive"
"github.com/stellar/go/xdr"
)
type HistoryArchiveBackend struct {
metaArchive metaarchive.MetaArchive
}
func NewHistoryArchiveBackend(metaArchive metaarchive.MetaArchive) *HistoryArchiveBackend {
return &HistoryArchiveBackend{
metaArchive: metaArchive,
}
}
func (b *HistoryArchiveBackend) GetLatestLedgerSequence(ctx context.Context) (uint32, error) {
return b.metaArchive.GetLatestLedgerSequence(ctx)
}
func (b *HistoryArchiveBackend) PrepareRange(ctx context.Context, ledgerRange Range) error {
// Noop
return nil
}
func (b *HistoryArchiveBackend) IsPrepared(ctx context.Context, ledgerRange Range) (bool, error) {
// Noop
return true, nil
}
func (b *HistoryArchiveBackend) GetLedger(ctx context.Context, sequence uint32) (xdr.LedgerCloseMeta, error) {
serializedLedger, err := b.metaArchive.GetLedger(ctx, sequence)
if err != nil {
return xdr.LedgerCloseMeta{}, err
}
output, isV0 := serializedLedger.GetV0()
if !isV0 {
return xdr.LedgerCloseMeta{}, fmt.Errorf("unexpected serialized ledger version number (0x%x)", serializedLedger.V)
}
return output, nil
}
func (b *HistoryArchiveBackend) Close() error {
// Noop
return nil
}