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

REST API method to get path to latest available blockchain state #252

Closed
dmugtasimov opened this issue Jul 8, 2021 · 34 comments · Fixed by #291
Closed

REST API method to get path to latest available blockchain state #252

dmugtasimov opened this issue Jul 8, 2021 · 34 comments · Fixed by #291
Assignees

Comments

@dmugtasimov
Copy link
Contributor

dmugtasimov commented Jul 8, 2021

TODO:

  • Use thenewboston_node.business_logic.blockchain.file_blockchain.get_blockchain_state_filename_meta
  • GET /api/v1/blockchain-states-meta/?limit=&offset=&ordering=
  • ordering by block_number in both directions must be supported. do not forget to handle special case of blockchain genesis state ( implement by yielding blockchain states in either direction)
  • GET /api/v1/blockchain-states-meta/{block_number}/ (if leading zeros are provided then they should be striped from block_number
  • Use blockchain application
  • Base "urls" on "network_addresses" of the declared node

Response example:

[
        {
		"last_block_number": null,
                "url_path": "/blockchain/account-root-files/0/0/0/0/0/0/0/0/000000000!-arf.msgpack.xz",
		"urls": ["http://3.143.205.184:8555/blockchain/account-root-files/0/0/0/0/0/0/0/0/000000000!-arf.msgpack.xz"]
	},
	{
		"last_block_number": 10,
                "url_path": "/blockchain/account-root-files/0/0/0/0/0/0/0/0/0000000010-arf.msgpack.xz",
		"urls": ["http://3.143.205.184:8555/blockchain/account-root-files/0/0/0/0/0/0/0/0/0000000010-arf.msgpack.xz"]
	}
]

Use this code for pagination:

from collections import OrderedDict

from rest_framework.pagination import LimitOffsetPagination
from rest_framework.response import Response


class CustomLimitOffsetPaginationBase(LimitOffsetPagination):
    default_limit = 5
    max_limit = 20

    def get_paginated_dict(self, data):
        raise NotImplementedError('Must be implemented in a child class')

    def get_paginated_response(self, data):
        return Response(self.get_paginated_dict(data))


class CustomLimitOffsetPagination(CustomLimitOffsetPaginationBase):

    def get_paginated_dict(self, data):
        return OrderedDict((('count', self.count), ('results', data)))
@dmugtasimov
Copy link
Contributor Author

@andbortnik I rename path to url_path

@andbortnik andbortnik moved this from In progress to Paused in Blockchain Tasks Jul 24, 2021
@andbortnik andbortnik moved this from Paused to In progress in Blockchain Tasks Jul 25, 2021
@andbortnik
Copy link
Contributor

@dmugtasimov Please review #291

What do we do if the requested node is unregistered in the blockchain? In the PR urls is empty in this case.

@dmugtasimov
Copy link
Contributor Author

@andbortnik let's serve as usual. Just put a HIGH priority TODO about it. Because normally if a node unregisters itself it should also become offline and also even if it does not since it is unregistered other nodes should not consider it as available and therefore do not make API requests to it.

@dmugtasimov
Copy link
Contributor Author

@andbortnik I added some comments (maybe I will have more later). The main issue is that representation logic was put into business logic. Please, address the comments.

@dmugtasimov dmugtasimov moved this from Code review to In progress in Blockchain Tasks Jul 28, 2021
@dmugtasimov
Copy link
Contributor Author

@andbortnik also if you wish you may submit changes in smaller PRs. I do it sometimes myself: just abandon the entire large PR and make many more smaller PRs untill I cover everything I had in the large PR originally. This up to you, just a suggestion.

@andbortnik
Copy link
Contributor

@dmugtasimov Fixed

@andbortnik andbortnik assigned dmugtasimov and unassigned andbortnik Jul 29, 2021
@andbortnik andbortnik moved this from In progress to Code review in Blockchain Tasks Jul 29, 2021
@andbortnik andbortnik moved this from Code review to In progress in Blockchain Tasks Jul 29, 2021
@andbortnik andbortnik assigned andbortnik and unassigned dmugtasimov Jul 29, 2021
@dmugtasimov dmugtasimov added this to the New node deployment milestone Aug 13, 2021
@dmugtasimov
Copy link
Contributor Author

@andbortnik is this PR #329 ready for merge?

@andbortnik andbortnik moved this from In progress to Code review in Blockchain Tasks Aug 24, 2021
@andbortnik andbortnik assigned dmugtasimov and unassigned andbortnik Aug 24, 2021
@dmugtasimov
Copy link
Contributor Author

@andbortnik #329 merged, thank you

@dmugtasimov
Copy link
Contributor Author

@andbortnik please, address the comment for #350

@dmugtasimov
Copy link
Contributor Author

@andbortnik rebase required: #351

@dmugtasimov dmugtasimov moved this from Code review to In progress in Blockchain Tasks Aug 24, 2021
@dmugtasimov
Copy link
Contributor Author

@andbortnik #350 merged, thank you

@dmugtasimov
Copy link
Contributor Author

Fixup: #366

@dmugtasimov
Copy link
Contributor Author

@andbortnik Thank you #351 is merged

@dmugtasimov
Copy link
Contributor Author

@andbortnik thank you, #364 merged

@dmugtasimov
Copy link
Contributor Author

@andbortnik is there anything left to do in this task?

@dmugtasimov dmugtasimov moved this from Code review to In progress in Blockchain Tasks Aug 28, 2021
@andbortnik
Copy link
Contributor

@andbortnik is there anything left to do in this task?

Nothing. I'll close the task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

2 participants