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

Updated Dash Masternode RPC Calls #3

Merged
merged 26 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f40b61e
fix: replace name
mayoreee Jul 26, 2022
de1b9a6
tests: add get masternode count test
mayoreee Jul 26, 2022
b26988e
tests: update masternode count test
mayoreee Jul 26, 2022
ca304a8
feat: add get masternode list
mayoreee Jul 28, 2022
b3b5991
fix: masternode list test
mayoreee Jul 28, 2022
85df6a1
feat: add get masternode outputs
mayoreee Jul 28, 2022
5a095f5
feat: add masternode payments
mayoreee Jul 28, 2022
d543264
feat: add masternode status
mayoreee Jul 28, 2022
4165fa1
feat: add masternode winners
mayoreee Jul 28, 2022
45e9f11
fix: swap `to_string()` for string literal type `&str`
mayoreee Jul 28, 2022
dd94519
docs: update example script
mayoreee Jul 28, 2022
e9325e3
tests: add masternode winners
mayoreee Jul 28, 2022
0969664
fix: rename data structures and types
mayoreee Jul 28, 2022
7a39ebe
fix: proTxHash decoded to array bytes
mayoreee Jul 29, 2022
1ba5638
fix: deserialize `dashcore::Outpoint` struct
mayoreee Jul 29, 2022
ca72938
fix: deserialize masternode address
mayoreee Jul 29, 2022
c2e72e5
fix: deserialize `payoutAddress` and `votingAddress`
mayoreee Jul 29, 2022
63225e6
fix: deserialize socket address
mayoreee Jul 29, 2022
914982e
fix: rename types
mayoreee Jul 29, 2022
2137ed1
fix: rename types
mayoreee Jul 29, 2022
5105439
fix: rpc call options
mayoreee Jul 30, 2022
bf6f608
docs: update docs
mayoreee Jul 30, 2022
458e6cf
docs: update docs
mayoreee Jul 30, 2022
67ac398
fix: deserialize masternode state
mayoreee Jul 30, 2022
51a923c
tests: update tests
mayoreee Jul 30, 2022
df7f3e6
fix: add `NONRECONISED` MasternodeState
mayoreee Aug 1, 2022
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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("<FILL RPC USERNAME>".to_string(),
"<FILL RPC PASSWORD>".to_string())).unwrap();
let best_block_hash = rpc.get_best_block_hash().unwrap();
Expand Down
35 changes: 28 additions & 7 deletions client/examples/connect_to_masternode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
33 changes: 32 additions & 1 deletion client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,9 +1168,40 @@ pub trait RpcApi: Sized {
fn get_masternode_count(&self) -> Result<json::GetMasternodeCountResult> {
self.call("masternode", &["count".into()])
}


/// Returns a list of known masternodes
fn get_masternode_list(&self) -> Result<HashMap<String, json::GetMasternodeListJSON>>{
let mut args = ["list".into(), "json".into()];
self.call::<HashMap<String, json::GetMasternodeListJSON>>("masternode", handle_defaults(&mut args, &[null()]))
}

/// Returns masternode compatible outputs
fn get_masternode_outputs(&self) -> Result<HashMap<String, String>>{
let mut args = ["outputs".into()];
self.call::<HashMap<String, String>>("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<Vec<json::GetMasternodePaymentsResult>>{
let mut args = ["payments".into()];
self.call::<Vec<json::GetMasternodePaymentsResult>>("masternode", handle_defaults(&mut args, &[null()]))
}

/// Returns masternode status information
fn get_masternode_status(&self) -> Result<json::GetMasternodeStatusResult> {
self.call("masternode", &["status".into()])
}

/// Returns the list of masternode winners
fn get_masternode_winners(&self, count: &str, filter: &str) -> Result<HashMap<String, String>> {
self.call("masternode", &["winners".into(), count.into(), filter.into()])
}


}

/// 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,
}
Expand Down
41 changes: 41 additions & 0 deletions integration_test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ fn main() {
test_add_ban(&cl);
test_set_network_active(&cl);
test_stop(cl);
test_get_masternode_count(cl);
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) {
Expand Down Expand Up @@ -1136,3 +1141,39 @@ 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.total > 0);
assert!(masternode_count.enabled > 0);
assert!(masternode_count.total >= masternode_count.enabled);
}

fn test_get_masternode_list(cl: &Client) {
let masternode_list = rpc.get_masternode_list().unwrap();
}

fn test_get_masternode_outputs(cl: &Client) {
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);
}

fn test_get_masternode_status(cl: &Client) {
let masternode_status = rpc.get_masternode_status().unwrap();
}

fn test_get_masternode_winners(cl: &Client) {
let masternode_winners = rpc.get_masternode_winners("10", "").unwrap();
}
85 changes: 85 additions & 0 deletions json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,91 @@ pub struct GetMasternodeCountResult {
pub enabled: u32,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct GetMasternodeListJSON {
mayoreee marked this conversation as resolved.
Show resolved Hide resolved
#[serde(rename = "proTxHash")]
pub pro_tx_hash: String,
mayoreee marked this conversation as resolved.
Show resolved Hide resolved
pub address: String,
mayoreee marked this conversation as resolved.
Show resolved Hide resolved
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,
}

#[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<Payee>,
}

#[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<Masternode>,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct DMNState {
pub service: String,
#[serde(rename = "registeredHeight")]
mayoreee marked this conversation as resolved.
Show resolved Hide resolved
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,
mayoreee marked this conversation as resolved.
Show resolved Hide resolved
#[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")]
mayoreee marked this conversation as resolved.
Show resolved Hide resolved
pub pubkey_operator: String,
}

#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
pub struct GetMasternodeStatusResult {
mayoreee marked this conversation as resolved.
Show resolved Hide resolved
pub outpoint: String,
mayoreee marked this conversation as resolved.
Show resolved Hide resolved
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.

Expand Down