Skip to content

Commit da804af

Browse files
better asset unlocks (#7)
* better asset unlocks * better asset unlocks * better asset unlocks
1 parent 3b2a9a7 commit da804af

3 files changed

Lines changed: 74 additions & 31 deletions

File tree

src/blockdata/transaction/special_transaction/asset_unlock/request_info.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,21 @@
1212
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
1313
//
1414

15-
//! Dash Credit Withdrawal Special Transaction.
15+
//! Dash Asset unlock Special Transaction request info.
1616
//!
17-
//! The credit withdrawal special transaction is used to withdraw from the asset lock credit pool.
17+
//! The asset unlock special transaction is used to withdraw from the asset lock credit pool.
1818
//!
19-
//!
20-
//! It is defined in DIPX https://github.com/dashpay/dips/blob/master/dip-000X.md as follows:
21-
//!
22-
//!
23-
//! The special transaction type used for CrWithTx Transactions is 9.
19+
//! The request info should be added once the quorum selection for signing has been made.
2420
2521
use ::{io};
2622
use io::{Error, Write};
2723
use consensus::{Decodable, Encodable, encode};
2824
use ::{QuorumHash};
2925
use prelude::*;
3026

31-
/// A Credit Withdrawal payload. This is contained as the payload of a credit withdrawal special
32-
/// transaction.
33-
/// The Credit Withdrawal Special transaction and this payload is described in the Asset Lock DIP2X
34-
/// (todo:update this).
35-
/// The Credit Withdrawal Payload is signed by a quorum.
36-
///
37-
/// Transaction using it have no inputs. Hence the proof of validity lies solely on the BLS signature.
38-
///
27+
/// An asset unlock request info
28+
/// This is the information about the signing quorum
29+
/// The request height should be the height at which the specified quorum is active on core.
3930
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
4031
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
4132
pub struct AssetUnlockRequestInfo {

src/blockdata/transaction/special_transaction/asset_unlock/unqualified_asset_unlock.rs

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,37 @@
1212
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
1313
//
1414

15-
//! Dash Credit Withdrawal Special Transaction.
15+
//! Dash Asset Unlock Base Special Transaction and Payload.
1616
//!
17-
//! The credit withdrawal special transaction is used to withdraw from the asset lock credit pool.
17+
//! These base elements are used in withdrawal queues.
1818
//!
1919
//!
2020
//! It is defined in DIPX https://github.com/dashpay/dips/blob/master/dip-000X.md as follows:
2121
//!
2222
//!
23-
//! The special transaction type used for CrWithTx Transactions is 9.
23+
//! The special transaction type used for AssetUnlockTx Transactions is 9.
2424
2525
use io::{Error, Write};
26-
use io;
26+
use core::convert::TryFrom;
27+
use ::{io, TxOut};
28+
use blockdata::transaction::special_transaction::TransactionType;
29+
use blockdata::transaction::special_transaction::TransactionType::AssetUnlock;
2730
use consensus::{Decodable, Encodable, encode};
31+
use consensus::encode::MAX_VEC_SIZE;
32+
use TxIn;
33+
use prelude::*;
2834

29-
/// A Credit Withdrawal payload. This is contained as the payload of a credit withdrawal special
30-
/// transaction.
31-
/// The Credit Withdrawal Special transaction and this payload is described in the Asset Lock DIP2X
32-
/// (todo:update this).
33-
/// The Credit Withdrawal Payload is signed by a quorum.
34-
///
35-
/// Transaction using it have no inputs. Hence the proof of validity lies solely on the BLS signature.
36-
///
35+
/// An Asset Unlock Base payload. This is the base payload of the Asset Unlock. In order to make
36+
/// it a full payload the request info should be added.
3737
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
3838
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
3939
pub struct AssetUnlockBasePayload {
40-
version: u8,
41-
index: u64,
42-
fee: u32,
40+
/// The payload protocol version, is currently expected to be 0.
41+
pub version: u8,
42+
/// The index of the unlock transaction. It gets bumped on each transaction
43+
pub index: u64,
44+
/// The fee used in Duffs (Satoshis)
45+
pub fee: u32,
4346
}
4447

4548
impl Encodable for AssetUnlockBasePayload {
@@ -64,3 +67,52 @@ impl Decodable for AssetUnlockBasePayload {
6467
})
6568
}
6669
}
70+
71+
/// An Asset Unlock Base Transaction Info. This is the base transaction information that is needed
72+
/// to be kept in withdrawal queues.
73+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
74+
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
75+
pub struct AssetUnlockBaseTransactionInfo {
76+
/// The protocol version, is currently expected to be 1 or 2 (BIP 68).
77+
pub version: u16,
78+
/// Block number before which this transaction is valid, or 0 for valid immediately.
79+
pub lock_time: u32,
80+
/// List of transaction outputs.
81+
pub output: Vec<TxOut>,
82+
/// Base payload information
83+
pub base_payload: AssetUnlockBasePayload,
84+
}
85+
86+
impl Encodable for AssetUnlockBaseTransactionInfo {
87+
fn consensus_encode<S: Write>(&self, mut s: S) -> Result<usize, Error> {
88+
let mut len = 0;
89+
len += self.version.consensus_encode(&mut s)?;
90+
len += (AssetUnlock as u16).consensus_encode(&mut s)?;
91+
len += Vec::<TxIn>::new().consensus_encode(&mut s)?;
92+
len += self.output.consensus_encode(&mut s)?;
93+
len += self.lock_time.consensus_encode(&mut s)?;
94+
len += self.base_payload.consensus_encode(&mut s)?;
95+
Ok(len)
96+
}
97+
}
98+
99+
impl Decodable for AssetUnlockBaseTransactionInfo {
100+
fn consensus_decode<D: io::Read>(d: D) -> Result<Self, encode::Error> {
101+
let mut d = d.take(MAX_VEC_SIZE as u64);
102+
let version = u16::consensus_decode(&mut d)?;
103+
let special_transaction_type_u16 = u16::consensus_decode(&mut d)?;
104+
let special_transaction_type = TransactionType::try_from(special_transaction_type_u16).map_err(|_| encode::Error::UnknownSpecialTransactionType(special_transaction_type_u16))?;
105+
if special_transaction_type != AssetUnlock {
106+
return Err(encode::Error::WrongSpecialTransactionPayloadConversion{ expected: AssetUnlock, actual: special_transaction_type})
107+
}
108+
Vec::<TxIn>::consensus_decode(&mut d)?; //no inputs
109+
Ok(AssetUnlockBaseTransactionInfo {
110+
version,
111+
output: Decodable::consensus_decode(&mut d)?,
112+
lock_time: Decodable::consensus_decode(&mut d)?,
113+
base_payload: AssetUnlockBasePayload::consensus_decode(d)?
114+
})
115+
}
116+
}
117+
118+

src/blockdata/transaction/special_transaction/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl TransactionPayload {
193193
/// The first part for the version and the second part for the transaction
194194
/// type.
195195
///
196-
#[derive(Clone, Copy)]
196+
#[derive(Clone, Copy, PartialEq, Eq)]
197197
#[repr(u16)]
198198
pub enum TransactionType {
199199
/// A Classic transaction

0 commit comments

Comments
 (0)