public virtual void ConfigureEscrowedCoin(uint160 channelId, ScriptCoin escrowedCoin, Key escrowKey,
                                                  Script redeemDestination)
        {
            if (escrowedCoin == null)
            {
                throw new ArgumentNullException(nameof(escrowedCoin));
            }
            if (escrowKey == null)
            {
                throw new ArgumentNullException(nameof(escrowKey));
            }
            var escrow = EscrowScriptPubKeyParameters.GetFromCoin(escrowedCoin);

            if (escrow == null ||
                escrow.Initiator != escrowKey.PubKey)
            {
                throw new PuzzleException("Invalid escrow");
            }
            InternalState.ChannelId         = channelId ?? throw new ArgumentNullException(nameof(channelId));
            InternalState.EscrowedCoin      = escrowedCoin;
            InternalState.EscrowKey         = escrowKey;
            InternalState.RedeemDestination =
                redeemDestination ?? throw new ArgumentNullException(nameof(redeemDestination));

            Logs.Tumbler.LogDebug(
                $"EscrowInitiator.ConfigureEscrowedCoin() - ChannelId : {InternalState.ChannelId}, EscrowedCoin.Outpoint.Hash : {InternalState.EscrowedCoin.Outpoint.Hash}, EscrowedCoin.Outpoint.N : {InternalState.EscrowedCoin.Outpoint.N}, RedeemDestination : {InternalState.RedeemDestination}");
        }
        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);
        }
        public virtual void ConfigureEscrowedCoin(ScriptCoin escrowedCoin, Key escrowKey, Script redeemDestination)
        {
            if (escrowedCoin == null)
            {
                throw new ArgumentNullException(nameof(escrowedCoin));
            }
            if (escrowKey == null)
            {
                throw new ArgumentNullException(nameof(escrowKey));
            }
            if (redeemDestination == null)
            {
                throw new ArgumentNullException(nameof(redeemDestination));
            }
            var escrow = EscrowScriptPubKeyParameters.GetFromCoin(escrowedCoin);

            if (escrow == null ||
                escrow.Initiator != escrowKey.PubKey)
            {
                throw new PuzzleException("Invalid escrow");
            }
            InternalState.EscrowedCoin      = escrowedCoin;
            InternalState.EscrowKey         = escrowKey;
            InternalState.RedeemDestination = redeemDestination;
        }