Skip to content

Commit 71d40ce

Browse files
committed
Add additional defi header fields and token_id in TxOut
1 parent 8d32a49 commit 71d40ce

File tree

9 files changed

+63
-21
lines changed

9 files changed

+63
-21
lines changed

bitcoin/src/bip152.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl HeaderAndShortIds {
232232
}
233233

234234
Ok(HeaderAndShortIds {
235-
header: block.header,
235+
header: block.header.clone(),
236236
nonce,
237237
// Provide coinbase prefilled.
238238
prefilled_txs: prefilled,

bitcoin/src/blockdata/block.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub use crate::{
3838
/// ### Bitcoin Core References
3939
///
4040
/// * [CBlockHeader definition](https://github.com/bitcoin/bitcoin/blob/345457b542b6a980ccfbc868af0970a6f91d1b82/src/primitives/block.h#L20)
41-
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
41+
#[derive(PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
4242
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4343
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
4444
pub struct Header {
@@ -52,11 +52,24 @@ pub struct Header {
5252
pub time: u32,
5353
/// The target value below which the blockhash must lie.
5454
pub bits: CompactTarget,
55-
/// The nonce, selected to obtain a low enough blockhash.
56-
pub nonce: u32,
55+
pub stake_modifier: [u8; 32],
56+
pub deprecated_height: u64,
57+
pub minted_blocks: u64,
58+
pub sig: Vec<u8>,
5759
}
5860

59-
impl_consensus_encoding!(Header, version, prev_blockhash, merkle_root, time, bits, nonce);
61+
impl_consensus_encoding!(
62+
Header,
63+
version,
64+
prev_blockhash,
65+
merkle_root,
66+
time,
67+
bits,
68+
stake_modifier,
69+
deprecated_height,
70+
minted_blocks,
71+
sig
72+
);
6073

6174
impl Header {
6275
/// The number of bytes that the block header contributes to the size of a block.
@@ -109,7 +122,11 @@ impl fmt::Debug for Header {
109122
.field("merkle_root", &self.merkle_root)
110123
.field("time", &self.time)
111124
.field("bits", &self.bits)
112-
.field("nonce", &self.nonce)
125+
.field("bits", &self.bits)
126+
.field("stake_modifier", &self.stake_modifier)
127+
.field("deprecated_height", &self.deprecated_height)
128+
.field("minted_blocks", &self.minted_blocks)
129+
.field("sig", &self.sig)
113130
.finish()
114131
}
115132
}

bitcoin/src/blockdata/constants.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! single transaction.
88
//!
99
10+
use alloc::vec;
1011
use core::default::Default;
1112

1213
use hashes::{sha256d, Hash};
@@ -79,7 +80,11 @@ fn bitcoin_genesis_tx() -> Transaction {
7980
let script_bytes = hex!("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f");
8081
let out_script =
8182
script::Builder::new().push_slice(script_bytes).push_opcode(OP_CHECKSIG).into_script();
82-
ret.output.push(TxOut { value: Amount::from_sat(50 * 100_000_000), script_pubkey: out_script });
83+
ret.output.push(TxOut {
84+
value: Amount::from_sat(50 * 100_000_000),
85+
script_pubkey: out_script,
86+
unused_token_id: 0,
87+
});
8388

8489
// end
8590
ret
@@ -98,7 +103,10 @@ pub fn genesis_block(network: Network) -> Block {
98103
merkle_root,
99104
time: 1231006505,
100105
bits: CompactTarget::from_consensus(0x1d00ffff),
101-
nonce: 2083236893,
106+
stake_modifier: [0u8; 32],
107+
deprecated_height: 0,
108+
minted_blocks: 0,
109+
sig: vec![],
102110
},
103111
txdata,
104112
},
@@ -109,7 +117,10 @@ pub fn genesis_block(network: Network) -> Block {
109117
merkle_root,
110118
time: 1296688602,
111119
bits: CompactTarget::from_consensus(0x1d00ffff),
112-
nonce: 414098458,
120+
stake_modifier: [0u8; 32],
121+
deprecated_height: 0,
122+
minted_blocks: 0,
123+
sig: vec![],
113124
},
114125
txdata,
115126
},
@@ -120,7 +131,10 @@ pub fn genesis_block(network: Network) -> Block {
120131
merkle_root,
121132
time: 1598918400,
122133
bits: CompactTarget::from_consensus(0x1e0377ae),
123-
nonce: 52613770,
134+
stake_modifier: [0u8; 32],
135+
deprecated_height: 0,
136+
minted_blocks: 0,
137+
sig: vec![],
124138
},
125139
txdata,
126140
},
@@ -131,7 +145,10 @@ pub fn genesis_block(network: Network) -> Block {
131145
merkle_root,
132146
time: 1296688602,
133147
bits: CompactTarget::from_consensus(0x207fffff),
134-
nonce: 2,
148+
stake_modifier: [0u8; 32],
149+
deprecated_height: 0,
150+
minted_blocks: 0,
151+
sig: vec![],
135152
},
136153
txdata,
137154
},

bitcoin/src/blockdata/transaction.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,12 +504,17 @@ pub struct TxOut {
504504
pub value: Amount,
505505
/// The script which must be satisfied for the output to be spent.
506506
pub script_pubkey: ScriptBuf,
507+
/// Unused. Legacy token_id
508+
pub unused_token_id: u8,
507509
}
508510

509511
impl TxOut {
510512
/// This is used as a "null txout" in consensus signing code.
511-
pub const NULL: Self =
512-
TxOut { value: Amount::from_sat(0xffffffffffffffff), script_pubkey: ScriptBuf::new() };
513+
pub const NULL: Self = TxOut {
514+
value: Amount::from_sat(0xffffffffffffffff),
515+
script_pubkey: ScriptBuf::new(),
516+
unused_token_id: 0,
517+
};
513518

514519
/// The weight of this output.
515520
///
@@ -548,6 +553,7 @@ impl TxOut {
548553
TxOut {
549554
value: Amount::from_sat(dust_amount + 1), // minimal non-dust amount is one higher than dust amount
550555
script_pubkey,
556+
unused_token_id: 0,
551557
}
552558
}
553559
}
@@ -1006,7 +1012,7 @@ impl Decodable for Version {
10061012
}
10071013
}
10081014

1009-
impl_consensus_encoding!(TxOut, value, script_pubkey);
1015+
impl_consensus_encoding!(TxOut, value, script_pubkey, unused_token_id);
10101016

10111017
impl Encodable for OutPoint {
10121018
fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {

bitcoin/src/internal_macros.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
//! Macros meant to be used inside the Rust Bitcoin library.
66
//!
77
8+
#[macro_export]
89
macro_rules! impl_consensus_encoding {
910
($thing:ident, $($field:ident),+) => (
1011
impl $crate::consensus::Encodable for $thing {
1112
#[inline]
12-
fn consensus_encode<R: $crate::io::Write + ?Sized>(
13+
fn consensus_encode<R: io::Write + ?Sized>(
1314
&self,
1415
r: &mut R,
15-
) -> Result<usize, $crate::io::Error> {
16+
) -> Result<usize, io::Error> {
1617
let mut len = 0;
1718
$(len += self.$field.consensus_encode(r)?;)+
1819
Ok(len)
@@ -22,7 +23,7 @@ macro_rules! impl_consensus_encoding {
2223
impl $crate::consensus::Decodable for $thing {
2324

2425
#[inline]
25-
fn consensus_decode_from_finite_reader<R: $crate::io::Read + ?Sized>(
26+
fn consensus_decode_from_finite_reader<R: io::Read + ?Sized>(
2627
r: &mut R,
2728
) -> Result<$thing, $crate::consensus::encode::Error> {
2829
Ok($thing {
@@ -31,7 +32,7 @@ macro_rules! impl_consensus_encoding {
3132
}
3233

3334
#[inline]
34-
fn consensus_decode<R: $crate::io::Read + ?Sized>(
35+
fn consensus_decode<R: io::Read + ?Sized>(
3536
r: &mut R,
3637
) -> Result<$thing, $crate::consensus::encode::Error> {
3738
let mut r = r.take($crate::consensus::encode::MAX_VEC_SIZE as u64);

bitcoin/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub mod sign_message;
113113
pub mod string;
114114
pub mod taproot;
115115

116-
use bitcoin_io::io;
116+
pub use bitcoin_io::io;
117117

118118
#[rustfmt::skip] // Keep public re-exports separate.
119119
#[doc(inline)]

bitcoin/src/merkle_tree/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl MerkleBlock {
123123
let matches: Vec<bool> = block_txids.iter().map(match_txids).collect();
124124

125125
let pmt = PartialMerkleTree::from_txids(block_txids, &matches);
126-
MerkleBlock { header: *header, txn: pmt }
126+
MerkleBlock { header: header.clone(), txn: pmt }
127127
}
128128

129129
/// Extract the matching txid's represented by this partial merkle tree

bitcoin/src/p2p/message_compact_blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//! BIP152 Compact Blocks network messages
55
//!
66
7-
use crate::bip152;
87
use crate::internal_macros::impl_consensus_encoding;
8+
use crate::{bip152, io};
99

1010
/// sendcmpct message
1111
#[derive(PartialEq, Eq, Clone, Debug, Copy, PartialOrd, Ord, Hash)]

bitcoin/src/p2p/message_filter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
use crate::hash_types::{BlockHash, FilterHash, FilterHeader};
99
use crate::internal_macros::impl_consensus_encoding;
10+
use crate::io;
1011

1112
/// getcfilters message
1213
#[derive(PartialEq, Eq, Clone, Debug)]

0 commit comments

Comments
 (0)