-
Notifications
You must be signed in to change notification settings - Fork 0
/
ledger_entry.go
43 lines (38 loc) · 933 Bytes
/
ledger_entry.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
package xdr
import "fmt"
// LedgerKey implements the `Keyer` interface
func (entry *LedgerEntry) LedgerKey() LedgerKey {
var body interface{}
switch entry.Data.Type {
case LedgerEntryTypeAccount:
account := entry.Data.MustAccount()
body = LedgerKeyAccount{
AccountId: account.AccountId,
}
case LedgerEntryTypeData:
data := entry.Data.MustData()
body = LedgerKeyData{
AccountId: data.AccountId,
DataName: data.DataName,
}
case LedgerEntryTypeOffer:
offer := entry.Data.MustOffer()
body = LedgerKeyOffer{
SellerId: offer.SellerId,
OfferId: offer.OfferId,
}
case LedgerEntryTypeTrustline:
tline := entry.Data.MustTrustLine()
body = LedgerKeyTrustLine{
AccountId: tline.AccountId,
Asset: tline.Asset,
}
default:
panic(fmt.Errorf("Unknown entry type: %v", entry.Data.Type))
}
ret, err := NewLedgerKey(entry.Data.Type, body)
if err != nil {
panic(err)
}
return ret
}