Skip to content
Draft
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
5 changes: 2 additions & 3 deletions kindelia/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ macro_rules! discriminant {
};
}

// Clap CLI definitions
// ====================

/// Clap CLI definitions
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
pub struct Cli {
Expand Down Expand Up @@ -314,6 +312,7 @@ pub enum GetKind {
#[clap(subcommand)]
stat_kind: Option<GetStatsKind>,
},
/// Get node peers
Peers {
/// Get all seen peers, including inactive ones
#[clap(long)]
Expand Down
3 changes: 2 additions & 1 deletion kindelia/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use kindelia_core::net::{Address, ProtoComm};
use kindelia_core::node::{
spawn_miner, Node, Transaction, MAX_TRANSACTION_SIZE,
};

use kindelia_core::persistence::{
get_ordered_blocks_path, SimpleFileStorage, BLOCKS_DIR,
};
Expand Down Expand Up @@ -630,7 +631,7 @@ pub fn publish_code(
// spawn'd, the task should begin executing immediately.
tasks.spawn_on(
async move {
let results = match client.publish_code(stmts_hex.clone()).await {
let results = match client.publish_code(stmts_hex).await {
Ok(r) => r,
Err(e) => {
println!("NOT PUBLISHED to {}. ({})", *client, e);
Expand Down
8 changes: 4 additions & 4 deletions kindelia_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use reqwest::{Client, IntoUrl, Method, RequestBuilder, Url};
use serde::{de::DeserializeOwned, Serialize};

use kindelia_core::api::{
BlockInfo, CtrInfo, FuncInfo, Hash, HexStatement, Name, PublishError,
RegInfo, Stats,
BlockInfo, CtrInfo, FuncInfo, Hash, HexStatement, PublishError, RegInfo,
Stats,
};
use kindelia_core::net::ProtoComm;
use kindelia_core::{runtime, node};
use kindelia_lang::ast;
use kindelia_core::{node, runtime};
use kindelia_lang::ast::{self, Name};

pub struct ApiClient {
client: reqwest::Client,
Expand Down
41 changes: 25 additions & 16 deletions kindelia_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ pub mod nohash_hasher;

pub use primitive_types::U256;

use std::fmt;
use std::str::FromStr;
use std::string::ToString;
use std::{fmt, ops::Deref};

use serde::{Deserialize, Serialize};

// U120
// ====

/// A unsigned 120 bit integer: the native unboxed integer type
/// of the Kindelia's HVM.

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash)]
#[serde(into = "String", try_from = "&str")]
#[repr(transparent)]
pub struct U120(pub u128);
pub struct U120(u128);

impl U120 {
pub const ZERO: U120 = U120(0);
Expand Down Expand Up @@ -245,11 +242,23 @@ impl Name {
Name(numb)
}

/// Converts a name string to a Name. Same as `from_str`, but panics when name
/// length > 12 or on invalid letter. It also does not handle `~` (NONE)
/// syntax. **DEPRECATED**.
#[allow(clippy::should_implement_trait)]
pub fn from_str(name_txt: &str) -> Result<Self, String> {
if name_txt.len() > Self::MAX_CHARS {
Err(format!("Name '{}' exceeds {} letters.", name_txt, Self::MAX_CHARS))
} else {
let mut num: u128 = 0;
for chr in name_txt.chars() {
num = (num << 6) + char_to_code(chr)?;
}
Ok(Name(num))
}
}

/// Converts a name string to a Name. Same as `from_str`, but panics
/// when name length > 12 or on invalid letter. **DEPRECATED**.
// TODO: This should be removed.
pub fn from_str_unsafe(name_txt: &str) -> Name {
pub fn from_str_unsafe(name_txt: &str) -> Self {
let mut num: u128 = 0;
for (i, chr) in name_txt.chars().enumerate() {
debug_assert!(i < Self::MAX_CHARS, "Name too big: `{}`.", name_txt);
Expand All @@ -263,13 +272,6 @@ impl Name {
}
}

impl std::ops::Deref for Name {
type Target = u128;
fn deref(&self) -> &Self::Target {
&self.0
}
}

impl fmt::Display for Name {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let name: String = if self.is_none() {
Expand All @@ -296,6 +298,13 @@ impl fmt::Display for Name {
}
}

impl Deref for Name {
type Target = u128;
fn deref(&self) -> &Self::Target {
&self.0
}
}

// Necessary for serde `try_from` attr
impl TryFrom<&str> for Name {
type Error = String;
Expand Down
2 changes: 1 addition & 1 deletion kindelia_core/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn block_with_txs_deserialize(c: &mut Criterion) {
b.iter(|| {
let de_bits = util::bytes_to_bitvec(black_box(&se_bytes));
let block = node::Block::proto_deserialized(&de_bits).unwrap();
let transactions = node::extract_transactions(&block.body);
let transactions = block.extract_transactions();
for transaction in transactions {
let de_stmt = transaction.to_statement().unwrap();
debug_assert_eq!(base_stmt, de_stmt);
Expand Down
Loading