-
Notifications
You must be signed in to change notification settings - Fork 8
/
txClient.ts
97 lines (91 loc) · 2.7 KB
/
txClient.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { GeneratedType, OfflineSigner, Registry } from "@cosmjs/proto-signing"
import {
defaultRegistryTypes,
GasPrice,
QueryClient,
setupAuthExtension,
setupDistributionExtension,
setupGovExtension,
setupIbcExtension,
setupStakingExtension,
SigningStargateClient,
SigningStargateClientOptions,
} from "@cosmjs/stargate"
import { Tendermint37Client } from "@cosmjs/tendermint-rpc"
import { setupWasmExtension } from "@cosmjs/cosmwasm-stargate"
import { NibiruExtensions, setupNibiruExtension } from ".."
import { accountFromNibiru } from "./account"
import {
NibiSigningCosmWasmClient,
NibiSigningCosmWasmClientOptions,
} from "../core/signingcosmwasmclient"
export const nibiruRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [
...defaultRegistryTypes,
]
export class NibiruTxClient extends SigningStargateClient {
public readonly nibiruExtensions: NibiruExtensions
public readonly wasmClient: NibiSigningCosmWasmClient
protected constructor(
tmClient: Tendermint37Client,
signer: OfflineSigner,
options: SigningStargateClientOptions,
wasm: NibiSigningCosmWasmClient
) {
super(tmClient, signer, options)
this.wasmClient = wasm
this.nibiruExtensions = QueryClient.withExtensions(
tmClient,
setupDistributionExtension,
setupGovExtension,
setupStakingExtension,
setupIbcExtension,
setupWasmExtension,
setupAuthExtension,
setupNibiruExtension
)
}
public static async connectWithSigner(
endpoint: string,
signer: OfflineSigner,
options: SigningStargateClientOptions = {},
wasmOptions: NibiSigningCosmWasmClientOptions = {}
): Promise<NibiruTxClient> {
const tmClient = await Tendermint37Client.connect(endpoint)
const wasmClient = await NibiSigningCosmWasmClient.connectWithSigner(
endpoint,
signer,
{
gasPrice: GasPrice.fromString("0.025unibi"),
accountParser: accountFromNibiru,
...wasmOptions,
}
)
return new NibiruTxClient(
tmClient,
signer,
{
registry: new Registry(nibiruRegistryTypes),
gasPrice: GasPrice.fromString("0.025unibi"),
broadcastPollIntervalMs: 1_000, // 1 second poll times
accountParser: accountFromNibiru,
...options,
},
wasmClient
)
}
public async waitForHeight(height: number) {
while ((await this.getHeight()) < height) {
await new Promise((resolve) => {
setTimeout(resolve, 300)
})
}
}
public async waitForNextBlock() {
const currentHeight = await this.getHeight()
while (currentHeight == (await this.getHeight())) {
await new Promise((resolve) => {
setTimeout(resolve, 300)
})
}
}
}