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

feat: add pallets/dispatchables endpoint #1209

Merged
merged 14 commits into from
Mar 13, 2023
Merged

Conversation

marshacb
Copy link
Collaborator

@marshacb marshacb commented Jan 31, 2023

Summary: An endpoint that returns the dispatchables for a given pallet

/pallets/{palletId}/dispatchables

Query Params

  • onlyIds: boolean to return only the Id of each dispatchable instead of the entirety of each dispatchable

Sample response for /pallets/democracy/dispatchables?onlyIds=true

{
	"at": {
		"hash": "0xf66741758c3b3dd5ed7ebac42b20d5f5d5a39f47ee5069c1ab5ffc5e1929428d",
		"height": "14045022"
	},
	"pallet": "democracy",
	"palletIndex": "14",
	"items": [
		"propose",
		"second",
		"vote",
		"emergencyCancel",
		"externalPropose",
		"externalProposeMajority",
		"externalProposeDefault",
		"fastTrack",
		"vetoExternal",
		"cancelReferendum",
		"delegate",
		"undelegate",
		"clearPublicProposals",
		"unlock",
		"removeVote",
		"removeOtherVote",
		"blacklist",
		"cancelProposal"
	]
}

/pallets/{palletId}/dispatchables/{dispatchableItemId}

Query Params

  • metadata: boolean to choose whether to include a dispatchable's metadata in the response

Sample response for /pallets/democracy/dispatchables/propose

{
	"at": {
		"hash": "0x96a6c2e87fe3b2e1b367c56299287bdf10811cc39656e92afd3db15aad7feda4",
		"height": "14046525"
	},
	"pallet": "democracy",
	"palletIndex": "14",
	"dispatchableItem": "propose"
}

@marshacb marshacb changed the title Cameron pallet calls endpoint feat: add pallets/dispatchables endpoint Jan 31, 2023
@marshacb marshacb marked this pull request as ready for review February 13, 2023 15:53
@marshacb marshacb requested a review from a team as a code owner February 13, 2023 15:53
docs/src/openapi-v1.yaml Outdated Show resolved Hide resolved
docs/src/openapi-v1.yaml Outdated Show resolved Hide resolved
docs/src/openapi-v1.yaml Outdated Show resolved Hide resolved
docs/src/openapi-v1.yaml Outdated Show resolved Hide resolved
Copy link
Member

@TarikGul TarikGul left a comment

Choose a reason for hiding this comment

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

Giving this a thumbs up even though I requested for review, that was by accident (until I realized we had discussed about that at query param before).

Just some small nits, and comments but overall great job!

Copy link
Contributor

@Imod7 Imod7 left a comment

Choose a reason for hiding this comment

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

Amazing work as always! 💯 I added some comments and suggestions that I think are quick fixes! 🙏

And I have two additional questions :

  1. For the endpoint http://127.0.0.1:8080/pallets/53/dispatchables (connected to polkadot) why the calls are an empty array ?

    {
      "at": {
        "hash": "0x726844aacf88c26d62dab9506e10fa6a943f6bd850c557c14d5179dba9618744",
        "height": "14430205"
      },
      "pallet": "paraInclusion",
      "palletIndex": "53",
      "items": []
    }
    

    It is not an error since in polkadot parachains inclusion it looks like it is also empty. I was just wondering what is the use of this empty array.

  2. It is not related to the dispatchables endpoint so if it is out of scope of this PR please let me know and I will address it at another place. For the storage endpoint :
    http://127.0.0.1:8080/pallets/authorityDiscovery/storage
    I get an error

    {
      "code": 400,
      "message": "no queryable storage items found for palletId \"authorityDiscovery\"",
      "stack": "BadRequestError: no queryable storage items found for palletId \"authorityDiscovery\"\n    at PalletsStorageService.findPalletMeta (/Users/tiny_imod/Documents/Parity/substrate-api-sidecar/build/src/services/AbstractPalletsService.js:94:19)\n    at PalletsStorageService.fetchStorage (/Users/tiny_imod/Documents/Parity/substrate-api-sidecar/build/src/services/pallets/PalletsStorageService.js:92:50)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async PalletsStorageController.getStorage (/Users/tiny_imod/Documents/Parity/substrate-api-sidecar/build/src/controllers/pallets/PalletsStorageController.js:65:57)\n    at async /Users/tiny_imod/Documents/Parity/substrate-api-sidecar/build/src/controllers/AbstractController.js:226:9",
      "level": "error"
    }
    

    while connected to polkadot. But in Substrate under Authority Discovery pallet I can find two storage items, keys and nextKeys. When I also tried to retrieve those storage items from pjs-api (docs) with api.query.authorityDiscovery.keys it does not work either. I was wondering why.

Thank you so much!!! 🙏

docs/src/openapi-v1.yaml Outdated Show resolved Hide resolved
src/services/AbstractPalletsService.ts Show resolved Hide resolved
src/services/AbstractPalletsService.ts Outdated Show resolved Hide resolved
e2e-tests/latest/endpoints/polkadot.ts Show resolved Hide resolved
Copy link
Contributor

@CurlyBracketEffect CurlyBracketEffect left a comment

Choose a reason for hiding this comment

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

Nice Work!

@marshacb
Copy link
Collaborator Author

marshacb commented Mar 8, 2023

Amazing work as always! 💯 I added some comments and suggestions that I think are quick fixes! 🙏

And I have two additional questions :

  1. For the endpoint http://127.0.0.1:8080/pallets/53/dispatchables (connected to polkadot) why the calls are an empty array ?

    {
      "at": {
        "hash": "0x726844aacf88c26d62dab9506e10fa6a943f6bd850c557c14d5179dba9618744",
        "height": "14430205"
      },
      "pallet": "paraInclusion",
      "palletIndex": "53",
      "items": []
    }
    

    It is not an error since in polkadot parachains inclusion it looks like it is also empty. I was just wondering what is the use of this empty array.

  2. It is not related to the dispatchables endpoint so if it is out of scope of this PR please let me know and I will address it at another place. For the storage endpoint :
    http://127.0.0.1:8080/pallets/authorityDiscovery/storage
    I get an error

    {
      "code": 400,
      "message": "no queryable storage items found for palletId \"authorityDiscovery\"",
      "stack": "BadRequestError: no queryable storage items found for palletId \"authorityDiscovery\"\n    at PalletsStorageService.findPalletMeta (/Users/tiny_imod/Documents/Parity/substrate-api-sidecar/build/src/services/AbstractPalletsService.js:94:19)\n    at PalletsStorageService.fetchStorage (/Users/tiny_imod/Documents/Parity/substrate-api-sidecar/build/src/services/pallets/PalletsStorageService.js:92:50)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async PalletsStorageController.getStorage (/Users/tiny_imod/Documents/Parity/substrate-api-sidecar/build/src/controllers/pallets/PalletsStorageController.js:65:57)\n    at async /Users/tiny_imod/Documents/Parity/substrate-api-sidecar/build/src/controllers/AbstractController.js:226:9",
      "level": "error"
    }
    

    while connected to polkadot. But in Substrate under Authority Discovery pallet I can find two storage items, keys and nextKeys. When I also tried to retrieve those storage items from pjs-api (docs) with api.query.authorityDiscovery.keys it does not work either. I was wondering why.

Thank you so much!!! 🙏

I'm not exactly sure why this is empty in the polkadot codebase. Ill make a note and see if I can find a reason at some point.

As for the storage question I have no idea at the moment. Since polkadot js also doesnt show those items I assume its for a reason but we probably need to check it out in more detail.

@marshacb marshacb requested a review from Imod7 March 8, 2023 18:02
Copy link
Contributor

@Imod7 Imod7 left a comment

Choose a reason for hiding this comment

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

Approved witrh 2 small corrections to make (as mentioned below) :

  1. in the docs and
  2. removal of debugging statement

and 3 additional notes :

  1. I think it is worth adding a break; statement also in the errors and events loop so right after this line and this line respectively since the loop continues in the whole list of entries even if it finds the entry requested. So the same correction that was applied for the dispatchables.
  2. By reading Tarik s comment, it looks like there is a reason for not having the query param at in both dispatchables endpoints. However, I could not find a comment (as Tarik mentioned) that explains the why. It would be really useful to have an explanation if possible. 🙏
  3. Also, in the description of this PR in the section /pallets/{palletId}/dispatchables/{dispatchableItemId} it mentions query param at. If we do not have it maybe we could update the description by removing it ?

src/services/AbstractPalletsService.ts Outdated Show resolved Hide resolved
docs/src/openapi-v1.yaml Outdated Show resolved Hide resolved
@marshacb marshacb merged commit b685ac2 into master Mar 13, 2023
@marshacb marshacb deleted the cameron-pallet-calls-endpoint branch March 13, 2023 18:29
@IkerAlus IkerAlus mentioned this pull request Jul 20, 2023
10 tasks
This pull request was closed.
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.

4 participants