diff --git a/ain-grpc/build.rs b/ain-grpc/build.rs index f3d6be9..84928f3 100644 --- a/ain-grpc/build.rs +++ b/ain-grpc/build.rs @@ -71,7 +71,7 @@ const TYPE_ATTRS: &[Attr] = &[ matcher: ".*", attr: Some("#[derive(Serialize, Deserialize)] #[serde(rename_all=\"camelCase\")]"), rename: None, - skip: &["^(Meta)?BlockResult", "NonUtxo", "^Transaction"], + skip: &["^BlockResult", "NonUtxo", "^Transaction"], }, Attr { matcher: ".*", @@ -92,13 +92,13 @@ const FIELD_ATTRS: &[Attr] = &[ matcher: ":::prost::alloc::string::String", attr: Some("#[serde(skip_serializing_if = \"String::is_empty\")]"), rename: None, - skip: &["^(Meta)?BlockResult", "NonUtxo", "^Transaction"], + skip: &["^BlockResult", "NonUtxo", "^Transaction"], }, Attr { matcher: ":::prost::alloc::vec::Vec", attr: Some("#[serde(skip_serializing_if = \"Vec::is_empty\")]"), rename: None, - skip: &["MetaBlockResult"], + skip: &[], }, Attr { matcher: "req_sigs", @@ -182,7 +182,7 @@ impl ServiceGenerator for WrappedGenerator { let re = Regex::new("\\[rpc: (.*?)\\]").unwrap(); for method in &service.methods { let mut ref_map = self.methods.borrow_mut(); - let vec = ref_map.entry(service.name.clone()).or_insert(vec![]); + let vec = ref_map.entry(service.name.clone()).or_default(); let mut rpc = Rpc { name: method.proto_name.clone(), input_ty: method.input_proto_type.clone(), @@ -303,7 +303,7 @@ fn modify_codegen( Span::call_site(), ), Ident::new( - &format!("{}Server", server_mod).to_snek_case(), + &format!("{server_mod}Server").to_snek_case(), Span::call_site(), ), Ident::new(&server_mod.to_pascal_case(), Span::call_site()), @@ -455,6 +455,7 @@ fn apply_substitutions( #[allow(non_snake_case)] fn NewClient(addr: &str) -> Result, Box> { if CLIENTS.read().unwrap().get(addr).is_none() { + log::info!("Initializing RPC client for {}", addr); let c = Client { inner: Arc::new(HttpClientBuilder::default().build(addr)?), handle: RUNTIME.rt_handle.clone(), @@ -480,7 +481,7 @@ fn apply_substitutions( #[allow(dead_code)] fn missing_param(field: &str) -> jsonrpsee_core::Error { jsonrpsee_core::Error::Call(jsonrpsee_types::error::CallError::Custom( - jsonrpsee_types::ErrorObject::borrowed(-1, &format!("Missing required parameter '{}'", field), None).into_owned() + jsonrpsee_types::ErrorObject::borrowed(-1, &format!("Missing required parameter '{field}'"), None).into_owned() )) } }; diff --git a/ain-grpc/src/codegen.rs b/ain-grpc/src/codegen.rs index 7428fd7..cd75308 100644 --- a/ain-grpc/src/codegen.rs +++ b/ain-grpc/src/codegen.rs @@ -52,48 +52,6 @@ impl<'de> Deserialize<'de> for types::BlockResult { } } -impl Serialize for types::MetaBlockResult { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - if !self.hash.is_empty() { - return serializer.serialize_str(&self.hash); - } - - if !self.block.is_empty() { - return self.block.serialize(serializer); - } - - serializer.serialize_str("") - } -} - -impl<'de> Deserialize<'de> for types::MetaBlockResult { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - #[derive(Deserialize)] - #[serde(untagged)] - enum Res { - Hash(String), - Block(Vec), - } - - match Res::deserialize(deserializer)? { - Res::Hash(s) => Ok(types::MetaBlockResult { - hash: s, - block: vec![], - }), - Res::Block(b) => Ok(types::MetaBlockResult { - hash: "".into(), - block: b, - }), - } - } -} - impl Serialize for types::Transaction { fn serialize(&self, serializer: S) -> Result where @@ -135,7 +93,7 @@ impl<'de> Deserialize<'de> for types::Transaction { #[cfg(test)] mod tests { - use super::types::{BlockResult, MetaBlockResult, Transaction}; + use super::types::{BlockResult, Transaction}; #[test] fn test_block_result_json() { @@ -148,17 +106,6 @@ mod tests { assert_eq!(serde_json::to_value(&foo2).unwrap(), "foobar"); } - #[test] - fn test_meta_block_result_json() { - let foo = MetaBlockResult { - hash: "foobar".into(), - block: vec![], - }; - let res = serde_json::to_value(&foo).unwrap(); - let foo2: MetaBlockResult = serde_json::from_value(res).unwrap(); - assert_eq!(serde_json::to_value(&foo2).unwrap(), "foobar"); - } - #[test] fn test_transaction() { let foo = Transaction { diff --git a/protobuf/rpc/dmc.proto b/protobuf/rpc/dmc.proto index ca3b082..9b7639d 100644 --- a/protobuf/rpc/dmc.proto +++ b/protobuf/rpc/dmc.proto @@ -3,16 +3,12 @@ package rpc; import "types/dmc.proto"; -service Metachain { - // [rpc: metaConsensusRpc_getBlockHash] [client] - rpc GetBlockHash(types.MetaBlockInput) returns (types.MetaBlockResult); - - // [rpc: metaConsensusRpc_getBlock] [client] - rpc GetBlock(types.MetaBlockInput) returns (types.MetaBlockResult); +// NOTE: The definitions here must match those in metachain +service Metachain { // [rpc: metaConsensusRpc_mintBlock] [client] - rpc MintBlock(types.MetaMintInput) returns (types.MetaMintResult); + rpc MetaMintBlock(types.MetaBlockInput) returns (types.MetaBlockResult); // [rpc: metaConsensusRpc_connectBlock] [client] - rpc ConnectBlock(types.MetaConnectBlockInput) returns (types.MetaConnectBlockResult); + rpc MetaConnectBlock(types.MetaConnectBlockInput) returns (types.MetaConnectBlockResult); } diff --git a/protobuf/types/dmc.proto b/protobuf/types/dmc.proto index 83cfacb..54af197 100644 --- a/protobuf/types/dmc.proto +++ b/protobuf/types/dmc.proto @@ -1,39 +1,26 @@ syntax = "proto3"; package types; +// NOTE: The definitions here must match those in metachain + message MetaTransaction { string from = 1; string to = 2; int64 amount = 3; - string signature = 4; } message MetaBlockInput { - int64 at = 1; // [default: -1] + repeated MetaTransaction txs = 2; } message MetaBlockResult { - string hash = 1; - bytes block = 2; -} - -message MetaMintInput { - repeated MetaTransaction dnc_txs = 1; - uint64 secret = 2; // secret obtained from handshake -} - -message MetaMintResult { - bytes block = 1; - repeated MetaTransaction dmc_txs = 2; + bytes payload = 1; } message MetaConnectBlockInput { - bytes dmc_payload = 1; - repeated MetaTransaction dnc_txs = 2; - uint64 secret = 3; // secret obtained from handshake + bytes payload = 1; } message MetaConnectBlockResult { - bool imported = 1; - repeated MetaTransaction dmc_txs = 2; + string hash = 1; }