Julian Strobl d4eed021c8
[go.mod] Switch module to github.com (#86)
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>
2023-09-21 17:37:57 +02:00

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
}