mirror of
https://github.com/Qortal/pirate-librustzcash.git
synced 2025-01-30 23:42:13 +00:00
Attempt to redeem P2SH with secret. This is highly experimental.
Based on Qortal standard HTLCs. Will need adapting to Pirate specific ones at the very least.
This commit is contained in:
parent
3bc31b9cce
commit
a2e12ea51e
@ -141,6 +141,7 @@ struct TransparentInputInfo {
|
||||
sk: secp256k1::SecretKey,
|
||||
pubkey: [u8; secp256k1::constants::PUBLIC_KEY_SIZE],
|
||||
coin: TxOut,
|
||||
secret: Vec<u8>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
@ -171,6 +172,7 @@ impl TransparentInputs {
|
||||
sk: secp256k1::SecretKey,
|
||||
utxo: OutPoint,
|
||||
coin: TxOut,
|
||||
secret: Vec<u8>,
|
||||
) -> Result<(), Error> {
|
||||
if coin.value.is_negative() {
|
||||
return Err(Error::InvalidAmount);
|
||||
@ -190,7 +192,7 @@ impl TransparentInputs {
|
||||
}
|
||||
|
||||
mtx.vin.push(TxIn::new(utxo));
|
||||
self.inputs.push(TransparentInputInfo { sk, pubkey, coin });
|
||||
self.inputs.push(TransparentInputInfo { sk, pubkey, coin, secret });
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -232,10 +234,16 @@ impl TransparentInputs {
|
||||
let mut sig_bytes: Vec<u8> = sig.serialize_der()[..].to_vec();
|
||||
sig_bytes.extend(&[SIGHASH_ALL as u8]);
|
||||
|
||||
if (&info.secret.len() > 0) {
|
||||
// Include secret and redeem script
|
||||
mtx.vin[i].script_sig = Script::default() << &info.secret[..] << &sig_bytes[..] << &info.pubkey[..] << &info.coin.script_pubkey[..];
|
||||
}
|
||||
else {
|
||||
// P2PKH scriptSig
|
||||
mtx.vin[i].script_sig = Script::default() << &sig_bytes[..] << &info.pubkey[..];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "transparent-inputs"))]
|
||||
fn apply_signatures(&self, _: &mut TransactionData, _: consensus::BranchId) {}
|
||||
@ -398,7 +406,19 @@ impl<R: RngCore + CryptoRng> Builder<R> {
|
||||
utxo: OutPoint,
|
||||
coin: TxOut,
|
||||
) -> Result<(), Error> {
|
||||
self.transparent_inputs.push(&mut self.mtx, sk, utxo, coin)
|
||||
self.transparent_inputs.push(&mut self.mtx, sk, utxo, coin, Vec::new())
|
||||
}
|
||||
|
||||
/// Adds a transparent coin to be spent in this transaction, with HTLC secret.
|
||||
#[cfg(feature = "transparent-inputs")]
|
||||
pub fn add_transparent_input_with_secret(
|
||||
&mut self,
|
||||
sk: secp256k1::SecretKey,
|
||||
utxo: OutPoint,
|
||||
coin: TxOut,
|
||||
secret: Vec<u8>,
|
||||
) -> Result<(), Error> {
|
||||
self.transparent_inputs.push(&mut self.mtx, sk, utxo, coin, secret)
|
||||
}
|
||||
|
||||
/// Adds a transparent address to send funds to.
|
||||
|
Loading…
Reference in New Issue
Block a user