From ba2a7ea0f52c22c4d922cdf745032272500963bd Mon Sep 17 00:00:00 2001 From: rooooooooob Date: Thu, 10 Feb 2022 13:47:30 -0800 Subject: [PATCH 01/26] PointerAddress support for >u32::MAX Fixes #364 in a way that requires the least changes. Only users who are manually creating `Pointer` to make a new `PointerAddress` from parts will be affected by this API change. We could also alternatively change *ALL* references of `Slot` and `TransactionIndex` to support `BigNum` instead of `u32`. This would be inline with the alonzo.cddl binary spec, but would make use of the library more annoying, especially from javascript/wasm, as well as requiring more code changes. I don't see why you would have a transaction index greater than even a single byte, let alone 2^32 - 1. But since that's how the binary spec is, it's possible we'll run into on-chain data that do this in the future. This isn't the only place where we run into issues like this as there are edge cases anywhere where `nint` is specified since the CBOR library we support doesn't handle numbers between `i64::MIN` and `-u64::MAX`. --- rust/src/address.rs | 55 ++++++++++++++++++++++++------------------ rust/src/tx_builder.rs | 6 ++--- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/rust/src/address.rs b/rust/src/address.rs index 430930fd..2166c330 100644 --- a/rust/src/address.rs +++ b/rust/src/address.rs @@ -293,9 +293,9 @@ impl Address { | (ptr.network & 0xF); buf.push(header); buf.extend(ptr.payment.to_raw_bytes()); - buf.extend(variable_nat_encode(ptr.stake.slot.into())); - buf.extend(variable_nat_encode(ptr.stake.tx_index.into())); - buf.extend(variable_nat_encode(ptr.stake.cert_index.into())); + buf.extend(variable_nat_encode(from_bignum(&ptr.stake.slot))); + buf.extend(variable_nat_encode(from_bignum(&ptr.stake.tx_index))); + buf.extend(variable_nat_encode(from_bignum(&ptr.stake.cert_index))); }, AddrType::Enterprise(enterprise) => { let header: u8 = 0b0110_0000 @@ -393,9 +393,9 @@ impl Address { network, &payment_cred, &Pointer::new( - slot.try_into().map_err(|_| DeserializeError::new("Address.Pointer.slot", DeserializeFailure::CBOR(cbor_event::Error::ExpectedU32)))?, - tx_index.try_into().map_err(|_| DeserializeError::new("Address.Pointer.tx_index", DeserializeFailure::CBOR(cbor_event::Error::ExpectedU32)))?, - cert_index.try_into().map_err(|_| DeserializeError::new("Address.Pointer.cert_index", DeserializeFailure::CBOR(cbor_event::Error::ExpectedU32)))?))) + &to_bignum(slot), + &to_bignum(tx_index), + &to_bignum(cert_index)))) }, // enterprise 0b0110 | 0b0111 => { @@ -608,30 +608,30 @@ impl Deserialize for RewardAddress { #[wasm_bindgen] #[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd)] pub struct Pointer { - slot: Slot, - tx_index: TransactionIndex, - cert_index: CertificateIndex, + slot: BigNum, + tx_index: BigNum, + cert_index: BigNum, } #[wasm_bindgen] impl Pointer { - pub fn new(slot: Slot, tx_index: TransactionIndex, cert_index: CertificateIndex) -> Self { + pub fn new(slot: &BigNum, tx_index: &BigNum, cert_index: &BigNum) -> Self { Self { - slot, - tx_index, - cert_index, + slot: slot.clone(), + tx_index: tx_index.clone(), + cert_index: cert_index.clone(), } } - pub fn slot(&self) -> Slot { + pub fn slot(&self) -> BigNum { self.slot.clone() } - pub fn tx_index(&self) -> TransactionIndex { + pub fn tx_index(&self) -> BigNum { self.tx_index.clone() } - pub fn cert_index(&self) -> CertificateIndex { + pub fn cert_index(&self) -> BigNum { self.cert_index.clone() } } @@ -711,7 +711,7 @@ mod tests { let ptr = PointerAddress::new( 25, &StakeCredential::from_keyhash(&Ed25519KeyHash::from([23; Ed25519KeyHash::BYTE_COUNT])), - &Pointer::new(2354556573, 127, 0)); + &Pointer::new(&to_bignum(2354556573), &to_bignum(127), &to_bignum(0))); let addr = ptr.to_address(); let addr2 = Address::from_bytes(addr.to_bytes()).unwrap(); assert_eq!(addr.to_bytes(), addr2.to_bytes()); @@ -827,9 +827,9 @@ mod tests { .derive(0) .to_public(); let spend_cred = StakeCredential::from_keyhash(&spend.to_raw_key().hash()); - let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new(1, 2, 3)).to_address(); + let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); assert_eq!(addr_net_0.to_bech32(None).unwrap(), "addr_test1gz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerspqgpsqe70et"); - let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new(24157, 177, 42)).to_address(); + let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); assert_eq!(addr_net_3.to_bech32(None).unwrap(), "addr1gx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer5ph3wczvf2w8lunk"); } @@ -883,9 +883,9 @@ mod tests { .derive(0) .to_public(); let spend_cred = StakeCredential::from_keyhash(&spend.to_raw_key().hash()); - let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new(1, 2, 3)).to_address(); + let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); assert_eq!(addr_net_0.to_bech32(None).unwrap(), "addr_test1gpu5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5egpqgpsdhdyc0"); - let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new(24157, 177, 42)).to_address(); + let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); assert_eq!(addr_net_3.to_bech32(None).unwrap(), "addr1g9u5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5evph3wczvf2kd5vam"); } @@ -966,9 +966,9 @@ mod tests { .derive(0) .to_public(); let spend_cred = StakeCredential::from_keyhash(&spend.to_raw_key().hash()); - let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new(1, 2, 3)).to_address(); + let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); assert_eq!(addr_net_0.to_bech32(None).unwrap(), "addr_test1gqy6nhfyks7wdu3dudslys37v252w2nwhv0fw2nfawemmnqpqgps5mee0p"); - let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new(24157, 177, 42)).to_address(); + let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); assert_eq!(addr_net_3.to_bech32(None).unwrap(), "addr1gyy6nhfyks7wdu3dudslys37v252w2nwhv0fw2nfawemmnyph3wczvf2dqflgt"); } @@ -1041,4 +1041,13 @@ mod tests { let addr_net_3 = BaseAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &stake_cred).to_address(); assert_eq!(addr_net_3.to_bech32(None).unwrap(), "addr1x80de0mz3m9xmgtlmqqzu06s0uvfsczskdec8k7v4jhr7077mjlk9rk2dkshlkqq9cl4qlccnps9pvmns0duet9w8ulsylzv28"); } + + #[test] + fn pointer_address_big() { + let addr = Address::from_bech32("addr_test1grqe6lg9ay8wkcu5k5e38lne63c80h3nq6xxhqfmhewf645pllllllllllll7lupllllllllllll7lupllllllllllll7lc9wayvj").unwrap(); + let ptr = PointerAddress::from_address(&addr).unwrap().stake; + assert_eq!(u64::MAX, from_bignum(&ptr.slot)); + assert_eq!(u64::MAX, from_bignum(&ptr.tx_index)); + assert_eq!(u64::MAX, from_bignum(&ptr.cert_index)); + } } diff --git a/rust/src/tx_builder.rs b/rust/src/tx_builder.rs index 5db91a7d..52d56774 100644 --- a/rust/src/tx_builder.rs +++ b/rust/src/tx_builder.rs @@ -1847,9 +1847,9 @@ mod tests { NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new( - 0, - 0, - 0 + &to_bignum(0), + &to_bignum(0), + &to_bignum(0) ) ).to_address(), &TransactionInput::new(&genesis_id(), 0), From 1e16c32142265f5f4e60b3afd36f9ea8ab3a6c59 Mon Sep 17 00:00:00 2001 From: rooooooooob Date: Thu, 10 Feb 2022 14:08:33 -0800 Subject: [PATCH 02/26] variable_nat_decode() check for overflow / add test case --- rust/src/address.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/rust/src/address.rs b/rust/src/address.rs index 2166c330..7bb31a97 100644 --- a/rust/src/address.rs +++ b/rust/src/address.rs @@ -6,13 +6,16 @@ use ed25519_bip32::XPub; // returns (Number represented, bytes read) if valid encoding // or None if decoding prematurely finished fn variable_nat_decode(bytes: &[u8]) -> Option<(u64, usize)> { - let mut output = 0u64; + let mut output = 0u128; let mut bytes_read = 0; for byte in bytes { - output = (output << 7) | (byte & 0x7F) as u64; + output = (output << 7) | (byte & 0x7F) as u128; + if output > u64::MAX.into() { + return None; + } bytes_read += 1; if (byte & 0x80) == 0 { - return Some((output, bytes_read)); + return Some((output as u64, bytes_read)); } } None @@ -695,6 +698,12 @@ mod tests { } } + #[test] + fn variable_nat_decode_too_big() { + let too_big = [129, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127]; + assert_eq!(None, variable_nat_decode(&too_big)); + } + #[test] fn base_serialize_consistency() { let base = BaseAddress::new( From 22be0157a7aa24b4a834aaffe17abc2c9cd2b91b Mon Sep 17 00:00:00 2001 From: lisicky Date: Wed, 27 Apr 2022 05:13:33 +0300 Subject: [PATCH 03/26] try save backward capability --- rust/src/address.rs | 44 ++++++++++++++++++++++++++++++------------ rust/src/tx_builder.rs | 2 +- rust/src/utils.rs | 19 ++++++++++++++++++ 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/rust/src/address.rs b/rust/src/address.rs index 7bb31a97..a15f5e9a 100644 --- a/rust/src/address.rs +++ b/rust/src/address.rs @@ -395,7 +395,7 @@ impl Address { PointerAddress::new( network, &payment_cred, - &Pointer::new( + &Pointer::new_bignum( &to_bignum(slot), &to_bignum(tx_index), &to_bignum(cert_index)))) @@ -618,7 +618,15 @@ pub struct Pointer { #[wasm_bindgen] impl Pointer { - pub fn new(slot: &BigNum, tx_index: &BigNum, cert_index: &BigNum) -> Self { + pub fn new(slot: &Slot, tx_index: &Slot, cert_index: &Slot) -> Self { + Self { + slot: slot.clone().into(), + tx_index: tx_index.clone().into(), + cert_index: cert_index.clone().into(), + } + } + + pub fn new_bignum(slot: &BigNum, tx_index: &BigNum, cert_index: &BigNum) -> Self { Self { slot: slot.clone(), tx_index: tx_index.clone(), @@ -626,15 +634,27 @@ impl Pointer { } } - pub fn slot(&self) -> BigNum { + pub fn slot(&self) -> Result { + self.slot.clone().try_into() + } + + pub fn tx_index(&self) -> Result { + self.tx_index.clone().try_into() + } + + pub fn cert_index(&self) -> Result { + self.cert_index.clone().try_into() + } + + pub fn slot_bignum(&self) -> BigNum { self.slot.clone() } - pub fn tx_index(&self) -> BigNum { + pub fn tx_index_bignum(&self) -> BigNum { self.tx_index.clone() } - pub fn cert_index(&self) -> BigNum { + pub fn cert_index_bignum(&self) -> BigNum { self.cert_index.clone() } } @@ -720,7 +740,7 @@ mod tests { let ptr = PointerAddress::new( 25, &StakeCredential::from_keyhash(&Ed25519KeyHash::from([23; Ed25519KeyHash::BYTE_COUNT])), - &Pointer::new(&to_bignum(2354556573), &to_bignum(127), &to_bignum(0))); + &Pointer::new_bignum(&to_bignum(2354556573), &to_bignum(127), &to_bignum(0))); let addr = ptr.to_address(); let addr2 = Address::from_bytes(addr.to_bytes()).unwrap(); assert_eq!(addr.to_bytes(), addr2.to_bytes()); @@ -836,9 +856,9 @@ mod tests { .derive(0) .to_public(); let spend_cred = StakeCredential::from_keyhash(&spend.to_raw_key().hash()); - let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); + let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new_bignum(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); assert_eq!(addr_net_0.to_bech32(None).unwrap(), "addr_test1gz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerspqgpsqe70et"); - let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); + let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new_bignum(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); assert_eq!(addr_net_3.to_bech32(None).unwrap(), "addr1gx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer5ph3wczvf2w8lunk"); } @@ -892,9 +912,9 @@ mod tests { .derive(0) .to_public(); let spend_cred = StakeCredential::from_keyhash(&spend.to_raw_key().hash()); - let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); + let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new_bignum(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); assert_eq!(addr_net_0.to_bech32(None).unwrap(), "addr_test1gpu5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5egpqgpsdhdyc0"); - let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); + let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new_bignum(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); assert_eq!(addr_net_3.to_bech32(None).unwrap(), "addr1g9u5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5evph3wczvf2kd5vam"); } @@ -975,9 +995,9 @@ mod tests { .derive(0) .to_public(); let spend_cred = StakeCredential::from_keyhash(&spend.to_raw_key().hash()); - let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); + let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new_bignum(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); assert_eq!(addr_net_0.to_bech32(None).unwrap(), "addr_test1gqy6nhfyks7wdu3dudslys37v252w2nwhv0fw2nfawemmnqpqgps5mee0p"); - let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); + let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new_bignum(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); assert_eq!(addr_net_3.to_bech32(None).unwrap(), "addr1gyy6nhfyks7wdu3dudslys37v252w2nwhv0fw2nfawemmnyph3wczvf2dqflgt"); } diff --git a/rust/src/tx_builder.rs b/rust/src/tx_builder.rs index 52d56774..631b4143 100644 --- a/rust/src/tx_builder.rs +++ b/rust/src/tx_builder.rs @@ -1846,7 +1846,7 @@ mod tests { &PointerAddress::new( NetworkInfo::testnet().network_id(), &spend_cred, - &Pointer::new( + &Pointer::new_bignum( &to_bignum(0), &to_bignum(0), &to_bignum(0) diff --git a/rust/src/utils.rs b/rust/src/utils.rs index b2a397e2..6b7d14f1 100644 --- a/rust/src/utils.rs +++ b/rust/src/utils.rs @@ -2,6 +2,7 @@ use cbor_event::{self, de::Deserializer, se::{Serialize, Serializer}}; use hex::FromHex; use serde_json; use std::{collections::HashMap, io::{BufRead, Seek, Write}}; +use std::convert::{TryFrom}; use itertools::Itertools; use std::ops::{Rem, Div, Sub}; @@ -228,6 +229,24 @@ impl BigNum { } } +impl TryFrom for u32 { + type Error = JsError; + + fn try_from(value: BigNum) -> Result { + if value.0 > u32::MAX.into() { + Err(JsError::from_str(&format!("Value {} is bigger than max u32 {}", value.0, u32::MAX))) + } else { + Ok(value.0 as u32) + } + } +} + +impl From for BigNum { + fn from(value: u32) -> Self { + return BigNum(value.into()) + } +} + impl cbor_event::se::Serialize for BigNum { fn serialize<'se, W: Write>(&self, serializer: &'se mut Serializer) -> cbor_event::Result<&'se mut Serializer> { serializer.write_unsigned_integer(self.0) From e5837bc065762e9ab10f34157f30a474b22772a7 Mon Sep 17 00:00:00 2001 From: lisicky Date: Fri, 29 Apr 2022 15:50:38 +0300 Subject: [PATCH 04/26] slot type u32 -> bignum --- rust/src/address.rs | 5 +- rust/src/lib.rs | 109 +++++++++++++++++++++++++++++++------- rust/src/serialization.rs | 10 ++-- rust/src/tx_builder.rs | 18 +++++-- rust/src/utils.rs | 4 +- 5 files changed, 114 insertions(+), 32 deletions(-) diff --git a/rust/src/address.rs b/rust/src/address.rs index a15f5e9a..ba87d6e2 100644 --- a/rust/src/address.rs +++ b/rust/src/address.rs @@ -618,7 +618,8 @@ pub struct Pointer { #[wasm_bindgen] impl Pointer { - pub fn new(slot: &Slot, tx_index: &Slot, cert_index: &Slot) -> Self { + + pub fn new(slot: &Slot32, tx_index: &TransactionIndex, cert_index: &CertificateIndex) -> Self { Self { slot: slot.clone().into(), tx_index: tx_index.clone().into(), @@ -626,7 +627,7 @@ impl Pointer { } } - pub fn new_bignum(slot: &BigNum, tx_index: &BigNum, cert_index: &BigNum) -> Self { + pub fn new_bignum(slot: &SlotBigNum, tx_index: &BigNum, cert_index: &BigNum) -> Self { Self { slot: slot.clone(), tx_index: tx_index.clone(), diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 09db52b5..110bcda7 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -95,7 +95,8 @@ impl UnitInterval { type SubCoin = UnitInterval; type Rational = UnitInterval; type Epoch = u32; -type Slot = u32; +type Slot32 = u32; +type SlotBigNum = BigNum; #[wasm_bindgen] #[derive(Clone)] @@ -233,12 +234,12 @@ pub struct TransactionBody { inputs: TransactionInputs, outputs: TransactionOutputs, fee: Coin, - ttl: Option, + ttl: Option, certs: Option, withdrawals: Option, update: Option, auxiliary_data_hash: Option, - validity_start_interval: Option, + validity_start_interval: Option, mint: Option, script_data_hash: Option, collateral: Option, @@ -262,7 +263,18 @@ impl TransactionBody { self.fee.clone() } - pub fn ttl(&self) -> Option { + //TODO: add deprecated + pub fn ttl(&self) -> Result, JsError> { + match self.ttl { + Some(ttl) => + match ttl.try_into() { + Ok(ttl32) => Ok(Some(ttl32)), + Err(err) => Err(err)}, + None => Ok(None) + } + } + + pub fn ttl_bignum(&self) -> Option { self.ttl } @@ -298,14 +310,31 @@ impl TransactionBody { self.auxiliary_data_hash.clone() } - pub fn set_validity_start_interval(&mut self, validity_start_interval: Slot) { + //TODO: add deprecated + pub fn set_validity_start_interval(&mut self, validity_start_interval: Slot32) { + self.validity_start_interval = Some(validity_start_interval.into()) + } + + pub fn set_validity_start_interval_bignum(&mut self, validity_start_interval: SlotBigNum) { self.validity_start_interval = Some(validity_start_interval) } - pub fn validity_start_interval(&self) -> Option { + pub fn validity_start_interval_bignum(&self) -> Option { self.validity_start_interval.clone() } + //TODO: add deprecated + pub fn validity_start_interval(&self) -> Result, JsError> { + match self.validity_start_interval.clone() { + Some(interval) => match interval.try_into() + { + Ok(internal32) => Ok(Some(internal32)), + Err(err) => Err(err) + }, + None => Ok(None) + } + } + pub fn set_mint(&mut self, mint: &Mint) { self.mint = Some(mint.clone()) } @@ -356,16 +385,17 @@ impl TransactionBody { self.network_id.clone() } + //TODO: add new for bignum pub fn new( inputs: &TransactionInputs, outputs: &TransactionOutputs, fee: &Coin, - ttl: Option) -> Self { + ttl: Option) -> Self { Self { inputs: inputs.clone(), outputs: outputs.clone(), fee: fee.clone(), - ttl: ttl, + ttl: match ttl.clone() { Some(ttl32) => Some(ttl32.into()), None => None}, certs: None, withdrawals: None, update: None, @@ -1562,18 +1592,32 @@ impl ScriptNOfK { #[wasm_bindgen] #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] pub struct TimelockStart { - slot: Slot, + slot: SlotBigNum, } to_from_bytes!(TimelockStart); #[wasm_bindgen] impl TimelockStart { - pub fn slot(&self) -> Slot { + + //TODO add deprecated + pub fn slot(&self) -> Result { + self.slot.try_into() + } + + + pub fn slot_bignum(&self) -> SlotBigNum{ self.slot } - pub fn new(slot: Slot) -> Self { + //TODO add deprecated + pub fn new(slot: Slot32) -> Self { + Self { + slot: slot.into(), + } + } + + pub fn new_bignum(slot: SlotBigNum) -> Self { Self { slot, } @@ -1583,20 +1627,25 @@ impl TimelockStart { #[wasm_bindgen] #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] pub struct TimelockExpiry { - slot: Slot, + slot: SlotBigNum, } to_from_bytes!(TimelockExpiry); #[wasm_bindgen] impl TimelockExpiry { - pub fn slot(&self) -> Slot { + pub fn slot(&self) -> Result { + self.slot.try_into() + } + + pub fn slot_bignum(&self) -> SlotBigNum { self.slot } - pub fn new(slot: Slot) -> Self { + //TODO: Add new for bignum + pub fn new(slot: Slot32) -> Self { Self { - slot, + slot: (slot.into()) } } } @@ -2394,7 +2443,7 @@ impl OperationalCert { #[derive(Clone)] pub struct HeaderBody { block_number: u32, - slot: Slot, + slot: SlotBigNum, prev_hash: Option, issuer_vkey: Vkey, vrf_vkey: VRFVKey, @@ -2414,7 +2463,12 @@ impl HeaderBody { self.block_number.clone() } - pub fn slot(&self) -> Slot { + //TODO: add deprecated + pub fn slot(&self) -> Result { + self.slot.clone().try_into() + } + + pub fn slot_bignun(&self) -> SlotBigNum { self.slot.clone() } @@ -2454,10 +2508,27 @@ impl HeaderBody { self.protocol_version.clone() } - pub fn new(block_number: u32, slot: Slot, prev_hash: Option, issuer_vkey: &Vkey, vrf_vkey: &VRFVKey, nonce_vrf: &VRFCert, leader_vrf: &VRFCert, block_body_size: u32, block_body_hash: &BlockHash, operational_cert: &OperationalCert, protocol_version: &ProtocolVersion) -> Self { + //TODO add deprecated + pub fn new(block_number: u32, slot: Slot32, prev_hash: Option, issuer_vkey: &Vkey, vrf_vkey: &VRFVKey, nonce_vrf: &VRFCert, leader_vrf: &VRFCert, block_body_size: u32, block_body_hash: &BlockHash, operational_cert: &OperationalCert, protocol_version: &ProtocolVersion) -> Self { + Self { + block_number: block_number, + slot: slot.clone().into(), + prev_hash: prev_hash.clone(), + issuer_vkey: issuer_vkey.clone(), + vrf_vkey: vrf_vkey.clone(), + nonce_vrf: nonce_vrf.clone(), + leader_vrf: leader_vrf.clone(), + block_body_size: block_body_size, + block_body_hash: block_body_hash.clone(), + operational_cert: operational_cert.clone(), + protocol_version: protocol_version.clone(), + } + } + + pub fn new_bignum(block_number: u32, slot: SlotBigNum, prev_hash: Option, issuer_vkey: &Vkey, vrf_vkey: &VRFVKey, nonce_vrf: &VRFCert, leader_vrf: &VRFCert, block_body_size: u32, block_body_hash: &BlockHash, operational_cert: &OperationalCert, protocol_version: &ProtocolVersion) -> Self { Self { block_number: block_number, - slot: slot, + slot: slot.clone(), prev_hash: prev_hash.clone(), issuer_vkey: issuer_vkey.clone(), vrf_vkey: vrf_vkey.clone(), diff --git a/rust/src/serialization.rs b/rust/src/serialization.rs index 8cce61b0..7c398c9a 100644 --- a/rust/src/serialization.rs +++ b/rust/src/serialization.rs @@ -341,7 +341,7 @@ impl Deserialize for TransactionBody { } ttl = Some((|| -> Result<_, DeserializeError> { read_len.read_elems(1)?; - Ok(Slot::deserialize(raw)?) + Ok(SlotBigNum::deserialize(raw)?) })().map_err(|e| e.annotate("ttl"))?); }, 4 => { @@ -386,7 +386,7 @@ impl Deserialize for TransactionBody { } validity_start_interval = Some((|| -> Result<_, DeserializeError> { read_len.read_elems(1)?; - Ok(Slot::deserialize(raw)?) + Ok(SlotBigNum::deserialize(raw)?) })().map_err(|e| e.annotate("validity_start_interval"))?); }, 9 => { @@ -2171,7 +2171,7 @@ impl DeserializeEmbeddedGroup for TimelockStart { Ok(()) })().map_err(|e| e.annotate("index_0"))?; let slot = (|| -> Result<_, DeserializeError> { - Ok(Slot::deserialize(raw)?) + Ok(SlotBigNum::deserialize(raw)?) })().map_err(|e| e.annotate("slot"))?; Ok(TimelockStart { slot, @@ -2223,7 +2223,7 @@ impl DeserializeEmbeddedGroup for TimelockExpiry { Ok(()) })().map_err(|e| e.annotate("index_0"))?; let slot = (|| -> Result<_, DeserializeError> { - Ok(Slot::deserialize(raw)?) + Ok(SlotBigNum::deserialize(raw)?) })().map_err(|e| e.annotate("slot"))?; Ok(TimelockExpiry { slot, @@ -3243,7 +3243,7 @@ impl DeserializeEmbeddedGroup for HeaderBody { Ok(u32::deserialize(raw)?) })().map_err(|e| e.annotate("block_number"))?; let slot = (|| -> Result<_, DeserializeError> { - Ok(Slot::deserialize(raw)?) + Ok(SlotBigNum::deserialize(raw)?) })().map_err(|e| e.annotate("slot"))?; let prev_hash = (|| -> Result<_, DeserializeError> { Ok(match raw.cbor_type()? != CBORType::Special { diff --git a/rust/src/tx_builder.rs b/rust/src/tx_builder.rs index 631b4143..c6e4b36b 100644 --- a/rust/src/tx_builder.rs +++ b/rust/src/tx_builder.rs @@ -308,11 +308,11 @@ pub struct TransactionBuilder { inputs: Vec, outputs: TransactionOutputs, fee: Option, - ttl: Option, // absolute slot number + ttl: Option, // absolute slot number certs: Option, withdrawals: Option, auxiliary_data: Option, - validity_start_interval: Option, + validity_start_interval: Option, input_types: MockWitnessSet, mint: Option, mint_scripts: Option, @@ -710,11 +710,21 @@ impl TransactionBuilder { self.fee = Some(fee.clone()) } - pub fn set_ttl(&mut self, ttl: Slot) { + //TODO: add deprecated + pub fn set_ttl(&mut self, ttl: Slot32) { + self.ttl = Some(ttl.into()) + } + + pub fn set_ttl_bignum(&mut self, ttl: SlotBigNum) { self.ttl = Some(ttl) } - pub fn set_validity_start_interval(&mut self, validity_start_interval: Slot) { + //TODO: add deprecateed + pub fn set_validity_start_interval(&mut self, validity_start_interval: Slot32) { + self.validity_start_interval = Some(validity_start_interval.into()) + } + + pub fn set_validity_start_interval_bignum(&mut self, validity_start_interval: SlotBigNum) { self.validity_start_interval = Some(validity_start_interval) } diff --git a/rust/src/utils.rs b/rust/src/utils.rs index 6b7d14f1..b805a7f9 100644 --- a/rust/src/utils.rs +++ b/rust/src/utils.rs @@ -2246,7 +2246,7 @@ mod tests { Bip32PublicKey::from_bytes(&hex::decode(cosigner0_hex).unwrap()).unwrap().to_raw_key().hash() ); let all_1 = all.get(1).as_timelock_start().unwrap(); - assert_eq!(all_1.slot(), 120); + assert_eq!(all_1.slot().unwrap(), 120); let any = from.get(1).as_script_any().unwrap().native_scripts(); assert_eq!(all.len(), 2); let any_0 = any.get(0).as_script_pubkey().unwrap(); @@ -2255,7 +2255,7 @@ mod tests { Bip32PublicKey::from_bytes(&hex::decode(cosigner1_hex).unwrap()).unwrap().to_raw_key().hash() ); let any_1 = any.get(1).as_timelock_expiry().unwrap(); - assert_eq!(any_1.slot(), 1000); + assert_eq!(any_1.slot().unwrap(), 1000); let self_key = from.get(2).as_script_pubkey().unwrap(); assert_eq!( self_key.addr_keyhash(), From a0fa15bdfca5216849f41f6e6444da57c5b49028 Mon Sep 17 00:00:00 2001 From: lisicky Date: Fri, 29 Apr 2022 15:57:32 +0300 Subject: [PATCH 05/26] remove pass by ref for new pointer --- rust/src/address.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/src/address.rs b/rust/src/address.rs index ba87d6e2..194b61d5 100644 --- a/rust/src/address.rs +++ b/rust/src/address.rs @@ -619,11 +619,11 @@ pub struct Pointer { #[wasm_bindgen] impl Pointer { - pub fn new(slot: &Slot32, tx_index: &TransactionIndex, cert_index: &CertificateIndex) -> Self { + pub fn new(slot: Slot32, tx_index: TransactionIndex, cert_index: CertificateIndex) -> Self { Self { - slot: slot.clone().into(), - tx_index: tx_index.clone().into(), - cert_index: cert_index.clone().into(), + slot: slot.into(), + tx_index: tx_index.into(), + cert_index: cert_index.into(), } } From 8af8afda17db335152ee24cfabbef87704a1a3d1 Mon Sep 17 00:00:00 2001 From: lisicky Date: Fri, 29 Apr 2022 16:37:00 +0300 Subject: [PATCH 06/26] slot to bignum --- rust/src/lib.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 110bcda7..d731a303 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -385,7 +385,7 @@ impl TransactionBody { self.network_id.clone() } - //TODO: add new for bignum + //TODO: add deprecated pub fn new( inputs: &TransactionInputs, outputs: &TransactionOutputs, @@ -395,7 +395,33 @@ impl TransactionBody { inputs: inputs.clone(), outputs: outputs.clone(), fee: fee.clone(), - ttl: match ttl.clone() { Some(ttl32) => Some(ttl32.into()), None => None}, + ttl: match ttl.clone() { + Some(ttl32) => Some(ttl32.into()), + None => None + }, + certs: None, + withdrawals: None, + update: None, + auxiliary_data_hash: None, + validity_start_interval: None, + mint: None, + script_data_hash: None, + collateral: None, + required_signers: None, + network_id: None, + } + } + + pub fn new_bignum( + inputs: &TransactionInputs, + outputs: &TransactionOutputs, + fee: &Coin, + ttl: Option) -> Self { + Self { + inputs: inputs.clone(), + outputs: outputs.clone(), + fee: fee.clone(), + ttl: ttl.clone(), certs: None, withdrawals: None, update: None, From 1bf1961dfe0499781204f255eccd65925a51d8cb Mon Sep 17 00:00:00 2001 From: lisicky Date: Fri, 29 Apr 2022 16:49:15 +0300 Subject: [PATCH 07/26] add updated js flow --- rust/pkg/cardano_serialization_lib.js.flow | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index 7e054184..472fcad6 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -1904,6 +1904,11 @@ declare export class HeaderBody { */ slot(): number; + /** + * @returns {BigNum} + */ + slot_bignun(): BigNum; + /** * @returns {BlockHash | void} */ @@ -1976,6 +1981,34 @@ declare export class HeaderBody { operational_cert: OperationalCert, protocol_version: ProtocolVersion ): HeaderBody; + + /** + * @param {number} block_number + * @param {BigNum} slot + * @param {BlockHash | void} prev_hash + * @param {Vkey} issuer_vkey + * @param {VRFVKey} vrf_vkey + * @param {VRFCert} nonce_vrf + * @param {VRFCert} leader_vrf + * @param {number} block_body_size + * @param {BlockHash} block_body_hash + * @param {OperationalCert} operational_cert + * @param {ProtocolVersion} protocol_version + * @returns {HeaderBody} + */ + static new_bignum( + block_number: number, + slot: BigNum, + prev_hash: BlockHash | void, + issuer_vkey: Vkey, + vrf_vkey: VRFVKey, + nonce_vrf: VRFCert, + leader_vrf: VRFCert, + block_body_size: number, + block_body_hash: BlockHash, + operational_cert: OperationalCert, + protocol_version: ProtocolVersion + ): HeaderBody; } /** */ @@ -3219,6 +3252,18 @@ declare export class Pointer { */ static new(slot: number, tx_index: number, cert_index: number): Pointer; + /** + * @param {BigNum} slot + * @param {BigNum} tx_index + * @param {BigNum} cert_index + * @returns {Pointer} + */ + static new_bignum( + slot: BigNum, + tx_index: BigNum, + cert_index: BigNum + ): Pointer; + /** * @returns {number} */ @@ -3233,6 +3278,21 @@ declare export class Pointer { * @returns {number} */ cert_index(): number; + + /** + * @returns {BigNum} + */ + slot_bignum(): BigNum; + + /** + * @returns {BigNum} + */ + tx_index_bignum(): BigNum; + + /** + * @returns {BigNum} + */ + cert_index_bignum(): BigNum; } /** */ @@ -4768,6 +4828,11 @@ declare export class TimelockExpiry { */ slot(): number; + /** + * @returns {BigNum} + */ + slot_bignum(): BigNum; + /** * @param {number} slot * @returns {TimelockExpiry} @@ -4795,11 +4860,22 @@ declare export class TimelockStart { */ slot(): number; + /** + * @returns {BigNum} + */ + slot_bignum(): BigNum; + /** * @param {number} slot * @returns {TimelockStart} */ static new(slot: number): TimelockStart; + + /** + * @param {BigNum} slot + * @returns {TimelockStart} + */ + static new_bignum(slot: BigNum): TimelockStart; } /** */ @@ -4927,6 +5003,11 @@ declare export class TransactionBody { */ ttl(): number | void; + /** + * @returns {BigNum | void} + */ + ttl_bignum(): BigNum | void; + /** * @param {Certificates} certs */ @@ -4972,6 +5053,16 @@ declare export class TransactionBody { */ set_validity_start_interval(validity_start_interval: number): void; + /** + * @param {BigNum} validity_start_interval + */ + set_validity_start_interval_bignum(validity_start_interval: BigNum): void; + + /** + * @returns {BigNum | void} + */ + validity_start_interval_bignum(): BigNum | void; + /** * @returns {number | void} */ @@ -5047,6 +5138,20 @@ declare export class TransactionBody { fee: BigNum, ttl?: number ): TransactionBody; + + /** + * @param {TransactionInputs} inputs + * @param {TransactionOutputs} outputs + * @param {BigNum} fee + * @param {BigNum | void} ttl + * @returns {TransactionBody} + */ + static new_bignum( + inputs: TransactionInputs, + outputs: TransactionOutputs, + fee: BigNum, + ttl?: BigNum + ): TransactionBody; } /** */ @@ -5145,11 +5250,21 @@ declare export class TransactionBuilder { */ set_ttl(ttl: number): void; + /** + * @param {BigNum} ttl + */ + set_ttl_bignum(ttl: BigNum): void; + /** * @param {number} validity_start_interval */ set_validity_start_interval(validity_start_interval: number): void; + /** + * @param {BigNum} validity_start_interval + */ + set_validity_start_interval_bignum(validity_start_interval: BigNum): void; + /** * @param {Certificates} certs */ From 0493f292cd32ba9c41cfe12a76edd0715bdca9f3 Mon Sep 17 00:00:00 2001 From: lisicky Date: Tue, 3 May 2022 12:39:12 +0400 Subject: [PATCH 08/26] add new for TimelockExpiry --- rust/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index d731a303..6149d5d9 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1668,12 +1668,18 @@ impl TimelockExpiry { self.slot } - //TODO: Add new for bignum + //TODO: deprecated pub fn new(slot: Slot32) -> Self { Self { slot: (slot.into()) } } + + pub fn new_bignum(slot: BigNum) -> Self { + Self { + slot + } + } } #[wasm_bindgen] From 3b8023bac63f8d8a6a5874e1e2e96ecc33e2cea7 Mon Sep 17 00:00:00 2001 From: lisicky Date: Tue, 3 May 2022 14:05:49 +0400 Subject: [PATCH 09/26] add info for deprecated functions --- rust/src/lib.rs | 69 ++++++++++++++++++++++++++++++++++++------ rust/src/tx_builder.rs | 14 +++++++-- 2 files changed, 72 insertions(+), 11 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 6149d5d9..bdcd2884 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -263,7 +263,14 @@ impl TransactionBody { self.fee.clone() } - //TODO: add deprecated + + /// !!! DEPRECATED !!! + /// Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. + /// Otherwise will just return JsError. + #[deprecated( + since = "11.0.0", + note = "Possible boundary error. Use ttl_bignum instead" + )] pub fn ttl(&self) -> Result, JsError> { match self.ttl { Some(ttl) => @@ -310,7 +317,12 @@ impl TransactionBody { self.auxiliary_data_hash.clone() } - //TODO: add deprecated + /// !!! DEPRECATED !!! + /// Set validity_start_interval value. + #[deprecated( + since = "11.0.0", + note = "Underlying value capacity of slot (BigNum u64) bigger then Slot32. Use set_validity_start_interval_bignum instead." + )] pub fn set_validity_start_interval(&mut self, validity_start_interval: Slot32) { self.validity_start_interval = Some(validity_start_interval.into()) } @@ -323,7 +335,13 @@ impl TransactionBody { self.validity_start_interval.clone() } - //TODO: add deprecated + /// !!! DEPRECATED !!! + /// Returns a Option (u32) value in case the underlying original Option (u64) value is within the limits. + /// Otherwise will just return JsError. + #[deprecated( + since = "11.0.0", + note = "Possible boundary error. Use validity_start_interval_bignum instead" + )] pub fn validity_start_interval(&self) -> Result, JsError> { match self.validity_start_interval.clone() { Some(interval) => match interval.try_into() @@ -385,7 +403,12 @@ impl TransactionBody { self.network_id.clone() } - //TODO: add deprecated + /// !!! DEPRECATED !!! + /// Returns a new TransactionBody. + #[deprecated( + since = "11.0.0", + note = "Underlying value capacity of ttl (BigNum u64) bigger then Slot32. Use new_bignum instead." + )] pub fn new( inputs: &TransactionInputs, outputs: &TransactionOutputs, @@ -1626,7 +1649,13 @@ to_from_bytes!(TimelockStart); #[wasm_bindgen] impl TimelockStart { - //TODO add deprecated + /// !!! DEPRECATED !!! + /// Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. + /// Otherwise will just return JsError. + #[deprecated( + since = "11.0.0", + note = "Possible boundary error. Use slot_bignum instead" + )] pub fn slot(&self) -> Result { self.slot.try_into() } @@ -1636,7 +1665,12 @@ impl TimelockStart { self.slot } - //TODO add deprecated + /// !!! DEPRECATED !!! + /// Returns a new TimelockStart from Slot32 (u32) value. + #[deprecated( + since = "11.0.0", + note = "Underlying value capacity (BigNum u64) bigger then Slot32. Use new_bignum instead." + )] pub fn new(slot: Slot32) -> Self { Self { slot: slot.into(), @@ -1668,7 +1702,12 @@ impl TimelockExpiry { self.slot } - //TODO: deprecated + /// !!! DEPRECATED !!! + /// Returns a new TimelockExpiry from Slot32 (u32) value. + #[deprecated( + since = "11.0.0", + note = "Underlying value capacity (BigNum u64) bigger then Slot32. Use new_bignum instead." + )] pub fn new(slot: Slot32) -> Self { Self { slot: (slot.into()) @@ -2495,7 +2534,14 @@ impl HeaderBody { self.block_number.clone() } - //TODO: add deprecated + + /// !!! DEPRECATED !!! + /// Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. + /// Otherwise will just return JsError. + #[deprecated( + since = "11.0.0", + note = "Possible boundary error. Use slot_bignum instead" + )] pub fn slot(&self) -> Result { self.slot.clone().try_into() } @@ -2540,7 +2586,12 @@ impl HeaderBody { self.protocol_version.clone() } - //TODO add deprecated + /// !!! DEPRECATED !!! + /// Returns a new HeaderBody. + #[deprecated( + since = "11.0.0", + note = "Underlying value capacity of slot (BigNum u64) bigger then Slot32. Use new_bignum instead." + )] pub fn new(block_number: u32, slot: Slot32, prev_hash: Option, issuer_vkey: &Vkey, vrf_vkey: &VRFVKey, nonce_vrf: &VRFCert, leader_vrf: &VRFCert, block_body_size: u32, block_body_hash: &BlockHash, operational_cert: &OperationalCert, protocol_version: &ProtocolVersion) -> Self { Self { block_number: block_number, diff --git a/rust/src/tx_builder.rs b/rust/src/tx_builder.rs index c6e4b36b..57b55bc5 100644 --- a/rust/src/tx_builder.rs +++ b/rust/src/tx_builder.rs @@ -710,7 +710,12 @@ impl TransactionBuilder { self.fee = Some(fee.clone()) } - //TODO: add deprecated + /// !!! DEPRECATED !!! + /// Set ttl value. + #[deprecated( + since = "11.0.0", + note = "Underlying value capacity of ttl (BigNum u64) bigger then Slot32. Use set_ttl_bignum instead." + )] pub fn set_ttl(&mut self, ttl: Slot32) { self.ttl = Some(ttl.into()) } @@ -719,7 +724,12 @@ impl TransactionBuilder { self.ttl = Some(ttl) } - //TODO: add deprecateed + /// !!! DEPRECATED !!! + /// Set validity_start_interval value. + #[deprecated( + since = "11.0.0", + note = "Underlying value capacity of validity_start_interval (BigNum u64) bigger then Slot32. Use set_validity_start_interval_bignum instead." + )] pub fn set_validity_start_interval(&mut self, validity_start_interval: Slot32) { self.validity_start_interval = Some(validity_start_interval.into()) } From 0d95b220c1c6adad9a2f36d5df54ebda072d11d5 Mon Sep 17 00:00:00 2001 From: lisicky Date: Tue, 3 May 2022 14:45:55 +0400 Subject: [PATCH 10/26] pass bignum by ref --- rust/src/lib.rs | 14 +++++++------- rust/src/tx_builder.rs | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index bdcd2884..e0589773 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -328,7 +328,7 @@ impl TransactionBody { } pub fn set_validity_start_interval_bignum(&mut self, validity_start_interval: SlotBigNum) { - self.validity_start_interval = Some(validity_start_interval) + self.validity_start_interval = Some(validity_start_interval.clone()) } pub fn validity_start_interval_bignum(&self) -> Option { @@ -439,7 +439,7 @@ impl TransactionBody { inputs: &TransactionInputs, outputs: &TransactionOutputs, fee: &Coin, - ttl: Option) -> Self { + ttl: &Option) -> Self { Self { inputs: inputs.clone(), outputs: outputs.clone(), @@ -1677,9 +1677,9 @@ impl TimelockStart { } } - pub fn new_bignum(slot: SlotBigNum) -> Self { + pub fn new_bignum(slot: &SlotBigNum) -> Self { Self { - slot, + slot: slot.clone(), } } } @@ -1714,9 +1714,9 @@ impl TimelockExpiry { } } - pub fn new_bignum(slot: BigNum) -> Self { + pub fn new_bignum(slot: &SlotBigNum) -> Self { Self { - slot + slot : slot.clone() } } } @@ -2608,7 +2608,7 @@ impl HeaderBody { } } - pub fn new_bignum(block_number: u32, slot: SlotBigNum, prev_hash: Option, issuer_vkey: &Vkey, vrf_vkey: &VRFVKey, nonce_vrf: &VRFCert, leader_vrf: &VRFCert, block_body_size: u32, block_body_hash: &BlockHash, operational_cert: &OperationalCert, protocol_version: &ProtocolVersion) -> Self { + pub fn new_bignum(block_number: u32, slot: &SlotBigNum, prev_hash: Option, issuer_vkey: &Vkey, vrf_vkey: &VRFVKey, nonce_vrf: &VRFCert, leader_vrf: &VRFCert, block_body_size: u32, block_body_hash: &BlockHash, operational_cert: &OperationalCert, protocol_version: &ProtocolVersion) -> Self { Self { block_number: block_number, slot: slot.clone(), diff --git a/rust/src/tx_builder.rs b/rust/src/tx_builder.rs index 57b55bc5..94ff6525 100644 --- a/rust/src/tx_builder.rs +++ b/rust/src/tx_builder.rs @@ -720,8 +720,8 @@ impl TransactionBuilder { self.ttl = Some(ttl.into()) } - pub fn set_ttl_bignum(&mut self, ttl: SlotBigNum) { - self.ttl = Some(ttl) + pub fn set_ttl_bignum(&mut self, ttl: &SlotBigNum) { + self.ttl = Some(ttl.clone()) } /// !!! DEPRECATED !!! @@ -735,7 +735,7 @@ impl TransactionBuilder { } pub fn set_validity_start_interval_bignum(&mut self, validity_start_interval: SlotBigNum) { - self.validity_start_interval = Some(validity_start_interval) + self.validity_start_interval = Some(validity_start_interval.clone()) } pub fn set_certs(&mut self, certs: &Certificates) { From 63150c5609dc5d449f7e91f57c7e8b5f338ee348 Mon Sep 17 00:00:00 2001 From: lisicky Date: Tue, 3 May 2022 14:49:10 +0400 Subject: [PATCH 11/26] revert for wasm bingen support --- rust/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index e0589773..2e3aee25 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -439,7 +439,7 @@ impl TransactionBody { inputs: &TransactionInputs, outputs: &TransactionOutputs, fee: &Coin, - ttl: &Option) -> Self { + ttl: Option) -> Self { Self { inputs: inputs.clone(), outputs: outputs.clone(), From 711324e0217744480dbd58f6a879eda15d1585a8 Mon Sep 17 00:00:00 2001 From: lisicky Date: Wed, 4 May 2022 11:59:24 +0400 Subject: [PATCH 12/26] update js.flow file --- rust/pkg/cardano_serialization_lib.js.flow | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index 472fcad6..e823c13e 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -1900,6 +1900,9 @@ declare export class HeaderBody { block_number(): number; /** + * !!! DEPRECATED !!! + * Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. + * Otherwise will just return JsError. * @returns {number} */ slot(): number; @@ -1955,6 +1958,8 @@ declare export class HeaderBody { protocol_version(): ProtocolVersion; /** + * !!! DEPRECATED !!! + * Returns a new HeaderBody. * @param {number} block_number * @param {number} slot * @param {BlockHash | void} prev_hash @@ -4834,10 +4839,18 @@ declare export class TimelockExpiry { slot_bignum(): BigNum; /** + * !!! DEPRECATED !!! + * Returns a new TimelockExpiry from Slot32 (u32) value. * @param {number} slot * @returns {TimelockExpiry} */ static new(slot: number): TimelockExpiry; + + /** + * @param {BigNum} slot + * @returns {TimelockExpiry} + */ + static new_bignum(slot: BigNum): TimelockExpiry; } /** */ @@ -4856,6 +4869,9 @@ declare export class TimelockStart { static from_bytes(bytes: Uint8Array): TimelockStart; /** + * !!! DEPRECATED !!! + * Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. + * Otherwise will just return JsError. * @returns {number} */ slot(): number; @@ -4866,6 +4882,8 @@ declare export class TimelockStart { slot_bignum(): BigNum; /** + * !!! DEPRECATED !!! + * Returns a new TimelockStart from Slot32 (u32) value. * @param {number} slot * @returns {TimelockStart} */ @@ -4999,6 +5017,9 @@ declare export class TransactionBody { fee(): BigNum; /** + * !!! DEPRECATED !!! + * Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. + * Otherwise will just return JsError. * @returns {number | void} */ ttl(): number | void; @@ -5049,6 +5070,8 @@ declare export class TransactionBody { auxiliary_data_hash(): AuxiliaryDataHash | void; /** + * !!! DEPRECATED !!! + * Set validity_start_interval value. * @param {number} validity_start_interval */ set_validity_start_interval(validity_start_interval: number): void; @@ -5064,6 +5087,9 @@ declare export class TransactionBody { validity_start_interval_bignum(): BigNum | void; /** + * !!! DEPRECATED !!! + * Returns a Option (u32) value in case the underlying original Option (u64) value is within the limits. + * Otherwise will just return JsError. * @returns {number | void} */ validity_start_interval(): number | void; @@ -5126,6 +5152,8 @@ declare export class TransactionBody { network_id(): NetworkId | void; /** + * !!! DEPRECATED !!! + * Returns a new TransactionBody. * @param {TransactionInputs} inputs * @param {TransactionOutputs} outputs * @param {BigNum} fee @@ -5246,6 +5274,8 @@ declare export class TransactionBuilder { set_fee(fee: BigNum): void; /** + * !!! DEPRECATED !!! + * Set ttl value. * @param {number} ttl */ set_ttl(ttl: number): void; @@ -5256,6 +5286,8 @@ declare export class TransactionBuilder { set_ttl_bignum(ttl: BigNum): void; /** + * !!! DEPRECATED !!! + * Set validity_start_interval value. * @param {number} validity_start_interval */ set_validity_start_interval(validity_start_interval: number): void; From 2b1e4b676f05ba15cc4c67ad9ed3716ee8215859 Mon Sep 17 00:00:00 2001 From: lisicky Date: Wed, 4 May 2022 16:57:11 +0400 Subject: [PATCH 13/26] change ttl setting location for TransactionBody --- rust/src/lib.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 2e3aee25..c9939675 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -285,6 +285,14 @@ impl TransactionBody { self.ttl } + pub fn set_ttl(&mut self, ttl: &SlotBigNum) { + self.ttl = Some(ttl.clone()) + } + + pub fn remove_ttl(&mut self) { + self.ttl = None + } + pub fn set_certs(&mut self, certs: &Certificates) { self.certs = Some(certs.clone()) } @@ -407,7 +415,7 @@ impl TransactionBody { /// Returns a new TransactionBody. #[deprecated( since = "11.0.0", - note = "Underlying value capacity of ttl (BigNum u64) bigger then Slot32. Use new_bignum instead." + note = "Underlying value capacity of ttl (BigNum u64) bigger then Slot32. Use new_tx_body instead." )] pub fn new( inputs: &TransactionInputs, @@ -435,16 +443,18 @@ impl TransactionBody { } } - pub fn new_bignum( + /// Returns a new TransactionBody. + /// In the new version of "new" we removed optional ttl for support it by wasm_bingen. + /// Your can use "set_ttl" and "remove_ttl" to set a new value for ttl or set it as None. + pub fn new_tx_body( inputs: &TransactionInputs, outputs: &TransactionOutputs, - fee: &Coin, - ttl: Option) -> Self { + fee: &Coin) -> Self { Self { inputs: inputs.clone(), outputs: outputs.clone(), fee: fee.clone(), - ttl: ttl.clone(), + ttl: None, certs: None, withdrawals: None, update: None, From a6ba16b2b0ba466d1a56c9ca48968df30618d31b Mon Sep 17 00:00:00 2001 From: lisicky Date: Wed, 4 May 2022 17:00:18 +0400 Subject: [PATCH 14/26] rename new "new" --- rust/pkg/cardano_serialization_lib.js.flow | 18 ++++++++++++++---- rust/src/address.rs | 2 +- rust/src/lib.rs | 6 +++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index e823c13e..a9ca0a00 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -5029,6 +5029,15 @@ declare export class TransactionBody { */ ttl_bignum(): BigNum | void; + /** + * @param {BigNum} ttl + */ + set_ttl(ttl: BigNum): void; + + /** + */ + remove_ttl(): void; + /** * @param {Certificates} certs */ @@ -5168,17 +5177,18 @@ declare export class TransactionBody { ): TransactionBody; /** + * Returns a new TransactionBody. + * In the new version of "new" we removed optional ttl for support it by wasm_bingen. + * Your can use "set_ttl" and "remove_ttl" to set a new value for ttl or set it as None. * @param {TransactionInputs} inputs * @param {TransactionOutputs} outputs * @param {BigNum} fee - * @param {BigNum | void} ttl * @returns {TransactionBody} */ - static new_bignum( + static new_tx_body( inputs: TransactionInputs, outputs: TransactionOutputs, - fee: BigNum, - ttl?: BigNum + fee: BigNum ): TransactionBody; } /** diff --git a/rust/src/address.rs b/rust/src/address.rs index 194b61d5..f24d97d9 100644 --- a/rust/src/address.rs +++ b/rust/src/address.rs @@ -627,7 +627,7 @@ impl Pointer { } } - pub fn new_bignum(slot: &SlotBigNum, tx_index: &BigNum, cert_index: &BigNum) -> Self { + pub fn new_pointer(slot: &SlotBigNum, tx_index: &BigNum, cert_index: &BigNum) -> Self { Self { slot: slot.clone(), tx_index: tx_index.clone(), diff --git a/rust/src/lib.rs b/rust/src/lib.rs index c9939675..4355de39 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1687,7 +1687,7 @@ impl TimelockStart { } } - pub fn new_bignum(slot: &SlotBigNum) -> Self { + pub fn new_timelockstart(slot: &SlotBigNum) -> Self { Self { slot: slot.clone(), } @@ -1724,7 +1724,7 @@ impl TimelockExpiry { } } - pub fn new_bignum(slot: &SlotBigNum) -> Self { + pub fn new_timelockexpiry(slot: &SlotBigNum) -> Self { Self { slot : slot.clone() } @@ -2618,7 +2618,7 @@ impl HeaderBody { } } - pub fn new_bignum(block_number: u32, slot: &SlotBigNum, prev_hash: Option, issuer_vkey: &Vkey, vrf_vkey: &VRFVKey, nonce_vrf: &VRFCert, leader_vrf: &VRFCert, block_body_size: u32, block_body_hash: &BlockHash, operational_cert: &OperationalCert, protocol_version: &ProtocolVersion) -> Self { + pub fn new_headerbody(block_number: u32, slot: &SlotBigNum, prev_hash: Option, issuer_vkey: &Vkey, vrf_vkey: &VRFVKey, nonce_vrf: &VRFCert, leader_vrf: &VRFCert, block_body_size: u32, block_body_hash: &BlockHash, operational_cert: &OperationalCert, protocol_version: &ProtocolVersion) -> Self { Self { block_number: block_number, slot: slot.clone(), From d07a853852a6ca9d66d517fd32524b24f14cc53b Mon Sep 17 00:00:00 2001 From: lisicky Date: Wed, 4 May 2022 17:03:53 +0400 Subject: [PATCH 15/26] fix after renaming --- rust/src/address.rs | 16 ++++++++-------- rust/src/tx_builder.rs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/rust/src/address.rs b/rust/src/address.rs index f24d97d9..91dd07ee 100644 --- a/rust/src/address.rs +++ b/rust/src/address.rs @@ -395,7 +395,7 @@ impl Address { PointerAddress::new( network, &payment_cred, - &Pointer::new_bignum( + &Pointer::new_pointer( &to_bignum(slot), &to_bignum(tx_index), &to_bignum(cert_index)))) @@ -741,7 +741,7 @@ mod tests { let ptr = PointerAddress::new( 25, &StakeCredential::from_keyhash(&Ed25519KeyHash::from([23; Ed25519KeyHash::BYTE_COUNT])), - &Pointer::new_bignum(&to_bignum(2354556573), &to_bignum(127), &to_bignum(0))); + &Pointer::new_pointer(&to_bignum(2354556573), &to_bignum(127), &to_bignum(0))); let addr = ptr.to_address(); let addr2 = Address::from_bytes(addr.to_bytes()).unwrap(); assert_eq!(addr.to_bytes(), addr2.to_bytes()); @@ -857,9 +857,9 @@ mod tests { .derive(0) .to_public(); let spend_cred = StakeCredential::from_keyhash(&spend.to_raw_key().hash()); - let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new_bignum(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); + let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new_pointer(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); assert_eq!(addr_net_0.to_bech32(None).unwrap(), "addr_test1gz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerspqgpsqe70et"); - let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new_bignum(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); + let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new_pointer(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); assert_eq!(addr_net_3.to_bech32(None).unwrap(), "addr1gx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer5ph3wczvf2w8lunk"); } @@ -913,9 +913,9 @@ mod tests { .derive(0) .to_public(); let spend_cred = StakeCredential::from_keyhash(&spend.to_raw_key().hash()); - let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new_bignum(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); + let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new_pointer(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); assert_eq!(addr_net_0.to_bech32(None).unwrap(), "addr_test1gpu5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5egpqgpsdhdyc0"); - let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new_bignum(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); + let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new_pointer(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); assert_eq!(addr_net_3.to_bech32(None).unwrap(), "addr1g9u5vlrf4xkxv2qpwngf6cjhtw542ayty80v8dyr49rf5evph3wczvf2kd5vam"); } @@ -996,9 +996,9 @@ mod tests { .derive(0) .to_public(); let spend_cred = StakeCredential::from_keyhash(&spend.to_raw_key().hash()); - let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new_bignum(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); + let addr_net_0 = PointerAddress::new(NetworkInfo::testnet().network_id(), &spend_cred, &Pointer::new_pointer(&to_bignum(1), &to_bignum(2), &to_bignum(3))).to_address(); assert_eq!(addr_net_0.to_bech32(None).unwrap(), "addr_test1gqy6nhfyks7wdu3dudslys37v252w2nwhv0fw2nfawemmnqpqgps5mee0p"); - let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new_bignum(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); + let addr_net_3 = PointerAddress::new(NetworkInfo::mainnet().network_id(), &spend_cred, &Pointer::new_pointer(&to_bignum(24157), &to_bignum(177), &to_bignum(42))).to_address(); assert_eq!(addr_net_3.to_bech32(None).unwrap(), "addr1gyy6nhfyks7wdu3dudslys37v252w2nwhv0fw2nfawemmnyph3wczvf2dqflgt"); } diff --git a/rust/src/tx_builder.rs b/rust/src/tx_builder.rs index 94ff6525..f73bc425 100644 --- a/rust/src/tx_builder.rs +++ b/rust/src/tx_builder.rs @@ -1866,7 +1866,7 @@ mod tests { &PointerAddress::new( NetworkInfo::testnet().network_id(), &spend_cred, - &Pointer::new_bignum( + &Pointer::new_pointer( &to_bignum(0), &to_bignum(0), &to_bignum(0) From 95f1fb1dd2161c90b4c8a4f957be5fb4dfab687b Mon Sep 17 00:00:00 2001 From: lisicky Date: Wed, 4 May 2022 17:05:36 +0400 Subject: [PATCH 16/26] update flow.js --- rust/pkg/cardano_serialization_lib.js.flow | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index a9ca0a00..955d95a0 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -2001,7 +2001,7 @@ declare export class HeaderBody { * @param {ProtocolVersion} protocol_version * @returns {HeaderBody} */ - static new_bignum( + static new_headerbody( block_number: number, slot: BigNum, prev_hash: BlockHash | void, @@ -3263,7 +3263,7 @@ declare export class Pointer { * @param {BigNum} cert_index * @returns {Pointer} */ - static new_bignum( + static new_pointer( slot: BigNum, tx_index: BigNum, cert_index: BigNum @@ -4850,7 +4850,7 @@ declare export class TimelockExpiry { * @param {BigNum} slot * @returns {TimelockExpiry} */ - static new_bignum(slot: BigNum): TimelockExpiry; + static new_timelockexpiry(slot: BigNum): TimelockExpiry; } /** */ @@ -4893,7 +4893,7 @@ declare export class TimelockStart { * @param {BigNum} slot * @returns {TimelockStart} */ - static new_bignum(slot: BigNum): TimelockStart; + static new_timelockstart(slot: BigNum): TimelockStart; } /** */ From bdd2c7eea4abd50c18f58d5d763668ecd4030224 Mon Sep 17 00:00:00 2001 From: lisicky Date: Wed, 11 May 2022 14:14:18 +0400 Subject: [PATCH 17/26] fix misspelling --- rust/pkg/cardano_serialization_lib.js.flow | 2 +- rust/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index 955d95a0..f39efe4c 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -1910,7 +1910,7 @@ declare export class HeaderBody { /** * @returns {BigNum} */ - slot_bignun(): BigNum; + slot_bignum(): BigNum; /** * @returns {BlockHash | void} diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 4355de39..b5587ca6 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -2556,7 +2556,7 @@ impl HeaderBody { self.slot.clone().try_into() } - pub fn slot_bignun(&self) -> SlotBigNum { + pub fn slot_bignum(&self) -> SlotBigNum { self.slot.clone() } From 8aa9d1156e326497938fe37728996f05f345fb23 Mon Sep 17 00:00:00 2001 From: vantuz-subhuman Date: Sat, 14 May 2022 22:51:58 +0300 Subject: [PATCH 18/26] Added a test comparing two pointer constructors --- rust/src/address.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rust/src/address.rs b/rust/src/address.rs index 91dd07ee..e4a1dfb6 100644 --- a/rust/src/address.rs +++ b/rust/src/address.rs @@ -1080,4 +1080,11 @@ mod tests { assert_eq!(u64::MAX, from_bignum(&ptr.tx_index)); assert_eq!(u64::MAX, from_bignum(&ptr.cert_index)); } + + #[test] + fn point_address_old() { + let p1 = Pointer::new(10, 20, 30); + let p2 = Pointer::new_pointer(&to_bignum(10), &to_bignum(20), &to_bignum(30)); + assert_eq!(p1, p2); + } } From fefbdd3944aaa3e909ceb0e058440c75e0847035 Mon Sep 17 00:00:00 2001 From: vantuz-subhuman Date: Sat, 14 May 2022 23:03:32 +0300 Subject: [PATCH 19/26] deprecation version changed --- rust/src/lib.rs | 18 +++++++++--------- rust/src/tx_builder.rs | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index b5587ca6..d695bae6 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -268,7 +268,7 @@ impl TransactionBody { /// Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. /// Otherwise will just return JsError. #[deprecated( - since = "11.0.0", + since = "10.1.0", note = "Possible boundary error. Use ttl_bignum instead" )] pub fn ttl(&self) -> Result, JsError> { @@ -328,7 +328,7 @@ impl TransactionBody { /// !!! DEPRECATED !!! /// Set validity_start_interval value. #[deprecated( - since = "11.0.0", + since = "10.1.0", note = "Underlying value capacity of slot (BigNum u64) bigger then Slot32. Use set_validity_start_interval_bignum instead." )] pub fn set_validity_start_interval(&mut self, validity_start_interval: Slot32) { @@ -347,7 +347,7 @@ impl TransactionBody { /// Returns a Option (u32) value in case the underlying original Option (u64) value is within the limits. /// Otherwise will just return JsError. #[deprecated( - since = "11.0.0", + since = "10.1.0", note = "Possible boundary error. Use validity_start_interval_bignum instead" )] pub fn validity_start_interval(&self) -> Result, JsError> { @@ -414,7 +414,7 @@ impl TransactionBody { /// !!! DEPRECATED !!! /// Returns a new TransactionBody. #[deprecated( - since = "11.0.0", + since = "10.1.0", note = "Underlying value capacity of ttl (BigNum u64) bigger then Slot32. Use new_tx_body instead." )] pub fn new( @@ -1663,7 +1663,7 @@ impl TimelockStart { /// Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. /// Otherwise will just return JsError. #[deprecated( - since = "11.0.0", + since = "10.1.0", note = "Possible boundary error. Use slot_bignum instead" )] pub fn slot(&self) -> Result { @@ -1678,7 +1678,7 @@ impl TimelockStart { /// !!! DEPRECATED !!! /// Returns a new TimelockStart from Slot32 (u32) value. #[deprecated( - since = "11.0.0", + since = "10.1.0", note = "Underlying value capacity (BigNum u64) bigger then Slot32. Use new_bignum instead." )] pub fn new(slot: Slot32) -> Self { @@ -1715,7 +1715,7 @@ impl TimelockExpiry { /// !!! DEPRECATED !!! /// Returns a new TimelockExpiry from Slot32 (u32) value. #[deprecated( - since = "11.0.0", + since = "10.1.0", note = "Underlying value capacity (BigNum u64) bigger then Slot32. Use new_bignum instead." )] pub fn new(slot: Slot32) -> Self { @@ -2549,7 +2549,7 @@ impl HeaderBody { /// Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. /// Otherwise will just return JsError. #[deprecated( - since = "11.0.0", + since = "10.1.0", note = "Possible boundary error. Use slot_bignum instead" )] pub fn slot(&self) -> Result { @@ -2599,7 +2599,7 @@ impl HeaderBody { /// !!! DEPRECATED !!! /// Returns a new HeaderBody. #[deprecated( - since = "11.0.0", + since = "10.1.0", note = "Underlying value capacity of slot (BigNum u64) bigger then Slot32. Use new_bignum instead." )] pub fn new(block_number: u32, slot: Slot32, prev_hash: Option, issuer_vkey: &Vkey, vrf_vkey: &VRFVKey, nonce_vrf: &VRFCert, leader_vrf: &VRFCert, block_body_size: u32, block_body_hash: &BlockHash, operational_cert: &OperationalCert, protocol_version: &ProtocolVersion) -> Self { diff --git a/rust/src/tx_builder.rs b/rust/src/tx_builder.rs index 850c4dfc..9aacffa7 100644 --- a/rust/src/tx_builder.rs +++ b/rust/src/tx_builder.rs @@ -713,7 +713,7 @@ impl TransactionBuilder { /// !!! DEPRECATED !!! /// Set ttl value. #[deprecated( - since = "11.0.0", + since = "10.1.0", note = "Underlying value capacity of ttl (BigNum u64) bigger then Slot32. Use set_ttl_bignum instead." )] pub fn set_ttl(&mut self, ttl: Slot32) { @@ -727,7 +727,7 @@ impl TransactionBuilder { /// !!! DEPRECATED !!! /// Set validity_start_interval value. #[deprecated( - since = "11.0.0", + since = "10.1.0", note = "Underlying value capacity of validity_start_interval (BigNum u64) bigger then Slot32. Use set_validity_start_interval_bignum instead." )] pub fn set_validity_start_interval(&mut self, validity_start_interval: Slot32) { From da5ae7d1066675f4891d3d2650ae3c3ea2c363c8 Mon Sep 17 00:00:00 2001 From: Evgenii Lisitskii Date: Mon, 16 May 2022 12:16:13 +0400 Subject: [PATCH 20/26] Update comment in rust/src/lib.rs Co-authored-by: Ruslan Dudin --- rust/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index d695bae6..2c88f28b 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -412,7 +412,8 @@ impl TransactionBody { } /// !!! DEPRECATED !!! - /// Returns a new TransactionBody. + /// This constructor uses outdated slot number format for the ttl value. + /// Use `.new_tx_body` and then `.set_ttl` instead #[deprecated( since = "10.1.0", note = "Underlying value capacity of ttl (BigNum u64) bigger then Slot32. Use new_tx_body instead." From 64fbf1724e9138eaf1a9dc6a86b198cd0d77ca0b Mon Sep 17 00:00:00 2001 From: Evgenii Lisitskii Date: Mon, 16 May 2022 12:16:32 +0400 Subject: [PATCH 21/26] Update comment in rust/src/lib.rs Co-authored-by: Ruslan Dudin --- rust/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 2c88f28b..0567efee 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1677,7 +1677,8 @@ impl TimelockStart { } /// !!! DEPRECATED !!! - /// Returns a new TimelockStart from Slot32 (u32) value. + /// This constructor uses outdated slot number format. + /// Use `.new_timelockstart` instead. #[deprecated( since = "10.1.0", note = "Underlying value capacity (BigNum u64) bigger then Slot32. Use new_bignum instead." From 34853d206569e45c9164bf827c8f241de84a4c8a Mon Sep 17 00:00:00 2001 From: Evgenii Lisitskii Date: Mon, 16 May 2022 12:17:59 +0400 Subject: [PATCH 22/26] Apply suggestions from code review Co-authored-by: Ruslan Dudin --- rust/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 0567efee..1b6ce427 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -345,7 +345,8 @@ impl TransactionBody { /// !!! DEPRECATED !!! /// Returns a Option (u32) value in case the underlying original Option (u64) value is within the limits. - /// Otherwise will just return JsError. + /// Otherwise will just raise an error. + /// Use `.validity_start_interval_bignum` instead. #[deprecated( since = "10.1.0", note = "Possible boundary error. Use validity_start_interval_bignum instead" @@ -1662,7 +1663,8 @@ impl TimelockStart { /// !!! DEPRECATED !!! /// Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. - /// Otherwise will just return JsError. + /// Otherwise will just raise an error. + /// Use `.slot_bignum` instead #[deprecated( since = "10.1.0", note = "Possible boundary error. Use slot_bignum instead" From 83614a92e3bc92714b50832fd370a36db0a287b3 Mon Sep 17 00:00:00 2001 From: lisicky Date: Mon, 16 May 2022 12:40:48 +0400 Subject: [PATCH 23/26] fix comments according to suggestion --- rust/pkg/cardano_serialization_lib.js.flow | 31 ++++++++++++++++------ rust/src/lib.rs | 6 ++--- rust/src/tx_builder.rs | 2 +- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index f39efe4c..bf17ecdf 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -1902,7 +1902,7 @@ declare export class HeaderBody { /** * !!! DEPRECATED !!! * Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. - * Otherwise will just return JsError. + * Otherwise will just raise an error. * @returns {number} */ slot(): number; @@ -2020,6 +2020,17 @@ declare export class HeaderBody { declare export class Int { free(): void; + /** + * @returns {Uint8Array} + */ + to_bytes(): Uint8Array; + + /** + * @param {Uint8Array} bytes + * @returns {Int} + */ + static from_bytes(bytes: Uint8Array): Int; + /** * @param {BigNum} x * @returns {Int} @@ -4871,7 +4882,8 @@ declare export class TimelockStart { /** * !!! DEPRECATED !!! * Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. - * Otherwise will just return JsError. + * Otherwise will just raise an error. + * Use `.slot_bignum` instead * @returns {number} */ slot(): number; @@ -4883,7 +4895,8 @@ declare export class TimelockStart { /** * !!! DEPRECATED !!! - * Returns a new TimelockStart from Slot32 (u32) value. + * This constructor uses outdated slot number format. + * Use `.new_timelockstart` instead. * @param {number} slot * @returns {TimelockStart} */ @@ -5019,7 +5032,7 @@ declare export class TransactionBody { /** * !!! DEPRECATED !!! * Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. - * Otherwise will just return JsError. + * Otherwise will just raise an error. * @returns {number | void} */ ttl(): number | void; @@ -5080,7 +5093,7 @@ declare export class TransactionBody { /** * !!! DEPRECATED !!! - * Set validity_start_interval value. + * Uses outdated slot number format. * @param {number} validity_start_interval */ set_validity_start_interval(validity_start_interval: number): void; @@ -5098,7 +5111,8 @@ declare export class TransactionBody { /** * !!! DEPRECATED !!! * Returns a Option (u32) value in case the underlying original Option (u64) value is within the limits. - * Otherwise will just return JsError. + * Otherwise will just raise an error. + * Use `.validity_start_interval_bignum` instead. * @returns {number | void} */ validity_start_interval(): number | void; @@ -5162,7 +5176,8 @@ declare export class TransactionBody { /** * !!! DEPRECATED !!! - * Returns a new TransactionBody. + * This constructor uses outdated slot number format for the ttl value. + * Use `.new_tx_body` and then `.set_ttl` instead * @param {TransactionInputs} inputs * @param {TransactionOutputs} outputs * @param {BigNum} fee @@ -5297,7 +5312,7 @@ declare export class TransactionBuilder { /** * !!! DEPRECATED !!! - * Set validity_start_interval value. + * Uses outdated slot number format. * @param {number} validity_start_interval */ set_validity_start_interval(validity_start_interval: number): void; diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 1b6ce427..571ca895 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -266,7 +266,7 @@ impl TransactionBody { /// !!! DEPRECATED !!! /// Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. - /// Otherwise will just return JsError. + /// Otherwise will just raise an error. #[deprecated( since = "10.1.0", note = "Possible boundary error. Use ttl_bignum instead" @@ -326,7 +326,7 @@ impl TransactionBody { } /// !!! DEPRECATED !!! - /// Set validity_start_interval value. + /// Uses outdated slot number format. #[deprecated( since = "10.1.0", note = "Underlying value capacity of slot (BigNum u64) bigger then Slot32. Use set_validity_start_interval_bignum instead." @@ -2551,7 +2551,7 @@ impl HeaderBody { /// !!! DEPRECATED !!! /// Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits. - /// Otherwise will just return JsError. + /// Otherwise will just raise an error. #[deprecated( since = "10.1.0", note = "Possible boundary error. Use slot_bignum instead" diff --git a/rust/src/tx_builder.rs b/rust/src/tx_builder.rs index 9aacffa7..84541a8a 100644 --- a/rust/src/tx_builder.rs +++ b/rust/src/tx_builder.rs @@ -725,7 +725,7 @@ impl TransactionBuilder { } /// !!! DEPRECATED !!! - /// Set validity_start_interval value. + /// Uses outdated slot number format. #[deprecated( since = "10.1.0", note = "Underlying value capacity of validity_start_interval (BigNum u64) bigger then Slot32. Use set_validity_start_interval_bignum instead." From 4d2475f5fe723e7ed38ee315314202dc5c30ebde Mon Sep 17 00:00:00 2001 From: lisicky Date: Mon, 16 May 2022 13:32:08 +0400 Subject: [PATCH 24/26] update constructor comment --- rust/pkg/cardano_serialization_lib.js.flow | 3 +++ rust/src/address.rs | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index bf17ecdf..fb516d2d 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -3261,6 +3261,9 @@ declare export class Pointer { free(): void; /** + * !!! DEPRECATED !!! + * This constructor uses outdated slot number format for the ttl value, tx_index and cert_index. + * Use `.new_pointer` instead * @param {number} slot * @param {number} tx_index * @param {number} cert_index diff --git a/rust/src/address.rs b/rust/src/address.rs index e4a1dfb6..54d40881 100644 --- a/rust/src/address.rs +++ b/rust/src/address.rs @@ -619,6 +619,13 @@ pub struct Pointer { #[wasm_bindgen] impl Pointer { + /// !!! DEPRECATED !!! + /// This constructor uses outdated slot number format for the ttl value, tx_index and cert_index. + /// Use `.new_pointer` instead + #[deprecated( + since = "10.1.0", + note = "Underlying value capacity of ttl (BigNum u64) bigger then Slot32. Use new_pointer instead." + )] pub fn new(slot: Slot32, tx_index: TransactionIndex, cert_index: CertificateIndex) -> Self { Self { slot: slot.into(), From 4d436951f02bffd660942b734b53875e54cb514d Mon Sep 17 00:00:00 2001 From: lisicky Date: Mon, 16 May 2022 13:42:52 +0400 Subject: [PATCH 25/26] update constructor comment --- rust/pkg/cardano_serialization_lib.js.flow | 6 ++++-- rust/src/lib.rs | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/rust/pkg/cardano_serialization_lib.js.flow b/rust/pkg/cardano_serialization_lib.js.flow index fb516d2d..bd79a739 100644 --- a/rust/pkg/cardano_serialization_lib.js.flow +++ b/rust/pkg/cardano_serialization_lib.js.flow @@ -1959,7 +1959,8 @@ declare export class HeaderBody { /** * !!! DEPRECATED !!! - * Returns a new HeaderBody. + * This constructor uses outdated slot number format. + * Use `.new_headerbody` instead * @param {number} block_number * @param {number} slot * @param {BlockHash | void} prev_hash @@ -4854,7 +4855,8 @@ declare export class TimelockExpiry { /** * !!! DEPRECATED !!! - * Returns a new TimelockExpiry from Slot32 (u32) value. + * This constructor uses outdated slot number format. + * Use `.new_timelockexpiry` instead * @param {number} slot * @returns {TimelockExpiry} */ diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 571ca895..cbc9fc50 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1717,7 +1717,8 @@ impl TimelockExpiry { } /// !!! DEPRECATED !!! - /// Returns a new TimelockExpiry from Slot32 (u32) value. + /// This constructor uses outdated slot number format. + /// Use `.new_timelockexpiry` instead #[deprecated( since = "10.1.0", note = "Underlying value capacity (BigNum u64) bigger then Slot32. Use new_bignum instead." @@ -2601,7 +2602,8 @@ impl HeaderBody { } /// !!! DEPRECATED !!! - /// Returns a new HeaderBody. + /// This constructor uses outdated slot number format. + /// Use `.new_headerbody` instead #[deprecated( since = "10.1.0", note = "Underlying value capacity of slot (BigNum u64) bigger then Slot32. Use new_bignum instead." From e42b934759e1d515a2dfe9e230f205d0378dc15f Mon Sep 17 00:00:00 2001 From: lisicky Date: Mon, 16 May 2022 17:27:42 +0400 Subject: [PATCH 26/26] remove using old constructors --- rust/src/utils.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rust/src/utils.rs b/rust/src/utils.rs index 7aa57a3b..1ea74e8a 100644 --- a/rust/src/utils.rs +++ b/rust/src/utils.rs @@ -241,6 +241,12 @@ impl TryFrom for u32 { } } +impl From for BigNum { + fn from(value: u64) -> Self { + return BigNum(value) + } +} + impl From for BigNum { fn from(value: u32) -> Self { return BigNum(value.into()) @@ -1288,9 +1294,9 @@ fn encode_template_to_native_script( serde_json::Value::Object(map) if map.contains_key("active_from") => { if let serde_json::Value::Number(active_from) = map.get("active_from").unwrap() { if let Some(n) = active_from.as_u64() { - let slot: u32 = n as u32; + let slot: SlotBigNum = n.into(); - let time_lock_start = TimelockStart::new(slot); + let time_lock_start = TimelockStart::new_timelockstart(&slot); Ok(NativeScript::new_timelock_start(&time_lock_start)) } else { @@ -1305,9 +1311,9 @@ fn encode_template_to_native_script( serde_json::Value::Object(map) if map.contains_key("active_until") => { if let serde_json::Value::Number(active_until) = map.get("active_until").unwrap() { if let Some(n) = active_until.as_u64() { - let slot: u32 = n as u32; + let slot: SlotBigNum = n.into(); - let time_lock_expiry = TimelockExpiry::new(slot); + let time_lock_expiry = TimelockExpiry::new_timelockexpiry(&slot); Ok(NativeScript::new_timelock_expiry(&time_lock_expiry)) } else {