Skip to content

Commit

Permalink
Merge pull request #314 from 0xcregis/313-cancel-coin_limit-of-210000…
Browse files Browse the repository at this point in the history
…00-for-dogecoin

fix: cancel max coin of 21000000 for dogecoin
  • Loading branch information
loki-cmu authored Dec 26, 2024
2 parents 46db076 + 68d3383 commit a8b4e85
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 101 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/anychain-bitcoin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "anychain-bitcoin"
description = "A Rust library for Bitcoin-focused cryptocurrency wallets, enabling seamless transactions on the Bitcoin blockchain"
version = "0.1.11"
version = "0.1.12"
keywords = ["bitcoin", "blockchain", "wallet", "transactions"]
categories = ["cryptography::cryptocurrencies"]

Expand Down
100 changes: 1 addition & 99 deletions crates/anychain-bitcoin/src/amount.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use anychain_core::no_std::*;
use anychain_core::{Amount, AmountError};

use core::fmt;
Expand All @@ -8,9 +7,6 @@ use std::ops::{Add, Sub};
// Number of satoshis (base unit) per BTC
const COIN: i64 = 1_0000_0000;

// Maximum number of satoshis
const MAX_COINS: i64 = 21_000_000 * COIN;

/// Represents the amount of Bitcoin in satoshis
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
pub struct BitcoinAmount(pub i64);
Expand Down Expand Up @@ -72,14 +68,7 @@ impl BitcoinAmount {
pub const ONE_BTC: BitcoinAmount = BitcoinAmount(COIN);

pub fn from_satoshi(satoshis: i64) -> Result<Self, AmountError> {
if (-MAX_COINS..=MAX_COINS).contains(&satoshis) {
Ok(Self(satoshis))
} else {
Err(AmountError::AmountOutOfBounds(
satoshis.to_string(),
MAX_COINS.to_string(),
))
}
Ok(Self(satoshis))
}

pub fn from_ubtc(ubtc_value: i64) -> Result<Self, AmountError> {
Expand Down Expand Up @@ -312,93 +301,6 @@ mod tests {
mod test_invalid {
use super::*;

mod test_out_of_bounds {
use super::*;

const INVALID_TEST_AMOUNTS: [AmountDenominationTestCase; 4] = [
AmountDenominationTestCase {
satoshi: 2100000100000000,
micro_bit: 21000001000000,
milli_bit: 21000001000,
centi_bit: 2100000100,
deci_bit: 210000010,
bitcoin: 21000001,
},
AmountDenominationTestCase {
satoshi: -2100000100000000,
micro_bit: -21000001000000,
milli_bit: -21000001000,
centi_bit: -2100000100,
deci_bit: -210000010,
bitcoin: -21000001,
},
AmountDenominationTestCase {
satoshi: 1000000000000000000,
micro_bit: 10000000000000000,
milli_bit: 10000000000000,
centi_bit: 1000000000000,
deci_bit: 100000000000,
bitcoin: 10000000000,
},
AmountDenominationTestCase {
satoshi: -1000000000000000000,
micro_bit: -10000000000000000,
milli_bit: -10000000000000,
centi_bit: -1000000000000,
deci_bit: -100000000000,
bitcoin: -10000000000,
},
];

#[should_panic(expected = "AmountOutOfBounds")]
#[test]
fn test_invalid_satoshi_conversion() {
INVALID_TEST_AMOUNTS.iter().for_each(|amounts| {
test_from_satoshi(amounts.satoshi, BitcoinAmount(amounts.satoshi))
});
}

#[should_panic(expected = "AmountOutOfBounds")]
#[test]
fn test_invalid_ubtc_conversion() {
INVALID_TEST_AMOUNTS.iter().for_each(|amounts| {
test_from_ubtc(amounts.micro_bit, BitcoinAmount(amounts.satoshi))
});
}

#[should_panic(expected = "AmountOutOfBounds")]
#[test]
fn test_invalid_mbtc_conversion() {
INVALID_TEST_AMOUNTS.iter().for_each(|amounts| {
test_from_mbtc(amounts.milli_bit, BitcoinAmount(amounts.satoshi))
});
}

#[should_panic(expected = "AmountOutOfBounds")]
#[test]
fn test_invalid_cbtc_conversion() {
INVALID_TEST_AMOUNTS.iter().for_each(|amounts| {
test_from_cbtc(amounts.centi_bit, BitcoinAmount(amounts.satoshi))
});
}

#[should_panic(expected = "AmountOutOfBounds")]
#[test]
fn test_invalid_dbtc_conversion() {
INVALID_TEST_AMOUNTS.iter().for_each(|amounts| {
test_from_dbtc(amounts.deci_bit, BitcoinAmount(amounts.satoshi))
});
}

#[should_panic(expected = "AmountOutOfBounds")]
#[test]
fn test_invalid_btc_conversion() {
INVALID_TEST_AMOUNTS.iter().for_each(|amounts| {
test_from_btc(amounts.bitcoin, BitcoinAmount(amounts.satoshi))
});
}
}

mod test_invalid_conversion {
use super::*;

Expand Down

0 comments on commit a8b4e85

Please sign in to comment.