Skip to content

Commit

Permalink
Merge pull request #132 from deryacog/loopix_new_rebased
Browse files Browse the repository at this point in the history
Loopix new rebased
  • Loading branch information
deryacog authored Nov 9, 2024
2 parents 7210764 + 5a896a2 commit 0b4797a
Show file tree
Hide file tree
Showing 33 changed files with 4,033 additions and 198 deletions.
229 changes: 197 additions & 32 deletions cli/Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
"test": [
"make cargo_test"
],
"code": [
"code --user-data-dir .vscode --profile fledger ."
],
"fledger": [
"cd cli && cargo run -p fledger"
]
Expand Down
41 changes: 41 additions & 0 deletions flarch/src/nodeids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ impl From<GenericArray<u8, U32>> for U256 {
}
}

impl From<u64> for U256 {
fn from(value: u64) -> Self {
let mut bytes = [0u8; 32];
bytes[24..].copy_from_slice(&value.to_be_bytes());
U256 { 0: bytes }
}
}


impl From<u32> for U256 {
fn from(value: u32) -> Self {
let mut bytes = [0u8; 32];
bytes[28..].copy_from_slice(&value.to_be_bytes());
U256 { 0: bytes }
}
}

impl From<i32> for U256 {
fn from(value: i32) -> Self {
let mut bytes = [0u8; 32];
bytes[28..].copy_from_slice(&value.to_be_bytes());
U256 { 0: bytes }
}
}

impl From<[u8; 32]> for U256 {
fn from(b: [u8; 32]) -> Self {
U256 { 0: b }
Expand Down Expand Up @@ -123,6 +148,22 @@ impl NodeIDs {
ret
}

/// Returns a NodeIDs from 'from'(included) to 'to'(excluded)
pub fn new_range(from: u32, to: u32) -> Self {
let mut ret = NodeIDs { 0: vec![] };
for i in from..to {
let mut bytes = [0u8; 32];
bytes[28..].copy_from_slice(&i.to_be_bytes());
ret.0.push(NodeID::from(bytes));
}
ret
}

/// Returns NodeIDs as a Vec<NodeID>
pub fn to_vec(&self) -> Vec<NodeID> {
self.0.clone()
}

// Returns an empty NodeIDs
pub fn empty() -> Self {
NodeIDs::new(0)
Expand Down
Loading

0 comments on commit 0b4797a

Please sign in to comment.