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
2525use 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 ;
2730use 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 ) ) ]
3939pub 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
4548impl 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+
0 commit comments