Skip to content

Commit

Permalink
error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Aug 29, 2022
1 parent 3040c2a commit 2e3f582
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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 ) }),

};
};
Expand Down
7 changes: 4 additions & 3 deletions x/cookies/keeper/msg_server_buy_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2e3f582

Please sign in to comment.