Skip to content

Commit 837205f

Browse files
committed
feat: add quorum_listextended_reversed to support legacy code
1 parent 9cb1184 commit 837205f

File tree

3 files changed

+124
-55
lines changed

3 files changed

+124
-55
lines changed

dash/src/hash_types.rs

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ mod newtypes {
7373
#[cfg(feature = "core-block-hash-use-x11")]
7474
use hashes::hash_x11;
7575
use hashes::hex::Error;
76-
use hashes::{Hash, hash_newtype, hash_newtype_no_ord, hash160, sha256, sha256d};
76+
use hashes::{hash160, hash_newtype, hash_newtype_no_ord, sha256, sha256d, Hash};
7777

7878
use crate::alloc::string::ToString;
7979
use crate::prelude::String;
@@ -168,7 +168,9 @@ mod newtypes {
168168
}
169169

170170
impl PartialOrd for ScoreHash {
171-
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
171+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
172+
Some(self.cmp(other))
173+
}
172174
}
173175

174176
/// A hash used to identify a quorum
@@ -211,10 +213,14 @@ mod newtypes {
211213

212214
impl Txid {
213215
/// Create a Txid from a string
214-
pub fn from_hex(s: &str) -> Result<Txid, Error> { Ok(Self(sha256d::Hash::from_str(s)?)) }
216+
pub fn from_hex(s: &str) -> Result<Txid, Error> {
217+
Ok(Self(sha256d::Hash::from_str(s)?))
218+
}
215219

216220
/// Convert a Txid to a string
217-
pub fn to_hex(&self) -> String { self.0.to_string() }
221+
pub fn to_hex(&self) -> String {
222+
self.0.to_string()
223+
}
218224
}
219225

220226
impl ProTxHash {
@@ -224,7 +230,9 @@ mod newtypes {
224230
}
225231

226232
/// Convert a ProTxHash to a string
227-
pub fn to_hex(&self) -> String { self.0.to_string() }
233+
pub fn to_hex(&self) -> String {
234+
self.0.to_string()
235+
}
228236
}
229237

230238
impl ScoreHash {
@@ -234,7 +242,9 @@ mod newtypes {
234242
}
235243

236244
/// Convert a ScoreHash to a string
237-
pub fn to_hex(&self) -> String { self.0.to_string() }
245+
pub fn to_hex(&self) -> String {
246+
self.0.to_string()
247+
}
238248

239249
/// Creates a score based on the optional confirmed hash and the quorum modifier.
240250
///
@@ -266,7 +276,9 @@ mod newtypes {
266276
}
267277

268278
/// Convert a ScoreHash to a string
269-
pub fn to_hex(&self) -> String { self.0.to_string() }
279+
pub fn to_hex(&self) -> String {
280+
self.0.to_string()
281+
}
270282

271283
/// Creates an ordering hash based on the quorum and request id.
272284
///
@@ -285,7 +297,9 @@ mod newtypes {
285297
}
286298

287299
impl Default for ConfirmedHash {
288-
fn default() -> Self { ConfirmedHash::from_byte_array([0; 32]) }
300+
fn default() -> Self {
301+
ConfirmedHash::from_byte_array([0; 32])
302+
}
289303
}
290304

291305
impl ConfirmedHash {
@@ -295,7 +309,9 @@ mod newtypes {
295309
}
296310

297311
/// Convert a ConfirmedHash to a string
298-
pub fn to_hex(&self) -> String { self.0.to_string() }
312+
pub fn to_hex(&self) -> String {
313+
self.0.to_string()
314+
}
299315
}
300316

301317
impl ConfirmedHashHashedWithProRegTx {
@@ -305,7 +321,9 @@ mod newtypes {
305321
}
306322

307323
/// Convert a ConfirmedHash to a string
308-
pub fn to_hex(&self) -> String { self.0.to_string() }
324+
pub fn to_hex(&self) -> String {
325+
self.0.to_string()
326+
}
309327

310328
/// Hashes the members
311329
pub fn hash_members(pro_tx_hash: &ProTxHash, confirmed_hash: &ConfirmedHash) -> Self {
@@ -329,7 +347,9 @@ mod newtypes {
329347
}
330348

331349
/// Convert a ConfirmedHash to a string
332-
pub fn to_hex(&self) -> String { self.0.to_string() }
350+
pub fn to_hex(&self) -> String {
351+
self.0.to_string()
352+
}
333353
}
334354

335355
impl InputsHash {
@@ -339,12 +359,16 @@ mod newtypes {
339359
}
340360

341361
/// Convert an InputsHash to a string
342-
pub fn to_hex(&self) -> String { self.0.to_string() }
362+
pub fn to_hex(&self) -> String {
363+
self.0.to_string()
364+
}
343365
}
344366

345367
impl SpecialTransactionPayloadHash {
346368
/// Create a SpecialTransactionPayloadHash from a string
347-
pub fn to_hex(&self) -> String { self.0.to_string() }
369+
pub fn to_hex(&self) -> String {
370+
self.0.to_string()
371+
}
348372
}
349373

350374
impl PubkeyHash {
@@ -354,6 +378,8 @@ mod newtypes {
354378
}
355379

356380
/// Convert a PubkeyHash to a string
357-
pub fn to_hex(&self) -> String { self.0.to_string() }
381+
pub fn to_hex(&self) -> String {
382+
self.0.to_string()
383+
}
358384
}
359385
}

rpc-client/src/client.rs

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ use serde;
2121
use serde_json::{self, Value};
2222

2323
use crate::dashcore::address::NetworkUnchecked;
24+
use crate::dashcore::secp256k1::hashes::hex::DisplayHex;
2425
use crate::dashcore::{block, consensus, ScriptBuf};
26+
use crate::error::*;
27+
use crate::json;
28+
use crate::queryable;
29+
use crate::Error::UnexpectedStructure;
2530
use dashcore::hashes::hex::FromHex;
2631
use dashcore::secp256k1::ecdsa::Signature;
2732
use dashcore::{
@@ -32,11 +37,6 @@ use dashcore_rpc_json::dashcore::{BlockHash, ChainLock};
3237
use dashcore_rpc_json::{ProTxInfo, ProTxListType, QuorumType};
3338
use hex::ToHex;
3439
use log::Level::{Debug, Trace, Warn};
35-
use crate::dashcore::secp256k1::hashes::hex::DisplayHex;
36-
use crate::error::*;
37-
use crate::json;
38-
use crate::queryable;
39-
use crate::Error::UnexpectedStructure;
4040

4141
/// Crate-specific Result type, shorthand for `std::result::Result` with our
4242
/// crate-specific Error type;
@@ -446,12 +446,10 @@ pub trait RpcApi: Sized {
446446
Ok(dashcore::consensus::encode::deserialize(&bytes)?)
447447
}
448448

449-
fn get_instant_locks(
450-
&self,
451-
txids: Vec<&dashcore::Txid>,
452-
) -> Result<Vec<String>> {
449+
fn get_instant_locks(&self, txids: Vec<&dashcore::Txid>) -> Result<Vec<String>> {
453450
let mut args = [into_json(txids)?];
454-
let instant_locks: Vec<String> = self.call("getislocks", handle_defaults(&mut args, &[null()]))?;
451+
let instant_locks: Vec<String> =
452+
self.call("getislocks", handle_defaults(&mut args, &[null()]))?;
455453
Ok(instant_locks)
456454
}
457455

@@ -1236,6 +1234,30 @@ pub trait RpcApi: Sized {
12361234
self.call::<json::ExtendedQuorumListResult>("quorum", handle_defaults(&mut args, &[]))
12371235
}
12381236

1237+
/// Returns an extended list of on-chain quorums with quorum hashes reversed
1238+
/// This is incorrect response format, but it was used by platform and we need to support it
1239+
fn get_quorum_listextended_reversed(
1240+
&self,
1241+
height: Option<u32>,
1242+
) -> Result<json::ExtendedQuorumListResult> {
1243+
let mut result = self.get_quorum_listextended(height)?;
1244+
1245+
result.quorums_by_type = result
1246+
.quorums_by_type
1247+
.into_iter()
1248+
.map(|(quorum_type, quorums)| {
1249+
let reversed_quorums = quorums
1250+
.into_iter()
1251+
.map(|(quorum_hash, details)| (quorum_hash.reverse(), details))
1252+
.collect();
1253+
1254+
(quorum_type, reversed_quorums)
1255+
})
1256+
.collect();
1257+
1258+
Ok(result)
1259+
}
1260+
12391261
/// Returns information about a specific quorum
12401262
fn get_quorum_info(
12411263
&self,
@@ -1397,7 +1419,11 @@ pub trait RpcApi: Sized {
13971419
}
13981420

13991421
/// Returns a returns detailed information about a deterministic masternode
1400-
fn get_protx_info(&self, protx_hash: &ProTxHash, block_hash: Option<&BlockHash>) -> Result<json::ProTxInfo> {
1422+
fn get_protx_info(
1423+
&self,
1424+
protx_hash: &ProTxHash,
1425+
block_hash: Option<&BlockHash>,
1426+
) -> Result<json::ProTxInfo> {
14011427
let mut args = ["info".into(), into_json(protx_hash.to_hex())?, opt_into_json(block_hash)?];
14021428

14031429
self.call::<json::ProTxInfo>("protx", handle_defaults(&mut args, &[null()]))

rpc-json/src/lib.rs

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,7 +3260,9 @@ mod tests {
32603260
use dashcore::hashes::Hash;
32613261
use serde_json::json;
32623262

3263-
use crate::{deserialize_u32_opt, MasternodeListDiff, MnSyncStatus};
3263+
use crate::{
3264+
deserialize_u32_opt, ExtendedQuorumListResult, MasternodeListDiff, MnSyncStatus, QuorumType,
3265+
};
32643266

32653267
#[test]
32663268
fn test_deserialize_u32_opt() {
@@ -3278,35 +3280,50 @@ mod tests {
32783280
assert_eq!(result.field, None);
32793281
}
32803282

3281-
// #[test]
3282-
// fn deserialize_quorum_listextended() {
3283-
// let json_list = r#"{
3284-
// "llmq_50_60": [
3285-
// {
3286-
// "000000da4509523408c751905d4e48df335e3ee565b4d2288800c7e51d592e2f": {
3287-
// "creationHeight": 871992,
3288-
// "minedBlockHash": "000000cd7f101437069956c0ca9f4180b41f0506827a828d57e85b35f215487e",
3289-
// "numValidMembers": 50,
3290-
// "healthRatio": "1.00"
3291-
// }
3292-
// }
3293-
// ]
3294-
// }"#;
3295-
// let result: ExtendedQuorumListResult =
3296-
// serde_json::from_str(json_list).expect("expected to deserialize json");
3297-
// println!("{:#?}", result);
3298-
// let first_type = result.quorums_by_type.get(&QuorumType::Llmq50_60).unwrap();
3299-
// let first_quorum = first_type.into_iter().nth(0).unwrap();
3300-
//
3301-
// assert_eq!(
3302-
// "000000da4509523408c751905d4e48df335e3ee565b4d2288800c7e51d592e2f",
3303-
// first_quorum.0.to_hex()
3304-
// );
3305-
// assert_eq!(
3306-
// "000000cd7f101437069956c0ca9f4180b41f0506827a828d57e85b35f215487e",
3307-
// first_quorum.1.mined_block_hash.to_hex()
3308-
// );
3309-
// }
3283+
#[test]
3284+
fn deserialize_quorum_listextended() {
3285+
let json_list = r#"{
3286+
"llmq_50_60": [
3287+
{
3288+
"000000da4509523408c751905d4e48df335e3ee565b4d2288800c7e51d592e2f": {
3289+
"creationHeight": 871992,
3290+
"minedBlockHash": "000000cd7f101437069956c0ca9f4180b41f0506827a828d57e85b35f215487e",
3291+
"numValidMembers": 50,
3292+
"healthRatio": "1.00"
3293+
}
3294+
}
3295+
]
3296+
}"#;
3297+
let result: ExtendedQuorumListResult =
3298+
serde_json::from_str(json_list).expect("expected to deserialize json");
3299+
let first_type = result.quorums_by_type.get(&QuorumType::Llmq50_60).unwrap();
3300+
let first_quorum = first_type.into_iter().nth(0).unwrap();
3301+
3302+
assert_eq!(
3303+
first_quorum.0.to_byte_array(),
3304+
[
3305+
47, 46, 89, 29, 229, 199, 0, 136, 40, 210, 180, 101, 229, 62, 94, 51, 223, 72, 78,
3306+
93, 144, 81, 199, 8, 52, 82, 9, 69, 218, 0, 0, 0,
3307+
]
3308+
);
3309+
3310+
assert_eq!(
3311+
first_quorum.1.mined_block_hash.to_byte_array(),
3312+
[
3313+
126, 72, 21, 242, 53, 91, 232, 87, 141, 130, 122, 130, 6, 5, 31, 180, 128, 65, 159,
3314+
202, 192, 86, 153, 6, 55, 20, 16, 127, 205, 0, 0, 0,
3315+
]
3316+
);
3317+
3318+
assert_eq!(
3319+
"000000da4509523408c751905d4e48df335e3ee565b4d2288800c7e51d592e2f",
3320+
first_quorum.0.to_string()
3321+
);
3322+
assert_eq!(
3323+
"000000cd7f101437069956c0ca9f4180b41f0506827a828d57e85b35f215487e",
3324+
first_quorum.1.mined_block_hash.to_string()
3325+
);
3326+
}
33103327

33113328
#[test]
33123329
fn deserialize_mn_listdiff() {

0 commit comments

Comments
 (0)