Skip to content

Commit 90f28c4

Browse files
committed
chore: export some tx stuff
1 parent a9221ef commit 90f28c4

File tree

9 files changed

+63
-44
lines changed

9 files changed

+63
-44
lines changed

dash/src/blockdata/transaction/mod.rs

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -179,29 +179,8 @@ pub struct Transaction {
179179
pub special_transaction_payload: Option<TransactionPayload>,
180180
}
181181

182+
#[cfg_attr(feature = "apple", ferment_macro::export)]
182183
impl Transaction {
183-
/// Computes a "normalized TXID" which does not include any signatures.
184-
/// This gives a way to identify a transaction that is "the same" as
185-
/// another in the sense of having same inputs and outputs.
186-
pub fn ntxid(&self) -> sha256d::Hash {
187-
let cloned_tx = Transaction {
188-
version: self.version,
189-
lock_time: self.lock_time,
190-
input: self
191-
.input
192-
.iter()
193-
.map(|txin| TxIn {
194-
script_sig: ScriptBuf::new(),
195-
witness: Witness::default(),
196-
..*txin
197-
})
198-
.collect(),
199-
output: self.output.clone(),
200-
special_transaction_payload: self.special_transaction_payload.clone(),
201-
};
202-
cloned_tx.txid().into()
203-
}
204-
205184
/// Computes the txid. For non-segwit transactions this will be identical
206185
/// to the output of `wtxid()`, but for segwit transactions,
207186
/// this will give the correct txid (not including witnesses) while `wtxid`
@@ -229,6 +208,36 @@ impl Transaction {
229208
TransactionType::from_optional_payload(&self.special_transaction_payload)
230209
}
231210

211+
/// Is this a coin base transaction?
212+
pub fn is_coin_base(&self) -> bool {
213+
self.input.len() == 1 && self.input[0].previous_output.is_null()
214+
}
215+
216+
}
217+
218+
impl Transaction {
219+
/// Computes a "normalized TXID" which does not include any signatures.
220+
/// This gives a way to identify a transaction that is "the same" as
221+
/// another in the sense of having same inputs and outputs.
222+
pub fn ntxid(&self) -> sha256d::Hash {
223+
let cloned_tx = Transaction {
224+
version: self.version,
225+
lock_time: self.lock_time,
226+
input: self
227+
.input
228+
.iter()
229+
.map(|txin| TxIn {
230+
script_sig: ScriptBuf::new(),
231+
witness: Witness::default(),
232+
..*txin
233+
})
234+
.collect(),
235+
output: self.output.clone(),
236+
special_transaction_payload: self.special_transaction_payload.clone(),
237+
};
238+
cloned_tx.txid().into()
239+
}
240+
232241
/// Computes SegWit-version of the transaction id (wtxid). For transaction with the witness
233242
/// data this hash includes witness, for pre-witness transaction it is equal to the normal
234243
/// value returned by txid() function.
@@ -557,11 +566,6 @@ impl Transaction {
557566
Ok(())
558567
}
559568

560-
/// Is this a coin base transaction?
561-
pub fn is_coin_base(&self) -> bool {
562-
self.input.len() == 1 && self.input[0].previous_output.is_null()
563-
}
564-
565569
/// Returns `true` if the transaction itself opted in to be BIP-125-replaceable (RBF). This
566570
/// **does not** cover the case where a transaction becomes replaceable due to ancestors being
567571
/// RBF.

dash/src/blockdata/transaction/special_transaction/asset_lock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub struct AssetLockPayload {
4747
pub credit_outputs: Vec<TxOut>,
4848
}
4949

50+
#[cfg_attr(feature = "apple", ferment_macro::export)]
5051
impl AssetLockPayload {
5152
/// The size of the payload in bytes.
5253
pub fn size(&self) -> usize {

dash/src/blockdata/transaction/special_transaction/coinbase.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub struct CoinbasePayload {
4646
pub asset_locked_amount: Option<u64>,
4747
}
4848

49+
#[cfg_attr(feature = "apple", ferment_macro::export)]
4950
impl CoinbasePayload {
5051
/// The size of the payload in bytes.
5152
/// version(2) + height(4) + merkle_root_masternode_list(32) + merkle_root_quorums(32)

dash/src/blockdata/transaction/special_transaction/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ impl Encodable for TransactionPayload {
9999
}
100100
}
101101

102+
#[cfg_attr(feature = "apple", ferment_macro::export)]
102103
impl TransactionPayload {
103104
/// Gets the Transaction Type for a Special Transaction Payload
104105
pub fn get_type(&self) -> TransactionType {
@@ -129,6 +130,9 @@ impl TransactionPayload {
129130
}
130131
}
131132

133+
}
134+
impl TransactionPayload {
135+
132136
/// Convenience method that assumes the payload to be a provider registration payload to get it
133137
/// easier.
134138
/// Errors if it is not a provider registration payload.
@@ -255,6 +259,7 @@ impl TransactionPayload {
255259
///
256260
#[derive(Clone, Copy, PartialEq, Eq)]
257261
#[repr(u16)]
262+
#[cfg_attr(feature = "apple", ferment_macro::export)]
258263
pub enum TransactionType {
259264
/// A Classic transaction
260265
Classic = 0,

dash/src/blockdata/transaction/special_transaction/provider_registration.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,23 @@ pub struct ProviderRegistrationPayload {
118118
pub platform_p2p_port: Option<u16>,
119119
pub platform_http_port: Option<u16>,
120120
}
121-
121+
#[cfg_attr(feature = "apple", ferment_macro::export)]
122+
impl ProviderRegistrationPayload {
123+
/// The size of the payload in bytes.
124+
/// version(2) + provider_type(2) + provider_mode(2) + collateral_outpoint(32 + 4) + ip_address(16) +
125+
/// port(2) + owner_key_hash(20) + operator_public_key(48) + voting_key_hash(20) + operator_reward(2) +
126+
/// script_payout(VarInt(script_payout_len).len() + script_payout_len) +
127+
/// inputs_hash(32) +
128+
/// payload_sig(VarInt(payload_sig_len).len() + payload_sig_len)
129+
pub fn size(&self) -> usize {
130+
let mut size = 2 + 2 + 2 + 32 + 4 + 16 + 2 + 20 + 48 + 20 + 2 + 32; // 182 bytes
131+
let script_payout_len = self.script_payout.0.len();
132+
let signature_len = self.signature.len();
133+
size += VarInt(script_payout_len as u64).len() + script_payout_len;
134+
size += VarInt(signature_len as u64).len() + signature_len;
135+
size
136+
}
137+
}
122138
impl ProviderRegistrationPayload {
123139
/// A convenience method to get the address from payout script
124140
pub fn payout_address(&self, network: Network) -> Result<Address, encode::Error> {
@@ -153,21 +169,6 @@ impl ProviderRegistrationPayload {
153169
base_payload_hash.as_byte_array().to_hex_string(Lower)
154170
))
155171
}
156-
157-
/// The size of the payload in bytes.
158-
/// version(2) + provider_type(2) + provider_mode(2) + collateral_outpoint(32 + 4) + ip_address(16) +
159-
/// port(2) + owner_key_hash(20) + operator_public_key(48) + voting_key_hash(20) + operator_reward(2) +
160-
/// script_payout(VarInt(script_payout_len).len() + script_payout_len) +
161-
/// inputs_hash(32) +
162-
/// payload_sig(VarInt(payload_sig_len).len() + payload_sig_len)
163-
pub fn size(&self) -> usize {
164-
let mut size = 2 + 2 + 2 + 32 + 4 + 16 + 2 + 20 + 48 + 20 + 2 + 32; // 182 bytes
165-
let script_payout_len = self.script_payout.0.len();
166-
let signature_len = self.signature.len();
167-
size += VarInt(script_payout_len as u64).len() + script_payout_len;
168-
size += VarInt(signature_len as u64).len() + signature_len;
169-
size
170-
}
171172
}
172173

173174
impl SpecialTransactionBasePayloadEncodable for ProviderRegistrationPayload {

dash/src/blockdata/transaction/special_transaction/provider_update_registrar.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub struct ProviderUpdateRegistrarPayload {
5959
pub payload_sig: Vec<u8>, // TODO: Need to figure out, is this signature BLS Signature (length 96)
6060
}
6161

62+
#[cfg_attr(feature = "apple", ferment_macro::export)]
6263
impl ProviderUpdateRegistrarPayload {
6364
/// The size of the payload in bytes.
6465
pub fn size(&self) -> usize {

dash/src/blockdata/transaction/special_transaction/provider_update_revocation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ pub struct ProviderUpdateRevocationPayload {
6262
pub payload_sig: BLSSignature,
6363
}
6464

65+
#[cfg_attr(feature = "apple", ferment_macro::export)]
6566
impl ProviderUpdateRevocationPayload {
6667
/// The size of the payload in bytes.
6768
pub fn size(&self) -> usize {

dash/src/blockdata/transaction/special_transaction/provider_update_service.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub struct ProviderUpdateServicePayload {
6363
pub payload_sig: BLSSignature,
6464
}
6565

66+
#[cfg_attr(feature = "apple", ferment_macro::export)]
6667
impl ProviderUpdateServicePayload {
6768
/// The size of the payload in bytes.
6869
pub fn size(&self) -> usize {

dash/src/blockdata/transaction/special_transaction/quorum_commitment.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub struct QuorumEntry {
5252
pub threshold_sig: BLSSignature,
5353
pub all_commitment_aggregated_signature: BLSSignature,
5454
}
55-
55+
#[cfg_attr(feature = "apple", ferment_macro::export)]
5656
impl QuorumEntry {
5757
/// The size of the payload in bytes.
5858
pub fn size(&self) -> usize {
@@ -67,6 +67,9 @@ impl QuorumEntry {
6767
size
6868
}
6969

70+
}
71+
impl QuorumEntry {
72+
7073
pub fn validate_structure(&self) -> Result<(), QuorumValidationError> {
7174
let quorum_threshold = self.llmq_type.threshold() as u64;
7275

@@ -191,6 +194,7 @@ pub struct QuorumCommitmentPayload {
191194
pub finalization_commitment: QuorumEntry,
192195
}
193196

197+
#[cfg_attr(feature = "apple", ferment_macro::export)]
194198
impl QuorumCommitmentPayload {
195199
/// The size of the payload in bytes.
196200
pub fn size(&self) -> usize {

0 commit comments

Comments
 (0)