mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00

This is the quasi-standard and fixes the error below: ``` $ go get -u github.com/planetmint/planetmint-go@v0.1.0 go: github.com/planetmint/planetmint-go@v0.1.0: parsing go.mod: module declares its path as: planetmint-go but was required as: github.com/planetmint/planetmint-go ``` Signed-off-by: Julian Strobl <jmastr@mailbox.org>
30 lines
809 B
Go
30 lines
809 B
Go
package keeper
|
|
|
|
import (
|
|
"github.com/planetmint/planetmint-go/x/asset/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/store/prefix"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
func (k Keeper) StoreAsset(ctx sdk.Context, asset types.Asset) {
|
|
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AssetKey))
|
|
appendValue := k.cdc.MustMarshal(&asset)
|
|
store.Set(GetAssetHashBytes(asset.Hash), appendValue)
|
|
}
|
|
|
|
func (k Keeper) GetAsset(ctx sdk.Context, hash string) (val types.Asset, found bool) {
|
|
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.AssetKey))
|
|
asset := store.Get(GetAssetHashBytes(hash))
|
|
if asset == nil {
|
|
return val, false
|
|
}
|
|
k.cdc.MustUnmarshal(asset, &val)
|
|
return val, true
|
|
}
|
|
|
|
func GetAssetHashBytes(hash string) []byte {
|
|
bz := []byte(hash)
|
|
return bz
|
|
}
|