-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from cosmology-tech/signing-client
Signing client
- Loading branch information
Showing
40 changed files
with
715 additions
and
2,534 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.