/
main.go
72 lines (65 loc) · 2.69 KB
/
main.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
package io
import (
"github.com/diamnet/go/support/errors"
"github.com/diamnet/go/xdr"
)
var ErrNotFound = errors.New("not found")
// StateReader reads state data from history archive buckets for a single
// checkpoint ledger / HAS.
type StateReader interface {
// GetSequence returns the checkpoint ledger sequence this reader is
// reading.
GetSequence() uint32
// Read should return next ledger entry. If there are no more
// entries it should return `io.EOF` error.
Read() (xdr.LedgerEntryChange, error)
// Close should be called when reading is finished. This is especially
// helpful when there are still some entries available so reader can stop
// streaming them.
Close() error
}
// StateWriter interface placeholder
type StateWriter interface {
// Write is used to pass ledger entry change to the next processor. It can return
// `ErrClosedPipe` when the pipe between processors has been closed meaning
// that next processor does not need more data. In such situation the current
// processor can terminate as sending more entries to a `StateWriter`
// does not make sense (will not be read).
Write(xdr.LedgerEntryChange) error
// Close should be called when there are no more entries
// to write.
Close() error
}
// LedgerReader provides convenient, streaming access to the transactions within a ledger.
type LedgerReader interface {
GetSequence() uint32
GetHeader() xdr.LedgerHeaderHistoryEntry
// Read should return the next transaction. If there are no more
// transactions it should return `io.EOF` error.
Read() (LedgerTransaction, error)
// Close should be called when reading is finished. This is especially
// helpful when there are still some transactions available so reader can stop
// streaming them.
Close() error
}
// LedgerWriter provides convenient, streaming access to the transactions within a ledger.
type LedgerWriter interface {
// Write is used to pass a transaction to the next processor. It can return
// `io.ErrClosedPipe` when the pipe between processors has been closed meaning
// that next processor does not need more data. In such situation the current
// processor can terminate as sending more transactions to a `LedgerWriter`
// does not make sense (will not be read).
Write(LedgerTransaction) error
// Close should be called when reading is finished. This is especially
// helpful when there are still some transactions available so the reader can stop
// streaming them.
Close() error
}
// LedgerTransaction represents the data for a single transaction within a ledger.
type LedgerTransaction struct {
Index uint32
Envelope xdr.TransactionEnvelope
Result xdr.TransactionResultPair
Meta xdr.TransactionMeta
FeeChanges xdr.LedgerEntryChanges
}