Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0.0: Fix remaining REST untyped responses #882

Merged
merged 9 commits into from
Aug 15, 2024

Conversation

jasonpaulos
Copy link
Contributor

@jasonpaulos jasonpaulos commented Aug 8, 2024

Prior to this PR, the following algod request classes still had untyped responses: Genesis, GetLedgerStateDelta, GetLedgerStateDeltaForTransactionGroup, GetTransactionGroupLedgerStateDeltasForRound, HealthCheck, Ready, SetBlockOffsetTimestamp, SetSyncRound, UnsetSyncRound. These mostly fall into two categories: either they return no information, or they returned something related to state deltas and were passed over when #776 was merged.

This PR resolves this and fixes a few other related issues/improvements:

  • HTTPClient no longer parses JSON responses. This simplifies the prepare method in request classes and no longer requires passing in JSON parsing options at the time of every request.
  • POST & DELETE requests used to override the do method to implement their requests. That meant the doRaw method wasn't overridden and would produce incorrect results. Fixed by moving the override to a new executeRequest method which is called from both do and doRaw.
  • Removed the second, unneeded generic type argument from JSONRequest
  • Added BlockHashSchema because JSON block hashes get b32 encoded and prefixed with blk-.
  • Added LedgerStateDelta and required subtypes. This comes with the caveat that the SDK does not currently support decoding maps with object keys (needed to support the Txleases field), so I've left that as an UntypedValue for now. I'll open a separate issue to track that, but I don't view it as urgent/required for v3.

Relies on algorand/generator#80

Copy link
Contributor

@algorandskiy algorandskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good to me.
It was a great effort to support all these types spawn by StateDelta but I do think it was mistake making StateDelta available through REST API. It was always thought as ledger internal so that easily modifiable as needed.

// eslint-disable-next-line class-methods-use-this
path() {
return '/health';
}

async do(headers = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm I right and the overridden do was needed only becase jsonOptions: { intDecoding: IntDecoding.BIGINT } ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the reason for it was so that an error could be thrown if the request failed. But it wasn't really effective, since if res.ok was false the underlying c.get method would already throw an error.

And since this method doesn't return any data, the bigint decoding doesn't really make a difference.

Copy link
Contributor

@gmalouf gmalouf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About 70% through, minimal comments so far.

src/client/client.ts Show resolved Hide resolved
@jasonpaulos jasonpaulos merged commit ceccfe4 into 3.0.0 Aug 15, 2024
2 checks passed
@jasonpaulos jasonpaulos deleted the rest-untyped-responses-fix branch August 15, 2024 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants