@ark-us/wasmx-stargate 0.0.11 → 0.0.13
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.
- package/LICENSE +674 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +5 -1
- package/build/index.js.map +1 -1
- package/build/modules/wasmx/aminomessages.js +2 -0
- package/build/modules/wasmx/aminomessages.js.map +1 -1
- package/build/signingwasmxclient.js +8 -8
- package/build/signingwasmxclient.js.map +1 -1
- package/build/tendermintclient.d.ts +4 -2
- package/build/tendermintclient.js +8 -1
- package/build/tendermintclient.js.map +1 -1
- package/build/wasmxclient.d.ts +1 -2
- package/build/wasmxclient.js +2 -32
- package/build/wasmxclient.js.map +1 -1
- package/package.json +10 -10
- package/.DS_Store +0 -0
- package/.eslintignore +0 -5
- package/.eslintrc.js +0 -108
- package/.gitignore +0 -5
- package/build/encoding.spec.d.ts +0 -1
- package/build/encoding.spec.js +0 -78
- package/build/encoding.spec.js.map +0 -1
- package/build/modules/wasmx/aminomessages.spec.d.ts +0 -1
- package/build/modules/wasmx/aminomessages.spec.js +0 -242
- package/build/modules/wasmx/aminomessages.spec.js.map +0 -1
- package/jasmine-testrunner.js +0 -38
- package/karma.conf.js +0 -54
- package/src/encoding.spec.ts +0 -99
- package/src/encoding.ts +0 -21
- package/src/index.ts +0 -30
- package/src/modules/index.ts +0 -20
- package/src/modules/wasmx/aminomessages.spec.ts +0 -258
- package/src/modules/wasmx/aminomessages.ts +0 -177
- package/src/modules/wasmx/messages.ts +0 -54
- package/src/modules/wasmx/queries.ts +0 -141
- package/src/modules/wasmx/utils.ts +0 -43
- package/src/signingwasmxclient.ts +0 -658
- package/src/tendermintclient.ts +0 -7
- package/src/wasmxclient.ts +0 -494
- package/tsconfig.eslint.json +0 -9
- package/tsconfig.json +0 -12
- package/typedoc.js +0 -11
- package/webpack.web.config.js +0 -37
- package/yarn-error.log +0 -4205
- package/yarn.lock +0 -4145
package/src/wasmxclient.ts
DELETED
|
@@ -1,494 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import { fromUtf8, toHex } from "@cosmjs/encoding";
|
|
3
|
-
import { Uint53 } from "@cosmjs/math";
|
|
4
|
-
import {
|
|
5
|
-
Account,
|
|
6
|
-
AuthExtension,
|
|
7
|
-
BankExtension,
|
|
8
|
-
Block,
|
|
9
|
-
BroadcastTxError,
|
|
10
|
-
Coin,
|
|
11
|
-
DeliverTxResponse,
|
|
12
|
-
fromTendermintEvent,
|
|
13
|
-
IndexedTx,
|
|
14
|
-
isSearchByHeightQuery,
|
|
15
|
-
isSearchBySentFromOrToQuery,
|
|
16
|
-
isSearchByTagsQuery,
|
|
17
|
-
QueryClient,
|
|
18
|
-
SearchTxFilter,
|
|
19
|
-
SearchTxQuery,
|
|
20
|
-
SequenceResponse,
|
|
21
|
-
setupAuthExtension,
|
|
22
|
-
setupBankExtension,
|
|
23
|
-
setupTxExtension,
|
|
24
|
-
TimeoutError,
|
|
25
|
-
TxExtension,
|
|
26
|
-
} from "@cosmjs/stargate";
|
|
27
|
-
import {
|
|
28
|
-
HttpEndpoint,
|
|
29
|
-
Tendermint34Client,
|
|
30
|
-
toRfc3339WithNanoseconds,
|
|
31
|
-
} from "@cosmjs/tendermint-rpc";
|
|
32
|
-
import {TendermintClient} from './tendermintclient';
|
|
33
|
-
import { assert, sleep } from "@cosmjs/utils";
|
|
34
|
-
import {
|
|
35
|
-
QueryCodesResponse,
|
|
36
|
-
QueryContractsByCodeResponse,
|
|
37
|
-
} from "@ark-us/wasmxjs/types/codegen/mythos/wasmx/v1/query";
|
|
38
|
-
import { CodeInfoPB } from "@ark-us/wasmxjs/types/codegen/mythos/wasmx/v1/contract";
|
|
39
|
-
import { JsonObject, setupWasmExtension, WasmExtension } from "./modules";
|
|
40
|
-
import { accountFromAnyWasmx } from "./modules/wasmx/utils";
|
|
41
|
-
|
|
42
|
-
export interface Code {
|
|
43
|
-
readonly id: number;
|
|
44
|
-
/** Bech32 account address */
|
|
45
|
-
readonly creator: string;
|
|
46
|
-
/** Hex-encoded sha256 hash of the code stored here */
|
|
47
|
-
readonly checksum: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface CodeDetails extends Code {
|
|
51
|
-
/** The original Wasm bytes */
|
|
52
|
-
readonly data: Uint8Array;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export interface Contract {
|
|
56
|
-
readonly address: string;
|
|
57
|
-
readonly codeId: number;
|
|
58
|
-
/** Bech32 account address */
|
|
59
|
-
readonly creator: string;
|
|
60
|
-
readonly label: string;
|
|
61
|
-
readonly ibcPortId: string | undefined;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface ContractCodeHistoryEntry {
|
|
65
|
-
/** The source of this history entry */
|
|
66
|
-
readonly operation: "Genesis" | "Init" | "Migrate";
|
|
67
|
-
readonly codeId: number;
|
|
68
|
-
readonly msg: JsonObject;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** Use for testing only */
|
|
72
|
-
export interface PrivateWasmXClient {
|
|
73
|
-
readonly tmClient: TendermintClient | undefined;
|
|
74
|
-
readonly queryClient:
|
|
75
|
-
| (QueryClient & AuthExtension & BankExtension & TxExtension & WasmExtension)
|
|
76
|
-
| undefined;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export class WasmXClient {
|
|
80
|
-
private readonly tmClient: TendermintClient | undefined;
|
|
81
|
-
private readonly queryClient:
|
|
82
|
-
| (QueryClient & AuthExtension & BankExtension & TxExtension & WasmExtension)
|
|
83
|
-
| undefined;
|
|
84
|
-
private readonly codesCache = new Map<number, CodeDetails>();
|
|
85
|
-
private readonly codeInfosCache = new Map<number, CodeInfoPB>();
|
|
86
|
-
private chainId: string = "";
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Creates an instance by connecting to the given Tendermint RPC endpoint.
|
|
90
|
-
*
|
|
91
|
-
* For now this uses the Tendermint 0.34 client. If you need Tendermint 0.37
|
|
92
|
-
* support, see `create`.
|
|
93
|
-
*/
|
|
94
|
-
public static async connect(endpoint: string | HttpEndpoint): Promise<WasmXClient> {
|
|
95
|
-
const tmClient = await Tendermint34Client.connect(endpoint);
|
|
96
|
-
return WasmXClient.create(tmClient);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Creates an instance from a manually created Tendermint client.
|
|
101
|
-
* Use this to use `Tendermint37Client` instead of `Tendermint34Client`.
|
|
102
|
-
*/
|
|
103
|
-
public static async create(tmClient: TendermintClient): Promise<WasmXClient> {
|
|
104
|
-
return new WasmXClient(tmClient);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
protected constructor(tmClient: TendermintClient | undefined) {
|
|
108
|
-
if (tmClient) {
|
|
109
|
-
this.tmClient = tmClient;
|
|
110
|
-
this.queryClient = QueryClient.withExtensions(
|
|
111
|
-
tmClient,
|
|
112
|
-
setupAuthExtension,
|
|
113
|
-
setupBankExtension,
|
|
114
|
-
setupWasmExtension,
|
|
115
|
-
setupTxExtension,
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
protected getTmClient(): TendermintClient | undefined {
|
|
121
|
-
return this.tmClient;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
protected forceGetTmClient(): TendermintClient {
|
|
125
|
-
if (!this.tmClient) {
|
|
126
|
-
throw new Error(
|
|
127
|
-
"Tendermint client not available. You cannot use online functionality in offline mode.",
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
return this.tmClient;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
protected getQueryClient():
|
|
134
|
-
| (QueryClient & AuthExtension & BankExtension & TxExtension & WasmExtension)
|
|
135
|
-
| undefined {
|
|
136
|
-
return this.queryClient;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
protected forceGetQueryClient(): QueryClient & AuthExtension & BankExtension & TxExtension & WasmExtension {
|
|
140
|
-
if (!this.queryClient) {
|
|
141
|
-
throw new Error("Query client not available. You cannot use online functionality in offline mode.");
|
|
142
|
-
}
|
|
143
|
-
return this.queryClient;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
public async getChainId(): Promise<string> {
|
|
147
|
-
if (!this.chainId) {
|
|
148
|
-
const response = await this.forceGetTmClient().status();
|
|
149
|
-
const chainId = response.nodeInfo.network;
|
|
150
|
-
if (!chainId) throw new Error("Chain ID must not be empty");
|
|
151
|
-
this.chainId = chainId;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return this.chainId;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
public async getHeight(): Promise<number> {
|
|
158
|
-
const status = await this.forceGetTmClient().status();
|
|
159
|
-
return status.syncInfo.latestBlockHeight;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
public async getAccount(searchAddress: string): Promise<Account | null> {
|
|
163
|
-
try {
|
|
164
|
-
const account = await this.forceGetQueryClient().auth.account(searchAddress);
|
|
165
|
-
return account ? accountFromAnyWasmx(account) : null;
|
|
166
|
-
} catch (error: any) {
|
|
167
|
-
if (/rpc error: code = NotFound/i.test(error.toString())) {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
throw error;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
public async getSequence(address: string): Promise<SequenceResponse> {
|
|
175
|
-
const account = await this.getAccount(address);
|
|
176
|
-
if (!account) {
|
|
177
|
-
throw new Error(
|
|
178
|
-
`Account '${address}' does not exist on chain. Send some tokens there before trying to query sequence.`,
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
return {
|
|
182
|
-
accountNumber: account.accountNumber,
|
|
183
|
-
sequence: account.sequence,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
public async getBlock(height?: number): Promise<Block> {
|
|
188
|
-
const response = await this.forceGetTmClient().block(height);
|
|
189
|
-
return {
|
|
190
|
-
id: toHex(response.blockId.hash).toUpperCase(),
|
|
191
|
-
header: {
|
|
192
|
-
version: {
|
|
193
|
-
block: new Uint53(response.block.header.version.block).toString(),
|
|
194
|
-
app: new Uint53(response.block.header.version.app).toString(),
|
|
195
|
-
},
|
|
196
|
-
height: response.block.header.height,
|
|
197
|
-
chainId: response.block.header.chainId,
|
|
198
|
-
time: toRfc3339WithNanoseconds(response.block.header.time),
|
|
199
|
-
},
|
|
200
|
-
txs: response.block.txs,
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
public async getBalance(address: string, searchDenom: string): Promise<Coin> {
|
|
205
|
-
return this.forceGetQueryClient().bank.balance(address, searchDenom);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
public async getTx(id: string): Promise<IndexedTx | null> {
|
|
209
|
-
const results = await this.txsQuery(`tx.hash='${id}'`);
|
|
210
|
-
return results[0] ?? null;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
public async searchTx(query: SearchTxQuery, filter: SearchTxFilter = {}): Promise<readonly IndexedTx[]> {
|
|
214
|
-
const minHeight = filter.minHeight || 0;
|
|
215
|
-
const maxHeight = filter.maxHeight || Number.MAX_SAFE_INTEGER;
|
|
216
|
-
|
|
217
|
-
if (maxHeight < minHeight) return []; // optional optimization
|
|
218
|
-
|
|
219
|
-
function withFilters(originalQuery: string): string {
|
|
220
|
-
return `${originalQuery} AND tx.height>=${minHeight} AND tx.height<=${maxHeight}`;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
let txs: readonly IndexedTx[];
|
|
224
|
-
|
|
225
|
-
if (isSearchByHeightQuery(query)) {
|
|
226
|
-
txs =
|
|
227
|
-
query.height >= minHeight && query.height <= maxHeight
|
|
228
|
-
? await this.txsQuery(`tx.height=${query.height}`)
|
|
229
|
-
: [];
|
|
230
|
-
} else if (isSearchBySentFromOrToQuery(query)) {
|
|
231
|
-
const sentQuery = withFilters(`message.module='bank' AND transfer.sender='${query.sentFromOrTo}'`);
|
|
232
|
-
const receivedQuery = withFilters(
|
|
233
|
-
`message.module='bank' AND transfer.recipient='${query.sentFromOrTo}'`,
|
|
234
|
-
);
|
|
235
|
-
const [sent, received] = await Promise.all(
|
|
236
|
-
[sentQuery, receivedQuery].map((rawQuery) => this.txsQuery(rawQuery)),
|
|
237
|
-
);
|
|
238
|
-
const sentHashes = sent.map((t) => t.hash);
|
|
239
|
-
txs = [...sent, ...received.filter((t) => !sentHashes.includes(t.hash))];
|
|
240
|
-
} else if (isSearchByTagsQuery(query)) {
|
|
241
|
-
const rawQuery = withFilters(query.tags.map((t) => `${t.key}='${t.value}'`).join(" AND "));
|
|
242
|
-
txs = await this.txsQuery(rawQuery);
|
|
243
|
-
} else {
|
|
244
|
-
throw new Error("Unknown query type");
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
const filtered = txs.filter((tx) => tx.height >= minHeight && tx.height <= maxHeight);
|
|
248
|
-
return filtered;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
public disconnect(): void {
|
|
252
|
-
if (this.tmClient) this.tmClient.disconnect();
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Broadcasts a signed transaction to the network and monitors its inclusion in a block.
|
|
257
|
-
*
|
|
258
|
-
* If broadcasting is rejected by the node for some reason (e.g. because of a CheckTx failure),
|
|
259
|
-
* an error is thrown.
|
|
260
|
-
*
|
|
261
|
-
* If the transaction is not included in a block before the provided timeout, this errors with a `TimeoutError`.
|
|
262
|
-
*
|
|
263
|
-
* If the transaction is included in a block, a `DeliverTxResponse` is returned. The caller then
|
|
264
|
-
* usually needs to check for execution success or failure.
|
|
265
|
-
*/
|
|
266
|
-
// NOTE: This method is tested against slow chains and timeouts in the @cosmjs/stargate package.
|
|
267
|
-
// Make sure it is kept in sync!
|
|
268
|
-
public async broadcastTx(
|
|
269
|
-
tx: Uint8Array,
|
|
270
|
-
timeoutMs = 60_000,
|
|
271
|
-
pollIntervalMs = 3_000,
|
|
272
|
-
): Promise<DeliverTxResponse> {
|
|
273
|
-
let timedOut = false;
|
|
274
|
-
const txPollTimeout = setTimeout(() => {
|
|
275
|
-
timedOut = true;
|
|
276
|
-
}, timeoutMs);
|
|
277
|
-
|
|
278
|
-
const pollForTx = async (txId: string): Promise<DeliverTxResponse> => {
|
|
279
|
-
if (timedOut) {
|
|
280
|
-
throw new TimeoutError(
|
|
281
|
-
`Transaction with ID ${txId} was submitted but was not yet found on the chain. You might want to check later. There was a wait of ${
|
|
282
|
-
timeoutMs / 1000
|
|
283
|
-
} seconds.`,
|
|
284
|
-
txId,
|
|
285
|
-
);
|
|
286
|
-
}
|
|
287
|
-
await sleep(pollIntervalMs);
|
|
288
|
-
const result = await this.getTx(txId);
|
|
289
|
-
return result
|
|
290
|
-
? {
|
|
291
|
-
code: result.code,
|
|
292
|
-
height: result.height,
|
|
293
|
-
rawLog: result.rawLog,
|
|
294
|
-
transactionHash: txId,
|
|
295
|
-
events: result.events,
|
|
296
|
-
gasUsed: result.gasUsed,
|
|
297
|
-
gasWanted: result.gasWanted,
|
|
298
|
-
txIndex: 0,
|
|
299
|
-
}
|
|
300
|
-
: pollForTx(txId);
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
const broadcasted = await this.forceGetTmClient().broadcastTxSync({ tx });
|
|
304
|
-
if (broadcasted.code) {
|
|
305
|
-
return Promise.reject(
|
|
306
|
-
new BroadcastTxError(broadcasted.code, broadcasted.codespace ?? "", broadcasted.log),
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
const transactionId = toHex(broadcasted.hash).toUpperCase();
|
|
310
|
-
return new Promise((resolve, reject) =>
|
|
311
|
-
pollForTx(transactionId).then(
|
|
312
|
-
(value) => {
|
|
313
|
-
clearTimeout(txPollTimeout);
|
|
314
|
-
resolve(value);
|
|
315
|
-
},
|
|
316
|
-
(error) => {
|
|
317
|
-
clearTimeout(txPollTimeout);
|
|
318
|
-
reject(error);
|
|
319
|
-
},
|
|
320
|
-
),
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* getCodes() returns all codes and is just looping through all pagination pages.
|
|
326
|
-
*
|
|
327
|
-
* This is potentially inefficient and advanced apps should consider creating
|
|
328
|
-
* their own query client to handle pagination together with the app's screens.
|
|
329
|
-
*/
|
|
330
|
-
public async getCodes(): Promise<readonly Code[]> {
|
|
331
|
-
const allCodes = [];
|
|
332
|
-
|
|
333
|
-
let startAtKey: Uint8Array | undefined = undefined;
|
|
334
|
-
do {
|
|
335
|
-
const { codeInfos, pagination }: QueryCodesResponse =
|
|
336
|
-
await this.forceGetQueryClient().wasm.listCodeInfo(startAtKey);
|
|
337
|
-
const loadedCodes = codeInfos || [];
|
|
338
|
-
allCodes.push(...loadedCodes);
|
|
339
|
-
startAtKey = pagination?.nextKey;
|
|
340
|
-
} while (startAtKey?.length !== 0);
|
|
341
|
-
|
|
342
|
-
return allCodes.map((entry: CodeInfoPB): Code => {
|
|
343
|
-
// assert(entry.creator && entry.codeId && entry.codeHash, "entry incomplete");
|
|
344
|
-
assert(entry.creator && entry.codeHash, "entry incomplete");
|
|
345
|
-
return {
|
|
346
|
-
// id: entry.codeId.toNumber(),
|
|
347
|
-
id: 0,
|
|
348
|
-
creator: entry.creator,
|
|
349
|
-
checksum: toHex(entry.codeHash),
|
|
350
|
-
};
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
public async getCodeDetails(codeId: number): Promise<CodeDetails> {
|
|
355
|
-
const cached = this.codesCache.get(codeId);
|
|
356
|
-
if (cached) return cached;
|
|
357
|
-
|
|
358
|
-
const { codeInfo, data } = await this.forceGetQueryClient().wasm.getCode(codeId);
|
|
359
|
-
assert(
|
|
360
|
-
codeInfo && codeInfo.creator && codeInfo.codeHash && data,
|
|
361
|
-
"codeInfo missing or incomplete",
|
|
362
|
-
);
|
|
363
|
-
const codeDetails: CodeDetails = {
|
|
364
|
-
id: codeId,
|
|
365
|
-
creator: codeInfo.creator,
|
|
366
|
-
checksum: toHex(codeInfo.codeHash),
|
|
367
|
-
data: data,
|
|
368
|
-
};
|
|
369
|
-
this.codesCache.set(codeId, codeDetails);
|
|
370
|
-
return codeDetails;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
public async getCodeInfo(codeId: number): Promise<CodeInfoPB> {
|
|
374
|
-
const cached = this.codeInfosCache.get(codeId);
|
|
375
|
-
if (cached) return cached;
|
|
376
|
-
|
|
377
|
-
const { codeInfo } = await this.forceGetQueryClient().wasm.getCodeInfo(codeId);
|
|
378
|
-
assert(
|
|
379
|
-
codeInfo && codeInfo.creator && codeInfo.codeHash,
|
|
380
|
-
"codeInfo missing or incomplete",
|
|
381
|
-
);
|
|
382
|
-
this.codeInfosCache.set(codeId, codeInfo);
|
|
383
|
-
return codeInfo;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* getContracts() returns all contract instances for one code and is just looping through all pagination pages.
|
|
388
|
-
*
|
|
389
|
-
* This is potentially inefficient and advanced apps should consider creating
|
|
390
|
-
* their own query client to handle pagination together with the app's screens.
|
|
391
|
-
*/
|
|
392
|
-
public async getContracts(codeId: number): Promise<readonly string[]> {
|
|
393
|
-
const allContracts = [];
|
|
394
|
-
let startAtKey: Uint8Array | undefined = undefined;
|
|
395
|
-
do {
|
|
396
|
-
const { contracts, pagination }: QueryContractsByCodeResponse =
|
|
397
|
-
await this.forceGetQueryClient().wasm.listContractsByCodeId(codeId, startAtKey);
|
|
398
|
-
const loadedContracts = contracts || [];
|
|
399
|
-
allContracts.push(...loadedContracts);
|
|
400
|
-
startAtKey = pagination?.nextKey;
|
|
401
|
-
} while (startAtKey?.length !== 0 && startAtKey !== undefined);
|
|
402
|
-
|
|
403
|
-
return allContracts;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
/**
|
|
407
|
-
* Throws an error if no contract was found at the address
|
|
408
|
-
*/
|
|
409
|
-
public async getContract(address: string): Promise<Contract> {
|
|
410
|
-
const { address: retrievedAddress, contractInfo } = await this.forceGetQueryClient().wasm.getContractInfo(
|
|
411
|
-
address,
|
|
412
|
-
);
|
|
413
|
-
if (!contractInfo) throw new Error(`No contract found at address "${address}"`);
|
|
414
|
-
assert(retrievedAddress, "address missing");
|
|
415
|
-
assert(contractInfo.codeId && contractInfo.creator && contractInfo.label, "contractInfo incomplete");
|
|
416
|
-
return {
|
|
417
|
-
address: retrievedAddress,
|
|
418
|
-
codeId: contractInfo.codeId.toNumber(),
|
|
419
|
-
creator: contractInfo.creator,
|
|
420
|
-
label: contractInfo.label,
|
|
421
|
-
ibcPortId: contractInfo.ibcPortId || undefined,
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Returns the data at the key if present (raw contract dependent storage data)
|
|
427
|
-
* or null if no data at this key.
|
|
428
|
-
*
|
|
429
|
-
* Promise is rejected when contract does not exist.
|
|
430
|
-
*/
|
|
431
|
-
public async queryContractRaw(address: string, key: Uint8Array): Promise<Uint8Array | null> {
|
|
432
|
-
// just test contract existence
|
|
433
|
-
await this.getContract(address);
|
|
434
|
-
|
|
435
|
-
const { data } = await this.forceGetQueryClient().wasm.queryContractRaw(address, key);
|
|
436
|
-
return data ?? null;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* Makes a smart query on the contract, returns the parsed JSON document.
|
|
441
|
-
*
|
|
442
|
-
* Promise is rejected when contract does not exist.
|
|
443
|
-
* Promise is rejected for invalid query format.
|
|
444
|
-
* Promise is rejected for invalid response format.
|
|
445
|
-
*/
|
|
446
|
-
public async queryContractSmart(address: string, queryMsg: JsonObject): Promise<JsonObject> {
|
|
447
|
-
try {
|
|
448
|
-
return await this.forceGetQueryClient().wasm.queryContractSmart(address, queryMsg);
|
|
449
|
-
} catch (error) {
|
|
450
|
-
if (error instanceof Error) {
|
|
451
|
-
if (error.message.startsWith("not found: contract")) {
|
|
452
|
-
throw new Error(`No contract found at address "${address}"`);
|
|
453
|
-
} else {
|
|
454
|
-
throw error;
|
|
455
|
-
}
|
|
456
|
-
} else {
|
|
457
|
-
throw error;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
public async queryContractFull(sender: string, address: string, queryMsg: JsonObject, funds: Coin[], dependencies: string[]): Promise<JsonObject> {
|
|
463
|
-
try {
|
|
464
|
-
return await this.forceGetQueryClient().wasm.queryContractFull(sender, address, queryMsg, funds, dependencies);
|
|
465
|
-
} catch (error) {
|
|
466
|
-
if (error instanceof Error) {
|
|
467
|
-
if (error.message.startsWith("not found: contract")) {
|
|
468
|
-
throw new Error(`No contract found at address "${address}"`);
|
|
469
|
-
} else {
|
|
470
|
-
throw error;
|
|
471
|
-
}
|
|
472
|
-
} else {
|
|
473
|
-
throw error;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
private async txsQuery(query: string): Promise<readonly IndexedTx[]> {
|
|
479
|
-
const results = await this.forceGetTmClient().txSearchAll({ query: query });
|
|
480
|
-
return results.txs.map((tx: any) => {
|
|
481
|
-
return {
|
|
482
|
-
height: tx.height,
|
|
483
|
-
hash: toHex(tx.hash).toUpperCase(),
|
|
484
|
-
code: tx.result.code,
|
|
485
|
-
events: tx.result.events.map(fromTendermintEvent),
|
|
486
|
-
rawLog: tx.result.log || "",
|
|
487
|
-
tx: tx.tx,
|
|
488
|
-
gasUsed: tx.result.gasUsed,
|
|
489
|
-
gasWanted: tx.result.gasWanted,
|
|
490
|
-
txIndex: tx.result.index,
|
|
491
|
-
};
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
}
|
package/tsconfig.eslint.json
DELETED
package/tsconfig.json
DELETED
package/typedoc.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const packageJson = require("./package.json");
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
entryPoints: ["./src"],
|
|
5
|
-
out: "docs",
|
|
6
|
-
exclude: "**/*.spec.ts",
|
|
7
|
-
name: `${packageJson.name} Documentation`,
|
|
8
|
-
readme: "README.md",
|
|
9
|
-
excludeExternals: true,
|
|
10
|
-
excludePrivate: true,
|
|
11
|
-
};
|
package/webpack.web.config.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
const glob = require("glob");
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const webpack = require("webpack");
|
|
5
|
-
|
|
6
|
-
const target = "web";
|
|
7
|
-
const distdir = path.join(__dirname, "dist", "web");
|
|
8
|
-
|
|
9
|
-
module.exports = [
|
|
10
|
-
{
|
|
11
|
-
// bundle used for Karma tests
|
|
12
|
-
target: target,
|
|
13
|
-
entry: glob.sync("./build/**/*.spec.js"),
|
|
14
|
-
output: {
|
|
15
|
-
path: distdir,
|
|
16
|
-
filename: "tests.js",
|
|
17
|
-
},
|
|
18
|
-
plugins: [
|
|
19
|
-
new webpack.EnvironmentPlugin({
|
|
20
|
-
WASMD_ENABLED: "",
|
|
21
|
-
}),
|
|
22
|
-
new webpack.ProvidePlugin({
|
|
23
|
-
Buffer: ["buffer", "Buffer"],
|
|
24
|
-
}),
|
|
25
|
-
],
|
|
26
|
-
resolve: {
|
|
27
|
-
fallback: {
|
|
28
|
-
buffer: false,
|
|
29
|
-
crypto: false,
|
|
30
|
-
events: false,
|
|
31
|
-
path: false,
|
|
32
|
-
stream: false,
|
|
33
|
-
string_decoder: false,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
];
|