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

Adds newly supported classic ops, tweaks route and query for history #8

Merged
merged 23 commits into from
Dec 13, 2023

Conversation

aristidesstaffieri
Copy link
Contributor

@aristidesstaffieri aristidesstaffieri commented Nov 20, 2023

Adds new classic ops recently added to Mercury.

This adds the remaining classic side ops queries to be used for account history routes.
Also fixes a few small query bugs found during testing.
Adds fallback to Horizon and transformer.

Notes -
This completes the queries needed for data parity with Horizon/Soroban RPC.

@aristidesstaffieri aristidesstaffieri self-assigned this Nov 20, 2023
@aristidesstaffieri aristidesstaffieri changed the title [WIP] adds newly supported classic ops, tweaks route and query for history Adds newly supported classic ops, tweaks route and query for history Nov 29, 2023
@aristidesstaffieri aristidesstaffieri marked this pull request as ready for review November 29, 2023 17:34
contractId: edge.node.contractId,
fnName: scValToNative(xdr.ScVal.fromXDR(edge.node.topic1, "base64")),
to: scValToNative(xdr.ScVal.fromXDR(edge.node.topic3, "base64")),
from: scValToNative(xdr.ScVal.fromXDR(edge.node.topic2, "base64")),
Copy link
Contributor

Choose a reason for hiding this comment

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

there's some repetition in the return value that can be cleaned up in a future PR:

For ex: you could:

const fnName = scValToNative(xdr.ScVal.fromXDR(edge.node.topic1, "base64"));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I don't see where? Each scValToNative(xdr.ScVal.fromXDR(edge.node.topic1, "base64")) is for a different event in this case.

Copy link
Contributor

@piyalbasu piyalbasu Dec 5, 2023

Choose a reason for hiding this comment

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

Oh my bad - I read this wrong. Disregard my code suggestion above :) But I do wonder if some helpers could be useful here. Maybe something more like

const transferEdgeHelper = (edge) => ({
        contractId: edge.node.contractId,
        fnName: scValToNative(xdr.ScVal.fromXDR(edge.node.topic1, "base64")),
        to: scValToNative(xdr.ScVal.fromXDR(edge.node.topic3, "base64")),
        from: scValToNative(xdr.ScVal.fromXDR(edge.node.topic2, "base64")),
});

Mostly just trying to guard against these attrs from falling out of sync because of a typo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh yeah 100%, I'll make that helper since they're all the same shape.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm actually after looking at this again I think the differences make this trickier to abstract. Each topic from each event correspond to a different key dependent on the event. So even though we see a few lines that have similar code like scValToNative(xdr.ScVal.fromXDR(some topic, "base64")), they name of the key and topic should be mapped according to what the event itself names them, so for mint - topic 2 is the to arg but for transferTo, the to arg is topic3.

Let me know if you think differently but I think this means the helper would have to be per topic which seems like less of an abstraction.

source_account: pubKey,
asset_issuer: edge.node.contractId,
asset_code: tokenDetails.symbol,
type: "invoke_host_function",
Copy link
Contributor

Choose a reason for hiding this comment

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

you can use the enum OperationResponseType from stellar-sdk for these types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah nice, thank you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so right now I cast this as a Partial<Horizon.ServerApi.InvokeHostFunctionOperationRecord> which extends from the base OperationResponseType. I think these are more accurate because they map to the specific op were building up. Let me know if I missed what you meant here but I think the underlying type for the specific op gives us a more accurate type here.

} catch (error) {
this.logger.error(error);
const _error = JSON.stringify(error);
this.logger.error(_error);
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that you have an established pattern of logging the raw error and then a string version of the error. I think that makes sense when the string version has some added info to make it more human readable. In this case, would this be a little noisy? Basically just seeing the same error twice in a row?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah I see yeah I think this is because the router has a built in logger that logs any uncaught errors in the route itself, so yeah maybe it makes sense to not log these in the services at all, good call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh wait I see now that this one is just a copy pasta, removed in ce46724

@aristidesstaffieri aristidesstaffieri merged commit 88d8d43 into main Dec 13, 2023
3 checks passed
@aristidesstaffieri aristidesstaffieri deleted the feat/more-classic-ops branch December 13, 2023 21:06
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.

2 participants