예제 #1
0
        public PromiseClientSession ReceiveTumblerEscrowedCoin(ScriptCoin escrowedCoin)
        {
            AssertState(TumblerClientSessionStates.WaitingTumblerEscrow);
            var escrow         = EscrowScriptPubKeyParameters.GetFromCoin(escrowedCoin);
            var expectedEscrow = new EscrowScriptPubKeyParameters()
            {
                Initiator = escrow?.Initiator,
                Receiver  = InternalState.TumblerEscrowKey.PubKey,
                LockTime  = GetCycle().GetTumblerLockTime()
            };

            if (escrow == null || escrow != expectedEscrow)
            {
                throw new PuzzleException("invalid-escrow");
            }
            if (escrowedCoin.Amount != Parameters.Denomination)
            {
                throw new PuzzleException("invalid-amount");
            }


            InternalState.Status = TumblerClientSessionStates.PromisePhase;
            var session = new PromiseClientSession(Parameters.CreatePromiseParamaters());

            session.SetChannelId(InternalState.ChannelId);
            session.ConfigureEscrowedCoin(escrowedCoin, InternalState.TumblerEscrowKey);
            InternalState.TumblerEscrowKey = null;
            return(session);
        }
        public PromiseClientSession ReceiveTumblerEscrowedCoin(ScriptCoin escrowedCoin)
        {
            AssertState(TumblerClientSessionStates.WaitingTumblerEscrow);
            var escrow = EscrowScriptPubKeyParameters.GetFromCoin(escrowedCoin);

            if (escrow == null)
            {
                throw new PuzzleException("invalid-escrow");
            }
            if (!escrowedCoin.IsP2SH || escrowedCoin.RedeemType != RedeemType.WitnessV0)
            {
                throw new PuzzleException("invalid-escrow");
            }
            var expectedEscrow = GetTumblerEscrowParameters(escrow.Initiator);

            if (escrow != expectedEscrow)
            {
                throw new PuzzleException("invalid-escrow");
            }
            if (escrowedCoin.Amount != Parameters.Denomination)
            {
                throw new PuzzleException("invalid-amount");
            }


            InternalState.Status = TumblerClientSessionStates.PromisePhase;
            var session = new PromiseClientSession(Parameters.CreatePromiseParamaters());

            session.SetChannelId(InternalState.ChannelId);
            session.ConfigureEscrowedCoin(escrowedCoin, InternalState.TumblerEscrowKey);
            InternalState.TumblerEscrowKey = null;
            return(session);
        }