Skip to content

Commit

Permalink
added burning token message
Browse files Browse the repository at this point in the history
  • Loading branch information
faneaatiku committed Feb 9, 2024
1 parent 2091028 commit eff76fa
Show file tree
Hide file tree
Showing 19 changed files with 829 additions and 113 deletions.
2 changes: 2 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32342,6 +32342,8 @@ definitions:
admin:
type: string
title: 'Can be empty for no admin, or a valid osmosis address'
bze.tokenfactory.v1.MsgBurnResponse:
type: object
bze.tokenfactory.v1.MsgCreateDenomResponse:
type: object
properties:
Expand Down
12 changes: 10 additions & 2 deletions proto/tokenfactory/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ option go_package = "github.com/bze-alphateam/bze/x/tokenfactory/types";
service Msg {
rpc CreateDenom(MsgCreateDenom) returns (MsgCreateDenomResponse);
rpc Mint(MsgMint) returns (MsgMintResponse);
rpc Burn(MsgBurn) returns (MsgBurnResponse);
// this line is used by starport scaffolding # proto/tx/rpc
}

Expand All @@ -23,11 +24,18 @@ message MsgCreateDenomResponse {

message MsgMint {
string creator = 1;
string denom = 2;
string amount = 3;
string coins = 2;
}

message MsgMintResponse {
}

message MsgBurn {
string creator = 1;
string coins = 2;
}

message MsgBurnResponse {
}

// this line is used by starport scaffolding # proto/tx/message
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,18 @@ export default {
},


async sendMsgMint({ rootGetters }, { value, fee = [], memo = '' }) {
async sendMsgBurn({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgMint(value)
const msg = await txClient.msgBurn(value)
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
gas: "200000" }, memo})
return result
} catch (e) {
if (e == MissingWalletError) {
throw new Error('TxClient:MsgMint:Init Could not initialize signing client. Wallet is required.')
throw new Error('TxClient:MsgBurn:Init Could not initialize signing client. Wallet is required.')
}else{
throw new Error('TxClient:MsgMint:Send Could not broadcast Tx: '+ e.message)
throw new Error('TxClient:MsgBurn:Send Could not broadcast Tx: '+ e.message)
}
}
},
Expand All @@ -198,17 +198,32 @@ export default {
}
}
},

async MsgMint({ rootGetters }, { value }) {
async sendMsgMint({ rootGetters }, { value, fee = [], memo = '' }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgMint(value)
return msg
const result = await txClient.signAndBroadcast([msg], {fee: { amount: fee,
gas: "200000" }, memo})
return result
} catch (e) {
if (e == MissingWalletError) {
throw new Error('TxClient:MsgMint:Init Could not initialize signing client. Wallet is required.')
}else{
throw new Error('TxClient:MsgMint:Send Could not broadcast Tx: '+ e.message)
}
}
},

async MsgBurn({ rootGetters }, { value }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgBurn(value)
return msg
} catch (e) {
if (e == MissingWalletError) {
throw new Error('TxClient:MsgBurn:Init Could not initialize signing client. Wallet is required.')
} else{
throw new Error('TxClient:MsgMint:Create Could not create message: ' + e.message)
throw new Error('TxClient:MsgBurn:Create Could not create message: ' + e.message)
}
}
},
Expand All @@ -225,6 +240,19 @@ export default {
}
}
},
async MsgMint({ rootGetters }, { value }) {
try {
const txClient=await initTxClient(rootGetters)
const msg = await txClient.msgMint(value)
return msg
} catch (e) {
if (e == MissingWalletError) {
throw new Error('TxClient:MsgMint:Init Could not initialize signing client. Wallet is required.')
} else{
throw new Error('TxClient:MsgMint:Create Could not create message: ' + e.message)
}
}
},

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { StdFee } from "@cosmjs/launchpad";
import { SigningStargateClient } from "@cosmjs/stargate";
import { Registry, OfflineSigner, EncodeObject, DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { Api } from "./rest";
import { MsgMint } from "./types/tokenfactory/tx";
import { MsgBurn } from "./types/tokenfactory/tx";
import { MsgCreateDenom } from "./types/tokenfactory/tx";
import { MsgMint } from "./types/tokenfactory/tx";


const types = [
["/bze.tokenfactory.v1.MsgMint", MsgMint],
["/bze.tokenfactory.v1.MsgBurn", MsgBurn],
["/bze.tokenfactory.v1.MsgCreateDenom", MsgCreateDenom],
["/bze.tokenfactory.v1.MsgMint", MsgMint],

];
export const MissingWalletError = new Error("wallet is required");
Expand Down Expand Up @@ -43,8 +45,9 @@ const txClient = async (wallet: OfflineSigner, { addr: addr }: TxClientOptions =

return {
signAndBroadcast: (msgs: EncodeObject[], { fee, memo }: SignAndBroadcastOptions = {fee: defaultFee, memo: ""}) => client.signAndBroadcast(address, msgs, fee,memo),
msgMint: (data: MsgMint): EncodeObject => ({ typeUrl: "/bze.tokenfactory.v1.MsgMint", value: MsgMint.fromPartial( data ) }),
msgBurn: (data: MsgBurn): EncodeObject => ({ typeUrl: "/bze.tokenfactory.v1.MsgBurn", value: MsgBurn.fromPartial( data ) }),
msgCreateDenom: (data: MsgCreateDenom): EncodeObject => ({ typeUrl: "/bze.tokenfactory.v1.MsgCreateDenom", value: MsgCreateDenom.fromPartial( data ) }),
msgMint: (data: MsgMint): EncodeObject => ({ typeUrl: "/bze.tokenfactory.v1.MsgMint", value: MsgMint.fromPartial( data ) }),

};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface Tokenfactoryv1Params {
createDenomFee?: string;
}

export type V1MsgBurnResponse = object;

export interface V1MsgCreateDenomResponse {
new_denom?: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ export interface MsgCreateDenomResponse {

export interface MsgMint {
creator: string;
denom: string;
amount: string;
coins: string;
}

export interface MsgMintResponse {}

export interface MsgBurn {
creator: string;
coins: string;
}

export interface MsgBurnResponse {}

const baseMsgCreateDenom: object = { creator: "", subdenom: "" };

export const MsgCreateDenom = {
Expand Down Expand Up @@ -152,18 +158,15 @@ export const MsgCreateDenomResponse = {
},
};

const baseMsgMint: object = { creator: "", denom: "", amount: "" };
const baseMsgMint: object = { creator: "", coins: "" };

export const MsgMint = {
encode(message: MsgMint, writer: Writer = Writer.create()): Writer {
if (message.creator !== "") {
writer.uint32(10).string(message.creator);
}
if (message.denom !== "") {
writer.uint32(18).string(message.denom);
}
if (message.amount !== "") {
writer.uint32(26).string(message.amount);
if (message.coins !== "") {
writer.uint32(18).string(message.coins);
}
return writer;
},
Expand All @@ -179,10 +182,7 @@ export const MsgMint = {
message.creator = reader.string();
break;
case 2:
message.denom = reader.string();
break;
case 3:
message.amount = reader.string();
message.coins = reader.string();
break;
default:
reader.skipType(tag & 7);
Expand All @@ -199,24 +199,18 @@ export const MsgMint = {
} else {
message.creator = "";
}
if (object.denom !== undefined && object.denom !== null) {
message.denom = String(object.denom);
if (object.coins !== undefined && object.coins !== null) {
message.coins = String(object.coins);
} else {
message.denom = "";
}
if (object.amount !== undefined && object.amount !== null) {
message.amount = String(object.amount);
} else {
message.amount = "";
message.coins = "";
}
return message;
},

toJSON(message: MsgMint): unknown {
const obj: any = {};
message.creator !== undefined && (obj.creator = message.creator);
message.denom !== undefined && (obj.denom = message.denom);
message.amount !== undefined && (obj.amount = message.amount);
message.coins !== undefined && (obj.coins = message.coins);
return obj;
},

Expand All @@ -227,15 +221,10 @@ export const MsgMint = {
} else {
message.creator = "";
}
if (object.denom !== undefined && object.denom !== null) {
message.denom = object.denom;
} else {
message.denom = "";
}
if (object.amount !== undefined && object.amount !== null) {
message.amount = object.amount;
if (object.coins !== undefined && object.coins !== null) {
message.coins = object.coins;
} else {
message.amount = "";
message.coins = "";
}
return message;
},
Expand Down Expand Up @@ -279,11 +268,122 @@ export const MsgMintResponse = {
},
};

const baseMsgBurn: object = { creator: "", coins: "" };

export const MsgBurn = {
encode(message: MsgBurn, writer: Writer = Writer.create()): Writer {
if (message.creator !== "") {
writer.uint32(10).string(message.creator);
}
if (message.coins !== "") {
writer.uint32(18).string(message.coins);
}
return writer;
},

decode(input: Reader | Uint8Array, length?: number): MsgBurn {
const reader = input instanceof Uint8Array ? new Reader(input) : input;
let end = length === undefined ? reader.len : reader.pos + length;
const message = { ...baseMsgBurn } as MsgBurn;
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.creator = reader.string();
break;
case 2:
message.coins = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},

fromJSON(object: any): MsgBurn {
const message = { ...baseMsgBurn } as MsgBurn;
if (object.creator !== undefined && object.creator !== null) {
message.creator = String(object.creator);
} else {
message.creator = "";
}
if (object.coins !== undefined && object.coins !== null) {
message.coins = String(object.coins);
} else {
message.coins = "";
}
return message;
},

toJSON(message: MsgBurn): unknown {
const obj: any = {};
message.creator !== undefined && (obj.creator = message.creator);
message.coins !== undefined && (obj.coins = message.coins);
return obj;
},

fromPartial(object: DeepPartial<MsgBurn>): MsgBurn {
const message = { ...baseMsgBurn } as MsgBurn;
if (object.creator !== undefined && object.creator !== null) {
message.creator = object.creator;
} else {
message.creator = "";
}
if (object.coins !== undefined && object.coins !== null) {
message.coins = object.coins;
} else {
message.coins = "";
}
return message;
},
};

const baseMsgBurnResponse: object = {};

export const MsgBurnResponse = {
encode(_: MsgBurnResponse, writer: Writer = Writer.create()): Writer {
return writer;
},

decode(input: Reader | Uint8Array, length?: number): MsgBurnResponse {
const reader = input instanceof Uint8Array ? new Reader(input) : input;
let end = length === undefined ? reader.len : reader.pos + length;
const message = { ...baseMsgBurnResponse } as MsgBurnResponse;
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},

fromJSON(_: any): MsgBurnResponse {
const message = { ...baseMsgBurnResponse } as MsgBurnResponse;
return message;
},

toJSON(_: MsgBurnResponse): unknown {
const obj: any = {};
return obj;
},

fromPartial(_: DeepPartial<MsgBurnResponse>): MsgBurnResponse {
const message = { ...baseMsgBurnResponse } as MsgBurnResponse;
return message;
},
};

/** Msg defines the Msg service. */
export interface Msg {
CreateDenom(request: MsgCreateDenom): Promise<MsgCreateDenomResponse>;
/** this line is used by starport scaffolding # proto/tx/rpc */
Mint(request: MsgMint): Promise<MsgMintResponse>;
/** this line is used by starport scaffolding # proto/tx/rpc */
Burn(request: MsgBurn): Promise<MsgBurnResponse>;
}

export class MsgClientImpl implements Msg {
Expand All @@ -308,6 +408,12 @@ export class MsgClientImpl implements Msg {
const promise = this.rpc.request("bze.tokenfactory.v1.Msg", "Mint", data);
return promise.then((data) => MsgMintResponse.decode(new Reader(data)));
}

Burn(request: MsgBurn): Promise<MsgBurnResponse> {
const data = MsgBurn.encode(request).finish();
const promise = this.rpc.request("bze.tokenfactory.v1.Msg", "Burn", data);
return promise.then((data) => MsgBurnResponse.decode(new Reader(data)));
}
}

interface Rpc {
Expand Down
Loading

0 comments on commit eff76fa

Please sign in to comment.