Merge PR #3555: Reintroduce Fees OR Semantics
This commit is contained in:
committed by
Jack Zampolin
parent
685bfca1d4
commit
7bc837aa06
@@ -299,6 +299,26 @@ func (coins Coins) IsAllLTE(coinsB Coins) bool {
|
||||
return coinsB.IsAllGTE(coins)
|
||||
}
|
||||
|
||||
// IsAnyGTE returns true iff coins contains at least one denom that is present
|
||||
// at a greater or equal amount in coinsB; it returns false otherwise.
|
||||
//
|
||||
// NOTE: IsAnyGTE operates under the invariant that both coin sets are sorted
|
||||
// by denominations and there exists no zero coins.
|
||||
func (coins Coins) IsAnyGTE(coinsB Coins) bool {
|
||||
if len(coinsB) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, coin := range coins {
|
||||
amt := coinsB.AmountOf(coin.Denom)
|
||||
if coin.Amount.GTE(amt) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// IsZero returns true if there are no coins or all coins are zero.
|
||||
func (coins Coins) IsZero() bool {
|
||||
for _, coin := range coins {
|
||||
|
||||
@@ -508,3 +508,22 @@ func TestAmountOf(t *testing.T) {
|
||||
|
||||
assert.Panics(t, func() { cases[0].coins.AmountOf("Invalid") })
|
||||
}
|
||||
|
||||
func TestCoinsIsAnyGTE(t *testing.T) {
|
||||
one := NewInt(1)
|
||||
two := NewInt(2)
|
||||
|
||||
assert.False(t, Coins{}.IsAnyGTE(Coins{}))
|
||||
assert.False(t, Coins{{"a", one}}.IsAnyGTE(Coins{}))
|
||||
assert.False(t, Coins{}.IsAnyGTE(Coins{{"a", one}}))
|
||||
assert.False(t, Coins{{"a", one}}.IsAnyGTE(Coins{{"a", two}}))
|
||||
assert.True(t, Coins{{"a", one}, {"b", two}}.IsAnyGTE(Coins{{"a", two}, {"b", one}}))
|
||||
assert.True(t, Coins{{"a", one}}.IsAnyGTE(Coins{{"a", one}}))
|
||||
assert.True(t, Coins{{"a", two}}.IsAnyGTE(Coins{{"a", one}}))
|
||||
assert.True(t, Coins{{"a", one}}.IsAnyGTE(Coins{{"a", one}, {"b", two}}))
|
||||
assert.True(t, Coins{{"b", two}}.IsAnyGTE(Coins{{"a", one}, {"b", two}}))
|
||||
assert.False(t, Coins{{"b", one}}.IsAnyGTE(Coins{{"a", one}, {"b", two}}))
|
||||
assert.True(t, Coins{{"a", one}, {"b", two}}.IsAnyGTE(Coins{{"a", one}, {"b", one}}))
|
||||
assert.True(t, Coins{{"a", one}, {"b", one}}.IsAnyGTE(Coins{{"a", one}, {"b", two}}))
|
||||
assert.True(t, Coins{{"x", one}, {"y", one}}.IsAnyGTE(Coins{{"b", one}, {"c", one}, {"y", one}, {"z", one}}))
|
||||
}
|
||||
|
||||
+3
-1
@@ -2,6 +2,7 @@ package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@@ -375,7 +376,8 @@ func ParseDecCoins(coinsStr string) (coins DecCoins, err error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
coinStrs := strings.Split(coinsStr, ",")
|
||||
splitRe := regexp.MustCompile(",|;")
|
||||
coinStrs := splitRe.Split(coinsStr, -1)
|
||||
for _, coinStr := range coinStrs {
|
||||
coin, err := ParseDecCoin(coinStr)
|
||||
if err != nil {
|
||||
|
||||
@@ -16,6 +16,8 @@ func equal(i *big.Int, i2 *big.Int) bool { return i.Cmp(i2) == 0 }
|
||||
|
||||
func gt(i *big.Int, i2 *big.Int) bool { return i.Cmp(i2) == 1 }
|
||||
|
||||
func gte(i *big.Int, i2 *big.Int) bool { return i.Cmp(i2) >= 0 }
|
||||
|
||||
func lt(i *big.Int, i2 *big.Int) bool { return i.Cmp(i2) == -1 }
|
||||
|
||||
func lte(i *big.Int, i2 *big.Int) bool { return i.Cmp(i2) <= 0 }
|
||||
@@ -188,6 +190,12 @@ func (i Int) GT(i2 Int) bool {
|
||||
return gt(i.i, i2.i)
|
||||
}
|
||||
|
||||
// GTE returns true if receiver Int is greater than or equal to the parameter
|
||||
// Int.
|
||||
func (i Int) GTE(i2 Int) bool {
|
||||
return gte(i.i, i2.i)
|
||||
}
|
||||
|
||||
// LT returns true if first Int is lesser than second
|
||||
func (i Int) LT(i2 Int) bool {
|
||||
return lt(i.i, i2.i)
|
||||
|
||||
Reference in New Issue
Block a user