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

[DMP 2024]: Create the core modules of cord.js sdk in Python #2

Open
3 tasks
adi-a11y opened this issue Jun 19, 2024 · 6 comments
Open
3 tasks

[DMP 2024]: Create the core modules of cord.js sdk in Python #2

adi-a11y opened this issue Jun 19, 2024 · 6 comments
Labels

Comments

@adi-a11y
Copy link
Collaborator

Description

cord.js is an SDK to connect to CORD. We have a requirement to write the same SDK in Python.
As part of this we have to first create the core SDK modules that include the DID and Chainspace. Scope of this issue it to create an SDK in Python along with any dependencies.

Goals

  • Basic framework of the SDK established, able to connect to CORD
  • Replication of all packages present currently in CORD.js ex: statement, asset, network-score etc.
  • Demo scripts for all implemented packages currently present in CORD.js, similar to statement demo-script -> https://github.com/dhiway/cord.js/blob/develop/demo/src/func-test.ts

Expected Outcome

We should have a functioning SDK written in Python that connects to CORD and is able to make calls to CORD

Acceptance Criteria

Fully functioning SDK written in Python with all the available methods/functions implemented
A working demo script https://github.com/dhiway/cord.js/blob/develop/demo/src/func-test.ts
All the unit test cases implemented

Implementation Details

Refer cord.js repo for reference SDK written in typescript, this needs to be replicated in Python
Refer to the documentation https://docs.cord.network/cordjs/integratecord/ for the detailed explanation on the working of demo script https://github.com/dhiway/cord.js/blob/develop/demo/src/func-test.ts
Note: There will be some dependency modules before these two modules can work

Mockups/Wireframes

NA

Product Name

cord sdk in Python

Organisation Name

Dhiway

Domain

Open Source Library

Tech Skills Needed

Python, TypeScript

Mentor(s)

@adi-a11y @amarts @NiranjanAP

Category

Other

@hardiksharma11
Copy link
Contributor

hardiksharma11 commented Jun 23, 2024

Weekly Learnings & Updates (To be filled by contributor)

Week 1

  • Learning 1 - I learned how to effectively manage Python modules using a setup.py file. The process involves organizing the project structure to include all necessary init.py files, creating a setup.py file to define package metadata and dependencies, and installing the package in editable mode using pip install -e .. This approach allows for the use of absolute imports, ensuring modules are correctly recognized without modifying sys.path or relying on relative imports. Running scripts from the project root ensures Python can resolve the package structure properly, making module management more straightforward and maintainable.
  • Learning 2 - The ErrorHandler module plays a vital role in this process by providing functions to detect and manage errors related to extrinsic submissions. This module allows the application to determine if a transaction has failed or succeeded by inspecting the events returned from the blockchain.
  • Learning 3 - I learnt to make connection with cord network using substrate-interface for python.

Week 2

  • Learning 1 - I learned to use class effectively in python which was required in creating SDKErrors module that makes the errors for differernt more organised.
  • Learning 2 - Written various crypto utils function from scratch because there were not directly available in substrate-interface. These could be found in the PR submitted.
  • Learning 3 - Written identifier module as it would be used in did module. Defined all the prefixes and idents in a separate file in utils as constants.

Week 3

  • Learning 1 - I wrote the demo script demonstrating the working of sdk uptill now. I learned to create account using substrate-interface(Polkascan) using Cord blockchain.
  • Learning 2 - I went through many functions of substrate interface and understood to use compose_call which is used to create transaction that could be converter to extrinsics (signed/unsigned). I also learnend to use queries to get information from the blockchain.

Week 4

  • Learning 1- Learned to use CORD explorer which helped me to see the interaction with the chain.
  • Learning 2 - Wrote the utils for Did module. Came accross parse function and I imlemented it with re module in python. Also Written various checks for value being passed.
  • Learning 3 - Started demo for did by trying to write createDid function. It is causing some errors and I will deal with them in the coming week.

Week 5

  • Learning 1 - Learned how to add custom types to the type_registry in substrate-interface. It could be helpful when dealing with data whose types are not already implemened. Although it is not being used now.
  • Learning 2 - I wa sstruggling a lot with some errors so I understood the internal working of the SCALE encoding by the scalecodec library i.e things like how are value passed in encode and process_encode and deal with nested types while dealing with the input_api in the createDid function.
  • Learning 3 - I was finally able to solve the errors and at this stage did is being created successfully.

Week 6

  • Made the create_did method working
  • Connected to theauthors and maintainers of the Polkascan library for fixing of some issue.

Week 7

  • Created several functions of Chainspace module.
  • Also created Subspace and delegate authorization. Detailed work can be found in PRs.

Week 8

  • Authored the methods and function for the schema pallet.
  • Also written some of the function for the statement module eventually completing the statement demo script along with it too.

Week 9

  • Written some remaining functions of statement like Statement dispatch revoke to chain, Statement dispatch restore to chain, Statement verify against prop and completed it.
  • Started new pallet , Asset. Also written the demo for the function written.
  • Completed the asset module along with the demo script as now there is very similiar work to be done. So work is happening very fast.

Week 10

  • Started working on the last module that is Network score module.
  • It was also more or less performing the same as schema and statement and so it was easy to write code for it.
  • Completed Network-score module along with demo.

Week 11

  • This week was all about merging the PRs. I learned a lot of good practices from my mentors that one must follow while working in open source and making changes in code through some PR.
  • I learned we should be different branches as PRs for every independent change we do so that we dont get trouble while mergin them.
  • We resolved the conflicts of all the PRs and merged them along with a updated README file which have even more details about using the SDK.

@vatsa287 vatsa287 reopened this Jul 23, 2024
@adi-a11y
Copy link
Collaborator Author

adi-a11y commented Jul 23, 2024

Week 1 goal:

  • Connection with cord and basic structure

@adi-a11y
Copy link
Collaborator Author

adi-a11y commented Jul 23, 2024

Week 2 goal:

  • Configuration and network

@adi-a11y
Copy link
Collaborator Author

adi-a11y commented Jul 23, 2024

Week 3 goal:

  • Identifier

@adi-a11y
Copy link
Collaborator Author

adi-a11y commented Jul 23, 2024

Week 4 goal:

  • DID module

@adi-a11y
Copy link
Collaborator Author

Week 5 goal:

  • Chainspace module

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

No branches or pull requests

3 participants