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

add helper for parsing AnchorTransaction #111

Merged
merged 3 commits into from
Mar 26, 2024
Merged

Conversation

acharb
Copy link
Contributor

@acharb acharb commented Mar 19, 2024

@@ -57,3 +57,15 @@ describe("SEP-10 helpers", () => {
expect(isValid).toBeFalsy();
});
});

describe("Server helpers", () => {
it("should parse a JSON AnchorTransaction", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test for MGI incomplete transactions?

Copy link
Contributor Author

@acharb acharb Mar 20, 2024

Choose a reason for hiding this comment

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

ya, do you have a json string by chance? I'm having trouble generating one

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll get one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @Ifropc were you able to get one?

Copy link
Contributor

@piyalbasu piyalbasu left a comment

Choose a reason for hiding this comment

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

Looks good from a JS perspective. Once the incomplete tx test is in, we should be good

transaction: string,
): AnchorTransaction => {
const parsed = JSON.parse(transaction);
if (parsed.kind === "withdrawal") {
Copy link
Contributor

@CassioMG CassioMG Mar 25, 2024

Choose a reason for hiding this comment

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

should this method recognize withdrawal-exchange and deposit-exchange kinds as well? I know the task is about Sep-24 but in case we wanna make it Sep-6 friendly as well we could easily adapt it by checking parsed.kind?.includes("withdrawal") instead of the direct === comparison. Wdyt?

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 like the idea but imo I think separating the parse functions would be better bc of the types. The types for sep6 and sep24 transactions are similar but have slight differences. I think if we'd want to add a parse method for sep6 it should be a separate method to make it clear what the method is returning 🤔

right now it's returning AnchorTransaction, if it was returning AnchorTransaction | Sep6Transaction I think it would be a bit messy / too general

imo we can add in a separate PR if it's needed

if you feel strongly though lmk!

Copy link
Contributor

Choose a reason for hiding this comment

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

that makes sense to me!

export const parseAnchorTransaction = (
transaction: string,
): AnchorTransaction => {
const parsed = JSON.parse(transaction);
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe JSON.parse() alone can throw, should we wrap it with try catch just in case we receive something not well formatted from the server?

Copy link
Contributor

Choose a reason for hiding this comment

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

And throw a different error in this case, something like TransactionIsNotValidJSONError() or similar.

Too conservative?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ya I was on the fence if the try-catch should be handled here or by the function using this method.

But I think you've nudged me over the edge :)
4684622

@acharb
Copy link
Contributor Author

acharb commented Mar 26, 2024

spoke with @Ifropc offline, going to merge this in to unblock it and will add the MGI test in a subsequent PR

tracking it here https://stellarorg.atlassian.net/browse/WAL-1409

@acharb acharb merged commit 5d627da into release/1.4.0 Mar 26, 2024
5 checks passed
@acharb acharb deleted the acharb-parsejson branch March 26, 2024 00:27
acharb added a commit that referenced this pull request Mar 26, 2024
* fix broken test (#93)

* add sep10 sign challenge txn helper (#95)

* add sep10 helper method

* name change

* correct resp

* create server module

* add npm publish gha (#96)

* WAL-1064 - add anchor platform integration tests (#99)

* create workspace (#101)

* create workspace

* try

* try

* try

* try

* cleanup

* update anchor platform docker run

* fix

* fix

* upgrade babel/traverse

* upgrade browserify-sign

* add keypair package in a second workspace (#102)

* add km package

* fix tests

* cleanup

* add second CD (#109)

* fix stellar-sdk imports (#112)

* fix imports

* fix

* preparing for 1.4.0 release stuff (#110)

* fix

* fix webpack process

* webpack fix (#113)

* webpack fix

* cleanup

* add helper for parsing AnchorTransaction (#111)

* add helper for parsing AnchorTransaction

* use kind

* add try-catch

---------

Co-authored-by: Alec Charbonneau <aleccharb21@gmail.com>
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.

None yet

4 participants