From 97a1342a312331fe5395151ef67f476242f1e179 Mon Sep 17 00:00:00 2001 From: Artem Pikulin Date: Wed, 9 Jun 2021 20:11:24 +0700 Subject: [PATCH 1/2] WIP. Got conflicting block header version between BTC/DOGE/QTUM. --- mm2src/coins/utxo/utxo_tests.rs | 28 ++ mm2src/mm2_bitcoin/chain/src/block_header.rs | 488 ++++++++++++++++++- 2 files changed, 499 insertions(+), 17 deletions(-) diff --git a/mm2src/coins/utxo/utxo_tests.rs b/mm2src/coins/utxo/utxo_tests.rs index 39c61146d0..319a53ffb1 100644 --- a/mm2src/coins/utxo/utxo_tests.rs +++ b/mm2src/coins/utxo/utxo_tests.rs @@ -2553,6 +2553,34 @@ fn btc_mtp() { assert_eq!(mtp, 1620019527); } +#[test] +fn qtum_mtp() { + let electrum = electrum_client_for_test(&[ + "electrum1.cipig.net:10050", + "electrum2.cipig.net:10050", + "electrum3.cipig.net:10050", + ]); + let mtp = electrum + .get_median_time_past(681659, NonZeroU64::new(11).unwrap()) + .wait() + .unwrap(); + assert_eq!(mtp, 1598854128); +} + +#[test] +fn zer_mtp() { + let electrum = electrum_client_for_test(&[ + "electrum1.cipig.net:10065", + "electrum2.cipig.net:10065", + "electrum3.cipig.net:10065", + ]); + let mtp = electrum + .get_median_time_past(1130915, NonZeroU64::new(11).unwrap()) + .wait() + .unwrap(); + assert_eq!(mtp, 1623240214); +} + #[test] #[ignore] fn send_and_refund_dex_fee() { diff --git a/mm2src/mm2_bitcoin/chain/src/block_header.rs b/mm2src/mm2_bitcoin/chain/src/block_header.rs index d7dfd41a01..569530c44c 100644 --- a/mm2src/mm2_bitcoin/chain/src/block_header.rs +++ b/mm2src/mm2_bitcoin/chain/src/block_header.rs @@ -1,11 +1,11 @@ use compact::Compact; use crypto::dhash256; -use hash::{EquihashSolution, H256}; +use hash::H256; use hex::FromHex; -use ser::{deserialize, serialize, CompactInteger, Deserializable, Reader, Serializable, Stream}; +use ser::{deserialize, serialize, Deserializable, Reader, Serializable, Stream}; use std::io; use transaction::{deserialize_tx, TxType}; -use Transaction; +use {OutPoint, Transaction}; #[derive(Clone, Debug, PartialEq)] pub enum BlockHeaderNonce { @@ -40,6 +40,7 @@ impl Serializable for BlockHeaderBits { const AUX_POW_VERSION_DOGE: u32 = 6422788; const AUX_POW_VERSION_SYS: u32 = 537919744; const MTP_POW_VERSION: u32 = 0x20001000u32; +const QTUM_BLOCK_HEADER_VERSION: u32 = 536870912; #[derive(Clone, Debug, PartialEq, Deserializable, Serializable)] pub struct MerkleBranch { @@ -83,13 +84,20 @@ pub struct BlockHeader { pub time: u32, pub bits: BlockHeaderBits, pub nonce: BlockHeaderNonce, - pub solution_size: Option, - pub solution: Option, + pub solution: Option>, /// https://en.bitcoin.it/wiki/Merged_mining_specification#Merged_mining_coinbase pub aux_pow: Option, /// https://github.com/firoorg/firo/blob/75f72d061eb793c39148c6d3f3eb5595159fdca0/src/primitives/block.h#L159 pub mtp_pow: Option, pub is_verus: bool, + /// https://github.com/qtumproject/qtum/blob/2792457a6a7b7922bc33ba934c3ed47a3ff66bf9/src/primitives/block.h#L30 + pub hash_state_root: Option, + /// https://github.com/qtumproject/qtum/blob/2792457a6a7b7922bc33ba934c3ed47a3ff66bf9/src/primitives/block.h#L31 + pub hash_utxo_root: Option, + /// https://github.com/qtumproject/qtum/blob/2792457a6a7b7922bc33ba934c3ed47a3ff66bf9/src/primitives/block.h#L33 + pub prevout_stake: Option, + /// https://github.com/qtumproject/qtum/blob/2792457a6a7b7922bc33ba934c3ed47a3ff66bf9/src/primitives/block.h#L34 + pub vch_block_sig_dlgt: Option>, } impl Serializable for BlockHeader { @@ -110,11 +118,8 @@ impl Serializable for BlockHeader { s.append(&self.time); s.append(&self.bits); s.append(&self.nonce); - if let Some(size) = &self.solution_size { - s.append(size); - } if let Some(sol) = &self.solution { - s.append(sol); + s.append_list(sol); } if let Some(pow) = &self.aux_pow { s.append(pow); @@ -122,6 +127,22 @@ impl Serializable for BlockHeader { if let Some(pow) = &self.mtp_pow { s.append(pow); } + + if let Some(root) = &self.hash_state_root { + s.append(root); + } + + if let Some(root) = &self.hash_utxo_root { + s.append(root); + } + + if let Some(prevout) = &self.prevout_stake { + s.append(prevout); + } + + if let Some(vec) = &self.vch_block_sig_dlgt { + s.append_list(vec); + } } } @@ -149,8 +170,7 @@ impl Deserializable for BlockHeader { } else { BlockHeaderNonce::U32(reader.read()?) }; - let solution_size = if version == 4 { Some(reader.read()?) } else { None }; - let solution = if version == 4 { Some(reader.read()?) } else { None }; + let solution = if version == 4 { Some(reader.read_list()?) } else { None }; // https://en.bitcoin.it/wiki/Merged_mining_specification#Merged_mining_coinbase let aux_pow = if version == AUX_POW_VERSION_DOGE || version == AUX_POW_VERSION_SYS { @@ -176,6 +196,18 @@ impl Deserializable for BlockHeader { None }; + let (hash_state_root, hash_utxo_root, prevout_stake, vch_block_sig_dlgt) = + if version == QTUM_BLOCK_HEADER_VERSION { + ( + Some(reader.read()?), + Some(reader.read()?), + Some(reader.read()?), + Some(reader.read_list()?), + ) + } else { + (None, None, None, None) + }; + Ok(BlockHeader { version, previous_header_hash, @@ -184,11 +216,14 @@ impl Deserializable for BlockHeader { time, bits, nonce, - solution_size, solution, aux_pow, mtp_pow, is_verus, + hash_state_root, + hash_utxo_root, + prevout_stake, + vch_block_sig_dlgt, }) } } @@ -203,8 +238,8 @@ impl From<&'static str> for BlockHeader { #[cfg(test)] mod tests { - use super::BlockHeader; - use block_header::{BlockHeaderBits, BlockHeaderNonce, AUX_POW_VERSION_DOGE, AUX_POW_VERSION_SYS, MTP_POW_VERSION}; + use block_header::{BlockHeader, BlockHeaderBits, BlockHeaderNonce, AUX_POW_VERSION_DOGE, AUX_POW_VERSION_SYS, + MTP_POW_VERSION, QTUM_BLOCK_HEADER_VERSION}; use hex::FromHex; use ser::{deserialize, serialize, serialize_list, Error as ReaderError, Reader, Stream}; @@ -219,10 +254,13 @@ mod tests { bits: BlockHeaderBits::Compact(5.into()), nonce: BlockHeaderNonce::U32(6), solution: None, - solution_size: None, aux_pow: None, mtp_pow: None, is_verus: false, + hash_state_root: None, + hash_utxo_root: None, + prevout_stake: None, + vch_block_sig_dlgt: None, }; let mut stream = Stream::default(); @@ -256,11 +294,14 @@ mod tests { time: 4, bits: BlockHeaderBits::Compact(5.into()), nonce: BlockHeaderNonce::U32(6), - solution_size: None, solution: None, aux_pow: None, mtp_pow: None, is_verus: false, + hash_state_root: None, + hash_utxo_root: None, + prevout_stake: None, + vch_block_sig_dlgt: None, }; assert_eq!(expected, reader.read().unwrap()); @@ -273,7 +314,23 @@ mod tests { let header_hex = "040000008e4e7283b71dd1572d220935db0a1654d1042e92378579f8abab67b143f93a02fa026610d2634b72ff729b9ea7850c0d2c25eeaf7a82878ca42a8e9912028863a2d8a734eb73a4dc734072dbfd12406f1e7121bfe0e3d6c10922495c44e5cc1c91185d5ee519011d0400b9caaf41d4b63a6ab55bb4e6925d46fc3adea7be37b713d3a615e7cf0000fd40050001a80fa65b9a46fdb1506a7a4d26f43e7995d69902489b9f6c4599c88f9c169605cc135258953da0d6299ada4ff81a76ad63c943261078d5dd1918f91cea68b65b7fc362e9df49ba57c2ea5c6dba91591c85eb0d59a1905ac66e2295b7a291a1695301489a3cc7310fd45f2b94e3b8d94f3051e9bbaada1e0641fcec6e0d6230e76753aa9574a3f3e28eaa085959beffd3231dbe1aeea3955328f3a973650a38e31632a4ffc7ec007a3345124c0b99114e2444b3ef0ada75adbd077b247bbf3229adcffbe95bc62daac88f96317d5768540b5db636f8c39a8529a736465ed830ab2c1bbddf523587abe14397a6f1835d248092c4b5b691a955572607093177a5911e317739187b41f4aa662aa6bca0401f1a0a77915ebb6947db686cff549c5f4e7b9dd93123b00a1ae8d411cfb13fa7674de21cbee8e9fc74e12aa6753b261eab3d9256c7c32cc9b16219dad73c61014e7d88d74d5e218f12e11bc47557347ff49a9ab4490647418d2a5c2da1df24d16dfb611173608fe4b10a357b0fa7a1918b9f2d7836c84bf05f384e1e678b2fdd47af0d8e66e739fe45209ede151a180aba1188058a0db093e30bc9851980cf6fbfa5adb612d1146905da662c3347d7e7e569a1041641049d951ab867bc0c6a3863c7667d43f596a849434958cee2b63dc8fa11bd0f38aa96df86ed66461993f64736345313053508c4e939506c08a766f5b6ed0950759f3901bbc4db3dc97e05bf20b9dda4ff242083db304a4e487ac2101b823998371542354e5d534b5b6ae6420cc19b11512108b61208f4d9a5a97263d2c060da893544dea6251bcadc682d2238af35f2b1c2f65a73b89a4e194f9e1eef6f0e5948ef8d0d2862f48fd3356126b00c6a2d3770ecd0d1a78fa34974b454f270b23d461e357c9356c19496522b59ff9d5b4608c542ff89e558798324021704b2cfe9f6c1a70906c43c7a690f16615f198d29fa647d84ce8461fa570b33e3eada2ed7d77e1f280a0d2e9f03c2e1db535d922b1759a191b417595f3c15d8e8b7f810527ff942e18443a3860e67ccba356809ecedc31c5d8db59c7e039dae4b53d126679e8ffa20cc26e8b9d229c8f6ee434ad053f5f4f5a94e249a13afb995aad82b4d90890187e516e114b168fc7c7e291b9738ea578a7bab0ba31030b14ba90b772b577806ea2d17856b0cb9e74254ba582a9f2638ea7ed2ca23be898c6108ff8f466b443537ed9ec56b8771bfbf0f2f6e1092a28a7fd182f111e1dbdd155ea82c6cb72d5f9e6518cc667b8226b5f5c6646125fc851e97cf125f48949f988ed37c4283072fc03dd1da3e35161e17f44c0e22c76f708bb66405737ef24176e291b4fc2eadab876115dc62d48e053a85f0ad132ef07ad5175b036fe39e1ad14fcdcdc6ac5b3daabe05161a72a50545dd812e0f9af133d061b726f491e904d89ee57811ef58d3bda151f577aed381963a30d91fb98dc49413300d132a7021a5e834e266b4ac982d76e00f43f5336b8e8028a0cacfa11813b01e50f71236a73a4c0d0757c1832b0680ada56c80edf070f438ab2bc587542f926ff8d3644b8b8a56c78576f127dec7aed9cb3e1bc2442f978a9df1dc3056a63e653132d0f419213d3cb86e7b61720de1aa3af4b3757a58156970da27560c6629257158452b9d5e4283dc6fe7df42d2fda3352d5b62ce5a984d912777c3b01837df8968a4d494db1b663e0e68197dbf196f21ea11a77095263dec548e2010460840231329d83978885ee2423e8b327785970e27c6c6d436157fb5b56119b19239edbb730ebae013d82c35df4a6e70818a74d1ef7a2e87c090ff90e32939f58ed24e85b492b5750fd2cd14b9b8517136b76b1cc6ccc6f6f027f65f1967a0eb4f32cd6e5d5315"; let header_bytes: Vec = header_hex.from_hex().unwrap(); let header: BlockHeader = deserialize(header_bytes.as_slice()).unwrap(); - let expected_header = BlockHeader { version: 4, previous_header_hash: "8e4e7283b71dd1572d220935db0a1654d1042e92378579f8abab67b143f93a02".into(), merkle_root_hash: "fa026610d2634b72ff729b9ea7850c0d2c25eeaf7a82878ca42a8e9912028863".into(), hash_final_sapling_root: Some("a2d8a734eb73a4dc734072dbfd12406f1e7121bfe0e3d6c10922495c44e5cc1c".into()), time: 1583159441, bits: BlockHeaderBits::U32(486611429), nonce: BlockHeaderNonce::H256("0400b9caaf41d4b63a6ab55bb4e6925d46fc3adea7be37b713d3a615e7cf0000".into()), solution_size: Some(1344u32.into()), solution: Some("0001a80fa65b9a46fdb1506a7a4d26f43e7995d69902489b9f6c4599c88f9c169605cc135258953da0d6299ada4ff81a76ad63c943261078d5dd1918f91cea68b65b7fc362e9df49ba57c2ea5c6dba91591c85eb0d59a1905ac66e2295b7a291a1695301489a3cc7310fd45f2b94e3b8d94f3051e9bbaada1e0641fcec6e0d6230e76753aa9574a3f3e28eaa085959beffd3231dbe1aeea3955328f3a973650a38e31632a4ffc7ec007a3345124c0b99114e2444b3ef0ada75adbd077b247bbf3229adcffbe95bc62daac88f96317d5768540b5db636f8c39a8529a736465ed830ab2c1bbddf523587abe14397a6f1835d248092c4b5b691a955572607093177a5911e317739187b41f4aa662aa6bca0401f1a0a77915ebb6947db686cff549c5f4e7b9dd93123b00a1ae8d411cfb13fa7674de21cbee8e9fc74e12aa6753b261eab3d9256c7c32cc9b16219dad73c61014e7d88d74d5e218f12e11bc47557347ff49a9ab4490647418d2a5c2da1df24d16dfb611173608fe4b10a357b0fa7a1918b9f2d7836c84bf05f384e1e678b2fdd47af0d8e66e739fe45209ede151a180aba1188058a0db093e30bc9851980cf6fbfa5adb612d1146905da662c3347d7e7e569a1041641049d951ab867bc0c6a3863c7667d43f596a849434958cee2b63dc8fa11bd0f38aa96df86ed66461993f64736345313053508c4e939506c08a766f5b6ed0950759f3901bbc4db3dc97e05bf20b9dda4ff242083db304a4e487ac2101b823998371542354e5d534b5b6ae6420cc19b11512108b61208f4d9a5a97263d2c060da893544dea6251bcadc682d2238af35f2b1c2f65a73b89a4e194f9e1eef6f0e5948ef8d0d2862f48fd3356126b00c6a2d3770ecd0d1a78fa34974b454f270b23d461e357c9356c19496522b59ff9d5b4608c542ff89e558798324021704b2cfe9f6c1a70906c43c7a690f16615f198d29fa647d84ce8461fa570b33e3eada2ed7d77e1f280a0d2e9f03c2e1db535d922b1759a191b417595f3c15d8e8b7f810527ff942e18443a3860e67ccba356809ecedc31c5d8db59c7e039dae4b53d126679e8ffa20cc26e8b9d229c8f6ee434ad053f5f4f5a94e249a13afb995aad82b4d90890187e516e114b168fc7c7e291b9738ea578a7bab0ba31030b14ba90b772b577806ea2d17856b0cb9e74254ba582a9f2638ea7ed2ca23be898c6108ff8f466b443537ed9ec56b8771bfbf0f2f6e1092a28a7fd182f111e1dbdd155ea82c6cb72d5f9e6518cc667b8226b5f5c6646125fc851e97cf125f48949f988ed37c4283072fc03dd1da3e35161e17f44c0e22c76f708bb66405737ef24176e291b4fc2eadab876115dc62d48e053a85f0ad132ef07ad5175b036fe39e1ad14fcdcdc6ac5b3daabe05161a72a50545dd812e0f9af133d061b726f491e904d89ee57811ef58d3bda151f577aed381963a30d91fb98dc49413300d132a7021a5e834e266b4ac982d76e00f43f5336b8e8028a0cacfa11813b01e50f71236a73a4c0d0757c1832b0680ada56c80edf070f438ab2bc587542f926ff8d3644b8b8a56c78576f127dec7aed9cb3e1bc2442f978a9df1dc3056a63e653132d0f419213d3cb86e7b61720de1aa3af4b3757a58156970da27560c6629257158452b9d5e4283dc6fe7df42d2fda3352d5b62ce5a984d912777c3b01837df8968a4d494db1b663e0e68197dbf196f21ea11a77095263dec548e2010460840231329d83978885ee2423e8b327785970e27c6c6d436157fb5b56119b19239edbb730ebae013d82c35df4a6e70818a74d1ef7a2e87c090ff90e32939f58ed24e85b492b5750fd2cd14b9b8517136b76b1cc6ccc6f6f027f65f1967a0eb4f32cd6e5d5315".into()), aux_pow: None, mtp_pow: None, is_verus: false }; + let expected_header = BlockHeader { + version: 4, + previous_header_hash: "8e4e7283b71dd1572d220935db0a1654d1042e92378579f8abab67b143f93a02".into(), + merkle_root_hash: "fa026610d2634b72ff729b9ea7850c0d2c25eeaf7a82878ca42a8e9912028863".into(), + hash_final_sapling_root: Some("a2d8a734eb73a4dc734072dbfd12406f1e7121bfe0e3d6c10922495c44e5cc1c".into()), + time: 1583159441, + bits: BlockHeaderBits::U32(486611429), + nonce: BlockHeaderNonce::H256("0400b9caaf41d4b63a6ab55bb4e6925d46fc3adea7be37b713d3a615e7cf0000".into()), + solution: Some("0001a80fa65b9a46fdb1506a7a4d26f43e7995d69902489b9f6c4599c88f9c169605cc135258953da0d6299ada4ff81a76ad63c943261078d5dd1918f91cea68b65b7fc362e9df49ba57c2ea5c6dba91591c85eb0d59a1905ac66e2295b7a291a1695301489a3cc7310fd45f2b94e3b8d94f3051e9bbaada1e0641fcec6e0d6230e76753aa9574a3f3e28eaa085959beffd3231dbe1aeea3955328f3a973650a38e31632a4ffc7ec007a3345124c0b99114e2444b3ef0ada75adbd077b247bbf3229adcffbe95bc62daac88f96317d5768540b5db636f8c39a8529a736465ed830ab2c1bbddf523587abe14397a6f1835d248092c4b5b691a955572607093177a5911e317739187b41f4aa662aa6bca0401f1a0a77915ebb6947db686cff549c5f4e7b9dd93123b00a1ae8d411cfb13fa7674de21cbee8e9fc74e12aa6753b261eab3d9256c7c32cc9b16219dad73c61014e7d88d74d5e218f12e11bc47557347ff49a9ab4490647418d2a5c2da1df24d16dfb611173608fe4b10a357b0fa7a1918b9f2d7836c84bf05f384e1e678b2fdd47af0d8e66e739fe45209ede151a180aba1188058a0db093e30bc9851980cf6fbfa5adb612d1146905da662c3347d7e7e569a1041641049d951ab867bc0c6a3863c7667d43f596a849434958cee2b63dc8fa11bd0f38aa96df86ed66461993f64736345313053508c4e939506c08a766f5b6ed0950759f3901bbc4db3dc97e05bf20b9dda4ff242083db304a4e487ac2101b823998371542354e5d534b5b6ae6420cc19b11512108b61208f4d9a5a97263d2c060da893544dea6251bcadc682d2238af35f2b1c2f65a73b89a4e194f9e1eef6f0e5948ef8d0d2862f48fd3356126b00c6a2d3770ecd0d1a78fa34974b454f270b23d461e357c9356c19496522b59ff9d5b4608c542ff89e558798324021704b2cfe9f6c1a70906c43c7a690f16615f198d29fa647d84ce8461fa570b33e3eada2ed7d77e1f280a0d2e9f03c2e1db535d922b1759a191b417595f3c15d8e8b7f810527ff942e18443a3860e67ccba356809ecedc31c5d8db59c7e039dae4b53d126679e8ffa20cc26e8b9d229c8f6ee434ad053f5f4f5a94e249a13afb995aad82b4d90890187e516e114b168fc7c7e291b9738ea578a7bab0ba31030b14ba90b772b577806ea2d17856b0cb9e74254ba582a9f2638ea7ed2ca23be898c6108ff8f466b443537ed9ec56b8771bfbf0f2f6e1092a28a7fd182f111e1dbdd155ea82c6cb72d5f9e6518cc667b8226b5f5c6646125fc851e97cf125f48949f988ed37c4283072fc03dd1da3e35161e17f44c0e22c76f708bb66405737ef24176e291b4fc2eadab876115dc62d48e053a85f0ad132ef07ad5175b036fe39e1ad14fcdcdc6ac5b3daabe05161a72a50545dd812e0f9af133d061b726f491e904d89ee57811ef58d3bda151f577aed381963a30d91fb98dc49413300d132a7021a5e834e266b4ac982d76e00f43f5336b8e8028a0cacfa11813b01e50f71236a73a4c0d0757c1832b0680ada56c80edf070f438ab2bc587542f926ff8d3644b8b8a56c78576f127dec7aed9cb3e1bc2442f978a9df1dc3056a63e653132d0f419213d3cb86e7b61720de1aa3af4b3757a58156970da27560c6629257158452b9d5e4283dc6fe7df42d2fda3352d5b62ce5a984d912777c3b01837df8968a4d494db1b663e0e68197dbf196f21ea11a77095263dec548e2010460840231329d83978885ee2423e8b327785970e27c6c6d436157fb5b56119b19239edbb730ebae013d82c35df4a6e70818a74d1ef7a2e87c090ff90e32939f58ed24e85b492b5750fd2cd14b9b8517136b76b1cc6ccc6f6f027f65f1967a0eb4f32cd6e5d5315".from_hex().unwrap()), + aux_pow: None, + mtp_pow: None, + is_verus: false, + hash_state_root: None, + hash_utxo_root: None, + prevout_stake: None, + vch_block_sig_dlgt: None + }; assert_eq!(expected_header, header); let serialized = serialize(&header); assert_eq!(serialized.take(), header_bytes); @@ -1693,4 +1750,401 @@ mod tests { let serialized = serialize_list(&headers); assert_eq!(serialized.take(), headers_bytes); } + + #[test] + fn test_qtum_block_headers_serde_11() { + let headers_bytes: &[u8] = &[ + 11, 0, 0, 0, 32, 84, 248, 53, 90, 38, 181, 8, 110, 19, 148, 91, 169, 240, 150, 182, 184, 55, 183, 121, 139, + 25, 204, 109, 86, 254, 164, 73, 253, 131, 248, 209, 188, 139, 217, 156, 97, 217, 113, 70, 233, 134, 46, + 198, 35, 63, 42, 245, 207, 162, 38, 194, 198, 192, 140, 187, 207, 133, 13, 129, 230, 129, 220, 75, 222, + 176, 146, 76, 95, 177, 152, 8, 26, 0, 0, 0, 0, 164, 45, 100, 130, 183, 211, 232, 228, 203, 167, 25, 125, + 44, 76, 114, 241, 2, 147, 221, 153, 106, 45, 219, 226, 118, 157, 78, 245, 205, 54, 2, 117, 221, 178, 135, + 247, 109, 175, 212, 234, 59, 84, 109, 232, 193, 212, 156, 39, 188, 164, 193, 160, 82, 18, 71, 17, 208, 172, + 132, 193, 80, 153, 114, 158, 15, 20, 53, 111, 205, 1, 11, 201, 236, 155, 27, 181, 249, 145, 163, 19, 65, + 200, 247, 5, 194, 63, 159, 11, 94, 197, 229, 167, 139, 202, 32, 80, 1, 0, 0, 0, 65, 32, 92, 171, 222, 183, + 152, 10, 131, 119, 237, 132, 198, 202, 122, 29, 94, 254, 157, 167, 79, 205, 158, 137, 195, 88, 213, 73, + 144, 217, 100, 206, 126, 143, 85, 78, 221, 95, 221, 36, 237, 168, 232, 153, 228, 73, 229, 98, 122, 42, 183, + 156, 95, 27, 182, 154, 214, 107, 102, 166, 48, 240, 204, 100, 193, 194, 0, 0, 0, 32, 45, 180, 196, 69, 152, + 237, 209, 202, 136, 123, 0, 224, 112, 199, 234, 35, 207, 231, 127, 11, 121, 45, 143, 218, 163, 186, 35, + 199, 141, 14, 74, 88, 7, 33, 4, 226, 55, 47, 177, 47, 110, 197, 214, 234, 245, 51, 145, 247, 103, 104, 44, + 8, 187, 218, 62, 29, 13, 248, 242, 138, 54, 127, 53, 231, 96, 147, 76, 95, 144, 135, 8, 26, 0, 0, 0, 0, + 164, 45, 100, 130, 183, 211, 232, 228, 203, 167, 25, 125, 44, 76, 114, 241, 2, 147, 221, 153, 106, 45, 219, + 226, 118, 157, 78, 245, 205, 54, 2, 117, 221, 178, 135, 247, 109, 175, 212, 234, 59, 84, 109, 232, 193, + 212, 156, 39, 188, 164, 193, 160, 82, 18, 71, 17, 208, 172, 132, 193, 80, 153, 114, 158, 80, 135, 235, 188, + 117, 127, 200, 73, 221, 83, 176, 97, 106, 109, 59, 128, 85, 242, 43, 48, 238, 63, 137, 154, 56, 14, 115, + 58, 175, 28, 138, 57, 2, 0, 0, 0, 65, 31, 186, 207, 83, 249, 74, 45, 37, 73, 208, 10, 137, 176, 39, 197, + 207, 213, 88, 27, 14, 93, 67, 22, 25, 49, 127, 113, 107, 80, 176, 145, 37, 195, 10, 76, 222, 67, 18, 177, + 208, 254, 88, 6, 68, 187, 19, 27, 73, 91, 181, 14, 111, 217, 203, 56, 72, 169, 238, 213, 94, 194, 96, 226, + 68, 113, 0, 0, 0, 32, 254, 42, 73, 106, 64, 102, 80, 104, 98, 135, 2, 229, 153, 170, 1, 70, 29, 80, 143, 2, + 163, 60, 44, 244, 103, 52, 26, 107, 6, 112, 166, 56, 113, 220, 182, 182, 188, 181, 197, 197, 119, 209, 224, + 158, 254, 47, 87, 212, 249, 238, 104, 241, 244, 149, 78, 212, 111, 16, 167, 142, 33, 73, 77, 119, 128, 147, + 76, 95, 88, 187, 8, 26, 0, 0, 0, 0, 164, 45, 100, 130, 183, 211, 232, 228, 203, 167, 25, 125, 44, 76, 114, + 241, 2, 147, 221, 153, 106, 45, 219, 226, 118, 157, 78, 245, 205, 54, 2, 117, 221, 178, 135, 247, 109, 175, + 212, 234, 59, 84, 109, 232, 193, 212, 156, 39, 188, 164, 193, 160, 82, 18, 71, 17, 208, 172, 132, 193, 80, + 153, 114, 158, 126, 41, 219, 12, 226, 204, 246, 250, 17, 137, 175, 134, 219, 249, 81, 218, 137, 144, 42, + 247, 122, 166, 11, 44, 209, 104, 178, 15, 109, 190, 33, 87, 2, 0, 0, 0, 65, 31, 108, 153, 195, 77, 192, + 145, 175, 143, 212, 238, 126, 172, 170, 162, 16, 228, 145, 227, 200, 136, 15, 80, 33, 20, 38, 18, 89, 242, + 182, 42, 209, 13, 40, 27, 250, 101, 148, 23, 66, 147, 8, 195, 250, 236, 251, 196, 46, 44, 181, 57, 83, 79, + 47, 218, 187, 118, 68, 93, 82, 187, 2, 179, 100, 148, 0, 0, 0, 32, 114, 126, 145, 132, 68, 36, 217, 64, + 205, 174, 182, 251, 51, 227, 180, 169, 224, 72, 51, 225, 42, 196, 116, 30, 173, 49, 189, 184, 227, 66, 129, + 101, 180, 184, 146, 146, 241, 21, 238, 45, 89, 85, 67, 227, 13, 36, 3, 125, 197, 178, 96, 249, 224, 40, + 223, 148, 4, 8, 182, 35, 5, 233, 25, 139, 176, 147, 76, 95, 250, 84, 8, 26, 0, 0, 0, 0, 164, 45, 100, 130, + 183, 211, 232, 228, 203, 167, 25, 125, 44, 76, 114, 241, 2, 147, 221, 153, 106, 45, 219, 226, 118, 157, 78, + 245, 205, 54, 2, 117, 221, 178, 135, 247, 109, 175, 212, 234, 59, 84, 109, 232, 193, 212, 156, 39, 188, + 164, 193, 160, 82, 18, 71, 17, 208, 172, 132, 193, 80, 153, 114, 158, 233, 212, 67, 169, 198, 132, 228, + 111, 9, 40, 203, 56, 94, 145, 97, 13, 117, 149, 132, 178, 20, 128, 133, 48, 186, 154, 73, 251, 150, 89, + 142, 201, 1, 0, 0, 0, 65, 32, 223, 7, 71, 175, 243, 162, 41, 40, 153, 243, 225, 59, 69, 79, 111, 5, 1, 0, + 249, 113, 228, 127, 29, 81, 245, 130, 248, 235, 28, 41, 152, 3, 56, 220, 165, 190, 245, 222, 211, 120, 242, + 233, 226, 200, 93, 196, 84, 121, 56, 87, 104, 184, 55, 228, 167, 245, 57, 139, 111, 119, 240, 45, 144, 99, + 0, 0, 0, 32, 148, 10, 172, 208, 86, 229, 240, 133, 0, 72, 98, 247, 241, 120, 3, 170, 194, 55, 84, 91, 231, + 178, 107, 15, 109, 176, 56, 73, 240, 31, 136, 4, 133, 192, 185, 41, 241, 137, 142, 220, 180, 134, 114, 77, + 14, 104, 169, 186, 60, 73, 219, 216, 41, 147, 140, 228, 239, 168, 51, 123, 128, 32, 84, 72, 224, 147, 76, + 95, 67, 3, 8, 26, 0, 0, 0, 0, 164, 45, 100, 130, 183, 211, 232, 228, 203, 167, 25, 125, 44, 76, 114, 241, + 2, 147, 221, 153, 106, 45, 219, 226, 118, 157, 78, 245, 205, 54, 2, 117, 221, 178, 135, 247, 109, 175, 212, + 234, 59, 84, 109, 232, 193, 212, 156, 39, 188, 164, 193, 160, 82, 18, 71, 17, 208, 172, 132, 193, 80, 153, + 114, 158, 156, 139, 183, 171, 75, 206, 255, 142, 247, 23, 198, 102, 54, 132, 174, 122, 65, 12, 121, 102, + 112, 40, 3, 101, 15, 23, 95, 165, 211, 181, 138, 45, 28, 0, 0, 0, 130, 31, 55, 154, 187, 125, 213, 81, 206, + 220, 143, 45, 236, 223, 185, 22, 130, 128, 236, 228, 132, 162, 252, 96, 93, 149, 58, 215, 198, 73, 164, + 132, 85, 225, 126, 118, 14, 80, 141, 207, 245, 11, 166, 9, 30, 131, 93, 243, 236, 109, 50, 160, 109, 244, + 33, 75, 82, 52, 229, 142, 101, 41, 74, 124, 255, 255, 31, 24, 191, 133, 48, 252, 149, 19, 178, 127, 244, + 30, 195, 70, 141, 215, 201, 141, 251, 86, 103, 67, 138, 87, 169, 64, 100, 252, 185, 212, 22, 57, 197, 88, + 41, 62, 229, 249, 209, 225, 58, 58, 182, 112, 147, 181, 240, 177, 154, 26, 227, 16, 131, 4, 135, 93, 49, + 83, 75, 86, 217, 150, 110, 78, 67, 0, 0, 0, 32, 108, 83, 240, 180, 48, 164, 126, 147, 244, 99, 248, 43, + 188, 112, 176, 142, 222, 159, 109, 17, 9, 179, 13, 180, 101, 252, 238, 221, 51, 156, 223, 149, 123, 150, + 111, 239, 239, 203, 72, 143, 98, 240, 161, 96, 220, 56, 183, 60, 162, 0, 185, 24, 63, 101, 110, 76, 133, + 126, 2, 129, 65, 90, 34, 251, 240, 147, 76, 95, 173, 180, 7, 26, 0, 0, 0, 0, 164, 45, 100, 130, 183, 211, + 232, 228, 203, 167, 25, 125, 44, 76, 114, 241, 2, 147, 221, 153, 106, 45, 219, 226, 118, 157, 78, 245, 205, + 54, 2, 117, 221, 178, 135, 247, 109, 175, 212, 234, 59, 84, 109, 232, 193, 212, 156, 39, 188, 164, 193, + 160, 82, 18, 71, 17, 208, 172, 132, 193, 80, 153, 114, 158, 112, 182, 36, 39, 191, 36, 13, 247, 234, 4, 29, + 108, 116, 115, 176, 235, 149, 11, 6, 140, 182, 31, 215, 148, 229, 78, 213, 202, 210, 179, 192, 88, 1, 0, 0, + 0, 65, 31, 100, 150, 146, 162, 176, 72, 154, 202, 37, 120, 254, 171, 246, 43, 124, 147, 2, 135, 132, 183, + 89, 20, 12, 37, 7, 89, 82, 7, 220, 56, 145, 205, 53, 233, 89, 193, 160, 182, 113, 234, 225, 132, 217, 76, + 41, 44, 82, 149, 235, 116, 91, 36, 248, 37, 161, 47, 141, 216, 189, 102, 76, 7, 76, 32, 0, 0, 0, 32, 176, + 49, 240, 249, 175, 178, 209, 115, 195, 57, 234, 108, 161, 102, 76, 225, 166, 98, 179, 144, 108, 125, 133, + 128, 161, 115, 187, 237, 163, 219, 130, 154, 246, 86, 242, 85, 69, 211, 161, 86, 102, 40, 130, 37, 227, 88, + 109, 111, 20, 182, 132, 45, 227, 98, 180, 18, 113, 162, 30, 160, 140, 83, 190, 88, 96, 148, 76, 95, 177, + 75, 7, 26, 0, 0, 0, 0, 164, 45, 100, 130, 183, 211, 232, 228, 203, 167, 25, 125, 44, 76, 114, 241, 2, 147, + 221, 153, 106, 45, 219, 226, 118, 157, 78, 245, 205, 54, 2, 117, 221, 178, 135, 247, 109, 175, 212, 234, + 59, 84, 109, 232, 193, 212, 156, 39, 188, 164, 193, 160, 82, 18, 71, 17, 208, 172, 132, 193, 80, 153, 114, + 158, 225, 158, 3, 111, 51, 13, 178, 17, 13, 89, 241, 15, 46, 217, 133, 227, 101, 15, 233, 11, 34, 56, 167, + 181, 128, 104, 138, 211, 30, 126, 78, 104, 1, 0, 0, 0, 65, 31, 221, 135, 0, 218, 137, 174, 200, 234, 25, + 246, 71, 164, 146, 218, 162, 123, 159, 103, 84, 224, 119, 27, 28, 7, 87, 170, 187, 161, 245, 25, 76, 218, + 94, 97, 76, 130, 28, 2, 84, 190, 101, 84, 110, 157, 182, 201, 0, 246, 20, 226, 134, 30, 125, 40, 104, 191, + 28, 221, 248, 155, 252, 30, 198, 51, 0, 0, 0, 32, 173, 216, 94, 63, 96, 82, 158, 179, 106, 63, 161, 252, + 219, 233, 142, 34, 58, 85, 55, 251, 38, 166, 227, 118, 195, 106, 137, 120, 137, 29, 120, 156, 108, 185, + 238, 156, 201, 134, 140, 72, 44, 50, 172, 96, 81, 201, 40, 49, 47, 144, 1, 62, 34, 68, 198, 21, 131, 190, + 235, 30, 58, 139, 193, 199, 224, 149, 76, 95, 40, 61, 7, 26, 0, 0, 0, 0, 164, 45, 100, 130, 183, 211, 232, + 228, 203, 167, 25, 125, 44, 76, 114, 241, 2, 147, 221, 153, 106, 45, 219, 226, 118, 157, 78, 245, 205, 54, + 2, 117, 221, 178, 135, 247, 109, 175, 212, 234, 59, 84, 109, 232, 193, 212, 156, 39, 188, 164, 193, 160, + 82, 18, 71, 17, 208, 172, 132, 193, 80, 153, 114, 158, 159, 4, 3, 118, 76, 106, 199, 80, 166, 147, 76, 83, + 178, 58, 161, 160, 99, 234, 239, 226, 71, 129, 16, 154, 113, 142, 171, 25, 216, 81, 55, 67, 1, 0, 0, 0, 65, + 32, 146, 73, 82, 253, 190, 226, 250, 245, 235, 109, 221, 150, 114, 15, 225, 11, 36, 63, 115, 202, 119, 127, + 217, 191, 181, 51, 111, 146, 209, 80, 129, 155, 40, 154, 29, 193, 16, 63, 172, 152, 215, 59, 137, 20, 156, + 77, 9, 89, 22, 67, 160, 2, 193, 173, 247, 18, 90, 54, 251, 62, 167, 186, 197, 88, 0, 0, 0, 32, 108, 183, + 41, 174, 13, 230, 76, 231, 233, 110, 211, 167, 7, 107, 102, 16, 218, 49, 178, 102, 8, 144, 98, 44, 0, 23, + 31, 224, 222, 136, 91, 198, 105, 15, 233, 57, 85, 44, 115, 125, 77, 144, 28, 117, 110, 248, 145, 46, 187, + 121, 41, 104, 160, 26, 207, 90, 8, 237, 227, 200, 123, 254, 153, 110, 16, 150, 76, 95, 230, 51, 8, 26, 0, + 0, 0, 0, 164, 45, 100, 130, 183, 211, 232, 228, 203, 167, 25, 125, 44, 76, 114, 241, 2, 147, 221, 153, 106, + 45, 219, 226, 118, 157, 78, 245, 205, 54, 2, 117, 221, 178, 135, 247, 109, 175, 212, 234, 59, 84, 109, 232, + 193, 212, 156, 39, 188, 164, 193, 160, 82, 18, 71, 17, 208, 172, 132, 193, 80, 153, 114, 158, 16, 121, 152, + 51, 192, 203, 189, 183, 31, 30, 22, 171, 79, 85, 206, 192, 115, 82, 71, 28, 178, 28, 135, 6, 121, 164, 23, + 230, 88, 78, 64, 105, 2, 0, 0, 0, 65, 31, 75, 23, 186, 246, 44, 185, 94, 212, 150, 98, 117, 27, 27, 221, + 170, 5, 247, 36, 43, 26, 108, 131, 249, 144, 53, 54, 182, 159, 128, 24, 67, 93, 33, 242, 50, 81, 15, 233, + 179, 147, 13, 146, 178, 106, 123, 128, 98, 63, 160, 8, 199, 136, 15, 103, 125, 229, 132, 199, 75, 209, 61, + 14, 142, 50, 0, 0, 0, 32, 185, 1, 22, 170, 87, 98, 186, 17, 242, 169, 93, 39, 10, 188, 170, 150, 192, 235, + 131, 77, 180, 153, 186, 73, 231, 123, 166, 13, 63, 194, 6, 144, 79, 174, 64, 113, 102, 126, 213, 254, 151, + 115, 10, 85, 113, 140, 70, 20, 212, 111, 251, 108, 161, 105, 88, 0, 102, 21, 17, 4, 161, 50, 228, 65, 160, + 150, 76, 95, 115, 227, 7, 26, 0, 0, 0, 0, 164, 45, 100, 130, 183, 211, 232, 228, 203, 167, 25, 125, 44, 76, + 114, 241, 2, 147, 221, 153, 106, 45, 219, 226, 118, 157, 78, 245, 205, 54, 2, 117, 221, 178, 135, 247, 109, + 175, 212, 234, 59, 84, 109, 232, 193, 212, 156, 39, 188, 164, 193, 160, 82, 18, 71, 17, 208, 172, 132, 193, + 80, 153, 114, 158, 60, 42, 198, 17, 174, 7, 59, 141, 168, 12, 37, 8, 135, 23, 213, 20, 248, 186, 220, 198, + 11, 55, 199, 189, 36, 223, 29, 227, 255, 89, 200, 128, 2, 0, 0, 0, 65, 31, 96, 101, 239, 29, 169, 30, 193, + 224, 111, 44, 10, 229, 143, 19, 197, 157, 145, 33, 54, 38, 49, 140, 48, 148, 128, 173, 16, 110, 67, 185, + 218, 121, 115, 63, 43, 162, 200, 77, 145, 51, 74, 251, 201, 45, 40, 59, 155, 230, 186, 142, 159, 184, 41, + 27, 74, 1, 14, 173, 203, 246, 62, 117, 28, 14, 0, 0, 0, 32, 104, 17, 117, 135, 192, 203, 57, 114, 17, 110, + 103, 215, 4, 58, 107, 192, 79, 21, 44, 76, 2, 8, 183, 228, 76, 177, 172, 196, 15, 40, 122, 2, 126, 168, 93, + 207, 82, 209, 116, 85, 112, 162, 58, 225, 83, 191, 142, 245, 174, 223, 98, 186, 187, 132, 28, 242, 21, 22, + 208, 239, 218, 219, 50, 150, 224, 150, 76, 95, 73, 243, 7, 26, 0, 0, 0, 0, 164, 45, 100, 130, 183, 211, + 232, 228, 203, 167, 25, 125, 44, 76, 114, 241, 2, 147, 221, 153, 106, 45, 219, 226, 118, 157, 78, 245, 205, + 54, 2, 117, 221, 178, 135, 247, 109, 175, 212, 234, 59, 84, 109, 232, 193, 212, 156, 39, 188, 164, 193, + 160, 82, 18, 71, 17, 208, 172, 132, 193, 80, 153, 114, 158, 151, 207, 93, 166, 125, 159, 189, 9, 42, 152, + 28, 47, 11, 93, 73, 80, 156, 50, 201, 143, 162, 33, 205, 25, 158, 133, 161, 228, 67, 207, 109, 216, 2, 0, + 0, 0, 65, 31, 51, 71, 165, 69, 107, 96, 27, 47, 65, 155, 93, 145, 49, 183, 182, 228, 207, 33, 41, 124, 31, + 226, 1, 77, 51, 114, 115, 8, 152, 211, 49, 161, 62, 190, 80, 119, 154, 30, 193, 226, 46, 248, 169, 69, 226, + 86, 134, 101, 238, 115, 14, 63, 174, 123, 30, 7, 123, 174, 60, 13, 100, 49, 23, 123, + ]; + let mut reader = Reader::new(headers_bytes); + let headers = reader.read_list::().unwrap(); + for header in headers.iter() { + assert_eq!(header.version, QTUM_BLOCK_HEADER_VERSION); + } + let serialized = serialize_list(&headers); + assert_eq!(serialized.take(), headers_bytes); + } + + #[test] + fn test_zer_block_headers_serde_11() { + let headers_bytes: &[u8] = &[ + 11, 4, 0, 0, 0, 12, 31, 177, 243, 98, 47, 86, 82, 110, 153, 169, 148, 211, 117, 114, 54, 80, 129, 169, 243, + 56, 141, 237, 18, 155, 178, 228, 245, 86, 6, 0, 0, 248, 96, 174, 126, 114, 121, 252, 224, 11, 0, 214, 214, + 166, 106, 123, 99, 176, 203, 205, 143, 86, 202, 166, 74, 7, 116, 213, 102, 123, 230, 33, 93, 28, 194, 158, + 128, 255, 171, 220, 133, 139, 225, 108, 38, 25, 223, 68, 22, 199, 42, 33, 201, 82, 68, 139, 87, 250, 170, + 233, 53, 75, 189, 189, 96, 127, 171, 192, 96, 22, 124, 13, 30, 48, 0, 21, 196, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 2, 1, 2, 0, 253, 144, 1, 2, 116, 130, 132, 119, 206, 105, 12, + 86, 123, 18, 81, 150, 148, 143, 108, 115, 13, 206, 211, 112, 155, 212, 102, 72, 21, 50, 186, 60, 13, 252, + 17, 157, 69, 52, 162, 37, 28, 23, 212, 127, 182, 244, 51, 137, 3, 11, 236, 12, 93, 40, 141, 202, 192, 254, + 17, 14, 87, 165, 124, 60, 4, 37, 82, 238, 175, 29, 184, 49, 186, 81, 205, 245, 14, 33, 83, 31, 190, 245, + 154, 191, 229, 207, 158, 89, 109, 222, 54, 25, 122, 39, 39, 143, 141, 226, 221, 215, 108, 61, 190, 5, 12, + 131, 141, 2, 26, 3, 46, 100, 212, 178, 149, 167, 243, 85, 85, 194, 169, 62, 205, 234, 159, 144, 34, 226, + 12, 34, 4, 250, 84, 3, 226, 41, 213, 214, 68, 82, 152, 164, 158, 53, 150, 163, 134, 173, 185, 25, 191, 30, + 88, 10, 32, 166, 24, 209, 119, 209, 138, 106, 87, 129, 103, 178, 89, 14, 217, 172, 236, 197, 79, 56, 52, + 230, 197, 55, 32, 118, 198, 124, 163, 97, 43, 243, 163, 188, 99, 78, 195, 18, 37, 10, 145, 167, 126, 169, + 246, 157, 174, 41, 197, 3, 97, 8, 133, 173, 246, 164, 71, 159, 153, 2, 157, 209, 91, 69, 193, 118, 34, 216, + 190, 79, 242, 108, 57, 69, 30, 139, 247, 103, 248, 182, 10, 52, 225, 146, 100, 119, 56, 138, 62, 94, 98, + 138, 182, 52, 30, 229, 239, 206, 221, 6, 43, 4, 89, 177, 164, 221, 208, 40, 24, 60, 201, 162, 223, 3, 189, + 189, 98, 161, 33, 67, 73, 190, 11, 143, 14, 234, 47, 76, 26, 144, 3, 237, 198, 37, 90, 18, 2, 93, 84, 22, + 1, 152, 237, 114, 67, 42, 238, 56, 190, 6, 37, 70, 92, 156, 239, 145, 224, 31, 210, 26, 21, 49, 197, 43, 3, + 148, 111, 17, 234, 69, 165, 208, 7, 170, 7, 140, 166, 197, 227, 195, 139, 135, 196, 51, 88, 65, 80, 192, + 73, 1, 247, 156, 144, 227, 238, 141, 204, 177, 40, 27, 179, 172, 64, 7, 11, 148, 156, 31, 251, 129, 50, + 242, 43, 149, 98, 81, 159, 10, 42, 40, 91, 71, 127, 146, 30, 223, 87, 227, 159, 110, 158, 103, 149, 26, 25, + 173, 202, 90, 41, 95, 149, 9, 223, 157, 211, 191, 246, 237, 195, 4, 0, 0, 0, 183, 19, 227, 196, 219, 114, + 34, 159, 170, 142, 14, 29, 143, 244, 4, 235, 6, 189, 224, 115, 3, 38, 71, 154, 200, 206, 19, 222, 242, 3, + 0, 0, 0, 239, 187, 77, 126, 12, 71, 174, 10, 215, 7, 16, 213, 83, 8, 54, 212, 50, 202, 48, 3, 73, 82, 93, + 219, 120, 72, 139, 0, 220, 6, 225, 94, 211, 180, 239, 16, 221, 39, 220, 196, 255, 10, 113, 209, 66, 22, 50, + 106, 128, 200, 192, 110, 142, 38, 218, 211, 246, 27, 89, 177, 28, 156, 15, 197, 172, 192, 96, 158, 85, 13, + 30, 23, 255, 255, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 106, 246, + 75, 0, 253, 144, 1, 1, 151, 12, 120, 248, 148, 72, 78, 146, 196, 196, 115, 196, 217, 228, 37, 90, 166, 85, + 238, 47, 73, 216, 225, 241, 5, 52, 5, 35, 118, 150, 53, 207, 219, 127, 184, 22, 69, 135, 135, 94, 28, 163, + 57, 155, 250, 50, 233, 25, 110, 19, 25, 48, 190, 215, 43, 21, 64, 234, 117, 236, 108, 114, 11, 61, 172, + 137, 209, 4, 203, 132, 192, 186, 31, 136, 34, 47, 141, 74, 87, 147, 54, 254, 113, 61, 169, 87, 146, 54, + 208, 14, 83, 186, 213, 45, 236, 44, 159, 34, 220, 7, 5, 207, 208, 42, 104, 83, 186, 24, 148, 208, 203, 64, + 236, 148, 88, 197, 147, 25, 196, 191, 115, 4, 33, 57, 23, 49, 48, 70, 236, 208, 220, 75, 178, 60, 152, 227, + 51, 143, 86, 90, 179, 88, 129, 209, 132, 29, 10, 54, 119, 18, 98, 49, 230, 191, 77, 94, 26, 22, 87, 153, + 124, 230, 96, 182, 115, 153, 72, 33, 173, 192, 143, 10, 117, 226, 21, 91, 96, 164, 225, 34, 137, 9, 164, + 73, 220, 224, 39, 149, 140, 126, 132, 138, 142, 54, 95, 147, 181, 47, 92, 1, 171, 168, 92, 98, 251, 236, + 168, 217, 119, 100, 122, 3, 88, 234, 83, 116, 175, 49, 83, 227, 55, 69, 105, 41, 6, 227, 156, 255, 221, + 132, 25, 174, 180, 57, 234, 35, 81, 176, 94, 37, 80, 8, 214, 111, 88, 239, 116, 106, 48, 10, 161, 172, 172, + 86, 138, 88, 234, 164, 55, 152, 182, 164, 131, 236, 6, 39, 242, 9, 206, 123, 167, 44, 230, 220, 16, 109, + 159, 234, 200, 199, 216, 44, 205, 89, 237, 80, 3, 11, 222, 70, 110, 246, 213, 88, 123, 157, 33, 22, 42, 28, + 78, 145, 40, 6, 224, 46, 45, 106, 59, 83, 48, 84, 195, 144, 211, 84, 54, 53, 101, 97, 148, 228, 29, 59, 77, + 38, 207, 113, 85, 135, 102, 199, 244, 249, 30, 41, 213, 182, 72, 180, 69, 119, 182, 22, 38, 141, 163, 59, + 58, 43, 112, 144, 43, 192, 77, 19, 230, 249, 142, 45, 235, 243, 93, 33, 142, 90, 101, 175, 44, 159, 29, + 170, 255, 27, 45, 130, 141, 185, 192, 21, 244, 35, 113, 251, 190, 138, 230, 145, 167, 132, 229, 71, 49, + 226, 139, 237, 30, 44, 84, 4, 0, 0, 0, 25, 54, 48, 205, 202, 249, 148, 69, 32, 106, 2, 200, 17, 9, 65, 109, + 223, 158, 225, 145, 91, 107, 9, 30, 229, 191, 250, 188, 61, 2, 0, 0, 92, 16, 151, 21, 67, 223, 226, 188, + 207, 109, 93, 146, 165, 13, 183, 129, 42, 84, 20, 83, 195, 231, 194, 158, 54, 31, 4, 180, 223, 94, 115, + 163, 94, 211, 180, 239, 16, 221, 39, 220, 196, 255, 10, 113, 209, 66, 22, 50, 106, 128, 200, 192, 110, 142, + 38, 218, 211, 246, 27, 89, 177, 28, 156, 15, 11, 173, 192, 96, 74, 123, 13, 30, 80, 0, 0, 16, 201, 142, + 246, 139, 26, 203, 135, 126, 144, 253, 177, 172, 231, 128, 52, 200, 0, 0, 0, 0, 0, 0, 0, 0, 18, 20, 82, 16, + 253, 144, 1, 0, 98, 58, 238, 210, 37, 13, 102, 208, 109, 14, 78, 224, 246, 33, 246, 100, 139, 150, 126, + 159, 111, 157, 124, 99, 124, 181, 188, 253, 219, 110, 236, 117, 197, 154, 71, 160, 72, 77, 26, 44, 58, 143, + 146, 72, 141, 227, 237, 222, 144, 0, 237, 152, 97, 217, 218, 192, 65, 235, 209, 217, 35, 147, 47, 169, 105, + 183, 250, 106, 11, 124, 167, 169, 44, 226, 69, 27, 248, 209, 146, 143, 157, 245, 240, 190, 59, 102, 5, 177, + 233, 255, 75, 68, 151, 149, 81, 9, 218, 176, 220, 4, 71, 3, 116, 228, 35, 88, 143, 156, 23, 135, 145, 112, + 95, 165, 6, 201, 255, 249, 46, 73, 163, 254, 159, 164, 18, 53, 54, 206, 63, 102, 9, 190, 63, 47, 129, 84, + 33, 60, 238, 22, 69, 192, 252, 146, 137, 241, 5, 217, 132, 15, 28, 242, 71, 210, 232, 45, 91, 140, 151, 24, + 231, 211, 61, 90, 27, 43, 164, 9, 169, 147, 29, 211, 56, 0, 21, 146, 97, 67, 76, 163, 163, 105, 236, 83, + 210, 143, 228, 152, 253, 75, 237, 33, 41, 187, 85, 189, 234, 124, 37, 2, 6, 29, 146, 103, 216, 209, 159, + 81, 95, 162, 132, 211, 244, 83, 109, 32, 118, 234, 51, 168, 163, 49, 162, 54, 15, 24, 242, 208, 183, 2, + 150, 44, 197, 158, 39, 6, 180, 9, 46, 222, 138, 63, 225, 35, 3, 241, 151, 217, 16, 22, 195, 161, 141, 131, + 200, 19, 58, 118, 210, 63, 61, 178, 208, 223, 47, 209, 100, 37, 116, 233, 229, 45, 185, 38, 24, 9, 20, 16, + 129, 224, 149, 14, 250, 149, 226, 174, 2, 137, 167, 23, 149, 242, 197, 89, 60, 170, 179, 163, 229, 6, 57, + 252, 36, 124, 152, 154, 85, 103, 85, 227, 87, 84, 150, 188, 34, 178, 154, 27, 130, 73, 11, 240, 39, 24, 36, + 219, 153, 180, 160, 87, 212, 64, 175, 157, 24, 6, 133, 244, 219, 251, 106, 78, 85, 195, 67, 141, 63, 185, + 163, 99, 217, 61, 230, 110, 235, 44, 219, 119, 59, 243, 108, 6, 150, 132, 119, 125, 43, 187, 37, 111, 205, + 202, 37, 224, 100, 143, 9, 120, 63, 207, 169, 197, 192, 25, 73, 253, 199, 26, 32, 70, 92, 141, 154, 225, + 167, 251, 119, 79, 189, 4, 0, 0, 0, 114, 193, 23, 14, 189, 208, 241, 210, 235, 78, 212, 47, 134, 20, 144, + 100, 38, 190, 237, 130, 9, 48, 89, 240, 54, 102, 198, 194, 59, 5, 0, 0, 211, 36, 35, 72, 44, 129, 145, 176, + 255, 55, 44, 62, 107, 93, 244, 86, 133, 235, 53, 186, 186, 165, 211, 153, 159, 26, 114, 82, 138, 137, 156, + 124, 94, 211, 180, 239, 16, 221, 39, 220, 196, 255, 10, 113, 209, 66, 22, 50, 106, 128, 200, 192, 110, 142, + 38, 218, 211, 246, 27, 89, 177, 28, 156, 15, 67, 173, 192, 96, 27, 198, 13, 30, 7, 255, 255, 218, 79, 137, + 28, 45, 118, 239, 254, 181, 174, 148, 7, 252, 18, 231, 114, 232, 0, 0, 0, 0, 0, 0, 0, 0, 103, 58, 84, 197, + 253, 144, 1, 0, 22, 47, 117, 135, 99, 116, 184, 198, 159, 60, 27, 69, 70, 90, 116, 34, 226, 61, 137, 2, + 251, 176, 251, 186, 28, 61, 184, 33, 242, 241, 24, 21, 179, 45, 144, 171, 130, 97, 243, 30, 177, 215, 53, + 46, 117, 154, 174, 52, 26, 21, 165, 191, 125, 42, 29, 15, 21, 193, 116, 14, 59, 98, 52, 250, 210, 23, 11, + 237, 113, 30, 87, 210, 12, 52, 74, 49, 174, 39, 136, 46, 87, 106, 236, 172, 187, 95, 151, 38, 108, 53, 226, + 18, 95, 25, 194, 179, 220, 8, 76, 1, 137, 141, 100, 28, 34, 192, 221, 109, 7, 241, 168, 52, 89, 15, 86, + 224, 69, 238, 223, 49, 157, 137, 30, 61, 13, 25, 236, 118, 195, 125, 30, 211, 155, 88, 204, 205, 211, 73, + 172, 98, 201, 91, 185, 36, 212, 206, 192, 239, 26, 20, 50, 68, 125, 144, 56, 155, 10, 142, 252, 102, 169, + 98, 39, 176, 222, 116, 7, 157, 41, 224, 95, 27, 156, 227, 39, 118, 22, 166, 233, 21, 80, 97, 50, 152, 114, + 127, 148, 207, 60, 156, 0, 239, 165, 151, 234, 83, 18, 122, 226, 3, 12, 166, 240, 166, 35, 15, 252, 24, 95, + 65, 234, 231, 216, 12, 36, 181, 110, 178, 16, 252, 59, 61, 201, 64, 59, 27, 190, 255, 18, 49, 143, 138, 60, + 42, 19, 255, 170, 222, 69, 190, 112, 123, 251, 35, 160, 83, 243, 32, 246, 5, 95, 254, 209, 203, 90, 213, + 193, 58, 212, 123, 91, 64, 243, 7, 51, 26, 134, 12, 190, 197, 28, 225, 63, 68, 94, 105, 96, 53, 129, 10, + 41, 206, 169, 127, 240, 216, 150, 45, 181, 44, 233, 195, 187, 80, 106, 75, 227, 7, 207, 7, 25, 61, 125, + 214, 222, 2, 61, 38, 2, 82, 61, 132, 13, 8, 154, 159, 54, 206, 9, 106, 149, 188, 196, 172, 13, 10, 170, 33, + 24, 63, 148, 65, 111, 153, 205, 84, 50, 152, 120, 146, 123, 77, 90, 176, 78, 217, 102, 171, 222, 7, 164, + 94, 68, 239, 189, 139, 38, 248, 45, 14, 122, 209, 53, 105, 237, 130, 90, 20, 189, 237, 124, 226, 155, 189, + 12, 184, 61, 244, 228, 241, 221, 60, 203, 146, 104, 85, 54, 185, 207, 100, 63, 12, 166, 89, 14, 197, 196, + 160, 89, 4, 0, 0, 0, 184, 13, 53, 28, 34, 206, 18, 14, 222, 170, 140, 99, 78, 243, 94, 174, 97, 174, 111, + 14, 125, 29, 171, 104, 208, 11, 239, 124, 76, 8, 0, 0, 163, 177, 219, 26, 119, 147, 226, 246, 243, 113, 37, + 60, 204, 179, 185, 196, 168, 55, 45, 16, 218, 209, 48, 166, 181, 229, 6, 36, 42, 49, 246, 158, 220, 106, + 150, 246, 77, 156, 74, 126, 248, 136, 124, 100, 155, 18, 239, 188, 174, 15, 248, 45, 212, 253, 101, 40, + 112, 132, 179, 217, 252, 199, 171, 36, 126, 173, 192, 96, 224, 77, 14, 30, 111, 255, 255, 240, 99, 131, + 114, 93, 159, 74, 31, 46, 183, 246, 245, 171, 101, 56, 221, 66, 0, 0, 0, 0, 0, 0, 0, 0, 4, 36, 63, 170, + 253, 144, 1, 3, 72, 133, 111, 88, 251, 72, 85, 244, 138, 50, 160, 4, 183, 108, 221, 189, 44, 93, 245, 239, + 243, 208, 155, 182, 52, 30, 149, 75, 60, 248, 151, 164, 126, 157, 226, 116, 100, 70, 30, 79, 148, 24, 174, + 17, 88, 209, 100, 195, 220, 20, 106, 29, 147, 38, 170, 115, 177, 118, 90, 190, 211, 193, 199, 129, 133, + 137, 47, 53, 82, 240, 148, 228, 199, 185, 29, 119, 154, 54, 111, 193, 232, 180, 74, 91, 7, 125, 84, 92, 81, + 126, 24, 97, 21, 190, 226, 185, 28, 212, 230, 3, 86, 102, 164, 215, 243, 90, 80, 40, 110, 100, 72, 118, + 185, 41, 132, 81, 99, 245, 227, 192, 2, 242, 218, 21, 5, 235, 4, 193, 156, 179, 82, 43, 170, 158, 234, 75, + 84, 103, 90, 170, 91, 146, 193, 209, 94, 51, 165, 4, 196, 41, 14, 206, 193, 40, 58, 91, 25, 241, 185, 36, + 240, 147, 222, 249, 43, 179, 130, 6, 208, 119, 169, 124, 27, 3, 47, 160, 0, 109, 35, 1, 24, 143, 59, 153, + 209, 67, 164, 71, 75, 15, 253, 61, 213, 207, 248, 83, 173, 42, 249, 3, 238, 219, 245, 42, 42, 219, 178, + 129, 86, 134, 55, 134, 2, 220, 228, 242, 207, 206, 87, 237, 199, 255, 192, 114, 22, 107, 154, 42, 140, 254, + 52, 23, 190, 223, 175, 2, 213, 146, 39, 51, 186, 218, 114, 159, 77, 207, 202, 154, 206, 20, 251, 193, 87, + 70, 14, 232, 50, 150, 89, 25, 86, 194, 11, 241, 20, 166, 173, 165, 5, 192, 137, 242, 80, 141, 35, 228, 216, + 167, 142, 150, 92, 175, 93, 80, 141, 82, 56, 26, 229, 44, 242, 21, 54, 108, 223, 227, 186, 78, 243, 5, 124, + 34, 157, 15, 89, 41, 95, 245, 90, 45, 140, 81, 182, 74, 226, 124, 48, 21, 178, 222, 138, 242, 14, 34, 23, + 170, 140, 43, 10, 208, 150, 236, 163, 145, 167, 107, 54, 115, 233, 163, 142, 199, 143, 128, 139, 139, 238, + 67, 248, 17, 255, 60, 203, 76, 132, 209, 129, 3, 76, 63, 139, 85, 246, 39, 198, 119, 45, 138, 85, 61, 91, + 163, 179, 56, 41, 189, 91, 104, 98, 32, 87, 181, 1, 242, 74, 62, 214, 105, 197, 197, 79, 186, 133, 187, 15, + 215, 185, 194, 254, 4, 0, 0, 0, 219, 64, 41, 178, 38, 227, 244, 33, 187, 109, 253, 46, 216, 106, 143, 42, + 98, 135, 238, 171, 76, 37, 122, 65, 83, 168, 179, 80, 68, 14, 0, 0, 132, 247, 218, 58, 201, 127, 9, 93, + 233, 202, 222, 108, 154, 45, 1, 186, 2, 230, 67, 100, 145, 167, 142, 250, 182, 89, 108, 107, 254, 197, 142, + 219, 220, 106, 150, 246, 77, 156, 74, 126, 248, 136, 124, 100, 155, 18, 239, 188, 174, 15, 248, 45, 212, + 253, 101, 40, 112, 132, 179, 217, 252, 199, 171, 36, 22, 174, 192, 96, 77, 50, 14, 30, 48, 0, 21, 98, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 93, 135, 30, 1, 253, 144, 1, 2, 29, 14, + 28, 87, 38, 225, 216, 60, 211, 155, 93, 130, 168, 155, 11, 207, 111, 245, 143, 226, 219, 247, 145, 215, 65, + 164, 228, 224, 21, 29, 95, 146, 168, 182, 211, 142, 213, 247, 34, 219, 252, 69, 142, 79, 99, 239, 63, 107, + 138, 5, 6, 161, 85, 137, 184, 196, 57, 4, 202, 133, 126, 7, 60, 110, 190, 231, 253, 209, 217, 112, 89, 186, + 24, 113, 6, 229, 169, 26, 220, 46, 94, 23, 120, 30, 195, 127, 85, 47, 66, 164, 93, 98, 246, 34, 47, 243, + 129, 156, 53, 33, 155, 85, 218, 239, 7, 95, 39, 133, 212, 43, 186, 50, 56, 250, 145, 238, 71, 163, 130, + 225, 175, 212, 132, 109, 43, 135, 203, 105, 182, 183, 223, 120, 176, 185, 156, 228, 51, 212, 32, 100, 235, + 154, 93, 150, 47, 121, 87, 110, 175, 40, 191, 82, 198, 170, 151, 104, 77, 27, 217, 177, 81, 166, 114, 60, + 62, 82, 8, 34, 142, 99, 81, 249, 133, 86, 59, 246, 255, 189, 146, 124, 84, 186, 174, 252, 229, 8, 214, 29, + 224, 220, 91, 183, 245, 168, 216, 185, 103, 230, 83, 8, 211, 81, 8, 67, 126, 70, 90, 127, 217, 137, 119, + 242, 255, 144, 211, 116, 65, 28, 254, 33, 67, 88, 222, 105, 11, 69, 180, 154, 213, 111, 2, 221, 182, 97, + 239, 48, 177, 166, 16, 241, 83, 103, 58, 62, 172, 49, 212, 59, 145, 13, 104, 142, 80, 230, 31, 85, 153, + 208, 121, 124, 48, 65, 249, 131, 115, 250, 51, 192, 135, 223, 69, 25, 247, 136, 31, 92, 33, 205, 81, 8, + 122, 173, 7, 30, 188, 232, 82, 48, 81, 251, 154, 249, 168, 145, 209, 155, 175, 255, 180, 25, 166, 20, 112, + 30, 44, 143, 83, 61, 30, 60, 23, 20, 2, 27, 179, 224, 40, 241, 174, 20, 155, 19, 231, 81, 74, 48, 69, 197, + 87, 201, 19, 52, 239, 183, 9, 115, 122, 110, 229, 166, 199, 205, 150, 240, 186, 91, 133, 195, 204, 29, 160, + 89, 164, 199, 108, 163, 114, 20, 210, 83, 68, 69, 185, 163, 203, 159, 24, 177, 150, 165, 78, 243, 235, 41, + 92, 96, 109, 206, 62, 171, 44, 124, 40, 216, 78, 151, 201, 215, 86, 61, 161, 32, 63, 142, 188, 179, 201, + 251, 227, 4, 0, 0, 0, 188, 89, 209, 206, 20, 73, 185, 57, 58, 66, 2, 229, 104, 106, 84, 183, 219, 195, 165, + 63, 228, 182, 178, 118, 77, 105, 184, 119, 89, 3, 0, 0, 206, 62, 63, 18, 131, 8, 22, 21, 63, 239, 158, 178, + 27, 204, 90, 34, 143, 129, 207, 16, 253, 173, 19, 225, 191, 217, 6, 254, 80, 152, 145, 65, 220, 106, 150, + 246, 77, 156, 74, 126, 248, 136, 124, 100, 155, 18, 239, 188, 174, 15, 248, 45, 212, 253, 101, 40, 112, + 132, 179, 217, 252, 199, 171, 36, 211, 174, 192, 96, 188, 89, 14, 30, 103, 254, 196, 207, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 230, 221, 179, 0, 253, 144, 1, 1, 209, 2, 79, 205, + 202, 0, 205, 32, 1, 211, 125, 23, 35, 10, 165, 75, 12, 49, 213, 213, 45, 12, 48, 128, 38, 172, 63, 88, 144, + 179, 84, 69, 91, 147, 226, 199, 138, 44, 144, 253, 214, 34, 82, 155, 155, 193, 198, 130, 89, 15, 150, 42, + 18, 233, 244, 38, 93, 107, 119, 242, 219, 225, 158, 248, 85, 202, 200, 101, 213, 140, 23, 156, 25, 104, 35, + 46, 101, 175, 254, 199, 95, 213, 80, 25, 59, 163, 9, 155, 178, 167, 82, 191, 226, 124, 124, 217, 168, 7, 9, + 4, 106, 110, 215, 60, 197, 210, 14, 9, 219, 140, 46, 227, 189, 104, 26, 178, 105, 195, 222, 219, 247, 247, + 251, 104, 19, 234, 38, 208, 72, 225, 84, 85, 237, 139, 59, 40, 17, 80, 26, 95, 23, 229, 102, 3, 54, 225, 2, + 42, 167, 6, 176, 158, 72, 60, 80, 22, 31, 119, 83, 246, 138, 97, 185, 21, 173, 216, 16, 189, 175, 72, 29, + 105, 136, 77, 25, 230, 197, 115, 109, 152, 39, 78, 136, 180, 107, 1, 2, 245, 21, 19, 104, 55, 149, 6, 55, + 208, 174, 53, 123, 5, 30, 84, 206, 250, 81, 218, 56, 97, 84, 63, 168, 225, 114, 243, 215, 2, 70, 6, 208, + 190, 83, 183, 215, 208, 8, 51, 155, 4, 143, 125, 175, 175, 13, 31, 46, 204, 243, 129, 10, 19, 219, 165, + 181, 94, 229, 116, 245, 92, 147, 16, 195, 53, 44, 22, 18, 235, 97, 165, 124, 50, 203, 101, 223, 71, 14, + 236, 188, 75, 142, 136, 15, 210, 64, 199, 27, 202, 77, 187, 236, 244, 219, 128, 25, 175, 169, 106, 2, 84, + 240, 221, 145, 46, 25, 62, 142, 184, 238, 2, 175, 14, 206, 204, 244, 172, 113, 5, 224, 128, 159, 215, 201, + 146, 76, 196, 205, 194, 206, 41, 78, 32, 69, 229, 8, 219, 31, 190, 3, 145, 76, 23, 22, 12, 167, 149, 204, + 154, 70, 221, 103, 196, 155, 91, 165, 195, 49, 129, 85, 206, 25, 29, 70, 79, 174, 29, 32, 202, 10, 4, 165, + 84, 208, 100, 163, 194, 210, 207, 25, 202, 222, 131, 137, 133, 186, 4, 60, 175, 159, 39, 71, 20, 221, 228, + 197, 211, 173, 223, 53, 171, 172, 19, 220, 37, 94, 163, 23, 181, 198, 16, 148, 4, 0, 0, 0, 251, 166, 65, + 54, 97, 9, 150, 105, 220, 120, 84, 74, 79, 29, 131, 221, 52, 171, 44, 84, 205, 207, 189, 153, 139, 197, + 224, 89, 142, 11, 0, 0, 57, 109, 36, 39, 134, 155, 193, 87, 125, 249, 164, 120, 228, 217, 182, 207, 245, + 95, 111, 57, 98, 205, 176, 34, 210, 218, 1, 17, 82, 62, 228, 8, 220, 106, 150, 246, 77, 156, 74, 126, 248, + 136, 124, 100, 155, 18, 239, 188, 174, 15, 248, 45, 212, 253, 101, 40, 112, 132, 179, 217, 252, 199, 171, + 36, 217, 174, 192, 96, 93, 218, 14, 30, 48, 0, 0, 52, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 189, 230, 60, 0, 253, 144, 1, 2, 190, 156, 254, 123, 20, 88, 24, 195, 48, 16, 27, 34, + 238, 217, 227, 219, 87, 133, 67, 94, 252, 183, 89, 97, 11, 107, 84, 135, 63, 197, 169, 164, 246, 186, 191, + 166, 101, 190, 199, 238, 38, 243, 10, 10, 211, 185, 223, 2, 112, 11, 95, 120, 212, 90, 55, 18, 54, 3, 106, + 199, 230, 129, 208, 124, 114, 128, 156, 74, 148, 135, 63, 243, 66, 237, 34, 211, 255, 174, 193, 91, 34, + 169, 44, 17, 111, 119, 244, 19, 157, 255, 192, 164, 145, 193, 200, 247, 45, 152, 249, 2, 218, 50, 179, 156, + 96, 206, 27, 237, 237, 79, 229, 192, 99, 227, 138, 198, 71, 82, 37, 123, 227, 223, 99, 113, 5, 232, 50, + 144, 250, 17, 134, 104, 162, 20, 36, 178, 112, 186, 219, 209, 71, 186, 138, 93, 104, 207, 205, 117, 177, + 12, 234, 51, 198, 4, 227, 139, 12, 37, 184, 175, 208, 85, 138, 68, 35, 250, 130, 193, 108, 134, 77, 238, + 71, 235, 79, 37, 107, 94, 152, 214, 221, 234, 198, 150, 184, 84, 187, 118, 43, 47, 247, 22, 130, 233, 188, + 237, 211, 223, 6, 5, 191, 133, 22, 239, 249, 219, 87, 117, 185, 106, 76, 1, 242, 102, 213, 117, 190, 194, + 75, 43, 87, 120, 113, 53, 58, 104, 172, 172, 54, 69, 16, 49, 249, 11, 247, 53, 244, 150, 212, 42, 166, 155, + 77, 152, 10, 151, 100, 99, 160, 26, 136, 55, 177, 218, 12, 56, 76, 32, 223, 116, 195, 82, 121, 214, 34, + 120, 245, 145, 72, 215, 45, 29, 211, 53, 53, 184, 218, 168, 216, 221, 21, 242, 127, 46, 74, 169, 52, 4, + 133, 227, 165, 68, 99, 191, 202, 99, 251, 90, 30, 26, 39, 30, 19, 255, 240, 161, 202, 38, 85, 162, 117, + 234, 185, 91, 46, 122, 143, 54, 180, 22, 197, 251, 5, 223, 62, 101, 84, 197, 31, 74, 162, 149, 41, 150, + 153, 127, 246, 103, 121, 126, 185, 118, 94, 154, 58, 87, 78, 20, 221, 65, 189, 133, 224, 81, 233, 90, 115, + 31, 20, 219, 145, 181, 38, 35, 75, 209, 57, 137, 88, 108, 185, 80, 80, 58, 71, 207, 159, 86, 247, 237, 22, + 128, 26, 149, 139, 19, 39, 166, 98, 252, 85, 212, 102, 59, 74, 147, 85, 214, 123, 4, 0, 0, 0, 178, 253, + 239, 61, 116, 130, 95, 99, 15, 6, 78, 63, 7, 121, 224, 128, 137, 4, 22, 167, 68, 80, 110, 68, 236, 176, 67, + 252, 255, 0, 0, 0, 143, 32, 179, 1, 17, 61, 20, 181, 220, 83, 124, 13, 80, 103, 224, 200, 48, 136, 231, 1, + 216, 137, 142, 36, 32, 15, 73, 120, 163, 160, 54, 187, 220, 106, 150, 246, 77, 156, 74, 126, 248, 136, 124, + 100, 155, 18, 239, 188, 174, 15, 248, 45, 212, 253, 101, 40, 112, 132, 179, 217, 252, 199, 171, 36, 228, + 174, 192, 96, 135, 3, 15, 30, 88, 0, 0, 43, 215, 99, 39, 179, 228, 254, 18, 167, 176, 63, 124, 39, 153, 70, + 243, 136, 0, 0, 0, 0, 0, 0, 0, 0, 70, 191, 188, 103, 253, 144, 1, 1, 33, 14, 212, 103, 233, 207, 193, 2, + 222, 185, 26, 211, 248, 96, 194, 179, 194, 133, 159, 239, 98, 242, 102, 89, 3, 200, 103, 19, 13, 227, 90, + 47, 83, 244, 39, 125, 114, 67, 239, 231, 239, 186, 46, 81, 18, 109, 65, 113, 214, 15, 31, 30, 220, 254, + 100, 198, 208, 82, 50, 2, 55, 49, 4, 24, 90, 165, 205, 66, 22, 236, 167, 165, 120, 230, 61, 35, 252, 120, + 195, 36, 116, 193, 241, 189, 118, 235, 119, 115, 224, 255, 161, 134, 254, 71, 206, 145, 98, 15, 2, 28, 57, + 136, 64, 79, 219, 119, 108, 177, 251, 246, 18, 234, 224, 82, 14, 164, 40, 75, 35, 123, 7, 163, 193, 172, + 30, 246, 225, 61, 201, 60, 210, 25, 64, 94, 204, 211, 211, 118, 245, 219, 197, 124, 113, 120, 147, 7, 48, + 153, 161, 39, 72, 35, 234, 111, 115, 144, 85, 114, 180, 65, 255, 103, 33, 207, 133, 221, 221, 85, 210, 214, + 237, 17, 81, 96, 43, 200, 254, 58, 238, 171, 17, 84, 132, 141, 207, 127, 244, 110, 65, 107, 174, 142, 213, + 74, 235, 115, 226, 162, 40, 7, 175, 251, 215, 224, 79, 164, 110, 123, 219, 188, 52, 178, 73, 252, 161, 139, + 141, 110, 177, 174, 215, 129, 102, 19, 18, 209, 9, 244, 229, 184, 147, 140, 68, 142, 250, 211, 132, 179, + 180, 94, 154, 205, 161, 152, 230, 245, 8, 166, 57, 17, 46, 158, 190, 223, 137, 154, 248, 39, 20, 149, 167, + 115, 8, 184, 234, 233, 131, 173, 105, 206, 233, 231, 203, 68, 30, 56, 182, 107, 25, 176, 84, 63, 44, 117, + 92, 51, 130, 201, 53, 204, 54, 236, 53, 189, 233, 243, 132, 88, 177, 12, 199, 68, 78, 33, 26, 18, 54, 59, + 60, 140, 238, 81, 133, 103, 85, 119, 142, 72, 183, 128, 50, 183, 26, 112, 94, 135, 1, 56, 145, 51, 25, 34, + 91, 29, 60, 238, 153, 49, 15, 111, 51, 203, 70, 148, 28, 185, 113, 167, 165, 17, 157, 88, 25, 39, 1, 202, + 135, 228, 231, 194, 113, 33, 208, 95, 198, 133, 180, 98, 65, 237, 171, 106, 22, 103, 58, 69, 161, 180, 219, + 130, 156, 41, 246, 183, 100, 29, 99, 223, 236, 70, 55, 102, 133, 10, 193, 145, 12, 12, 71, 4, 0, 0, 0, 47, + 173, 224, 18, 48, 16, 71, 146, 49, 87, 134, 43, 159, 255, 121, 128, 172, 114, 168, 165, 20, 98, 14, 17, + 179, 81, 27, 240, 27, 13, 0, 0, 87, 102, 111, 48, 206, 0, 179, 77, 134, 192, 200, 112, 46, 38, 60, 235, 38, + 157, 219, 13, 239, 113, 234, 204, 237, 71, 180, 194, 232, 95, 23, 61, 220, 106, 150, 246, 77, 156, 74, 126, + 248, 136, 124, 100, 155, 18, 239, 188, 174, 15, 248, 45, 212, 253, 101, 40, 112, 132, 179, 217, 252, 199, + 171, 36, 133, 175, 192, 96, 242, 16, 15, 30, 127, 255, 255, 235, 132, 38, 62, 247, 152, 251, 12, 82, 62, + 40, 198, 34, 24, 174, 133, 125, 0, 0, 0, 0, 0, 0, 0, 0, 78, 134, 7, 7, 253, 144, 1, 0, 93, 219, 187, 68, + 202, 196, 93, 12, 72, 165, 72, 129, 151, 212, 172, 205, 175, 161, 242, 240, 219, 0, 187, 99, 50, 52, 90, + 73, 84, 240, 206, 147, 204, 18, 42, 108, 184, 157, 37, 110, 165, 141, 102, 209, 115, 101, 148, 163, 55, 21, + 79, 113, 36, 23, 197, 237, 143, 93, 26, 225, 130, 85, 220, 153, 123, 65, 225, 186, 233, 248, 207, 232, 98, + 50, 22, 222, 58, 190, 74, 17, 12, 235, 220, 152, 57, 100, 131, 52, 234, 122, 188, 112, 61, 234, 142, 73, + 227, 13, 165, 6, 140, 99, 209, 146, 59, 83, 222, 230, 57, 118, 47, 66, 77, 250, 201, 191, 18, 124, 231, + 154, 215, 68, 108, 154, 20, 69, 124, 244, 111, 1, 135, 30, 172, 67, 165, 219, 210, 142, 210, 242, 47, 202, + 136, 196, 227, 93, 189, 134, 80, 21, 220, 233, 38, 147, 107, 213, 146, 202, 123, 217, 182, 132, 211, 193, + 194, 196, 241, 241, 218, 83, 79, 121, 152, 213, 25, 62, 93, 208, 204, 136, 140, 183, 128, 44, 146, 96, 210, + 108, 11, 118, 246, 79, 37, 110, 128, 141, 254, 208, 249, 2, 69, 226, 143, 165, 85, 178, 46, 124, 187, 97, + 230, 196, 7, 180, 99, 209, 4, 150, 34, 185, 129, 211, 132, 149, 14, 36, 218, 30, 251, 113, 202, 159, 83, + 14, 235, 28, 201, 74, 23, 231, 255, 212, 79, 8, 166, 133, 231, 235, 45, 3, 11, 154, 38, 93, 213, 48, 59, + 40, 121, 14, 84, 234, 18, 119, 134, 20, 86, 110, 217, 45, 21, 171, 107, 169, 48, 255, 153, 97, 112, 41, + 229, 59, 152, 220, 171, 115, 56, 120, 89, 223, 93, 208, 30, 85, 109, 95, 74, 129, 224, 3, 31, 156, 136, + 204, 215, 242, 108, 173, 95, 227, 105, 112, 175, 106, 155, 226, 212, 140, 182, 192, 169, 8, 141, 177, 8, + 111, 201, 55, 87, 93, 20, 49, 137, 95, 221, 215, 1, 113, 136, 70, 201, 100, 221, 94, 158, 90, 254, 72, 51, + 48, 243, 102, 244, 18, 110, 18, 47, 171, 202, 27, 116, 70, 26, 67, 157, 251, 88, 6, 24, 223, 141, 207, 150, + 145, 55, 156, 237, 222, 192, 213, 164, 227, 229, 189, 39, 119, 182, 186, 140, 6, 64, 82, 17, 240, 180, 117, + 140, 57, 90, 4, 0, 0, 0, 252, 211, 32, 165, 184, 226, 151, 110, 53, 250, 221, 144, 217, 235, 21, 221, 135, + 82, 29, 148, 28, 56, 104, 179, 204, 74, 102, 55, 227, 7, 0, 0, 231, 155, 54, 126, 46, 9, 199, 26, 14, 92, + 141, 133, 187, 66, 112, 231, 212, 3, 211, 127, 158, 7, 165, 199, 198, 94, 22, 235, 46, 36, 35, 199, 220, + 106, 150, 246, 77, 156, 74, 126, 248, 136, 124, 100, 155, 18, 239, 188, 174, 15, 248, 45, 212, 253, 101, + 40, 112, 132, 179, 217, 252, 199, 171, 36, 217, 175, 192, 96, 126, 245, 14, 30, 23, 255, 255, 254, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 101, 196, 76, 0, 253, 144, 1, 0, 171, 202, + 230, 126, 247, 220, 113, 208, 23, 6, 9, 241, 176, 16, 154, 204, 130, 77, 30, 66, 35, 29, 13, 112, 24, 36, + 57, 196, 241, 175, 6, 148, 210, 44, 123, 21, 45, 84, 192, 30, 182, 21, 75, 88, 223, 197, 212, 255, 173, 24, + 24, 235, 195, 110, 17, 154, 92, 140, 152, 204, 155, 101, 192, 249, 14, 7, 231, 17, 163, 188, 43, 64, 181, + 245, 38, 62, 167, 26, 38, 206, 218, 211, 230, 141, 190, 41, 40, 21, 180, 174, 229, 84, 7, 55, 42, 91, 230, + 253, 122, 6, 158, 9, 240, 190, 227, 10, 21, 212, 44, 60, 48, 102, 232, 105, 206, 29, 17, 53, 245, 128, 243, + 102, 238, 172, 60, 63, 217, 118, 156, 1, 178, 137, 73, 220, 136, 97, 149, 22, 181, 230, 137, 221, 51, 8, + 153, 69, 230, 15, 219, 12, 234, 58, 241, 211, 130, 208, 206, 198, 176, 85, 87, 68, 83, 130, 179, 158, 189, + 33, 132, 242, 96, 226, 74, 6, 17, 17, 33, 121, 222, 253, 175, 153, 91, 158, 134, 219, 37, 143, 142, 166, + 183, 182, 46, 103, 248, 27, 191, 149, 217, 1, 108, 227, 53, 191, 119, 3, 176, 47, 131, 150, 147, 242, 106, + 34, 137, 102, 150, 187, 103, 89, 1, 181, 192, 212, 15, 212, 85, 150, 65, 54, 175, 95, 194, 89, 128, 53, + 194, 71, 116, 134, 191, 95, 123, 93, 167, 161, 196, 221, 105, 20, 243, 156, 80, 50, 184, 140, 49, 115, 250, + 4, 92, 179, 152, 244, 27, 194, 123, 46, 188, 24, 103, 193, 182, 133, 28, 141, 195, 175, 65, 171, 12, 172, + 222, 217, 195, 30, 249, 98, 209, 181, 229, 195, 159, 96, 33, 155, 247, 102, 65, 14, 121, 103, 148, 105, + 255, 81, 161, 94, 219, 141, 13, 72, 27, 10, 150, 187, 67, 94, 25, 215, 225, 137, 119, 104, 88, 161, 101, + 73, 80, 116, 107, 120, 118, 53, 208, 211, 8, 16, 185, 76, 115, 12, 210, 106, 152, 183, 168, 243, 189, 16, + 208, 24, 26, 30, 73, 77, 62, 113, 223, 92, 214, 241, 194, 33, 104, 249, 81, 37, 174, 235, 255, 151, 182, + 217, 32, 161, 122, 60, 57, 208, 175, 224, 149, 253, 156, 91, 114, 115, 150, 124, 72, 55, 165, 3, 5, 46, + 166, 81, 146, + ]; + let mut reader = Reader::new(headers_bytes); + let headers = reader.read_list::().unwrap(); + for header in headers.iter() { + assert_eq!(header.version, 4); + } + let serialized = serialize_list(&headers); + assert_eq!(serialized.take(), headers_bytes); + } } From 5af01081342a360acd9b8238a1b999a2cbaa00a3 Mon Sep 17 00:00:00 2001 From: Artem Pikulin Date: Thu, 10 Jun 2021 18:18:05 +0700 Subject: [PATCH 2/2] Add coin_variant to serialization::Reader. --- mm2src/coins/qrc20.rs | 7 ++-- mm2src/coins/utxo/qtum.rs | 5 ++- mm2src/coins/utxo/rpc_clients.rs | 25 +++++++++++--- mm2src/coins/utxo/utxo_common.rs | 6 ++-- mm2src/coins/utxo/utxo_standard.rs | 5 ++- mm2src/coins/utxo/utxo_tests.rs | 33 ++++++++++++------- mm2src/mm2_bitcoin/chain/src/block_header.rs | 6 ++-- mm2src/mm2_bitcoin/serialization/src/lib.rs | 2 +- .../mm2_bitcoin/serialization/src/reader.rs | 31 ++++++++++++++++- 9 files changed, 90 insertions(+), 30 deletions(-) diff --git a/mm2src/coins/qrc20.rs b/mm2src/coins/qrc20.rs index 95ed088e64..d4964a1d69 100644 --- a/mm2src/coins/qrc20.rs +++ b/mm2src/coins/qrc20.rs @@ -38,8 +38,7 @@ use rpc::v1::types::{Bytes as BytesJson, Transaction as RpcTransaction, H160 as use script::{Builder as ScriptBuilder, Opcode, Script, TransactionInputSigner}; use script_pubkey::generate_contract_call_script_pubkey; use serde_json::{self as json, Value as Json}; -use serialization::deserialize; -use serialization::serialize; +use serialization::{deserialize, serialize, CoinVariant}; use std::ops::{Deref, Neg}; #[cfg(not(target_arch = "wasm32"))] use std::path::PathBuf; use std::str::FromStr; @@ -480,7 +479,9 @@ impl UtxoCommonOps for Qrc20Coin { utxo_common::address_from_str(&self.utxo.conf, address) } - async fn get_current_mtp(&self) -> UtxoRpcResult { utxo_common::get_current_mtp(&self.utxo).await } + async fn get_current_mtp(&self) -> UtxoRpcResult { + utxo_common::get_current_mtp(&self.utxo, CoinVariant::Qtum).await + } fn is_unspent_mature(&self, output: &RpcTransaction) -> bool { self.is_qtum_unspent_mature(output) } diff --git a/mm2src/coins/utxo/qtum.rs b/mm2src/coins/utxo/qtum.rs index 58b3668bfa..f5a2a1b9b8 100644 --- a/mm2src/coins/utxo/qtum.rs +++ b/mm2src/coins/utxo/qtum.rs @@ -5,6 +5,7 @@ use common::mm_metrics::MetricsArc; use common::mm_number::MmNumber; use ethereum_types::H160; use futures::{FutureExt, TryFutureExt}; +use serialization::CoinVariant; pub const QTUM_STANDARD_DUST: u64 = 1000; @@ -166,7 +167,9 @@ impl UtxoCommonOps for QtumCoin { utxo_common::address_from_str(&self.utxo_arc.conf, address) } - async fn get_current_mtp(&self) -> UtxoRpcResult { utxo_common::get_current_mtp(&self.utxo_arc).await } + async fn get_current_mtp(&self) -> UtxoRpcResult { + utxo_common::get_current_mtp(&self.utxo_arc, CoinVariant::Qtum).await + } fn is_unspent_mature(&self, output: &RpcTransaction) -> bool { self.is_qtum_unspent_mature(output) } diff --git a/mm2src/coins/utxo/rpc_clients.rs b/mm2src/coins/utxo/rpc_clients.rs index c000d4b965..ed045aa11b 100644 --- a/mm2src/coins/utxo/rpc_clients.rs +++ b/mm2src/coins/utxo/rpc_clients.rs @@ -31,7 +31,7 @@ use keys::Address; use rpc::v1::types::{Bytes as BytesJson, Transaction as RpcTransaction, H256 as H256Json}; use script::Builder; use serde_json::{self as json, Value as Json}; -use serialization::{deserialize, serialize, CompactInteger, Reader}; +use serialization::{deserialize, serialize, CoinVariant, CompactInteger, Reader}; use sha2::{Digest, Sha256}; use std::collections::hash_map::{Entry, HashMap}; use std::fmt; @@ -245,7 +245,12 @@ pub trait UtxoRpcClientOps: fmt::Debug + Send + Sync + 'static { ) -> Box, Error = String> + Send>; /// Get median time past for `count` blocks in the past including `starting_block` - fn get_median_time_past(&self, starting_block: u64, count: NonZeroU64) -> UtxoRpcFut; + fn get_median_time_past( + &self, + starting_block: u64, + count: NonZeroU64, + coin_variant: CoinVariant, + ) -> UtxoRpcFut; } #[derive(Clone, Deserialize, Debug)] @@ -660,7 +665,12 @@ impl UtxoRpcClientOps for NativeClient { Box::new(fut.boxed().compat()) } - fn get_median_time_past(&self, starting_block: u64, count: NonZeroU64) -> UtxoRpcFut { + fn get_median_time_past( + &self, + starting_block: u64, + count: NonZeroU64, + _coin_variant: CoinVariant, + ) -> UtxoRpcFut { let selfi = self.clone(); let fut = async move { let starting_block_hash = selfi.get_block_hash(starting_block).compat().await?; @@ -1575,7 +1585,12 @@ impl UtxoRpcClientOps for ElectrumClient { Box::new(fut.boxed().compat()) } - fn get_median_time_past(&self, starting_block: u64, count: NonZeroU64) -> UtxoRpcFut { + fn get_median_time_past( + &self, + starting_block: u64, + count: NonZeroU64, + coin_variant: CoinVariant, + ) -> UtxoRpcFut { let from = if starting_block <= count.get() { 0 } else { @@ -1591,7 +1606,7 @@ impl UtxoRpcClientOps for ElectrumClient { let len = CompactInteger::from(res.count); let mut serialized = serialize(&len).take(); serialized.extend(res.hex.0.into_iter()); - let mut reader = Reader::new(serialized.as_slice()); + let mut reader = Reader::new_with_coin_variant(serialized.as_slice(), coin_variant); let headers = reader.read_list::()?; let mut timestamps: Vec<_> = headers.into_iter().map(|block| block.time).collect(); // can unwrap because count is non zero diff --git a/mm2src/coins/utxo/utxo_common.rs b/mm2src/coins/utxo/utxo_common.rs index f4e813e18c..858176a89f 100644 --- a/mm2src/coins/utxo/utxo_common.rs +++ b/mm2src/coins/utxo/utxo_common.rs @@ -22,7 +22,7 @@ use script::{Builder, Opcode, Script, ScriptAddress, SignatureVersion, Transacti UnsignedTransactionInput}; use secp256k1::{PublicKey, Signature}; use serde_json::{self as json}; -use serialization::{deserialize, serialize}; +use serialization::{deserialize, serialize, CoinVariant}; use std::cmp::Ordering; use std::collections::hash_map::{Entry, HashMap}; use std::str::FromStr; @@ -253,10 +253,10 @@ pub fn address_from_str(conf: &UtxoCoinConf, address: &str) -> Result UtxoRpcResult { +pub async fn get_current_mtp(coin: &UtxoCoinFields, coin_variant: CoinVariant) -> UtxoRpcResult { let current_block = coin.rpc_client.get_block_count().compat().await?; coin.rpc_client - .get_median_time_past(current_block, coin.conf.mtp_block_count) + .get_median_time_past(current_block, coin.conf.mtp_block_count, coin_variant) .compat() .await } diff --git a/mm2src/coins/utxo/utxo_standard.rs b/mm2src/coins/utxo/utxo_standard.rs index b9ebb36509..259f62cdde 100644 --- a/mm2src/coins/utxo/utxo_standard.rs +++ b/mm2src/coins/utxo/utxo_standard.rs @@ -4,6 +4,7 @@ use crate::{CanRefundHtlc, CoinBalance, NegotiateSwapContractAddrErr, SwapOps, T use common::mm_metrics::MetricsArc; use common::mm_number::MmNumber; use futures::{FutureExt, TryFutureExt}; +use serialization::CoinVariant; #[derive(Clone, Debug)] pub struct UtxoStandardCoin { @@ -58,7 +59,9 @@ impl UtxoCommonOps for UtxoStandardCoin { utxo_common::address_from_str(&self.utxo_arc.conf, address) } - async fn get_current_mtp(&self) -> UtxoRpcResult { utxo_common::get_current_mtp(&self.utxo_arc).await } + async fn get_current_mtp(&self) -> UtxoRpcResult { + utxo_common::get_current_mtp(&self.utxo_arc, CoinVariant::Standard).await + } fn is_unspent_mature(&self, output: &RpcTransaction) -> bool { utxo_common::is_unspent_mature(self.utxo_arc.conf.mature_confirmations, output) diff --git a/mm2src/coins/utxo/utxo_tests.rs b/mm2src/coins/utxo/utxo_tests.rs index 319a53ffb1..bc6fcbff43 100644 --- a/mm2src/coins/utxo/utxo_tests.rs +++ b/mm2src/coins/utxo/utxo_tests.rs @@ -16,7 +16,7 @@ use futures::future::join_all; use mocktopus::mocking::*; use rpc::v1::types::H256 as H256Json; use script::Opcode; -use serialization::deserialize; +use serialization::{deserialize, CoinVariant}; use std::thread; use std::time::Duration; @@ -1016,7 +1016,7 @@ fn test_get_median_time_past_from_electrum_kmd() { ]); let mtp = client - .get_median_time_past(1773390, KMD_MTP_BLOCK_COUNT) + .get_median_time_past(1773390, KMD_MTP_BLOCK_COUNT, CoinVariant::Standard) .wait() .unwrap(); // the MTP is block time of 1773385 in this case @@ -1031,7 +1031,10 @@ fn test_get_median_time_past_from_electrum_btc() { "electrum3.cipig.net:10000", ]); - let mtp = client.get_median_time_past(632858, KMD_MTP_BLOCK_COUNT).wait().unwrap(); + let mtp = client + .get_median_time_past(632858, KMD_MTP_BLOCK_COUNT, CoinVariant::Standard) + .wait() + .unwrap(); assert_eq!(1591173041, mtp); } @@ -1055,7 +1058,10 @@ fn test_get_median_time_past_from_native_has_median_in_get_block() { ) }); - let mtp = client.get_median_time_past(632858, KMD_MTP_BLOCK_COUNT).wait().unwrap(); + let mtp = client + .get_median_time_past(632858, KMD_MTP_BLOCK_COUNT, CoinVariant::Standard) + .wait() + .unwrap(); assert_eq!(1591173041, mtp); } @@ -1098,7 +1104,10 @@ fn test_get_median_time_past_from_native_does_not_have_median_in_get_block() { MockResult::Return(Box::new(futures01::future::ok(block))) }); - let mtp = client.get_median_time_past(632858, KMD_MTP_BLOCK_COUNT).wait().unwrap(); + let mtp = client + .get_median_time_past(632858, KMD_MTP_BLOCK_COUNT, CoinVariant::Standard) + .wait() + .unwrap(); assert_eq!(1591173041, mtp); } @@ -2389,7 +2398,7 @@ fn doge_mtp() { "electrum3.cipig.net:10060", ]); let mtp = electrum - .get_median_time_past(3631820, NonZeroU64::new(11).unwrap()) + .get_median_time_past(3631820, NonZeroU64::new(11).unwrap(), CoinVariant::Standard) .wait() .unwrap(); assert_eq!(mtp, 1614849084); @@ -2403,7 +2412,7 @@ fn firo_mtp() { "electrumx03.firo.org:50001", ]); let mtp = electrum - .get_median_time_past(356730, NonZeroU64::new(11).unwrap()) + .get_median_time_past(356730, NonZeroU64::new(11).unwrap(), CoinVariant::Standard) .wait() .unwrap(); assert_eq!(mtp, 1616492629); @@ -2413,7 +2422,7 @@ fn firo_mtp() { fn verus_mtp() { let electrum = electrum_client_for_test(&["el0.verus.io:17485", "el1.verus.io:17485", "el2.verus.io:17485"]); let mtp = electrum - .get_median_time_past(1480113, NonZeroU64::new(11).unwrap()) + .get_median_time_past(1480113, NonZeroU64::new(11).unwrap(), CoinVariant::Standard) .wait() .unwrap(); assert_eq!(mtp, 1618579909); @@ -2533,7 +2542,7 @@ fn sys_mtp() { "electrum3.cipig.net:10064", ]); let mtp = electrum - .get_median_time_past(1006678, NonZeroU64::new(11).unwrap()) + .get_median_time_past(1006678, NonZeroU64::new(11).unwrap(), CoinVariant::Standard) .wait() .unwrap(); assert_eq!(mtp, 1620019628); @@ -2547,7 +2556,7 @@ fn btc_mtp() { "electrum3.cipig.net:10000", ]); let mtp = electrum - .get_median_time_past(681659, NonZeroU64::new(11).unwrap()) + .get_median_time_past(681659, NonZeroU64::new(11).unwrap(), CoinVariant::Standard) .wait() .unwrap(); assert_eq!(mtp, 1620019527); @@ -2561,7 +2570,7 @@ fn qtum_mtp() { "electrum3.cipig.net:10050", ]); let mtp = electrum - .get_median_time_past(681659, NonZeroU64::new(11).unwrap()) + .get_median_time_past(681659, NonZeroU64::new(11).unwrap(), CoinVariant::Qtum) .wait() .unwrap(); assert_eq!(mtp, 1598854128); @@ -2575,7 +2584,7 @@ fn zer_mtp() { "electrum3.cipig.net:10065", ]); let mtp = electrum - .get_median_time_past(1130915, NonZeroU64::new(11).unwrap()) + .get_median_time_past(1130915, NonZeroU64::new(11).unwrap(), CoinVariant::Standard) .wait() .unwrap(); assert_eq!(mtp, 1623240214); diff --git a/mm2src/mm2_bitcoin/chain/src/block_header.rs b/mm2src/mm2_bitcoin/chain/src/block_header.rs index 569530c44c..a25cc6b597 100644 --- a/mm2src/mm2_bitcoin/chain/src/block_header.rs +++ b/mm2src/mm2_bitcoin/chain/src/block_header.rs @@ -197,7 +197,7 @@ impl Deserializable for BlockHeader { }; let (hash_state_root, hash_utxo_root, prevout_stake, vch_block_sig_dlgt) = - if version == QTUM_BLOCK_HEADER_VERSION { + if version == QTUM_BLOCK_HEADER_VERSION && reader.coin_variant().is_qtum() { ( Some(reader.read()?), Some(reader.read()?), @@ -241,7 +241,7 @@ mod tests { use block_header::{BlockHeader, BlockHeaderBits, BlockHeaderNonce, AUX_POW_VERSION_DOGE, AUX_POW_VERSION_SYS, MTP_POW_VERSION, QTUM_BLOCK_HEADER_VERSION}; use hex::FromHex; - use ser::{deserialize, serialize, serialize_list, Error as ReaderError, Reader, Stream}; + use ser::{deserialize, serialize, serialize_list, CoinVariant, Error as ReaderError, Reader, Stream}; #[test] fn test_block_header_stream() { @@ -1873,7 +1873,7 @@ mod tests { 226, 1, 77, 51, 114, 115, 8, 152, 211, 49, 161, 62, 190, 80, 119, 154, 30, 193, 226, 46, 248, 169, 69, 226, 86, 134, 101, 238, 115, 14, 63, 174, 123, 30, 7, 123, 174, 60, 13, 100, 49, 23, 123, ]; - let mut reader = Reader::new(headers_bytes); + let mut reader = Reader::new_with_coin_variant(headers_bytes, CoinVariant::Qtum); let headers = reader.read_list::().unwrap(); for header in headers.iter() { assert_eq!(header.version, QTUM_BLOCK_HEADER_VERSION); diff --git a/mm2src/mm2_bitcoin/serialization/src/lib.rs b/mm2src/mm2_bitcoin/serialization/src/lib.rs index 03682544c9..1591c9787f 100644 --- a/mm2src/mm2_bitcoin/serialization/src/lib.rs +++ b/mm2src/mm2_bitcoin/serialization/src/lib.rs @@ -11,6 +11,6 @@ pub use primitives::{bytes, compact, hash}; pub use compact_integer::CompactInteger; pub use list::List; -pub use reader::{deserialize, deserialize_iterator, Deserializable, Error, ReadIterator, Reader}; +pub use reader::{deserialize, deserialize_iterator, CoinVariant, Deserializable, Error, ReadIterator, Reader}; pub use stream::{serialize, serialize_list, serialize_with_flags, serialized_list_size, serialized_list_size_with_flags, Serializable, Stream, SERIALIZE_TRANSACTION_WITNESS}; diff --git a/mm2src/mm2_bitcoin/serialization/src/reader.rs b/mm2src/mm2_bitcoin/serialization/src/reader.rs index 73b23209e9..a32f539534 100644 --- a/mm2src/mm2_bitcoin/serialization/src/reader.rs +++ b/mm2src/mm2_bitcoin/serialization/src/reader.rs @@ -46,16 +46,42 @@ pub trait Deserializable { T: io::Read; } +#[derive(Debug)] +pub enum CoinVariant { + Standard, + Qtum, +} + +impl CoinVariant { + pub fn is_qtum(&self) -> bool { matches!(self, CoinVariant::Qtum) } +} + /// Bitcoin structures reader. #[derive(Debug)] pub struct Reader { buffer: T, peeked: Option, + coin_variant: CoinVariant, } impl<'a> Reader<&'a [u8]> { /// Convenient way of creating for slice of bytes - pub fn new(buffer: &'a [u8]) -> Self { Reader { buffer, peeked: None } } + pub fn new(buffer: &'a [u8]) -> Self { + Reader { + buffer, + peeked: None, + coin_variant: CoinVariant::Standard, + } + } + + /// Convenient way of creating for slice of bytes + pub fn new_with_coin_variant(buffer: &'a [u8], coin_variant: CoinVariant) -> Self { + Reader { + buffer, + peeked: None, + coin_variant, + } + } } impl io::Read for Reader @@ -88,6 +114,7 @@ where Reader { buffer: read, peeked: None, + coin_variant: CoinVariant::Standard, } } @@ -158,6 +185,8 @@ where Err(_) => true, } } + + pub fn coin_variant(&self) -> &CoinVariant { &self.coin_variant } } /// Should be used to iterate over structures of the same type