Esempio n. 1
0
		/// <summary>
		/// Check if valid transaction signature
		/// </summary>
		/// <param name="sig">The signature</param>
		/// <param name="scriptVerify">Verification rules</param>
		/// <param name="error">Error</param>
		/// <returns>True if valid</returns>
		public static bool IsValid(byte[] sig, ScriptVerify scriptVerify, out ScriptError error)
		{
			if(sig == null)
				throw new ArgumentNullException("sig");
			if(sig.Length == 0)
			{
				error = ScriptError.SigDer;
				return false;
			}
			error = ScriptError.OK;
			var ctx = new ScriptEvaluationContext()
			{
				ScriptVerify = scriptVerify
			};
			if(!ctx.CheckSignatureEncoding(sig))
			{
				error = ctx.Error;
				return false;
			}
			return true;
		}
 private bool VerifyScript(IndexedTxIn input, Script scriptPubKey, Money value, ScriptVerify scriptVerify, out ScriptError error)
 {
     if (!this.UseConsensusLib)
     {
         return(input.VerifyScript(this.network, scriptPubKey, value, scriptVerify, out error));
     }
     else
     {
         bool ok = Script.VerifyScriptConsensus(scriptPubKey, input.Transaction, input.Index, scriptVerify);
         if (!ok)
         {
             if (input.VerifyScript(this.network, scriptPubKey, scriptVerify, out error))
             {
                 error = ScriptError.UnknownError;
             }
             return(false);
         }
         else
         {
             error = ScriptError.OK;
         }
         return(true);
     }
 }
Esempio n. 3
0
		public static bool VerifyScript(Script scriptPubKey, Transaction tx, int i, ScriptVerify scriptVerify, SigHash sigHash, out ScriptError error)
		{
			var scriptSig = tx.Inputs[i].ScriptSig;
			return VerifyScript(scriptSig, scriptPubKey, tx, i, scriptVerify, sigHash, out error);
		}
		private bool VerifyScript(IndexedTxIn input, Script scriptPubKey, ScriptVerify scriptVerify, out ScriptError error)
		{
			if(!UseConsensusLib)
				return input.VerifyScript(scriptPubKey, scriptVerify, out error);
			else
			{
				var ok = Script.VerifyScriptConsensus(scriptPubKey, input.Transaction, input.Index, scriptVerify);
				if(!ok)
				{
					if(input.VerifyScript(scriptPubKey, scriptVerify, out error))
						error = ScriptError.UnknownError;
					return false;
				}
				else
				{
					error = ScriptError.OK;
				}
				return true;
			}
		}
Esempio n. 5
0
		public static bool VerifyScript(Script scriptSig, Script scriptPubKey, Transaction tx, int i, Money value, out ScriptError error)
		{
			return VerifyScript(scriptSig, scriptPubKey, tx, i, value, ScriptVerify.Standard, SigHash.Undefined, out error);
		}
Esempio n. 6
0
        public static bool VerifyScript(Script scriptSig, Script scriptPubKey, Transaction tx, int i, Money value, ScriptVerify scriptVerify, SigHash sigHash, out ScriptError error)
        {
            var eval = new ScriptEvaluationContext
            {
                SigHash      = sigHash,
                ScriptVerify = scriptVerify
            };
            var result = eval.VerifyScript(scriptSig, scriptPubKey, tx, i, value);

            error = eval.Error;
            return(result);
        }
        public static bool VerifyScript(Transaction tx, int i, TxOut spentOutput, out ScriptError error)
        {
            var scriptSig = tx.Inputs[i].ScriptSig;

            return(VerifyScript(scriptSig, tx, i, spentOutput, ScriptVerify.Standard, SigHash.Undefined, out error));
        }
Esempio n. 8
0
 public bool VerifyScript(ICoin coin, ScriptVerify scriptVerify, out ScriptError error)
 {
     return(Script.VerifyScript(coin.TxOut.ScriptPubKey, Transaction, (int)Index, coin.TxOut.Value, scriptVerify, SigHash.Undefined, out error));
 }
Esempio n. 9
0
 public ScriptErrorNavigator(ScriptError error, IServiceProvider sp)
 {
     this.error = error;
     this.sp    = sp;
 }
Esempio n. 10
0
 public bool VerifyScript(Script scriptPubKey, out ScriptError error)
 {
     return(Script.VerifyScript(scriptPubKey, Transaction, (int)Index, null, out error));
 }
Esempio n. 11
0
 public bool VerifyScript(Script scriptPubKey, Money value, ScriptVerify scriptVerify, out ScriptError error)
 {
     return(Script.VerifyScript(scriptPubKey, Transaction, (int)Index, value, scriptVerify, SigHash.Undefined, out error));
 }
Esempio n. 12
0
 public virtual void ShowErrors(params Exception[] exceptions)
 {
     ShowErrors(exceptions.Select(ex => ScriptError.From(ex)).ToArray());
 }
Esempio n. 13
0
		private bool VerifyScript(IndexedTxIn input, Script scriptPubKey, Money value, ScriptVerify scriptVerify, out ScriptError error)
		{
#if !NOCONSENSUSLIB
			if(!UseConsensusLib)
#endif
				return input.VerifyScript(scriptPubKey, value, scriptVerify, out error);
#if !NOCONSENSUSLIB
			else
			{
				var ok = Script.VerifyScriptConsensus(scriptPubKey, input.Transaction, input.Index, scriptVerify);
				if(!ok)
				{
					if(input.VerifyScript(scriptPubKey, scriptVerify, out error))
						error = ScriptError.UnknownError;
					return false;
				}
				else
				{
					error = ScriptError.OK;
				}
				return true;
			}
#endif
		}
Esempio n. 14
0
 internal InputValidationResult(int index, ScriptError error, ExecutionData executionData)
 {
     InputIndex    = index;
     Error         = error;
     ExecutionData = executionData;
 }
        private bool VerifyScript(IndexedTxIn input, Script scriptPubKey, Money value, ScriptVerify scriptVerify, out ScriptError error)
        {
#if !NOCONSENSUSLIB
            if (!UseConsensusLib)
#endif
            {
                if (input.Transaction is IHasForkId)
                {
                    scriptVerify |= NBitcoin.ScriptVerify.ForkId;
                }
                return(input.VerifyScript(scriptPubKey, value, scriptVerify, out error));
            }
#if !NOCONSENSUSLIB
            else
            {
                if (input.Transaction is IHasForkId)
                {
                    scriptVerify |= (NBitcoin.ScriptVerify)(1U << 16);
                }
                var ok = Script.VerifyScriptConsensus(scriptPubKey, input.Transaction, input.Index, scriptVerify);
                if (!ok)
                {
                    if (input.VerifyScript(scriptPubKey, scriptVerify, out error))
                    {
                        error = ScriptError.UnknownError;
                    }
                    return(false);
                }
                else
                {
                    error = ScriptError.OK;
                }
                return(true);
            }
#endif
        }
Esempio n. 16
0
 public static bool VerifyScript(Script scriptSig, Script scriptPubKey, Transaction tx, int i, out ScriptError error)
 {
     return(VerifyScript(scriptSig, scriptPubKey, tx, i, ScriptVerify.Standard, SigHash.Undefined, out error));
 }
Esempio n. 17
0
        /// <summary>
        /// Check if valid transaction signature
        /// </summary>
        /// <param name="network">The blockchain network class.</param>
        /// <param name="sig">The signature</param>
        /// <param name="scriptVerify">Verification rules</param>
        /// <param name="error">Error</param>
        /// <returns>True if valid</returns>
        public static bool IsValid(Network network, byte[] sig, ScriptVerify scriptVerify, out ScriptError error)
        {
            if (sig == null)
            {
                throw new ArgumentNullException("sig");
            }
            if (sig.Length == 0)
            {
                error = ScriptError.SigDer;
                return(false);
            }
            error = ScriptError.OK;
            var ctx = new ScriptEvaluationContext(network)
            {
                ScriptVerify = scriptVerify
            };

            if (!ctx.CheckSignatureEncoding(sig))
            {
                error = ctx.Error;
                return(false);
            }
            return(true);
        }
        private bool VerifyScript(IndexedTxIn input, Script scriptPubKey, Money value, ScriptVerify scriptVerify, out ScriptError error)
        {
#if !NOCONSENSUSLIB
            if (!UseConsensusLib)
#endif
            return(input.VerifyScript(this.network, scriptPubKey, value, scriptVerify, out error));

#if !NOCONSENSUSLIB
            else
            {
                var ok = Script.VerifyScriptConsensus(scriptPubKey, input.Transaction, input.Index, scriptVerify);
                if (!ok)
                {
                    if (input.VerifyScript(this.network, scriptPubKey, scriptVerify, out error))
                    {
                        error = ScriptError.UnknownError;
                    }
                    return(false);
                }
                else
                {
                    error = ScriptError.OK;
                }
                return(true);
            }
#endif
        }
        public static bool VerifyScript(Script scriptPubKey, Transaction tx, int i, Money value, out ScriptError error)
        {
            var scriptSig = tx.Inputs[i].ScriptSig;

            return(VerifyScript(scriptSig, scriptPubKey, tx, i, value, ScriptVerify.Standard, SigHash.Undefined, out error));
        }
        public string GetErrorString(ScriptError error)
        {
            switch (error)
            {
            case ScriptError.NoError:
                return("No error found");

            case ScriptError.Error:
                return("Unknown Error");

            case ScriptError.FileDoesNotExist:
                return("File does not exist");

            case ScriptError.CannotOpenFile:
                return("Cannot open the file");

            case ScriptError.FileEmpty:
                return("Empty file");

            case ScriptError.SecBegOfLineErr:
                return("Begning of section invalid");

            case ScriptError.UnknownSecErr:
                return("Unknown section");

            case ScriptError.SyntaxErr:
                return("Syntax error");

            case ScriptError.SecRepeatErr:
                return("Section repeated");

            case ScriptError.UnknownSerialPortSetting:
                return("Unknown serial port setting");

            case ScriptError.BaudRateResolutionErr:
                return("Cannot resolve baud rate");

            case ScriptError.ParityResolutionErr:
                return("Cannot resolve parity");

            case ScriptError.DataBitsResolutionErr:
                return("Cannot resolve data bits");

            case ScriptError.StopBitsResolutionErr:
                return("Cannot resolve stop bits");

            case ScriptError.HandShakeResolutionErr:
                return("Cannot resolve handshaking protocol");

            case ScriptError.UnknownCmdErr:
                return("Unknown command");

            case ScriptError.CannotOpenSP:
                return("Cannot open serial port");

            case ScriptError.CannotCloseSP:
                return("Cannot close serial port");

            case ScriptError.SPNotOpen:
                return("Serial port not open");

            case ScriptError.CannotTalkToSP:
                return("Cannot talk toSerial port");

            case ScriptError.NotEnoughParamsRet:
                return("Not enough prameters returned");

            case ScriptError.UnexpectedOutputFormat:
                return("Unexpected output format");

            case ScriptError.DtrEnableErr:
                return("Cannot resolve DTR state");

            default:
                return("Unknown error");
            }
        }
        public static bool VerifyScript(Script scriptPubKey, Transaction tx, int i, Money value, ScriptVerify scriptVerify, SigHash sigHash, out ScriptError error)
        {
            var scriptSig = tx.Inputs[i].ScriptSig;

            return(VerifyScript(scriptSig, scriptPubKey, tx, i, value, scriptVerify, sigHash, out error));
        }
        public ScriptError RunCommands(ScriptCommand ScriptCMD)
        {
            if (scriptParsed == false)
            {
                ScriptError RetVal = this.ParseScriptFile();
                if (RetVal != ScriptError.NoError)
                {
                    return(RetVal);
                }
            }

            if (ScriptCMD == ScriptCommand.OpenSerialPortCMD)
            {
                if (this.FreqCntrPort == null)
                {
                    this.FreqCntrPort = new SerialPort();
                }

                if (this.FreqCntrPort.IsOpen == false)
                {
                    this.FreqCntrPort.PortName  = serialPortName;
                    this.FreqCntrPort.BaudRate  = spBaudRate;
                    this.FreqCntrPort.Parity    = spParity;
                    this.FreqCntrPort.DataBits  = spDataBits;
                    this.FreqCntrPort.StopBits  = spStopBits;
                    this.FreqCntrPort.Handshake = spHandshake;
                    this.FreqCntrPort.DtrEnable = spDtrEnable;
                    this.FreqCntrPort.Encoding  = Encoding.ASCII;
                    try
                    {
                        this.FreqCntrPort.Open();
                    }
                    catch
                    {
                        return(ScriptError.CannotOpenSP);
                    }
                }
            }
            else if (ScriptCMD == ScriptCommand.InitCMD)
            {
                foreach (string currentCMD in secInitCommands)
                {
                    ScriptError RetVal = this.ParseCommand(currentCMD);
                    if (RetVal != ScriptError.NoError)
                    {
                        return(RetVal);
                    }
                }
            }
            else if (ScriptCMD == ScriptCommand.MeasureCMD)
            {
                foreach (string currentCMD in secMeasureCommands)
                {
                    ScriptError RetVal = this.ParseCommand(currentCMD);
                    if (RetVal != ScriptError.NoError)
                    {
                        return(RetVal);
                    }
                }
            }
            else if (ScriptCMD == ScriptCommand.StopCMD)
            {
                foreach (string currentCMD in secStopCommands)
                {
                    ScriptError RetVal = this.ParseCommand(currentCMD);
                    if (RetVal != ScriptError.NoError)
                    {
                        return(RetVal);
                    }
                }
            }
            else if (ScriptCMD == ScriptCommand.CloseSerialPortCMD)
            {
                if (this.FreqCntrPort != null)
                {
                    try
                    {
                        if (this.FreqCntrPort.IsOpen)
                        {
                            this.FreqCntrPort.Close();
                        }
                    }
                    catch
                    {
                        return(ScriptError.CannotCloseSP);
                    }
                }
                else
                {
                    return(ScriptError.SPNotOpen);
                }
            }
            return(ScriptError.NoError);
        }
Esempio n. 23
0
		public ScriptPolicyError(IndexedTxIn input, ScriptError error, ScriptVerify scriptVerify, Script scriptPubKey)
			: base("Script error on input " + input.Index + " (" + error + ")", input)
		{
			_ScriptError = error;
			_ScriptVerify = scriptVerify;
			_ScriptPubKey = scriptPubKey;
		}
Esempio n. 24
0
        public static bool VerifyScript(Script scriptSig, Transaction tx, int i, TxOut spentOutput, ScriptVerify scriptVerify, SigHash sigHash, out ScriptError error)
        {
            if (spentOutput == null)
            {
                throw new ArgumentNullException(nameof(spentOutput));
            }
            var eval = new ScriptEvaluationContext
            {
                SigHash      = sigHash,
                ScriptVerify = scriptVerify
            };
            var result = eval.VerifyScript(scriptSig, tx, i, spentOutput);

            error = eval.Error;
            return(result);
        }
Esempio n. 25
0
		public static bool VerifyScript(Script scriptPubKey, Transaction tx, int i, out ScriptError error)
		{
			var scriptSig = tx.Inputs[i].ScriptSig;
			return VerifyScript(scriptSig, scriptPubKey, tx, i, ScriptVerify.Standard, SigHash.Undefined, out error);
		}
Esempio n. 26
0
        public static bool VerifyScript(Transaction tx, int i, TxOut spentOutput, ScriptVerify scriptVerify, SigHash sigHash, out ScriptError error)
        {
            var scriptSig = tx.Inputs[i].ScriptSig;

            return(VerifyScript(scriptSig, tx, i, spentOutput, scriptVerify, sigHash, out error));
        }
Esempio n. 27
0
		public static bool VerifyScript(Script scriptSig, Script scriptPubKey, Transaction tx, int i, ScriptVerify scriptVerify, SigHash sigHash, out ScriptError error)
		{
			var eval = new ScriptEvaluationContext
			{
				SigHash = sigHash,
				ScriptVerify = scriptVerify
			};
			var result = eval.VerifyScript(scriptSig, scriptPubKey, tx, i);
			error = eval.Error;
			return result;
		}
Esempio n. 28
0
        public override void ErrorReported(ScriptSource source, string message, SourceSpan span, int errorCode, Severity severity)
        {
            ScriptError arg = new ScriptError(message, severity.ToString(), span.Start.Line, span.Start.Column);

            Errors.Add(arg);
        }