-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(katana-rpc): isolate dev JSON RPC API from
katana
namespace (
#1544) * feat: isolate dev JSON RPC API from katana impl * feat: fix the changes * feat: remove the duplicate endpoint in katana
- Loading branch information
1 parent
68e81f6
commit ca3b018
Showing
7 changed files
with
92 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use jsonrpsee::core::RpcResult; | ||
use jsonrpsee::proc_macros::rpc; | ||
use katana_primitives::FieldElement; | ||
|
||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "dev"))] | ||
#[cfg_attr(feature = "client", rpc(client, server, namespace = "dev"))] | ||
pub trait DevApi { | ||
#[method(name = "generateBlock")] | ||
async fn generate_block(&self) -> RpcResult<()>; | ||
|
||
#[method(name = "nextBlockTimestamp")] | ||
async fn next_block_timestamp(&self) -> RpcResult<()>; | ||
|
||
#[method(name = "setNextBlockTimestamp")] | ||
async fn set_next_block_timestamp(&self, timestamp: u64) -> RpcResult<()>; | ||
|
||
#[method(name = "increaseNextBlockTimestamp")] | ||
async fn increase_next_block_timestamp(&self, timestamp: u64) -> RpcResult<()>; | ||
|
||
#[method(name = "setStorageAt")] | ||
async fn set_storage_at( | ||
&self, | ||
contract_address: FieldElement, | ||
key: FieldElement, | ||
value: FieldElement, | ||
) -> RpcResult<()>; | ||
} |
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,31 +1,10 @@ | ||
use jsonrpsee::core::RpcResult; | ||
use jsonrpsee::proc_macros::rpc; | ||
use katana_primitives::FieldElement; | ||
use katana_rpc_types::account::Account; | ||
|
||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "katana"))] | ||
#[cfg_attr(feature = "client", rpc(client, server, namespace = "katana"))] | ||
pub trait KatanaApi { | ||
#[method(name = "generateBlock")] | ||
async fn generate_block(&self) -> RpcResult<()>; | ||
|
||
#[method(name = "nextBlockTimestamp")] | ||
async fn next_block_timestamp(&self) -> RpcResult<u64>; | ||
|
||
#[method(name = "setNextBlockTimestamp")] | ||
async fn set_next_block_timestamp(&self, timestamp: u64) -> RpcResult<()>; | ||
|
||
#[method(name = "increaseNextBlockTimestamp")] | ||
async fn increase_next_block_timestamp(&self, timestamp: u64) -> RpcResult<()>; | ||
|
||
#[method(name = "predeployedAccounts")] | ||
async fn predeployed_accounts(&self) -> RpcResult<Vec<Account>>; | ||
|
||
#[method(name = "setStorageAt")] | ||
async fn set_storage_at( | ||
&self, | ||
contract_address: FieldElement, | ||
key: FieldElement, | ||
value: FieldElement, | ||
) -> RpcResult<()>; | ||
} |
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,55 @@ | ||
use std::sync::Arc; | ||
|
||
use jsonrpsee::core::{async_trait, Error}; | ||
use katana_core::sequencer::KatanaSequencer; | ||
use katana_primitives::FieldElement; | ||
use katana_rpc_api::dev::DevApiServer; | ||
use katana_rpc_types::error::katana::KatanaApiError; | ||
|
||
pub struct DevApi { | ||
sequencer: Arc<KatanaSequencer>, | ||
} | ||
|
||
impl DevApi { | ||
pub fn new(sequencer: Arc<KatanaSequencer>) -> Self { | ||
Self { sequencer } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl DevApiServer for DevApi { | ||
async fn generate_block(&self) -> Result<(), Error> { | ||
self.sequencer.block_producer().force_mine(); | ||
Ok(()) | ||
} | ||
|
||
async fn next_block_timestamp(&self) -> Result<(), Error> { | ||
// Ok(self.sequencer.backend().env.read().block.block_timestamp.0) | ||
Ok(()) | ||
} | ||
|
||
async fn set_next_block_timestamp(&self, timestamp: u64) -> Result<(), Error> { | ||
self.sequencer | ||
.set_next_block_timestamp(timestamp) | ||
.map_err(|_| Error::from(KatanaApiError::FailedToChangeNextBlockTimestamp)) | ||
} | ||
|
||
async fn increase_next_block_timestamp(&self, timestamp: u64) -> Result<(), Error> { | ||
self.sequencer | ||
.increase_next_block_timestamp(timestamp) | ||
.map_err(|_| Error::from(KatanaApiError::FailedToChangeNextBlockTimestamp)) | ||
} | ||
|
||
async fn set_storage_at( | ||
&self, | ||
_contract_address: FieldElement, | ||
_key: FieldElement, | ||
_value: FieldElement, | ||
) -> Result<(), Error> { | ||
// self.sequencer | ||
// .set_storage_at(contract_address.into(), key, value) | ||
// .await | ||
// .map_err(|_| Error::from(KatanaApiError::FailedToUpdateStorage)) | ||
Ok(()) | ||
} | ||
} |
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