snarkOS
snarkOS copied to clipboard
[Feature] Add REST endpoint to get all items in a mapping
Motivation
This PR adds a new GET get_mapping_values REST endpoint to read all the elements in a mapping.
GET /<network>/program/{programID}/mapping/{mappingName}?all={true}&metadata={true}
Example:
GET /<network>/program/credits.aleo/mapping/bonded?all=true&metadata=true will return the full bonded mapping of addresses + amounts staked on the network.
Notes:
- The new GET endpoint currently requires a query parameters
allto be set totrue. In the future, this functionality can be expanded to get subsets of mapping data if required. - The endpoint is guarded behind the JSON Web Token auth because this call can be expensive for large mappings and may be a DOS vector for nodes. This JWT ensures that only authorized users can call this (potentially) expensive endpoint.
Related PRs
https://github.com/AleoNet/snarkOS/pull/3219