Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update macro to allow for return value, add get_incoming_transactions #378

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions zingocli/tests/darkside/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@ type UnderlyingService = BoxCloneService<
>;

macro_rules! define_darkside_connector_methods(
($($name:ident (&$self:ident, $($param:ident: $param_type:ty),*$(,)?) {$param_packing:expr}),*) => {$(
($($name:ident (&$self:ident $(,$param:ident: $param_type:ty)*$(,)?) -> $return:ty {$param_packing:expr}),*) => {$(
#[allow(unused)]
pub(crate) async fn $name(&$self, $($param: $param_type),*) -> ::std::result::Result<(), String> {
pub(crate) async fn $name(&$self, $($param: $param_type),*) -> ::std::result::Result<$return, String> {
let request = ::tonic::Request::new($param_packing);

let mut client = $self.get_client().await.map_err(|e| format!("{e}"))?;

let _response = client
client
.$name(request)
.await
.map_err(|e| format!("{}", e))?
.into_inner();

Ok(())
.map_err(|e| format!("{}", e))
.map(|resp| resp.into_inner())
})*}
);

Expand Down Expand Up @@ -84,40 +82,40 @@ impl DarksideConnector {
}

define_darkside_connector_methods!(
apply_staged(&self, height: i32) { DarksideHeight { height } },
add_tree_state(&self, tree_state: TreeState) { tree_state },
apply_staged(&self, height: i32) -> Empty { DarksideHeight { height } },
add_tree_state(&self, tree_state: TreeState) -> Empty { tree_state },
reset(
&self,
sapling_activation: i32,
branch_id: String,
chain_name: String,
) {
) -> Empty {
DarksideMetaState {
sapling_activation,
branch_id,
chain_name,
}
},
stage_blocks(&self, url: String) { DarksideBlocksUrl { url } },
stage_blocks(&self, url: String) -> Empty { DarksideBlocksUrl { url } },
stage_blocks_create(
&self,
height: i32,
count: i32,
nonce: i32
) {
) -> Empty {
DarksideEmptyBlocks {
height,
count,
nonce
}
},

stage_blocks_stream(&self, blocks: Vec<String>) {
stage_blocks_stream(&self, blocks: Vec<String>) -> Empty {
::futures_util::stream::iter(
blocks.into_iter().map(|block| DarksideBlock { block })
)
},
stage_transactions_stream(&self, transactions: Vec<(Vec<u8>, u64)>) {
stage_transactions_stream(&self, transactions: Vec<(Vec<u8>, u64)>) -> Empty {
::futures_util::stream::iter(
transactions.into_iter().map(|transaction| {
RawTransaction {
Expand All @@ -126,6 +124,9 @@ impl DarksideConnector {
}
})
)
},
get_incoming_transactions(&self) -> ::tonic::Streaming<RawTransaction> {
Empty {}
}
);
}
Expand Down