Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signing client #26

Merged
merged 9 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "Debug Jest Tests in inj",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"--config",
"./jest.starship.config.js",
"--verbose",
"--bail",
"starship/__tests__/gov.test.ts"
],
"console": "integratedTerminal",
"cwd": "${workspaceFolder}/networks/injective",
"internalConsoleOptions": "neverOpen"
}
"type": "node",
"request": "launch",
"name": "Debug Jest Tests in Interchainjs",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"--config",
"./jest.starship.config.js",
"--verbose",
"--bail",
"starship/__tests__/token.test.ts"
],
"console": "integratedTerminal",
"cwd": "${workspaceFolder}/libs/interchainjs",
"internalConsoleOptions": "neverOpen"
}
]
}
4 changes: 2 additions & 2 deletions libs/interchainjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
"build:dev": "npm run clean; tsc --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
"lint": "eslint . --fix",
"starship": "starship --config ./starship/configs/starship.yaml",
"starship:local": "starship --config ./starship/configs/starship.local.yaml",
"starship": "starship --config ./starship/configs/config.yaml",
"starship:local": "starship --config ./starship/configs/config.local.yaml",
"starship:test": "jest --config ./jest.starship.config.js --verbose --bail",
"starship:debug": "jest --config ./jest.starship.config.js --runInBand --verbose --bail",
"starship:watch": "jest --watch --config ./jest.starship.config.js",
Expand Down
36 changes: 20 additions & 16 deletions libs/interchainjs/src/cosmwasm-stargate.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
import { AminoSigner } from '@interchainjs/cosmos/amino';
import { RpcClient } from '@interchainjs/cosmos/query/rpc';
import { QueryClient } from '@interchainjs/cosmos/types';
import { OfflineSigner } from '@interchainjs/cosmos/types/wallet';
import { toConverter, toEncoder } from '@interchainjs/cosmos/utils';
import { CosmWasmMsgs } from '@interchainjs/cosmos-types/cosmwasm';
import { CosmWasmStargateImpl as TxImpl } from '@interchainjs/cosmos-types/service-ops';
import { StargateMsgs } from '@interchainjs/cosmos-types/stargate';
import { HttpEndpoint } from '@interchainjs/types';

import { SigningClient } from './signing-client';
import { SignerOptions } from './types/signing-client';
import { defaultAuth } from './utils';

export class CosmWasmSigningClient extends SigningClient {
readonly helpers: TxImpl;

constructor(
aminoSigner: AminoSigner,
client: QueryClient | null | undefined,
offlineSigner: OfflineSigner,
options: SignerOptions = {}
) {
super(aminoSigner, offlineSigner, options);
this.aminoSigner.addEncoders(
[...StargateMsgs, ...CosmWasmMsgs].map((g) => toEncoder(g))
);
this.aminoSigner.addConverters(
[...StargateMsgs, ...CosmWasmMsgs].map((g) => toConverter(g))
);
const msgs = [...StargateMsgs, ...CosmWasmMsgs];
options.registry = options.registry || [];
options.registry = options.registry.concat(msgs.map((g) => [g.typeUrl, g]));

options.aminoConverters = options.aminoConverters || {};

msgs.forEach((g) => {
options.aminoConverters[g.typeUrl] = g;
});

super(client, offlineSigner, options);
this.helpers = new TxImpl();
this.helpers.init(this.txRpc);
}

static connectWithSigner(
static async connectWithSigner(
endpoint: string | HttpEndpoint,
signer: OfflineSigner,
options: SignerOptions = {}
): CosmWasmSigningClient {
const aminoSigner = new AminoSigner(defaultAuth, [], []);
): Promise<CosmWasmSigningClient> {
const signingClient = new CosmWasmSigningClient(
aminoSigner,
new RpcClient(endpoint, undefined, options.prefix),
signer,
options
);
signingClient.setEndpoint(endpoint);

await signingClient.connect();

return signingClient;
}
}
Loading
Loading