Skip to content

feat: support account link pallet update#557

Merged
rflechtner merged 12 commits intodevelopfrom
rf-account-link-update
Jul 25, 2022
Merged

feat: support account link pallet update#557
rflechtner merged 12 commits intodevelopfrom
rf-account-link-update

Conversation

@rflechtner
Copy link
Contributor

@rflechtner rflechtner commented Jun 15, 2022

fixes KILTProtocol/ticket#2048

This adds discovery of whether the account linking pallet has updated to support ethereum alongside substrate addresses.
Extrinsic and query parameter encoding as well as decoding of results will adapt automatically.

How to test:

As long as KILTprotocol/kilt-node#355 is not yet merged, testing will have to be done against an image built from source on that branch.
Tests for ethereum address linking have therefore been set up to be skipped.
Integration tests against latest & latest-develop images should nevertheless still work.

Checklist:

  • I have verified that the code works
  • I have verified that the code is easy to understand
    • If not, I have left a well-balanced amount of inline comments
  • I have left the code in a better state
  • I have documented the changes (where applicable)

@rflechtner rflechtner marked this pull request as ready for review June 16, 2022 10:36
@rflechtner rflechtner requested a review from ntn-x2 June 16, 2022 10:36
@rflechtner rflechtner self-assigned this Jun 16, 2022
signature: string
}

export type JsonEnum<K extends string, V> = K extends any
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks just like Record. What does it do differently and is it important enough to have a new type for it? Because it makes things more confusing.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, I played around with a bit and Record would not work here.
The only solution I could come up with is:

export type JsonEnum<K extends string, V> = {
  [P in K]?: V
}

Which I like more, because it is more straightforward and understandable. Only downside is, that it allows empty objects, but I don't see a way around that. On the other side,makeJsonEnum would not be needed anymore, which currently uses type assertion with as and is needed, because it would not be possible to assign to the JsonEnum type without it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AFAIK it's the only way to turn 'a' | 'b' into something like {a: any} | {b: any}, which is the sort of type that polkadot requires for the creation of enums. What you proposed gives you {a?: any, b?: any} which besides empty objects also allows {a: 1, b: 2}. And it is not assignable to the polkadot type, so I don't think that will work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another way is to list the types explicitly: {a: any} | {b: any}. It is wordier and longer (a downside) but also explicit (an upside).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but what does that solve? if variable a is typed as a union of string literals, typescript interprets {[a]: any} as {[key: string]: any} and will not accept it for a signature that requires {a: any} | {b: any}

@arty-name
Copy link
Contributor

I think this should be discussed after #554 is merged, it will duplicate less code. I think the enum discussion also belongs to #554.

@rflechtner rflechtner requested review from arty-name and tjwelde July 20, 2022 12:51
Copy link
Contributor

@arty-name arty-name left a comment

Choose a reason for hiding this comment

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

Looking forward to some cleanup after Ethereum is added to all our blockchains :)

@rflechtner
Copy link
Contributor Author

Looking forward to some cleanup after Ethereum is added to all our blockchains :)

I can see that! I hope we can develop a decent concept though for abstracting over the different storage versions, because if we ever want to query old state, we would need that again.

Copy link
Contributor

@tjwelde tjwelde left a comment

Choose a reason for hiding this comment

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

LGTM

@rflechtner
Copy link
Contributor Author

Seeing that there are efforts to find better ways to deal with polkadot/api's requirements for enum encoding, I'm merging this now so we have a better basis on which to continue discussions - because this feature makes quite some use of this pattern too, and has different requirements with regards to key type unions.

@rflechtner rflechtner merged commit c11f4b0 into develop Jul 25, 2022
@rflechtner rflechtner deleted the rf-account-link-update branch July 25, 2022 15:56
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