Ejemplo n.º 1
0
 /// <inheritdoc/>
 /// <exception cref="ArgumentException"/>
 /// <exception cref="ArgumentNullException"/>
 /// <exception cref="ArgumentOutOfRangeException"/>
 public void SetToMultiSig(Signature sig, IRedeemScript redeem, ITransaction tx, int inputIndex)
 {
     if (sig is null)
     {
         throw new ArgumentNullException(nameof(sig), "Signature can not be null.");
     }
     if (redeem is null)
     {
         throw new ArgumentNullException(nameof(redeem), "Redeem script can not be null.");
     }
     if (tx is null)
     {
         throw new ArgumentNullException(nameof(tx), "Transaction can not be null.");
     }
     if (inputIndex < 0 || inputIndex >= tx.TxInList.Length)
     {
         throw new ArgumentOutOfRangeException(nameof(inputIndex), "Invalid input index.");
     }
     if (redeem.Data.Length > Constants.MaxScriptItemLength)
     {
         throw new ArgumentOutOfRangeException(nameof(redeem), "Redeem script is bigger than allowed length.");
     }
     if (redeem.GetRedeemScriptType() != RedeemScriptType.MultiSig)
     {
         throw new ArgumentException("Invalid redeem script type.");
     }
     if (!redeem.TryEvaluate(out IOperation[] rdmOps, out _, out string error))
     {
         throw new ArgumentException($"Can not evaluate redeem script: {error}");
     }
     // OP_m | pub1 | pub2 | ... | pub(n) | OP_n | OP_CheckMultiSig
     if (!((PushDataOp)rdmOps[0]).TryGetNumber(out long m, out error))
     {
         throw new ArgumentException($"Invalid m ({error}).");
     }
     if (m < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(m), "M can not be negative.");
     }
     if (m == 0)
     {
         throw new ArgumentOutOfRangeException(nameof(m), "M value zero is not allowed to prevent funds being stolen.");
     }
     if (!((PushDataOp)rdmOps[^ 2]).TryGetNumber(out long n, out error))
Ejemplo n.º 2
0
        public void GetRedeemScriptTypeTest(IRedeemScript scr, RedeemScriptType expected)
        {
            RedeemScriptType actual = scr.GetRedeemScriptType();

            Assert.Equal(expected, actual);
        }