From f40b61ecbec477dbd06db03719aa9b214ebdb8be Mon Sep 17 00:00:00 2001 From: mayoreee Date: Tue, 26 Jul 2022 01:27:52 +0100 Subject: [PATCH 01/26] fix: replace name --- client/src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/client.rs b/client/src/client.rs index 0036a5dd..1bcd97a2 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1170,7 +1170,7 @@ pub trait RpcApi: Sized { } } -/// Client implements a JSON-RPC client for the Bitcoin Core daemon or compatible APIs. +/// Client implements a JSON-RPC client for the Dash Core daemon or compatible APIs. pub struct Client { client: jsonrpc::client::Client, } From de1b9a6f940bc1fb832d9b96c8772b824911eecb Mon Sep 17 00:00:00 2001 From: mayoreee Date: Tue, 26 Jul 2022 01:33:31 +0100 Subject: [PATCH 02/26] tests: add get masternode count test --- integration_test/src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index 9737e096..d63cc3d5 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -213,6 +213,7 @@ fn main() { test_add_ban(&cl); test_set_network_active(&cl); test_stop(cl); + test_get_masternode_count(cl); } fn test_get_network_info(cl: &Client) { @@ -1136,3 +1137,11 @@ fn test_getblocktemplate(cl: &Client) { fn test_stop(cl: Client) { println!("Stopping: '{}'", cl.stop().unwrap()); } + + +// ---------------------- Masternode RPC tests--------------------- + +fn test_get_masternode_count(cl: &Client) { + let masternode_count = rpc.get_masternode_count().unwrap(); + assert!(masternode_count > 0); +} \ No newline at end of file From b26988eceb5102e21618d426e96e4458f068d891 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Tue, 26 Jul 2022 13:06:45 +0100 Subject: [PATCH 03/26] tests: update masternode count test --- integration_test/src/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index d63cc3d5..448d22c4 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -1143,5 +1143,7 @@ fn test_stop(cl: Client) { fn test_get_masternode_count(cl: &Client) { let masternode_count = rpc.get_masternode_count().unwrap(); - assert!(masternode_count > 0); + assert!(masternode_count.total > 0); + assert!(masternode_count.enabled > 0); + assert!(masternode_count.total >= masternode_count.enabled); } \ No newline at end of file From ca304a827d3165a18730d2bf4b8320cc4cc48a31 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Thu, 28 Jul 2022 19:24:04 +0100 Subject: [PATCH 04/26] feat: add get masternode list --- client/src/client.rs | 9 +++++++++ integration_test/src/main.rs | 5 +++++ json/src/lib.rs | 21 +++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/client/src/client.rs b/client/src/client.rs index 1bcd97a2..c52a8186 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1168,6 +1168,15 @@ pub trait RpcApi: Sized { fn get_masternode_count(&self) -> Result { self.call("masternode", &["count".into()]) } + + + /// Returns a list of known masternodes + fn get_masternode_list(&self) -> Result>{ + let mut args = ["list".into(), "json".into()]; + self.call::>("masternode", handle_defaults(&mut args, &[null()])) + } + + } /// Client implements a JSON-RPC client for the Dash Core daemon or compatible APIs. diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index 448d22c4..99644f26 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -214,6 +214,7 @@ fn main() { test_set_network_active(&cl); test_stop(cl); test_get_masternode_count(cl); + test_get_masternode_list(cl); } fn test_get_network_info(cl: &Client) { @@ -1146,4 +1147,8 @@ fn test_get_masternode_count(cl: &Client) { assert!(masternode_count.total > 0); assert!(masternode_count.enabled > 0); assert!(masternode_count.total >= masternode_count.enabled); +} + +fn test_get_masternode_list(cl: &Client) { + let masternode_count = rpc.get_masternode_count().unwrap(); } \ No newline at end of file diff --git a/json/src/lib.rs b/json/src/lib.rs index 07ddb2f1..bc9f58d6 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -1986,6 +1986,27 @@ pub struct GetMasternodeCountResult { pub enabled: u32, } +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct GetMasternodeListJSON { + #[serde(rename = "proTxHash")] + pub pro_tx_hash: String, + pub address: String, + pub payee: String, + pub status: String, + #[serde(rename = "lastpaidtime")] + pub last_paid_time: u32, + #[serde(rename = "lastpaidblock")] + pub last_paid_block: u32, + #[serde(rename = "owneraddress")] + pub owner_address: String, + #[serde(rename = "votingaddress")] + pub voting_address: String, + #[serde(rename = "collateraladdress")] + pub collateral_address: String, + #[serde(rename = "pubkeyoperator")] + pub pubkey_operator: String, +} + // Custom deserializer functions. From b3b5991d479aaa81bf872e77905704881e96adb6 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Thu, 28 Jul 2022 19:41:32 +0100 Subject: [PATCH 05/26] fix: masternode list test --- integration_test/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index 99644f26..60f10221 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -1150,5 +1150,5 @@ fn test_get_masternode_count(cl: &Client) { } fn test_get_masternode_list(cl: &Client) { - let masternode_count = rpc.get_masternode_count().unwrap(); + let masternode_count = rpc.get_masternode_list().unwrap(); } \ No newline at end of file From 85df6a1a1e1aa3af8f8b3a2470aa5d3555b54db8 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Thu, 28 Jul 2022 19:42:52 +0100 Subject: [PATCH 06/26] feat: add get masternode outputs --- client/src/client.rs | 6 ++++++ integration_test/src/main.rs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/client/src/client.rs b/client/src/client.rs index c52a8186..c278a0aa 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1176,6 +1176,12 @@ pub trait RpcApi: Sized { self.call::>("masternode", handle_defaults(&mut args, &[null()])) } + /// Returns masternode compatible outputs + fn get_masternode_outputs(&self) -> Result>{ + let mut args = ["outputs".into()]; + self.call::>("masternode", handle_defaults(&mut args, &[null()])) + } + } diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index 60f10221..c5269547 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -215,6 +215,7 @@ fn main() { test_stop(cl); test_get_masternode_count(cl); test_get_masternode_list(cl); + test_get_masternode_outputs(cl); } fn test_get_network_info(cl: &Client) { @@ -1151,4 +1152,8 @@ fn test_get_masternode_count(cl: &Client) { fn test_get_masternode_list(cl: &Client) { let masternode_count = rpc.get_masternode_list().unwrap(); +} + +fn test_get_masternode_outputs(cl: &Client) { + let masternode_count = rpc.get_masternode_outputs().unwrap(); } \ No newline at end of file From 5a095f5acb061ded874170b9b2819d1dd49ccc4d Mon Sep 17 00:00:00 2001 From: mayoreee Date: Thu, 28 Jul 2022 20:22:28 +0100 Subject: [PATCH 07/26] feat: add masternode payments --- client/src/client.rs | 6 ++++++ integration_test/src/main.rs | 15 +++++++++++++-- json/src/lib.rs | 23 +++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/client/src/client.rs b/client/src/client.rs index c278a0aa..0bb3df72 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1182,6 +1182,12 @@ pub trait RpcApi: Sized { self.call::>("masternode", handle_defaults(&mut args, &[null()])) } + /// Returns an array of deterministic masternodes and their payments for the specified block + fn get_masternode_payments(&self) -> Result>{ + let mut args = ["payments".into()]; + self.call::>("masternode", handle_defaults(&mut args, &[null()])) + } + } diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index c5269547..c6198d9b 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -216,6 +216,7 @@ fn main() { test_get_masternode_count(cl); test_get_masternode_list(cl); test_get_masternode_outputs(cl); + test_get_masternode_payments(cl); } fn test_get_network_info(cl: &Client) { @@ -1151,9 +1152,19 @@ fn test_get_masternode_count(cl: &Client) { } fn test_get_masternode_list(cl: &Client) { - let masternode_count = rpc.get_masternode_list().unwrap(); + let masternode_list = rpc.get_masternode_list().unwrap(); } fn test_get_masternode_outputs(cl: &Client) { - let masternode_count = rpc.get_masternode_outputs().unwrap(); + let masternode_outputs = rpc.get_masternode_outputs().unwrap(); +} + +fn test_get_masternode_payments(cl: &Client) { + let masternode_payments = rpc.get_masternode_payments().unwrap(); + assert!(masternode_payments[0].height > 0); + assert!(masternode_payments[0].amount > 0); + assert!(masternode_payments[0].masternodes[0].amount > 0); + assert!(masternode_payments[0].masternodes[0].payees[0].amount > 0); + assert_eq!(masternode_payments[0].amount, masternode_payments[0].masternodes[0].amount); + assert_eq!(masternode_payments[0].amount, masternode_payments[0].masternodes[0].payees[0].amount); } \ No newline at end of file diff --git a/json/src/lib.rs b/json/src/lib.rs index bc9f58d6..8b9b0a22 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -2007,6 +2007,29 @@ pub struct GetMasternodeListJSON { pub pubkey_operator: String, } +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct Payee { + pub address: String, + pub script: String, + pub amount: u32, +} + +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct Masternode { + #[serde(rename = "proTxHash")] + pub pro_tx_hash: String, + pub amount: u32, + pub payees: Vec, +} + +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct GetMasternodePaymentsResult { + pub height: u32, + #[serde(rename = "blockhash")] + pub block_hash: String, + pub amount: u32, + pub masternodes: Vec, +} // Custom deserializer functions. From d5432643d46680c5aaa999f46b16e84475e4acf0 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Thu, 28 Jul 2022 21:06:53 +0100 Subject: [PATCH 08/26] feat: add masternode status --- client/src/client.rs | 5 +++++ integration_test/src/main.rs | 4 ++++ json/src/lib.rs | 41 ++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/client/src/client.rs b/client/src/client.rs index 0bb3df72..ddda8ac1 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1188,6 +1188,11 @@ pub trait RpcApi: Sized { self.call::>("masternode", handle_defaults(&mut args, &[null()])) } + /// Returns masternode status information + fn get_masternode_status(&self) -> Result { + self.call("masternode", &["status".into()]) + } + } diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index c6198d9b..42b25572 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -1167,4 +1167,8 @@ fn test_get_masternode_payments(cl: &Client) { assert!(masternode_payments[0].masternodes[0].payees[0].amount > 0); assert_eq!(masternode_payments[0].amount, masternode_payments[0].masternodes[0].amount); assert_eq!(masternode_payments[0].amount, masternode_payments[0].masternodes[0].payees[0].amount); +} + +fn test_get_masternode_status(cl: &Client) { + let masternode_status = rpc.get_masternode_status().unwrap(); } \ No newline at end of file diff --git a/json/src/lib.rs b/json/src/lib.rs index 8b9b0a22..9e0ac87b 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -2031,6 +2031,47 @@ pub struct GetMasternodePaymentsResult { pub masternodes: Vec, } +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct DMNState { + pub service: String, + #[serde(rename = "registeredHeight")] + pub registered_height: u32, + #[serde(rename = "lastPaidHeight")] + pub last_paid_height: u32, + #[serde(rename = "PoSePenalty")] + pub pose_penalty: u32, + #[serde(rename = "PoSeRevivedHeight")] + pub pose_revived_height: u32, + #[serde(rename = "PoSeBanHeight")] + pub pose_ban_height: i32, + #[serde(rename = "revocationReason")] + pub revocation_reason: u32, + #[serde(rename = "ownerAddress")] + pub owner_address: String, + #[serde(rename = "votingAddress")] + pub voting_address: String, + #[serde(rename = "payoutAddress")] + pub payout_address: String, + #[serde(rename = "pubKeyOperator")] + pub pubkey_operator: String, +} + +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub struct GetMasternodeStatusResult { + pub outpoint: String, + pub service: String, + #[serde(rename = "proTxHash")] + pub pro_tx_hash: String, + #[serde(rename = "collateralHash")] + pub collateral_hash: String, + #[serde(rename = "collateralIndex")] + pub collateral_index: u32, + #[serde(rename = "dmnState")] + pub dmn_state: DMNState, + pub state: String, + pub status: String, +} + // Custom deserializer functions. /// deserialize_hex_array_opt deserializes a vector of hex-encoded byte arrays. From 4165fa11006c4488e6db6b0a1c4cd49eb98abb63 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Thu, 28 Jul 2022 21:19:45 +0100 Subject: [PATCH 09/26] feat: add masternode winners --- client/src/client.rs | 5 +++++ integration_test/src/main.rs | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/client/src/client.rs b/client/src/client.rs index ddda8ac1..2e7b7f90 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1193,6 +1193,11 @@ pub trait RpcApi: Sized { self.call("masternode", &["status".into()]) } + /// Returns the list of masternode winners + fn get_masternode_winners(&self, count: &str, filter: &str) -> Result> { + self.call("masternode", &["winners".into(), count.into(), filter.into()]) + } + } diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index 42b25572..6902d61b 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -217,6 +217,7 @@ fn main() { test_get_masternode_list(cl); test_get_masternode_outputs(cl); test_get_masternode_payments(cl); + test_get_masternode_status(cl); } fn test_get_network_info(cl: &Client) { @@ -1171,4 +1172,8 @@ fn test_get_masternode_payments(cl: &Client) { fn test_get_masternode_status(cl: &Client) { let masternode_status = rpc.get_masternode_status().unwrap(); -} \ No newline at end of file +} + +fn test_get_masternode_winners(cl: &Client) { + let masternode_winners = rpc.get_masternode_winners("10", "").unwrap(); +} From 45e9f119c6acded0a58c9327e3e3da48b88ff506 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Thu, 28 Jul 2022 21:32:09 +0100 Subject: [PATCH 10/26] fix: swap `to_string()` for string literal type `&str` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a2ad646e..1876e960 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ use dashcore_rpc::{Auth, Client, RpcApi}; fn main() { - let rpc = Client::new("localhost:19998".to_string(), + let rpc = Client::new("localhost:19998", Auth::UserPass("".to_string(), "".to_string())).unwrap(); let best_block_hash = rpc.get_best_block_hash().unwrap(); From dd945194c4b1ffc4bb17ab8318e94ceabe5bcc97 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Thu, 28 Jul 2022 21:33:34 +0100 Subject: [PATCH 11/26] docs: update example script --- client/examples/connect_to_masternode.rs | 35 +++++++++++++++++++----- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/client/examples/connect_to_masternode.rs b/client/examples/connect_to_masternode.rs index e123e6ab..3cd725de 100644 --- a/client/examples/connect_to_masternode.rs +++ b/client/examples/connect_to_masternode.rs @@ -3,29 +3,50 @@ extern crate dashcore_rpc; use dashcore_rpc::{Auth, Client, RpcApi}; fn main() { - let rpc = Client::new( - "localhost:19998".to_string(), + let rpc = Client::new("127.0.0.1:19998", Auth::UserPass("dashrpc".to_string(), "rpcpassword".to_string()), ) .unwrap(); - // Get Dash network info + // // Get Dash network info let network_info = rpc.get_network_info().unwrap(); println!("\nDash network info: \n{:?}", network_info); - // Get best block hash + // // Get best block hash let best_block_hash = rpc.get_best_block_hash().unwrap(); println!("\n\nBest block hash: \n{}", best_block_hash); - // Get block count + // // Get block count let block_count = rpc.get_block_count().unwrap(); println!("\n\nBlock count: \n{}", block_count); - // Get block hash (for the a specified block height) + // // Get block hash (for the a specified block height) let block_hash = rpc.get_block_hash(block_count).unwrap(); - println!("\n\nBlock hash at block height \n{}: {}", block_count, block_hash); + println!("\n\nBlock hash at block height {}: \n{}", block_count, block_hash); // Get masternode count let masternode_count = rpc.get_masternode_count().unwrap(); println!("\n\nMasternode Count: \n{:?}", masternode_count); + + + // Get masternode list + let mn_list = rpc.get_masternode_list().unwrap(); + println!("\n\nMasternode List: \n{:?}", mn_list); + + // Get masternode outputs + let mn_outputs = rpc.get_masternode_outputs().unwrap(); + println!("\n\nMasternode Outputs: \n{:?}", mn_outputs); + + // Get masternode payments + let mn_payments = rpc.get_masternode_payments().unwrap(); + println!("\n\nMasternode Payments: \n{:?}", mn_payments); + + // Get masternode status + let mn_status = rpc.get_masternode_status().unwrap(); + println!("\n\nMasternode Status: \n{:?}", mn_status); + + // Get masternode winners + let mn_winners = rpc.get_masternode_winners("10", "").unwrap(); + println!("\n\nMasternode Winners: \n{:?}", mn_winners); + } From e9325e368c60eab1c56dc9007099e21c23063c83 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Thu, 28 Jul 2022 21:52:45 +0100 Subject: [PATCH 12/26] tests: add masternode winners --- integration_test/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index 6902d61b..d15e7cf7 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -218,6 +218,7 @@ fn main() { test_get_masternode_outputs(cl); test_get_masternode_payments(cl); test_get_masternode_status(cl); + test_get_masternode_winners(cl); } fn test_get_network_info(cl: &Client) { From 09696646f73994708193ed488e437c3616b1dc01 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Thu, 28 Jul 2022 23:42:15 +0100 Subject: [PATCH 13/26] fix: rename data structures and types --- client/src/client.rs | 6 +++--- json/src/lib.rs | 22 ++++++++-------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/client/src/client.rs b/client/src/client.rs index 2e7b7f90..2f5dae4e 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1171,9 +1171,9 @@ pub trait RpcApi: Sized { /// Returns a list of known masternodes - fn get_masternode_list(&self) -> Result>{ + fn get_masternode_list(&self) -> Result>{ let mut args = ["list".into(), "json".into()]; - self.call::>("masternode", handle_defaults(&mut args, &[null()])) + self.call::>("masternode", handle_defaults(&mut args, &[null()])) } /// Returns masternode compatible outputs @@ -1189,7 +1189,7 @@ pub trait RpcApi: Sized { } /// Returns masternode status information - fn get_masternode_status(&self) -> Result { + fn get_masternode_status(&self) -> Result { self.call("masternode", &["status".into()]) } diff --git a/json/src/lib.rs b/json/src/lib.rs index 9e0ac87b..e83bc2ef 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -1987,7 +1987,7 @@ pub struct GetMasternodeCountResult { } #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] -pub struct GetMasternodeListJSON { +pub struct Masternode { #[serde(rename = "proTxHash")] pub pro_tx_hash: String, pub address: String, @@ -2015,7 +2015,7 @@ pub struct Payee { } #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] -pub struct Masternode { +pub struct MasternodePayment { #[serde(rename = "proTxHash")] pub pro_tx_hash: String, pub amount: u32, @@ -2026,38 +2026,32 @@ pub struct Masternode { pub struct GetMasternodePaymentsResult { pub height: u32, #[serde(rename = "blockhash")] - pub block_hash: String, + pub block_hash: dashcore::BlockHash, pub amount: u32, - pub masternodes: Vec, + pub masternodes: Vec, } #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] pub struct DMNState { pub service: String, - #[serde(rename = "registeredHeight")] pub registered_height: u32, - #[serde(rename = "lastPaidHeight")] pub last_paid_height: u32, #[serde(rename = "PoSePenalty")] pub pose_penalty: u32, #[serde(rename = "PoSeRevivedHeight")] pub pose_revived_height: u32, #[serde(rename = "PoSeBanHeight")] - pub pose_ban_height: i32, - #[serde(rename = "revocationReason")] + pub pose_ban_height: u32, pub revocation_reason: u32, - #[serde(rename = "ownerAddress")] pub owner_address: String, - #[serde(rename = "votingAddress")] pub voting_address: String, - #[serde(rename = "payoutAddress")] pub payout_address: String, - #[serde(rename = "pubKeyOperator")] - pub pubkey_operator: String, + pub pub_key_operator: String, } #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] -pub struct GetMasternodeStatusResult { +pub struct MasternodeStatus { pub outpoint: String, pub service: String, #[serde(rename = "proTxHash")] From 7a39ebe4e985c026a0a5a286a04c84912ed2be56 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Fri, 29 Jul 2022 13:24:13 +0100 Subject: [PATCH 14/26] fix: proTxHash decoded to array bytes --- json/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/json/src/lib.rs b/json/src/lib.rs index e83bc2ef..bac7440b 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -1988,8 +1988,8 @@ pub struct GetMasternodeCountResult { #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] pub struct Masternode { - #[serde(rename = "proTxHash")] - pub pro_tx_hash: String, + #[serde(rename = "proTxHash",with = "::serde_hex")] + pub pro_tx_hash: Vec, pub address: String, pub payee: String, pub status: String, @@ -2016,8 +2016,8 @@ pub struct Payee { #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] pub struct MasternodePayment { - #[serde(rename = "proTxHash")] - pub pro_tx_hash: String, + #[serde(rename = "proTxHash",with = "::serde_hex")] + pub pro_tx_hash: Vec, pub amount: u32, pub payees: Vec, } @@ -2054,8 +2054,8 @@ pub struct DMNState { pub struct MasternodeStatus { pub outpoint: String, pub service: String, - #[serde(rename = "proTxHash")] - pub pro_tx_hash: String, + #[serde(rename = "proTxHash",with = "::serde_hex")] + pub pro_tx_hash: Vec, #[serde(rename = "collateralHash")] pub collateral_hash: String, #[serde(rename = "collateralIndex")] From 1ba5638f62316243b0c9e3a6ea870ee1a4b81daa Mon Sep 17 00:00:00 2001 From: mayoreee Date: Fri, 29 Jul 2022 14:07:40 +0100 Subject: [PATCH 15/26] fix: deserialize `dashcore::Outpoint` struct --- json/src/lib.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/json/src/lib.rs b/json/src/lib.rs index bac7440b..35a8b167 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -2052,9 +2052,10 @@ pub struct DMNState { #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] pub struct MasternodeStatus { - pub outpoint: String, + #[serde(default, deserialize_with = "deserialize_outpoint")] + pub outpoint: dashcore::OutPoint, pub service: String, - #[serde(rename = "proTxHash",with = "::serde_hex")] + #[serde(rename = "proTxHash", with = "::serde_hex")] pub pro_tx_hash: Vec, #[serde(rename = "collateralHash")] pub collateral_hash: String, @@ -2084,3 +2085,24 @@ where Ok(Some(res)) } +/// deserialize_outpoint deserialzes a hex-encoded outpoint +fn deserialize_outpoint<'de, D>(deserializer: D) -> Result +where + D: serde::Deserializer<'de>, +{ + let str_sequence = String::deserialize(deserializer)?; + let str_array: Vec = str_sequence + .split('-') + .map(|item| item.to_owned()) + .collect(); + + let tx_id: dashcore::Txid = dashcore::Txid::from_hex(&str_array[0]).unwrap(); + let vout: u32 = str_array[1].parse().unwrap(); + + let outpoint = dashcore::OutPoint{ + txid: tx_id, + vout: vout, + }; + Ok(outpoint) +} + From ca72938a204acb44f02879901248691cd862940c Mon Sep 17 00:00:00 2001 From: mayoreee Date: Fri, 29 Jul 2022 14:31:55 +0100 Subject: [PATCH 16/26] fix: deserialize masternode address --- json/src/lib.rs | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/json/src/lib.rs b/json/src/lib.rs index 35a8b167..2777ec17 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -1986,11 +1986,18 @@ pub struct GetMasternodeCountResult { pub enabled: u32, } +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize, Default)] +pub struct MasternodeAddress { + pub ip: String, + pub port: String, +} + #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] pub struct Masternode { #[serde(rename = "proTxHash",with = "::serde_hex")] pub pro_tx_hash: Vec, - pub address: String, + #[serde(default, deserialize_with = "deserialize_mn_address")] + pub address: MasternodeAddress, pub payee: String, pub status: String, #[serde(rename = "lastpaidtime")] @@ -2096,13 +2103,35 @@ where .map(|item| item.to_owned()) .collect(); - let tx_id: dashcore::Txid = dashcore::Txid::from_hex(&str_array[0]).unwrap(); + let txid: dashcore::Txid = dashcore::Txid::from_hex(&str_array[0]).unwrap(); let vout: u32 = str_array[1].parse().unwrap(); let outpoint = dashcore::OutPoint{ - txid: tx_id, + txid: txid, vout: vout, }; Ok(outpoint) } +/// deserialize_mn_address deserialzes a masternode address +fn deserialize_mn_address<'de, D>(deserializer: D) -> Result +where + D: serde::Deserializer<'de>, +{ + let str_sequence = String::deserialize(deserializer)?; + let str_array: Vec = str_sequence + .split(':') + .map(|item| item.to_owned()) + .collect(); + + let ip: String = str_array[0].to_string(); + let port: String = str_array[1].to_string(); + + let mn_address = MasternodeAddress{ + ip: ip, + port: port, + }; + Ok(mn_address) +} + + From c2e72e5a3c819df82729454ac5aefe62efcce907 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Fri, 29 Jul 2022 19:41:15 +0100 Subject: [PATCH 17/26] fix: deserialize `payoutAddress` and `votingAddress` --- json/src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/json/src/lib.rs b/json/src/lib.rs index 2777ec17..1c6b03fd 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -1994,7 +1994,7 @@ pub struct MasternodeAddress { #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] pub struct Masternode { - #[serde(rename = "proTxHash",with = "::serde_hex")] + #[serde(rename = "proTxHash", with = "::serde_hex")] pub pro_tx_hash: Vec, #[serde(default, deserialize_with = "deserialize_mn_address")] pub address: MasternodeAddress, @@ -2023,7 +2023,7 @@ pub struct Payee { #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] pub struct MasternodePayment { - #[serde(rename = "proTxHash",with = "::serde_hex")] + #[serde(rename = "proTxHash", with = "::serde_hex")] pub pro_tx_hash: Vec, pub amount: u32, pub payees: Vec, @@ -2052,8 +2052,10 @@ pub struct DMNState { pub pose_ban_height: u32, pub revocation_reason: u32, pub owner_address: String, - pub voting_address: String, - pub payout_address: String, + #[serde(with = "::serde_hex")] + pub voting_address: Vec, + #[serde(with = "::serde_hex")] + pub payout_address: Vec, pub pub_key_operator: String, } @@ -2092,7 +2094,7 @@ where Ok(Some(res)) } -/// deserialize_outpoint deserialzes a hex-encoded outpoint +/// deserialize_outpoint deserializes a hex-encoded outpoint fn deserialize_outpoint<'de, D>(deserializer: D) -> Result where D: serde::Deserializer<'de>, @@ -2113,7 +2115,7 @@ where Ok(outpoint) } -/// deserialize_mn_address deserialzes a masternode address +/// deserialize_mn_address deserializes a masternode address fn deserialize_mn_address<'de, D>(deserializer: D) -> Result where D: serde::Deserializer<'de>, @@ -2133,5 +2135,3 @@ where }; Ok(mn_address) } - - From 63225e62d2048b7224cd3c5092cd193b3a3b9e0b Mon Sep 17 00:00:00 2001 From: mayoreee Date: Fri, 29 Jul 2022 21:58:50 +0100 Subject: [PATCH 18/26] fix: deserialize socket address --- json/Cargo.toml | 1 + json/src/lib.rs | 34 ++++++---------------------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/json/Cargo.toml b/json/Cargo.toml index b5d5f511..ef06ab5d 100644 --- a/json/Cargo.toml +++ b/json/Cargo.toml @@ -20,5 +20,6 @@ path = "src/lib.rs" [dependencies] serde = { version = "1", features = [ "derive" ] } serde_json = "1" +serde_with = "2.0.0" dashcore = { git = "https://github.com/dashevo/rust-dashcore", branch = "master", features = [ "use-serde" ] } diff --git a/json/src/lib.rs b/json/src/lib.rs index 1c6b03fd..e10e0d6e 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -21,6 +21,7 @@ pub extern crate dashcore; #[macro_use] // `macro_use` is needed for v1.24.0 compilation. extern crate serde; extern crate serde_json; +extern crate serde_with; use std::collections::HashMap; @@ -31,7 +32,9 @@ use dashcore::util::{bip158, bip32}; use dashcore::{Address, Amount, PrivateKey, PublicKey, Script, SignedAmount, Transaction}; use serde::de::Error as SerdeError; use serde::{Deserialize, Serialize}; +use serde_with::{serde_as, DisplayFromStr}; use std::fmt; +use std::net::{SocketAddr}; //TODO(stevenroose) consider using a Time type @@ -1986,18 +1989,13 @@ pub struct GetMasternodeCountResult { pub enabled: u32, } -#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize, Default)] -pub struct MasternodeAddress { - pub ip: String, - pub port: String, -} - +#[serde_as] #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] pub struct Masternode { #[serde(rename = "proTxHash", with = "::serde_hex")] pub pro_tx_hash: Vec, - #[serde(default, deserialize_with = "deserialize_mn_address")] - pub address: MasternodeAddress, + #[serde_as(as = "DisplayFromStr")] + pub address: SocketAddr, pub payee: String, pub status: String, #[serde(rename = "lastpaidtime")] @@ -2115,23 +2113,3 @@ where Ok(outpoint) } -/// deserialize_mn_address deserializes a masternode address -fn deserialize_mn_address<'de, D>(deserializer: D) -> Result -where - D: serde::Deserializer<'de>, -{ - let str_sequence = String::deserialize(deserializer)?; - let str_array: Vec = str_sequence - .split(':') - .map(|item| item.to_owned()) - .collect(); - - let ip: String = str_array[0].to_string(); - let port: String = str_array[1].to_string(); - - let mn_address = MasternodeAddress{ - ip: ip, - port: port, - }; - Ok(mn_address) -} From 914982efe68e20a1c5a04b2cb65a3c333158873c Mon Sep 17 00:00:00 2001 From: mayoreee Date: Fri, 29 Jul 2022 23:44:31 +0100 Subject: [PATCH 19/26] fix: rename types --- json/src/lib.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/json/src/lib.rs b/json/src/lib.rs index e10e0d6e..1165ce20 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -2015,7 +2015,7 @@ pub struct Masternode { #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] pub struct Payee { pub address: String, - pub script: String, + pub script: Script, pub amount: u32, } @@ -2036,10 +2036,12 @@ pub struct GetMasternodePaymentsResult { pub masternodes: Vec, } +#[serde_as] #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] pub struct DMNState { - pub service: String, + #[serde_as(as = "DisplayFromStr")] + pub service: SocketAddr, pub registered_height: u32, pub last_paid_height: u32, #[serde(rename = "PoSePenalty")] @@ -2057,15 +2059,17 @@ pub struct DMNState { pub pub_key_operator: String, } +#[serde_as] #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] pub struct MasternodeStatus { #[serde(default, deserialize_with = "deserialize_outpoint")] pub outpoint: dashcore::OutPoint, - pub service: String, + #[serde_as(as = "DisplayFromStr")] + pub service: SocketAddr, #[serde(rename = "proTxHash", with = "::serde_hex")] pub pro_tx_hash: Vec, - #[serde(rename = "collateralHash")] - pub collateral_hash: String, + #[serde(rename = "collateralHash", with = "::serde_hex")] + pub collateral_hash: Vec, #[serde(rename = "collateralIndex")] pub collateral_index: u32, #[serde(rename = "dmnState")] From 2137ed1e59d38be842beb49cf980ab6c276af247 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Sat, 30 Jul 2022 00:09:59 +0100 Subject: [PATCH 20/26] fix: rename types --- json/src/lib.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/json/src/lib.rs b/json/src/lib.rs index 1165ce20..5e8966de 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -32,7 +32,7 @@ use dashcore::util::{bip158, bip32}; use dashcore::{Address, Amount, PrivateKey, PublicKey, Script, SignedAmount, Transaction}; use serde::de::Error as SerdeError; use serde::{Deserialize, Serialize}; -use serde_with::{serde_as, DisplayFromStr}; +use serde_with::{serde_as, DisplayFromStr, Bytes}; use std::fmt; use std::net::{SocketAddr}; @@ -1996,25 +1996,32 @@ pub struct Masternode { pub pro_tx_hash: Vec, #[serde_as(as = "DisplayFromStr")] pub address: SocketAddr, - pub payee: String, + #[serde_as(as = "Bytes")] + pub payee: Vec, pub status: String, #[serde(rename = "lastpaidtime")] pub last_paid_time: u32, #[serde(rename = "lastpaidblock")] pub last_paid_block: u32, + #[serde_as(as = "Bytes")] #[serde(rename = "owneraddress")] - pub owner_address: String, + pub owner_address: Vec, + #[serde_as(as = "Bytes")] #[serde(rename = "votingaddress")] - pub voting_address: String, + pub voting_address: Vec, + #[serde_as(as = "Bytes")] #[serde(rename = "collateraladdress")] - pub collateral_address: String, + pub collateral_address: Vec, + #[serde_as(as = "Bytes")] #[serde(rename = "pubkeyoperator")] - pub pubkey_operator: String, + pub pubkey_operator: Vec, } +#[serde_as] #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] pub struct Payee { - pub address: String, + #[serde_as(as = "Bytes")] + pub address: Vec, pub script: Script, pub amount: u32, } @@ -2051,12 +2058,14 @@ pub struct DMNState { #[serde(rename = "PoSeBanHeight")] pub pose_ban_height: u32, pub revocation_reason: u32, - pub owner_address: String, - #[serde(with = "::serde_hex")] + #[serde_as(as = "Bytes")] + pub owner_address: Vec, + #[serde_as(as = "Bytes")] pub voting_address: Vec, - #[serde(with = "::serde_hex")] + #[serde_as(as = "Bytes")] pub payout_address: Vec, - pub pub_key_operator: String, + #[serde_as(as = "Bytes")] + pub pub_key_operator: Vec, } #[serde_as] From 51054394b0a39b775ef995b897799982bfb2d8f4 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Sat, 30 Jul 2022 11:17:45 +0100 Subject: [PATCH 21/26] fix: rpc call options --- client/src/client.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/client/src/client.rs b/client/src/client.rs index 2f5dae4e..08d6530e 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1171,9 +1171,9 @@ pub trait RpcApi: Sized { /// Returns a list of known masternodes - fn get_masternode_list(&self) -> Result>{ - let mut args = ["list".into(), "json".into()]; - self.call::>("masternode", handle_defaults(&mut args, &[null()])) + fn get_masternode_list(&self, mode: Option<&str>, filter: Option<&str>) -> Result>{ + let mut args = ["list".into(), into_json(mode)?, opt_into_json(filter)?]; + self.call::>("masternode", handle_defaults(&mut args, &["json".into(), null()])) } /// Returns masternode compatible outputs @@ -1183,9 +1183,9 @@ pub trait RpcApi: Sized { } /// Returns an array of deterministic masternodes and their payments for the specified block - fn get_masternode_payments(&self) -> Result>{ - let mut args = ["payments".into()]; - self.call::>("masternode", handle_defaults(&mut args, &[null()])) + fn get_masternode_payments(&self, block_hash: Option<&str>, count: Option<&str>) -> Result>{ + let mut args = ["payments".into(), opt_into_json(block_hash)?, opt_into_json(count)?]; + self.call::>("masternode", handle_defaults(&mut args, &[null(), null()])) } /// Returns masternode status information @@ -1194,8 +1194,9 @@ pub trait RpcApi: Sized { } /// Returns the list of masternode winners - fn get_masternode_winners(&self, count: &str, filter: &str) -> Result> { - self.call("masternode", &["winners".into(), count.into(), filter.into()]) + fn get_masternode_winners(&self, count: Option<&str>, filter: Option<&str>) -> Result> { + let mut args = ["winners".into(), opt_into_json(count)?, opt_into_json(filter)?]; + self.call::>("masternode", handle_defaults(&mut args, &["10".into(), null()])) } From bf6f608111457b5008c9920405d59619e264f648 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Sat, 30 Jul 2022 11:19:55 +0100 Subject: [PATCH 22/26] docs: update docs --- README.md | 3 ++- client/examples/connect_to_masternode.rs | 17 +++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1876e960..326cc364 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ use dashcore_rpc::{Auth, Client, RpcApi}; fn main() { - let rpc = Client::new("localhost:19998", + let rpc = Client::new( + "localhost:19998", Auth::UserPass("".to_string(), "".to_string())).unwrap(); let best_block_hash = rpc.get_best_block_hash().unwrap(); diff --git a/client/examples/connect_to_masternode.rs b/client/examples/connect_to_masternode.rs index 3cd725de..ee566882 100644 --- a/client/examples/connect_to_masternode.rs +++ b/client/examples/connect_to_masternode.rs @@ -3,24 +3,25 @@ extern crate dashcore_rpc; use dashcore_rpc::{Auth, Client, RpcApi}; fn main() { - let rpc = Client::new("127.0.0.1:19998", + let rpc = Client::new( + "127.0.0.1:19998", Auth::UserPass("dashrpc".to_string(), "rpcpassword".to_string()), ) .unwrap(); - // // Get Dash network info + // Get Dash network info let network_info = rpc.get_network_info().unwrap(); println!("\nDash network info: \n{:?}", network_info); - // // Get best block hash + // Get best block hash let best_block_hash = rpc.get_best_block_hash().unwrap(); println!("\n\nBest block hash: \n{}", best_block_hash); - // // Get block count + // Get block count let block_count = rpc.get_block_count().unwrap(); println!("\n\nBlock count: \n{}", block_count); - // // Get block hash (for the a specified block height) + // Get block hash (for the a specified block height) let block_hash = rpc.get_block_hash(block_count).unwrap(); println!("\n\nBlock hash at block height {}: \n{}", block_count, block_hash); @@ -30,7 +31,7 @@ fn main() { // Get masternode list - let mn_list = rpc.get_masternode_list().unwrap(); + let mn_list = rpc.get_masternode_list(Some("json"), None).unwrap(); println!("\n\nMasternode List: \n{:?}", mn_list); // Get masternode outputs @@ -38,7 +39,7 @@ fn main() { println!("\n\nMasternode Outputs: \n{:?}", mn_outputs); // Get masternode payments - let mn_payments = rpc.get_masternode_payments().unwrap(); + let mn_payments = rpc.get_masternode_payments(None, None).unwrap(); println!("\n\nMasternode Payments: \n{:?}", mn_payments); // Get masternode status @@ -46,7 +47,7 @@ fn main() { println!("\n\nMasternode Status: \n{:?}", mn_status); // Get masternode winners - let mn_winners = rpc.get_masternode_winners("10", "").unwrap(); + let mn_winners = rpc.get_masternode_winners(None, None).unwrap(); println!("\n\nMasternode Winners: \n{:?}", mn_winners); } From 458e6cf721399688ac24e3ff727cbf6057cfa6ac Mon Sep 17 00:00:00 2001 From: mayoreee Date: Sat, 30 Jul 2022 11:21:08 +0100 Subject: [PATCH 23/26] docs: update docs --- client/examples/connect_to_masternode.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/examples/connect_to_masternode.rs b/client/examples/connect_to_masternode.rs index ee566882..2fe8bfd0 100644 --- a/client/examples/connect_to_masternode.rs +++ b/client/examples/connect_to_masternode.rs @@ -4,7 +4,7 @@ use dashcore_rpc::{Auth, Client, RpcApi}; fn main() { let rpc = Client::new( - "127.0.0.1:19998", + "localhost:19998", Auth::UserPass("dashrpc".to_string(), "rpcpassword".to_string()), ) .unwrap(); From 67ac398f67243cf3febacff202448318bb8c75c9 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Sat, 30 Jul 2022 13:02:30 +0100 Subject: [PATCH 24/26] fix: deserialize masternode state --- json/src/lib.rs | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/json/src/lib.rs b/json/src/lib.rs index 5e8966de..1bb120e6 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -2068,6 +2068,19 @@ pub struct DMNState { pub pub_key_operator: Vec, } +#[serde(untagged)] +#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] +pub enum MasternodeState{ + MASTERNODE_WAITING_FOR_PROTX, + MASTERNODE_POSE_BANNED, + MASTERNODE_REMOVED, + MASTERNODE_OPERATOR_KEY_CHANGED, + MASTERNODE_PROTX_IP_CHANGED, + MASTERNODE_READY, + MASTERNODE_ERROR, + UNKNOWN +} + #[serde_as] #[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)] pub struct MasternodeStatus { @@ -2083,7 +2096,8 @@ pub struct MasternodeStatus { pub collateral_index: u32, #[serde(rename = "dmnState")] pub dmn_state: DMNState, - pub state: String, + #[serde(deserialize_with = "deserialize_mn_state")] + pub state: MasternodeState, pub status: String, } @@ -2126,3 +2140,26 @@ where Ok(outpoint) } +/// deserialize_mn_state deserializes a masternode state +fn deserialize_mn_state<'de, D>(deserializer: D) -> Result +where + D: serde::Deserializer<'de>, +{ + let str_sequence = String::deserialize(deserializer)?; + + Ok( + match str_sequence.as_str() { + "WAITING_FOR_PROTX" => MasternodeState::MASTERNODE_WAITING_FOR_PROTX, + "POSE_BANNED" => MasternodeState::MASTERNODE_POSE_BANNED, + "REMOVED" => MasternodeState::MASTERNODE_REMOVED, + "OPERATOR_KEY_CHANGED" => MasternodeState::MASTERNODE_OPERATOR_KEY_CHANGED, + "PROTX_IP_CHANGED" => MasternodeState::MASTERNODE_PROTX_IP_CHANGED, + "READY" => MasternodeState::MASTERNODE_READY, + "ERROR" => MasternodeState::MASTERNODE_ERROR, + "UNKNOWN" => MasternodeState::UNKNOWN, + _ => panic!(), + } +) +} + + From 51a923c97f7ec3f4a25b6c09dc1895537193e503 Mon Sep 17 00:00:00 2001 From: mayoreee Date: Sat, 30 Jul 2022 14:07:19 +0100 Subject: [PATCH 25/26] tests: update tests --- integration_test/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integration_test/src/main.rs b/integration_test/src/main.rs index d15e7cf7..04ce7910 100644 --- a/integration_test/src/main.rs +++ b/integration_test/src/main.rs @@ -1154,7 +1154,7 @@ fn test_get_masternode_count(cl: &Client) { } fn test_get_masternode_list(cl: &Client) { - let masternode_list = rpc.get_masternode_list().unwrap(); + let masternode_list = rpc.get_masternode_list(Some("json"), None).unwrap(); } fn test_get_masternode_outputs(cl: &Client) { @@ -1162,7 +1162,7 @@ fn test_get_masternode_outputs(cl: &Client) { } fn test_get_masternode_payments(cl: &Client) { - let masternode_payments = rpc.get_masternode_payments().unwrap(); + let masternode_payments = rpc.get_masternode_payments(None, None).unwrap(); assert!(masternode_payments[0].height > 0); assert!(masternode_payments[0].amount > 0); assert!(masternode_payments[0].masternodes[0].amount > 0); @@ -1176,5 +1176,5 @@ fn test_get_masternode_status(cl: &Client) { } fn test_get_masternode_winners(cl: &Client) { - let masternode_winners = rpc.get_masternode_winners("10", "").unwrap(); + let masternode_winners = rpc.get_masternode_winners(None, None).unwrap(); } From df7f3e6f732376e80306d38a3a2262b34e992cce Mon Sep 17 00:00:00 2001 From: mayoreee Date: Mon, 1 Aug 2022 19:11:38 +0100 Subject: [PATCH 26/26] fix: add `NONRECONISED` MasternodeState --- json/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/json/src/lib.rs b/json/src/lib.rs index 1bb120e6..eac3431e 100644 --- a/json/src/lib.rs +++ b/json/src/lib.rs @@ -2078,7 +2078,8 @@ pub enum MasternodeState{ MASTERNODE_PROTX_IP_CHANGED, MASTERNODE_READY, MASTERNODE_ERROR, - UNKNOWN + UNKNOWN, + NONRECOGNISED, } #[serde_as] @@ -2157,7 +2158,7 @@ where "READY" => MasternodeState::MASTERNODE_READY, "ERROR" => MasternodeState::MASTERNODE_ERROR, "UNKNOWN" => MasternodeState::UNKNOWN, - _ => panic!(), + _ => MasternodeState::NONRECOGNISED, } ) }