-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pad addresses to correct length (#2486)
<!-- Reference any GitHub issues resolved by this PR --> Closes #2248 Closes #2424 ## Introduced changes <!-- A brief description of the changes --> - Addresses used in `sncast account create`, `sncast declare` and `sncast deploy` are now correctly padded to 66 (64 after `0x`) characters length. ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md` --------- Co-authored-by: ddoktorski <[email protected]>
- Loading branch information
1 parent
c8331be
commit 84167fa
Showing
22 changed files
with
232 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use crate::FromConv; | ||
use cairo_serde_macros::CairoSerialize; | ||
use conversions::from_thru_felt252; | ||
use serde::{Deserialize, Serialize, Serializer}; | ||
use starknet_api::core::{ClassHash, ContractAddress}; | ||
use starknet_types_core::felt::Felt as Felt252; | ||
use std::fmt; | ||
use std::fmt::{Formatter, LowerHex}; | ||
|
||
#[derive(Clone, Copy, Debug, PartialEq, Deserialize, CairoSerialize)] | ||
pub struct PaddedFelt(pub Felt252); | ||
|
||
impl FromConv<Felt252> for PaddedFelt { | ||
fn from_(value: Felt252) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl Serialize for PaddedFelt { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
serializer.serialize_str(&format!("{:#064x}", &self.0)) | ||
} | ||
} | ||
|
||
impl LowerHex for PaddedFelt { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { | ||
fmt::LowerHex::fmt(&self.0, f) | ||
} | ||
} | ||
|
||
from_thru_felt252!(ClassHash, PaddedFelt); | ||
from_thru_felt252!(ContractAddress, PaddedFelt); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ mod entrypoint_selector; | |
mod felt252; | ||
mod field_elements; | ||
mod nonce; | ||
mod padded_felt; | ||
mod string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use conversions::padded_felt::PaddedFelt; | ||
use conversions::{FromConv, IntoConv}; | ||
use starknet_api::core::{ClassHash, ContractAddress}; | ||
use starknet_types_core::felt::Felt as Felt252; | ||
|
||
#[test] | ||
fn test_padded_felt_conversions_happy_case() { | ||
let felt = Felt252::from_bytes_be(&[1u8; 32]); | ||
let padded_felt = PaddedFelt(felt); | ||
|
||
assert_eq!(padded_felt, ContractAddress::from_(padded_felt).into_()); | ||
assert_eq!(padded_felt, ClassHash::from_(padded_felt).into_()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.