diff --git a/package.json b/package.json index b4d1c07..02b5325 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cybercongress/cyber-js", - "version": "0.3.9", + "version": "0.3.91", "description": "Cyber SDK", "license": "", "main": "build/index.js", @@ -29,13 +29,13 @@ "format-text": "prettier --write \"./*.md\"" }, "dependencies": { - "@cosmjs/cosmwasm-stargate": "^0.30.0", - "@cosmjs/stargate": "^0.30.0", - "@cosmjs/amino": "^0.30.0", - "@cosmjs/crypto": "^0.30.0", - "@cosmjs/math": "^0.30.0", - "@cosmjs/proto-signing": "^0.30.0", - "@cosmjs/utils": "^0.30.0", + "@cosmjs/amino": "0.31.3", + "@cosmjs/cosmwasm-stargate": "0.31.3", + "@cosmjs/crypto": "0.31.3", + "@cosmjs/math": "0.31.3", + "@cosmjs/proto-signing": "0.31.3", + "@cosmjs/stargate": "0.31.3", + "@cosmjs/utils": "0.31.3", "cosmjs-types": "^0.7", "fast-deep-equal": "^3.1.3", "fs-extra": "^10.1.0", diff --git a/src/cyberclient.ts b/src/cyberclient.ts index f20987c..2deb221 100644 --- a/src/cyberclient.ts +++ b/src/cyberclient.ts @@ -23,12 +23,7 @@ import { GovProposalId, IbcExtension, IndexedTx, - isSearchByHeightQuery, - isSearchBySentFromOrToQuery, - isSearchByTagsQuery, QueryClient, - SearchTxFilter, - SearchTxQuery, SequenceResponse, setupAuthExtension, setupBankExtension, @@ -47,7 +42,6 @@ import { toRfc3339WithNanoseconds, } from "@cosmjs/tendermint-rpc"; import { assert } from "@cosmjs/utils"; -import { QueryTotalSupplyResponse } from "cosmjs-types/cosmos/bank/v1beta1/query"; import { QueryCommunityPoolResponse, QueryDelegationRewardsResponse, @@ -137,6 +131,7 @@ import { setupRankExtension, setupResourcesExtension, } from "./queries/index"; +import { CyberSearchTxFilter, CyberSearchTxQuery } from "./types"; export { Code, CodeDetails, Contract, ContractCodeHistoryEntry }; @@ -318,7 +313,10 @@ export class CyberClient { return results[0] ?? null; } - public async searchTx(query: SearchTxQuery, filter: SearchTxFilter = {}): Promise { + public async searchTx( + query: CyberSearchTxQuery, + filter: CyberSearchTxFilter = {}, + ): Promise { const minHeight = filter.minHeight || 0; const maxHeight = filter.maxHeight || Number.MAX_SAFE_INTEGER; @@ -330,12 +328,12 @@ export class CyberClient { let txs: readonly IndexedTx[]; - if (isSearchByHeightQuery(query)) { + if (query?.height !== undefined) { txs = query.height >= minHeight && query.height <= maxHeight ? await this.txsQuery(`tx.height=${query.height}`) : []; - } else if (isSearchBySentFromOrToQuery(query)) { + } else if (query?.sentFromOrTo !== undefined) { const sentQuery = withFilters(`message.module='bank' AND transfer.sender='${query.sentFromOrTo}'`); const receivedQuery = withFilters( `message.module='bank' AND transfer.recipient='${query.sentFromOrTo}'`, @@ -345,7 +343,7 @@ export class CyberClient { ); const sentHashes = sent.map((t) => t.hash); txs = [...sent, ...received.filter((t) => !sentHashes.includes(t.hash))]; - } else if (isSearchByTagsQuery(query)) { + } else if (query?.tags !== undefined) { const rawQuery = withFilters(query.tags.map((t) => `${t.key}='${t.value}'`).join(" AND ")); txs = await this.txsQuery(rawQuery); } else { @@ -363,6 +361,7 @@ export class CyberClient { public async broadcastTx(tx: Uint8Array): Promise { const broadcasted = await this.forceGetTmClient().broadcastTxSync({ tx }); const transactionId = toHex(broadcasted.hash).toUpperCase(); + return { code: broadcasted.code, height: 0, @@ -372,6 +371,7 @@ export class CyberClient { gasWanted: broadcasted.gasWanted, txIndex: 0, events: [], // TODO: broadcasted.events, + msgResponses: [], }; } @@ -916,6 +916,7 @@ export class CyberClient { gasWanted: tx.result.gasWanted, txIndex: tx.index, events: [], // TODO: tx.result.events || [], + msgResponses: [], }; }); } diff --git a/src/renderItems.ts b/src/renderItems.ts index 8034a64..686600a 100644 --- a/src/renderItems.ts +++ b/src/renderItems.ts @@ -1,7 +1,7 @@ import { toUtf8 } from "@cosmjs/encoding"; import { Uint53 } from "@cosmjs/math"; import { longify } from "@cosmjs/stargate/build/queryclient"; -import { MsgExec, MsgGrant, MsgRevoke } from "cosmjs-types/cosmos/authz/v1beta1/tx"; +// import { MsgExec, MsgGrant, MsgRevoke } from "cosmjs-types/cosmos/authz/v1beta1/tx"; import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx"; import { MsgWithdrawDelegatorReward } from "cosmjs-types/cosmos/distribution/v1beta1/tx"; import { MsgDeposit, MsgSubmitProposal, MsgVote } from "cosmjs-types/cosmos/gov/v1beta1/tx"; @@ -37,13 +37,6 @@ const testAddress2 = "bostrom1frk9k38pvp70vheezhdfd4nvqnlsm9dw3j8hlw"; const testContract = "bostrom1nwnejwsdpqktusvh8qhxe5arsznjd5asdwutmaz9n5qcpl3dcmhsujhemd"; const testValidatorAddress = "bostromvaloper135ca8hdpy9sk0ntwqzpzsvatyl48ptx52tn60p"; -const executePlaceholder = { - transfer: { - recipient: "bostrom1p0r7uxstcw8ehrwuj4kn8qzzs0yypsjwxgd445", - amount: "1", - }, -}; - const depositCoin = { denom: "boot", amount: "1000000" }; const depositCoins = [ @@ -51,26 +44,10 @@ const depositCoins = [ { denom: "hydrogen", amount: "1000000" }, ]; -const instantiatePlaceholder = { - name: "Nation coin", - symbol: "NTN", - decimals: 0, - initial_balances: [ - { - address: "bostrom1p0r7uxstcw8ehrwuj4kn8qzzs0yypsjwxgd445", - amount: "100000", - }, - ], - mint: { - minter: "bostrom1p0r7uxstcw8ehrwuj4kn8qzzs0yypsjwxgd445", - cap: "1000000", - }, -}; - interface RenderItem { typeUrl: string; value: Partial; - data: {}; + data: any; } interface RenderItems extends Array {} diff --git a/src/signingcyberclient.ts b/src/signingcyberclient.ts index c253696..03ea1cf 100644 --- a/src/signingcyberclient.ts +++ b/src/signingcyberclient.ts @@ -133,14 +133,14 @@ export function links(from: string, to: string): Link[] { } export function chain(particles: string[]): Link[] { - const chain = []; + const chainResult = []; for (let i = 0; i < particles.length - 1; i++) { - chain.push({ + chainResult.push({ from: particles[i], to: particles[i + 1], }); } - return chain; + return chainResult; } // Experimental for remote dapps with cyb's signer integration @@ -256,9 +256,9 @@ export class SigningCyberClient extends CyberClient { } public render(): string { - const arr: Array<{}> = []; + const arr: Array> = []; - renderItems.forEach((i, o) => { + renderItems.forEach((i) => { arr.push({ [i.typeUrl.toString()]: { proto: { @@ -986,11 +986,11 @@ export class SigningCyberClient extends CyberClient { memo = "", ): Promise { // Experimental for remote dapps with cyb's signer integration - const msg = messages.map((msg) => this.aminoTypes.fromAmino({ type: msg.type, value: msg.value })); + const msgs = messages.map((msg) => this.aminoTypes.fromAmino({ type: msg.type, value: msg.value })); if (isOfflineDappSigner(this.signer)) { - return msg.map((m) => toBase64(Buffer.from(JSON.stringify(m), "utf-8"))); + return msgs.map((m) => toBase64(Buffer.from(JSON.stringify(m), "utf-8"))); } - const txRaw = await this.sign(signerAddress, msg, fee, memo); + const txRaw = await this.sign(signerAddress, msgs, fee, memo); const txBytes = TxRaw.encode(txRaw).finish(); return this.broadcastTx(txBytes); } diff --git a/src/types.ts b/src/types.ts index b8e7c3f..183e75f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -34,3 +34,14 @@ export interface Link { from: string; to: string; } + +export interface CyberSearchTxFilter { + readonly minHeight?: number; + readonly maxHeight?: number; +} + +export interface CyberSearchTxQuery { + sentFromOrTo?: string; + height?: number; + tags?: ReadonlyArray<{ readonly key: string; readonly value: string }>; +}