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

Revert "JS: Make numeric union arms callable by adding a _ prefix" #167

Merged
merged 4 commits into from
Aug 17, 2023

Conversation

Shaptic
Copy link
Contributor

@Shaptic Shaptic commented Aug 16, 2023

This alleged fix is a product of a fundamental misunderstanding of the way that js-xdr works in terms of building the Union structures. In fact, this breaks them. The way that you can initialize numeric unions such as TransactionMeta, whose definition is:

union TransactionMeta switch (int v)
{
case 0:
    OperationMeta operations<>;
case 1:
    TransactionMetaV1 v1;
case 2:
    TransactionMetaV2 v2;
case 3:
    TransactionMetaV3 v3;
};

is by passing the enum switch and its value to the constructor, e.g.

  //   case 0:
  //       OperationMeta operations<>;
  //   case 1:
  //       TransactionMetaV1 v1;
  //   case 2:
  //       TransactionMetaV2 v2;
  //   case 3:
  //       TransactionMetaV3 v3;
  //   };

is by passing the enum switch and its value to the constructor, e.g.

const v3 = new xdr.TransactionMeta(3, new xdr.TransactionMetaV3({
  /* v3 parameters go here */
});

The "correct" way to fix this odd behavior is just by adding a constructor on the TypeScript side (i.e. in stellar/dts-xdr) as such:

class TransactionMeta {
  constructor(
    v: number, 
    value: 
      | xdr.TransactionMetaV1
      | xdr.TransactionMetaV2
      | xdr.TransactionMetaV3);
}

@Shaptic Shaptic merged commit 2bb0b55 into master Aug 17, 2023
3 checks passed
@Shaptic Shaptic deleted the revert-166-js-digit-methods branch August 17, 2023 16:57
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