Commit Graph

79 Commits

Author SHA1 Message Date
mergify[bot] ad4ad43f02
fix: decrement types.Dec max length to keep decimal bits in DecimalPrecisionBits (backport #11772) (#11805) 2022-04-27 14:16:29 -04:00
mergify[bot] 147720c8d3
feat: min and max operators on coins (backport #11200) (#11249)
* feat: min and max operators on coins (#11200)

## Description

Closes: #10995

Adds `Min()` and `Max()` operations on `sdk.Coins` for per-denom minimum and maximum.

Replaced an example of manual low-level construction of `Coins` with higher-level operators.
Upcoming enhancements to vesting accounts make heavy use of this pattern.

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [X] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [X] added `!` to the type prefix if API or client breaking change
- [X] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [X] provided a link to the relevant issue or specification
- [X] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [X] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [X] added a changelog entry to `CHANGELOG.md`
- [X] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [X] updated the relevant documentation or specification
- [X] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)

(cherry picked from commit afbb0bd194)

# Conflicts:
#	CHANGELOG.md

* fix conflicts

Co-authored-by: Jim Larson <32469398+JimLarson@users.noreply.github.com>
Co-authored-by: marbar3778 <marbar3778@yahoo.com>
2022-02-24 00:51:55 +01:00
mergify[bot] f11689b9de
fix: null guard for tx fee amounts (backport #10327) (#10342)
* fix: null guard for tx fee amounts (#10327)

## Description

It is possible to submit a TX with a fees object containing a Coin with a nil amount. This results in a rather cryptic redacted panic response when the basic validation checks fee Coins for negative amounts.

This PR adds an additional check for nil to provide a friendlier error message.

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification (note: No issue exists)
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) (note: First PR against the SDK so please comment with what needs to be done)
- [x] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)

(cherry picked from commit 96e162b8a3)

# Conflicts:
#	CHANGELOG.md

* solve conflicts

* move sections

Co-authored-by: Alex Megalokonomos <alex.megalokonomos@tendermint.com>
Co-authored-by: marbar3778 <marbar3778@yahoo.com>
2021-10-12 12:47:54 +02:00
Robert Zaremba 68d461052b
add sorted check for the coins sub/add fun parameter (#9240)
* add sorted check for the coins sub/add fun parameter

* adding internal tests

* fix tests

* docs update

* add self sorted check

* add unit test for self sorted check

* adding a comment

* review updates

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-05-05 15:55:28 +00:00
Robert Zaremba be4a965599
codec: Rename codec and marshaler interfaces (#9226)
* codec: Rename codec and marshaler interfaces, ref: 8413

* codec: remove BinaryBare

* changelog update

* Update comments and documentation

* adding doc string comments

* Update CHANGELOG.md

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update codec/codec.go

Co-authored-by: Marko <marbar3778@yahoo.com>

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
Co-authored-by: Marko <marbar3778@yahoo.com>
2021-04-29 10:46:22 +00:00
Hanjun Kim cf7b03efcd
add AddAmount/SubAmount methods to sdk.Coin (#9091)
Co-authored-by: Marko <marbar3778@yahoo.com>
Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-04-13 15:01:21 +00:00
Emmanuel T Odeke 6344d626db
types/Coin: compile and reuse Regexps to reduce massive RAM+CPU burn (#7989)
* types/Coin: compile and reuse Regexps to reduce massive RAM+CPU burn

Fixes a resource (CPU+RAM) burn from recompiling Regexps which would
consume 1.2+MiB of RAM and 1.1ms per ParseCoin invocation, which means
that 1,000 invocations would consume 1.2GiB of RAM and >1second.

With the change, ParseCoin now takes 3.2us down from 1.1ms, with
dramatic results:

name         old time/op    new time/op    delta
ParseCoin-8    1.04ms ± 4%    0.00ms ± 1%  -99.69%  (p=0.000 n=9+10)

name         old alloc/op   new alloc/op   delta
ParseCoin-8    1.20MB ± 0%    0.00MB ± 0%  -99.94%  (p=0.000 n=10+10)

name         old allocs/op  new allocs/op  delta
ParseCoin-8     17.8k ± 0%      0.0k ± 0%  -99.89%  (p=0.000 n=10+10)

Fixes #7986.

* replace the CoinDenomRegex variable with SetCoinDenomRegex() (#7998)

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
2020-11-20 19:37:45 +00:00
yihuang 54201d11e6
cli: convert coins to smallest unit registered (#7777)
* cli: convert coins to smallest unit registered

fixes: #7623

- test order of decimal operations
- support both int and decimal coins, truncate when normalizing to
  base unit

* Update types/coin_test.go

* Update types/coin_test.go

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Amaury <amaury.martiny@protonmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-11-16 11:34:54 +00:00
billy rennekamp 3e6089dc0e
R4R: Add custom validation for denom (#6755)
Allow ValidateDenom to be customized per application.

closes: #6744
2020-10-06 18:06:41 +01:00
Alessio Treglia ddaa3c5176
types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00
Alessio Treglia 8601dcdbb7
types: tests -> test suites migration (#7400)
Ref #7362
2020-09-28 12:46:49 +02:00
Alessio Treglia 04ff40a8df
types: start grouping tests in test suites (#7395)
Ref #7362
2020-09-27 23:51:14 +02:00
dauTT 30f9862b4b
Remove zero coins from ParseCoins and ParseDecCoins (#7348)
* Remove zero coins from ParseCoins and ParseDecCoins

* Implement requested changes

* Update types/coin_test.go

* Revert

* Align the behaviour of NewCoins and ParseCoins (respectively NewDecCoins and ParseDecCoins)

* Amend comments

* Update types/dec_coin.go

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Alessio Treglia <quadrispro@ubuntu.com>
Co-authored-by: SaReN <sahithnarahari@gmail.com>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
2020-09-25 08:31:31 +00:00
Anil Kumar Kammari 64b6bb5270
rename RegisterCodec to RegisterLegacyAminoCodec (#7243)
* rename RegisterCodec to RegisterLegacyAminoCodec

* Add changelog

* gofmt

* rename codec.New() to codec.NewLegacyAmino()

* Add change log

* Update CHANGELOG.md

Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>

* Fix

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
2020-09-07 14:47:12 +00:00
Federico Kunze 3022fe9044
x/ibc-transfer: ADR001 source tracing implementation (#6871)
* x/ibc-transfer: ADR001 source tracing implementation

* gRPC proto file

* validation

* fix validation

* import export genesis

* relay.go updates

* gRPC service methods

* client CLI

* update implementation

* build

* trace test

* fix CLI tx args

* genesis import/export tests

* update comments

* update proto files

* GRPC tests

* remove field from packet

* fix coin validation bug

* more validations

* update comments

* minor refactor

* update relay.go

* try fix test

* minor updates

* fix tests

* fix test

* ADR updates and comments

* build

* Apply suggestions from code review

Co-authored-by: Aditya <adityasripal@gmail.com>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* address a few comments from review

* gRPC annotations

* update proto files

* Apply suggestions from code review

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* address comments

* docs and changelog

* sort traces

* final changes to ADR

* client support for full path denom prefixes

* address @AdityaSripal comments

* address TODO

* increase test timeouts

Co-authored-by: Aditya <adityasripal@gmail.com>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
2020-08-14 17:46:26 -04:00
Federico Kunze 1b08e1032c
types: update coin regex (#7027)
* types: update coin regex

* more tests

* fix test case

* increase coverage

* changelog

* fix tests

* support unicode letters and numbers

* remove ToUpper

* Update types/coin.go

Co-authored-by: Aaron Craelius <aaron@regen.network>

* Validate function

* fix ICS20 test

* table tests and revert unicodes

* add test case

* add test cases and comment

Co-authored-by: Aaron Craelius <aaron@regen.network>
2020-08-14 09:09:53 +00:00
Ira Miller 282afcdb12
Fix for 6786 removeZeroCoins mutates original slice (#6811)
* added test cases to show errors identified in 6786

* mods to fix remove zero coin mutation in slice

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-07-28 10:17:58 +00:00
Jonathan Gimeno c44ca8ae34
add string test for coin and coins (#6547)
Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
2020-06-30 14:11:29 -04:00
Alexander Bezobchuk 26d6e49d6a
Merge PR #5491: Protobuf Introduction + Types 2020-01-24 10:32:00 -05:00
Ferenc Fabian 066dd1114f Merge PR #5449: Add New constructor for the DecCoin 2020-01-03 15:44:53 -05:00
Marko b9490f2d93 Merge PR #5203: Add more linters 2019-10-17 09:47:35 -04:00
Federico Kunze e85a734a57 update x/genaccounts to match module spec (#4759) 2019-07-22 16:26:42 +01:00
colin axner 314af42d92 Reintroduce Coin.IsValid() (#4558)
Closes #4556
2019-06-18 18:02:31 +02:00
Alexander Bezobchuk dc84c99dee Revert "Generalize auth/types.StdSignature (#4507)" (#4512)
This reverts commit a32d5a46d7.
2019-06-08 11:04:52 +01:00
Alessio Treglia a32d5a46d7
Generalize auth/types.StdSignature (#4507)
New Signature interface available in the top level types package.
auth.StdSignature implements such interface. User defined auth
module can now define their own custom signature types.

Work carried out in the context of the following issues:
- #4488
- #4487
2019-06-07 14:21:35 +01:00
Federico Kunze 9c65e47329 Merge PR #4485: rename expected pkg to exported
* rename expected pkg to exported

* rename pkg
2019-06-05 13:42:25 -04:00
Alexander Bezobchuk 6ec9b26cef
Merge PR #4454: Implement MarshalJSON for Coins Type 2019-05-31 11:16:08 -04:00
Alessio Treglia 04ed12dd2a Merge PR #4303: Fix coins findDup() 2019-05-08 09:51:30 -04:00
Alexander Bezobchuk 1bd70a238d
Merge PR #4281: Fix addGenesisAccount 2019-05-07 13:10:35 -04:00
Frank Yang 7e53da86ee Merge PR #3884: steak to stake 2019-03-14 10:32:46 -04:00
Alessio Treglia 7af11ece92 Merge PR #3864: Make IsAllGTE() more consistent
* Make IsAllGTE() more consistent

Co-Authored-By: alessio <quadrispro@ubuntu.com>
2019-03-12 19:13:36 +01:00
Alessio Treglia 862cc436f3 Fix tests 2019-03-08 01:09:26 +00:00
Alessio Treglia 714168f473
Merge branch 'develop' into sunny/coins-AllGT-test 2019-03-08 01:58:24 +01:00
Alessio Treglia fbd79d0cad Merge PR #3818: Introduce sdk.NewCoins 2019-03-07 16:55:08 -08:00
Sunny Aggarwal 9ffe64dc1e failing test 2019-03-07 09:02:40 +01:00
frog power 4000 a814e5ce66
Merge PR #3679: Consistent Operators
* Minus->Sub Plus->Add Div->Quo

* pending

* Update PENDING.md

Co-Authored-By: rigelrozanski <rigel.rozanski@gmail.com>

* fix

* typo
2019-02-21 12:35:55 -05:00
Alexander Bezobchuk 26c13b28cd Merge PR #3607: Reconcile DecCoin/s API with Coin/s API 2019-02-15 16:33:23 +01:00
Alexander Bezobchuk 2216f4716e Merge PR #3625: Fix Fee Comparison 2019-02-12 16:22:04 +01:00
Alexander Bezobchuk 7bc837aa06 Merge PR #3555: Reintroduce Fees OR Semantics 2019-02-07 18:14:54 -08:00
Alexander Bezobchuk 36d1736a08 Refactor Gas/Fee Model (#3258) 2019-01-18 08:45:20 -08:00
Alexander Bezobchuk 03bdd3f870 Fix IsAnyGTE (#3265) 2019-01-09 12:31:03 -08:00
Alessio Treglia 1040e3a8f5 Increase CLI test coverage (#3254) 2019-01-08 08:43:36 -08:00
Zaki Manian ed2b6bd9a7 Multiple fees in min fees to OR instead of AND (#3239) 2019-01-08 08:21:54 -08:00
Dev Ojha 67a1e47c6e Fix is_valid bug (#3211) 2019-01-02 11:14:12 -08:00
Christopher Goes 5ca8c5bb83
Merge PR #3207: Fix token printing bug
* Add IsPositive, case check on coins[0]
* Link to correct PR
* Add testcase
2019-01-02 19:17:27 +01:00
Alessio Treglia 500fa2b694 Make coins denoms case insensitive (#3092) 2018-12-18 11:14:11 -08:00
Alexander Bezobchuk 41fc538ac7 Add Safety Measures to Coin/Coins (#2797) 2018-11-20 01:22:35 -08:00
Alessio Treglia 70826495b8 Merge PR #2752: Don't hardcode bondable denom 2018-11-12 19:54:18 +01:00
Jae Kwon 2a3d1f1e87
Fix coins.IsLT() impl (#2686)
* Fix coins.IsLT() impl
* Fix coin.IsLT() impl
* Coins.IsLT -> Coins.IsAllLT etc
2018-11-07 00:14:48 -08:00
Christopher Goes 17983460b8
Merge PR #2219: Update to Tendermint 0.24 (except NextValSet offsets) 2018-10-03 17:48:23 +02:00