-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(server): refactoring tanour server (#20)
* refactor(server): refactoring tanour server * wip: updating tanour server * adding read_page and write_page apis * exported functions argument as byte slice * executing contract from server * installing capnp for github action * updating ChangeLog
- Loading branch information
Showing
20 changed files
with
233 additions
and
371 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[workspace] | ||
members = [ | ||
"tanour", | ||
# "tanour-server", | ||
"tanour-server", | ||
] | ||
exclude = ["test-contract"] |
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,6 +1,6 @@ | ||
[package] | ||
name = "tanour-server" | ||
version = "0.1.0" | ||
version = "0.2.0" | ||
authors = ["Pactus blockchain <[email protected]>"] | ||
edition = "2021" | ||
|
||
|
@@ -14,13 +14,19 @@ path = "src/main.rs" | |
capnpc = { git = "https://github.com/capnproto/capnproto-rust" } | ||
|
||
[dependencies] | ||
capnp = { git = "https://github.com/capnproto/capnproto-rust" } | ||
capnp = { git = "https://github.com/capnproto/capnproto-rust" } | ||
capnp-rpc = { git = "https://github.com/capnproto/capnproto-rust" } | ||
futures = "0.3.0" | ||
tokio = { version = "0.2.0", features = ["time", "sync", "rt-util", "rt-core", "net", "macros"]} | ||
tokio = { version = "0.2.0", features = [ | ||
"time", | ||
"sync", | ||
"rt-util", | ||
"rt-core", | ||
"net", | ||
"macros", | ||
] } | ||
tokio-util = { version = "0.3.0", features = ["compat"] } | ||
tanour = { path = "../tanour" } | ||
primitive-types = "0.7.2" | ||
tanour = { version = "0.2.0" } | ||
async-std = "1.5.0" | ||
log = "0.4" | ||
simple_logger = "1.4.0" |
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,76 @@ | ||
use crate::tanour_capnp; | ||
|
||
use log::debug; | ||
|
||
use tanour::{blockchain_api::BlockchainAPI, Address}; | ||
|
||
unsafe impl Send for tanour_capnp::provider::Client {} | ||
|
||
pub struct BlockchainAdaptor { | ||
client: tanour_capnp::provider::Client, | ||
} | ||
|
||
impl BlockchainAdaptor { | ||
pub fn new(client: tanour_capnp::provider::Client) -> Self { | ||
BlockchainAdaptor { client } | ||
} | ||
} | ||
|
||
impl BlockchainAPI for BlockchainAdaptor { | ||
fn page_size(&self) -> Result<u32, tanour::error::Error> { | ||
let req = self.client.page_size_request(); | ||
|
||
let handle = async move { | ||
debug!("Try ot call `page_size` method in client"); | ||
let result = req.send().promise.await.unwrap(); //TODO: no unwrap | ||
result.get().unwrap().get_size() //TODO: no unwrap | ||
}; | ||
|
||
Ok(futures::executor::block_on(handle)) | ||
} | ||
|
||
fn read_page(&self, page_no: u32) -> Result<Vec<u8>, tanour::error::Error> { | ||
let mut req = self.client.read_page_request(); | ||
req.get().set_page_no(page_no); | ||
|
||
let handle = async move { | ||
debug!("Try ot call `read_page` method in client"); | ||
let result = req.send().promise.await.unwrap(); //TODO: no unwrap | ||
result.get().unwrap().get_data().unwrap().to_vec() //TODO: no unwrap | ||
}; | ||
|
||
Ok(futures::executor::block_on(handle)) //TODO: no unwrap | ||
} | ||
|
||
fn write_page(&self, page_no: u32, data: &[u8]) -> Result<(), tanour::error::Error> { | ||
let mut req = self.client.write_page_request(); | ||
req.get().set_page_no(page_no); | ||
req.get().set_data(data); | ||
|
||
let handle = async move { | ||
debug!("Try ot call `write_page` method in client"); | ||
let result = req.send().promise.await.unwrap(); //TODO: no unwrap | ||
result.get().unwrap(); //TODO: no unwrap | ||
}; | ||
|
||
futures::executor::block_on(handle); | ||
Ok(()) //TODO: no unwrap | ||
} | ||
|
||
fn exist(&self, address: &Address) -> Result<bool, tanour::error::Error> { | ||
let mut req = self.client.exists_request(); | ||
req.get().set_address(address); | ||
|
||
let handle = async move { | ||
debug!("Try ot call `exists` method in client"); | ||
let result = req.send().promise.await.unwrap(); //TODO: no unwrap | ||
result.get().unwrap().get_exist() //TODO: no unwrap | ||
}; | ||
|
||
Ok(futures::executor::block_on(handle)) | ||
} | ||
|
||
fn current_block_number(&self) -> u32 { | ||
todo!() | ||
} | ||
} |
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,4 +1,6 @@ | ||
|
||
fn main() { | ||
::capnpc::CompilerCommand::new().file("tanour.capnp").run().unwrap(); | ||
} | ||
::capnpc::CompilerCommand::new() | ||
.file("tanour.capnp") | ||
.run() | ||
.unwrap(); | ||
} |
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
Oops, something went wrong.