public VerificationContract GetContract() { UInt160 publicKeyHash = ((ECPoint)comboBox1.SelectedItem).EncodePoint(true).ToScriptHash(); ContractParameterType[] parameterList = textBox1.Text.HexToBytes().Select(p => (ContractParameterType)p).ToArray(); byte[] redeemScript = textBox2.Text.HexToBytes(); return(VerificationContract.Create(publicKeyHash, parameterList, redeemScript)); }
public VerificationContract GetContract() { ECPoint publicKey = (ECPoint)comboBox1.SelectedItem; uint timestamp = dateTimePicker1.Value.ToTimestamp(); using (ScriptBuilder sb = new ScriptBuilder()) { sb.EmitPush(publicKey); sb.EmitPush(timestamp); // Lock 2.0 in mainnet tx:4e84015258880ced0387f34842b1d96f605b9cc78b308e1f0d876933c2c9134b sb.EmitAppCall(UInt160.Parse("d3cce84d0800172d09c88ccad61130611bd047a4")); return(VerificationContract.Create(publicKey.EncodePoint(true).ToScriptHash(), new[] { ContractParameterType.Signature }, sb.ToArray())); } }
// This example was inspired by the following pages from the NEO Tutorial: // http://docs.neo.org/en-us/sc/tutorial/verify.html // http://docs.neo.org/en-us/sc/test.html // ...and @relfos' neo-debugger project: https://github.com/Relfos/neo-debugger-tools // **NOTE:** The `contract` created below is simply an in-memory contract. // It is not deployed and the contract is not used in the subsequent code that runs the script in the VM // Reference: https://github.com/mwherman2000/neo-windocs/blob/master/windocs/quickstart-csharp/09-deploytestsmartcontract.md#import-the-existing-developer-account-from-the-neo-privatenet-docker-container // Reference: https://hub.docker.com/r/metachris/neo-privnet-with-gas/#Wallet // ...as displayed by [account] > View Private Key in neo-gui-developer //public const string WIF2 = "KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr"; // 52 chars //public const string WIF2Address = "AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y"; // 34 chars //public const string WIF2PublicKey = "031a6c6fbbdf02ca351745fa86b9ba5a9452d785ac4f7fc2b7548ca2a46c4fcf4a"; // 66 chars //public const string WIF2PrivateKeyHex = "1dd37fba80fec4e6a6f13fd708d8dcb3b29def768017052f6c930fa1c5d90bbb"; // 64 chars //public static readonly byte[] WIF2AddressScriptHash = Neo.SmartContract.Framework.Helper.ToScriptHash(WIF2Address); static void Main(string[] args) { var engine = new ExecutionEngine(null, Crypto.Default); engine.LoadScript(File.ReadAllBytes(@"..\..\..\ReturnOperation1\bin\debug\ReturnOperation1.avm")); // // ReturnOperation1.avm // //public class ReturnOperation1 : SmartContract //{ // public static string Main(string operation, object[] args) // { // string message = operation + " world"; // Runtime.Log(message); // Runtime.Notify(operation, message); // return message; // } //} // Dump out the loaded script... byte[] scriptReturnOperation1 = engine.CurrentContext.Script; Console.WriteLine("CurrentContext.Script:\t" + scriptReturnOperation1.Length); Console.WriteLine("CurrentContext.Script:\t" + BytesToHexString(scriptReturnOperation1).Length); Console.WriteLine("CurrentContext.Script:\t" + BytesToHexString(scriptReturnOperation1)); Console.WriteLine("CurrentContext.Script:\t" + scriptReturnOperation1.ToHexString().Length); Console.WriteLine("CurrentContext.Script:\t" + scriptReturnOperation1.ToHexString()); //Console.WriteLine("CurrentContext.Script:\t" + script.ToHexString().HexToBytes().Length); // Dump out the script's hash var scriptHash = engine.CurrentContext.ScriptHash; Console.WriteLine("CurrentContext.scriptHash:\t" + BytesToHexString(scriptHash).Length); Console.WriteLine("CurrentContext.scriptHash:\t" + BytesToHexString(scriptHash) + " wrong"); var scriptHash2 = scriptReturnOperation1.ToScriptHash(); Console.WriteLine("scriptReturnOperation1.ToScriptHash():\t" + scriptHash2.ToString().Length); Console.WriteLine("scriptReturnOperation1.ToScriptHash():\t" + scriptHash2.ToString() + " good"); // Create an Contract Account and dump out it's properties (e.g. Contract Account address) // NOTE: You need to have th NEO privatenet configured and running. `contract.Address` needs config.json file. Checkout the following for details: // https://github.com/mwherman2000/neo-windocs/blob/master/windocs/quickstart-csharp/07-installneoprivatenetcontainer.md //UInt160 accountPublicKeyHash = ((ECPoint)(object)WIF2PublicKey).EncodePoint(true).ToScriptHash(); ContractParameterType[] scriptParameterListDeclaration = { ContractParameterType.String, ContractParameterType.Array }; Contract contract = VerificationContract.Create(scriptParameterListDeclaration, scriptReturnOperation1); string contractAddress = contract.Address; string contractScript = contract.Script.ToHexString(); string contractScriptHash = contract.ScriptHash.ToString(); Console.WriteLine("contractAddress:\t" + contractAddress.Length.ToString() + " " + contractAddress); Console.WriteLine("contractScriptHash:\t" + contractScriptHash.Length.ToString() + " " + contractScriptHash); Console.WriteLine("contractScript:\t" + contractScript.Length.ToString() + " " + contractScript); //neo-gui hash: 0x431bfd28ecb875e807b8e8be365120adf63fb987 //scriptHash: 87B93FF6AD205136BEE8B807E875B8EC28FD1B43 ReturnOperation1.avm //scriptHash2: 0x431bfd28ecb875e807b8e8be365120adf63fb987 //neo-gui Address: AU9WnnGD8AY3NqAqyZ98cF59X4SCk81aF9 //contract.Address: AU9WnnGD8AY3NqAqyZ98cF59X4SCk81aF9 string operationParameter = "hello"; Console.WriteLine("operationParameter:\t" + operationParameter.ToString() + "\t" + operationParameter.ToString()); ContractParameter integer1 = new ContractParameter(ContractParameterType.Integer); integer1.Value = 3; ContractParameter integer2 = new ContractParameter(ContractParameterType.Integer); integer2.Value = 4; ContractParameter[] arrayOfIntegers = { integer1, integer2 }; ContractParameter arrayOfObjectParameter = new ContractParameter(ContractParameterType.Array); arrayOfObjectParameter.Value = arrayOfIntegers; ; using (ScriptBuilder sb = new ScriptBuilder()) { sb.EmitPush(arrayOfObjectParameter); sb.EmitPush(operationParameter); engine.LoadScript(sb.ToArray()); } bool singleStep = false; // Debugging the debugger if (singleStep) { engine.AddBreakPoint(0); engine.StepInto(); engine.StepInto(); engine.StepInto(); engine.StepInto(); engine.StepInto(); } else { engine.Execute(); // start execution } Console.WriteLine("engine.State:\t{0}", engine.State.ToString()); DumpInvocationStack(engine); DumpEngineExecutionContext(engine); DumpAltStack(engine); DumpEvaluationStack(engine); var result = engine.EvaluationStack.Peek().GetBigInteger(); // set the return value here Console.WriteLine($"Execution result {result}"); var result2 = engine.EvaluationStack.Peek(); // set the return value here Console.WriteLine($"Execution result {result2}"); var result3 = engine.EvaluationStack.Peek().GetString(); // set the return value here Console.WriteLine($"Execution result {result3}"); Console.ReadLine(); }