decentralcardgame-cardchain-client-ts 0.0.27 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,104 +1,102 @@
1
1
  // Generated by Ignite ignite.com/cli
2
2
 
3
- import {StdFee} from "@cosmjs/amino";
4
- import {SigningStargateClient, DeliverTxResponse} from "@cosmjs/stargate";
5
- import {EncodeObject, GeneratedType, OfflineSigner, Registry} from "@cosmjs/proto-signing";
6
- import {msgTypes} from './registry';
7
- import {IgniteClient} from "../client"
8
- import {MissingWalletError} from "../helpers"
9
- import {Api} from "./rest";
3
+ import { StdFee } from "@cosmjs/amino";
4
+ import { SigningStargateClient, DeliverTxResponse } from "@cosmjs/stargate";
5
+ import { EncodeObject, GeneratedType, OfflineSigner, Registry } from "@cosmjs/proto-signing";
6
+ import { msgTypes } from './registry';
7
+ import { IgniteClient } from "../client"
8
+ import { MissingWalletError } from "../helpers"
9
+ import { Api } from "./rest";
10
10
 
11
- import {Flag as typeFlag} from "./types"
12
- import {Params as typeParams} from "./types"
13
- import {FlagEnableProposal as typeFlagEnableProposal} from "./types"
11
+ import { Flag as typeFlag} from "./types"
12
+ import { Params as typeParams} from "./types"
13
+ import { FlagEnableProposal as typeFlagEnableProposal} from "./types"
14
+
15
+ export { };
14
16
 
15
- export {};
16
17
 
17
18
 
18
19
  export const registry = new Registry(msgTypes);
19
20
 
20
21
  type Field = {
21
- name: string;
22
- type: unknown;
22
+ name: string;
23
+ type: unknown;
23
24
  }
24
-
25
25
  function getStructure(template) {
26
- const structure: { fields: Field[] } = {fields: []}
27
- for (let [key, value] of Object.entries(template)) {
28
- let field = {name: key, type: typeof value}
29
- structure.fields.push(field)
30
- }
31
- return structure
26
+ const structure: {fields: Field[]} = { fields: [] }
27
+ for (let [key, value] of Object.entries(template)) {
28
+ let field = { name: key, type: typeof value }
29
+ structure.fields.push(field)
30
+ }
31
+ return structure
32
32
  }
33
-
34
33
  const defaultFee = {
35
- amount: [],
36
- gas: "200000",
34
+ amount: [],
35
+ gas: "200000",
37
36
  };
38
37
 
39
38
  interface TxClientOptions {
40
- addr: string
41
- prefix: string
42
- signer?: OfflineSigner
39
+ addr: string
40
+ prefix: string
41
+ signer?: OfflineSigner
43
42
  }
44
43
 
45
- export const txClient = ({signer, prefix, addr}: TxClientOptions = {
46
- addr: "http://localhost:26657",
47
- prefix: "cosmos"
48
- }) => {
44
+ export const txClient = ({ signer, prefix, addr }: TxClientOptions = { addr: "http://localhost:26657", prefix: "cosmos" }) => {
49
45
 
50
- return {}
46
+ return {
47
+
48
+
49
+ }
51
50
  };
52
51
 
53
52
  interface QueryClientOptions {
54
- addr: string
53
+ addr: string
55
54
  }
56
55
 
57
- export const queryClient = ({addr: addr}: QueryClientOptions = {addr: "http://localhost:1317"}) => {
58
- return new Api({baseURL: addr});
56
+ export const queryClient = ({ addr: addr }: QueryClientOptions = { addr: "http://localhost:1317" }) => {
57
+ return new Api({ baseURL: addr });
59
58
  };
60
59
 
61
60
  class SDKModule {
62
- public query: ReturnType<typeof queryClient>;
63
- public tx: ReturnType<typeof txClient>;
64
- public structure: Record<string, unknown>;
65
- public registry: Array<[string, GeneratedType]> = [];
66
-
67
- constructor(client: IgniteClient) {
68
-
69
- this.query = queryClient({addr: client.env.apiURL});
70
- this.updateTX(client);
71
- this.structure = {
72
- Flag: getStructure(typeFlag.fromPartial({})),
73
- Params: getStructure(typeParams.fromPartial({})),
74
- FlagEnableProposal: getStructure(typeFlagEnableProposal.fromPartial({})),
75
-
76
- };
77
- client.on('signer-changed', (signer) => {
78
- this.updateTX(client);
79
- })
80
- }
81
-
82
- updateTX(client: IgniteClient) {
83
- const methods = txClient({
84
- signer: client.signer,
85
- addr: client.env.rpcURL,
86
- prefix: client.env.prefix ?? "cosmos",
87
- })
88
-
89
- this.tx = methods;
90
- for (let m in methods) {
91
- this.tx[m] = methods[m].bind(this.tx);
92
- }
61
+ public query: ReturnType<typeof queryClient>;
62
+ public tx: ReturnType<typeof txClient>;
63
+ public structure: Record<string,unknown>;
64
+ public registry: Array<[string, GeneratedType]> = [];
65
+
66
+ constructor(client: IgniteClient) {
67
+
68
+ this.query = queryClient({ addr: client.env.apiURL });
69
+ this.updateTX(client);
70
+ this.structure = {
71
+ Flag: getStructure(typeFlag.fromPartial({})),
72
+ Params: getStructure(typeParams.fromPartial({})),
73
+ FlagEnableProposal: getStructure(typeFlagEnableProposal.fromPartial({})),
74
+
75
+ };
76
+ client.on('signer-changed',(signer) => {
77
+ this.updateTX(client);
78
+ })
79
+ }
80
+ updateTX(client: IgniteClient) {
81
+ const methods = txClient({
82
+ signer: client.signer,
83
+ addr: client.env.rpcURL,
84
+ prefix: client.env.prefix ?? "cosmos",
85
+ })
86
+
87
+ this.tx = methods;
88
+ for (let m in methods) {
89
+ this.tx[m] = methods[m].bind(this.tx);
93
90
  }
91
+ }
94
92
  };
95
93
 
96
94
  const Module = (test: IgniteClient) => {
97
- return {
98
- module: {
99
- DecentralCardGameCardchainFeatureflag: new SDKModule(test)
100
- },
101
- registry: msgTypes
102
- }
95
+ return {
96
+ module: {
97
+ DecentralCardGameCardchainFeatureflag: new SDKModule(test)
98
+ },
99
+ registry: msgTypes
100
+ }
103
101
  }
104
102
  export default Module;
package/client.js CHANGED
@@ -20,7 +20,10 @@ export class IgniteClient extends EventEmitter {
20
20
  async signAndBroadcast(msgs, fee, memo) {
21
21
  if (this.signer) {
22
22
  const { address } = (await this.signer.getAccounts())[0];
23
- const signingClient = await SigningStargateClient.connectWithSigner(this.env.rpcURL, this.signer, { registry: new Registry(this.registry), prefix: this.env.prefix });
23
+ const signingClient = await SigningStargateClient.connectWithSigner(this.env.rpcURL, this.signer, {
24
+ registry: new Registry(this.registry),
25
+ prefix: this.env.prefix
26
+ });
24
27
  return await signingClient.signAndBroadcast(address, msgs, fee ? fee : defaultFee, memo);
25
28
  }
26
29
  else {
package/client.ts CHANGED
@@ -1,169 +1,176 @@
1
1
  /// <reference path="./types.d.ts" />
2
2
  import {
3
- GeneratedType,
4
- OfflineSigner,
5
- EncodeObject,
6
- Registry,
3
+ GeneratedType,
4
+ OfflineSigner,
5
+ EncodeObject,
6
+ Registry,
7
7
  } from "@cosmjs/proto-signing";
8
- import { StdFee } from "@cosmjs/amino";
9
- import { SigningStargateClient } from "@cosmjs/stargate";
10
- import { Env } from "./env";
11
- import { UnionToIntersection, Return, Constructor } from "./helpers";
12
- import { Module } from "./modules";
13
- import { EventEmitter } from "events";
14
- import { ChainInfo } from "@keplr-wallet/types";
8
+ import {StdFee} from "@cosmjs/amino";
9
+ import {SigningStargateClient} from "@cosmjs/stargate";
10
+ import {Env} from "./env";
11
+ import {UnionToIntersection, Return, Constructor} from "./helpers";
12
+ import {Module} from "./modules";
13
+ import {EventEmitter} from "events";
14
+ import {ChainInfo} from "@keplr-wallet/types";
15
15
 
16
16
  const defaultFee = {
17
- amount: [],
18
- gas: "200000",
17
+ amount: [],
18
+ gas: "200000",
19
19
  };
20
20
 
21
21
  export class IgniteClient extends EventEmitter {
22
- static plugins: Module[] = [];
23
- env: Env;
24
- signer?: OfflineSigner;
25
- registry: Array<[string, GeneratedType]> = [];
26
- static plugin<T extends Module | Module[]>(plugin: T) {
27
- const currentPlugins = this.plugins;
28
-
29
- class AugmentedClient extends this {
30
- static plugins = currentPlugins.concat(plugin);
22
+ static plugins: Module[] = [];
23
+ env: Env;
24
+ signer?: OfflineSigner;
25
+ registry: Array<[string, GeneratedType]> = [];
26
+
27
+ static plugin<T extends Module | Module[]>(plugin: T) {
28
+ const currentPlugins = this.plugins;
29
+
30
+ class AugmentedClient extends this {
31
+ static plugins = currentPlugins.concat(plugin);
32
+ }
33
+
34
+ if (Array.isArray(plugin)) {
35
+ type Extension = UnionToIntersection<Return<T>['module']>
36
+ return AugmentedClient as typeof IgniteClient & Constructor<Extension>;
37
+ }
38
+
39
+ type Extension = Return<T>['module']
40
+ return AugmentedClient as typeof IgniteClient & Constructor<Extension>;
31
41
  }
32
42
 
33
- if (Array.isArray(plugin)) {
34
- type Extension = UnionToIntersection<Return<T>['module']>
35
- return AugmentedClient as typeof IgniteClient & Constructor<Extension>;
43
+ async signAndBroadcast(msgs: EncodeObject[], fee: StdFee, memo: string) {
44
+ if (this.signer) {
45
+ const {address} = (await this.signer.getAccounts())[0];
46
+ const signingClient = await SigningStargateClient.connectWithSigner(this.env.rpcURL, this.signer, {
47
+ registry: new Registry(this.registry),
48
+ prefix: this.env.prefix
49
+ });
50
+ return await signingClient.signAndBroadcast(address, msgs, fee ? fee : defaultFee, memo)
51
+ } else {
52
+ throw new Error(" Signer is not present.");
53
+ }
36
54
  }
37
55
 
38
- type Extension = Return<T>['module']
39
- return AugmentedClient as typeof IgniteClient & Constructor<Extension>;
40
- }
41
-
42
- async signAndBroadcast(msgs: EncodeObject[], fee: StdFee, memo: string) {
43
- if (this.signer) {
44
- const { address } = (await this.signer.getAccounts())[0];
45
- const signingClient = await SigningStargateClient.connectWithSigner(this.env.rpcURL, this.signer, { registry: new Registry(this.registry), prefix: this.env.prefix });
46
- return await signingClient.signAndBroadcast(address, msgs, fee ? fee : defaultFee, memo)
47
- } else {
48
- throw new Error(" Signer is not present.");
56
+ constructor(env: Env, signer?: OfflineSigner) {
57
+ super();
58
+ this.env = env;
59
+ this.setMaxListeners(0);
60
+ this.signer = signer;
61
+ const classConstructor = this.constructor as typeof IgniteClient;
62
+ classConstructor.plugins.forEach(plugin => {
63
+ const pluginInstance = plugin(this);
64
+ Object.assign(this, pluginInstance.module)
65
+ if (this.registry) {
66
+ this.registry = this.registry.concat(pluginInstance.registry)
67
+ }
68
+ });
49
69
  }
50
- }
51
-
52
- constructor(env: Env, signer?: OfflineSigner) {
53
- super();
54
- this.env = env;
55
- this.setMaxListeners(0);
56
- this.signer = signer;
57
- const classConstructor = this.constructor as typeof IgniteClient;
58
- classConstructor.plugins.forEach(plugin => {
59
- const pluginInstance = plugin(this);
60
- Object.assign(this, pluginInstance.module)
61
- if (this.registry) {
62
- this.registry = this.registry.concat(pluginInstance.registry)
63
- }
64
- });
65
- }
66
- useSigner(signer: OfflineSigner) {
67
- this.signer = signer;
68
- this.emit("signer-changed", this.signer);
69
- }
70
- removeSigner() {
71
- this.signer = undefined;
72
- this.emit("signer-changed", this.signer);
73
- }
74
- async useKeplr(keplrChainInfo: Partial<ChainInfo> = {}) {
75
- // Using queryClients directly because BaseClient has no knowledge of the modules at this stage
76
- try {
77
- const queryClient = (
78
- await import("./cosmos.base.tendermint.v1beta1/module")
79
- ).queryClient;
80
- const stakingQueryClient = (
81
- await import("./cosmos.staking.v1beta1/module")
82
- ).queryClient;
83
- const bankQueryClient = (await import("./cosmos.bank.v1beta1/module"))
84
- .queryClient;
85
-
86
- const stakingqc = stakingQueryClient({ addr: this.env.apiURL });
87
- const qc = queryClient({ addr: this.env.apiURL });
88
- const node_info = await (await qc.serviceGetNodeInfo()).data;
89
- const chainId = node_info.default_node_info?.network ?? "";
90
- const chainName = chainId?.toUpperCase() + " Network";
91
- const staking = await (await stakingqc.queryParams()).data;
92
- const bankqc = bankQueryClient({ addr: this.env.apiURL });
93
- const tokens = await (await bankqc.queryTotalSupply()).data;
94
- const addrPrefix = this.env.prefix ?? "cosmos";
95
- const rpc = this.env.rpcURL;
96
- const rest = this.env.apiURL;
97
- let stakeCurrency = {
98
- coinDenom: staking.params?.bond_denom?.toUpperCase() ?? "",
99
- coinMinimalDenom: staking.params?.bond_denom ?? "",
100
- coinDecimals: 0,
101
- };
102
-
103
- let bip44 = {
104
- coinType: 118,
105
- };
106
-
107
- let bech32Config = {
108
- bech32PrefixAccAddr: addrPrefix,
109
- bech32PrefixAccPub: addrPrefix + "pub",
110
- bech32PrefixValAddr: addrPrefix + "valoper",
111
- bech32PrefixValPub: addrPrefix + "valoperpub",
112
- bech32PrefixConsAddr: addrPrefix + "valcons",
113
- bech32PrefixConsPub: addrPrefix + "valconspub",
114
- };
115
-
116
- let currencies =
117
- tokens.supply?.map((x) => {
118
- const y = {
119
- coinDenom: x.denom?.toUpperCase() ?? "",
120
- coinMinimalDenom: x.denom ?? "",
121
- coinDecimals: 0,
122
- };
123
- return y;
124
- }) ?? [];
125
-
126
- let feeCurrencies =
127
- tokens.supply?.map((x) => {
128
- const y = {
129
- coinDenom: x.denom?.toUpperCase() ?? "",
130
- coinMinimalDenom: x.denom ?? "",
131
- coinDecimals: 0,
132
- };
133
- return y;
134
- }) ?? [];
135
-
136
- let coinType = 118;
137
-
138
- if (chainId) {
139
- const suggestOptions: ChainInfo = {
140
- chainId,
141
- chainName,
142
- rpc,
143
- rest,
144
- stakeCurrency,
145
- bip44,
146
- bech32Config,
147
- currencies,
148
- feeCurrencies,
149
- ...keplrChainInfo,
150
- };
151
- await window.keplr.experimentalSuggestChain(suggestOptions);
152
-
153
- window.keplr.defaultOptions = {
154
- sign: {
155
- preferNoSetFee: true,
156
- preferNoSetMemo: true,
157
- },
158
- };
159
- }
160
- await window.keplr.enable(chainId);
161
- this.signer = window.keplr.getOfflineSigner(chainId);
162
- this.emit("signer-changed", this.signer);
163
- } catch (e) {
164
- throw new Error(
165
- "Could not load tendermint, staking and bank modules. Please ensure your client loads them to use useKeplr()"
166
- );
70
+
71
+ useSigner(signer: OfflineSigner) {
72
+ this.signer = signer;
73
+ this.emit("signer-changed", this.signer);
74
+ }
75
+
76
+ removeSigner() {
77
+ this.signer = undefined;
78
+ this.emit("signer-changed", this.signer);
79
+ }
80
+
81
+ async useKeplr(keplrChainInfo: Partial<ChainInfo> = {}) {
82
+ // Using queryClients directly because BaseClient has no knowledge of the modules at this stage
83
+ try {
84
+ const queryClient = (
85
+ await import("./cosmos.base.tendermint.v1beta1/module")
86
+ ).queryClient;
87
+ const stakingQueryClient = (
88
+ await import("./cosmos.staking.v1beta1/module")
89
+ ).queryClient;
90
+ const bankQueryClient = (await import("./cosmos.bank.v1beta1/module"))
91
+ .queryClient;
92
+
93
+ const stakingqc = stakingQueryClient({addr: this.env.apiURL});
94
+ const qc = queryClient({addr: this.env.apiURL});
95
+ const node_info = await (await qc.serviceGetNodeInfo()).data;
96
+ const chainId = node_info.default_node_info?.network ?? "";
97
+ const chainName = chainId?.toUpperCase() + " Network";
98
+ const staking = await (await stakingqc.queryParams()).data;
99
+ const bankqc = bankQueryClient({addr: this.env.apiURL});
100
+ const tokens = await (await bankqc.queryTotalSupply()).data;
101
+ const addrPrefix = this.env.prefix ?? "cosmos";
102
+ const rpc = this.env.rpcURL;
103
+ const rest = this.env.apiURL;
104
+ let stakeCurrency = {
105
+ coinDenom: staking.params?.bond_denom?.toUpperCase() ?? "",
106
+ coinMinimalDenom: staking.params?.bond_denom ?? "",
107
+ coinDecimals: 0,
108
+ };
109
+
110
+ let bip44 = {
111
+ coinType: 118,
112
+ };
113
+
114
+ let bech32Config = {
115
+ bech32PrefixAccAddr: addrPrefix,
116
+ bech32PrefixAccPub: addrPrefix + "pub",
117
+ bech32PrefixValAddr: addrPrefix + "valoper",
118
+ bech32PrefixValPub: addrPrefix + "valoperpub",
119
+ bech32PrefixConsAddr: addrPrefix + "valcons",
120
+ bech32PrefixConsPub: addrPrefix + "valconspub",
121
+ };
122
+
123
+ let currencies =
124
+ tokens.supply?.map((x) => {
125
+ const y = {
126
+ coinDenom: x.denom?.toUpperCase() ?? "",
127
+ coinMinimalDenom: x.denom ?? "",
128
+ coinDecimals: 0,
129
+ };
130
+ return y;
131
+ }) ?? [];
132
+
133
+ let feeCurrencies =
134
+ tokens.supply?.map((x) => {
135
+ const y = {
136
+ coinDenom: x.denom?.toUpperCase() ?? "",
137
+ coinMinimalDenom: x.denom ?? "",
138
+ coinDecimals: 0,
139
+ };
140
+ return y;
141
+ }) ?? [];
142
+
143
+ let coinType = 118;
144
+
145
+ if (chainId) {
146
+ const suggestOptions: ChainInfo = {
147
+ chainId,
148
+ chainName,
149
+ rpc,
150
+ rest,
151
+ stakeCurrency,
152
+ bip44,
153
+ bech32Config,
154
+ currencies,
155
+ feeCurrencies,
156
+ ...keplrChainInfo,
157
+ };
158
+ await window.keplr.experimentalSuggestChain(suggestOptions);
159
+
160
+ window.keplr.defaultOptions = {
161
+ sign: {
162
+ preferNoSetFee: true,
163
+ preferNoSetMemo: true,
164
+ },
165
+ };
166
+ }
167
+ await window.keplr.enable(chainId);
168
+ this.signer = window.keplr.getOfflineSigner(chainId);
169
+ this.emit("signer-changed", this.signer);
170
+ } catch (e) {
171
+ throw new Error(
172
+ "Could not load tendermint, staking and bank modules. Please ensure your client loads them to use useKeplr()"
173
+ );
174
+ }
167
175
  }
168
- }
169
176
  }
@@ -18,10 +18,7 @@ const defaultFee = {
18
18
  amount: [],
19
19
  gas: "200000",
20
20
  };
21
- export const txClient = ({ signer, prefix, addr } = {
22
- addr: "http://localhost:26657",
23
- prefix: "cosmos"
24
- }) => {
21
+ export const txClient = ({ signer, prefix, addr } = { addr: "http://localhost:26657", prefix: "cosmos" }) => {
25
22
  return {};
26
23
  };
27
24
  export const queryClient = ({ addr: addr } = { addr: "http://localhost:1317" }) => {