-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: use a struct for namespace and rename namespaceID (#175)
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> Closes #172 and #174 ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [ ] New and updated code has appropriate documentation - [ ] New and updated code has new and/or updated testing - [ ] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [ ] Linked issues closed with keywords --------- Co-authored-by: Rootul P <rootulp@gmail.com>
- Loading branch information
Showing
11 changed files
with
185 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,37 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity ^0.8.19; | ||
|
||
type NamespaceID is bytes29; | ||
/// @notice A representation of the Celestia-app namespace ID and its version. | ||
/// See: https://celestiaorg.github.io/celestia-app/specs/namespace.html | ||
struct Namespace { | ||
// The namespace version. | ||
bytes1 version; | ||
// The namespace ID. | ||
bytes28 id; | ||
} | ||
|
||
using {equalTo, lessThan, greaterThan, toBytes} for Namespace global; | ||
|
||
using {equality as ==} for NamespaceID global; | ||
using {lessthan as <} for NamespaceID global; | ||
using {greaterthan as >} for NamespaceID global; | ||
function equalTo(Namespace memory l, Namespace memory r) pure returns (bool) { | ||
return l.toBytes() == r.toBytes(); | ||
} | ||
|
||
function lessThan(Namespace memory l, Namespace memory r) pure returns (bool) { | ||
return l.toBytes() < r.toBytes(); | ||
} | ||
|
||
function equality(NamespaceID l, NamespaceID r) pure returns (bool) { | ||
return NamespaceID.unwrap(l) == NamespaceID.unwrap(r); | ||
function greaterThan(Namespace memory l, Namespace memory r) pure returns (bool) { | ||
return l.toBytes() > r.toBytes(); | ||
} | ||
|
||
function lessthan(NamespaceID l, NamespaceID r) pure returns (bool) { | ||
return NamespaceID.unwrap(l) < NamespaceID.unwrap(r); | ||
function toBytes(Namespace memory n) pure returns (bytes29) { | ||
return bytes29(abi.encodePacked(n.version, n.id)); | ||
} | ||
|
||
function greaterthan(NamespaceID l, NamespaceID r) pure returns (bool) { | ||
return NamespaceID.unwrap(l) > NamespaceID.unwrap(r); | ||
function toNamespace(bytes29 n) pure returns (Namespace memory) { | ||
bytes memory id = new bytes(28); | ||
for (uint256 i = 1; i < 29; i++) { | ||
id[i - 1] = n[i]; | ||
} | ||
return Namespace(n[0], bytes28(id)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.