decentralcardgame-cardchain-client-ts 0.0.18 → 0.0.20

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.
@@ -0,0 +1,23 @@
1
+ export function isAminoMsgTransferCard(msg) {
2
+ return msg.type === "decentral-cardgame/MsgTransferCard";
3
+ }
4
+ export function isAminoMsgRegisterForCouncil(msg) {
5
+ return msg.type === "decentral-cardgame/MsgRegisterForCouncil";
6
+ }
7
+ export function createDecentralCardgameAminoConverters() {
8
+ return {
9
+ "/DecentralCardGame.cardchain.cardchain.MsgTransferCard": {
10
+ aminoType: "decentral-cardgame/MsgTransferCard",
11
+ toAmino: (msg) => (msg),
12
+ fromAmino: (msg) => (msg),
13
+ },
14
+ "/DecentralCardGame.cardchain.cardchain.MsgRegisterForCouncil": {
15
+ aminoType: "decentral-cardgame/MsgRegisterForCouncil",
16
+ toAmino: (msg) => {
17
+ console.log("Hier hier, was da los?", msg);
18
+ return msg;
19
+ },
20
+ fromAmino: (msg) => (msg),
21
+ },
22
+ };
23
+ }
@@ -0,0 +1,52 @@
1
+ /* eslint-disable @typescript-eslint/naming-convention */
2
+ import { AminoMsg } from "@cosmjs/amino";
3
+
4
+ // eslint-disable-next-line import/no-cycle
5
+ import { AminoConverter } from "@cosmjs/stargate";
6
+ import {MsgRegisterForCouncil, MsgTransferCard } from "./tx";
7
+
8
+ type AminoConverters = Record<string, AminoConverter>;
9
+
10
+ /** A high level transaction of the coin module */
11
+ export interface AminoMsgTransferCard extends AminoMsg {
12
+ readonly type: "decentral-cardgame/MsgTransferCard";
13
+ readonly value: {
14
+ readonly creator: string;
15
+ readonly cardId: number;
16
+ readonly receiver: string;
17
+ };
18
+ }
19
+
20
+ export interface AminoMsgRegisterForCouncil extends AminoMsg {
21
+ readonly type: "decentral-cardgame/MsgRegisterForCouncil";
22
+ readonly value: {
23
+ readonly creator: string;
24
+ };
25
+ }
26
+
27
+ export function isAminoMsgTransferCard(msg: AminoMsg): msg is AminoMsgTransferCard {
28
+ return msg.type === "decentral-cardgame/MsgTransferCard";
29
+ }
30
+
31
+ export function isAminoMsgRegisterForCouncil(msg: AminoMsg): msg is AminoMsgRegisterForCouncil {
32
+ return msg.type === "decentral-cardgame/MsgRegisterForCouncil";
33
+ }
34
+
35
+
36
+ export function createDecentralCardgameAminoConverters(): AminoConverters {
37
+ return {
38
+ "/DecentralCardGame.cardchain.cardchain.MsgTransferCard": {
39
+ aminoType: "decentral-cardgame/MsgTransferCard",
40
+ toAmino: (msg: MsgTransferCard): AminoMsgTransferCard["value"] => (msg),
41
+ fromAmino: (msg: AminoMsgTransferCard["value"]): MsgTransferCard => (msg),
42
+ },
43
+ "/DecentralCardGame.cardchain.cardchain.MsgRegisterForCouncil": {
44
+ aminoType: "decentral-cardgame/MsgRegisterForCouncil",
45
+ toAmino: (msg: MsgRegisterForCouncil): AminoMsgRegisterForCouncil["value"] => {
46
+ console.log("Hier hier, was da los?", msg)
47
+ return msg
48
+ },
49
+ fromAmino: (msg: AminoMsgRegisterForCouncil["value"]): MsgRegisterForCouncil => (msg),
50
+ },
51
+ };
52
+ }
package/client.js CHANGED
@@ -1,7 +1,8 @@
1
1
  /// <reference path="./types.d.ts" />
2
2
  import { Registry, } from "@cosmjs/proto-signing";
3
- import { SigningStargateClient } from "@cosmjs/stargate";
3
+ import { AminoTypes, SigningStargateClient } from "@cosmjs/stargate";
4
4
  import { EventEmitter } from "events";
5
+ import { createDecentralCardgameAminoConverters } from "./DecentralCardGame.cardchain.cardchain/types/cardchain/cardchain/aminomessages";
5
6
  const defaultFee = {
6
7
  amount: [],
7
8
  gas: "200000",
@@ -20,7 +21,11 @@ export class IgniteClient extends EventEmitter {
20
21
  async signAndBroadcast(msgs, fee, memo) {
21
22
  if (this.signer) {
22
23
  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 });
24
+ const signingClient = await SigningStargateClient.connectWithSigner(this.env.rpcURL, this.signer, {
25
+ aminoTypes: new AminoTypes({ ...createDecentralCardgameAminoConverters() }),
26
+ registry: new Registry(this.registry),
27
+ prefix: this.env.prefix
28
+ });
24
29
  return await signingClient.signAndBroadcast(address, msgs, fee ? fee : defaultFee, memo);
25
30
  }
26
31
  else {
package/client.ts CHANGED
@@ -1,169 +1,180 @@
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 {AminoTypes, 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
+ import {
16
+ createDecentralCardgameAminoConverters
17
+ } from "./DecentralCardGame.cardchain.cardchain/types/cardchain/cardchain/aminomessages";
15
18
 
16
19
  const defaultFee = {
17
- amount: [],
18
- gas: "200000",
20
+ amount: [],
21
+ gas: "200000",
19
22
  };
20
23
 
21
24
  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);
25
+ static plugins: Module[] = [];
26
+ env: Env;
27
+ signer?: OfflineSigner;
28
+ registry: Array<[string, GeneratedType]> = [];
29
+
30
+ static plugin<T extends Module | Module[]>(plugin: T) {
31
+ const currentPlugins = this.plugins;
32
+
33
+ class AugmentedClient extends this {
34
+ static plugins = currentPlugins.concat(plugin);
35
+ }
36
+
37
+ if (Array.isArray(plugin)) {
38
+ type Extension = UnionToIntersection<Return<T>['module']>
39
+ return AugmentedClient as typeof IgniteClient & Constructor<Extension>;
40
+ }
41
+
42
+ type Extension = Return<T>['module']
43
+ return AugmentedClient as typeof IgniteClient & Constructor<Extension>;
44
+ }
45
+
46
+ async signAndBroadcast(msgs: EncodeObject[], fee: StdFee, memo: string) {
47
+ if (this.signer) {
48
+ const {address} = (await this.signer.getAccounts())[0];
49
+ const signingClient = await SigningStargateClient.connectWithSigner(this.env.rpcURL, this.signer, {
50
+ aminoTypes: new AminoTypes({...createDecentralCardgameAminoConverters()}),
51
+ registry: new Registry(this.registry),
52
+ prefix: this.env.prefix
53
+ });
54
+ return await signingClient.signAndBroadcast(address, msgs, fee ? fee : defaultFee, memo)
55
+ } else {
56
+ throw new Error(" Signer is not present.");
57
+ }
58
+ }
59
+
60
+ constructor(env: Env, signer?: OfflineSigner) {
61
+ super();
62
+ this.env = env;
63
+ this.setMaxListeners(0);
64
+ this.signer = signer;
65
+ const classConstructor = this.constructor as typeof IgniteClient;
66
+ classConstructor.plugins.forEach(plugin => {
67
+ const pluginInstance = plugin(this);
68
+ Object.assign(this, pluginInstance.module)
69
+ if (this.registry) {
70
+ this.registry = this.registry.concat(pluginInstance.registry)
71
+ }
72
+ });
31
73
  }
32
74
 
33
- if (Array.isArray(plugin)) {
34
- type Extension = UnionToIntersection<Return<T>['module']>
35
- return AugmentedClient as typeof IgniteClient & Constructor<Extension>;
75
+ useSigner(signer: OfflineSigner) {
76
+ this.signer = signer;
77
+ this.emit("signer-changed", this.signer);
36
78
  }
37
79
 
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.");
80
+ removeSigner() {
81
+ this.signer = undefined;
82
+ this.emit("signer-changed", this.signer);
49
83
  }
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 = await window.keplr.getOfflineSignerAuto(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
- );
84
+
85
+ async useKeplr(keplrChainInfo: Partial<ChainInfo> = {}) {
86
+ // Using queryClients directly because BaseClient has no knowledge of the modules at this stage
87
+ try {
88
+ const queryClient = (
89
+ await import("./cosmos.base.tendermint.v1beta1/module")
90
+ ).queryClient;
91
+ const stakingQueryClient = (
92
+ await import("./cosmos.staking.v1beta1/module")
93
+ ).queryClient;
94
+ const bankQueryClient = (await import("./cosmos.bank.v1beta1/module"))
95
+ .queryClient;
96
+
97
+ const stakingqc = stakingQueryClient({addr: this.env.apiURL});
98
+ const qc = queryClient({addr: this.env.apiURL});
99
+ const node_info = await (await qc.serviceGetNodeInfo()).data;
100
+ const chainId = node_info.default_node_info?.network ?? "";
101
+ const chainName = chainId?.toUpperCase() + " Network";
102
+ const staking = await (await stakingqc.queryParams()).data;
103
+ const bankqc = bankQueryClient({addr: this.env.apiURL});
104
+ const tokens = await (await bankqc.queryTotalSupply()).data;
105
+ const addrPrefix = this.env.prefix ?? "cosmos";
106
+ const rpc = this.env.rpcURL;
107
+ const rest = this.env.apiURL;
108
+ let stakeCurrency = {
109
+ coinDenom: staking.params?.bond_denom?.toUpperCase() ?? "",
110
+ coinMinimalDenom: staking.params?.bond_denom ?? "",
111
+ coinDecimals: 0,
112
+ };
113
+
114
+ let bip44 = {
115
+ coinType: 118,
116
+ };
117
+
118
+ let bech32Config = {
119
+ bech32PrefixAccAddr: addrPrefix,
120
+ bech32PrefixAccPub: addrPrefix + "pub",
121
+ bech32PrefixValAddr: addrPrefix + "valoper",
122
+ bech32PrefixValPub: addrPrefix + "valoperpub",
123
+ bech32PrefixConsAddr: addrPrefix + "valcons",
124
+ bech32PrefixConsPub: addrPrefix + "valconspub",
125
+ };
126
+
127
+ let currencies =
128
+ tokens.supply?.map((x) => {
129
+ const y = {
130
+ coinDenom: x.denom?.toUpperCase() ?? "",
131
+ coinMinimalDenom: x.denom ?? "",
132
+ coinDecimals: 0,
133
+ };
134
+ return y;
135
+ }) ?? [];
136
+
137
+ let feeCurrencies =
138
+ tokens.supply?.map((x) => {
139
+ const y = {
140
+ coinDenom: x.denom?.toUpperCase() ?? "",
141
+ coinMinimalDenom: x.denom ?? "",
142
+ coinDecimals: 0,
143
+ };
144
+ return y;
145
+ }) ?? [];
146
+
147
+ let coinType = 118;
148
+
149
+ if (chainId) {
150
+ const suggestOptions: ChainInfo = {
151
+ chainId,
152
+ chainName,
153
+ rpc,
154
+ rest,
155
+ stakeCurrency,
156
+ bip44,
157
+ bech32Config,
158
+ currencies,
159
+ feeCurrencies,
160
+ ...keplrChainInfo,
161
+ };
162
+ await window.keplr.experimentalSuggestChain(suggestOptions);
163
+
164
+ window.keplr.defaultOptions = {
165
+ sign: {
166
+ preferNoSetFee: true,
167
+ preferNoSetMemo: true,
168
+ },
169
+ };
170
+ }
171
+ await window.keplr.enable(chainId);
172
+ this.signer = await window.keplr.getOfflineSignerAuto(chainId);
173
+ this.emit("signer-changed", this.signer);
174
+ } catch (e) {
175
+ throw new Error(
176
+ "Could not load tendermint, staking and bank modules. Please ensure your client loads them to use useKeplr()"
177
+ );
178
+ }
167
179
  }
168
- }
169
180
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "decentralcardgame-cardchain-client-ts",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "Autogenerated Typescript Client for crowdcontrol cardchain",
5
5
  "author": "Lxgr <lxgr@protonmail.com>",
6
6
  "license": "GPL-v3",