Skip to content

Commit

Permalink
fix: only query finalized blocks in javascript client (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayWhite2357 authored Nov 26, 2024
2 parents fa48f07 + 8222b5c commit 9464746
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions node/src/index_tail.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,41 @@ export class SxTClient {
}
return authResponse.json();
}
async #getCommitment(commitmentKey, blockHash = null) {
const params = blockHash ? [commitmentKey, blockHash] : [commitmentKey]

const commitmentResponse = await postHttpRequest({
async #querySubstrateRpc(method, params = null) {
const response = await postHttpRequest({
url: this.substrateNodeURL,
headers: {
"Content-Type": "application/json",
},
data: {
id: 1,
jsonrpc: "2.0",
method: "state_getStorage",
method,
params,
},
}
});

if (!commitmentResponse.ok) {
if (!response.ok) {
throw new Error(
`Error querying RPC node: ${commitmentResponse.status}: ${commitmentResponse.statusText}`,
`Error querying RPC node: ${response.status}: ${response.statusText}`,
);
}

return commitmentResponse.json();
return response.json()
}
async #getFinalizedHead() {
const response = await this.#querySubstrateRpc("chain_getFinalizedHead");

return response.result
}
async #getCommitment(commitmentKey, blockHash = null) {
if (!blockHash) {
blockHash = await this.#getFinalizedHead();
}

const commitmentResponse = await this.#querySubstrateRpc("state_getStorage", [commitmentKey, blockHash]);

return commitmentResponse;
}
async #getProof(accessToken, proverQuery) {
const proverResponse = await postHttpRequest({
Expand Down

0 comments on commit 9464746

Please sign in to comment.