Skip to content

Commit

Permalink
Merge pull request #26 from cosmology-tech/signing-client
Browse files Browse the repository at this point in the history
Signing client
  • Loading branch information
Zetazzz authored Jul 9, 2024
2 parents a554daa + 20c07bb commit 88218dc
Show file tree
Hide file tree
Showing 40 changed files with 715 additions and 2,534 deletions.
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

0 comments on commit 88218dc

Please sign in to comment.