File tree 1 file changed +8
-2
lines changed
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -517,7 +517,12 @@ func (coins Coins) Empty() bool {
517
517
// AmountOf returns the amount of a denom from coins
518
518
func (coins Coins ) AmountOf (denom string ) Int {
519
519
mustValidateDenom (denom )
520
+ return coins .AmountOfNoDenomValidation (denom )
521
+ }
520
522
523
+ // AmountOfNoDenomValidation returns the amount of a denom from coins
524
+ // without validating the denomination.
525
+ func (coins Coins ) AmountOfNoDenomValidation (denom string ) Int {
521
526
switch len (coins ) {
522
527
case 0 :
523
528
return ZeroInt ()
@@ -530,15 +535,16 @@ func (coins Coins) AmountOf(denom string) Int {
530
535
return ZeroInt ()
531
536
532
537
default :
538
+ // Binary search the amount of coins remaining
533
539
midIdx := len (coins ) / 2 // 2:1, 3:1, 4:2
534
540
coin := coins [midIdx ]
535
541
switch {
536
542
case denom < coin .Denom :
537
- return coins [:midIdx ].AmountOf (denom )
543
+ return coins [:midIdx ].AmountOfNoDenomValidation (denom )
538
544
case denom == coin .Denom :
539
545
return coin .Amount
540
546
default :
541
- return coins [midIdx + 1 :].AmountOf (denom )
547
+ return coins [midIdx + 1 :].AmountOfNoDenomValidation (denom )
542
548
}
543
549
}
544
550
}
You can’t perform that action at this time.
0 commit comments