forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis_ledger_state_reader.go
59 lines (48 loc) · 1.33 KB
/
genesis_ledger_state_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
51
52
53
54
55
56
57
58
59
package io
import (
"io"
"sync"
"github.com/stellar/go/amount"
"github.com/stellar/go/keypair"
"github.com/stellar/go/xdr"
)
// GenesisLedgerStateReader is a streaming ledger entries for genesis ledger
// (ledgerseq = 1) for of the network with the given passphrase.
type GenesisLedgerStateReader struct {
NetworkPassphrase string
mutex sync.Mutex
done bool
}
// Ensure GenesisLedgerStateReader implements ChangeReader
var _ ChangeReader = &GenesisLedgerStateReader{}
// Read returns a new ledger entry change on each call, returning io.EOF when the stream ends.
func (r *GenesisLedgerStateReader) Read() (Change, error) {
r.mutex.Lock()
defer r.mutex.Unlock()
if r.done {
return Change{}, io.EOF
}
masterKeyPair := keypair.Master(r.NetworkPassphrase)
masterAccountEntry := xdr.LedgerEntry{
LastModifiedLedgerSeq: 1,
Data: xdr.LedgerEntryData{
Type: xdr.LedgerEntryTypeAccount,
Account: &xdr.AccountEntry{
AccountId: xdr.MustAddress(masterKeyPair.Address()),
// 100B
Balance: amount.MustParse("100000000000"),
SeqNum: 0,
Thresholds: xdr.Thresholds{1, 0, 0, 0},
},
},
}
r.done = true
return Change{
Type: masterAccountEntry.Data.Type,
Post: &masterAccountEntry,
}, nil
}
// Close should be called when reading is finished.
func (r *GenesisLedgerStateReader) Close() error {
return nil
}