Skip to content

Commit

Permalink
[RELEASE] dkg.py v1.0.0 - Paranets (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
u-hubar authored Jun 26, 2024
2 parents 0e967c6 + dc4d2db commit 01ec4ec
Show file tree
Hide file tree
Showing 41 changed files with 4,703 additions and 8,980 deletions.
139 changes: 0 additions & 139 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@ ___
</p>
</div>

</br>

> **Disclaimer: Beta Version**
>
> Welcome to the beta version of our client! This software is currently in the beta testing phase, which means it is not the final release version. As a beta version, it may still contain bugs, undergo frequent updates, and have limited features.
Important Points to Note:

> **Use at Your Own Risk:** While we have made efforts to ensure the stability and reliability of the beta version, there is a possibility of encountering unexpected issues. Please use this software at your own risk.
> **Limited Support:** As this is a beta release, our support resources may be focused on addressing critical bugs and gathering feedback from users. Therefore, support for beta versions may be limited compared to our stable releases.
> **Feedback Appreciated:** Your feedback is invaluable to us. If you encounter any issues, have suggestions, or want to share your experiences with the beta version, please let us know. Your feedback will help us improve the software for the final release.
> **Not for Production Use:** The beta version is intended for testing and evaluation purposes only. It is not recommended for use in a production environment where stability and reliability are crucial.
</br>

<details open>
<summary>
<b>Table of Contents</b>
Expand All @@ -60,17 +43,6 @@ Important Points to Note:
<li><a href="#installation">Installation</a></li>
</ul>
</li>
<li>
<a href="#📜-roadmap">📜 Roadmap</a>
<ul>
<li><a href="#1️⃣-pre-development-phase">1️⃣ Pre-development Phase</a></li>
<li><a href="#2️⃣-development-phase">2️⃣ Development Phase</a></li>
<li><a href="#3️⃣-documentation-phase">3️⃣ Documentation Phase</a></li>
<li><a href="#4️⃣-pre-release-phase">4️⃣ Pre-release Phase</a></li>
<li><a href="#5️⃣-release">5️⃣ Release</a></li>
<li><a href="#6️⃣-post-release">6️⃣ Post-release</a></li>
</ul>
</li>
<li><a href="#📄-license">📄 License</a></li>
<li><a href="#🤝-contributing">🤝 Contributing</a></li>
<li><a href="#❤️-thanks-to-all-contributors">❤️ Contributors</a></li>
Expand Down Expand Up @@ -221,117 +193,6 @@ python3 examples/demo.py
<br/>
<p align="right">(<a href="#readme-top">back to top</a>)</p>

## 📜 Roadmap

This roadmap outlines the goals for the first major release of the `dkg.py`. Each section represents a stage in the development process and the features we plan to implement.

<details open>
<summary>

### 1️⃣ Pre-development Phase

</summary>

- [x] **Requirement Analysis and Planning**
- [x] Define the project's scope
- [x] Identify the core functionalities

- [x] **Design**
- [x] Plan the library's architecture
- [x] Establish coding standards

- [ ] **Setup Development Environment**
- [x] Setup development, testing and production environments
- [ ] Add pytest config
- [ ] Add mypy config
- [ ] Add tox config ?
- [ ] Setup Continuous Integration (CI) and Continuous Deployment (CD) pipeline
</details>

<details open>
<summary>

### 2️⃣ Development Phase
</summary>

| Feature | Status | Tests coverage |
|:-:|:-:|:-:|
| Get Allowance | 🟩 Completed ||
| Set Allowance | 🟩 Completed ||
| Increase Allowance | 🟩 Completed ||
| Decrease Allowance | 🟩 Completed ||
| Get Bid Suggestion | 🟩 Completed ||
| Create | 🟩 Completed ||
| Transfer | 🟩 Completed ||
| Update | 🟩 Completed ||
| Wait for finalization | 🟥 Not Started ||
| Cancel update | 🟩 Completed ||
| Burn | 🟩 Completed ||
| Get | 🟩 Completed ||
| Query | 🟩 Completed ||
| Extend storing period | 🟩 Completed ||
| Add tokens | 🟩 Completed ||
| Add update tokens | 🟩 Completed ||
| Get owner | 🟩 Completed ||
| Experimental | 🟥 Not Started ||
</details>

<details open>
<summary>

### 3️⃣ Documentation Phase
</summary>

- [ ] Write comprehensive documentation
- [x] Provide examples and use-cases
- [ ] Review and finalize documentation
</details>

<details open>
<summary>

### 4️⃣ Pre-release Phase
</summary>

- [ ] **Beta Release**
- [X] Release a beta version for testing
- [ ] Gather and address feedback

- **Bug Fixes**
- Identify and fix bugs

- [ ] **Final Testing and QA**
- [ ] Perform comprehensive testing
- [ ] Ensure the library meets quality standards
</details>

<details open>
<summary>

### 5️⃣ Release
</summary>

- [ ] Merge the first version into the main branch
- [ ] Release the v1.0.0 of the `dkg.py` library
</details>

<details open>
<summary>

### 6️⃣ Post-release
</summary>

- Monitor for any issues
- Plan for next versions based on user feedback and usage
</details>

<br/>

**Note:** This roadmap is subject to changes. Each step will be accompanied by appropriate documentation, testing and code review to maintain the quality of the library.

<br/>
<p align="right">(<a href="#readme-top">back to top</a>)</p>

## 📄 License

Distributed under the Apache-2.0 License. See `LICENSE` file for more information.
Expand Down
112 changes: 92 additions & 20 deletions dkg/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
from dkg.utils.ual import format_ual, parse_ual


class ContentAsset(Module):
class KnowledgeAsset(Module):
def __init__(self, manager: DefaultRequestManager):
self.manager = manager

Expand Down Expand Up @@ -196,6 +196,7 @@ def decrease_allowance(

_get_asset_storage_address = Method(BlockchainRequest.get_asset_storage_address)
_create = Method(BlockchainRequest.create_asset)
_mint_paranet_knowledge_asset = Method(BlockchainRequest.mint_knowledge_asset)

_get_bid_suggestion = Method(NodeRequest.bid_suggestion)
_local_store = Method(NodeRequest.local_store)
Expand All @@ -208,6 +209,7 @@ def create(
token_amount: Wei | None = None,
immutable: bool = False,
content_type: Literal["JSON-LD", "N-Quads"] = "JSON-LD",
paranet_ual: UAL | None = None,
) -> dict[str, UAL | HexStr | dict[str, dict[str, str] | TxReceipt]]:
blockchain_id = self.manager.blockchain_provider.blockchain_id
assertions = format_content(content, content_type)
Expand Down Expand Up @@ -242,20 +244,54 @@ def create(
result = {"publicAssertionId": public_assertion_id, "operation": {}}

try:
receipt: TxReceipt = self._create(
{
"assertionId": Web3.to_bytes(hexstr=public_assertion_id),
"size": public_assertion_metadata["size"],
"triplesNumber": public_assertion_metadata["triples_number"],
"chunksNumber": public_assertion_metadata["chunks_number"],
"tokenAmount": token_amount,
"epochsNumber": epochs_number,
"scoreFunctionId": DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS[
self.manager.blockchain_provider.environment
][blockchain_id],
"immutable_": immutable,
}
)
if paranet_ual is None:
receipt: TxReceipt = self._create(
{
"assertionId": Web3.to_bytes(hexstr=public_assertion_id),
"size": public_assertion_metadata["size"],
"triplesNumber": public_assertion_metadata["triples_number"],
"chunksNumber": public_assertion_metadata["chunks_number"],
"tokenAmount": token_amount,
"epochsNumber": epochs_number,
"scoreFunctionId": DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS[
self.manager.blockchain_provider.environment
][blockchain_id],
"immutable_": immutable,
}
)
else:
parsed_paranet_ual = parse_ual(paranet_ual)
paranet_knowledge_asset_storage, paranet_knowledge_asset_token_id = (
parsed_paranet_ual["contract_address"],
parsed_paranet_ual["token_id"],
)

receipt: TxReceipt = self._mint_paranet_knowledge_asset(
paranet_knowledge_asset_storage,
paranet_knowledge_asset_token_id,
{
"assertionId": Web3.to_bytes(hexstr=public_assertion_id),
"size": public_assertion_metadata["size"],
"triplesNumber": public_assertion_metadata["triples_number"],
"chunksNumber": public_assertion_metadata["chunks_number"],
"tokenAmount": token_amount,
"epochsNumber": epochs_number,
"scoreFunctionId": DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS[
self.manager.blockchain_provider.environment
][blockchain_id],
"immutable_": immutable,
},
)

result["paranetId"] = Web3.to_hex(
Web3.solidity_keccak(
["address", "uint256"],
[
paranet_knowledge_asset_storage,
paranet_knowledge_asset_token_id,
],
)
)
except ContractLogicError as err:
if is_allowance_increased:
self.decrease_allowance(token_amount)
Expand All @@ -280,7 +316,7 @@ def create(
"tokenId": token_id,
"assertionId": public_assertion_id,
"assertion": assertions["public"],
"storeType": StoreTypes.TRIPLE.value,
"storeType": StoreTypes.TRIPLE,
}
]

Expand All @@ -295,7 +331,7 @@ def create(
sort_pairs=True,
).root,
"assertion": assertions["private"],
"storeType": StoreTypes.TRIPLE.value,
"storeType": StoreTypes.TRIPLE,
}
)

Expand Down Expand Up @@ -325,6 +361,42 @@ def create(

return result

_submit_knowledge_asset = Method(BlockchainRequest.submit_knowledge_asset)

def submit_to_paranet(
self, ual: UAL, paranet_ual: UAL
) -> dict[str, UAL | Address | TxReceipt]:
parsed_ual = parse_ual(ual)
knowledge_asset_storage, knowledge_asset_token_id = (
parsed_ual["contract_address"],
parsed_ual["token_id"],
)

parsed_paranet_ual = parse_ual(paranet_ual)
paranet_knowledge_asset_storage, paranet_knowledge_asset_token_id = (
parsed_paranet_ual["contract_address"],
parsed_paranet_ual["token_id"],
)

receipt: TxReceipt = self._submit_knowledge_asset(
paranet_knowledge_asset_storage,
paranet_knowledge_asset_token_id,
knowledge_asset_storage,
knowledge_asset_token_id,
)

return {
"UAL": ual,
"paranetUAL": paranet_ual,
"paranetId": Web3.to_hex(
Web3.solidity_keccak(
["address", "uint256"],
[knowledge_asset_storage, knowledge_asset_token_id],
)
),
"operation": json.loads(Web3.to_json(receipt)),
}

_transfer = Method(BlockchainRequest.transfer_asset)

def transfer(
Expand Down Expand Up @@ -430,7 +502,7 @@ def update(
"tokenId": token_id,
"assertionId": public_assertion_id,
"assertion": assertions["public"],
"storeType": StoreTypes.PENDING.value,
"storeType": StoreTypes.PENDING,
}
]

Expand All @@ -445,7 +517,7 @@ def update(
sort_pairs=True,
).root,
"assertion": assertions["private"],
"storeType": StoreTypes.PENDING.value,
"storeType": StoreTypes.PENDING,
}
)

Expand All @@ -463,7 +535,7 @@ def update(
operation_result = self.get_operation_result(operation_id, "update")

return {
"UAL": format_ual(blockchain_id, content_asset_storage_address, token_id),
"UAL": ual,
"publicAssertionId": public_assertion_id,
"operation": {
"operationId": operation_id,
Expand Down
12 changes: 8 additions & 4 deletions dkg/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
"hub": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
"rpc": "http://localhost:9545",
},
"otp:2043": {
"hub": "0x7585a99C5C150a08f5CDeFD16465C6De8D41EbbD",
"rpc": "http://parachain-alphanet-02.origin-trail.network:9933",
},
},
"devnet": {
"otp:2160": {
Expand All @@ -44,6 +40,10 @@
"rpc": "https://rpc.chiadochain.net",
"gas_price_oracle": "https://blockscout.chiadochain.net/api/v1/gas-price-oracle",
},
"base:84532": {
"hub": "0x6C861Cb69300C34DfeF674F7C00E734e840C29C0",
"rpc": "https://sepolia.base.org",
}
},
"testnet": {
"otp:20430": {
Expand All @@ -55,6 +55,10 @@
"rpc": "https://rpc.chiadochain.net",
"gas_price_oracle": "https://blockscout.chiadochain.net/api/v1/gas-price-oracle",
},
"base:84532": {
"hub": "0x144eDa5cbf8926327cb2cceef168A121F0E4A299",
"rpc": "https://sepolia.base.org",
}
},
"mainnet": {
"otp:2043": {
Expand Down
Loading

0 comments on commit 01ec4ec

Please sign in to comment.