-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract execute_from_outside and upgrade (#799)
* Refactor execute_from_outside * Extract upgrade
- Loading branch information
Showing
24 changed files
with
293 additions
and
278 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
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,61 @@ | ||
use starknet::{ | ||
accounts::ConnectedAccount, | ||
core::types::{Call, InvokeTransactionResult}, | ||
signers::SigningKey, | ||
}; | ||
|
||
use crate::{ | ||
abigen::controller::OutsideExecution, | ||
account::outside_execution::{OutsideExecutionAccount, OutsideExecutionCaller}, | ||
controller::Controller, | ||
errors::ControllerError, | ||
provider::CartridgeProvider, | ||
utils::time::get_current_timestamp, | ||
Backend, | ||
}; | ||
|
||
#[cfg(test)] | ||
#[path = "execute_from_outside_test.rs"] | ||
mod execute_from_outside_test; | ||
|
||
impl<P, B> Controller<P, B> | ||
where | ||
P: CartridgeProvider + Send + Sync + Clone, | ||
B: Backend + Clone, | ||
{ | ||
async fn execute_from_outside_raw( | ||
&self, | ||
outside_execution: OutsideExecution, | ||
) -> Result<InvokeTransactionResult, ControllerError> { | ||
let signed = self | ||
.sign_outside_execution(outside_execution.clone()) | ||
.await?; | ||
|
||
let res = self | ||
.provider() | ||
.add_execute_outside_transaction(outside_execution, self.address, signed.signature) | ||
.await | ||
.map_err(ControllerError::PaymasterError)?; | ||
|
||
Ok(InvokeTransactionResult { | ||
transaction_hash: res.transaction_hash, | ||
}) | ||
} | ||
|
||
pub async fn execute_from_outside( | ||
&self, | ||
calls: Vec<Call>, | ||
) -> Result<InvokeTransactionResult, ControllerError> { | ||
let now = get_current_timestamp(); | ||
|
||
let outside_execution = OutsideExecution { | ||
caller: OutsideExecutionCaller::Any.into(), | ||
execute_after: 0, | ||
execute_before: now + 600, | ||
calls: calls.into_iter().map(|call| call.into()).collect(), | ||
nonce: SigningKey::from_random().secret_scalar(), | ||
}; | ||
|
||
self.execute_from_outside_raw(outside_execution).await | ||
} | ||
} |
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.