Skip to content

Commit

Permalink
fix: fix collections init issue
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed May 3, 2024
1 parent 62cfbab commit d4c1e91
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
15 changes: 4 additions & 11 deletions scripts/testnet/create_genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,10 @@ if [ ${#MONIKERS[@]} -ne 0 ]; then

VALIDATOR_ADDRESS=$($LOCAL_BIN keys show ${MONIKERS[$i]} --keyring-backend test --home $INDIVIDUAL_VAL_HOME_DIR -a)

if [ -z ${VESTING_AMOUNTS[$i]} ]; then
# to create their gentx
$LOCAL_BIN add-genesis-account $VALIDATOR_ADDRESS ${SELF_DELEGATION_AMOUNTS[$i]} --home $INDIVIDUAL_VAL_HOME_DIR
# to output geneis file
$LOCAL_BIN add-genesis-account $VALIDATOR_ADDRESS ${SELF_DELEGATION_AMOUNTS[$i]}
else
# to create their gentx
$LOCAL_BIN add-genesis-account $VALIDATOR_ADDRESS ${SELF_DELEGATION_AMOUNTS[$i]} --home $INDIVIDUAL_VAL_HOME_DIR --vesting-amount ${VESTING_AMOUNTS[$i]} --vesting-start-time 1708610400 --vesting-end-time 1716386400 --funder $FUNDER_ADDRESS
# to output geneis file
$LOCAL_BIN add-genesis-account $VALIDATOR_ADDRESS ${SELF_DELEGATION_AMOUNTS[$i]} --vesting-amount ${VESTING_AMOUNTS[$i]} --vesting-start-time 1708610400 --vesting-end-time 1716386400 --funder $FUNDER_ADDRESS
fi
# to create their gentx
$LOCAL_BIN add-genesis-account $VALIDATOR_ADDRESS ${SELF_DELEGATION_AMOUNTS[$i]} --home $INDIVIDUAL_VAL_HOME_DIR
# to output geneis file
$LOCAL_BIN add-genesis-account $VALIDATOR_ADDRESS ${SELF_DELEGATION_AMOUNTS[$i]}

$LOCAL_BIN gentx ${MONIKERS[$i]} ${SELF_DELEGATION_AMOUNTS[$i]} --moniker=${MONIKERS[$i]} --keyring-backend=test --home $INDIVIDUAL_VAL_HOME_DIR --ip=${IPS[$i]} --chain-id $CHAIN_ID

Expand Down
13 changes: 9 additions & 4 deletions x/wasm-storage/genesis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package wasmstorage

import (
"errors"

"cosmossdk.io/collections"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sedaprotocol/seda-chain/x/wasm-storage/keeper"
Expand Down Expand Up @@ -31,7 +34,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, data types.GenesisState) {
if err != nil {
panic(err)
}
err = k.ProxyContractRegistry.Set(ctx, proxyAddr)
err = k.ProxyContractRegistry.Set(ctx, proxyAddr.String())
if err != nil {
panic(err)
}
Expand All @@ -43,8 +46,10 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState {
wasms := k.GetAllWasms(ctx)
proxy, err := k.ProxyContractRegistry.Get(ctx)
if err != nil {
return types.NewGenesisState(wasms, "")
if errors.Is(err, collections.ErrNotFound) {
return types.NewGenesisState(wasms, "")
}
panic(err)
}
accAddress := sdk.AccAddress(proxy).String()
return types.NewGenesisState(wasms, accAddress)
return types.NewGenesisState(wasms, proxy)
}
21 changes: 12 additions & 9 deletions x/wasm-storage/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import (
var (
// DataRequestPrefix defines prefix to store Data Request Wasm binaries.
DataRequestPrefix = collections.NewPrefix(0)

// OverlayPrefix defines prefix to store Overlay Wasm binaries.
OverlayPrefix = collections.NewPrefix(1)

ParamsPrefix = collections.NewPrefix(2)
// ProxyContractRegistryPrefix defines prefix to store address of
// Proxy Contract.
ProxyContractRegistryPrefix = collections.NewPrefix(2)
// ParamsPrefix defines prefix to store parameters of wasm-storage module.
ParamsPrefix = collections.NewPrefix(3)
)

func GetDataRequestWasmKeyPrefixFull(hash []byte) []byte {
Expand All @@ -40,19 +42,20 @@ type Keeper struct {
Schema collections.Schema
DataRequestWasm collections.Map[[]byte, types.Wasm]
OverlayWasm collections.Map[[]byte, types.Wasm]
ProxyContractRegistry collections.Item[[]byte]
ProxyContractRegistry collections.Item[string]
Params collections.Item[types.Params]
}

func NewKeeper(cdc codec.BinaryCodec, storeService storetypes.KVStoreService, authority string, wk wasmtypes.ContractOpsKeeper) *Keeper {
sb := collections.NewSchemaBuilder(storeService)

return &Keeper{
authority: authority,
wasmKeeper: wk,
DataRequestWasm: collections.NewMap(sb, DataRequestPrefix, "data-request-wasm", collections.BytesKey, codec.CollValue[types.Wasm](cdc)),
OverlayWasm: collections.NewMap(sb, OverlayPrefix, "overlay-wasm", collections.BytesKey, codec.CollValue[types.Wasm](cdc)),
Params: collections.NewItem(sb, ParamsPrefix, "params", codec.CollValue[types.Params](cdc)),
authority: authority,
wasmKeeper: wk,
DataRequestWasm: collections.NewMap(sb, DataRequestPrefix, "data-request-wasm", collections.BytesKey, codec.CollValue[types.Wasm](cdc)),
OverlayWasm: collections.NewMap(sb, OverlayPrefix, "overlay-wasm", collections.BytesKey, codec.CollValue[types.Wasm](cdc)),
ProxyContractRegistry: collections.NewItem(sb, ProxyContractRegistryPrefix, "proxy-contract-registry", collections.StringValue),
Params: collections.NewItem(sb, ParamsPrefix, "params", codec.CollValue[types.Params](cdc)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/wasm-storage/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (m msgServer) InstantiateAndRegisterProxyContract(goCtx context.Context, ms
}

// update Proxy Contract registry
err = m.ProxyContractRegistry.Set(ctx, contractAddr)
err = m.ProxyContractRegistry.Set(ctx, contractAddr.String())
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d4c1e91

Please sign in to comment.