Skip to content

Commit

Permalink
Merge branch 'murisi+grarco/multi-tx-masp-vp-rebased2' (#3264)
Browse files Browse the repository at this point in the history
  • Loading branch information
murisi committed May 21, 2024
2 parents b0321a5 + 96218d8 commit dc6c44e
Show file tree
Hide file tree
Showing 39 changed files with 1,186 additions and 824 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/2690-multi-tx-masp-vp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Updated the masp vp to accept multiple transfers in a single transaction.
([\#2690](https://github.com/anoma/namada/pull/2690))
17 changes: 13 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ ledger-transport-hid = "0.10.0"
libc = "0.2.97"
libloading = "0.7.2"
linkme = "0.3.24"
# branch = "main"
masp_primitives = { git = "https://github.com/anoma/masp", rev = "b5e87a01c5928ce341f2d2a63a6fa6c4033be395" }
masp_proofs = { git = "https://github.com/anoma/masp", rev = "b5e87a01c5928ce341f2d2a63a6fa6c4033be395", default-features = false, features = ["local-prover"] }
# branch = "murisi/alternative-num-traits"
masp_primitives = { git = "https://github.com/anoma/masp", rev = "3aacc707c5948e7423589ac617305448bead9842" }
masp_proofs = { git = "https://github.com/anoma/masp", rev = "3aacc707c5948e7423589ac617305448bead9842", default-features = false, features = ["local-prover"] }
num256 = "0.3.5"
num_cpus = "1.13.0"
num-derive = "0.3.3"
Expand Down
26 changes: 6 additions & 20 deletions crates/core/src/arith.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
//! Arithmetics helpers

pub use masp_primitives::num_traits::ops::checked::{
CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedSub,
};
pub use masp_primitives::num_traits::ops::overflowing::{
OverflowingAdd, OverflowingSub,
};
pub use smooth_operator::{checked, Error};

/// Performs addition that returns `None` instead of wrapping around on
/// overflow.
pub trait CheckedAdd: Sized + Copy {
/// Adds two numbers, checking for overflow. If overflow happens, `None` is
/// returned.
fn checked_add(&self, rhs: Self) -> Option<Self>;
}

/// Helpers for testing.
#[cfg(feature = "testing")]
pub mod testing {
use super::*;

impl CheckedAdd for u64 {
fn checked_add(&self, rhs: Self) -> Option<Self> {
u64::checked_add(*self, rhs)
}
}
}
36 changes: 33 additions & 3 deletions crates/core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;

use crate::address::Address;
use crate::arith::{self, checked, CheckedAdd};
use crate::arith::{self, checked, CheckedAdd, CheckedSub};
use crate::dec::{Dec, POS_DECIMAL_PRECISION};
use crate::hash::Hash;
use crate::ibc::apps::transfer::types::Amount as IbcAmount;
Expand Down Expand Up @@ -336,8 +336,38 @@ impl Amount {
}

impl CheckedAdd for Amount {
fn checked_add(&self, rhs: Self) -> Option<Self> {
self.checked_add(rhs)
type Output = Amount;

fn checked_add(self, rhs: Self) -> Option<Self::Output> {
Amount::checked_add(&self, rhs)
}
}

impl CheckedAdd for &Amount {
type Output = Amount;

fn checked_add(self, rhs: Self) -> Option<Self::Output> {
self.checked_add(*rhs)
}
}

impl CheckedSub for Amount {
type Output = Amount;

fn checked_sub(self, amount: Self) -> Option<Self::Output> {
self.raw
.checked_sub(amount.raw)
.map(|result| Self { raw: result })
}
}

impl CheckedSub for &Amount {
type Output = Amount;

fn checked_sub(self, amount: Self) -> Option<Self::Output> {
self.raw
.checked_sub(amount.raw)
.map(|result| Amount { raw: result })
}
}

Expand Down
Loading

0 comments on commit dc6c44e

Please sign in to comment.