/// <summary> /// Pushes the number of stack items onto the stack. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { opData.Push(OpHelper.IntToByteArray(opData.ItemCount)); error = null; return(true); }
/// <summary> /// Removes top three stack items and converts them to <see cref="long"/>s: value, Min, Max. /// Pushes 1 if value was in range, otherwise 0. /// Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 3) { error = "Invalid number of elements in stack."; return(false); } // Stack is: x then min then max so we pop max first if (!OpHelper.TryConvertByteArrayToInt(opData.Pop(), out long max, true)) { error = "Couldn't convert to number."; return(false); } if (!OpHelper.TryConvertByteArrayToInt(opData.Pop(), out long min, true)) { error = "Couldn't convert to number."; return(false); } if (!OpHelper.TryConvertByteArrayToInt(opData.Pop(), out long x, true)) { error = "Couldn't convert to number."; return(false); } int c = (x >= min && x < max) ? 1 : 0; opData.Push(OpHelper.IntToByteArray(c)); error = null; return(true); }
protected bool TrySetLockTime(IOpData opData, out string error) { if (opData.ItemCount < 1) { error = "Not enough items left in the stack."; return(false); } // The two locktime OPs (CheckLocktimeVerify and CheckSequenceVerify) used to be NOPs. NOPs don't do anything. // For backward compatibility of the softfork, Run Peeks at the top item of the stack instead of Poping it. byte[] data = opData.Peek(); // TODO: move this check to OpHelper // (for locktimes max length is 5 for others it is 4) if (data.Length > 5) { error = "Data length for locktimes can not be bigger than 5."; return(false); } if (!OpHelper.TryConvertByteArrayToInt(data, out lt, true)) { error = "Invalid number format."; return(false); } if (lt < 0) { error = "Locktime can not be negative."; return(false); } error = null; return(true); }
/// <summary> /// Removes top two stack item checks their equality, fails if not equal. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 2) { error = "There was not enough items left in the stack to check."; return(false); } byte[] item1 = opData.Pop(); byte[] item2 = opData.Pop(); if (item1.IsEqualTo(item2)) { error = null; return(true); } else { error = "Items were not equal."; return(false); } // ^^ this way we skip unnecessary OP instantiation and Push() and Pop() operations on IOpData //EqualOp eq = new EqualOp(); //VerifyOp ver = new VerifyOp(); //if (!eq.Run(opData, out error)) //{ // return false; //} //return ver.Run(opData, out error); }
public override bool Run(IOpData opData, out string error) { Assert.Equal(expBool, TrySetValues(opData, out error)); Assert.Equal(expNum1, a); Assert.Equal(expNum2, b); return(expBool); }
/// <summary> /// Removes top three stack items and converts them to <see cref="long"/>s: value, Min, Max. /// Pushes 1 if value was in range, otherwise 0. /// Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 3) { error = Err.OpNotEnoughItems; return(false); } // Stack is: x then min then max => pop max first byte[][] numbers = opData.Pop(3); if (!TryConvertToLong(numbers[2], out long max, opData.StrictNumberEncoding)) { error = "Invalid number format (max)."; return(false); } if (!TryConvertToLong(numbers[1], out long min, opData.StrictNumberEncoding)) { error = "Invalid number format (min)."; return(false); } if (!TryConvertToLong(numbers[0], out long x, opData.StrictNumberEncoding)) { error = "Invalid number format (x)."; return(false); } opData.Push(x >= min && x < max); error = null; return(true); }
/// <summary> /// Converts the top stack item to locktime without removing it. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> protected bool TrySetLockTime(IOpData opData, out string error) { if (opData.ItemCount < 1) { error = Err.OpNotEnoughItems; return(false); } // The two locktime OPs (CheckLocktimeVerify and CheckSequenceVerify) used to be NOPs. NOPs don't do anything. // For backward compatibility of the softfork, Run() Peeks at the top item of the stack instead of Poping it. byte[] data = opData.Peek(); if (!TryConvertToLong(data, out lt, opData.StrictNumberEncoding, 5)) { error = "Invalid number format."; return(false); } if (lt < 0) { error = "Locktime can not be negative."; return(false); } error = null; return(true); }
/// <summary> /// Pushes the specified data of this instance at the top of the stack. /// </summary> /// <param name="opData">Stack to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (OpValue == OP._0) { opData.Push(new byte[0]); } else if (OpValue == OP.Negative1) { opData.Push(new byte[1] { 0b1000_0001 });
/// <summary> /// Duplicates the top stack item. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 1) { error = Err.OpNotEnoughItems; return(false); } opData.Push(opData.Peek()); return(CheckItemCount(opData, out error)); }
/// <summary> /// Replaces top two stack items interpreted as <see cref="long"/>s with their subtract result. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (!TrySetValues(opData, out error)) { return(false); } opData.Push(OpHelper.IntToByteArray(a - b)); error = null; return(true); }
public override bool Run(IOpData opData, out string error) { IOperation cms = new CheckMultiSigOp(); IOperation ver = new VerifyOp(); if (!cms.Run(opData, out error)) { return(false); } return(ver.Run(opData, out error)); }
/// <summary> /// Replaces top two stack items interpreted as <see cref="long"/>s with 1 if first one was bigger or equal, otherwise with 0. /// Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (!TrySetValues(opData, out error)) { return(false); } opData.Push(a >= b); error = null; return(true); }
/// <summary> /// Duplicates the top stack item. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 1) { error = "There was no item left in the stack to duplicate."; return(false); } opData.Push(opData.Peek()); error = null; return(true); }
public override bool Run(IOpData opData, out string error) { if (succeed) { error = null; return(true); } else { error = errMsg; return(false); } }
/// <summary> /// The item at the top of the stack is copied and inserted before the second-to-top item. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 2) { error = Err.OpNotEnoughItems; return(false); } byte[] data = opData.Peek(); opData.Insert(data, 2); return(CheckItemCount(opData, out error)); }
/// <summary> /// Removes top alt-stack item and puts it in stack. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.AltItemCount < 1) { error = Err.OpNotEnoughItems + "(alt stack)"; return(false); } opData.Push(opData.AltPop()); error = null; return(true); }
/// <summary> /// Removes the second item from top of stack. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 2) { error = "There was not enough items left in the stack to drop (\"nip\")."; return(false); } opData.PopAtIndex(1); // discard the popped value error = null; return(true); }
/// <summary> /// Removes the top stack item. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 1) { error = "There was no item left in the stack to drop."; return(false); } opData.Pop(); // Throw away the top stack item error = null; return(true); }
/// <summary> /// Pushes the size of the top stack item to the stack without removing the item. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 1) { error = Err.OpNotEnoughItems; return(false); } byte[] temp = opData.Peek(); opData.Push(IntToByteArray(temp.Length)); return(CheckItemCount(opData, out error)); }
/// <summary> /// Replaces top stack item with its hash digest. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 1) { error = "Not enough items in stack."; return(false); } opData.Push(Hash.ComputeHash(opData.Pop())); error = null; return(true); }
public override bool Run(IOpData opData, out string error) { if (!TrySetLockTime(opData, out error)) { return(false); } // Compare to tx.locktime, as relative locktime (we assume it is valid and skip this!) // TODO: change this for this tool if transactions were set inside IOpdata one day... error = null; return(true); }
/// <summary> /// Removes (discards) top two stack items. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 2) { error = "There was not enough items left in the stack to drop."; return(false); } opData.Pop(2); // Throw away the 2 items error = null; return(true); }
/// <summary> /// Removes top alt-stack item and puts it in stack. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.AltItemCount < 1) { error = "There was not enough items left in the alt-stack to copy to stack."; return(false); } opData.Push(opData.AltPop()); error = null; return(true); }
/// <summary> /// Replaces top two stack items interpreted as <see cref="long"/>s with 1 if either one is not 0, otherwise with 0. /// Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (!TrySetValues(opData, out error)) { return(false); } int c = (a != 0 || b != 0) ? 1 : 0; opData.Push(OpHelper.IntToByteArray(c)); error = null; return(true); }
/// <summary> /// Pushes the size of the top stack item to the stack. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public bool Run(IOpData opData, out string error) { if (opData.ItemCount < 1) { error = "There was not enough items left in the stack."; return(false); } byte[] temp = opData.Peek(); opData.Push(OpHelper.IntToByteArray(temp.Length)); error = null; return(true); }
/// <summary> /// Replaces top stack item with its hash digest. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 1) { error = Err.OpNotEnoughItems; return(false); } using Sha256 hash = new Sha256(); opData.Push(hash.ComputeHash(opData.Pop())); error = null; return(true); }
/// <summary> /// Removes top two stack items (signature and public key) and verifies the transaction signature. /// </summary> /// <param name="opData">Stack to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { bool b = ExtractAndVerify(opData, out error); if (error is null) { opData.Push(b); return(true); } else { return(false); } }
/// <summary> /// The item at the top of the stack is copied and inserted before the second-to-top item. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 2) { error = "There was not enough items left in the stack to tuck."; return(false); } byte[] data = opData.Peek(); opData.Insert(data, 2); error = null; return(true); }
/// <summary> /// Swaps the position of top 2 items on top of the stack. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 2) { error = "There was not enough items left in the stack to swap."; return(false); } byte[][] data = opData.Pop(2); opData.Push(new byte[2][] { data[1], data[0] }); error = null; return(true); }
/// <summary> /// Copies the second item from top of the stack to the top. Return value indicates success. /// </summary> /// <param name="opData">Data to use</param> /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param> /// <returns>True if operation was successful, false if otherwise</returns> public override bool Run(IOpData opData, out string error) { if (opData.ItemCount < 2) { error = "There was not enough items left in the stack to copy over."; return(false); } byte[] data = opData.PeekAtIndex(1); opData.Push(data); error = null; return(true); }