public static async Task <IDictionary <Coin, byte[]> > PreProcessAsync(
            InputsRegistrationRequest request,
            Prison prison,
            IRPCClient rpc,
            WabiSabiConfig config)
        {
            var inputRoundSignaturePairs = request.InputRoundSignaturePairs;
            var inputs = inputRoundSignaturePairs.Select(x => x.Input);

            int inputCount = inputs.Count();

            if (inputCount != inputs.Distinct().Count())
            {
                throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.NonUniqueInputs);
            }
            if (inputs.Any(x => prison.TryGet(x, out var inmate) && (!config.AllowNotedInputRegistration || inmate.Punishment != Punishment.Noted)))
            {
                throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.InputBanned);
            }

            Dictionary <Coin, byte[]> coinRoundSignaturePairs = new();

            foreach (var inputRoundSignaturePair in inputRoundSignaturePairs)
            {
                OutPoint input         = inputRoundSignaturePair.Input;
                var      txOutResponse = await rpc.GetTxOutAsync(input.Hash, (int)input.N, includeMempool : true).ConfigureAwait(false);

                if (txOutResponse is null)
                {
                    throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.InputSpent);
                }
                if (txOutResponse.Confirmations == 0)
                {
                    throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.InputUnconfirmed);
                }
                if (txOutResponse.IsCoinBase && txOutResponse.Confirmations <= 100)
                {
                    throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.InputImmature);
                }
                if (!txOutResponse.TxOut.ScriptPubKey.IsScriptType(ScriptType.P2WPKH))
                {
                    throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.ScriptNotAllowed);
                }

                coinRoundSignaturePairs.Add(new Coin(input, txOutResponse.TxOut), inputRoundSignaturePair.RoundSignature);
            }

            return(coinRoundSignaturePairs);
        }
예제 #2
0
        private static async Task RegisterAndAssertWrongPhaseAsync(InputsRegistrationRequest req, ArenaRequestHandler handler)
        {
            var ex = await Assert.ThrowsAsync <WabiSabiProtocolException>(async() => await handler.RegisterInputAsync(req));

            Assert.Equal(WabiSabiProtocolErrorCode.WrongPhase, ex.ErrorCode);
        }