Skip to content

Commit c8317da

Browse files
feat(platform)!: withdrawal limits (#2182)
1 parent 8b847ea commit c8317da

File tree

82 files changed

+4460
-324
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+4460
-324
lines changed

Cargo.lock

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/dashpay-contract/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ license = "MIT"
88

99
[dependencies]
1010
platform-version = { path = "../rs-platform-version" }
11-
thiserror = "1.0.58"
11+
thiserror = "1.0.64"
1212
serde_json = { version = "1.0" }
1313
platform-value = { path = "../rs-platform-value" }

packages/data-contracts/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rust-version.workspace = true
77
license = "MIT"
88

99
[dependencies]
10-
thiserror = "1.0.58"
10+
thiserror = "1.0.64"
1111
platform-version = { path = "../rs-platform-version" }
1212
serde_json = { version = "1.0" }
1313
withdrawals-contract = { path = "../withdrawals-contract" }

packages/dpns-contract/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rust-version.workspace = true
77
license = "MIT"
88

99
[dependencies]
10-
thiserror = "1.0.58"
10+
thiserror = "1.0.64"
1111
platform-version = { path = "../rs-platform-version" }
1212
serde_json = { version = "1.0" }
1313
platform-value = { path = "../rs-platform-value" }

packages/feature-flags-contract/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rust-version.workspace = true
77
license = "MIT"
88

99
[dependencies]
10-
thiserror = "1.0.58"
10+
thiserror = "1.0.64"
1111
platform-version = { path = "../rs-platform-version" }
1212
serde_json = { version = "1.0" }
1313
platform-value = { path = "../rs-platform-value" }

packages/masternode-reward-shares-contract/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rust-version.workspace = true
77
license = "MIT"
88

99
[dependencies]
10-
thiserror = "1.0.58"
10+
thiserror = "1.0.64"
1111
platform-version = { path = "../rs-platform-version" }
1212
serde_json = { version = "1.0" }
1313
platform-value = { path = "../rs-platform-value" }

packages/rs-dapi-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dapi-grpc = { path = "../dapi-grpc" }
2525
futures = "0.3.28"
2626
http-serde = { version = "1.1.3", optional = true }
2727
rand = { version = "0.8.5", features = ["small_rng"] }
28-
thiserror = "1.0.58"
28+
thiserror = "1.0.64"
2929
tracing = "0.1.40"
3030
tokio = { version = "1.32.0", default-features = false }
3131
sha2 = { version = "0.10", optional = true }

packages/rs-dpp/src/errors/consensus/basic/identity/invalid_identity_credit_withdrawal_transition_amount_error.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use bincode::{Decode, Encode};
1010
#[derive(
1111
Error, Debug, Clone, PartialEq, Eq, Encode, Decode, PlatformSerialize, PlatformDeserialize,
1212
)]
13-
#[error("Credit withdrawal amount {amount} must be greater or equal to {min_amount}")]
13+
#[error("Credit withdrawal amount {amount} must be greater or equal to {min_amount} and less than {max_amount}")]
1414
#[platform_serialize(unversioned)]
1515
pub struct InvalidIdentityCreditWithdrawalTransitionAmountError {
1616
/*
@@ -20,11 +20,16 @@ pub struct InvalidIdentityCreditWithdrawalTransitionAmountError {
2020
*/
2121
pub amount: u64,
2222
pub min_amount: u64,
23+
pub max_amount: u64,
2324
}
2425

2526
impl InvalidIdentityCreditWithdrawalTransitionAmountError {
26-
pub fn new(amount: u64, min_amount: u64) -> Self {
27-
Self { amount, min_amount }
27+
pub fn new(amount: u64, min_amount: u64, max_amount: u64) -> Self {
28+
Self {
29+
amount,
30+
min_amount,
31+
max_amount,
32+
}
2833
}
2934

3035
pub fn amount(&self) -> u64 {
@@ -34,6 +39,10 @@ impl InvalidIdentityCreditWithdrawalTransitionAmountError {
3439
pub fn min_amount(&self) -> u64 {
3540
self.min_amount
3641
}
42+
43+
pub fn max_amount(&self) -> u64 {
44+
self.max_amount
45+
}
3746
}
3847

3948
impl From<InvalidIdentityCreditWithdrawalTransitionAmountError> for ConsensusError {

packages/rs-dpp/src/identity/core_script.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,23 @@ impl CoreScript {
5151
Self::from_bytes(bytes)
5252
}
5353

54-
pub fn random_p2pkh(rng: &mut StdRng) -> Self {
55-
Self::new_p2pkh(rng.gen::<[u8; 20]>())
56-
}
57-
58-
pub fn random_p2sh(rng: &mut StdRng) -> Self {
54+
pub fn new_p2sh(script_hash: [u8; 20]) -> Self {
5955
let mut bytes = vec![
6056
opcodes::all::OP_HASH160.to_u8(),
6157
opcodes::all::OP_PUSHBYTES_20.to_u8(),
6258
];
63-
bytes.append(&mut rng.gen::<[u8; 20]>().to_vec());
59+
bytes.extend_from_slice(&script_hash);
6460
bytes.push(opcodes::all::OP_EQUAL.to_u8());
6561
Self::from_bytes(bytes)
6662
}
63+
64+
pub fn random_p2sh(rng: &mut StdRng) -> Self {
65+
Self::new_p2sh(rng.gen())
66+
}
67+
68+
pub fn random_p2pkh(rng: &mut StdRng) -> Self {
69+
Self::new_p2pkh(rng.gen())
70+
}
6771
}
6872

6973
impl From<Vec<u8>> for CoreScript {

packages/rs-dpp/src/util/units.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,33 @@ macro_rules! dash_to_credits {
2727
credits as u64
2828
}};
2929
}
30+
31+
#[macro_export]
32+
macro_rules! dash_to_duffs {
33+
// The macro takes a string literal representing the Dash amount.
34+
($dash:expr) => {{
35+
let dash_str = stringify!($dash);
36+
37+
// Parsing the input string to separate the whole and fractional parts.
38+
let parts: Vec<&str> = dash_str.split('.').collect();
39+
let mut credits: u128 = 0;
40+
41+
// Process the whole number part if it exists.
42+
if let Some(whole) = parts.get(0) {
43+
if let Ok(whole_number) = whole.parse::<u128>() {
44+
credits += whole_number * 100_000_000; // Whole Dash amount to credits
45+
}
46+
}
47+
48+
// Process the fractional part if it exists.
49+
if let Some(fraction) = parts.get(1) {
50+
let fraction_length = fraction.len();
51+
let fraction_number = fraction.parse::<u128>().unwrap_or(0);
52+
// Calculate the multiplier based on the number of digits in the fraction.
53+
let multiplier = 10u128.pow(8 - fraction_length as u32);
54+
credits += fraction_number * multiplier; // Fractional Dash to credits
55+
}
56+
57+
credits as u64
58+
}};
59+
}

0 commit comments

Comments
 (0)