示例#1
0
        public Money Offer(
            ECXOnlyPubKey oraclePubKey,
            SchnorrNonce eventNonce,
            DiscretePayoffs offererPayoffs,
            Timeouts timeouts, Money?collateral = null)
        {
            using var tx = StartTransaction();
            if (!s.IsInitiator)
            {
                throw new InvalidOperationException("The acceptor can't initiate an offer");
            }
            s.OracleInfo     = new OracleInfo(oraclePubKey, eventNonce);
            s.Timeouts       = timeouts;
            s.OffererPayoffs = offererPayoffs;
            s.Offerer        = new Party();
            var minimumCollateral = offererPayoffs.CalculateMinimumCollateral();

            if (collateral is Money m && m < minimumCollateral)
            {
                throw new ArgumentException($"The collateral is too small, it should be at least {minimumCollateral.ToString(false, false)}");
            }
            s.Offerer.Collateral = collateral ?? minimumCollateral;
            tx.Commit();
            return(s.Offerer.Collateral);
        }
示例#2
0
        public void CanConvertContractInfoToPayoff()
        {
            var payoffs = new DiscretePayoffs();

            payoffs.Add(new DiscreteOutcome("a"), Money.Coins(5.0m));
            payoffs.Add(new DiscreteOutcome("b"), Money.Coins(-5.0m));
            payoffs.Add(new DiscreteOutcome("c"), Money.Coins(-2.0m));
            Assert.Equal(Money.Coins(5.0m), payoffs.CalculateMinimumCollateral());
            var ci = payoffs.ToContractInfo(payoffs.CalculateMinimumCollateral());

            Assert.Equal(Money.Coins(10.0m), ci[0].Payout);
            Assert.Equal(Money.Coins(0m), ci[1].Payout);
            Assert.Equal(Money.Coins(3.0m), ci[2].Payout);

            payoffs = DiscretePayoffs.CreateFromContractInfo(ci, Money.Coins(5.0m));
            Assert.Equal(Money.Coins(5.0m), payoffs[0].Reward);
            Assert.Equal(Money.Coins(-5.0m), payoffs[1].Reward);
            Assert.Equal(Money.Coins(-2.0m), payoffs[2].Reward);
        }