public TrustedBroadcastRequest CreateRedeemTransaction(FeeRate feeRate)
        {
            if (feeRate == null)
            {
                throw new ArgumentNullException(nameof(feeRate));
            }

            var         escrow     = EscrowScriptPubKeyParameters.GetFromCoin(InternalState.EscrowedCoin);
            var         escrowCoin = InternalState.EscrowedCoin;
            Transaction tx         = new Transaction();

            tx.LockTime = escrow.LockTime;
            tx.Inputs.Add(new TxIn());
            //Put a dummy signature and the redeem script
            tx.Inputs[0].ScriptSig =
                new Script(
                    Op.GetPushOp(TrustedBroadcastRequest.PlaceholderSignature),
                    Op.GetPushOp(escrowCoin.Redeem.ToBytes()));
            tx.Inputs[0].Witnessify();
            tx.Inputs[0].Sequence = 0;

            tx.Outputs.Add(new TxOut(escrowCoin.Amount, InternalState.RedeemDestination));
            tx.Outputs[0].Value -= feeRate.GetFee(tx.GetVirtualSize());

            var redeemTransaction = new TrustedBroadcastRequest
            {
                Key = InternalState.EscrowKey,
                PreviousScriptPubKey = escrowCoin.ScriptPubKey,
                Transaction          = tx,
                KnownPrevious        = new Coin[] { escrowCoin }
            };

            return(redeemTransaction);
        }
Exemple #2
0
        public TrustedBroadcastRequest CreateRedeemTransaction(FeeRate feeRate, Script redeemDestination)
        {
            if (feeRate == null)
            {
                throw new ArgumentNullException(nameof(feeRate));
            }

            var coin   = InternalState.EscrowedCoin;
            var escrow = EscrowScriptBuilder.ExtractEscrowScriptPubKeyParameters(coin.Redeem);

            Transaction tx = new Transaction();

            tx.LockTime = escrow.LockTime;
            tx.Inputs.Add(new TxIn(coin.Outpoint));
            tx.Inputs[0].Sequence = 0;
            tx.Outputs.Add(new TxOut(coin.Amount, redeemDestination));
            tx.Inputs[0].ScriptSig = EscrowScriptBuilder.GenerateScriptSig(new TransactionSignature[] { null }) + Op.GetPushOp(coin.Redeem.ToBytes());

            var vSize = tx.GetVirtualSize() + 80;             // Size without signature + the signature size

            tx.Outputs[0].Value -= feeRate.GetFee(vSize);

            var redeemTransaction = new TrustedBroadcastRequest
            {
                Key = InternalState.RedeemKey,
                PreviousScriptPubKey = coin.Redeem.Hash.ScriptPubKey,
                Transaction          = tx
            };

            //Strip redeem script information so we check if TrustedBroadcastRequest can sign correctly
            redeemTransaction.Transaction = redeemTransaction.ReSign(new Coin(coin.Outpoint, coin.TxOut));
            return(redeemTransaction);
        }