-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cosmwasmclient extension & signingcosmwasmclient implementation (…
…#379) * feat: nibicosmwasmclient * feat: nibi signing cosm wasm client * refactor: adding nibi account parser to nibi signingcosmwasmclient * test: remove unused test file * test: take signingcosmwasmclient from coverage * chore: fix coverage
- Loading branch information
1 parent
b79eae5
commit b89a700
Showing
6 changed files
with
916 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate" | ||
import { | ||
Account, | ||
accountFromAny, | ||
AccountParser, | ||
HttpEndpoint, | ||
SequenceResponse, | ||
} from "@cosmjs/stargate" | ||
import { CometClient } from "@cosmjs/tendermint-rpc" | ||
|
||
export interface NibiCosmWasmClientOptions { | ||
readonly accountParser?: AccountParser | ||
} | ||
|
||
export class NibiCosmWasmClient extends CosmWasmClient { | ||
private readonly accountParser: AccountParser | ||
|
||
protected constructor( | ||
cometClient: CometClient | undefined, | ||
options: NibiCosmWasmClientOptions = {} | ||
) { | ||
super(cometClient) | ||
const { accountParser = accountFromAny } = options | ||
this.accountParser = accountParser | ||
} | ||
|
||
public static async connect( | ||
endpoint: string | HttpEndpoint, | ||
options: NibiCosmWasmClientOptions = {} | ||
): Promise<NibiCosmWasmClient> { | ||
const cosmWasmClient = await CosmWasmClient.connect(endpoint) | ||
return new NibiCosmWasmClient(cosmWasmClient["cometClient"], options) | ||
} | ||
|
||
public async getAccount(searchAddress: string): Promise<Account | null> { | ||
try { | ||
const account = await this.forceGetQueryClient().auth.account( | ||
searchAddress | ||
) | ||
return account ? this.accountParser(account) : null | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
} catch (error: any) { | ||
if (/rpc error: code = NotFound/i.test(error.toString())) { | ||
return null | ||
} | ||
throw error | ||
} | ||
} | ||
|
||
public async getSequence(address: string): Promise<SequenceResponse> { | ||
const account = await this.getAccount(address) | ||
if (!account) { | ||
throw new Error( | ||
`Account '${address}' does not exist on chain. Send some tokens there before trying to query sequence.` | ||
) | ||
} | ||
return { | ||
accountNumber: account.accountNumber, | ||
sequence: account.sequence, | ||
} | ||
} | ||
} |
Oops, something went wrong.