Skip to content

Commit

Permalink
update cosmjs to 0.31.3 (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
dasein108 authored Apr 29, 2024
1 parent 25e619c commit c7b629a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 51 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cybercongress/cyber-js",
"version": "0.3.9",
"version": "0.3.91",
"description": "Cyber SDK",
"license": "",
"main": "build/index.js",
Expand Down Expand Up @@ -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",
Expand Down
21 changes: 11 additions & 10 deletions src/cyberclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ import {
GovProposalId,
IbcExtension,
IndexedTx,
isSearchByHeightQuery,
isSearchBySentFromOrToQuery,
isSearchByTagsQuery,
QueryClient,
SearchTxFilter,
SearchTxQuery,
SequenceResponse,
setupAuthExtension,
setupBankExtension,
Expand All @@ -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,
Expand Down Expand Up @@ -137,6 +131,7 @@ import {
setupRankExtension,
setupResourcesExtension,
} from "./queries/index";
import { CyberSearchTxFilter, CyberSearchTxQuery } from "./types";

export { Code, CodeDetails, Contract, ContractCodeHistoryEntry };

Expand Down Expand Up @@ -318,7 +313,10 @@ export class CyberClient {
return results[0] ?? null;
}

public async searchTx(query: SearchTxQuery, filter: SearchTxFilter = {}): Promise<readonly IndexedTx[]> {
public async searchTx(
query: CyberSearchTxQuery,
filter: CyberSearchTxFilter = {},
): Promise<readonly IndexedTx[]> {
const minHeight = filter.minHeight || 0;
const maxHeight = filter.maxHeight || Number.MAX_SAFE_INTEGER;

Expand All @@ -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}'`,
Expand All @@ -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 {
Expand All @@ -363,6 +361,7 @@ export class CyberClient {
public async broadcastTx(tx: Uint8Array): Promise<DeliverTxResponse> {
const broadcasted = await this.forceGetTmClient().broadcastTxSync({ tx });
const transactionId = toHex(broadcasted.hash).toUpperCase();

return {
code: broadcasted.code,
height: 0,
Expand All @@ -372,6 +371,7 @@ export class CyberClient {
gasWanted: broadcasted.gasWanted,
txIndex: 0,
events: [], // TODO: broadcasted.events,
msgResponses: [],
};
}

Expand Down Expand Up @@ -916,6 +916,7 @@ export class CyberClient {
gasWanted: tx.result.gasWanted,
txIndex: tx.index,
events: [], // TODO: tx.result.events || [],
msgResponses: [],
};
});
}
Expand Down
27 changes: 2 additions & 25 deletions src/renderItems.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -37,40 +37,17 @@ const testAddress2 = "bostrom1frk9k38pvp70vheezhdfd4nvqnlsm9dw3j8hlw";
const testContract = "bostrom1nwnejwsdpqktusvh8qhxe5arsznjd5asdwutmaz9n5qcpl3dcmhsujhemd";
const testValidatorAddress = "bostromvaloper135ca8hdpy9sk0ntwqzpzsvatyl48ptx52tn60p";

const executePlaceholder = {
transfer: {
recipient: "bostrom1p0r7uxstcw8ehrwuj4kn8qzzs0yypsjwxgd445",
amount: "1",
},
};

const depositCoin = { denom: "boot", amount: "1000000" };

const depositCoins = [
{ denom: "boot", amount: "1000000" },
{ 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<any>;
data: {};
data: any;
}

interface RenderItems extends Array<RenderItem> {}
Expand Down
16 changes: 8 additions & 8 deletions src/signingcyberclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -256,9 +256,9 @@ export class SigningCyberClient extends CyberClient {
}

public render(): string {
const arr: Array<{}> = [];
const arr: Array<Record<string, any>> = [];

renderItems.forEach((i, o) => {
renderItems.forEach((i) => {
arr.push({
[i.typeUrl.toString()]: {
proto: {
Expand Down Expand Up @@ -986,11 +986,11 @@ export class SigningCyberClient extends CyberClient {
memo = "",
): Promise<DeliverTxResponse | string[]> {
// 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);
}
Expand Down
11 changes: 11 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>;
}

0 comments on commit c7b629a

Please sign in to comment.