forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
liquidity_pool_id.go
42 lines (33 loc) · 1.09 KB
/
liquidity_pool_id.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
//lint:file-ignore U1001 Ignore all unused code, staticcheck doesn't understand testify/suite
package txnbuild
import (
"fmt"
"github.com/stellar/go/support/errors"
"github.com/stellar/go/xdr"
)
// LiquidityPoolId represents the Stellar liquidity pool id.
type LiquidityPoolId [32]byte
func NewLiquidityPoolId(a, b Asset) (LiquidityPoolId, error) {
if b.LessThan(a) {
return LiquidityPoolId{}, fmt.Errorf("AssetA must be <= AssetB")
}
xdrAssetA, err := a.ToXDR()
if err != nil {
return LiquidityPoolId{}, errors.Wrap(err, "failed to build XDR AssetA ID")
}
xdrAssetB, err := b.ToXDR()
if err != nil {
return LiquidityPoolId{}, errors.Wrap(err, "failed to build XDR AssetB ID")
}
id, err := xdr.NewPoolId(xdrAssetA, xdrAssetB, xdr.LiquidityPoolFeeV18)
if err != nil {
return LiquidityPoolId{}, errors.Wrap(err, "failed to build XDR liquidity pool id")
}
return LiquidityPoolId(id), nil
}
func (lpi LiquidityPoolId) ToXDR() (xdr.PoolId, error) {
return xdr.PoolId(lpi), nil
}
func liquidityPoolIdFromXDR(poolId xdr.PoolId) (LiquidityPoolId, error) {
return LiquidityPoolId(poolId), nil
}