/
claim_atom.go
88 lines (80 loc) · 2.24 KB
/
claim_atom.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
81
82
83
84
85
86
87
88
package xdr
import (
"fmt"
"github.com/stellar/go/support/errors"
)
func (a ClaimAtom) OfferId() Int64 {
switch a.Type {
case ClaimAtomTypeClaimAtomTypeV0:
return a.V0.OfferId
case ClaimAtomTypeClaimAtomTypeOrderBook:
return a.OrderBook.OfferId
case ClaimAtomTypeClaimAtomTypeLiquidityPool:
panic(errors.New("liquidity pools don't have offers"))
default:
panic(fmt.Errorf("Unknown ClaimAtom type: %v", a.Type))
}
}
func (a ClaimAtom) SellerId() AccountId {
switch a.Type {
case ClaimAtomTypeClaimAtomTypeV0:
return AccountId{
Type: PublicKeyTypePublicKeyTypeEd25519,
Ed25519: &a.V0.SellerEd25519,
}
case ClaimAtomTypeClaimAtomTypeOrderBook:
return a.OrderBook.SellerId
case ClaimAtomTypeClaimAtomTypeLiquidityPool:
panic(errors.New("liquidity pools don't have a seller"))
default:
panic(fmt.Errorf("Unknown ClaimAtom type: %v", a.Type))
}
}
func (a ClaimAtom) AssetBought() Asset {
switch a.Type {
case ClaimAtomTypeClaimAtomTypeV0:
return a.V0.AssetBought
case ClaimAtomTypeClaimAtomTypeOrderBook:
return a.OrderBook.AssetBought
case ClaimAtomTypeClaimAtomTypeLiquidityPool:
return a.LiquidityPool.AssetBought
default:
panic(fmt.Errorf("Unknown ClaimAtom type: %v", a.Type))
}
}
func (a ClaimAtom) AmountBought() Int64 {
switch a.Type {
case ClaimAtomTypeClaimAtomTypeV0:
return a.V0.AmountBought
case ClaimAtomTypeClaimAtomTypeOrderBook:
return a.OrderBook.AmountBought
case ClaimAtomTypeClaimAtomTypeLiquidityPool:
return a.LiquidityPool.AmountBought
default:
panic(fmt.Errorf("Unknown ClaimAtom type: %v", a.Type))
}
}
func (a ClaimAtom) AssetSold() Asset {
switch a.Type {
case ClaimAtomTypeClaimAtomTypeV0:
return a.V0.AssetSold
case ClaimAtomTypeClaimAtomTypeOrderBook:
return a.OrderBook.AssetSold
case ClaimAtomTypeClaimAtomTypeLiquidityPool:
return a.LiquidityPool.AssetSold
default:
panic(fmt.Errorf("Unknown ClaimAtom type: %v", a.Type))
}
}
func (a ClaimAtom) AmountSold() Int64 {
switch a.Type {
case ClaimAtomTypeClaimAtomTypeV0:
return a.V0.AmountSold
case ClaimAtomTypeClaimAtomTypeOrderBook:
return a.OrderBook.AmountSold
case ClaimAtomTypeClaimAtomTypeLiquidityPool:
return a.LiquidityPool.AmountSold
default:
panic(fmt.Errorf("Unknown ClaimAtom type: %v", a.Type))
}
}