Skip to content

Commit

Permalink
Updates based on review.
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp committed Oct 6, 2021
1 parent b066eed commit a6b6ab0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
12 changes: 10 additions & 2 deletions client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,22 @@ func (c *coin) Value() uint64 {

var _ asset.Coin = (*coin)(nil)

// decodeCoinID decodes a coin id into a coin object. The coin id
// must contain an AmountCoinID.
func decodeCoinID(coinID []byte) (*coin, error) {
id, err := dexeth.DecodeAmountCoinID(coinID)
id, err := dexeth.DecodeCoinID(coinID)
if err != nil {
return nil, err
}

amountCoinID, ok := id.(*dexeth.AmountCoinID)
if !ok {
return nil,
fmt.Errorf("coinID is expected to be an amount coin id")
}

return &coin{
id: *id,
id: *amountCoinID,
}, nil
}

Expand Down
11 changes: 8 additions & 3 deletions server/asset/eth/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ func (c *AmountCoinID) Encode() []byte {

var _ CoinID = (*AmountCoinID)(nil)

// DecodeAmountCoinID decodes a byte slice into an AmountCoinID struct.
func DecodeAmountCoinID(coinID []byte) (*AmountCoinID, error) {
// decodeAmountCoinID decodes a byte slice into an AmountCoinID struct.
func decodeAmountCoinID(coinID []byte) (*AmountCoinID, error) {
if len(coinID) != amountCoinIDSize {
return nil, fmt.Errorf("DecodeAmountCoinID: length expected %v, got %v",
txCoinIDSize, len(coinID))
Expand All @@ -215,13 +215,18 @@ func DecodeAmountCoinID(coinID []byte) (*AmountCoinID, error) {
// DecodeCoinID decodes the coin id byte slice into an object implementing the
// CoinID interface.
func DecodeCoinID(coinID []byte) (CoinID, error) {
if len(coinID) < 2 {
return nil,
fmt.Errorf("DecodeCoinID: coinID length must be > 2, but got %v",
len(coinID))
}
flag := CoinIDFlag(binary.BigEndian.Uint16(coinID[:2]))
if flag == CIDTxID {
return decodeTxCoinID(coinID)
} else if flag == CIDSwap {
return decodeSwapCoinID(coinID)
} else if flag == CIDAmount {
return DecodeAmountCoinID(coinID)
return decodeAmountCoinID(coinID)
} else {
return nil, fmt.Errorf("DecodeCoinID: invalid coin id flag: %v", flag)
}
Expand Down

0 comments on commit a6b6ab0

Please sign in to comment.