public override bool Equals(object obj) { EscrowScriptPubKeyParameters item = obj as EscrowScriptPubKeyParameters; if (item == null) { return(false); } return(ToScript().Equals(item.ToScript())); }
private static EscrowScriptPubKeyParameters GetFromScript(Script script) { EscrowScriptPubKeyParameters parameters = new EscrowScriptPubKeyParameters(); try { var data = script.ToOps().Where(o => o.PushData != null).ToArray(); parameters.Initiator = new PubKey(data[0].PushData); parameters.Receiver = new PubKey(data[2].PushData); parameters.LockTime = new LockTime(data[3].GetInt().Value); //Verify it is the same as if we had done it if (parameters.ToScript() != script) { throw new Exception(); } return(parameters); } catch { return(null); } }
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)); }
public TrustedBroadcastRequest CreateRedeemTransaction(Network network, 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)); var virtualSize = tx.HasWitness ? tx.GetVirtualSize(network.Consensus.Options.WitnessScaleFactor) : tx.GetSerializedSize(); tx.Outputs[0].Value -= feeRate.GetFee(tx.GetVirtualSize(virtualSize)); var redeemTransaction = new TrustedBroadcastRequest { Key = InternalState.EscrowKey, PreviousScriptPubKey = escrowCoin.ScriptPubKey, Transaction = tx, KnownPrevious = new Coin[] { escrowCoin } }; return(redeemTransaction); }