From e6184f25ee20f50c1374c9b15187d142cb02514d Mon Sep 17 00:00:00 2001 From: MD Aleem <72057206+aleem1314@users.noreply.github.com> Date: Thu, 27 Oct 2022 00:55:32 +0530 Subject: [PATCH 1/7] build: set up command completions for goreleaser (#1563) Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com> --- .gitignore | 2 ++ .goreleaser.yml | 30 ++++++++++++++++++++++++++---- scripts/completions.sh | 9 +++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100755 scripts/completions.sh diff --git a/.gitignore b/.gitignore index 113212fbcf..7a3e7b013a 100644 --- a/.gitignore +++ b/.gitignore @@ -199,3 +199,5 @@ dist/ # Data - ideally these don't exist .localnet + +completions diff --git a/.goreleaser.yml b/.goreleaser.yml index 12d1ca6051..6edebe94e4 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,5 +1,9 @@ project_name: regen-ledger +before: + hooks: + - ./scripts/completions.sh + env: - GO111MODULE=on @@ -126,7 +130,9 @@ archives: wrap_in_directory: true format: zip files: - - none* + - README.md + - LICENSE + - completions/* brews: - name: regen-ledger @@ -143,6 +149,9 @@ brews: system "#{bin}/regen --version" install: | bin.install "regen" + bash_completion.install "completions/regen.bash" => "regen" + zsh_completion.install "completions/regen.zsh" => "_regen" + fish_completion.install "completions/regen.fish" nfpms: - maintainer: regen-network @@ -150,9 +159,22 @@ nfpms: homepage: "https://www.regen.network/" license: Apache2.0 formats: - - deb - - rpm - - apk + - deb + - rpm + - apk + contents: + - src: ./completions/regen.bash + dst: /usr/share/bash-completion/completions/regen + file_info: + mode: 0644 + - src: ./completions/regen.fish + dst: /usr/share/fish/vendor_completions.d/regen.fish + file_info: + mode: 0644 + - src: ./completions/regen.zsh + dst: /usr/share/zsh/vendor-completions/_regen + file_info: + mode: 0644 release: github: diff --git a/scripts/completions.sh b/scripts/completions.sh new file mode 100755 index 0000000000..c8c2f7511d --- /dev/null +++ b/scripts/completions.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e +rm -rf completions +mkdir completions + +for sh in bash zsh fish; do + go run cmd/regen/main.go completion "$sh" >"completions/regen.$sh" +done From ec3729ad7eff8ce4055ca16425e58d2f71a96f5c Mon Sep 17 00:00:00 2001 From: MD Aleem <72057206+aleem1314@users.noreply.github.com> Date: Thu, 27 Oct 2022 08:17:03 +0530 Subject: [PATCH 2/7] build: add replace directive for confio/ics23/go (#1578) Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com> --- go.mod | 2 ++ go.sum | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 3afd8f16e5..987d3a7512 100644 --- a/go.mod +++ b/go.mod @@ -180,3 +180,5 @@ replace github.com/regen-network/regen-ledger/api => ./api // Fix upstream GHSA-h395-qcrw-5vmq vulnerability. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 replace github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0 + +replace github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 diff --git a/go.sum b/go.sum index 269585e3b9..1265a21f47 100644 --- a/go.sum +++ b/go.sum @@ -220,8 +220,6 @@ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE github.com/coinbase/kryptology v1.8.0/go.mod h1:RYXOAPdzOGUe3qlSFkMGn58i3xUA8hmxYHksuq+8ciI= github.com/coinbase/rosetta-sdk-go v0.7.9 h1:lqllBjMnazTjIqYrOGv8h8jxjg9+hJazIGZr9ZvoCcA= github.com/coinbase/rosetta-sdk-go v0.7.9/go.mod h1:0/knutI7XGVqXmmH4OQD8OckFrbQ8yMsUZTG7FXCR2M= -github.com/confio/ics23/go v0.7.0 h1:00d2kukk7sPoHWL4zZBZwzxnpA2pec1NPdwbSokJ5w8= -github.com/confio/ics23/go v0.7.0/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg= github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= github.com/consensys/bavard v0.1.8-0.20210915155054-088da2f7f54a/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= github.com/consensys/gnark-crypto v0.4.1-0.20210426202927-39ac3d4b3f1f/go.mod h1:815PAHg3wvysy0SyIqanF8gZ0Y1wjk/hrDHD/iT88+Q= @@ -243,6 +241,8 @@ github.com/cosmos/cosmos-sdk/api v0.1.0 h1:xfSKM0e9p+EJTMQnf5PbWE6VT8ruxTABIJ64R github.com/cosmos/cosmos-sdk/api v0.1.0/go.mod h1:CupqQBskAOiTXO1XDZ/wrtWzN/wTxUvbQmOqdUhR8wI= github.com/cosmos/cosmos-sdk/errors v1.0.0-beta.5 h1:9ebZL9/nCkaxer3kWWHs0YT8OOmHd7xohULM8Weep7M= github.com/cosmos/cosmos-sdk/errors v1.0.0-beta.5/go.mod h1:wDFkBmFsFolsfsAfsLON7xX0EuWIvNxMO7NDjrijYU8= +github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 h1:iKclrn3YEOwk4jQHT2ulgzuXyxmzmPczUalMwW4XH9k= +github.com/cosmos/cosmos-sdk/ics23/go v0.8.0/go.mod h1:2a4dBq88TUoqoWAU5eu0lGvpFP3wWDPgdHPargtyw30= github.com/cosmos/cosmos-sdk/orm v1.0.0-alpha.12 h1:EswjcLv+gVv5cwUzLT98kp+5sYdp43OD+iFvtC7t9ww= github.com/cosmos/cosmos-sdk/orm v1.0.0-alpha.12/go.mod h1:XSTyCzMsetl+BoUgUF0F2FoU2LT+Zm7sxzhVgjayCnM= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= From c8d12d3be32021dc6e5313c9de003cde2fb10c0a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 31 Oct 2022 10:02:12 -0700 Subject: [PATCH 3/7] build(deps): Bump github.com/cosmos/ibc-go/v5 from 5.0.0 to 5.0.1 (#1581) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 987d3a7512..f17320dfa3 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( cosmossdk.io/math v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.46.3 - github.com/cosmos/ibc-go/v5 v5.0.0 + github.com/cosmos/ibc-go/v5 v5.0.1 github.com/gorilla/mux v1.8.0 github.com/prometheus/client_golang v1.12.2 // indirect github.com/rakyll/statik v0.1.7 diff --git a/go.sum b/go.sum index 1265a21f47..f3d5f63487 100644 --- a/go.sum +++ b/go.sum @@ -254,8 +254,8 @@ github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4 github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= github.com/cosmos/iavl v0.19.3 h1:cESO0OwTTxQm5rmyESKW+zESheDUYI7CcZDWWDwnuxg= github.com/cosmos/iavl v0.19.3/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= -github.com/cosmos/ibc-go/v5 v5.0.0 h1:MkObdarpoICPHXoRg/Ne9NRix4j7eQlJZq74/uzH3Zc= -github.com/cosmos/ibc-go/v5 v5.0.0/go.mod h1:Wqsguq98Iuns8tgTv8+xaGYbC+Q8zJfbpjzT6IgMJbs= +github.com/cosmos/ibc-go/v5 v5.0.1 h1:ZI5xCi6RDOL+hyu6Wx/w6JoAYFlOoK5hijsRTVWo+RA= +github.com/cosmos/ibc-go/v5 v5.0.1/go.mod h1:LX0DHLW3dfi/1e4BJzi8MGLWmQ4DSraPEgVjyo3VzAo= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= github.com/cosmos/ledger-go v0.9.2/go.mod h1:oZJ2hHAZROdlHiwTg4t7kP+GKIIkBT+o6c9QWFanOyI= From 323a953327ef78d98bb25d3ca014f0305ec1633c Mon Sep 17 00:00:00 2001 From: Tyler <48813565+technicallyty@users.noreply.github.com> Date: Mon, 31 Oct 2022 18:40:53 -0700 Subject: [PATCH 4/7] refactor(x/ecocredit): update credit to basket conversion and docs (#1559) Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com> --- api/regen/ecocredit/basket/v1/tx.pulsar.go | 21 +++-- api/regen/ecocredit/basket/v1/tx_grpc.pb.go | 68 +++++++++++++--- proto/regen/ecocredit/basket/v1/tx.proto | 56 +++++++++---- x/ecocredit/basket/keeper/msg_put.go | 21 +---- x/ecocredit/basket/keeper/utils.go | 19 +++++ x/ecocredit/basket/keeper/utils_test.go | 54 +++++++++++++ x/ecocredit/basket/types/v1/tx.pb.go | 89 ++++++++++++++++----- 7 files changed, 250 insertions(+), 78 deletions(-) diff --git a/api/regen/ecocredit/basket/v1/tx.pulsar.go b/api/regen/ecocredit/basket/v1/tx.pulsar.go index 362e4d8388..4461ce9e1a 100644 --- a/api/regen/ecocredit/basket/v1/tx.pulsar.go +++ b/api/regen/ecocredit/basket/v1/tx.pulsar.go @@ -5569,11 +5569,10 @@ type MsgCreate struct { // date_criteria is the date criteria for batches admitted to the basket. // At most, only one of the fields in the date_criteria should be set. DateCriteria *DateCriteria `protobuf:"bytes,8,opt,name=date_criteria,json=dateCriteria,proto3" json:"date_criteria,omitempty"` - // fee is the basket creation fee. A fee is not required if the list of fees - // in Params.basket_fee is empty. The provided fee must be one of the fees - // listed in Params.basket_fee. The provided amount can be greater than - // or equal to the listed amount but the basket creator will only be charged - // the listed amount (i.e. the minimum amount). + // fee is the basket creation fee. A fee is not required if no fee exists + // in the basket fee parameter. The fee must be greater than or equal to the + // fee param. The curator will be charged the amount specified in the fee + // parameter, even if a greater amount is provided. // // Note (Since Revision 1): Although this field supports a list of fees, the // basket creator must provide no more than one fee (i.e. one Coin in a list @@ -5715,9 +5714,7 @@ type MsgPut struct { // basket_denom is the basket denom to add credits to. BasketDenom string `protobuf:"bytes,2,opt,name=basket_denom,json=basketDenom,proto3" json:"basket_denom,omitempty"` // credits are credits to add to the basket. If they do not match the basket's - // admission criteria the operation will fail. If there are any "dust" credits - // left over when converting credits to basket tokens, these credits will - // not be converted to basket tokens and instead remain with the owner. + // admission criteria, the operation will fail. Credits []*BasketCredit `protobuf:"bytes,3,rep,name=credits,proto3" json:"credits,omitempty"` } @@ -5812,7 +5809,7 @@ type MsgTake struct { // amount is the integer number of basket tokens to convert into credits. Amount string `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount,omitempty"` // retirement_location is the optional retirement jurisdiction for the - // credits which will be used only if retire_on_take is true for this basket. + // credits which will be used only if retire_on_take is true. // // Deprecated (Since Revision 1): This field will be removed in the next // version in favor of retirement_jurisdiction. Only one of these need to be @@ -5822,10 +5819,12 @@ type MsgTake struct { RetirementLocation string `protobuf:"bytes,4,opt,name=retirement_location,json=retirementLocation,proto3" json:"retirement_location,omitempty"` // retire_on_take is a boolean that dictates whether the ecocredits // received in exchange for the basket tokens will be received as - // retired or tradable credits. + // retired or tradable credits. If the basket has disable_auto_retire set to + // false, retire_on_take MUST be set to true, and a retirement jurisdiction + // must be provided. RetireOnTake bool `protobuf:"varint,5,opt,name=retire_on_take,json=retireOnTake,proto3" json:"retire_on_take,omitempty"` // retirement_jurisdiction is the optional retirement jurisdiction for the - // credits which will be used only if retire_on_take is true for this basket. + // credits which will be used only if retire_on_take is true. // // Since Revision 1 RetirementJurisdiction string `protobuf:"bytes,6,opt,name=retirement_jurisdiction,json=retirementJurisdiction,proto3" json:"retirement_jurisdiction,omitempty"` diff --git a/api/regen/ecocredit/basket/v1/tx_grpc.pb.go b/api/regen/ecocredit/basket/v1/tx_grpc.pb.go index 182d19aa69..baac770800 100644 --- a/api/regen/ecocredit/basket/v1/tx_grpc.pb.go +++ b/api/regen/ecocredit/basket/v1/tx_grpc.pb.go @@ -22,12 +22,36 @@ const _ = grpc.SupportPackageIsVersion7 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type MsgClient interface { - // Create creates a bank denom which wraps credits. + // Create creates a basket that can hold different types of ecocredits that + // meet the basket's criteria. Upon depositing ecocredits into the basket, + // basket tokens are minted and sent to depositor using the Cosmos SDK Bank + // module. This allows basket tokens to be utilized within IBC. Basket tokens + // are fully fungible with other basket tokens from the same basket. The + // basket token denom is derived from the basket name, credit type + // abbreviation, and credit type precision (i.e. basket name "foo", credit + // type exponent 6, and credit type abbreviation "C" generates the denom + // eco.uC.foo). Baskets can limit credit acceptance criteria based on a + // combination of credit type, credit classes, and credit batch start date. + // Credits can be taken from the basket in exchange for basket tokens. Taken + // credits will be immediately retired, unless disable_auto_retire is set to + // true. When set to true, credits may be received in either a tradable or + // retired state, depending on the taker's request. If the basket fee + // governance parameter is set, a fee of equal or greater value must be + // provided in the request. Only the amount specified in the fee parameter + // will be charged, even if a greater value fee is provided. Fees from + // creating a basket are burned. Create(ctx context.Context, in *MsgCreate, opts ...grpc.CallOption) (*MsgCreateResponse, error) - // Put puts credits into a basket in return for basket tokens. + // Put deposits credits into the basket from the holder's tradable balance in + // exchange for basket tokens. The amount of tokens received is calculated by + // the following formula: sum(credits_deposited) * 10^credit_type_exponent. + // The credits being deposited MUST adhere to the criteria of the basket. Put(ctx context.Context, in *MsgPut, opts ...grpc.CallOption) (*MsgPutResponse, error) - // Take takes credits from a basket starting from the oldest - // credits first. + // Take exchanges basket tokens for credits from the specified basket. Credits + // are taken deterministically, ordered by oldest batch start date to the most + // recent batch start date. If the basket has disable_auto_retire set to + // false, both retirement_jurisdiction and retire_on_take must be set, and the + // taken credits will be retired immediately upon receipt. Otherwise, credits + // may be received as tradable or retired, based on the request. Take(ctx context.Context, in *MsgTake, opts ...grpc.CallOption) (*MsgTakeResponse, error) // UpdateBasketFee is a governance method that allows for updating the basket // creation fee. If not set, the basket creation fee will be removed and no @@ -35,7 +59,7 @@ type MsgClient interface { // // Since Revision 2 UpdateBasketFee(ctx context.Context, in *MsgUpdateBasketFee, opts ...grpc.CallOption) (*MsgUpdateBasketFeeResponse, error) - // UpdateCurator updates basket curator + // UpdateCurator updates basket curator. // // Since Revision 2 UpdateCurator(ctx context.Context, in *MsgUpdateCurator, opts ...grpc.CallOption) (*MsgUpdateCuratorResponse, error) @@ -98,12 +122,36 @@ func (c *msgClient) UpdateCurator(ctx context.Context, in *MsgUpdateCurator, opt // All implementations must embed UnimplementedMsgServer // for forward compatibility type MsgServer interface { - // Create creates a bank denom which wraps credits. + // Create creates a basket that can hold different types of ecocredits that + // meet the basket's criteria. Upon depositing ecocredits into the basket, + // basket tokens are minted and sent to depositor using the Cosmos SDK Bank + // module. This allows basket tokens to be utilized within IBC. Basket tokens + // are fully fungible with other basket tokens from the same basket. The + // basket token denom is derived from the basket name, credit type + // abbreviation, and credit type precision (i.e. basket name "foo", credit + // type exponent 6, and credit type abbreviation "C" generates the denom + // eco.uC.foo). Baskets can limit credit acceptance criteria based on a + // combination of credit type, credit classes, and credit batch start date. + // Credits can be taken from the basket in exchange for basket tokens. Taken + // credits will be immediately retired, unless disable_auto_retire is set to + // true. When set to true, credits may be received in either a tradable or + // retired state, depending on the taker's request. If the basket fee + // governance parameter is set, a fee of equal or greater value must be + // provided in the request. Only the amount specified in the fee parameter + // will be charged, even if a greater value fee is provided. Fees from + // creating a basket are burned. Create(context.Context, *MsgCreate) (*MsgCreateResponse, error) - // Put puts credits into a basket in return for basket tokens. + // Put deposits credits into the basket from the holder's tradable balance in + // exchange for basket tokens. The amount of tokens received is calculated by + // the following formula: sum(credits_deposited) * 10^credit_type_exponent. + // The credits being deposited MUST adhere to the criteria of the basket. Put(context.Context, *MsgPut) (*MsgPutResponse, error) - // Take takes credits from a basket starting from the oldest - // credits first. + // Take exchanges basket tokens for credits from the specified basket. Credits + // are taken deterministically, ordered by oldest batch start date to the most + // recent batch start date. If the basket has disable_auto_retire set to + // false, both retirement_jurisdiction and retire_on_take must be set, and the + // taken credits will be retired immediately upon receipt. Otherwise, credits + // may be received as tradable or retired, based on the request. Take(context.Context, *MsgTake) (*MsgTakeResponse, error) // UpdateBasketFee is a governance method that allows for updating the basket // creation fee. If not set, the basket creation fee will be removed and no @@ -111,7 +159,7 @@ type MsgServer interface { // // Since Revision 2 UpdateBasketFee(context.Context, *MsgUpdateBasketFee) (*MsgUpdateBasketFeeResponse, error) - // UpdateCurator updates basket curator + // UpdateCurator updates basket curator. // // Since Revision 2 UpdateCurator(context.Context, *MsgUpdateCurator) (*MsgUpdateCuratorResponse, error) diff --git a/proto/regen/ecocredit/basket/v1/tx.proto b/proto/regen/ecocredit/basket/v1/tx.proto index 1d74fe1adc..2a996df95a 100644 --- a/proto/regen/ecocredit/basket/v1/tx.proto +++ b/proto/regen/ecocredit/basket/v1/tx.proto @@ -11,15 +11,38 @@ option go_package = "github.com/regen-network/regen-ledger/x/ecocredit/basket/ty // Msg is the regen.ecocredit.basket.v1 Msg service. service Msg { - - // Create creates a bank denom which wraps credits. + // Create creates a basket that can hold different types of ecocredits that + // meet the basket's criteria. Upon depositing ecocredits into the basket, + // basket tokens are minted and sent to depositor using the Cosmos SDK Bank + // module. This allows basket tokens to be utilized within IBC. Basket tokens + // are fully fungible with other basket tokens from the same basket. The + // basket token denom is derived from the basket name, credit type + // abbreviation, and credit type precision (i.e. basket name "foo", credit + // type exponent 6, and credit type abbreviation "C" generates the denom + // eco.uC.foo). Baskets can limit credit acceptance criteria based on a + // combination of credit type, credit classes, and credit batch start date. + // Credits can be taken from the basket in exchange for basket tokens. Taken + // credits will be immediately retired, unless disable_auto_retire is set to + // true. When set to true, credits may be received in either a tradable or + // retired state, depending on the taker's request. If the basket fee + // governance parameter is set, a fee of equal or greater value must be + // provided in the request. Only the amount specified in the fee parameter + // will be charged, even if a greater value fee is provided. Fees from + // creating a basket are burned. rpc Create(MsgCreate) returns (MsgCreateResponse); - // Put puts credits into a basket in return for basket tokens. + // Put deposits credits into the basket from the holder's tradable balance in + // exchange for basket tokens. The amount of tokens received is calculated by + // the following formula: sum(credits_deposited) * 10^credit_type_exponent. + // The credits being deposited MUST adhere to the criteria of the basket. rpc Put(MsgPut) returns (MsgPutResponse); - // Take takes credits from a basket starting from the oldest - // credits first. + // Take exchanges basket tokens for credits from the specified basket. Credits + // are taken deterministically, ordered by oldest batch start date to the most + // recent batch start date. If the basket has disable_auto_retire set to + // false, both retirement_jurisdiction and retire_on_take must be set, and the + // taken credits will be retired immediately upon receipt. Otherwise, credits + // may be received as tradable or retired, based on the request. rpc Take(MsgTake) returns (MsgTakeResponse); // UpdateBasketFee is a governance method that allows for updating the basket @@ -29,7 +52,7 @@ service Msg { // Since Revision 2 rpc UpdateBasketFee(MsgUpdateBasketFee) returns (MsgUpdateBasketFeeResponse); - // UpdateCurator updates basket curator + // UpdateCurator updates basket curator. // // Since Revision 2 rpc UpdateCurator(MsgUpdateCurator) returns (MsgUpdateCuratorResponse); @@ -80,11 +103,10 @@ message MsgCreate { // At most, only one of the fields in the date_criteria should be set. DateCriteria date_criteria = 8; - // fee is the basket creation fee. A fee is not required if the list of fees - // in Params.basket_fee is empty. The provided fee must be one of the fees - // listed in Params.basket_fee. The provided amount can be greater than - // or equal to the listed amount but the basket creator will only be charged - // the listed amount (i.e. the minimum amount). + // fee is the basket creation fee. A fee is not required if no fee exists + // in the basket fee parameter. The fee must be greater than or equal to the + // fee param. The curator will be charged the amount specified in the fee + // parameter, even if a greater amount is provided. // // Note (Since Revision 1): Although this field supports a list of fees, the // basket creator must provide no more than one fee (i.e. one Coin in a list @@ -115,9 +137,7 @@ message MsgPut { string basket_denom = 2; // credits are credits to add to the basket. If they do not match the basket's - // admission criteria the operation will fail. If there are any "dust" credits - // left over when converting credits to basket tokens, these credits will - // not be converted to basket tokens and instead remain with the owner. + // admission criteria, the operation will fail. repeated BasketCredit credits = 3; } @@ -142,7 +162,7 @@ message MsgTake { string amount = 3; // retirement_location is the optional retirement jurisdiction for the - // credits which will be used only if retire_on_take is true for this basket. + // credits which will be used only if retire_on_take is true. // // Deprecated (Since Revision 1): This field will be removed in the next // version in favor of retirement_jurisdiction. Only one of these need to be @@ -151,11 +171,13 @@ message MsgTake { // retire_on_take is a boolean that dictates whether the ecocredits // received in exchange for the basket tokens will be received as - // retired or tradable credits. + // retired or tradable credits. If the basket has disable_auto_retire set to + // false, retire_on_take MUST be set to true, and a retirement jurisdiction + // must be provided. bool retire_on_take = 5; // retirement_jurisdiction is the optional retirement jurisdiction for the - // credits which will be used only if retire_on_take is true for this basket. + // credits which will be used only if retire_on_take is true. // // Since Revision 1 string retirement_jurisdiction = 6; diff --git a/x/ecocredit/basket/keeper/msg_put.go b/x/ecocredit/basket/keeper/msg_put.go index c392c1354c..5a7fa436dc 100644 --- a/x/ecocredit/basket/keeper/msg_put.go +++ b/x/ecocredit/basket/keeper/msg_put.go @@ -70,12 +70,12 @@ func (k Keeper) Put(ctx context.Context, req *types.MsgPut) (*types.MsgPutRespon return nil, err } // get the amount of basket tokens to give to the depositor - tokens, err := creditAmountToBasketCoins(amt, creditType.Precision, basket.BasketDenom) + tokens, err := creditAmountToBasketCoin(amt, creditType.Precision, basket.BasketDenom) if err != nil { return nil, err } // update the total amount received so far - amountReceived = amountReceived.Add(tokens[0].Amount) + amountReceived = amountReceived.Add(tokens.Amount) if err = sdkCtx.EventManager().EmitTypedEvent(&basetypes.EventTransfer{ Sender: ownerString, @@ -217,20 +217,3 @@ func (k Keeper) transferToBasket(ctx context.Context, sender sdk.AccAddress, amt } return nil } - -// creditAmountToBasketCoins calculates the tokens to award to the depositor -func creditAmountToBasketCoins(creditAmt regenmath.Dec, exp uint32, denom string) (sdk.Coins, error) { - var coins sdk.Coins - multiplier := regenmath.NewDecFinite(1, int32(exp)) - tokenAmt, err := multiplier.MulExact(creditAmt) - if err != nil { - return coins, err - } - - amtInt, err := tokenAmt.BigInt() - if err != nil { - return coins, err - } - - return sdk.Coins{sdk.NewCoin(denom, sdk.NewIntFromBigInt(amtInt))}, nil -} diff --git a/x/ecocredit/basket/keeper/utils.go b/x/ecocredit/basket/keeper/utils.go index 808637f85b..26eb1b2113 100644 --- a/x/ecocredit/basket/keeper/utils.go +++ b/x/ecocredit/basket/keeper/utils.go @@ -3,6 +3,8 @@ package keeper import ( "context" + sdk "github.com/cosmos/cosmos-sdk/types" + api "github.com/regen-network/regen-ledger/api/regen/ecocredit/basket/v1" "github.com/regen-network/regen-ledger/types/math" ) @@ -56,3 +58,20 @@ func (k Keeper) GetBasketBalanceMap(ctx context.Context) (map[uint64]math.Dec, e return batchKeyToBalance, nil } + +// creditAmountToBasketCoin calculates the coins to mint to the credit depositor using the following formula: +// coinAmount = creditAmt * (1 * 10^exp) +func creditAmountToBasketCoin(creditAmt math.Dec, exp uint32, denom string) (sdk.Coin, error) { + multiplier := math.NewDecFinite(1, int32(exp)) + tokenAmt, err := multiplier.MulExact(creditAmt) + if err != nil { + return sdk.Coin{}, err + } + + amtInt, err := tokenAmt.BigInt() + if err != nil { + return sdk.Coin{}, err + } + + return sdk.NewCoin(denom, sdk.NewIntFromBigInt(amtInt)), nil +} diff --git a/x/ecocredit/basket/keeper/utils_test.go b/x/ecocredit/basket/keeper/utils_test.go index aa5fff7342..c0f21f636e 100644 --- a/x/ecocredit/basket/keeper/utils_test.go +++ b/x/ecocredit/basket/keeper/utils_test.go @@ -1,6 +1,8 @@ package keeper import ( + "fmt" + "math/big" "testing" "github.com/golang/mock/gomock" @@ -87,6 +89,58 @@ func TestGetBasketBalances(t *testing.T) { require.Equal(t, IDToBalance[2], amtToDeposit) } +func FuzzCreditAmountToBasketCoin(f *testing.F) { + + // prefixLen returns the amount we need to adjust our length calculations by. + // for example, 0.23 * 10^2 produces 23, equal to the exponent. however, 1.12 * 10^2 produces 112, so we must adjust. + // similarly, 0.003 * 10^3 produces just 3, so we also consider subtracting from the adjustment. + prefixLen := func(d string) int { + prefixLen := 0 + // first we want to capture situations where the whole number has many digits (i.e. 12423.402) as this makes the resulting number LARGER + if d[0] != '0' { + for _, c := range d { + if c != '.' { + prefixLen++ + } else { + break + } + } + return prefixLen + } + // then we capture situations where we have many zeroes (i.e. 0.0023) as this makes the resulting number SMALLER. + count := 0 + for i := 2; i < len(d)-1; i++ { + if d[i] == '0' { + count-- + } else { + break + } + } + return count + } + + f.Add(uint32(6), 1.123456) + f.Fuzz(func(t *testing.T, exponent uint32, dec float64) { + if exponent > 24 || exponent == 0 { + t.Skip() + } + trimmedFloat := big.NewFloat(dec).Text('f', int(exponent)) + creditDec, err := math.NewPositiveFixedDecFromString(trimmedFloat, exponent) + if err != nil { + t.Skip() + } + if len(creditDec.String()) >= 36 { // decimals strings with length >= 36 create rounding errors. + t.Skip() + } + coin, err := creditAmountToBasketCoin(creditDec, exponent, "foo") + assert.NilError(t, err, fmt.Sprintf("error converting %s with exponent %d", creditDec.String(), exponent)) + add := prefixLen(creditDec.String()) + expected := int(exponent) + add + assert.Check(t, len(coin.Amount.String()) == expected, fmt.Sprintf("expected %v to have length %d given decimal %s and exponent %d with prefix length %d", coin, expected, creditDec.String(), exponent, add)) + + }) +} + func initBatch(t *testing.T, s *baseSuite, pid uint64, denom string, startDate *timestamppb.Timestamp) { assert.NilError(t, s.baseStore.BatchTable().Insert(s.ctx, &baseapi.Batch{ ProjectKey: pid, diff --git a/x/ecocredit/basket/types/v1/tx.pb.go b/x/ecocredit/basket/types/v1/tx.pb.go index ef49dc6aee..e806510488 100644 --- a/x/ecocredit/basket/types/v1/tx.pb.go +++ b/x/ecocredit/basket/types/v1/tx.pb.go @@ -66,11 +66,10 @@ type MsgCreate struct { // date_criteria is the date criteria for batches admitted to the basket. // At most, only one of the fields in the date_criteria should be set. DateCriteria *DateCriteria `protobuf:"bytes,8,opt,name=date_criteria,json=dateCriteria,proto3" json:"date_criteria,omitempty"` - // fee is the basket creation fee. A fee is not required if the list of fees - // in Params.basket_fee is empty. The provided fee must be one of the fees - // listed in Params.basket_fee. The provided amount can be greater than - // or equal to the listed amount but the basket creator will only be charged - // the listed amount (i.e. the minimum amount). + // fee is the basket creation fee. A fee is not required if no fee exists + // in the basket fee parameter. The fee must be greater than or equal to the + // fee param. The curator will be charged the amount specified in the fee + // parameter, even if a greater amount is provided. // // Note (Since Revision 1): Although this field supports a list of fees, the // basket creator must provide no more than one fee (i.e. one Coin in a list @@ -230,9 +229,7 @@ type MsgPut struct { // basket_denom is the basket denom to add credits to. BasketDenom string `protobuf:"bytes,2,opt,name=basket_denom,json=basketDenom,proto3" json:"basket_denom,omitempty"` // credits are credits to add to the basket. If they do not match the basket's - // admission criteria the operation will fail. If there are any "dust" credits - // left over when converting credits to basket tokens, these credits will - // not be converted to basket tokens and instead remain with the owner. + // admission criteria, the operation will fail. Credits []*BasketCredit `protobuf:"bytes,3,rep,name=credits,proto3" json:"credits,omitempty"` } @@ -345,7 +342,7 @@ type MsgTake struct { // amount is the integer number of basket tokens to convert into credits. Amount string `protobuf:"bytes,3,opt,name=amount,proto3" json:"amount,omitempty"` // retirement_location is the optional retirement jurisdiction for the - // credits which will be used only if retire_on_take is true for this basket. + // credits which will be used only if retire_on_take is true. // // Deprecated (Since Revision 1): This field will be removed in the next // version in favor of retirement_jurisdiction. Only one of these need to be @@ -353,10 +350,12 @@ type MsgTake struct { RetirementLocation string `protobuf:"bytes,4,opt,name=retirement_location,json=retirementLocation,proto3" json:"retirement_location,omitempty"` // Deprecated: Do not use. // retire_on_take is a boolean that dictates whether the ecocredits // received in exchange for the basket tokens will be received as - // retired or tradable credits. + // retired or tradable credits. If the basket has disable_auto_retire set to + // false, retire_on_take MUST be set to true, and a retirement jurisdiction + // must be provided. RetireOnTake bool `protobuf:"varint,5,opt,name=retire_on_take,json=retireOnTake,proto3" json:"retire_on_take,omitempty"` // retirement_jurisdiction is the optional retirement jurisdiction for the - // credits which will be used only if retire_on_take is true for this basket. + // credits which will be used only if retire_on_take is true. // // Since Revision 1 RetirementJurisdiction string `protobuf:"bytes,6,opt,name=retirement_jurisdiction,json=retirementJurisdiction,proto3" json:"retirement_jurisdiction,omitempty"` @@ -776,12 +775,36 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { - // Create creates a bank denom which wraps credits. + // Create creates a basket that can hold different types of ecocredits that + // meet the basket's criteria. Upon depositing ecocredits into the basket, + // basket tokens are minted and sent to depositor using the Cosmos SDK Bank + // module. This allows basket tokens to be utilized within IBC. Basket tokens + // are fully fungible with other basket tokens from the same basket. The + // basket token denom is derived from the basket name, credit type + // abbreviation, and credit type precision (i.e. basket name "foo", credit + // type exponent 6, and credit type abbreviation "C" generates the denom + // eco.uC.foo). Baskets can limit credit acceptance criteria based on a + // combination of credit type, credit classes, and credit batch start date. + // Credits can be taken from the basket in exchange for basket tokens. Taken + // credits will be immediately retired, unless disable_auto_retire is set to + // true. When set to true, credits may be received in either a tradable or + // retired state, depending on the taker's request. If the basket fee + // governance parameter is set, a fee of equal or greater value must be + // provided in the request. Only the amount specified in the fee parameter + // will be charged, even if a greater value fee is provided. Fees from + // creating a basket are burned. Create(ctx context.Context, in *MsgCreate, opts ...grpc.CallOption) (*MsgCreateResponse, error) - // Put puts credits into a basket in return for basket tokens. + // Put deposits credits into the basket from the holder's tradable balance in + // exchange for basket tokens. The amount of tokens received is calculated by + // the following formula: sum(credits_deposited) * 10^credit_type_exponent. + // The credits being deposited MUST adhere to the criteria of the basket. Put(ctx context.Context, in *MsgPut, opts ...grpc.CallOption) (*MsgPutResponse, error) - // Take takes credits from a basket starting from the oldest - // credits first. + // Take exchanges basket tokens for credits from the specified basket. Credits + // are taken deterministically, ordered by oldest batch start date to the most + // recent batch start date. If the basket has disable_auto_retire set to + // false, both retirement_jurisdiction and retire_on_take must be set, and the + // taken credits will be retired immediately upon receipt. Otherwise, credits + // may be received as tradable or retired, based on the request. Take(ctx context.Context, in *MsgTake, opts ...grpc.CallOption) (*MsgTakeResponse, error) // UpdateBasketFee is a governance method that allows for updating the basket // creation fee. If not set, the basket creation fee will be removed and no @@ -789,7 +812,7 @@ type MsgClient interface { // // Since Revision 2 UpdateBasketFee(ctx context.Context, in *MsgUpdateBasketFee, opts ...grpc.CallOption) (*MsgUpdateBasketFeeResponse, error) - // UpdateCurator updates basket curator + // UpdateCurator updates basket curator. // // Since Revision 2 UpdateCurator(ctx context.Context, in *MsgUpdateCurator, opts ...grpc.CallOption) (*MsgUpdateCuratorResponse, error) @@ -850,12 +873,36 @@ func (c *msgClient) UpdateCurator(ctx context.Context, in *MsgUpdateCurator, opt // MsgServer is the server API for Msg service. type MsgServer interface { - // Create creates a bank denom which wraps credits. + // Create creates a basket that can hold different types of ecocredits that + // meet the basket's criteria. Upon depositing ecocredits into the basket, + // basket tokens are minted and sent to depositor using the Cosmos SDK Bank + // module. This allows basket tokens to be utilized within IBC. Basket tokens + // are fully fungible with other basket tokens from the same basket. The + // basket token denom is derived from the basket name, credit type + // abbreviation, and credit type precision (i.e. basket name "foo", credit + // type exponent 6, and credit type abbreviation "C" generates the denom + // eco.uC.foo). Baskets can limit credit acceptance criteria based on a + // combination of credit type, credit classes, and credit batch start date. + // Credits can be taken from the basket in exchange for basket tokens. Taken + // credits will be immediately retired, unless disable_auto_retire is set to + // true. When set to true, credits may be received in either a tradable or + // retired state, depending on the taker's request. If the basket fee + // governance parameter is set, a fee of equal or greater value must be + // provided in the request. Only the amount specified in the fee parameter + // will be charged, even if a greater value fee is provided. Fees from + // creating a basket are burned. Create(context.Context, *MsgCreate) (*MsgCreateResponse, error) - // Put puts credits into a basket in return for basket tokens. + // Put deposits credits into the basket from the holder's tradable balance in + // exchange for basket tokens. The amount of tokens received is calculated by + // the following formula: sum(credits_deposited) * 10^credit_type_exponent. + // The credits being deposited MUST adhere to the criteria of the basket. Put(context.Context, *MsgPut) (*MsgPutResponse, error) - // Take takes credits from a basket starting from the oldest - // credits first. + // Take exchanges basket tokens for credits from the specified basket. Credits + // are taken deterministically, ordered by oldest batch start date to the most + // recent batch start date. If the basket has disable_auto_retire set to + // false, both retirement_jurisdiction and retire_on_take must be set, and the + // taken credits will be retired immediately upon receipt. Otherwise, credits + // may be received as tradable or retired, based on the request. Take(context.Context, *MsgTake) (*MsgTakeResponse, error) // UpdateBasketFee is a governance method that allows for updating the basket // creation fee. If not set, the basket creation fee will be removed and no @@ -863,7 +910,7 @@ type MsgServer interface { // // Since Revision 2 UpdateBasketFee(context.Context, *MsgUpdateBasketFee) (*MsgUpdateBasketFeeResponse, error) - // UpdateCurator updates basket curator + // UpdateCurator updates basket curator. // // Since Revision 2 UpdateCurator(context.Context, *MsgUpdateCurator) (*MsgUpdateCuratorResponse, error) From f1cbc554d0fd9529a75d9600aa367db021b5e7dd Mon Sep 17 00:00:00 2001 From: MD Aleem <72057206+aleem1314@users.noreply.github.com> Date: Thu, 3 Nov 2022 03:26:38 +0530 Subject: [PATCH 5/7] fix(x/data): return grpc error codes for queries (#1579) Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com> --- CHANGELOG.md | 6 ++ errors/go.mod | 15 ++++ errors/go.sum | 83 +++++++++++++++++++ errors/grpc.go | 22 +++++ go.mod | 3 + x/data/go.mod | 3 + x/data/server/query_anchor_by_hash.go | 10 +-- x/data/server/query_anchor_by_hash_test.go | 6 +- x/data/server/query_anchor_by_iri.go | 11 ++- x/data/server/query_anchor_by_iri_test.go | 6 +- .../server/query_attestations_by_attestor.go | 12 +-- .../query_attestations_by_attestor_test.go | 4 +- x/data/server/query_attestations_by_hash.go | 12 +-- .../server/query_attestations_by_hash_test.go | 6 +- x/data/server/query_attestations_by_iri.go | 12 +-- .../server/query_attestations_by_iri_test.go | 6 +- x/data/server/query_convert_hash_to_iri.go | 7 +- .../server/query_convert_hash_to_iri_test.go | 4 +- x/data/server/query_convert_iri_to_hash.go | 7 +- .../server/query_convert_iri_to_hash_test.go | 4 +- x/data/server/query_resolver.go | 6 +- x/data/server/query_resolver_test.go | 2 +- x/data/server/query_resolvers_by_hash.go | 16 ++-- x/data/server/query_resolvers_by_hash_test.go | 4 +- x/data/server/query_resolvers_by_iri.go | 16 ++-- x/data/server/query_resolvers_by_iri_test.go | 6 +- x/data/server/query_resolvers_by_url.go | 8 +- x/data/server/query_resolvers_by_url_test.go | 2 +- 28 files changed, 214 insertions(+), 85 deletions(-) create mode 100644 errors/go.mod create mode 100644 errors/go.sum create mode 100644 errors/grpc.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 865caa2883..c67ff78a7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### General +- [#1579](https://github.com/regen-network/regen-ledger/pull/1579) Add `errors` module + #### Changed - [#1244](https://github.com/regen-network/regen-ledger/pull/1244) Update all modules to Cosmos SDK v0.46 @@ -60,6 +62,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [#1395](https://github.com/regen-network/regen-ledger/pull/1395) Add `Resolver` state validation checks - [#1395](https://github.com/regen-network/regen-ledger/pull/1395) Add `DataResolver` state validation checks +#### Fixed + +- [#1579](https://github.com/regen-network/regen-ledger/pull/1579) Return gRPC response code in query response. + ### x/ecocredit #### API Breaking Changes diff --git a/errors/go.mod b/errors/go.mod new file mode 100644 index 0000000000..3c3b14eafb --- /dev/null +++ b/errors/go.mod @@ -0,0 +1,15 @@ +module github.com/regen-network/regen-ledger/errors + +go 1.18 + +require ( + cosmossdk.io/errors v1.0.0-beta.7 + google.golang.org/grpc v1.50.1 +) + +require ( + github.com/golang/protobuf v1.5.2 // indirect + github.com/pkg/errors v0.9.1 // indirect + google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect + google.golang.org/protobuf v1.27.1 // indirect +) diff --git a/errors/go.sum b/errors/go.sum new file mode 100644 index 0000000000..ec362fcdd0 --- /dev/null +++ b/errors/go.sum @@ -0,0 +1,83 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w= +cosmossdk.io/errors v1.0.0-beta.7/go.mod h1:mz6FQMJRku4bY7aqS/Gwfcmr/ue91roMEKAmDUDpBfE= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.50.1 h1:DS/BukOZWp8s6p4Dt/tOaJaTQyPyOoCcrjroHuCeLzY= +google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/errors/grpc.go b/errors/grpc.go new file mode 100644 index 0000000000..68d01d0a97 --- /dev/null +++ b/errors/grpc.go @@ -0,0 +1,22 @@ +package errros + +import ( + "cosmossdk.io/errors" + "google.golang.org/grpc/codes" +) + +const moduleName = "grpc" + +var ( + ErrCanceled = errors.RegisterWithGRPCCode(moduleName, 1, codes.Canceled, "canceled") + ErrUnknown = errors.RegisterWithGRPCCode(moduleName, 2, codes.Unknown, "unknown") + ErrInvalidArgument = errors.RegisterWithGRPCCode(moduleName, 3, codes.InvalidArgument, "invalid argument") + ErrNotFound = errors.RegisterWithGRPCCode(moduleName, 5, codes.NotFound, "not found") + ErrAlreadyExists = errors.RegisterWithGRPCCode(moduleName, 6, codes.AlreadyExists, "already exists") + ErrPermissionDenied = errors.RegisterWithGRPCCode(moduleName, 7, codes.PermissionDenied, "permission denied") + ErrResourceExhausted = errors.RegisterWithGRPCCode(moduleName, 8, codes.ResourceExhausted, "resource exhausted") + ErrUnimplemented = errors.RegisterWithGRPCCode(moduleName, 12, codes.Unimplemented, "unimplemented") + ErrInternal = errors.RegisterWithGRPCCode(moduleName, 13, codes.Internal, "internal") + ErrUnavailable = errors.RegisterWithGRPCCode(moduleName, 14, codes.Unavailable, "unavailable") + ErrUnauthenticated = errors.RegisterWithGRPCCode(moduleName, 16, codes.Unauthenticated, "unauthenticated") +) diff --git a/go.mod b/go.mod index f17320dfa3..9e846a2cb3 100644 --- a/go.mod +++ b/go.mod @@ -133,6 +133,7 @@ require ( github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/regen-network/cosmos-proto v0.3.1 // indirect github.com/regen-network/regen-ledger/api v0.8.0 // indirect + github.com/regen-network/regen-ledger/errors v0.0.0-00010101000000-000000000000 // indirect github.com/rs/cors v1.8.2 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect @@ -177,6 +178,8 @@ replace github.com/regen-network/regen-ledger/x/ecocredit => ./x/ecocredit replace github.com/regen-network/regen-ledger/api => ./api +replace github.com/regen-network/regen-ledger/errors => ./errors + // Fix upstream GHSA-h395-qcrw-5vmq vulnerability. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 replace github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0 diff --git a/x/data/go.mod b/x/data/go.mod index 8d397cbad2..e37fd15e9f 100644 --- a/x/data/go.mod +++ b/x/data/go.mod @@ -15,6 +15,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/regen-network/gocuke v0.6.2 github.com/regen-network/regen-ledger/api v0.8.0 + github.com/regen-network/regen-ledger/errors v0.0.0-00010101000000-000000000000 github.com/regen-network/regen-ledger/types v1.0.0 github.com/spf13/cobra v1.6.1 github.com/stretchr/testify v1.8.1 @@ -173,3 +174,5 @@ replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alp replace github.com/regen-network/regen-ledger/types => ../../types replace github.com/regen-network/regen-ledger/api => ../../api + +replace github.com/regen-network/regen-ledger/errors => ../../errors diff --git a/x/data/server/query_anchor_by_hash.go b/x/data/server/query_anchor_by_hash.go index ffcfd25e56..3bc829fe39 100644 --- a/x/data/server/query_anchor_by_hash.go +++ b/x/data/server/query_anchor_by_hash.go @@ -3,7 +3,7 @@ package server import ( "context" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/x/data" @@ -12,22 +12,22 @@ import ( // AnchorByHash queries a data anchor by the ContentHash of the data. func (s serverImpl) AnchorByHash(ctx context.Context, request *data.QueryAnchorByHashRequest) (*data.QueryAnchorByHashResponse, error) { if request.ContentHash == nil { - return nil, sdkerrors.ErrInvalidRequest.Wrap("content hash cannot be empty") + return nil, regenerrors.ErrInvalidArgument.Wrap("content hash cannot be empty") } iri, err := request.ContentHash.ToIRI() if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } dataID, err := s.stateStore.DataIDTable().GetByIri(ctx, iri) if err != nil { - return nil, sdkerrors.ErrNotFound.Wrap("data record with content hash") + return nil, regenerrors.ErrNotFound.Wrapf("data record with IRI: %s", iri) } anchor, err := s.stateStore.DataAnchorTable().Get(ctx, dataID.Id) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf(err.Error()) } return &data.QueryAnchorByHashResponse{ diff --git a/x/data/server/query_anchor_by_hash_test.go b/x/data/server/query_anchor_by_hash_test.go index f2cea9199c..7e141b8c04 100644 --- a/x/data/server/query_anchor_by_hash_test.go +++ b/x/data/server/query_anchor_by_hash_test.go @@ -53,13 +53,13 @@ func TestQuery_AnchorByHash(t *testing.T) { // query data anchor with empty content hash _, err = s.server.AnchorByHash(s.ctx, &data.QueryAnchorByHashRequest{}) - require.EqualError(t, err, "content hash cannot be empty: invalid request") + require.EqualError(t, err, "content hash cannot be empty: invalid argument") // query data anchor with invalid content hash _, err = s.server.AnchorByHash(s.ctx, &data.QueryAnchorByHashRequest{ ContentHash: &data.ContentHash{}, }) - require.EqualError(t, err, "invalid data.ContentHash: invalid type") + require.EqualError(t, err, "invalid data.ContentHash: invalid type: invalid argument") // query data anchor with content hash that has not been anchored _, err = s.server.AnchorByHash(s.ctx, &data.QueryAnchorByHashRequest{ @@ -69,5 +69,5 @@ func TestQuery_AnchorByHash(t *testing.T) { CanonicalizationAlgorithm: data.GraphCanonicalizationAlgorithm_GRAPH_CANONICALIZATION_ALGORITHM_URDNA2015, }}, }) - require.EqualError(t, err, "data record with content hash: not found") + require.EqualError(t, err, "data record with IRI: regen:13toVfvdftodu8c1Jc4TXxCnq7XLRAe4p9MgDKF2VeFKMx9eZXMgGnB.rdf: not found") } diff --git a/x/data/server/query_anchor_by_iri.go b/x/data/server/query_anchor_by_iri.go index 874d46fbcc..5422c0815d 100644 --- a/x/data/server/query_anchor_by_iri.go +++ b/x/data/server/query_anchor_by_iri.go @@ -3,8 +3,7 @@ package server import ( "context" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/x/data" ) @@ -12,22 +11,22 @@ import ( // AnchorByIRI queries a data anchor by the IRI of the data. func (s serverImpl) AnchorByIRI(ctx context.Context, request *data.QueryAnchorByIRIRequest) (*data.QueryAnchorByIRIResponse, error) { if len(request.Iri) == 0 { - return nil, sdkerrors.ErrInvalidRequest.Wrap("IRI cannot be empty") + return nil, regenerrors.ErrInvalidArgument.Wrap("IRI cannot be empty") } contentHash, err := data.ParseIRI(request.Iri) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrapf("failed to parse IRI: %s", err.Error()) } dataID, err := s.stateStore.DataIDTable().GetByIri(ctx, request.Iri) if err != nil { - return nil, sdkerrors.ErrNotFound.Wrapf("data record with IRI") + return nil, regenerrors.ErrNotFound.Wrapf("data record with IRI: %s", request.Iri) } anchor, err := s.stateStore.DataAnchorTable().Get(ctx, dataID.Id) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrap(err.Error()) } return &data.QueryAnchorByIRIResponse{ diff --git a/x/data/server/query_anchor_by_iri_test.go b/x/data/server/query_anchor_by_iri_test.go index 305cd54d4b..70dc00fc6f 100644 --- a/x/data/server/query_anchor_by_iri_test.go +++ b/x/data/server/query_anchor_by_iri_test.go @@ -54,17 +54,17 @@ func TestQuery_AnchorByIRI(t *testing.T) { // query data anchor with empty iri _, err = s.server.AnchorByIRI(s.ctx, &data.QueryAnchorByIRIRequest{}) - require.EqualError(t, err, "IRI cannot be empty: invalid request") + require.EqualError(t, err, "IRI cannot be empty: invalid argument") // query data anchor with invalid iri _, err = s.server.AnchorByIRI(s.ctx, &data.QueryAnchorByIRIRequest{ Iri: "foo", }) - require.EqualError(t, err, "failed to parse IRI foo: regen: prefix required: invalid IRI") + require.EqualError(t, err, "failed to parse IRI: failed to parse IRI foo: regen: prefix required: invalid IRI: invalid argument") // query data anchor with iri that has not been anchored _, err = s.server.AnchorByIRI(s.ctx, &data.QueryAnchorByIRIRequest{ Iri: "regen:13toVfvdftodu8c1Jc4TXxCnq7XLRAe4p9MgDKF2VeFKMx9eZXMgGnB.rdf", }) - require.EqualError(t, err, "data record with IRI: not found") + require.EqualError(t, err, "data record with IRI: regen:13toVfvdftodu8c1Jc4TXxCnq7XLRAe4p9MgDKF2VeFKMx9eZXMgGnB.rdf: not found") } diff --git a/x/data/server/query_attestations_by_attestor.go b/x/data/server/query_attestations_by_attestor.go index 6eb5f38678..4aff395fe1 100644 --- a/x/data/server/query_attestations_by_attestor.go +++ b/x/data/server/query_attestations_by_attestor.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/data/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/types/ormutil" "github.com/regen-network/regen-ledger/x/data" @@ -16,17 +16,17 @@ import ( // AttestationsByAttestor queries data attestations by an attestor. func (s serverImpl) AttestationsByAttestor(ctx context.Context, request *data.QueryAttestationsByAttestorRequest) (*data.QueryAttestationsByAttestorResponse, error) { if len(request.Attestor) == 0 { - return nil, sdkerrors.ErrInvalidRequest.Wrap("attestor cannot be empty") + return nil, regenerrors.ErrInvalidArgument.Wrap("attestor cannot be empty") } addr, err := sdk.AccAddressFromBech32(request.Attestor) if err != nil { - return nil, sdkerrors.ErrInvalidAddress.Wrapf("attestor: %s", err) + return nil, regenerrors.ErrInvalidArgument.Wrapf("attestor: %s", err.Error()) } pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := s.stateStore.DataAttestorTable().List( @@ -48,7 +48,7 @@ func (s serverImpl) AttestationsByAttestor(ctx context.Context, request *data.Qu dataID, err := s.stateStore.DataIDTable().Get(ctx, dataAttestor.Id) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrap(err.Error()) } attestations = append(attestations, &data.AttestationInfo{ @@ -60,7 +60,7 @@ func (s serverImpl) AttestationsByAttestor(ctx context.Context, request *data.Qu pageRes, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &data.QueryAttestationsByAttestorResponse{ diff --git a/x/data/server/query_attestations_by_attestor_test.go b/x/data/server/query_attestations_by_attestor_test.go index 6afb1e2c2c..78ffbab2f9 100644 --- a/x/data/server/query_attestations_by_attestor_test.go +++ b/x/data/server/query_attestations_by_attestor_test.go @@ -76,11 +76,11 @@ func TestQuery_AttestationsByAttestor(t *testing.T) { // query attestations with empty attestor _, err = s.server.AttestationsByAttestor(s.ctx, &data.QueryAttestationsByAttestorRequest{}) - require.EqualError(t, err, "attestor cannot be empty: invalid request") + require.EqualError(t, err, "attestor cannot be empty: invalid argument") // query attestations with invalid attestor address _, err = s.server.AttestationsByAttestor(s.ctx, &data.QueryAttestationsByAttestorRequest{ Attestor: "foo", }) - require.EqualError(t, err, "attestor: decoding bech32 failed: invalid bech32 string length 3: invalid address") + require.EqualError(t, err, "attestor: decoding bech32 failed: invalid bech32 string length 3: invalid argument") } diff --git a/x/data/server/query_attestations_by_hash.go b/x/data/server/query_attestations_by_hash.go index 3819bd531e..7fd00f13e8 100644 --- a/x/data/server/query_attestations_by_hash.go +++ b/x/data/server/query_attestations_by_hash.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/data/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/types/ormutil" "github.com/regen-network/regen-ledger/x/data" @@ -16,22 +16,22 @@ import ( // AttestationsByHash queries data attestations by the ContentHash of the data. func (s serverImpl) AttestationsByHash(ctx context.Context, request *data.QueryAttestationsByHashRequest) (*data.QueryAttestationsByHashResponse, error) { if request.ContentHash == nil { - return nil, sdkerrors.ErrInvalidRequest.Wrap("content hash cannot be empty") + return nil, regenerrors.ErrInvalidArgument.Wrap("content hash cannot be empty") } iri, err := request.ContentHash.ToIRI() if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrapf("failed to convert to IRI: %s", err.Error()) } dataID, err := s.stateStore.DataIDTable().GetByIri(ctx, iri) if err != nil { - return nil, sdkerrors.ErrNotFound.Wrap("data record with content hash") + return nil, regenerrors.ErrNotFound.Wrapf("data record with IRI: %s", iri) } pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := s.stateStore.DataAttestorTable().List( @@ -60,7 +60,7 @@ func (s serverImpl) AttestationsByHash(ctx context.Context, request *data.QueryA pageRes, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &data.QueryAttestationsByHashResponse{ diff --git a/x/data/server/query_attestations_by_hash_test.go b/x/data/server/query_attestations_by_hash_test.go index 3f7f029ab3..f9ef61d630 100644 --- a/x/data/server/query_attestations_by_hash_test.go +++ b/x/data/server/query_attestations_by_hash_test.go @@ -90,13 +90,13 @@ func TestQuery_AttestationsByHash(t *testing.T) { // query attestations with empty content hash _, err = s.server.AttestationsByHash(s.ctx, &data.QueryAttestationsByHashRequest{}) - require.EqualError(t, err, "content hash cannot be empty: invalid request") + require.EqualError(t, err, "content hash cannot be empty: invalid argument") // query attestations with invalid content hash _, err = s.server.AttestationsByHash(s.ctx, &data.QueryAttestationsByHashRequest{ ContentHash: &data.ContentHash{}, }) - require.EqualError(t, err, "invalid data.ContentHash: invalid type") + require.EqualError(t, err, "failed to convert to IRI: invalid data.ContentHash: invalid type: invalid argument") // query attestations with content hash that has not been anchored _, err = s.server.AttestationsByHash(s.ctx, &data.QueryAttestationsByHashRequest{ @@ -106,5 +106,5 @@ func TestQuery_AttestationsByHash(t *testing.T) { CanonicalizationAlgorithm: data.GraphCanonicalizationAlgorithm_GRAPH_CANONICALIZATION_ALGORITHM_URDNA2015, }}, }) - require.EqualError(t, err, "data record with content hash: not found") + require.EqualError(t, err, "data record with IRI: regen:13toVfw5KEeQwbmV733E3j9HwhVCQTxB7ojFPjGdmr7HX3kuSASGXxV.rdf: not found") } diff --git a/x/data/server/query_attestations_by_iri.go b/x/data/server/query_attestations_by_iri.go index 394a97f1c6..3fa2c3939e 100644 --- a/x/data/server/query_attestations_by_iri.go +++ b/x/data/server/query_attestations_by_iri.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/data/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/types/ormutil" "github.com/regen-network/regen-ledger/x/data" @@ -16,23 +16,23 @@ import ( // AttestationsByIRI queries data attestations by the IRI of the data. func (s serverImpl) AttestationsByIRI(ctx context.Context, request *data.QueryAttestationsByIRIRequest) (*data.QueryAttestationsByIRIResponse, error) { if len(request.Iri) == 0 { - return nil, sdkerrors.ErrInvalidRequest.Wrap("IRI cannot be empty") + return nil, regenerrors.ErrInvalidArgument.Wrap("IRI cannot be empty") } // check for valid IRI _, err := data.ParseIRI(request.Iri) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrapf("failed to parse IRI: %s", err.Error()) } dataID, err := s.stateStore.DataIDTable().GetByIri(ctx, request.Iri) if err != nil { - return nil, sdkerrors.ErrNotFound.Wrap("data record with IRI") + return nil, regenerrors.ErrNotFound.Wrapf("data record with IRI: %s", request.Iri) } pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := s.stateStore.DataAttestorTable().List( @@ -61,7 +61,7 @@ func (s serverImpl) AttestationsByIRI(ctx context.Context, request *data.QueryAt pageRes, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &data.QueryAttestationsByIRIResponse{ diff --git a/x/data/server/query_attestations_by_iri_test.go b/x/data/server/query_attestations_by_iri_test.go index c6ced2372c..29f6a6dd49 100644 --- a/x/data/server/query_attestations_by_iri_test.go +++ b/x/data/server/query_attestations_by_iri_test.go @@ -90,17 +90,17 @@ func TestQuery_AttestationsByIRI(t *testing.T) { // query attestations with empty iri _, err = s.server.AttestationsByIRI(s.ctx, &data.QueryAttestationsByIRIRequest{}) - require.EqualError(t, err, "IRI cannot be empty: invalid request") + require.EqualError(t, err, "IRI cannot be empty: invalid argument") // query attestations with invalid iri _, err = s.server.AttestationsByIRI(s.ctx, &data.QueryAttestationsByIRIRequest{ Iri: "foo", }) - require.EqualError(t, err, "failed to parse IRI foo: regen: prefix required: invalid IRI") + require.EqualError(t, err, "failed to parse IRI: failed to parse IRI foo: regen: prefix required: invalid IRI: invalid argument") // query attestations with iri that has not been anchored _, err = s.server.AttestationsByIRI(s.ctx, &data.QueryAttestationsByIRIRequest{ Iri: "regen:13toVfw5KEeQwbmV733E3j9HwhVCQTxB7ojFPjGdmr7HX3kuSASGXxV.rdf", }) - require.EqualError(t, err, "data record with IRI: not found") + require.EqualError(t, err, "data record with IRI: regen:13toVfw5KEeQwbmV733E3j9HwhVCQTxB7ojFPjGdmr7HX3kuSASGXxV.rdf: not found") } diff --git a/x/data/server/query_convert_hash_to_iri.go b/x/data/server/query_convert_hash_to_iri.go index 0e1a7ceff9..dc9563c56b 100644 --- a/x/data/server/query_convert_hash_to_iri.go +++ b/x/data/server/query_convert_hash_to_iri.go @@ -3,20 +3,19 @@ package server import ( "context" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/x/data" ) // ConvertHashToIRI converts a ContentHash to an IRI. func (s serverImpl) ConvertHashToIRI(_ context.Context, request *data.ConvertHashToIRIRequest) (*data.ConvertHashToIRIResponse, error) { if request.ContentHash == nil { - return nil, sdkerrors.ErrInvalidRequest.Wrap("content hash cannot be empty") + return nil, regenerrors.ErrInvalidArgument.Wrap("content hash cannot be empty") } iri, err := request.ContentHash.ToIRI() if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrapf("failed to parse IRI: %s", err.Error()) } return &data.ConvertHashToIRIResponse{ diff --git a/x/data/server/query_convert_hash_to_iri_test.go b/x/data/server/query_convert_hash_to_iri_test.go index 3e68119aa6..3503d6da1c 100644 --- a/x/data/server/query_convert_hash_to_iri_test.go +++ b/x/data/server/query_convert_hash_to_iri_test.go @@ -30,11 +30,11 @@ func TestQuery_ConvertHashToIRI(t *testing.T) { // query attestations with empty content hash _, err = s.server.ConvertHashToIRI(s.ctx, &data.ConvertHashToIRIRequest{}) - require.EqualError(t, err, "content hash cannot be empty: invalid request") + require.EqualError(t, err, "content hash cannot be empty: invalid argument") // query attestations with invalid content hash _, err = s.server.ConvertHashToIRI(s.ctx, &data.ConvertHashToIRIRequest{ ContentHash: &data.ContentHash{}, }) - require.EqualError(t, err, "invalid data.ContentHash: invalid type") + require.EqualError(t, err, "failed to parse IRI: invalid data.ContentHash: invalid type: invalid argument") } diff --git a/x/data/server/query_convert_iri_to_hash.go b/x/data/server/query_convert_iri_to_hash.go index 2bb113e481..d8de4028a6 100644 --- a/x/data/server/query_convert_iri_to_hash.go +++ b/x/data/server/query_convert_iri_to_hash.go @@ -3,20 +3,19 @@ package server import ( "context" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/x/data" ) // ConvertIRIToHash converts an IRI to a ContentHash. func (s serverImpl) ConvertIRIToHash(_ context.Context, request *data.ConvertIRIToHashRequest) (*data.ConvertIRIToHashResponse, error) { if len(request.Iri) == 0 { - return nil, sdkerrors.ErrInvalidRequest.Wrap("IRI cannot be empty") + return nil, regenerrors.ErrInvalidArgument.Wrap("IRI cannot be empty") } hash, err := data.ParseIRI(request.Iri) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrap(err.Error()) + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } return &data.ConvertIRIToHashResponse{ diff --git a/x/data/server/query_convert_iri_to_hash_test.go b/x/data/server/query_convert_iri_to_hash_test.go index 790ef322a6..2b9b9c6e8e 100644 --- a/x/data/server/query_convert_iri_to_hash_test.go +++ b/x/data/server/query_convert_iri_to_hash_test.go @@ -30,11 +30,11 @@ func TestQuery_ConvertIRIToHash(t *testing.T) { // query attestations with empty content hash _, err = s.server.ConvertIRIToHash(s.ctx, &data.ConvertIRIToHashRequest{}) - require.EqualError(t, err, "IRI cannot be empty: invalid request") + require.EqualError(t, err, "IRI cannot be empty: invalid argument") // query attestations with invalid content hash _, err = s.server.ConvertIRIToHash(s.ctx, &data.ConvertIRIToHashRequest{ Iri: "foo", }) - require.EqualError(t, err, "failed to parse IRI foo: regen: prefix required: invalid IRI: invalid request") + require.EqualError(t, err, "failed to parse IRI foo: regen: prefix required: invalid IRI: invalid argument") } diff --git a/x/data/server/query_resolver.go b/x/data/server/query_resolver.go index 60d9941b71..518e74a1ef 100644 --- a/x/data/server/query_resolver.go +++ b/x/data/server/query_resolver.go @@ -4,20 +4,20 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/x/data" ) // Resolver queries a resolver by its unique identifier. func (s serverImpl) Resolver(ctx context.Context, request *data.QueryResolverRequest) (*data.QueryResolverResponse, error) { if request.Id == 0 { - return nil, sdkerrors.ErrInvalidRequest.Wrap("ID cannot be empty") + return nil, regenerrors.ErrInvalidArgument.Wrap("ID cannot be empty") } resolver, err := s.stateStore.ResolverTable().Get(ctx, request.Id) if err != nil { - return nil, sdkerrors.ErrNotFound.Wrapf("resolver with ID: %d", request.Id) + return nil, regenerrors.ErrNotFound.Wrapf("resolver with ID: %d", request.Id) } manager := sdk.AccAddress(resolver.Manager).String() diff --git a/x/data/server/query_resolver_test.go b/x/data/server/query_resolver_test.go index 5fbd292f3a..ce5985c8ea 100644 --- a/x/data/server/query_resolver_test.go +++ b/x/data/server/query_resolver_test.go @@ -35,5 +35,5 @@ func TestQuery_Resolver(t *testing.T) { // query resolvers with empty id _, err = s.server.Resolver(s.ctx, &data.QueryResolverRequest{}) - require.EqualError(t, err, "ID cannot be empty: invalid request") + require.EqualError(t, err, "ID cannot be empty: invalid argument") } diff --git a/x/data/server/query_resolvers_by_hash.go b/x/data/server/query_resolvers_by_hash.go index d1e8d73936..40cf1514f7 100644 --- a/x/data/server/query_resolvers_by_hash.go +++ b/x/data/server/query_resolvers_by_hash.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/data/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" "github.com/regen-network/regen-ledger/x/data" ) @@ -15,22 +15,22 @@ import ( // ResolversByHash queries resolvers with registered data by the ContentHash of the data. func (s serverImpl) ResolversByHash(ctx context.Context, request *data.QueryResolversByHashRequest) (*data.QueryResolversByHashResponse, error) { if request.ContentHash == nil { - return nil, sdkerrors.ErrInvalidRequest.Wrap("content hash cannot be empty") + return nil, regenerrors.ErrInvalidArgument.Wrap("content hash cannot be empty") } iri, err := request.ContentHash.ToIRI() if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } dataID, err := s.stateStore.DataIDTable().GetByIri(ctx, iri) if err != nil { - return nil, sdkerrors.ErrNotFound.Wrapf("data record with content hash") + return nil, regenerrors.ErrNotFound.Wrap("data record with content hash") } pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := s.stateStore.DataResolverTable().List( @@ -39,7 +39,7 @@ func (s serverImpl) ResolversByHash(ctx context.Context, request *data.QueryReso ormlist.Paginate(pg), ) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } defer it.Close() @@ -52,7 +52,7 @@ func (s serverImpl) ResolversByHash(ctx context.Context, request *data.QueryReso resolver, err := s.stateStore.ResolverTable().Get(ctx, item.ResolverId) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("failed to get resolver by ID: %d", item.ResolverId) } manager := sdk.AccAddress(resolver.Manager).String() @@ -66,7 +66,7 @@ func (s serverImpl) ResolversByHash(ctx context.Context, request *data.QueryReso res.Pagination, err = ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return res, nil diff --git a/x/data/server/query_resolvers_by_hash_test.go b/x/data/server/query_resolvers_by_hash_test.go index 73a38ba464..ee88ff1fb6 100644 --- a/x/data/server/query_resolvers_by_hash_test.go +++ b/x/data/server/query_resolvers_by_hash_test.go @@ -89,13 +89,13 @@ func TestQuery_ResolversByHash(t *testing.T) { // query resolvers with empty content hash _, err = s.server.ResolversByHash(s.ctx, &data.QueryResolversByHashRequest{}) - require.EqualError(t, err, "content hash cannot be empty: invalid request") + require.EqualError(t, err, "content hash cannot be empty: invalid argument") // query resolvers with invalid content hash _, err = s.server.ResolversByHash(s.ctx, &data.QueryResolversByHashRequest{ ContentHash: &data.ContentHash{}, }) - require.EqualError(t, err, "invalid data.ContentHash: invalid type") + require.EqualError(t, err, "invalid data.ContentHash: invalid type: invalid argument") // query resolvers with content hash that has not been anchored _, err = s.server.ResolversByHash(s.ctx, &data.QueryResolversByHashRequest{ diff --git a/x/data/server/query_resolvers_by_iri.go b/x/data/server/query_resolvers_by_iri.go index ee96b292b0..c27189d0c1 100644 --- a/x/data/server/query_resolvers_by_iri.go +++ b/x/data/server/query_resolvers_by_iri.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/data/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" "github.com/regen-network/regen-ledger/x/data" ) @@ -15,23 +15,23 @@ import ( // ResolversByIRI queries resolvers with registered data by the IRI of the data. func (s serverImpl) ResolversByIRI(ctx context.Context, request *data.QueryResolversByIRIRequest) (*data.QueryResolversByIRIResponse, error) { if len(request.Iri) == 0 { - return nil, sdkerrors.ErrInvalidRequest.Wrap("IRI cannot be empty") + return nil, regenerrors.ErrInvalidArgument.Wrap("IRI cannot be empty") } // check for valid IRI _, err := data.ParseIRI(request.Iri) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } dataID, err := s.stateStore.DataIDTable().GetByIri(ctx, request.Iri) if err != nil { - return nil, sdkerrors.ErrNotFound.Wrap("data record with IRI") + return nil, regenerrors.ErrNotFound.Wrapf("data record with IRI: %s", request.Iri) } pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := s.stateStore.DataResolverTable().List( @@ -40,7 +40,7 @@ func (s serverImpl) ResolversByIRI(ctx context.Context, request *data.QueryResol ormlist.Paginate(pg), ) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } defer it.Close() @@ -53,7 +53,7 @@ func (s serverImpl) ResolversByIRI(ctx context.Context, request *data.QueryResol resolver, err := s.stateStore.ResolverTable().Get(ctx, item.ResolverId) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("resolver with ID: %d", item.ResolverId) } manager := sdk.AccAddress(resolver.Manager).String() @@ -67,7 +67,7 @@ func (s serverImpl) ResolversByIRI(ctx context.Context, request *data.QueryResol res.Pagination, err = ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return res, nil diff --git a/x/data/server/query_resolvers_by_iri_test.go b/x/data/server/query_resolvers_by_iri_test.go index db59378e52..e8706bfcd2 100644 --- a/x/data/server/query_resolvers_by_iri_test.go +++ b/x/data/server/query_resolvers_by_iri_test.go @@ -89,17 +89,17 @@ func TestQuery_ResolversByIRI(t *testing.T) { // query resolvers with empty iri _, err = s.server.ResolversByIRI(s.ctx, &data.QueryResolversByIRIRequest{}) - require.EqualError(t, err, "IRI cannot be empty: invalid request") + require.EqualError(t, err, "IRI cannot be empty: invalid argument") // query resolvers with invalid iri _, err = s.server.ResolversByIRI(s.ctx, &data.QueryResolversByIRIRequest{ Iri: "foo", }) - require.EqualError(t, err, "failed to parse IRI foo: regen: prefix required: invalid IRI") + require.EqualError(t, err, "failed to parse IRI foo: regen: prefix required: invalid IRI: invalid argument") // query resolvers with iri that has not been anchored _, err = s.server.ResolversByIRI(s.ctx, &data.QueryResolversByIRIRequest{ Iri: "regen:13toVfw5KEeQwbmV733E3j9HwhVCQTxB7ojFPjGdmr7HX3kuSASGXxV.rdf", }) - require.EqualError(t, err, "data record with IRI: not found") + require.EqualError(t, err, "data record with IRI: regen:13toVfw5KEeQwbmV733E3j9HwhVCQTxB7ojFPjGdmr7HX3kuSASGXxV.rdf: not found") } diff --git a/x/data/server/query_resolvers_by_url.go b/x/data/server/query_resolvers_by_url.go index 0e331983e5..028d2ae55d 100644 --- a/x/data/server/query_resolvers_by_url.go +++ b/x/data/server/query_resolvers_by_url.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/data/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" "github.com/regen-network/regen-ledger/x/data" ) @@ -15,12 +15,12 @@ import ( // ResolversByURL queries resolvers by URL. func (s serverImpl) ResolversByURL(ctx context.Context, request *data.QueryResolversByURLRequest) (*data.QueryResolversByURLResponse, error) { if len(request.Url) == 0 { - return nil, sdkerrors.ErrInvalidRequest.Wrap("URL cannot be empty") + return nil, regenerrors.ErrInvalidArgument.Wrap("URL cannot be empty") } pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := s.stateStore.ResolverTable().List( @@ -51,7 +51,7 @@ func (s serverImpl) ResolversByURL(ctx context.Context, request *data.QueryResol res.Pagination, err = ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return res, nil diff --git a/x/data/server/query_resolvers_by_url_test.go b/x/data/server/query_resolvers_by_url_test.go index 2e1ef90a5a..c06ab62962 100644 --- a/x/data/server/query_resolvers_by_url_test.go +++ b/x/data/server/query_resolvers_by_url_test.go @@ -52,5 +52,5 @@ func TestQuery_ResolversByURL(t *testing.T) { // query resolvers with empty url _, err = s.server.ResolversByURL(s.ctx, &data.QueryResolversByURLRequest{}) - require.EqualError(t, err, "URL cannot be empty: invalid request") + require.EqualError(t, err, "URL cannot be empty: invalid argument") } From f1f02bfbe4dc13d395478069d18425fdbeb491b4 Mon Sep 17 00:00:00 2001 From: MD Aleem <72057206+aleem1314@users.noreply.github.com> Date: Thu, 3 Nov 2022 03:50:50 +0530 Subject: [PATCH 6/7] fix(ecocredit): return gRPC errors for base queries (#1583) Co-authored-by: Ryan Christoffersen <12519942+ryanchristo@users.noreply.github.com> --- go.mod | 2 ++ x/ecocredit/base/keeper/query_all_balances.go | 7 ++++--- .../base/keeper/query_allowed_class_creators.go | 5 +++-- x/ecocredit/base/keeper/query_balance.go | 8 ++++---- x/ecocredit/base/keeper/query_balance_by_batch.go | 8 ++++---- x/ecocredit/base/keeper/query_balances.go | 9 +++++---- x/ecocredit/base/keeper/query_batch_info.go | 8 ++++---- x/ecocredit/base/keeper/query_batches.go | 7 ++++--- x/ecocredit/base/keeper/query_batches_by_class.go | 10 +++++----- x/ecocredit/base/keeper/query_batches_by_issuer.go | 10 +++++----- .../base/keeper/query_batches_by_issuer_test.go | 3 +-- x/ecocredit/base/keeper/query_batches_by_project.go | 8 ++++---- .../base/keeper/query_class_creator_allowlist.go | 3 ++- x/ecocredit/base/keeper/query_class_fee.go | 6 +++--- x/ecocredit/base/keeper/query_class_info.go | 4 ++-- x/ecocredit/base/keeper/query_class_issuers.go | 8 ++++---- x/ecocredit/base/keeper/query_classes.go | 5 +++-- x/ecocredit/base/keeper/query_classes_by_admin.go | 8 ++++---- .../base/keeper/query_classes_by_admin_test.go | 4 ++-- x/ecocredit/base/keeper/query_credit_type.go | 3 ++- x/ecocredit/base/keeper/query_credit_type_test.go | 4 +--- x/ecocredit/base/keeper/query_credit_types.go | 3 ++- x/ecocredit/base/keeper/query_params.go | 12 ++++++------ x/ecocredit/base/keeper/query_project_info.go | 6 +++--- x/ecocredit/base/keeper/query_projects.go | 7 ++++--- x/ecocredit/base/keeper/query_projects_by_admin.go | 10 +++++----- .../base/keeper/query_projects_by_admin_test.go | 6 ++++++ x/ecocredit/base/keeper/query_projects_by_class.go | 10 +++++----- .../base/keeper/query_projects_by_reference_id.go | 12 +++++------- x/ecocredit/base/keeper/query_supply.go | 7 +++---- x/ecocredit/base/keeper/query_supply_test.go | 7 +++++++ x/ecocredit/base/simulation/msg_add_credit_type.go | 4 ++-- x/ecocredit/base/simulation/operations.go | 4 ++-- x/ecocredit/go.mod | 3 +++ 34 files changed, 121 insertions(+), 100 deletions(-) diff --git a/go.mod b/go.mod index 9e846a2cb3..0f30e00006 100644 --- a/go.mod +++ b/go.mod @@ -185,3 +185,5 @@ replace github.com/regen-network/regen-ledger/errors => ./errors replace github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0 replace github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0 + +replace github.com/regen-network/regen-ledger/errors => ./errors diff --git a/x/ecocredit/base/keeper/query_all_balances.go b/x/ecocredit/base/keeper/query_all_balances.go index d8d351f66c..cce3adcbe2 100644 --- a/x/ecocredit/base/keeper/query_all_balances.go +++ b/x/ecocredit/base/keeper/query_all_balances.go @@ -5,6 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" + regenerrors "github.com/regen-network/regen-ledger/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" "github.com/regen-network/regen-ledger/types/ormutil" @@ -16,7 +17,7 @@ import ( func (k Keeper) AllBalances(ctx context.Context, req *types.QueryAllBalancesRequest) (*types.QueryAllBalancesResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrapf(err.Error()) } it, err := k.stateStore.BatchBalanceTable().List(ctx, api.BatchBalancePrimaryKey{}, ormlist.Paginate(pg)) if err != nil { @@ -33,7 +34,7 @@ func (k Keeper) AllBalances(ctx context.Context, req *types.QueryAllBalancesRequ batch, err := k.stateStore.BatchTable().Get(ctx, balance.BatchKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("batch with key: %d", balance.BatchKey) } res.Balances = append(res.Balances, &types.BatchBalanceInfo{ @@ -46,7 +47,7 @@ func (k Keeper) AllBalances(ctx context.Context, req *types.QueryAllBalancesRequ } res.Pagination, err = ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &res, nil } diff --git a/x/ecocredit/base/keeper/query_allowed_class_creators.go b/x/ecocredit/base/keeper/query_allowed_class_creators.go index 47d2192548..1c7ab04357 100644 --- a/x/ecocredit/base/keeper/query_allowed_class_creators.go +++ b/x/ecocredit/base/keeper/query_allowed_class_creators.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" baseapi "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -15,7 +16,7 @@ import ( func (k Keeper) AllowedClassCreators(ctx context.Context, req *types.QueryAllowedClassCreatorsRequest) (*types.QueryAllowedClassCreatorsResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } itr, err := k.stateStore.AllowedClassCreatorTable().List(ctx, baseapi.AllowedClassCreatorAddressIndexKey{}, ormlist.Paginate(pg)) @@ -36,7 +37,7 @@ func (k Keeper) AllowedClassCreators(ctx context.Context, req *types.QueryAllowe pr, err := ormutil.PulsarPageResToGogoPageRes(itr.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryAllowedClassCreatorsResponse{ diff --git a/x/ecocredit/base/keeper/query_balance.go b/x/ecocredit/base/keeper/query_balance.go index b14154a34e..f6b1507e0e 100644 --- a/x/ecocredit/base/keeper/query_balance.go +++ b/x/ecocredit/base/keeper/query_balance.go @@ -4,8 +4,8 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" "github.com/regen-network/regen-ledger/x/ecocredit/server/utils" ) @@ -15,17 +15,17 @@ import ( func (k Keeper) Balance(ctx context.Context, req *types.QueryBalanceRequest) (*types.QueryBalanceResponse, error) { batch, err := k.stateStore.BatchTable().GetByDenom(ctx, req.BatchDenom) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get batch with denom %s: %s", req.BatchDenom, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get batch with denom %s: %s", req.BatchDenom, err.Error()) } addr, err := sdk.AccAddressFromBech32(req.Address) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } balance, err := utils.GetBalance(ctx, k.stateStore.BatchBalanceTable(), addr, batch.Key) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("unable to get balance with batch key: %d", batch.Key) } info := types.BatchBalanceInfo{ diff --git a/x/ecocredit/base/keeper/query_balance_by_batch.go b/x/ecocredit/base/keeper/query_balance_by_batch.go index 431d882205..bec8cb6b06 100644 --- a/x/ecocredit/base/keeper/query_balance_by_batch.go +++ b/x/ecocredit/base/keeper/query_balance_by_batch.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -15,11 +15,11 @@ import ( func (k Keeper) BalancesByBatch(ctx context.Context, req *types.QueryBalancesByBatchRequest) (*types.QueryBalancesByBatchResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } batch, err := k.stateStore.BatchTable().GetByDenom(ctx, req.BatchDenom) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get batch with denom %s: %s", req.BatchDenom, err.Error()) + return nil, regenerrors.ErrInvalidArgument.Wrapf("could not get batch with denom %s: %s", req.BatchDenom, err.Error()) } it, err := k.stateStore.BatchBalanceTable().List(ctx, api.BatchBalanceBatchKeyAddressIndexKey{}.WithBatchKey(batch.Key), ormlist.Paginate(pg)) if err != nil { @@ -43,7 +43,7 @@ func (k Keeper) BalancesByBatch(ctx context.Context, req *types.QueryBalancesByB } pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryBalancesByBatchResponse{ Balances: balances, diff --git a/x/ecocredit/base/keeper/query_balances.go b/x/ecocredit/base/keeper/query_balances.go index 9684faf106..47fc250e03 100644 --- a/x/ecocredit/base/keeper/query_balances.go +++ b/x/ecocredit/base/keeper/query_balances.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -14,12 +15,12 @@ import ( func (k Keeper) Balances(ctx context.Context, req *types.QueryBalancesRequest) (*types.QueryBalancesResponse, error) { addr, err := sdk.AccAddressFromBech32(req.Address) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.BatchBalanceTable().List(ctx, api.BatchBalanceAddressBatchKeyIndexKey{}.WithAddress(addr), ormlist.Paginate(pg)) @@ -37,7 +38,7 @@ func (k Keeper) Balances(ctx context.Context, req *types.QueryBalancesRequest) ( batch, err := k.stateStore.BatchTable().Get(ctx, balance.BatchKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("balance with key: %d", balance.BatchKey) } info := types.BatchBalanceInfo{ @@ -53,7 +54,7 @@ func (k Keeper) Balances(ctx context.Context, req *types.QueryBalancesRequest) ( pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryBalancesResponse{Balances: balances, Pagination: pr}, nil diff --git a/x/ecocredit/base/keeper/query_batch_info.go b/x/ecocredit/base/keeper/query_batch_info.go index d2c81b6ad1..6ca603abba 100644 --- a/x/ecocredit/base/keeper/query_batch_info.go +++ b/x/ecocredit/base/keeper/query_batch_info.go @@ -4,8 +4,8 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/x/ecocredit/base" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -14,19 +14,19 @@ import ( // Batch queries for information on a credit batch. func (k Keeper) Batch(ctx context.Context, request *types.QueryBatchRequest) (*types.QueryBatchResponse, error) { if err := base.ValidateBatchDenom(request.BatchDenom); err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("batch denom: %s", err) + return nil, regenerrors.ErrInvalidArgument.Wrapf("batch denom: %s", err) } batch, err := k.stateStore.BatchTable().GetByDenom(ctx, request.BatchDenom) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get batch with denom %s: %s", request.BatchDenom, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get batch with denom %s: %s", request.BatchDenom, err.Error()) } issuer := sdk.AccAddress(batch.Issuer) project, err := k.stateStore.ProjectTable().Get(ctx, batch.ProjectKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("could not get project with key %d", batch.ProjectKey) } info := types.BatchInfo{ diff --git a/x/ecocredit/base/keeper/query_batches.go b/x/ecocredit/base/keeper/query_batches.go index eb531211c9..95c6aebf96 100644 --- a/x/ecocredit/base/keeper/query_batches.go +++ b/x/ecocredit/base/keeper/query_batches.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -16,7 +17,7 @@ import ( func (k Keeper) Batches(ctx context.Context, request *types.QueryBatchesRequest) (*types.QueryBatchesResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.BatchTable().List(ctx, api.BatchPrimaryKey{}, ormlist.Paginate(pg)) @@ -36,7 +37,7 @@ func (k Keeper) Batches(ctx context.Context, request *types.QueryBatchesRequest) project, err := k.stateStore.ProjectTable().Get(ctx, batch.ProjectKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("failed to get project by key: %d: %s", batch.ProjectKey, err.Error()) } info := types.BatchInfo{ @@ -55,7 +56,7 @@ func (k Keeper) Batches(ctx context.Context, request *types.QueryBatchesRequest) pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryBatchesResponse{ diff --git a/x/ecocredit/base/keeper/query_batches_by_class.go b/x/ecocredit/base/keeper/query_batches_by_class.go index 8453c0fdb9..a47a4ae03c 100644 --- a/x/ecocredit/base/keeper/query_batches_by_class.go +++ b/x/ecocredit/base/keeper/query_batches_by_class.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -17,12 +17,12 @@ import ( func (k Keeper) BatchesByClass(ctx context.Context, request *types.QueryBatchesByClassRequest) (*types.QueryBatchesByClassResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } class, err := k.stateStore.ClassTable().GetById(ctx, request.ClassId) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) } // we put a "-" after the class name to avoid including class names outside of the query (i.e. a query for C01 could technically include C011 otherwise). @@ -43,7 +43,7 @@ func (k Keeper) BatchesByClass(ctx context.Context, request *types.QueryBatchesB project, err := k.stateStore.ProjectTable().Get(ctx, batch.ProjectKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("unable to get project with key: %d", batch.ProjectKey) } info := types.BatchInfo{ @@ -62,7 +62,7 @@ func (k Keeper) BatchesByClass(ctx context.Context, request *types.QueryBatchesB pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryBatchesByClassResponse{ diff --git a/x/ecocredit/base/keeper/query_batches_by_issuer.go b/x/ecocredit/base/keeper/query_batches_by_issuer.go index acce1772c0..d519125411 100644 --- a/x/ecocredit/base/keeper/query_batches_by_issuer.go +++ b/x/ecocredit/base/keeper/query_batches_by_issuer.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -17,12 +17,12 @@ import ( func (k Keeper) BatchesByIssuer(ctx context.Context, req *types.QueryBatchesByIssuerRequest) (*types.QueryBatchesByIssuerResponse, error) { issuer, err := sdk.AccAddressFromBech32(req.Issuer) if err != nil { - return nil, sdkerrors.ErrInvalidAddress.Wrap(err.Error()) + return nil, regenerrors.ErrInvalidArgument.Wrapf("issuer: %s", err.Error()) } pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.BatchTable().List(ctx, api.BatchIssuerIndexKey{}.WithIssuer(issuer), ormlist.Paginate(pg)) @@ -41,7 +41,7 @@ func (k Keeper) BatchesByIssuer(ctx context.Context, req *types.QueryBatchesByIs project, err := k.stateStore.ProjectTable().Get(ctx, batch.ProjectKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("unable to get project by key: %d", batch.ProjectKey) } info := types.BatchInfo{ @@ -60,7 +60,7 @@ func (k Keeper) BatchesByIssuer(ctx context.Context, req *types.QueryBatchesByIs pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryBatchesByIssuerResponse{Batches: batches, Pagination: pr}, nil diff --git a/x/ecocredit/base/keeper/query_batches_by_issuer_test.go b/x/ecocredit/base/keeper/query_batches_by_issuer_test.go index cc645857ea..e9b65553f8 100644 --- a/x/ecocredit/base/keeper/query_batches_by_issuer_test.go +++ b/x/ecocredit/base/keeper/query_batches_by_issuer_test.go @@ -7,7 +7,6 @@ import ( "gotest.tools/v3/assert" "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" @@ -70,5 +69,5 @@ func TestQueryBatchesByIssuer(t *testing.T) { // query batches by an invalid address _, err = s.k.BatchesByIssuer(s.ctx, &types.QueryBatchesByIssuerRequest{Issuer: "foobar"}) - assert.ErrorContains(t, err, sdkerrors.ErrInvalidAddress.Error()) + assert.ErrorContains(t, err, "decoding bech32 failed: invalid bech32 string length 6: invalid argument") } diff --git a/x/ecocredit/base/keeper/query_batches_by_project.go b/x/ecocredit/base/keeper/query_batches_by_project.go index 77ef08686a..2f3ec051e5 100644 --- a/x/ecocredit/base/keeper/query_batches_by_project.go +++ b/x/ecocredit/base/keeper/query_batches_by_project.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -17,12 +17,12 @@ import ( func (k Keeper) BatchesByProject(ctx context.Context, request *types.QueryBatchesByProjectRequest) (*types.QueryBatchesByProjectResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } project, err := k.stateStore.ProjectTable().GetById(ctx, request.ProjectId) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get project with id %s: %s", request.ProjectId, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get project with id %s: %s", request.ProjectId, err.Error()) } it, err := k.stateStore.BatchTable().List(ctx, api.BatchProjectKeyIndexKey{}.WithProjectKey(project.Key), ormlist.Paginate(pg)) @@ -56,7 +56,7 @@ func (k Keeper) BatchesByProject(ctx context.Context, request *types.QueryBatche pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryBatchesByProjectResponse{ diff --git a/x/ecocredit/base/keeper/query_class_creator_allowlist.go b/x/ecocredit/base/keeper/query_class_creator_allowlist.go index c8e24bf1bc..7e3955b802 100644 --- a/x/ecocredit/base/keeper/query_class_creator_allowlist.go +++ b/x/ecocredit/base/keeper/query_class_creator_allowlist.go @@ -3,6 +3,7 @@ package keeper import ( "context" + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -10,7 +11,7 @@ import ( func (k Keeper) ClassCreatorAllowlist(ctx context.Context, request *types.QueryClassCreatorAllowlistRequest) (*types.QueryClassCreatorAllowlistResponse, error) { result, err := k.stateStore.ClassCreatorAllowlistTable().Get(ctx) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrapf("failed to get class creator allowlist: %s", err.Error()) } return &types.QueryClassCreatorAllowlistResponse{ diff --git a/x/ecocredit/base/keeper/query_class_fee.go b/x/ecocredit/base/keeper/query_class_fee.go index 4d85d6ac00..5fa4c1b63b 100644 --- a/x/ecocredit/base/keeper/query_class_fee.go +++ b/x/ecocredit/base/keeper/query_class_fee.go @@ -4,8 +4,8 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -14,7 +14,7 @@ import ( func (k Keeper) ClassFee(ctx context.Context, request *types.QueryClassFeeRequest) (*types.QueryClassFeeResponse, error) { classFee, err := k.stateStore.ClassFeeTable().Get(ctx) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrapf("failed to get class fee: %s", err.Error()) } var fee sdk.Coin @@ -22,7 +22,7 @@ func (k Keeper) ClassFee(ctx context.Context, request *types.QueryClassFeeReques var ok bool fee, ok = regentypes.ProtoCoinToCoin(classFee.Fee) if !ok { - return nil, sdkerrors.ErrInvalidType.Wrapf("failed to parse class fee") + return nil, regenerrors.ErrInternal.Wrapf("failed to parse class fee") } } diff --git a/x/ecocredit/base/keeper/query_class_info.go b/x/ecocredit/base/keeper/query_class_info.go index 3188f10c3c..9bc525b25d 100644 --- a/x/ecocredit/base/keeper/query_class_info.go +++ b/x/ecocredit/base/keeper/query_class_info.go @@ -4,8 +4,8 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -13,7 +13,7 @@ import ( func (k Keeper) Class(ctx context.Context, request *types.QueryClassRequest) (*types.QueryClassResponse, error) { class, err := k.stateStore.ClassTable().GetById(ctx, request.ClassId) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) } admin := sdk.AccAddress(class.Admin) diff --git a/x/ecocredit/base/keeper/query_class_issuers.go b/x/ecocredit/base/keeper/query_class_issuers.go index 43f35c1fed..9471e738e3 100644 --- a/x/ecocredit/base/keeper/query_class_issuers.go +++ b/x/ecocredit/base/keeper/query_class_issuers.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -16,12 +16,12 @@ import ( func (k Keeper) ClassIssuers(ctx context.Context, request *types.QueryClassIssuersRequest) (*types.QueryClassIssuersResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } classInfo, err := k.stateStore.ClassTable().GetById(ctx, request.ClassId) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) } it, err := k.stateStore.ClassIssuerTable().List(ctx, api.ClassIssuerClassKeyIssuerIndexKey{}.WithClassKey(classInfo.Key), ormlist.Paginate(pg)) @@ -40,7 +40,7 @@ func (k Keeper) ClassIssuers(ctx context.Context, request *types.QueryClassIssue } pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryClassIssuersResponse{ Issuers: issuers, diff --git a/x/ecocredit/base/keeper/query_classes.go b/x/ecocredit/base/keeper/query_classes.go index 549b2ebefb..c3ff863b31 100644 --- a/x/ecocredit/base/keeper/query_classes.go +++ b/x/ecocredit/base/keeper/query_classes.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -15,7 +16,7 @@ import ( func (k Keeper) Classes(ctx context.Context, request *types.QueryClassesRequest) (*types.QueryClassesResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.ClassTable().List(ctx, &api.ClassPrimaryKey{}, ormlist.Paginate(pg)) @@ -45,7 +46,7 @@ func (k Keeper) Classes(ctx context.Context, request *types.QueryClassesRequest) pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryClassesResponse{ diff --git a/x/ecocredit/base/keeper/query_classes_by_admin.go b/x/ecocredit/base/keeper/query_classes_by_admin.go index 3af1911175..af8f006af2 100644 --- a/x/ecocredit/base/keeper/query_classes_by_admin.go +++ b/x/ecocredit/base/keeper/query_classes_by_admin.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -16,12 +16,12 @@ import ( func (k Keeper) ClassesByAdmin(ctx context.Context, req *types.QueryClassesByAdminRequest) (*types.QueryClassesByAdminResponse, error) { admin, err := sdk.AccAddressFromBech32(req.Admin) if err != nil { - return nil, sdkerrors.ErrInvalidAddress.Wrap(err.Error()) + return nil, regenerrors.ErrInvalidArgument.Wrapf("invalid admin: %s", err.Error()) } pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.ClassTable().List(ctx, api.ClassAdminIndexKey{}.WithAdmin(admin), ormlist.Paginate(pg)) @@ -50,7 +50,7 @@ func (k Keeper) ClassesByAdmin(ctx context.Context, req *types.QueryClassesByAdm pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryClassesByAdminResponse{Classes: classes, Pagination: pr}, nil diff --git a/x/ecocredit/base/keeper/query_classes_by_admin_test.go b/x/ecocredit/base/keeper/query_classes_by_admin_test.go index 1715a857cb..6b574692b5 100644 --- a/x/ecocredit/base/keeper/query_classes_by_admin_test.go +++ b/x/ecocredit/base/keeper/query_classes_by_admin_test.go @@ -6,10 +6,10 @@ import ( "gotest.tools/v3/assert" "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -55,5 +55,5 @@ func TestQueryClassesByAdmin(t *testing.T) { // query classes by an invalid admin address _, err = s.k.ClassesByAdmin(s.ctx, &types.QueryClassesByAdminRequest{Admin: "foobar"}) - assert.ErrorContains(t, err, sdkerrors.ErrInvalidAddress.Error()) + assert.ErrorContains(t, err, regenerrors.ErrInvalidArgument.Error()) } diff --git a/x/ecocredit/base/keeper/query_credit_type.go b/x/ecocredit/base/keeper/query_credit_type.go index 0ae22d5567..c62948f160 100644 --- a/x/ecocredit/base/keeper/query_credit_type.go +++ b/x/ecocredit/base/keeper/query_credit_type.go @@ -3,6 +3,7 @@ package keeper import ( "context" + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -10,7 +11,7 @@ import ( func (k Keeper) CreditType(ctx context.Context, request *types.QueryCreditTypeRequest) (*types.QueryCreditTypeResponse, error) { creditType, err := k.stateStore.CreditTypeTable().Get(ctx, request.Abbreviation) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("unable to get credit type with abbreviation: %s", request.Abbreviation) } return &types.QueryCreditTypeResponse{ diff --git a/x/ecocredit/base/keeper/query_credit_type_test.go b/x/ecocredit/base/keeper/query_credit_type_test.go index 0db7a4b07d..a9091fe6b2 100644 --- a/x/ecocredit/base/keeper/query_credit_type_test.go +++ b/x/ecocredit/base/keeper/query_credit_type_test.go @@ -5,8 +5,6 @@ import ( "gotest.tools/v3/assert" - "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" - api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -33,5 +31,5 @@ func TestQuery_CreditType(t *testing.T) { _, err = s.k.CreditType(s.ctx, &types.QueryCreditTypeRequest{ Abbreviation: "D", }) - assert.ErrorIs(t, err, ormerrors.NotFound) + assert.Equal(t, err.Error(), "unable to get credit type with abbreviation: D: not found") } diff --git a/x/ecocredit/base/keeper/query_credit_types.go b/x/ecocredit/base/keeper/query_credit_types.go index 4206e68678..6f5fbec376 100644 --- a/x/ecocredit/base/keeper/query_credit_types.go +++ b/x/ecocredit/base/keeper/query_credit_types.go @@ -4,6 +4,7 @@ import ( "context" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -24,7 +25,7 @@ func (k Keeper) CreditTypes(ctx context.Context, _ *types.QueryCreditTypesReques } var creditType types.CreditType if err := ormutil.PulsarToGogoSlow(ct, &creditType); err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } creditTypes = append(creditTypes, &creditType) } diff --git a/x/ecocredit/base/keeper/query_params.go b/x/ecocredit/base/keeper/query_params.go index b6e74041ff..b189492dbf 100644 --- a/x/ecocredit/base/keeper/query_params.go +++ b/x/ecocredit/base/keeper/query_params.go @@ -4,10 +4,10 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" marketplacev1 "github.com/regen-network/regen-ledger/api/regen/ecocredit/marketplace/v1" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" regentypes "github.com/regen-network/regen-ledger/types" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -19,7 +19,7 @@ func (k Keeper) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types allowlistEnabled, err := k.stateStore.ClassCreatorAllowlistTable().Get(ctx) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrapf("unable to get allowlist param: %s", err.Error()) } itr, err := k.stateStore.AllowedClassCreatorTable().List(ctx, api.AllowedClassCreatorPrimaryKey{}) @@ -40,22 +40,22 @@ func (k Keeper) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types classFee, err := k.stateStore.ClassFeeTable().Get(ctx) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrapf("unable to get class fee param: %s", err.Error()) } classFeeCoin, ok := regentypes.ProtoCoinToCoin(classFee.Fee) if !ok { - return nil, sdkerrors.ErrInvalidCoins.Wrap("class fees") + return nil, regenerrors.ErrInternal.Wrap("failed to convert class fee") } basketFee, err := k.basketStore.BasketFeeTable().Get(ctx) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrapf("unable to get basket fee: %s", err.Error()) } basketFeeCoin, ok := regentypes.ProtoCoinToCoin(basketFee.Fee) if !ok { - return nil, sdkerrors.ErrInvalidCoins.Wrap("basket fees") + return nil, regenerrors.ErrInternal.Wrap("failed to convert basket fee") } allowedDenomsItr, err := k.marketStore.AllowedDenomTable().List(ctx, marketplacev1.AllowedDenomPrimaryKey{}) diff --git a/x/ecocredit/base/keeper/query_project_info.go b/x/ecocredit/base/keeper/query_project_info.go index b5db04add6..c3483a8327 100644 --- a/x/ecocredit/base/keeper/query_project_info.go +++ b/x/ecocredit/base/keeper/query_project_info.go @@ -4,8 +4,8 @@ import ( "context" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -13,14 +13,14 @@ import ( func (k Keeper) Project(ctx context.Context, request *types.QueryProjectRequest) (*types.QueryProjectResponse, error) { project, err := k.stateStore.ProjectTable().GetById(ctx, request.ProjectId) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get project with id %s: %s", request.ProjectId, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get project with id %s: %s", request.ProjectId, err.Error()) } admin := sdk.AccAddress(project.Admin) class, err := k.stateStore.ClassTable().Get(ctx, project.ClassKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("could not get class with key %d: %s", project.ClassKey, err.Error()) } info := types.ProjectInfo{ diff --git a/x/ecocredit/base/keeper/query_projects.go b/x/ecocredit/base/keeper/query_projects.go index 5f5e15b722..61c220601b 100644 --- a/x/ecocredit/base/keeper/query_projects.go +++ b/x/ecocredit/base/keeper/query_projects.go @@ -7,6 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -15,7 +16,7 @@ import ( func (k Keeper) Projects(ctx context.Context, request *types.QueryProjectsRequest) (*types.QueryProjectsResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.ProjectTable().List(ctx, api.ProjectIdIndexKey{}, ormlist.Paginate(pg)) @@ -35,7 +36,7 @@ func (k Keeper) Projects(ctx context.Context, request *types.QueryProjectsReques class, err := k.stateStore.ClassTable().Get(ctx, project.ClassKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("class with key: %d", project.ClassKey) } info := types.ProjectInfo{ @@ -52,7 +53,7 @@ func (k Keeper) Projects(ctx context.Context, request *types.QueryProjectsReques pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryProjectsResponse{ diff --git a/x/ecocredit/base/keeper/query_projects_by_admin.go b/x/ecocredit/base/keeper/query_projects_by_admin.go index c96ed4f99f..c431084c9b 100644 --- a/x/ecocredit/base/keeper/query_projects_by_admin.go +++ b/x/ecocredit/base/keeper/query_projects_by_admin.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -15,12 +15,12 @@ import ( func (k Keeper) ProjectsByAdmin(ctx context.Context, req *types.QueryProjectsByAdminRequest) (*types.QueryProjectsByAdminResponse, error) { admin, err := sdk.AccAddressFromBech32(req.Admin) if err != nil { - return nil, sdkerrors.ErrInvalidAddress.Wrap(err.Error()) + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.ProjectTable().List(ctx, api.ProjectAdminIndexKey{}.WithAdmin(admin), ormlist.Paginate(pg)) @@ -38,7 +38,7 @@ func (k Keeper) ProjectsByAdmin(ctx context.Context, req *types.QueryProjectsByA class, err := k.stateStore.ClassTable().Get(ctx, project.ClassKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("unable to get class with key: %d: %s", project.ClassKey, err.Error()) } projects = append(projects, &types.ProjectInfo{ @@ -53,7 +53,7 @@ func (k Keeper) ProjectsByAdmin(ctx context.Context, req *types.QueryProjectsByA pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryProjectsByAdminResponse{Projects: projects, Pagination: pr}, nil diff --git a/x/ecocredit/base/keeper/query_projects_by_admin_test.go b/x/ecocredit/base/keeper/query_projects_by_admin_test.go index 40388a4dab..54827b53d9 100644 --- a/x/ecocredit/base/keeper/query_projects_by_admin_test.go +++ b/x/ecocredit/base/keeper/query_projects_by_admin_test.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/testdata" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/stretchr/testify/require" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -82,4 +83,9 @@ func TestQuery_Projects_By_Admin(t *testing.T) { res, err = s.k.ProjectsByAdmin(s.ctx, &types.QueryProjectsByAdminRequest{Admin: admin2.String()}) assert.NilError(t, err) assert.Equal(t, len(res.Projects), 1) + + // query project by invalid bech32 address + _, err = s.k.ProjectsByAdmin(s.ctx, &types.QueryProjectsByAdminRequest{Admin: "address"}) + require.Error(t, err) + require.Equal(t, "decoding bech32 failed: invalid bech32 string length 7: invalid argument", err.Error()) } diff --git a/x/ecocredit/base/keeper/query_projects_by_class.go b/x/ecocredit/base/keeper/query_projects_by_class.go index d9d7904040..cf283b43f1 100644 --- a/x/ecocredit/base/keeper/query_projects_by_class.go +++ b/x/ecocredit/base/keeper/query_projects_by_class.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -16,12 +16,12 @@ import ( func (k Keeper) ProjectsByClass(ctx context.Context, request *types.QueryProjectsByClassRequest) (*types.QueryProjectsByClassResponse, error) { pg, err := ormutil.GogoPageReqToPulsarPageReq(request.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } cInfo, err := k.stateStore.ClassTable().GetById(ctx, request.ClassId) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) + return nil, regenerrors.ErrNotFound.Wrapf("could not get class with id %s: %s", request.ClassId, err.Error()) } it, err := k.stateStore.ProjectTable().List(ctx, api.ProjectClassKeyIdIndexKey{}.WithClassKey(cInfo.Key), ormlist.Paginate(pg)) @@ -41,7 +41,7 @@ func (k Keeper) ProjectsByClass(ctx context.Context, request *types.QueryProject class, err := k.stateStore.ClassTable().Get(ctx, project.ClassKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("could not get class with key: %d", project.ClassKey) } info := types.ProjectInfo{ @@ -58,7 +58,7 @@ func (k Keeper) ProjectsByClass(ctx context.Context, request *types.QueryProject pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryProjectsByClassResponse{ diff --git a/x/ecocredit/base/keeper/query_projects_by_reference_id.go b/x/ecocredit/base/keeper/query_projects_by_reference_id.go index 859efaaeda..b7c07b53eb 100644 --- a/x/ecocredit/base/keeper/query_projects_by_reference_id.go +++ b/x/ecocredit/base/keeper/query_projects_by_reference_id.go @@ -3,13 +3,11 @@ package keeper import ( "context" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - "github.com/cosmos/cosmos-sdk/orm/model/ormlist" sdk "github.com/cosmos/cosmos-sdk/types" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/types/ormutil" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -17,12 +15,12 @@ import ( // ProjectsByReferenceId queries projects by reference id. func (k Keeper) ProjectsByReferenceId(ctx context.Context, req *types.QueryProjectsByReferenceIdRequest) (*types.QueryProjectsByReferenceIdResponse, error) { //nolint:revive,stylecheck if req.ReferenceId == "" { - return nil, status.Errorf(codes.InvalidArgument, "reference-id is empty") + return nil, regenerrors.ErrInvalidArgument.Wrap("reference-id is empty") } pg, err := ormutil.GogoPageReqToPulsarPageReq(req.Pagination) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrap(err.Error()) } it, err := k.stateStore.ProjectTable().List(ctx, api.ProjectReferenceIdIndexKey{}.WithReferenceId(req.ReferenceId), ormlist.Paginate(pg)) @@ -40,7 +38,7 @@ func (k Keeper) ProjectsByReferenceId(ctx context.Context, req *types.QueryProje class, err := k.stateStore.ClassTable().Get(ctx, project.ClassKey) if err != nil { - return nil, err + return nil, regenerrors.ErrNotFound.Wrapf("class with key: %d", project.ClassKey) } info := &types.ProjectInfo{ @@ -57,7 +55,7 @@ func (k Keeper) ProjectsByReferenceId(ctx context.Context, req *types.QueryProje pr, err := ormutil.PulsarPageResToGogoPageRes(it.PageResponse()) if err != nil { - return nil, err + return nil, regenerrors.ErrInternal.Wrap(err.Error()) } return &types.QueryProjectsByReferenceIdResponse{ diff --git a/x/ecocredit/base/keeper/query_supply.go b/x/ecocredit/base/keeper/query_supply.go index 3ef5355b8d..f43f8c380b 100644 --- a/x/ecocredit/base/keeper/query_supply.go +++ b/x/ecocredit/base/keeper/query_supply.go @@ -3,8 +3,7 @@ package keeper import ( "context" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - + regenerrors "github.com/regen-network/regen-ledger/errors" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" ) @@ -12,12 +11,12 @@ import ( func (k Keeper) Supply(ctx context.Context, request *types.QuerySupplyRequest) (*types.QuerySupplyResponse, error) { batch, err := k.stateStore.BatchTable().GetByDenom(ctx, request.BatchDenom) if err != nil { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get batch with denom %s: %s", request.BatchDenom, err.Error()) + return nil, regenerrors.ErrInvalidArgument.Wrapf("could not get batch with denom %s: %s", request.BatchDenom, err.Error()) } supply, err := k.stateStore.BatchSupplyTable().Get(ctx, batch.Key) if err != nil { - return nil, err + return nil, regenerrors.ErrInvalidArgument.Wrapf("unable to get batch supply for batch: %s", batch.Denom) } return &types.QuerySupplyResponse{ diff --git a/x/ecocredit/base/keeper/query_supply_test.go b/x/ecocredit/base/keeper/query_supply_test.go index 6adc8f81d8..c3c7413bda 100644 --- a/x/ecocredit/base/keeper/query_supply_test.go +++ b/x/ecocredit/base/keeper/query_supply_test.go @@ -6,6 +6,7 @@ import ( "gotest.tools/v3/assert" "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" + "github.com/stretchr/testify/require" api "github.com/regen-network/regen-ledger/api/regen/ecocredit/v1" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" @@ -27,6 +28,12 @@ func TestQuery_Supply(t *testing.T) { StartDate: nil, EndDate: nil, })) + + // supply not found + _, err := s.k.Supply(s.ctx, &types.QuerySupplyRequest{BatchDenom: batchDenom}) + require.Error(t, err) + assert.Equal(t, "unable to get batch supply for batch: C01-001-20200101-20220101-001: invalid argument", err.Error()) + assert.NilError(t, s.stateStore.BatchSupplyTable().Insert(s.ctx, &api.BatchSupply{ BatchKey: 1, TradableAmount: tradable, diff --git a/x/ecocredit/base/simulation/msg_add_credit_type.go b/x/ecocredit/base/simulation/msg_add_credit_type.go index 846b7b2ccd..c07029f851 100644 --- a/x/ecocredit/base/simulation/msg_add_credit_type.go +++ b/x/ecocredit/base/simulation/msg_add_credit_type.go @@ -6,13 +6,13 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" simappparams "github.com/cosmos/cosmos-sdk/simapp/params" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/simulation" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/x/ecocredit" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" "github.com/regen-network/regen-ledger/x/ecocredit/simulation/utils" @@ -55,7 +55,7 @@ func SimulateMsgAddCreditType(ak ecocredit.AccountKeeper, bk ecocredit.BankKeepe Abbreviation: abbrev, }) if err != nil { - if !ormerrors.NotFound.Is(err) { + if !regenerrors.ErrNotFound.Is(err) { return simtypes.NoOpMsg(ecocredit.ModuleName, TypeMsgAddCreditType, err.Error()), nil, err } } diff --git a/x/ecocredit/base/simulation/operations.go b/x/ecocredit/base/simulation/operations.go index 0acb65a3ef..39ad183922 100644 --- a/x/ecocredit/base/simulation/operations.go +++ b/x/ecocredit/base/simulation/operations.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "math/rand" - "strings" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/orm/types/ormerrors" @@ -12,6 +11,7 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/cosmos/cosmos-sdk/x/simulation" + regenerrors "github.com/regen-network/regen-ledger/errors" "github.com/regen-network/regen-ledger/x/ecocredit" types "github.com/regen-network/regen-ledger/x/ecocredit/base/types/v1" baskettypes "github.com/regen-network/regen-ledger/x/ecocredit/basket/types/v1" @@ -298,7 +298,7 @@ func getRandomBatchFromProject(ctx context.Context, r *rand.Rand, qryClient type ProjectId: projectID, }) if err != nil { - if strings.Contains(err.Error(), ormerrors.NotFound.Error()) { + if regenerrors.ErrNotFound.Is(err) { return nil, simtypes.NoOpMsg(ecocredit.ModuleName, msgType, fmt.Sprintf("no credit batches for %s project", projectID)), nil } return nil, simtypes.NoOpMsg(ecocredit.ModuleName, msgType, err.Error()), err diff --git a/x/ecocredit/go.mod b/x/ecocredit/go.mod index 13957d18b4..8a6a8527c0 100644 --- a/x/ecocredit/go.mod +++ b/x/ecocredit/go.mod @@ -16,6 +16,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/regen-network/gocuke v0.6.2 github.com/regen-network/regen-ledger/api v0.8.0 + github.com/regen-network/regen-ledger/errors v0.0.0-00010101000000-000000000000 github.com/regen-network/regen-ledger/types v1.0.0 github.com/spf13/cobra v1.6.1 github.com/stretchr/testify v1.8.1 @@ -174,3 +175,5 @@ replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alp replace github.com/regen-network/regen-ledger/types => ../../types replace github.com/regen-network/regen-ledger/api => ../../api + +replace github.com/regen-network/regen-ledger/errors => ../../errors From 01e2a6a4eaeb6f8793b5fb864d0f264d415a8b2b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 15:34:09 -0700 Subject: [PATCH 7/7] build(deps): Bump github.com/cosmos/cosmos-sdk from 0.46.3 to 0.46.4 (#1584) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: ryanchristo <12519942+ryanchristo@users.noreply.github.com> --- go.mod | 4 ++-- go.sum | 8 ++++---- types/go.mod | 4 ++-- types/go.sum | 8 ++++---- x/data/go.mod | 4 ++-- x/data/go.sum | 8 ++++---- x/ecocredit/go.mod | 4 ++-- x/ecocredit/go.sum | 8 ++++---- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index 0f30e00006..ec7f437b19 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( cosmossdk.io/math v1.0.0-beta.3 - github.com/cosmos/cosmos-sdk v0.46.3 + github.com/cosmos/cosmos-sdk v0.46.4 github.com/cosmos/ibc-go/v5 v5.0.1 github.com/gorilla/mux v1.8.0 github.com/prometheus/client_golang v1.12.2 // indirect @@ -55,7 +55,7 @@ require ( github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogoproto v1.4.2 // indirect github.com/cosmos/gorocksdb v1.2.0 // indirect - github.com/cosmos/iavl v0.19.3 // indirect + github.com/cosmos/iavl v0.19.4 // indirect github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect github.com/cosmos/ledger-go v0.9.3 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect diff --git a/go.sum b/go.sum index f3d5f63487..abd5274416 100644 --- a/go.sum +++ b/go.sum @@ -235,8 +235,8 @@ github.com/cosmos/btcutil v1.0.4 h1:n7C2ngKXo7UC9gNyMNLbzqz7Asuf+7Qv4gnX/rOdQ44= github.com/cosmos/btcutil v1.0.4/go.mod h1:Ffqc8Hn6TJUdDgHBwIZLtrLQC1KdJ9jGJl/TvgUaxbU= github.com/cosmos/cosmos-proto v1.0.0-alpha8 h1:d3pCRuMYYvGA5bM0ZbbjKn+AoQD4A7dyNG2wzwWalUw= github.com/cosmos/cosmos-proto v1.0.0-alpha8/go.mod h1:6/p+Bc4O8JKeZqe0VqUGTX31eoYqemTT4C1hLCWsO7I= -github.com/cosmos/cosmos-sdk v0.46.3 h1:2jdJYcSwh4AtFJKGoNGvmEy2mKDWtGaVZphGpvedljQ= -github.com/cosmos/cosmos-sdk v0.46.3/go.mod h1:AynIAjXwtS3T/ApdhNCz/7/KGMbZSUBbKRTcbukb2ic= +github.com/cosmos/cosmos-sdk v0.46.4 h1:I4CPfnz7lAPM7cEvvyTxL1h3M/ugbhTNr5ZRcnW8WsU= +github.com/cosmos/cosmos-sdk v0.46.4/go.mod h1:b5usG7aBEEvhaatYCdV6orFbDUsj4BG1V6UtKwNcJeQ= github.com/cosmos/cosmos-sdk/api v0.1.0 h1:xfSKM0e9p+EJTMQnf5PbWE6VT8ruxTABIJ64Rd064dE= github.com/cosmos/cosmos-sdk/api v0.1.0/go.mod h1:CupqQBskAOiTXO1XDZ/wrtWzN/wTxUvbQmOqdUhR8wI= github.com/cosmos/cosmos-sdk/errors v1.0.0-beta.5 h1:9ebZL9/nCkaxer3kWWHs0YT8OOmHd7xohULM8Weep7M= @@ -252,8 +252,8 @@ github.com/cosmos/gogoproto v1.4.2 h1:UeGRcmFW41l0G0MiefWhkPEVEwvu78SZsHBvI78dAY github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= -github.com/cosmos/iavl v0.19.3 h1:cESO0OwTTxQm5rmyESKW+zESheDUYI7CcZDWWDwnuxg= -github.com/cosmos/iavl v0.19.3/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= +github.com/cosmos/iavl v0.19.4 h1:t82sN+Y0WeqxDLJRSpNd8YFX5URIrT+p8n6oJbJ2Dok= +github.com/cosmos/iavl v0.19.4/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= github.com/cosmos/ibc-go/v5 v5.0.1 h1:ZI5xCi6RDOL+hyu6Wx/w6JoAYFlOoK5hijsRTVWo+RA= github.com/cosmos/ibc-go/v5 v5.0.1/go.mod h1:LX0DHLW3dfi/1e4BJzi8MGLWmQ4DSraPEgVjyo3VzAo= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= diff --git a/types/go.mod b/types/go.mod index dac936ed34..c70f7de154 100644 --- a/types/go.mod +++ b/types/go.mod @@ -6,7 +6,7 @@ require ( cosmossdk.io/errors v1.0.0-beta.7 cosmossdk.io/math v1.0.0-beta.3 github.com/cockroachdb/apd/v2 v2.0.2 - github.com/cosmos/cosmos-sdk v0.46.3 + github.com/cosmos/cosmos-sdk v0.46.4 github.com/cosmos/cosmos-sdk/api v0.1.0 github.com/cosmos/cosmos-sdk/orm v1.0.0-alpha.12 github.com/gogo/protobuf v1.3.3 @@ -48,7 +48,7 @@ require ( github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gogoproto v1.4.2 // indirect github.com/cosmos/gorocksdb v1.2.0 // indirect - github.com/cosmos/iavl v0.19.3 // indirect + github.com/cosmos/iavl v0.19.4 // indirect github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect github.com/cosmos/ledger-go v0.9.3 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect diff --git a/types/go.sum b/types/go.sum index 082de7eee1..dba2704eb8 100644 --- a/types/go.sum +++ b/types/go.sum @@ -206,8 +206,8 @@ github.com/cosmos/btcutil v1.0.4 h1:n7C2ngKXo7UC9gNyMNLbzqz7Asuf+7Qv4gnX/rOdQ44= github.com/cosmos/btcutil v1.0.4/go.mod h1:Ffqc8Hn6TJUdDgHBwIZLtrLQC1KdJ9jGJl/TvgUaxbU= github.com/cosmos/cosmos-proto v1.0.0-alpha8 h1:d3pCRuMYYvGA5bM0ZbbjKn+AoQD4A7dyNG2wzwWalUw= github.com/cosmos/cosmos-proto v1.0.0-alpha8/go.mod h1:6/p+Bc4O8JKeZqe0VqUGTX31eoYqemTT4C1hLCWsO7I= -github.com/cosmos/cosmos-sdk v0.46.3 h1:2jdJYcSwh4AtFJKGoNGvmEy2mKDWtGaVZphGpvedljQ= -github.com/cosmos/cosmos-sdk v0.46.3/go.mod h1:AynIAjXwtS3T/ApdhNCz/7/KGMbZSUBbKRTcbukb2ic= +github.com/cosmos/cosmos-sdk v0.46.4 h1:I4CPfnz7lAPM7cEvvyTxL1h3M/ugbhTNr5ZRcnW8WsU= +github.com/cosmos/cosmos-sdk v0.46.4/go.mod h1:b5usG7aBEEvhaatYCdV6orFbDUsj4BG1V6UtKwNcJeQ= github.com/cosmos/cosmos-sdk/api v0.1.0 h1:xfSKM0e9p+EJTMQnf5PbWE6VT8ruxTABIJ64Rd064dE= github.com/cosmos/cosmos-sdk/api v0.1.0/go.mod h1:CupqQBskAOiTXO1XDZ/wrtWzN/wTxUvbQmOqdUhR8wI= github.com/cosmos/cosmos-sdk/errors v1.0.0-beta.5 h1:9ebZL9/nCkaxer3kWWHs0YT8OOmHd7xohULM8Weep7M= @@ -221,8 +221,8 @@ github.com/cosmos/gogoproto v1.4.2 h1:UeGRcmFW41l0G0MiefWhkPEVEwvu78SZsHBvI78dAY github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= -github.com/cosmos/iavl v0.19.3 h1:cESO0OwTTxQm5rmyESKW+zESheDUYI7CcZDWWDwnuxg= -github.com/cosmos/iavl v0.19.3/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= +github.com/cosmos/iavl v0.19.4 h1:t82sN+Y0WeqxDLJRSpNd8YFX5URIrT+p8n6oJbJ2Dok= +github.com/cosmos/iavl v0.19.4/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= github.com/cosmos/ledger-go v0.9.2/go.mod h1:oZJ2hHAZROdlHiwTg4t7kP+GKIIkBT+o6c9QWFanOyI= diff --git a/x/data/go.mod b/x/data/go.mod index e37fd15e9f..a50a0c874a 100644 --- a/x/data/go.mod +++ b/x/data/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( cosmossdk.io/errors v1.0.0-beta.7 github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce - github.com/cosmos/cosmos-sdk v0.46.3 + github.com/cosmos/cosmos-sdk v0.46.4 github.com/cosmos/cosmos-sdk/api v0.1.0 github.com/cosmos/cosmos-sdk/orm v1.0.0-alpha.12 github.com/gogo/protobuf v1.3.3 @@ -59,7 +59,7 @@ require ( github.com/cosmos/cosmos-sdk/errors v1.0.0-beta.5 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gorocksdb v1.2.0 // indirect - github.com/cosmos/iavl v0.19.3 // indirect + github.com/cosmos/iavl v0.19.4 // indirect github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect github.com/cosmos/ledger-go v0.9.3 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect diff --git a/x/data/go.sum b/x/data/go.sum index 8aee1dc8be..96d3b87304 100644 --- a/x/data/go.sum +++ b/x/data/go.sum @@ -241,8 +241,8 @@ github.com/cosmos/btcutil v1.0.4 h1:n7C2ngKXo7UC9gNyMNLbzqz7Asuf+7Qv4gnX/rOdQ44= github.com/cosmos/btcutil v1.0.4/go.mod h1:Ffqc8Hn6TJUdDgHBwIZLtrLQC1KdJ9jGJl/TvgUaxbU= github.com/cosmos/cosmos-proto v1.0.0-alpha8 h1:d3pCRuMYYvGA5bM0ZbbjKn+AoQD4A7dyNG2wzwWalUw= github.com/cosmos/cosmos-proto v1.0.0-alpha8/go.mod h1:6/p+Bc4O8JKeZqe0VqUGTX31eoYqemTT4C1hLCWsO7I= -github.com/cosmos/cosmos-sdk v0.46.3 h1:2jdJYcSwh4AtFJKGoNGvmEy2mKDWtGaVZphGpvedljQ= -github.com/cosmos/cosmos-sdk v0.46.3/go.mod h1:AynIAjXwtS3T/ApdhNCz/7/KGMbZSUBbKRTcbukb2ic= +github.com/cosmos/cosmos-sdk v0.46.4 h1:I4CPfnz7lAPM7cEvvyTxL1h3M/ugbhTNr5ZRcnW8WsU= +github.com/cosmos/cosmos-sdk v0.46.4/go.mod h1:b5usG7aBEEvhaatYCdV6orFbDUsj4BG1V6UtKwNcJeQ= github.com/cosmos/cosmos-sdk/api v0.1.0 h1:xfSKM0e9p+EJTMQnf5PbWE6VT8ruxTABIJ64Rd064dE= github.com/cosmos/cosmos-sdk/api v0.1.0/go.mod h1:CupqQBskAOiTXO1XDZ/wrtWzN/wTxUvbQmOqdUhR8wI= github.com/cosmos/cosmos-sdk/errors v1.0.0-beta.5 h1:9ebZL9/nCkaxer3kWWHs0YT8OOmHd7xohULM8Weep7M= @@ -255,8 +255,8 @@ github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4x github.com/cosmos/gogoproto v1.4.2 h1:UeGRcmFW41l0G0MiefWhkPEVEwvu78SZsHBvI78dAYw= github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= -github.com/cosmos/iavl v0.19.3 h1:cESO0OwTTxQm5rmyESKW+zESheDUYI7CcZDWWDwnuxg= -github.com/cosmos/iavl v0.19.3/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= +github.com/cosmos/iavl v0.19.4 h1:t82sN+Y0WeqxDLJRSpNd8YFX5URIrT+p8n6oJbJ2Dok= +github.com/cosmos/iavl v0.19.4/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= github.com/cosmos/ledger-go v0.9.2/go.mod h1:oZJ2hHAZROdlHiwTg4t7kP+GKIIkBT+o6c9QWFanOyI= diff --git a/x/ecocredit/go.mod b/x/ecocredit/go.mod index 8a6a8527c0..ce7e494ce9 100644 --- a/x/ecocredit/go.mod +++ b/x/ecocredit/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( cosmossdk.io/errors v1.0.0-beta.7 cosmossdk.io/math v1.0.0-beta.3 - github.com/cosmos/cosmos-sdk v0.46.3 + github.com/cosmos/cosmos-sdk v0.46.4 github.com/cosmos/cosmos-sdk/api v0.1.0 github.com/cosmos/cosmos-sdk/orm v1.0.0-alpha.12 github.com/cosmos/gogoproto v1.4.2 @@ -60,7 +60,7 @@ require ( github.com/cosmos/cosmos-sdk/errors v1.0.0-beta.5 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gorocksdb v1.2.0 // indirect - github.com/cosmos/iavl v0.19.3 // indirect + github.com/cosmos/iavl v0.19.4 // indirect github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect github.com/cosmos/ledger-go v0.9.3 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect diff --git a/x/ecocredit/go.sum b/x/ecocredit/go.sum index 0742083cd7..686d5ce5d8 100644 --- a/x/ecocredit/go.sum +++ b/x/ecocredit/go.sum @@ -241,8 +241,8 @@ github.com/cosmos/btcutil v1.0.4 h1:n7C2ngKXo7UC9gNyMNLbzqz7Asuf+7Qv4gnX/rOdQ44= github.com/cosmos/btcutil v1.0.4/go.mod h1:Ffqc8Hn6TJUdDgHBwIZLtrLQC1KdJ9jGJl/TvgUaxbU= github.com/cosmos/cosmos-proto v1.0.0-alpha8 h1:d3pCRuMYYvGA5bM0ZbbjKn+AoQD4A7dyNG2wzwWalUw= github.com/cosmos/cosmos-proto v1.0.0-alpha8/go.mod h1:6/p+Bc4O8JKeZqe0VqUGTX31eoYqemTT4C1hLCWsO7I= -github.com/cosmos/cosmos-sdk v0.46.3 h1:2jdJYcSwh4AtFJKGoNGvmEy2mKDWtGaVZphGpvedljQ= -github.com/cosmos/cosmos-sdk v0.46.3/go.mod h1:AynIAjXwtS3T/ApdhNCz/7/KGMbZSUBbKRTcbukb2ic= +github.com/cosmos/cosmos-sdk v0.46.4 h1:I4CPfnz7lAPM7cEvvyTxL1h3M/ugbhTNr5ZRcnW8WsU= +github.com/cosmos/cosmos-sdk v0.46.4/go.mod h1:b5usG7aBEEvhaatYCdV6orFbDUsj4BG1V6UtKwNcJeQ= github.com/cosmos/cosmos-sdk/api v0.1.0 h1:xfSKM0e9p+EJTMQnf5PbWE6VT8ruxTABIJ64Rd064dE= github.com/cosmos/cosmos-sdk/api v0.1.0/go.mod h1:CupqQBskAOiTXO1XDZ/wrtWzN/wTxUvbQmOqdUhR8wI= github.com/cosmos/cosmos-sdk/errors v1.0.0-beta.5 h1:9ebZL9/nCkaxer3kWWHs0YT8OOmHd7xohULM8Weep7M= @@ -256,8 +256,8 @@ github.com/cosmos/gogoproto v1.4.2 h1:UeGRcmFW41l0G0MiefWhkPEVEwvu78SZsHBvI78dAY github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU= github.com/cosmos/gorocksdb v1.2.0 h1:d0l3jJG8M4hBouIZq0mDUHZ+zjOx044J3nGRskwTb4Y= github.com/cosmos/gorocksdb v1.2.0/go.mod h1:aaKvKItm514hKfNJpUJXnnOWeBnk2GL4+Qw9NHizILw= -github.com/cosmos/iavl v0.19.3 h1:cESO0OwTTxQm5rmyESKW+zESheDUYI7CcZDWWDwnuxg= -github.com/cosmos/iavl v0.19.3/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= +github.com/cosmos/iavl v0.19.4 h1:t82sN+Y0WeqxDLJRSpNd8YFX5URIrT+p8n6oJbJ2Dok= +github.com/cosmos/iavl v0.19.4/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY= github.com/cosmos/ledger-go v0.9.2/go.mod h1:oZJ2hHAZROdlHiwTg4t7kP+GKIIkBT+o6c9QWFanOyI=