/// <summary> /// Initializes a new instance of <see cref="TransactionVerifier"/> using given parameters. /// </summary> /// <exception cref="ArgumentNullException"/> /// <param name="isMempool">Indicates whether this instance is used by the memory pool or block</param> /// <param name="utxoDatabase">UTXO database</param> /// <param name="memoryPool">Memory pool</param> /// <param name="consensus">Consensus rules</param> public TransactionVerifier(bool isMempool, IUtxoDatabase utxoDatabase, IMemoryPool memoryPool, IConsensus consensus) { if (utxoDatabase is null) { throw new ArgumentNullException(nameof(utxoDatabase), "UTXO database can not be null."); } if (memoryPool is null) { throw new ArgumentNullException(nameof(memoryPool), "Memory pool can not be null."); } if (consensus is null) { throw new ArgumentNullException(nameof(consensus), "Consensus rules can not be null."); } this.isMempool = isMempool; utxoDb = utxoDatabase; mempool = memoryPool; this.consensus = consensus; calc = new EllipticCurveCalculator(); scrSer = new ScriptSerializer(); hash160 = new Ripemd160Sha256(); sha256 = new Sha256(); }
public void ConvertWitnessTest(IOperation[] ops, byte[] expected) { ScriptSerializer ser = new ScriptSerializer(); byte[] actual = ser.ConvertWitness(ops); Assert.Equal(expected, actual); }
public static string ComputeHash(Script script) { var serializer = new ScriptSerializer(script); var hash = Blake2bHasher.ComputeHash(serializer.Serialize()); return(Util.Hex.BytesToHexString(hash)); }
public void Convert_MultiSigTest(IOperation[] ops, byte[][] sigs, byte[] expected) { ScriptSerializer ser = new ScriptSerializer(); byte[] actual = ser.ConvertMulti(ops, sigs); Assert.Equal(expected, actual); }
public void Convert_SingleSigTest(IOperation[] ops, byte[] sig, byte[] expected) { ScriptSerializer ser = new ScriptSerializer(); byte[] actual = ser.Convert(ops, sig); Assert.Equal(expected, actual); }
/// <summary> /// Applies the given script file to the source image. /// </summary> /// <param name="fileName">Name of the file.</param> private void _ApplyScriptFile(string fileName) { var localEngine = new ScriptEngine(); localEngine.AddWithoutExecution(new NullTransformCommand()); ScriptSerializer.LoadFromFile(localEngine, fileName); this._ExecuteScriptActions(localEngine.Actions.ToArray()); }
public void ConvertP2wpkhTest() { IOperation[] ops = new IOperation[2] { new PushDataOp(OP._0), new PushDataOp(Helper.GetBytes(20)) }; ScriptSerializer ser = new ScriptSerializer(); byte[] actual = ser.ConvertP2wpkh(ops); byte[] expected = Helper.HexToBytes($"76a914{Helper.GetBytesHex(20)}88ac"); Assert.Equal(expected, actual); }
public void TestSerialize() { var script = new Script { CodeHash = "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88", HashType = "type", Args = "0x3954acece65096bfa81258983ddb83915fc56bd8", }; var expected = "4900000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e8801140000003954acece65096bfa81258983ddb83915fc56bd8"; var serializer = new ScriptSerializer(script); Assert.Equal(ScriptSerializer.HexStringToBytes(expected), serializer.Serialize()); }
private void loadToolStripMenuItem_Click(object sender, EventArgs e) { var dialog = this.ofdOpenScript; if (dialog.ShowDialog() != DialogResult.OK) { return; } var filename = dialog.FileName; this._scriptEngine.Clear(); ScriptSerializer.LoadFromFile(this._scriptEngine, filename); }
private void saveToolStripMenuItem1_Click(object sender, EventArgs e) { var engine = this._scriptEngine; if (!engine.Actions.Any()) { MessageBox.Show(Resources.txNoScriptToSave, Resources.ttNoScriptToSave, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var dialog = this.sfdSaveScript; if (dialog.ShowDialog() != DialogResult.OK) { return; } var filename = dialog.FileName; ScriptSerializer.SaveToFile(engine, filename); }
private void showToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show(ScriptSerializer.SerializeState(this._scriptEngine), "Script", MessageBoxButtons.OK, MessageBoxIcon.None); }