Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ use blockdata::transaction::special_transaction::SpecialTransactionBasePayloadEn
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct AssetUnlockPayload {
base: AssetUnlockBasePayload,
request_info: AssetUnlockRequestInfo,
quorum_sig: BLSSignature,
/// The base information about the asset unlock. This base information is the information that
/// should be put into a queue.
pub base: AssetUnlockBasePayload,
/// The request information. This should be added to the unlock transaction as it is being sent
/// to be signed.
pub request_info: AssetUnlockRequestInfo,
/// The threshold signature. This should be returned by the consensus engine.
pub quorum_sig: BLSSignature,
}

impl SpecialTransactionBasePayloadEncodable for AssetUnlockPayload {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ use prelude::*;
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct AssetUnlockRequestInfo {
request_height: u32,
quorum_hash: QuorumHash,
/// The core request height of the transaction. This should match a period where the quorum_hash
/// is still active
pub request_height: u32,
/// The quorum hash. This is the block hash when the quorum was created.
pub quorum_hash: QuorumHash,
}

impl AssetUnlockRequestInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ use blockdata::transaction::special_transaction::TransactionType;
use blockdata::transaction::special_transaction::TransactionType::AssetUnlock;
use consensus::{Decodable, Encodable, encode};
use consensus::encode::MAX_VEC_SIZE;
use TxIn;
use ::{Script, TxIn};
use prelude::*;
use ::{PubkeyHash, ScriptHash};

/// An Asset Unlock Base payload. This is the base payload of the Asset Unlock. In order to make
/// it a full payload the request info should be added.
Expand Down Expand Up @@ -83,6 +84,40 @@ pub struct AssetUnlockBaseTransactionInfo {
pub base_payload: AssetUnlockBasePayload,
}

impl AssetUnlockBaseTransactionInfo {
/// Adds an output that burns Dash. Used to top up a Dash Identity;
/// accepts hash of the public key to prove ownership of the burnt
/// dash on Dash Platform.
pub fn add_burn_output(&mut self, satoshis_to_burn: u64, data: &[u8; 20]) {
let burn_script = Script::new_op_return(data);
let output = TxOut {
value: satoshis_to_burn,
script_pubkey: burn_script,
};
self.output.push(output)
}

/// Convenience method that adds an output that pays to a public key hash.
pub fn add_p2pkh_output(&mut self, amount: u64, public_key_hash: &PubkeyHash) {
let public_key_hash_script = Script::new_p2pkh(public_key_hash);
let output = TxOut {
value: amount,
script_pubkey: public_key_hash_script,
};
self.output.push(output)
}

/// Convenience method that adds an output that pays to a public key hash.
pub fn add_p2sh_output(&mut self, amount: u64, script_hash: &ScriptHash) {
let pay_to_script_hash_script = Script::new_p2sh(script_hash);
let output = TxOut {
value: amount,
script_pubkey: pay_to_script_hash_script,
};
self.output.push(output)
}
}

impl Encodable for AssetUnlockBaseTransactionInfo {
fn consensus_encode<S: Write>(&self, mut s: S) -> Result<usize, Error> {
let mut len = 0;
Expand Down