Skip to content

Commit

Permalink
prepare pr
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Mar 26, 2024
1 parent 8ee238c commit 6a689e5
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 71 deletions.
3 changes: 2 additions & 1 deletion bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ async fn main() -> anyhow::Result<()> {
sqlx::migrate!("../../crates/torii/migrations").run(&pool).await?;

let provider: Arc<_> = JsonRpcClient::new(HttpTransport::new(args.rpc.clone())).into();
let katana_provider: Arc<_> = KatanaClient::new(torii_core::provider::http::HttpTransport::new(args.rpc.clone())).into();
let katana_provider: Arc<_> =
KatanaClient::new(torii_core::provider::http::HttpTransport::new(args.rpc.clone())).into();

// Get world address
let world = WorldContractReader::new(args.world_address, &provider);
Expand Down
5 changes: 4 additions & 1 deletion crates/katana/primitives/src/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use derive_more::{AsRef, Deref, From};
use ethers::types::H256;
use starknet::core::types::{DataAvailabilityMode, DeployAccountTransactionV1, DeployAccountTransactionV3, ResourceBoundsMapping};
use starknet::core::types::{
DataAvailabilityMode, DeployAccountTransactionV1, DeployAccountTransactionV3,
ResourceBoundsMapping,
};

use crate::chain::ChainId;
use crate::contract::{
Expand Down
6 changes: 3 additions & 3 deletions crates/katana/rpc/rpc-types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use katana_primitives::conversion::rpc::{
};
use katana_primitives::transaction::{
DeclareTx, DeclareTxV1, DeclareTxV2, DeclareTxV3, DeclareTxWithClass, DeployAccountTx,
DeployAccountTxV1, DeployAccountTxV3, InvokeTx, InvokeTxV1, InvokeTxV3, TxHash, TxWithHash as InternalTxWithHash, Tx as InternalTx
DeployAccountTxV1, DeployAccountTxV3, InvokeTx, InvokeTxV1, InvokeTxV3, Tx as InternalTx,
TxHash, TxWithHash as InternalTxWithHash,
};
use katana_primitives::FieldElement;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -491,11 +492,10 @@ impl From<InternalTxWithHash> for Tx {
}
};

Tx(tx)
Tx(tx)
}
}


#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TransactionsPageCursor {
pub block_number: u64,
Expand Down
4 changes: 2 additions & 2 deletions crates/katana/rpc/rpc/tests/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async fn test_get_transactions() {

assert!(response.transactions.len() == 1);
assert!(
response.transactions[0].0 .0.transaction_hash().clone()
response.transactions[0].0.0.transaction_hash().clone()
== deploy_txn_future.transaction_hash
);
assert!(response.cursor.block_number == 3);
Expand Down Expand Up @@ -210,7 +210,7 @@ async fn test_get_transactions_with_instant_mining() {

assert!(response.transactions.len() == 1);
assert!(
response.transactions[0].0 .0.transaction_hash().clone()
response.transactions[0].0.0.transaction_hash().clone()
== deploy_txn_future.transaction_hash
);
assert!(response.cursor.block_number == 3);
Expand Down
18 changes: 4 additions & 14 deletions crates/torii/core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ use tokio::time::sleep;
use tracing::{error, info, trace, warn};

use crate::processors::{BlockProcessor, EventProcessor, TransactionProcessor};
use crate::sql::Sql;

use crate::provider::provider::{KatanaProvider, TransactionsPageCursor};
use crate::sql::Sql;

pub struct Processors<P: Provider + Sync> {
pub block: Vec<Box<dyn BlockProcessor<P>>>,
Expand Down Expand Up @@ -188,12 +187,8 @@ impl<P: KatanaProvider + Sync, R: Provider + Sync> Engine<P, R> {
self.db.set_head(block_number);

for (transaction, receipt) in transactions.transactions {
self.process_transaction_and_receipt(
&transaction,
Some(receipt),
block_number,
)
.await?;
self.process_transaction_and_receipt(&transaction, Some(receipt), block_number)
.await?;
}
}

Expand Down Expand Up @@ -224,12 +219,7 @@ impl<P: KatanaProvider + Sync, R: Provider + Sync> Engine<P, R> {
}

let transaction = self.provider.get_transaction_by_hash(event.transaction_hash).await?;
self.process_transaction_and_receipt(
&transaction,
None,
block_number,
)
.await?;
self.process_transaction_and_receipt(&transaction, None, block_number).await?;

Ok(())
}
Expand Down
7 changes: 1 addition & 6 deletions crates/torii/core/src/processors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ where
#[async_trait]
pub trait BlockProcessor<P: Provider + Sync> {
fn get_block_number(&self) -> String;
async fn process(
&self,
db: &mut Sql,
provider: &P,
block_number: u64,
) -> Result<(), Error>;
async fn process(&self, db: &mut Sql, provider: &P, block_number: u64) -> Result<(), Error>;
}

#[async_trait]
Expand Down
16 changes: 4 additions & 12 deletions crates/torii/core/src/provider/http.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use async_trait::async_trait;
use log::trace;
use reqwest::{Client, Url};
use serde::{de::DeserializeOwned, Serialize};
use serde::de::DeserializeOwned;
use serde::Serialize;

use super::{JsonRpcMethod, JsonRpcResponse, JsonRpcTransport};

Expand Down Expand Up @@ -32,10 +33,7 @@ impl HttpTransport {
}

pub fn new_with_client(url: impl Into<Url>, client: Client) -> Self {
Self {
client,
url: url.into(),
}
Self { client, url: url.into() }
}
}

Expand All @@ -53,12 +51,7 @@ impl JsonRpcTransport for HttpTransport {
P: Serialize + Send,
R: DeserializeOwned,
{
let request_body = JsonRpcRequest {
id: 1,
jsonrpc: "2.0",
method,
params,
};
let request_body = JsonRpcRequest { id: 1, jsonrpc: "2.0", method, params };

let request_body = serde_json::to_string(&request_body).map_err(Self::Error::Json)?;
trace!("Sending request via JSON-RPC: {}", request_body);
Expand All @@ -75,7 +68,6 @@ impl JsonRpcTransport for HttpTransport {
let response_body = response.text().await.map_err(Self::Error::Reqwest)?;
trace!("Response from JSON-RPC: {}", response_body);


let parsed_response = serde_json::from_str(&response_body).map_err(Self::Error::Json)?;

Ok(parsed_response)
Expand Down
45 changes: 22 additions & 23 deletions crates/torii/core/src/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,31 @@ pub mod http;
pub mod provider;
pub mod transport;

use std::{any::Any, error::Error, fmt::Display};
use std::any::Any;
use std::error::Error;
use std::fmt::Display;

use async_trait::async_trait;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use provider::{KatanaProvider, ProviderError, ProviderImplError};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use starknet::core::{
serde::unsigned_field_element::UfeHex,
types::{
requests::*, BlockHashAndNumber, BlockId, BroadcastedDeclareTransaction,
BroadcastedDeployAccountTransaction, BroadcastedInvokeTransaction, BroadcastedTransaction,
ContractClass, ContractErrorData, DeclareTransactionResult, DeployAccountTransactionResult,
EventFilter, EventFilterWithPage, EventsPage, FeeEstimate, FieldElement, FunctionCall,
InvokeTransactionResult, MaybePendingBlockWithTxHashes, MaybePendingBlockWithTxs,
MaybePendingStateUpdate, MaybePendingTransactionReceipt, MsgFromL1,
NoTraceAvailableErrorData, ResultPageRequest, SimulatedTransaction, SimulationFlag,
SimulationFlagForEstimateFee, StarknetError, SyncStatusType, Transaction,
TransactionExecutionErrorData, TransactionStatus, TransactionTrace,
TransactionTraceWithHash,
},
use starknet::core::serde::unsigned_field_element::UfeHex;
use starknet::core::types::requests::*;
use starknet::core::types::{
BlockHashAndNumber, BlockId, BroadcastedDeclareTransaction,
BroadcastedDeployAccountTransaction, BroadcastedInvokeTransaction, BroadcastedTransaction,
ContractClass, ContractErrorData, DeclareTransactionResult, DeployAccountTransactionResult,
EventFilter, EventFilterWithPage, EventsPage, FeeEstimate, FieldElement, FunctionCall,
InvokeTransactionResult, MaybePendingBlockWithTxHashes, MaybePendingBlockWithTxs,
MaybePendingStateUpdate, MaybePendingTransactionReceipt, MsgFromL1, NoTraceAvailableErrorData,
ResultPageRequest, SimulatedTransaction, SimulationFlag, SimulationFlagForEstimateFee,
StarknetError, SyncStatusType, Transaction, TransactionExecutionErrorData, TransactionStatus,
TransactionTrace, TransactionTraceWithHash,
};

use provider::{KatanaProvider, ProviderError, ProviderImplError};

use self::{
provider::{GetTransactionsRequest, TransactionsPage, TransactionsPageCursor},
transport::JsonRpcTransport,
};
use self::provider::{GetTransactionsRequest, TransactionsPage, TransactionsPageCursor};
use self::transport::JsonRpcTransport;

#[derive(Debug)]
pub struct KatanaClient<T> {
Expand Down Expand Up @@ -375,7 +373,8 @@ where
.await
}

/// Get the contract class hash in the given block for the contract deployed at the given address
/// Get the contract class hash in the given block for the contract deployed at the given
/// address
async fn get_class_hash_at<B, A>(
&self,
block_id: B,
Expand Down
8 changes: 6 additions & 2 deletions crates/torii/core/src/provider/provider.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use std::any::Any;
use std::error::Error;
use std::fmt::Debug;

use async_trait::async_trait;
use auto_impl::auto_impl;
use serde::{Deserialize, Serialize};
Expand All @@ -12,7 +16,6 @@ use starknet::core::types::{
SimulationFlagForEstimateFee, StarknetError, SyncStatusType, Transaction, TransactionStatus,
TransactionTrace, TransactionTraceWithHash,
};
use std::{any::Any, error::Error, fmt::Debug};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct GetTransactionsRequest {
Expand Down Expand Up @@ -117,7 +120,8 @@ pub trait KatanaProvider {
B: AsRef<BlockId> + Send + Sync,
H: AsRef<FieldElement> + Send + Sync;

/// Get the contract class hash in the given block for the contract deployed at the given address
/// Get the contract class hash in the given block for the contract deployed at the given
/// address
async fn get_class_hash_at<B, A>(
&self,
block_id: B,
Expand Down
8 changes: 5 additions & 3 deletions crates/torii/core/src/provider/transport.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::error::Error;

use async_trait::async_trait;
use auto_impl::auto_impl;
use serde::{de::DeserializeOwned, Serialize};
use std::error::Error;
use serde::de::DeserializeOwned;
use serde::Serialize;

use super::{JsonRpcMethod, JsonRpcResponse};

Expand All @@ -19,4 +21,4 @@ pub trait JsonRpcTransport {
where
P: Serialize + Send + Sync,
R: DeserializeOwned;
}
}
4 changes: 1 addition & 3 deletions crates/torii/core/src/sql_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ async fn test_load_from_remote() {
let _ = bootstrap_engine(
world,
db.clone(),
&KatanaClient::new(crate::provider::http::HttpTransport::new(
sequencer.url(),
)),
&KatanaClient::new(crate::provider::http::HttpTransport::new(sequencer.url())),
migration,
sequencer,
)
Expand Down
3 changes: 2 additions & 1 deletion crates/torii/graphql/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ pub async fn spinup_types_test() -> Result<SqlitePool> {

TransactionWaiter::new(transaction_hash, &provider).await?;

let katana_provider = KatanaClient::new(torii_core::provider::http::HttpTransport::new(sequencer.url()));
let katana_provider =
KatanaClient::new(torii_core::provider::http::HttpTransport::new(sequencer.url()));
let (shutdown_tx, _) = broadcast::channel(1);
let mut engine = Engine::new(
world,
Expand Down

0 comments on commit 6a689e5

Please sign in to comment.