Skip to content

Commit 9dcc9c5

Browse files
committed
Merge #273: Ensure missing return fields from types structs are tested for
16ae504 Add serde(deny_unknown_fileds) (Jamil Lambert, PhD) 6dcf4c3 Fix comment and derive order for method (Jamil Lambert, PhD) e84d8e9 Reorder derives to be the same (Jamil Lambert, PhD) Pull request description: If there are missing return fields in the types structs the integration tests still pass. All of the missing fields have been added in #243, #251, #255, #267 and #272. The solution suggested in issue #241 is adding `#[serde(deny_unknown_fields)]` to each struct which makes the test fail if there are fields returned that are not in the struct. - First two patches: do a small code reorganisation to make sure the third patch that uses a search and replace catches all cases. - Third patch: add `#[serde(deny_unknown_fields)]` to all structs in `types` that derive `Serialize` and therefore use serde. Using a search and replace. Closes #241 ACKs for top commit: tcharding: ACK 16ae504 Tree-SHA512: 5e898edb3b1ce9a05cd3c576b71caf9f96a2cd0f29660a480f6d5775d682fb277665c013cb52c986d90d37f36c5bc320139d351ffc29e1a755d72d11ad185c4f
2 parents 7e341c8 + 16ae504 commit 9dcc9c5

File tree

68 files changed

+396
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+396
-6
lines changed

types/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ pub fn compact_size_decode(slice: &mut &[u8]) -> u64 {
180180
/// backwards compatible so we only provide it not a v0.17 specific type. The `mtype::ScriptPubkey`
181181
/// mirrors this design (but with concrete `rust-bitcoin` types).
182182
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
183+
#[serde(deny_unknown_fields)]
183184
pub struct ScriptPubkey {
184185
/// Script assembly.
185186
pub asm: String,
@@ -218,6 +219,7 @@ impl ScriptPubkey {
218219

219220
/// Data returned by Core for a script signature.
220221
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
222+
#[serde(deny_unknown_fields)]
221223
pub struct ScriptSig {
222224
/// Assembly representation of the script.
223225
pub asm: String,

types/src/model/blockchain.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ use crate::ScriptPubkey;
1818

1919
/// Models the result of JSON-RPC method `getbestblockhash`.
2020
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
21+
#[serde(deny_unknown_fields)]
2122
pub struct GetBestBlockHash(pub BlockHash);
2223

2324
/// Models the result of JSON-RPC method `getblock` with verbosity set to 0.
2425
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
26+
#[serde(deny_unknown_fields)]
2527
pub struct GetBlockVerboseZero(pub Block);
2628

2729
/// Models the result of JSON-RPC method `getblock` with verbosity set to 1.
2830
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
31+
#[serde(deny_unknown_fields)]
2932
pub struct GetBlockVerboseOne {
3033
/// The block hash (same as provided) in RPC call.
3134
pub hash: BlockHash,
@@ -69,6 +72,7 @@ pub struct GetBlockVerboseOne {
6972

7073
/// Models the result of JSON-RPC method `getblockchaininfo`.
7174
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
75+
#[serde(deny_unknown_fields)]
7276
pub struct GetBlockchainInfo {
7377
/// Current network name as defined in BIP70 (main, test, signet, regtest).
7478
pub chain: Network,
@@ -114,6 +118,7 @@ pub struct GetBlockchainInfo {
114118

115119
/// Status of softfork.
116120
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
121+
#[serde(deny_unknown_fields)]
117122
pub struct Softfork {
118123
/// The [`SoftforkType`]: one of "buried", "bip9".
119124
#[serde(rename = "type")]
@@ -142,6 +147,7 @@ pub enum SoftforkType {
142147

143148
/// Status of BIP-9 softforks.
144149
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
150+
#[serde(deny_unknown_fields)]
145151
pub struct Bip9SoftforkInfo {
146152
/// One of "defined", "started", "locked_in", "active", "failed".
147153
pub status: Bip9SoftforkStatus,
@@ -176,6 +182,7 @@ pub enum Bip9SoftforkStatus {
176182

177183
/// Statistics for a BIP-9 softfork.
178184
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
185+
#[serde(deny_unknown_fields)]
179186
pub struct Bip9SoftforkStatistics {
180187
/// The length in blocks of the BIP9 signalling period.
181188
pub period: u32,
@@ -191,10 +198,12 @@ pub struct Bip9SoftforkStatistics {
191198

192199
/// Models the result of JSON-RPC method `getblockcount`.
193200
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
201+
#[serde(deny_unknown_fields)]
194202
pub struct GetBlockCount(pub u64);
195203

196204
/// Models the result of JSON-RPC method `getblockfilter`.
197205
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
206+
#[serde(deny_unknown_fields)]
198207
pub struct GetBlockFilter {
199208
/// The filter data.
200209
pub filter: Vec<u8>,
@@ -204,14 +213,17 @@ pub struct GetBlockFilter {
204213

205214
/// Models the result of JSON-RPC method `getblockhash`.
206215
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
216+
#[serde(deny_unknown_fields)]
207217
pub struct GetBlockHash(pub BlockHash);
208218

209219
/// Models the result of JSON-RPC method `getblockheader`.
210220
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
221+
#[serde(deny_unknown_fields)]
211222
pub struct GetBlockHeader(pub block::Header);
212223

213224
/// Models the result of JSON-RPC method `getblockheader`.
214225
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
226+
#[serde(deny_unknown_fields)]
215227
pub struct GetBlockHeaderVerbose {
216228
/// the block hash (same as provided).
217229
pub hash: BlockHash,
@@ -247,6 +259,7 @@ pub struct GetBlockHeaderVerbose {
247259

248260
/// Models the result of JSON-RPC method `getblockstats`.
249261
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
262+
#[serde(deny_unknown_fields)]
250263
pub struct GetBlockStats {
251264
/// Average fee in the block.
252265
pub average_fee: Amount,
@@ -316,10 +329,12 @@ pub struct GetBlockStats {
316329

317330
/// Models the result of JSON-RPC method `getchaintips`.
318331
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
332+
#[serde(deny_unknown_fields)]
319333
pub struct GetChainTips(pub Vec<ChainTips>);
320334

321335
/// An individual list item from the result of JSON-RPC method `getchaintips`.
322336
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
337+
#[serde(deny_unknown_fields)]
323338
pub struct ChainTips {
324339
/// Height of the chain tip.
325340
pub height: u32,
@@ -349,6 +364,7 @@ pub enum ChainTipsStatus {
349364

350365
/// Models the result of JSON-RPC method `getchaintxstats`.
351366
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
367+
#[serde(deny_unknown_fields)]
352368
pub struct GetChainTxStats {
353369
/// The timestamp for the final block in the window in UNIX format.
354370
pub time: u32,
@@ -370,30 +386,37 @@ pub struct GetChainTxStats {
370386

371387
/// Models the result of JSON-RPC method `getdifficulty`.
372388
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
389+
#[serde(deny_unknown_fields)]
373390
pub struct GetDifficulty(pub f64);
374391

375392
/// Models the result of JSON-RPC method `getmempoolancestors` with verbose set to false.
376393
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
394+
#[serde(deny_unknown_fields)]
377395
pub struct GetMempoolAncestors(pub Vec<Txid>);
378396

379397
/// Models the result of JSON-RPC method `getmempoolancestors` with verbose set to true.
380398
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
399+
#[serde(deny_unknown_fields)]
381400
pub struct GetMempoolAncestorsVerbose(pub BTreeMap<Txid, MempoolEntry>);
382401

383402
/// Models the result of JSON-RPC method `getmempoolancestors` with verbose set to false.
384403
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
404+
#[serde(deny_unknown_fields)]
385405
pub struct GetMempoolDescendants(pub Vec<Txid>);
386406

387407
/// Models the result of JSON-RPC method `getmempooldescendants` with verbose set to true.
388408
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
409+
#[serde(deny_unknown_fields)]
389410
pub struct GetMempoolDescendantsVerbose(pub BTreeMap<Txid, MempoolEntry>);
390411

391412
/// Models the result of JSON-RPC method `getmempoolentry`.
392413
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
414+
#[serde(deny_unknown_fields)]
393415
pub struct GetMempoolEntry(pub MempoolEntry);
394416

395417
/// A relative (ancestor or descendant) transaction of a transaction in the mempool.
396418
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
419+
#[serde(deny_unknown_fields)]
397420
pub struct MempoolEntry {
398421
/// Virtual transaction size as defined in BIP 141. v0.19 and later only.
399422
///
@@ -436,6 +459,7 @@ pub struct MempoolEntry {
436459

437460
/// (No docs in Core v0.17.)
438461
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
462+
#[serde(deny_unknown_fields)]
439463
pub struct MempoolEntryFees {
440464
/// Transaction fee in BTC.
441465
pub base: Amount,
@@ -449,6 +473,7 @@ pub struct MempoolEntryFees {
449473

450474
/// Models the result of JSON-RPC method `getmempoolinfo` with verbose set to true.
451475
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
476+
#[serde(deny_unknown_fields)]
452477
pub struct GetMempoolInfo {
453478
/// True if the mempool is fully loaded. v0.19 and later only.
454479
pub loaded: Option<bool>,
@@ -482,14 +507,17 @@ pub struct GetMempoolInfo {
482507

483508
/// Models the result of JSON-RPC method `getrawmempool` with verbose set to false.
484509
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
510+
#[serde(deny_unknown_fields)]
485511
pub struct GetRawMempool(pub Vec<Txid>);
486512

487513
/// Models the result of JSON-RPC method `getrawmempool` with verbose set to true.
488514
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
515+
#[serde(deny_unknown_fields)]
489516
pub struct GetRawMempoolVerbose(pub BTreeMap<Txid, MempoolEntry>);
490517

491518
/// Models the result of JSON-RPC method `gettxout`.
492519
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
520+
#[serde(deny_unknown_fields)]
493521
pub struct GetTxOut {
494522
/// The hash of the block at the tip of the chain.
495523
pub best_block: BlockHash,
@@ -507,6 +535,7 @@ pub struct GetTxOut {
507535

508536
/// Models the result of JSON-RPC method `gettxoutsetinfo`.
509537
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
538+
#[serde(deny_unknown_fields)]
510539
pub struct GetTxOutSetInfo {
511540
/// The current block height (index).
512541
pub height: u32,
@@ -533,10 +562,12 @@ pub struct GetTxOutSetInfo {
533562

534563
/// Models the result of JSON-RPC method `verifytxoutproof`.
535564
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
565+
#[serde(deny_unknown_fields)]
536566
pub struct VerifyTxOutProof(pub Vec<Txid>);
537567

538568
/// Models the result of the JSON-RPC method `getdescriptoractivity`.
539569
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
570+
#[serde(deny_unknown_fields)]
540571
pub struct GetDescriptorActivity {
541572
/// A list of activity events related to the descriptors.
542573
pub activity: Vec<ActivityEntry>,
@@ -553,6 +584,7 @@ pub enum ActivityEntry {
553584

554585
/// Models a 'spend' activity event with strongly typed fields.
555586
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
587+
#[serde(deny_unknown_fields)]
556588
pub struct SpendActivity {
557589
/// The total amount of the spent output.
558590
pub amount: Amount,
@@ -574,6 +606,7 @@ pub struct SpendActivity {
574606

575607
/// Models a 'receive' activity event with strongly typed fields.
576608
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
609+
#[serde(deny_unknown_fields)]
577610
pub struct ReceiveActivity {
578611
/// The total amount in BTC of the new output, converted to `bitcoin::Amount`.
579612
pub amount: Amount,

types/src/model/generating.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
1010

1111
/// Models the result of JSON-RPC method `generate`.
1212
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
13+
#[serde(deny_unknown_fields)]
1314
pub struct Generate(pub Vec<BlockHash>);
1415

1516
impl Generate {
@@ -22,6 +23,7 @@ impl Generate {
2223

2324
/// Models the result of JSON-RPC method `generatetoaddress`.
2425
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
26+
#[serde(deny_unknown_fields)]
2527
pub struct GenerateToAddress(pub Vec<BlockHash>);
2628

2729
impl GenerateToAddress {

types/src/model/mining.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use serde::{Deserialize, Serialize};
1414

1515
/// Models the result of JSON-RPC method `getblocktemplate`.
1616
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
17+
#[serde(deny_unknown_fields)]
1718
pub struct GetBlockTemplate {
1819
/// The preferred block version.
1920
pub version: block::Version,
@@ -73,6 +74,7 @@ pub struct GetBlockTemplate {
7374
///
7475
/// Returned as part of `getblocktemplate`.
7576
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
77+
#[serde(deny_unknown_fields)]
7678
pub struct BlockTemplateTransaction {
7779
/// The transaction.
7880
pub data: Transaction,
@@ -99,6 +101,7 @@ pub struct BlockTemplateTransaction {
99101

100102
/// Models the result of JSON-RPC method `getmininginfo`.
101103
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
104+
#[serde(deny_unknown_fields)]
102105
pub struct GetMiningInfo {
103106
/// The current block.
104107
pub blocks: u64,
@@ -131,6 +134,7 @@ pub struct GetMiningInfo {
131134

132135
/// Represents the `next` block information within the GetMiningInfo result.
133136
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
137+
#[serde(deny_unknown_fields)]
134138
pub struct NextBlockInfo {
135139
/// The next height.
136140
pub height: u64,
@@ -144,9 +148,11 @@ pub struct NextBlockInfo {
144148

145149
/// Models the result of JSON-RPC method `getprioritisedtransactions`.
146150
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
151+
#[serde(deny_unknown_fields)]
147152
pub struct GetPrioritisedTransactions(pub BTreeMap<Txid, PrioritisedTransaction>);
148153

149154
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
155+
#[serde(deny_unknown_fields)]
150156
pub struct PrioritisedTransaction {
151157
/// Transaction fee delta in satoshis.
152158
pub fee_delta: i64,

types/src/model/network.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use serde::{Deserialize, Serialize};
1111

1212
/// Models the result of JSON-RPC method `getnetworkinfo`.
1313
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
14+
#[serde(deny_unknown_fields)]
1415
pub struct GetNetworkInfo {
1516
/// The server version.
1617
pub version: usize,
@@ -48,6 +49,7 @@ pub struct GetNetworkInfo {
4849

4950
/// Part of the result of the JSON-RPC method `getnetworkinfo` (information per network).
5051
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
52+
#[serde(deny_unknown_fields)]
5153
pub struct GetNetworkInfoNetwork {
5254
/// Network (ipv4, ipv6, onion, i2p, cjdns).
5355
pub name: String,
@@ -63,6 +65,7 @@ pub struct GetNetworkInfoNetwork {
6365

6466
/// Part of the result of the JSON-RPC method `getnetworkinfo` (local address info).
6567
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
68+
#[serde(deny_unknown_fields)]
6669
pub struct GetNetworkInfoAddress {
6770
/// Network address.
6871
pub address: String,
@@ -78,10 +81,12 @@ pub struct GetNetworkInfoAddress {
7881
/// >
7982
/// > Return known addresses which can potentially be used to find new nodes in the network.
8083
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
84+
#[serde(deny_unknown_fields)]
8185
pub struct GetNodeAddresses(pub Vec<NodeAddress>);
8286

8387
/// An item from the list returned by the JSON-RPC method `getnodeaddresses`.
8488
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
89+
#[serde(deny_unknown_fields)]
8590
pub struct NodeAddress {
8691
/// Timestamp in seconds since epoch (Jan 1 1970 GMT) when the node was last seen.
8792
pub time: u64,

0 commit comments

Comments
 (0)