github.com/KiraCore/sekai@v0.3.43/x/layer2/keeper/bridge_registrar.go (about) 1 package keeper 2 3 import ( 4 "github.com/KiraCore/sekai/x/layer2/types" 5 sdk "github.com/cosmos/cosmos-sdk/types" 6 ) 7 8 func (k Keeper) SetBridgeRegistrarHelper(ctx sdk.Context, helper types.BridgeRegistrarHelper) { 9 bz := k.cdc.MustMarshal(&helper) 10 store := ctx.KVStore(k.storeKey) 11 store.Set(types.BridgeRegistrarHelperKey, bz) 12 } 13 14 func (k Keeper) GetBridgeRegistrarHelper(ctx sdk.Context) types.BridgeRegistrarHelper { 15 store := ctx.KVStore(k.storeKey) 16 bz := store.Get(types.BridgeRegistrarHelperKey) 17 if bz == nil { 18 return types.BridgeRegistrarHelper{} 19 } 20 21 helper := types.BridgeRegistrarHelper{} 22 k.cdc.MustUnmarshal(bz, &helper) 23 return helper 24 } 25 26 func (k Keeper) SetBridgeAccount(ctx sdk.Context, account types.BridgeAccount) { 27 bz := k.cdc.MustMarshal(&account) 28 store := ctx.KVStore(k.storeKey) 29 store.Set(types.BridgeAccountKey(account.Index), bz) 30 } 31 32 func (k Keeper) GetBridgeAccount(ctx sdk.Context, index uint64) types.BridgeAccount { 33 store := ctx.KVStore(k.storeKey) 34 bz := store.Get(types.BridgeAccountKey(index)) 35 if bz == nil { 36 return types.BridgeAccount{} 37 } 38 39 account := types.BridgeAccount{} 40 k.cdc.MustUnmarshal(bz, &account) 41 return account 42 } 43 44 func (k Keeper) GetBridgeAccounts(ctx sdk.Context) []types.BridgeAccount { 45 store := ctx.KVStore(k.storeKey) 46 47 accounts := []types.BridgeAccount{} 48 it := sdk.KVStorePrefixIterator(store, []byte(types.PrefixBridgeAccountKey)) 49 defer it.Close() 50 51 for ; it.Valid(); it.Next() { 52 account := types.BridgeAccount{} 53 k.cdc.MustUnmarshal(it.Value(), &account) 54 accounts = append(accounts, account) 55 } 56 return accounts 57 } 58 59 func (k Keeper) SetBridgeToken(ctx sdk.Context, token types.BridgeToken) { 60 bz := k.cdc.MustMarshal(&token) 61 store := ctx.KVStore(k.storeKey) 62 store.Set(types.BridgeTokenKey(token.Index), bz) 63 } 64 65 func (k Keeper) GetBridgeToken(ctx sdk.Context, index uint64) types.BridgeToken { 66 store := ctx.KVStore(k.storeKey) 67 bz := store.Get(types.BridgeTokenKey(index)) 68 if bz == nil { 69 return types.BridgeToken{} 70 } 71 72 token := types.BridgeToken{} 73 k.cdc.MustUnmarshal(bz, &token) 74 return token 75 } 76 77 func (k Keeper) GetBridgeTokens(ctx sdk.Context) []types.BridgeToken { 78 store := ctx.KVStore(k.storeKey) 79 80 tokens := []types.BridgeToken{} 81 it := sdk.KVStorePrefixIterator(store, []byte(types.PrefixBridgeTokenKey)) 82 defer it.Close() 83 84 for ; it.Valid(); it.Next() { 85 token := types.BridgeToken{} 86 k.cdc.MustUnmarshal(it.Value(), &token) 87 tokens = append(tokens, token) 88 } 89 return tokens 90 } 91 92 func (k Keeper) SetXAM(ctx sdk.Context, xam types.XAM) { 93 bz := k.cdc.MustMarshal(&xam) 94 store := ctx.KVStore(k.storeKey) 95 store.Set(types.XAMKey(xam.Res.Xid), bz) 96 } 97 98 func (k Keeper) GetXAM(ctx sdk.Context, xid uint64) types.XAM { 99 store := ctx.KVStore(k.storeKey) 100 bz := store.Get(types.XAMKey(xid)) 101 if bz == nil { 102 return types.XAM{} 103 } 104 105 xam := types.XAM{} 106 k.cdc.MustUnmarshal(bz, &xam) 107 return xam 108 } 109 110 func (k Keeper) GetXAMs(ctx sdk.Context) []types.XAM { 111 store := ctx.KVStore(k.storeKey) 112 113 xams := []types.XAM{} 114 it := sdk.KVStorePrefixIterator(store, []byte(types.PrefixXAMKey)) 115 defer it.Close() 116 117 for ; it.Valid(); it.Next() { 118 xam := types.XAM{} 119 k.cdc.MustUnmarshal(it.Value(), &xam) 120 xams = append(xams, xam) 121 } 122 return xams 123 }