Skip to content

Commit

Permalink
Merge pull request #63 from xelis-project/dev
Browse files Browse the repository at this point in the history
v1.12
  • Loading branch information
Slixe authored May 25, 2024
2 parents ad5785b + 44f0378 commit 7c36170
Show file tree
Hide file tree
Showing 31 changed files with 839 additions and 331 deletions.
168 changes: 89 additions & 79 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions xelis_common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xelis_common"
version = "1.11.0"
version = "1.12.0"
edition = "2021"
authors = ["Slixe <slixeprivate@gmail.com>"]
build = "build.rs"
Expand Down Expand Up @@ -46,6 +46,7 @@ tokio-tungstenite = { version = "0.21", features = ["rustls-tls-webpki-roots"] }
# Used for U256
primitive-types = { version = "0.12.2", features = ["serde"] }
console-subscriber = { version = "0.2.0", optional = true }
chacha20 = "0.9.1"

[target.'cfg(windows)'.dependencies]
win32console = "0.1.5"
Expand All @@ -59,4 +60,4 @@ json_rpc = ["dep:reqwest"]
prompt = ["dep:tokio"]
clap = ["dep:clap"]
rpc_server = ["dep:actix-rt", "dep:actix-web", "dep:actix-ws", "dep:futures-util", "dep:tokio", "dep:reqwest"]
tracing = ["dep:console-subscriber", "tokio/tracing"]
tracing = ["dep:console-subscriber", "tokio/tracing"]
12 changes: 11 additions & 1 deletion xelis_common/src/api/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ pub struct GetTransactionParams<'a> {
pub hash: Cow<'a, Hash>
}

pub type GetTransactionExecutorParams<'a> = GetTransactionParams<'a>;

#[derive(Serialize, Deserialize)]
pub struct GetTransactionExecutorResult<'a> {
pub block_topoheight: u64,
pub block_hash: Cow<'a, Hash>
}

// Direction is used for cache to knows from which context it got added
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Direction {
Expand Down Expand Up @@ -482,7 +490,9 @@ pub struct GetDifficultyResult {
pub struct ValidateAddressParams<'a> {
pub address: Cow<'a, Address>,
#[serde(default)]
pub allow_integrated: bool
pub allow_integrated: bool,
#[serde(default)]
pub max_integrated_data_size: Option<usize>
}

#[derive(Serialize, Deserialize)]
Expand Down
4 changes: 2 additions & 2 deletions xelis_common/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
Signature
},
transaction::{
aead::AEADCipher,
extra_data::UnknownExtraDataFormat,
BurnPayload,
Reference,
SourceCommitment,
Expand Down Expand Up @@ -50,7 +50,7 @@ pub struct DataHash<'a, T: Clone> {
pub struct RPCTransferPayload<'a> {
pub asset: Cow<'a, Hash>,
pub destination: Address,
pub extra_data: Cow<'a, Option<AEADCipher>>,
pub extra_data: Cow<'a, Option<UnknownExtraDataFormat>>,
pub commitment: Cow<'a, CompressedCommitment>,
pub sender_handle: Cow<'a, CompressedHandle>,
pub receiver_handle: Cow<'a, CompressedHandle>,
Expand Down
15 changes: 10 additions & 5 deletions xelis_common/src/prompt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,16 @@ impl State {
}

fn show_with_prompt_and_input(&self, prompt: &String, input: &String) -> Result<(), PromptError> {
// if not interactive, we don't need to show anything
if !self.is_interactive() {
return Ok(())
}

let current_count = self.count_lines(&format!("\r{}{}", prompt, input));
let previous_count = self.previous_prompt_line.swap(current_count, Ordering::SeqCst);

// > 1 because prompt line is already counted below
if self.is_interactive() && previous_count > 1 {
if previous_count > 1 {
print!("\x1B[{}A\x1B[J", previous_count - 1);
}

Expand Down Expand Up @@ -628,15 +633,15 @@ impl Prompt {
Ok(res == "y")
}

pub async fn read<F: FromStr>(&self, prompt: String) -> Result<F, PromptError>
pub async fn read<F: FromStr, S: ToString>(&self, prompt: S) -> Result<F, PromptError>
where
<F as FromStr>::Err: Display
{
let value = self.read_input(prompt, false).await?;
value.parse().map_err(|e: F::Err| PromptError::ParseInputError(e.to_string()))
}

pub async fn read_hash(&self, prompt: String) -> Result<Hash, PromptError> {
pub async fn read_hash<S: ToString>(&self, prompt: S) -> Result<Hash, PromptError> {
let hash_hex = self.read_input(prompt, false).await?;
Ok(Hash::from_hex(hash_hex)?)
}
Expand All @@ -647,7 +652,7 @@ impl Prompt {
}

// read a message from the user and apply the input mask if necessary
pub async fn read_input(&self, prompt: String, apply_mask: bool) -> Result<String, PromptError> {
pub async fn read_input<S: ToString>(&self, prompt: S, apply_mask: bool) -> Result<String, PromptError> {
// This is also used as a sempahore to have only one call at a time
let mut canceler = self.read_input_receiver.lock().await;

Expand Down Expand Up @@ -678,7 +683,7 @@ impl Prompt {
}

// update the prompt to the requested one and keep blocking on the receiver
self.update_prompt(prompt)?;
self.update_prompt(prompt.to_string())?;
let input = {
let input = tokio::select! {
Some(()) = canceler.recv() => {
Expand Down
4 changes: 2 additions & 2 deletions xelis_common/src/serializer/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ impl Serializer for HashSet<Hash> {

fn read(reader: &mut Reader) -> Result<Self, ReaderError> {
let total_size = reader.total_size();
if total_size % 32 != 0 {
if total_size % HASH_SIZE != 0 {
error!("Invalid size: {}, expected a multiple of 32 for hashes", total_size);
return Err(ReaderError::InvalidSize)
}

let count = total_size / 32;
let count = total_size / HASH_SIZE;
let mut tips = HashSet::with_capacity(count);
for _ in 0..count {
let hash = reader.read_hash()?;
Expand Down
124 changes: 0 additions & 124 deletions xelis_common/src/transaction/aead.rs

This file was deleted.

24 changes: 17 additions & 7 deletions xelis_common/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::{
};
use thiserror::Error;
use super::{
aead::{derive_aead_key_from_opening, PlaintextData, TAG_SIZE},
extra_data::{ExtraData, PlaintextData},
BurnPayload,
Reference,
Role,
Expand Down Expand Up @@ -298,8 +298,11 @@ impl TransactionBuilder {
+ 1;

if let Some(extra_data) = transfer.extra_data.as_ref().or(transfer.destination.get_extra_data()) {
// 2 represents u16 length
size += 2 + TAG_SIZE + extra_data.size();
// 2 represents u16 length of AEADCipher in extra data
// 2 represents u16 length of UnknownExtraDataFormat
// We have both length has we move one in the other
// This mean new ExtraData version has 2 + 2 + 32 (sender) + 32 (receiver) bytes of overhead.
size += 2 + 2 + (RISTRETTO_COMPRESSED_SIZE * 2) + extra_data.size();
}
}
transfers.len()
Expand Down Expand Up @@ -564,6 +567,7 @@ impl TransactionBuilder {
range_proof_values.reserve(transfers.len());
range_proof_openings.reserve(transfers.len());

let mut total_cipher_size = 0;
let transfers = transfers
.into_iter()
.map(|transfer| {
Expand All @@ -590,13 +594,15 @@ impl TransactionBuilder {
// Encrypt the extra data if it exists
let extra_data = if let Some(extra_data) = transfer.inner.extra_data {
let bytes = extra_data.to_bytes();
let key = derive_aead_key_from_opening(&transfer.amount_opening);
let cipher = PlaintextData(bytes).encrypt_in_place(&key);
if cipher.0.len() > EXTRA_DATA_LIMIT_SIZE {
let cipher = ExtraData::new(PlaintextData(bytes), source_keypair.get_public_key(), &transfer.destination);
let cipher_size = cipher.size();
if cipher_size > EXTRA_DATA_LIMIT_SIZE {
return Err(GenerationError::EncryptedExtraDataTooLarge);
}

Some(cipher)
total_cipher_size += cipher_size;

Some(cipher.into())
} else {
None
};
Expand All @@ -613,6 +619,10 @@ impl TransactionBuilder {
})
.collect::<Result<Vec<_>, GenerationError<B::Error>>>()?;

if total_cipher_size > EXTRA_DATA_LIMIT_SIZE {
return Err(GenerationError::EncryptedExtraDataTooLarge);
}

transfers
} else {
vec![]
Expand Down
Loading

0 comments on commit 7c36170

Please sign in to comment.