diff --git a/x/ecocredit/base/keeper/msg_cancel.go b/x/ecocredit/base/keeper/msg_cancel.go index 08bf05abc6..6bece70c92 100644 --- a/x/ecocredit/base/keeper/msg_cancel.go +++ b/x/ecocredit/base/keeper/msg_cancel.go @@ -26,7 +26,7 @@ func (k Keeper) Cancel(ctx context.Context, req *types.MsgCancel) (*types.MsgCan if err != nil { return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get batch with denom %s: %s", credit.BatchDenom, err.Error()) } - creditType, err := utils.GetCreditTypeFromBatchDenom(ctx, k.stateStore, batch) + creditType, err := utils.GetCreditTypeFromBatch(ctx, k.stateStore, batch) if err != nil { return nil, err } diff --git a/x/ecocredit/base/keeper/msg_mint_batch_credits.go b/x/ecocredit/base/keeper/msg_mint_batch_credits.go index a5e5664008..23fe9dda70 100644 --- a/x/ecocredit/base/keeper/msg_mint_batch_credits.go +++ b/x/ecocredit/base/keeper/msg_mint_batch_credits.go @@ -39,7 +39,7 @@ func (k Keeper) MintBatchCredits(ctx context.Context, req *types.MsgMintBatchCre return nil, err } - ct, err := utils.GetCreditTypeFromBatchDenom(ctx, k.stateStore, batch) + ct, err := utils.GetCreditTypeFromBatch(ctx, k.stateStore, batch) if err != nil { return nil, err } diff --git a/x/ecocredit/base/keeper/msg_retire.go b/x/ecocredit/base/keeper/msg_retire.go index d0c8bcbaf4..1f52b489ae 100644 --- a/x/ecocredit/base/keeper/msg_retire.go +++ b/x/ecocredit/base/keeper/msg_retire.go @@ -24,7 +24,7 @@ func (k Keeper) Retire(ctx context.Context, req *types.MsgRetire) (*types.MsgRet if err != nil { return nil, sdkerrors.ErrInvalidRequest.Wrapf("could not get batch with denom %s: %s", credit.BatchDenom, err.Error()) } - creditType, err := utils.GetCreditTypeFromBatchDenom(ctx, k.stateStore, batch) + creditType, err := utils.GetCreditTypeFromBatch(ctx, k.stateStore, batch) if err != nil { return nil, err } diff --git a/x/ecocredit/base/keeper/msg_send.go b/x/ecocredit/base/keeper/msg_send.go index fda0779b33..7a07bb584f 100644 --- a/x/ecocredit/base/keeper/msg_send.go +++ b/x/ecocredit/base/keeper/msg_send.go @@ -32,7 +32,7 @@ func (k Keeper) Send(ctx context.Context, req *types.MsgSend) (*types.MsgSendRes } // get credit type precision - creditType, err := utils.GetCreditTypeFromBatchDenom(ctx, k.stateStore, batch) + creditType, err := utils.GetCreditTypeFromBatch(ctx, k.stateStore, batch) if err != nil { return nil, err } diff --git a/x/ecocredit/marketplace/keeper/msg_buy_direct.go b/x/ecocredit/marketplace/keeper/msg_buy_direct.go index 3e5fb306dc..45e76da594 100644 --- a/x/ecocredit/marketplace/keeper/msg_buy_direct.go +++ b/x/ecocredit/marketplace/keeper/msg_buy_direct.go @@ -55,7 +55,7 @@ func (k Keeper) BuyDirect(ctx context.Context, req *types.MsgBuyDirect) (*types. if err != nil { return nil, err } - ct, err := utils.GetCreditTypeFromBatchDenom(ctx, k.baseStore, batch) + ct, err := utils.GetCreditTypeFromBatch(ctx, k.baseStore, batch) if err != nil { return nil, err } diff --git a/x/ecocredit/marketplace/keeper/msg_sell.go b/x/ecocredit/marketplace/keeper/msg_sell.go index e358ebac9d..fae230617a 100644 --- a/x/ecocredit/marketplace/keeper/msg_sell.go +++ b/x/ecocredit/marketplace/keeper/msg_sell.go @@ -40,7 +40,7 @@ func (k Keeper) Sell(ctx context.Context, req *types.MsgSell) (*types.MsgSellRes ) } - creditType, err := utils.GetCreditTypeFromBatchDenom(ctx, k.baseStore, batch) + creditType, err := utils.GetCreditTypeFromBatch(ctx, k.baseStore, batch) if err != nil { return nil, err } diff --git a/x/ecocredit/marketplace/keeper/msg_update_sell_orders.go b/x/ecocredit/marketplace/keeper/msg_update_sell_orders.go index 05b95cfee0..bdb44faed5 100644 --- a/x/ecocredit/marketplace/keeper/msg_update_sell_orders.go +++ b/x/ecocredit/marketplace/keeper/msg_update_sell_orders.go @@ -178,7 +178,7 @@ func (k Keeper) getCreditTypeFromBatchKey(ctx context.Context, key uint64) (*bas if err != nil { return nil, err } - creditType, err := utils.GetCreditTypeFromBatchDenom(ctx, k.baseStore, batch) + creditType, err := utils.GetCreditTypeFromBatch(ctx, k.baseStore, batch) if err != nil { return nil, err } diff --git a/x/ecocredit/server/utils/utils.go b/x/ecocredit/server/utils/utils.go index 251c9a647d..c1663c9557 100644 --- a/x/ecocredit/server/utils/utils.go +++ b/x/ecocredit/server/utils/utils.go @@ -10,8 +10,10 @@ import ( "github.com/regen-network/regen-ledger/types/v2/math" ) -// GetCreditTypeFromBatchDenom extracts the classID from a batch denom string, then retrieves it from the params. -func GetCreditTypeFromBatchDenom(ctx context.Context, store api.StateStore, batch *api.Batch) (*api.CreditType, error) { +// GetCreditTypeFromBatch extracts the credit type from a batch by querying the class table for the class key, and then +// querying the credit type table for the credit type abbreviation. This is a convenience function for use in message +// handlers, where the credit type is needed to perform further operations on the batch. +func GetCreditTypeFromBatch(ctx context.Context, store api.StateStore, batch *api.Batch) (*api.CreditType, error) { cls, err := store.ClassTable().Get(ctx, batch.ClassKey) if err != nil { return nil, err diff --git a/x/ecocredit/server/utils/utils_test.go b/x/ecocredit/server/utils/utils_test.go index 3867631245..2ed39a3619 100644 --- a/x/ecocredit/server/utils/utils_test.go +++ b/x/ecocredit/server/utils/utils_test.go @@ -115,7 +115,7 @@ func TestUtils_GetCreditTypeFromBatchDenom(t *testing.T) { ClassKey: clsKey, } assert.NilError(t, s.stateStore.BatchTable().Insert(s.ctx, batch)) - ct, err := GetCreditTypeFromBatchDenom(s.ctx, s.stateStore, batch) + ct, err := GetCreditTypeFromBatch(s.ctx, s.stateStore, batch) assert.NilError(t, err) assert.DeepEqual(t, ct, creditType, cmpopts.IgnoreUnexported(api.CreditType{})) }