-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ethexe/rpc): implement rpc methods (#4299)
Co-authored-by: Dmitry Novikov <[email protected]>
- Loading branch information
1 parent
386b3b0
commit 08e0da7
Showing
24 changed files
with
403 additions
and
105 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,73 @@ | ||
// This file is part of Gear. | ||
// | ||
// Copyright (C) 2024 Gear Technologies Inc. | ||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
use crate::{common::block_header_at_or_latest, errors}; | ||
use ethexe_common::BlockRequestEvent; | ||
use ethexe_db::{BlockHeader, BlockMetaStorage, Database}; | ||
use gprimitives::H256; | ||
use jsonrpsee::{ | ||
core::{async_trait, RpcResult}, | ||
proc_macros::rpc, | ||
}; | ||
use std::collections::VecDeque; | ||
|
||
#[rpc(server)] | ||
pub trait Block { | ||
#[method(name = "block_header")] | ||
async fn block_header(&self, hash: Option<H256>) -> RpcResult<(H256, BlockHeader)>; | ||
|
||
#[method(name = "block_commitmentQueue")] | ||
async fn block_commitment_queue(&self, hash: Option<H256>) -> RpcResult<VecDeque<H256>>; | ||
|
||
#[method(name = "block_events")] | ||
async fn block_events(&self, block_hash: Option<H256>) -> RpcResult<Vec<BlockRequestEvent>>; | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct BlockApi { | ||
db: Database, | ||
} | ||
|
||
impl BlockApi { | ||
pub fn new(db: Database) -> Self { | ||
Self { db } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl BlockServer for BlockApi { | ||
async fn block_header(&self, hash: Option<H256>) -> RpcResult<(H256, BlockHeader)> { | ||
block_header_at_or_latest(&self.db, hash) | ||
} | ||
|
||
async fn block_commitment_queue(&self, hash: Option<H256>) -> RpcResult<VecDeque<H256>> { | ||
let block_hash = block_header_at_or_latest(&self.db, hash)?.0; | ||
|
||
self.db | ||
.block_commitment_queue(block_hash) | ||
.ok_or_else(|| errors::db("Block commitment queue wasn't found")) | ||
} | ||
|
||
async fn block_events(&self, hash: Option<H256>) -> RpcResult<Vec<BlockRequestEvent>> { | ||
let block_hash = block_header_at_or_latest(&self.db, hash)?.0; | ||
|
||
self.db | ||
.block_events(block_hash) | ||
.ok_or_else(|| errors::db("Block events weren't found")) | ||
} | ||
} |
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,23 @@ | ||
// This file is part of Gear. | ||
// | ||
// Copyright (C) 2024 Gear Technologies Inc. | ||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
mod block; | ||
mod program; | ||
|
||
pub use block::{BlockApi, BlockServer}; | ||
pub use program::{ProgramApi, ProgramServer}; |
Oops, something went wrong.