Skip to content

Commit

Permalink
Merge branch 'master' into workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
huanxiangspace committed Jul 19, 2024
2 parents 1dc7481 + ee8f07a commit 3a7a482
Show file tree
Hide file tree
Showing 58 changed files with 1,954 additions and 7,965 deletions.
6 changes: 3 additions & 3 deletions blockchain/proto/iconlake/icon/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ message MsgUpdateClass {
message MsgUpdateClassResponse {}

message MsgBurn {
string creator = 1;
string classId = 2;
string id = 3;
string creator = 1;
string class_id = 2;
string id = 3;
}

message MsgBurnResponse {}
9 changes: 9 additions & 0 deletions blockchain/ts-client/amino.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createDropAminoConverters } from "./iconlake.drop/types/iconlake/drop/tx";
import { createIconAminoConverters } from "./iconlake.icon/types/iconlake/icon/tx";

export function createIconlakeAminoConverters() {
return {
...createIconAminoConverters(),
...createDropAminoConverters(),
}
}
152 changes: 63 additions & 89 deletions blockchain/ts-client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import {
Registry,
} from "@cosmjs/proto-signing";
import { StdFee } from "@cosmjs/launchpad";
import { SigningStargateClient } from "@cosmjs/stargate";
import { AminoTypes, SigningStargateClient } from "@cosmjs/stargate";
import { Env } from "./env";
import { UnionToIntersection, Return, Constructor } from "./helpers";
import { Module } from "./modules";
import { EventEmitter } from "events";
import { ChainInfo } from "@keplr-wallet/types";
import { createIconlakeAminoConverters } from "./amino";

const defaultFee = {
amount: [],
Expand All @@ -23,6 +24,7 @@ export class IgniteClient extends EventEmitter {
env: Env;
signer?: OfflineSigner;
registry: Array<[string, GeneratedType]> = [];
aminoTypes: AminoTypes;
static plugin<T extends Module | Module[]>(plugin: T) {
const currentPlugins = this.plugins;

Expand All @@ -42,7 +44,7 @@ export class IgniteClient extends EventEmitter {
async signAndBroadcast(msgs: EncodeObject[], fee: StdFee, memo: string) {
if (this.signer) {
const { address } = (await this.signer.getAccounts())[0];
const signingClient = await SigningStargateClient.connectWithSigner(this.env.rpcURL, this.signer, { registry: new Registry(this.registry), prefix: this.env.prefix });
const signingClient = await SigningStargateClient.connectWithSigner(this.env.rpcURL, this.signer, { registry: new Registry(this.registry), prefix: this.env.prefix, aminoTypes: this.aminoTypes });
return await signingClient.signAndBroadcast(address, msgs, fee ? fee : defaultFee, memo)
} else {
throw new Error(" Signer is not present.");
Expand All @@ -61,7 +63,8 @@ export class IgniteClient extends EventEmitter {
if (this.registry) {
this.registry = this.registry.concat(pluginInstance.registry)
}
});
});
this.aminoTypes = new AminoTypes(createIconlakeAminoConverters());
}
useSigner(signer: OfflineSigner) {
this.signer = signer;
Expand All @@ -72,100 +75,71 @@ export class IgniteClient extends EventEmitter {
this.emit("signer-changed", this.signer);
}
async useKeplr(keplrChainInfo: Partial<ChainInfo> = {}) {
// Using queryClients directly because BaseClient has no knowledge of the modules at this stage
try {
const queryClient = (
await import("./cosmos.base.tendermint.v1beta1/module")
).queryClient;
const bankQueryClient = (await import("./cosmos.bank.v1beta1/module"))
.queryClient;

const stakingQueryClient = (await import("./cosmos.staking.v1beta1/module")).queryClient;
const stakingqc = stakingQueryClient({ addr: this.env.apiURL });
const staking = await (await stakingqc.queryParams()).data;

const qc = queryClient({ addr: this.env.apiURL });
const node_info = await (await qc.serviceGetNodeInfo()).data;
const chainId = node_info.default_node_info?.network ?? "";
const chainName = chainId?.toUpperCase() + " Network";
const bankqc = bankQueryClient({ addr: this.env.apiURL });
const tokens = await (await bankqc.queryTotalSupply()).data;
const addrPrefix = this.env.prefix ?? "cosmos";
const rpc = this.env.rpcURL;
const rest = this.env.apiURL;
const chainId = "iconlake-1";
const chainName = "iconLake";
const addrPrefix = this.env.prefix ?? "iconlake";
const rpc = this.env.rpcURL;
const rest = this.env.apiURL;

let bip44 = {
coinType: 1009,
};
let bip44 = {
coinType: 1009,
};

let bech32Config = {
bech32PrefixAccAddr: addrPrefix,
bech32PrefixAccPub: addrPrefix + "pub",
bech32PrefixValAddr: addrPrefix + "valoper",
bech32PrefixValPub: addrPrefix + "valoperpub",
bech32PrefixConsAddr: addrPrefix + "valcons",
bech32PrefixConsPub: addrPrefix + "valconspub",
};
let bech32Config = {
bech32PrefixAccAddr: addrPrefix,
bech32PrefixAccPub: addrPrefix + "pub",
bech32PrefixValAddr: addrPrefix + "valoper",
bech32PrefixValPub: addrPrefix + "valoperpub",
bech32PrefixConsAddr: addrPrefix + "valcons",
bech32PrefixConsPub: addrPrefix + "valconspub",
};

let currencies =
tokens.supply?.map((x) => {
const y = {
coinDenom: x.denom?.toUpperCase() ?? "",
coinMinimalDenom: x.denom ?? "",
coinDecimals: 0,
};
return y;
}) ?? [];
let currencies = [{
coinDenom: "LAKE",
coinMinimalDenom: "ulake",
coinDecimals: 6,
}, {
coinDenom: "DROP",
coinMinimalDenom: "udrop",
coinDecimals: 4,
}];


let stakeCurrency = {
coinDenom: staking.params?.bond_denom?.toUpperCase() ?? "",
coinMinimalDenom: staking.params?.bond_denom ?? "",
coinDecimals: 0,
};

let feeCurrencies =
tokens.supply?.map((x) => {
const y = {
coinDenom: x.denom?.toUpperCase() ?? "",
coinMinimalDenom: x.denom ?? "",
coinDecimals: 0,

let stakeCurrency = {
coinDenom: "LAKE",
coinMinimalDenom: "ulake",
coinDecimals: 6,
};
return y;
}) ?? [];

let feeCurrencies = currencies;

let coinType = 1009;
let coinType = 1009;

if (chainId) {
const suggestOptions: ChainInfo = {
chainId,
chainName,
rpc,
rest,
stakeCurrency,
bip44,
bech32Config,
currencies,
feeCurrencies,
coinType,
...keplrChainInfo,
};
await window.keplr.experimentalSuggestChain(suggestOptions);
if (chainId) {
const suggestOptions: ChainInfo = {
chainId,
chainName,
rpc,
rest,
stakeCurrency,
bip44,
bech32Config,
currencies,
feeCurrencies,
coinType,
...keplrChainInfo,
};
await window.keplr.experimentalSuggestChain(suggestOptions);

window.keplr.defaultOptions = {
sign: {
preferNoSetFee: true,
preferNoSetMemo: true,
},
};
}
await window.keplr.enable(chainId);
this.signer = window.keplr.getOfflineSigner(chainId);
this.emit("signer-changed", this.signer);
} catch (e) {
throw new Error(
"Could not load tendermint, staking and bank modules. Please ensure your client loads them to use useKeplr()"
);
window.keplr.defaultOptions = {
sign: {
preferNoSetFee: true,
preferNoSetMemo: true,
},
};
}
await window.keplr.enable(chainId);
this.signer = window.keplr.getOfflineSigner(chainId);
this.emit("signer-changed", this.signer);
}
}
58 changes: 29 additions & 29 deletions blockchain/ts-client/cosmos.authz.v1beta1/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { msgTypes } from './registry';
import { IgniteClient } from "../client"
import { MissingWalletError } from "../helpers"
import { Api } from "./rest";
import { MsgGrant } from "./types/cosmos/authz/v1beta1/tx";
import { MsgExec } from "./types/cosmos/authz/v1beta1/tx";
import { MsgRevoke } from "./types/cosmos/authz/v1beta1/tx";
import { MsgGrant } from "./types/cosmos/authz/v1beta1/tx";

import { GenericAuthorization as typeGenericAuthorization} from "./types"
import { Grant as typeGrant} from "./types"
Expand All @@ -18,13 +18,7 @@ import { GrantQueueItem as typeGrantQueueItem} from "./types"
import { EventGrant as typeEventGrant} from "./types"
import { EventRevoke as typeEventRevoke} from "./types"

export { MsgGrant, MsgExec, MsgRevoke };

type sendMsgGrantParams = {
value: MsgGrant,
fee?: StdFee,
memo?: string
};
export { MsgExec, MsgRevoke, MsgGrant };

type sendMsgExecParams = {
value: MsgExec,
Expand All @@ -38,11 +32,13 @@ type sendMsgRevokeParams = {
memo?: string
};


type msgGrantParams = {
type sendMsgGrantParams = {
value: MsgGrant,
fee?: StdFee,
memo?: string
};


type msgExecParams = {
value: MsgExec,
};
Expand All @@ -51,6 +47,10 @@ type msgRevokeParams = {
value: MsgRevoke,
};

type msgGrantParams = {
value: MsgGrant,
};


export const registry = new Registry(msgTypes);

Expand Down Expand Up @@ -81,20 +81,6 @@ export const txClient = ({ signer, prefix, addr }: TxClientOptions = { addr: "ht

return {

async sendMsgGrant({ value, fee, memo }: sendMsgGrantParams): Promise<DeliverTxResponse> {
if (!signer) {
throw new Error('TxClient:sendMsgGrant: Unable to sign Tx. Signer is not present.')
}
try {
const { address } = (await signer.getAccounts())[0];
const signingClient = await SigningStargateClient.connectWithSigner(addr,signer,{registry, prefix});
let msg = this.msgGrant({ value: MsgGrant.fromPartial(value) })
return await signingClient.signAndBroadcast(address, [msg], fee ? fee : defaultFee, memo)
} catch (e: any) {
throw new Error('TxClient:sendMsgGrant: Could not broadcast Tx: '+ e.message)
}
},

async sendMsgExec({ value, fee, memo }: sendMsgExecParams): Promise<DeliverTxResponse> {
if (!signer) {
throw new Error('TxClient:sendMsgExec: Unable to sign Tx. Signer is not present.')
Expand Down Expand Up @@ -123,15 +109,21 @@ export const txClient = ({ signer, prefix, addr }: TxClientOptions = { addr: "ht
}
},


msgGrant({ value }: msgGrantParams): EncodeObject {
try {
return { typeUrl: "/cosmos.authz.v1beta1.MsgGrant", value: MsgGrant.fromPartial( value ) }
async sendMsgGrant({ value, fee, memo }: sendMsgGrantParams): Promise<DeliverTxResponse> {
if (!signer) {
throw new Error('TxClient:sendMsgGrant: Unable to sign Tx. Signer is not present.')
}
try {
const { address } = (await signer.getAccounts())[0];
const signingClient = await SigningStargateClient.connectWithSigner(addr,signer,{registry, prefix});
let msg = this.msgGrant({ value: MsgGrant.fromPartial(value) })
return await signingClient.signAndBroadcast(address, [msg], fee ? fee : defaultFee, memo)
} catch (e: any) {
throw new Error('TxClient:MsgGrant: Could not create message: ' + e.message)
throw new Error('TxClient:sendMsgGrant: Could not broadcast Tx: '+ e.message)
}
},


msgExec({ value }: msgExecParams): EncodeObject {
try {
return { typeUrl: "/cosmos.authz.v1beta1.MsgExec", value: MsgExec.fromPartial( value ) }
Expand All @@ -148,6 +140,14 @@ export const txClient = ({ signer, prefix, addr }: TxClientOptions = { addr: "ht
}
},

msgGrant({ value }: msgGrantParams): EncodeObject {
try {
return { typeUrl: "/cosmos.authz.v1beta1.MsgGrant", value: MsgGrant.fromPartial( value ) }
} catch (e: any) {
throw new Error('TxClient:MsgGrant: Could not create message: ' + e.message)
}
},

}
};

Expand Down
4 changes: 2 additions & 2 deletions blockchain/ts-client/cosmos.authz.v1beta1/registry.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { GeneratedType } from "@cosmjs/proto-signing";
import { MsgGrant } from "./types/cosmos/authz/v1beta1/tx";
import { MsgExec } from "./types/cosmos/authz/v1beta1/tx";
import { MsgRevoke } from "./types/cosmos/authz/v1beta1/tx";
import { MsgGrant } from "./types/cosmos/authz/v1beta1/tx";

const msgTypes: Array<[string, GeneratedType]> = [
["/cosmos.authz.v1beta1.MsgGrant", MsgGrant],
["/cosmos.authz.v1beta1.MsgExec", MsgExec],
["/cosmos.authz.v1beta1.MsgRevoke", MsgRevoke],
["/cosmos.authz.v1beta1.MsgGrant", MsgGrant],

];

Expand Down
Loading

0 comments on commit 3a7a482

Please sign in to comment.