Пример #1
0
        public TransactionSignature SignOffer(OfferInformation offerInformation)
        {
            if (offerInformation == null)
            {
                throw new ArgumentNullException(nameof(offerInformation));
            }
            AssertState(SolverClientStates.WaitingOffer);
            InternalState.FulfillKey          = offerInformation.FulfillKey;
            InternalState.OfferTransactionFee = offerInformation.Fee;
            Transaction tx        = CreateUnsignedOfferTransaction();
            var         signature = tx.Inputs.AsIndexedInputs().First().Sign(InternalState.EscrowKey, InternalState.EscrowedCoin, SigHash.All);

            InternalState.Status = SolverClientStates.WaitingPuzzleSolutions;
            return(signature);
        }
Пример #2
0
        public TransactionSignature SignOffer(OfferInformation offerInformation)
        {
            if (offerInformation == null)
            {
                throw new ArgumentNullException(nameof(offerInformation));
            }
            AssertState(SolverClientStates.WaitingOffer);

            var offerScript = new OfferScriptPubKeyParameters
            {
                Hashes     = _PuzzleElements.OfType <RealPuzzle>().Select(p => p.Commitment.KeyHash).ToArray(),
                FulfillKey = offerInformation.FulfillKey,
                Expiration = EscrowScriptPubKeyParameters.GetFromCoin(InternalState.EscrowedCoin).LockTime,
                RedeemKey  = InternalState.EscrowKey.PubKey
            }.ToScript();

            var escrowCoin = InternalState.EscrowedCoin;
            var txOut      = new TxOut(escrowCoin.Amount - offerInformation.Fee, offerScript.WitHash.ScriptPubKey.Hash);
            var offerCoin  = new Coin(escrowCoin.Outpoint, txOut).ToScriptCoin(offerScript);


            Transaction tx = new Transaction();

            tx.Inputs.Add(new TxIn(escrowCoin.Outpoint));
            tx.Outputs.Add(offerCoin.TxOut);

            var escrow = EscrowScriptPubKeyParameters.GetFromCoin(escrowCoin);

            escrowCoin = escrowCoin.Clone();
            escrowCoin.OverrideScriptCode(escrow.GetInitiatorScriptCode());
            var signature = tx.Inputs.AsIndexedInputs().First().Sign(InternalState.EscrowKey, escrowCoin, SigHash.All);

            InternalState.OfferCoin = offerCoin;
            InternalState.Status    = SolverClientStates.WaitingPuzzleSolutions;
            return(signature);
        }