-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
426 additions
and
539 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use crate::runtime::Runtime; | ||
use sov_default_stf::SequencerOutcome; | ||
use sov_modules_api::{ | ||
hooks::{ApplyBlobHooks, TxHooks}, | ||
transaction::Transaction, | ||
Context, Spec, | ||
}; | ||
use sov_state::WorkingSet; | ||
|
||
impl<C: Context> TxHooks for Runtime<C> { | ||
type Context = C; | ||
|
||
fn pre_dispatch_tx_hook( | ||
&self, | ||
tx: Transaction<Self::Context>, | ||
working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>, | ||
) -> anyhow::Result<<Self::Context as Spec>::Address> { | ||
self.accounts.pre_dispatch_tx_hook(tx, working_set) | ||
} | ||
|
||
fn post_dispatch_tx_hook( | ||
&self, | ||
tx: &Transaction<Self::Context>, | ||
working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>, | ||
) -> anyhow::Result<()> { | ||
self.accounts.post_dispatch_tx_hook(tx, working_set) | ||
} | ||
} | ||
|
||
impl<C: Context> ApplyBlobHooks for Runtime<C> { | ||
type Context = C; | ||
type BlobResult = SequencerOutcome; | ||
|
||
fn begin_blob_hook( | ||
&self, | ||
sequencer: &[u8], | ||
raw_blob: &[u8], | ||
working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>, | ||
) -> anyhow::Result<()> { | ||
self.sequencer | ||
.begin_blob_hook(sequencer, raw_blob, working_set) | ||
} | ||
|
||
fn end_blob_hook( | ||
&self, | ||
result: Self::BlobResult, | ||
working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>, | ||
) -> anyhow::Result<()> { | ||
let reward = match result { | ||
SequencerOutcome::Rewarded(r) => r, | ||
SequencerOutcome::Slashed(_) => 0, | ||
SequencerOutcome::Ignored => 0, | ||
}; | ||
self.sequencer.end_blob_hook(reward, working_set) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,29 +1,10 @@ | ||
pub mod app; | ||
#[cfg(feature = "native")] | ||
pub mod genesis_config; | ||
pub mod hooks_impl; | ||
#[cfg(feature = "native")] | ||
pub mod runner_config; | ||
pub mod runtime; | ||
#[cfg(test)] | ||
pub mod tests; | ||
pub mod tx_hooks_impl; | ||
pub mod tx_verifier_impl; | ||
|
||
#[cfg(feature = "native")] | ||
use sov_modules_api::{ | ||
default_context::DefaultContext, | ||
default_signature::{private_key::DefaultPrivateKey, DefaultSignature}, | ||
Hasher, Spec, | ||
}; | ||
|
||
pub use sov_state::ArrayWitness; | ||
pub use tx_verifier_impl::Transaction; | ||
|
||
#[cfg(feature = "native")] | ||
pub fn sign_tx(priv_key: &DefaultPrivateKey, message: &[u8], nonce: u64) -> DefaultSignature { | ||
let mut hasher = <DefaultContext as Spec>::Hasher::new(); | ||
hasher.update(message); | ||
hasher.update(&nonce.to_le_bytes()); | ||
let msg_hash = hasher.finalize(); | ||
priv_key.sign(msg_hash) | ||
} |
Oops, something went wrong.