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

Enable peer to join channel #489

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/api-engine/api/routes/node/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
from api.lib.agent import AgentHandler
from api.utils.port_picker import set_ports_mapping, find_available_ports
from api.common import ok, err
from api.routes.channel.views import init_env_vars, join_peers

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -748,6 +749,35 @@ def node_config(self, request, pk=None):
except Exception as e:
raise e

@action(methods=["post"], detail=True, url_path="block", url_name="block")
def block_file(self, request, pk=None):
'''
Peer join channel by uploading a genesis block file
'''
try:
self._validate_organization(request)
organization = request.user.organization
org = organization.name
try:
node = Node.objects.get(
id=pk, organization=organization
)
except ObjectDoesNotExist:
raise ResourceNotFound
envs = init_env_vars(node, organization)
block_path = "{}/{}/crypto-config/peerOrganizations/{}/peers/{}/{}.block" \
.format(CELLO_HOME, org, org, node.name + "." + org, "channel")
uploaded_block_file = request.data['file']
with open(block_path, 'wb+') as f:
for chunk in uploaded_block_file.chunks():
f.write(chunk)
join_peers(envs, block_path)
return Response(status=status.HTTP_202_ACCEPTED)
except Exception as e:
return Response(
err(e.args), status=status.HTTP_400_BAD_REQUEST
)

def _register_user(self, request, pk=None):
serializer = NodeUserCreateSerializer(data=request.data)
if serializer.is_valid(raise_exception=True):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2766,6 +2766,57 @@
}
},
"response": []
},
{
"name": "Peer Join Channel",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "JWT {{token}}",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "file",
"type": "file",
"src": "/home/ppx/Desktop/channel1.block"
}
]
},
"url": {
"raw": "http://127.0.0.1:8080/api/v1/nodes/:node_id/block",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"port": "8080",
"path": [
"api",
"v1",
"nodes",
":node_id",
"block"
],
"variable": [
{
"key": "node_id",
"value": "ecef0a57-1fe3-435c-9a08-71fababc3460"
}
]
}
},
"response": []
}
],
"event": [
Expand Down