-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added AccountProcedure and TryFrom [Felt; 8]
- Loading branch information
Showing
5 changed files
with
69 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::AccountError; | ||
|
||
use super::{Digest, Felt}; | ||
|
||
pub struct AccountProcedure { | ||
mast_root: Digest, | ||
storage_offset: u16, | ||
} | ||
|
||
impl AccountProcedure { | ||
// CONSTANTS | ||
// -------------------------------------------------------------------------------------------- | ||
|
||
/// The number of elements needed to represent an [AccountProcedure] | ||
pub const NUM_ELEMENTS_PER_PROC: usize = 8; | ||
|
||
/// Returns a reference to the procedure's mast_root | ||
pub fn mast_root(&self) -> &Digest { | ||
&self.mast_root | ||
} | ||
|
||
/// Returns a reference to the procedure's storage_offset | ||
pub fn storage_offset(&self) -> u16 { | ||
self.storage_offset | ||
} | ||
} | ||
|
||
impl TryFrom<[Felt; 8]> for AccountProcedure { | ||
type Error = AccountError; | ||
|
||
fn try_from(value: [Felt; 8]) -> Result<Self, Self::Error> { | ||
let mast_root = Digest::from(<[Felt; 4]>::try_from(&value[0..4]).unwrap()); | ||
let storage_offset = u16::try_from(value[4].inner()) | ||
.map_err(|_| AccountError::AccountCodeProcedureInvalidStorageOffset)?; | ||
|
||
Ok(Self { mast_root, storage_offset }) | ||
} | ||
} |
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