From 2e3f582003a2cf84d8b90376874ee11a6fb318d8 Mon Sep 17 00:00:00 2001 From: Marston Connell <34043723+TheMarstonConnell@users.noreply.github.com> Date: Mon, 29 Aug 2022 18:53:33 -0400 Subject: [PATCH] error checking --- .../index.ts | 32 +++++++++---------- .../module/index.ts | 6 ++-- x/cookies/keeper/msg_server_buy_building.go | 7 ++-- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/vue/src/store/generated/TheMarstonConnell/cookies/TheMarstonConnell.cookies.cookies/index.ts b/vue/src/store/generated/TheMarstonConnell/cookies/TheMarstonConnell.cookies.cookies/index.ts index b197ae9..5e8753f 100755 --- a/vue/src/store/generated/TheMarstonConnell/cookies/TheMarstonConnell.cookies.cookies/index.ts +++ b/vue/src/store/generated/TheMarstonConnell/cookies/TheMarstonConnell.cookies.cookies/index.ts @@ -228,60 +228,60 @@ export default { }, - async sendMsgBake({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgBuyBuilding({ rootGetters }, { value, fee = [], memo = '' }) { try { const txClient=await initTxClient(rootGetters) - const msg = await txClient.msgBake(value) + const msg = await txClient.msgBuyBuilding(value) const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee, gas: "200000" }, memo}) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgBake:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgBuyBuilding:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgBake:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgBuyBuilding:Send Could not broadcast Tx: '+ e.message) } } }, - async sendMsgBuyBuilding({ rootGetters }, { value, fee = [], memo = '' }) { + async sendMsgBake({ rootGetters }, { value, fee = [], memo = '' }) { try { const txClient=await initTxClient(rootGetters) - const msg = await txClient.msgBuyBuilding(value) + const msg = await txClient.msgBake(value) const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee, gas: "200000" }, memo}) return result } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgBuyBuilding:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgBake:Init Could not initialize signing client. Wallet is required.') }else{ - throw new Error('TxClient:MsgBuyBuilding:Send Could not broadcast Tx: '+ e.message) + throw new Error('TxClient:MsgBake:Send Could not broadcast Tx: '+ e.message) } } }, - async MsgBake({ rootGetters }, { value }) { + async MsgBuyBuilding({ rootGetters }, { value }) { try { const txClient=await initTxClient(rootGetters) - const msg = await txClient.msgBake(value) + const msg = await txClient.msgBuyBuilding(value) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgBake:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgBuyBuilding:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgBake:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgBuyBuilding:Create Could not create message: ' + e.message) } } }, - async MsgBuyBuilding({ rootGetters }, { value }) { + async MsgBake({ rootGetters }, { value }) { try { const txClient=await initTxClient(rootGetters) - const msg = await txClient.msgBuyBuilding(value) + const msg = await txClient.msgBake(value) return msg } catch (e) { if (e == MissingWalletError) { - throw new Error('TxClient:MsgBuyBuilding:Init Could not initialize signing client. Wallet is required.') + throw new Error('TxClient:MsgBake:Init Could not initialize signing client. Wallet is required.') } else{ - throw new Error('TxClient:MsgBuyBuilding:Create Could not create message: ' + e.message) + throw new Error('TxClient:MsgBake:Create Could not create message: ' + e.message) } } }, diff --git a/vue/src/store/generated/TheMarstonConnell/cookies/TheMarstonConnell.cookies.cookies/module/index.ts b/vue/src/store/generated/TheMarstonConnell/cookies/TheMarstonConnell.cookies.cookies/module/index.ts index bbab490..bf6098c 100755 --- a/vue/src/store/generated/TheMarstonConnell/cookies/TheMarstonConnell.cookies.cookies/module/index.ts +++ b/vue/src/store/generated/TheMarstonConnell/cookies/TheMarstonConnell.cookies.cookies/module/index.ts @@ -4,13 +4,13 @@ import { StdFee } from "@cosmjs/launchpad"; import { SigningStargateClient } from "@cosmjs/stargate"; import { Registry, OfflineSigner, EncodeObject, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; import { Api } from "./rest"; -import { MsgBake } from "./types/cookies/tx"; import { MsgBuyBuilding } from "./types/cookies/tx"; +import { MsgBake } from "./types/cookies/tx"; const types = [ - ["/TheMarstonConnell.cookies.cookies.MsgBake", MsgBake], ["/TheMarstonConnell.cookies.cookies.MsgBuyBuilding", MsgBuyBuilding], + ["/TheMarstonConnell.cookies.cookies.MsgBake", MsgBake], ]; export const MissingWalletError = new Error("wallet is required"); @@ -43,8 +43,8 @@ const txClient = async (wallet: OfflineSigner, { addr: addr }: TxClientOptions = return { signAndBroadcast: (msgs: EncodeObject[], { fee, memo }: SignAndBroadcastOptions = {fee: defaultFee, memo: ""}) => client.signAndBroadcast(address, msgs, fee,memo), - msgBake: (data: MsgBake): EncodeObject => ({ typeUrl: "/TheMarstonConnell.cookies.cookies.MsgBake", value: MsgBake.fromPartial( data ) }), msgBuyBuilding: (data: MsgBuyBuilding): EncodeObject => ({ typeUrl: "/TheMarstonConnell.cookies.cookies.MsgBuyBuilding", value: MsgBuyBuilding.fromPartial( data ) }), + msgBake: (data: MsgBake): EncodeObject => ({ typeUrl: "/TheMarstonConnell.cookies.cookies.MsgBake", value: MsgBake.fromPartial( data ) }), }; }; diff --git a/x/cookies/keeper/msg_server_buy_building.go b/x/cookies/keeper/msg_server_buy_building.go index 532a28e..2aa4df8 100644 --- a/x/cookies/keeper/msg_server_buy_building.go +++ b/x/cookies/keeper/msg_server_buy_building.go @@ -10,14 +10,15 @@ import ( func (k msgServer) BuyBuilding(goCtx context.Context, msg *types.MsgBuyBuilding) (*types.MsgBuyBuildingResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - // TODO: Handling the message - _ = ctx - building, ok := sdk.NewIntFromString(msg.Building) if !ok { return nil, types.ErrNoParse } + if building.Int64() > 7 || building.Int64() < 0 { + return nil, types.ErrNoParse + } + address, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { return nil, err