Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
feat: add rpc traceBlock
Browse files Browse the repository at this point in the history
clippy

taplo

add column to backend db

add l1_handler_paid_fee field to madara Backend

chore(client/db): remove unused generic type from db structs

tmp

tace block ok

fix class hash
  • Loading branch information
tdelabro committed Feb 8, 2024
1 parent 7900c0b commit 7b00b37
Show file tree
Hide file tree
Showing 30 changed files with 900 additions and 256 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Next release

- feat(rpc): added `get_state_update` real values from DA db
- feat(rpc/trace_api): add `trace_block_transaction`
- chore(runtime_api): remove unused `filter_extrinsic`

## v0.7.0

Expand Down Expand Up @@ -76,7 +78,7 @@
- feat: fixing getNonce Rpc Call and adding a new test
- refactor: use Zaun crate for Starknet core contract bindings
- refactor: use Anvil sandbox from Zaun crate
- feat(rpc) : estimateMessageFee RPC call implementation
- feat(rpc): estimateMessageFee RPC call implementation

## v0.6.0

Expand Down
54 changes: 29 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions crates/client/db/src/da_db.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::marker::PhantomData;
use std::sync::Arc;

// Substrate
use parity_scale_codec::{Decode, Encode};
use sp_database::Database;
use sp_runtime::traits::Block as BlockT;
// Starknet
use starknet_api::block::BlockHash;
use starknet_api::hash::StarkFelt;
Expand All @@ -14,17 +12,16 @@ use uuid::Uuid;
use crate::{DbError, DbHash};

// The fact db stores DA facts that need to be written to L1
pub struct DaDb<B: BlockT> {
pub struct DaDb {
pub(crate) db: Arc<dyn Database<DbHash>>,
pub(crate) _marker: PhantomData<B>,
}

// TODO: purge old cairo job keys
impl<B: BlockT> DaDb<B> {
pub fn state_diff(&self, block_hash: &BlockHash) -> Result<ThinStateDiff, String> {
impl DaDb {
pub fn state_diff(&self, block_hash: &BlockHash) -> Result<ThinStateDiff, DbError> {
match self.db.get(crate::columns::DA, block_hash.0.bytes()) {
Some(raw) => Ok(ThinStateDiff::decode(&mut &raw[..]).map_err(|e| format!("{:?}", e))?),
None => Err(String::from("can't write state diff")),
Some(raw) => Ok(ThinStateDiff::decode(&mut &raw[..])?),
None => Err(DbError::ValueNotInitialized(crate::columns::DA, block_hash.to_string())),
}
}

Expand Down
39 changes: 39 additions & 0 deletions crates/client/db/src/l1_handler_tx_fee.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use std::sync::Arc;

use parity_scale_codec::Encode;
use sp_database::Database;
use starknet_api::hash::StarkFelt;
use starknet_api::transaction::Fee;

use crate::{DbError, DbHash};

pub struct L1HandlerTxFeeDb {
pub(crate) db: Arc<dyn Database<DbHash>>,
}

impl L1HandlerTxFeeDb {
/// Store the fee paid on l1 for a specific L1Handler transaction
pub fn store_fee_paid_for_l1_handler_tx(&self, tx_hash: StarkFelt, fee: Fee) -> Result<(), DbError> {
let mut transaction = sp_database::Transaction::new();

transaction.set(crate::columns::L1_HANDLER_PAID_FEE, &tx_hash.encode(), &fee.0.to_le_bytes());

self.db.commit(transaction)?;

Ok(())
}

/// Return the stored fee paid on l1 for a specific L1Handler transaction
pub fn get_fee_paid_for_l1_handler_tx(&self, tx_hash: StarkFelt) -> Result<Fee, DbError> {
if let Some(bytes) = self.db.get(crate::columns::L1_HANDLER_PAID_FEE, &tx_hash.encode()) {
let mut buff = [0u8; 16];

buff.copy_from_slice(&bytes);
let fee = u128::from_le_bytes(buff);

Ok(Fee(fee))
} else {
Err(DbError::ValueNotInitialized(crate::columns::L1_HANDLER_PAID_FEE, tx_hash.to_string()))
}
}
}
Loading

0 comments on commit 7b00b37

Please sign in to comment.