Пример #1
0
        private AdaptorSignature SignCET(Key key, DLCOutcome outcome)
        {
            if (OracleInfo is null)
            {
                throw new InvalidOperationException("Invalid state for signing CET");
            }
            var cet  = BuildCET(outcome);
            var hash = cet.GetSignatureHash(GetFundCoin());

            if (!OracleInfo.TryComputeSigpoint(outcome, out var sigpoint) || sigpoint is null)
            {
                throw new InvalidOperationException("TryComputeSigpoint failed");
            }
            if (!key.ToECPrivKey().TrySignAdaptor(hash.ToBytes(), sigpoint, out var sig, out var proof) || sig  is null || proof is null)
            {
                throw new InvalidOperationException("TrySignAdaptor failed");
            }
            return(new AdaptorSignature(sig, proof));
        }
Пример #2
0
        public Transaction BuildCET(DLCOutcome outcome)
        {
            if (Timeouts is null ||
                Offerer?.Collateral is null ||
                Acceptor?.Collateral is null ||
                Offerer?.Payout is null ||
                Acceptor?.Payout is null ||
                Timeouts is null ||
                OffererRewards is null)
            {
                throw new InvalidOperationException("We did not received enough data to create the refund");
            }
            if (!OffererRewards.TryGetValue(outcome, out var offererPayout) || offererPayout is null)
            {
                throw new InvalidOperationException("Invalid outcome");
            }
            var         funding = BuildFunding();
            Transaction tx      = network.CreateTransaction();

            tx.Version  = 2;
            tx.LockTime = Timeouts.ContractMaturity;
            tx.Inputs.Add(new OutPoint(funding.GetHash(), 0), sequence: 0xFFFFFFFE);

            var collateral = Offerer.Collateral + Acceptor.Collateral;

            tx.Outputs.Add(offererPayout, Offerer.Payout);
            tx.Outputs.Add(collateral - offererPayout, Acceptor.Payout);
            foreach (var output in tx.Outputs.ToArray())
            {
                if (output.Value < Money.Satoshis(1000))
                {
                    tx.Outputs.Remove(output);
                }
            }
            return(tx);
        }
Пример #3
0
 public bool TryComputeSigpoint(DLCOutcome outcome, out ECPubKey?sigpoint)
 {
     return(PubKey.TryComputeSigPoint(outcome.Hash, RValue, out sigpoint));
 }