mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-05 21:56:45 +00:00

* add mint address to config file * ignite scaffold type mint-request beneficiary amount liquid-tx-hash --module dao * add mintrequest stores * rename mint_request.go * add unit tests for mint request store * ignite scaffold message mint-token mint-request:MintRequest --module dao * add ante handler for mint address * add msg validation for mint request * fix staticcheck error * ignite scaffold query get-mint-requests-by-hash hash --response mint-request:MintRequest --module dao * add a query for mint request and additional validation for msg server * add mock for mint unit testing * add unit test for mint token msg server * add unit tests for query mint requests by hash * ignite scaffold query mint-requests-by-address address --response mint-requests:MintRequests --module dao * implement query mint requests by address and unit tests * add e2e test for token mint --------- Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
46 lines
1.7 KiB
Go
46 lines
1.7 KiB
Go
package keeper
|
|
|
|
import (
|
|
"github.com/cosmos/cosmos-sdk/store/prefix"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/planetmint/planetmint-go/x/dao/types"
|
|
)
|
|
|
|
func (k Keeper) StoreMintRequest(ctx sdk.Context, mintRequest types.MintRequest) {
|
|
hashStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MintRequestHashKey))
|
|
hashAppendValue := k.cdc.MustMarshal(&mintRequest)
|
|
hashStore.Set(getMintRequestKeyBytes(mintRequest.LiquidTxHash), hashAppendValue)
|
|
|
|
addressStore := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MintRequestAddressKey))
|
|
mintRequests, _ := k.GetMintRequestsByAddress(ctx, mintRequest.Beneficiary)
|
|
mintRequests.Requests = append(mintRequests.Requests, &mintRequest)
|
|
addressAppendValue := k.cdc.MustMarshal(&mintRequests)
|
|
addressStore.Set(getMintRequestKeyBytes(mintRequest.Beneficiary), addressAppendValue)
|
|
|
|
}
|
|
|
|
func (k Keeper) GetMintRequestsByAddress(ctx sdk.Context, address string) (val types.MintRequests, found bool) {
|
|
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MintRequestAddressKey))
|
|
mintRequests := store.Get(getMintRequestKeyBytes(address))
|
|
if mintRequests == nil {
|
|
return val, false
|
|
}
|
|
k.cdc.MustUnmarshal(mintRequests, &val)
|
|
return val, true
|
|
}
|
|
|
|
func (k Keeper) GetMintRequestByHash(ctx sdk.Context, hash string) (val types.MintRequest, found bool) {
|
|
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.MintRequestHashKey))
|
|
mintRequest := store.Get(getMintRequestKeyBytes(hash))
|
|
if mintRequest == nil {
|
|
return val, false
|
|
}
|
|
k.cdc.MustUnmarshal(mintRequest, &val)
|
|
return val, true
|
|
}
|
|
|
|
func getMintRequestKeyBytes(key string) []byte {
|
|
bz := []byte(key)
|
|
return bz
|
|
}
|