Exemple #1
0
        static void Main(string[] args)
        {
            var settings = new Settings(args);

            Console.WriteLine("Loading Bluzelle contract bytecode...");

            var contractFile = settings.GetValue("avm.path");

            if (!File.Exists(contractFile))
            {
                Console.WriteLine($"The file '{contractFile}' was not found");
                Environment.Exit(-1);
            }

            var contractBytes = File.ReadAllBytes(contractFile);
            var contractHash  = contractBytes.ToScriptHash();

            var api = new CustomRPCNode(settings.GetValue("rpc.host", "localhost"), int.Parse(settings.GetValue("rpc.port", "30333")),
                                        settings.GetValue("neoscan.host", "localhost"), int.Parse(settings.GetValue("neoscan.port", "4000")));

            var lastBlock = api.GetBlockHeight() - 1;

            if (lastBlock < 0)
            {
                lastBlock = 0;
            }

            lastBlock = uint.Parse(settings.GetValue("block", lastBlock.ToString()));

            //var owner_keys = KeyPair.FromWIF("L3Vo5HcJhDoL7s81i4PSDTPfbUpVPrFHQ3V1GwSESkQtF4LW2vvJ");
            var owner_keys = KeyPair.FromWIF("KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr");

            Console.WriteLine("Fetching balances");
            var balances = api.GetAssetBalancesOf("AK2nJJpJr6o664CWJKi1QRXjqeic2zRp8y");

            if (balances == null || balances.Count == 0)
            {
                Console.WriteLine("Seems the private net is not currently running..");
                Environment.Exit(-1);
            }

            foreach (var entry in balances)
            {
                Console.WriteLine(entry.Key + " => " + entry.Value);
            }

            Console.WriteLine($"Searching for contract at address {contractHash.ToAddress()}...");

            /*var test = api.InvokeScript(contractHash, new object[] { "test", new object[] { null} });
             * var found = false;
             *
             * if (test != null && test.stack.Length > 0)
             * {
             *  try
             *  {
             *      var testResult = System.Text.Encoding.ASCII.GetString((byte[])test.stack[0]);
             *      found = testResult.Equals("OK");
             *  }
             *  catch
             *  {
             *      // skip
             *  }
             * }
             *
             * if (found)
             * {
             *  Console.WriteLine("Contract found in the NEO chain!");
             * }
             * else
             * {
             *  Console.WriteLine("Contract not found in the NEO chain, deploying...");
             *  var tx = api.DeployContract(owner_keys, contractBytes, new byte[] { 0x07, 0x10 }, 0x05, ContractPropertyState.HasStorage, "Bluzelle", "1.0", "Bluzelle", "*****@*****.**", "Bluzelle contract");
             *  api.WaitForTransaction(owner_keys, tx);
             *
             *  Console.WriteLine("Contract is now deployed!");
             * }
             */

            Console.WriteLine("Starting Bluzelle NEO bridge...");

            //            var swarm = new WSSwarm("ws://192.168.138.134:51010");
            var swarm = new WSSwarm("ws://testnet.bluzelle.com:51010");

            // test public address = AHKPx5dZYnwAweQUJQH3UefoswKm6beEz2
            var manager = new BridgeManager(api, swarm, owner_keys, contractHash, lastBlock);

            manager.Run();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var settings = new Settings(args);

            Console.WriteLine("Loading Bluzelle contract bytecode...");

            var contractFile = settings.GetValue("avm.path");

            if (!File.Exists(contractFile))
            {
                Console.WriteLine($"The file '{contractFile}' was not found");
                Environment.Exit(-1);
            }

            var contractBytes = File.ReadAllBytes(contractFile);
            var contractHash  = contractBytes.ToScriptHash();

            var api = new CustomRPCNode(settings.GetValue("rpc.host", "localhost"), int.Parse(settings.GetValue("rpc.port", "30333")),
                                        settings.GetValue("neoscan.host", "localhost"), int.Parse(settings.GetValue("neoscan.port", "4000")));


            Console.WriteLine("******Bluzelle Tool******");

            var uuid = "92b8bac6-3242-452a-9090-1aa48afd71a3";

            //var swarm = new WSSwarm("ws://192.168.138.134:51010");
            //var swarm = new WSSwarm("ws://13.78.131.94:51010");
            var swarm = new WSSwarm("ws://testnet.bluzelle.com:51010");

            //var owner_keys = KeyPair.FromWIF("L3Vo5HcJhDoL7s81i4PSDTPfbUpVPrFHQ3V1GwSESkQtF4LW2vvJ");
            var owner_keys = KeyPair.FromWIF("KxDgvEKzgSBPPfuVfw67oPQBSjidEiqTHURKSDL1R7yGaGYAeYnr");

            do
            {
                Console.WriteLine("0 - Exit");
                Console.WriteLine("1 - Swarm.Create");
                Console.WriteLine("2 - Swarm.Read");
                Console.WriteLine("3 - Swarm.Update");
                Console.WriteLine("4 - Swarm.Delete");
                Console.WriteLine("5 - Contract.Write");
                Console.WriteLine("6 - Contract.Read");
                Console.WriteLine("7 - Contract.Deploy");

                int option;

                if (int.TryParse(Console.ReadLine(), out option))
                {
                    switch (option)
                    {
                    case 0:
                    {
                        Environment.Exit(0);
                        break;
                    }

                    case 1:
                    {
                        Console.WriteLine("**CREATE**");

                        Console.Write("KEY: ");
                        var key = Console.ReadLine();

                        Console.Write("VALUE: ");
                        var val = Console.ReadLine();

                        var result = swarm.Create(uuid, key, val).GetAwaiter().GetResult();
                        if (result)
                        {
                            Console.WriteLine("Updated!");
                        }
                        else
                        {
                            Console.WriteLine("Failed!");
                        }

                        break;
                    }

                    case 2:
                    {
                        Console.WriteLine("**READ**");

                        Console.Write("KEY: ");
                        var key = Console.ReadLine();

                        var val = swarm.Read(uuid, key).GetAwaiter().GetResult();
                        if (val != null)
                        {
                            Console.WriteLine("GOT: " + val);
                        }
                        else
                        {
                            Console.WriteLine("Nothing found");
                        }

                        break;
                    }

                    case 3:
                    {
                        Console.WriteLine("**UPDATE**");

                        Console.Write("KEY: ");
                        var key = Console.ReadLine();

                        Console.Write("VALUE: ");
                        var val = Console.ReadLine();

                        var result = swarm.Update(uuid, key, val).GetAwaiter().GetResult();
                        if (result)
                        {
                            Console.WriteLine("Updated!");
                        }
                        else
                        {
                            Console.WriteLine("Failed!");
                        }

                        break;
                    }

                    case 4:
                    {
                        Console.WriteLine("**DELETE**");

                        Console.Write("KEY: ");
                        var key = Console.ReadLine();

                        var result = swarm.Delete(uuid, key).GetAwaiter().GetResult();
                        if (result)
                        {
                            Console.WriteLine("Removed!");
                        }
                        else
                        {
                            Console.WriteLine("Failed!");
                        }

                        break;
                    }

                    case 5:
                    {
                        Console.WriteLine("**CONTRACT.WRITE**");

                        Console.Write("KEY: ");
                        var key = Console.ReadLine();

                        Console.Write("VALUE: ");
                        var content = Console.ReadLine();

                        var tx = api.CallContract(owner_keys, contractHash, "update", new object[] { owner_keys.address.AddressToScriptHash(), uuid, key, content });

                        if (tx != null)
                        {
                            Console.WriteLine($"Unconfirmed tx: {tx.Hash}");
                            api.WaitForTransaction(owner_keys, tx);
                            Console.WriteLine($"Confirmed tx: {tx.Hash}");
                        }
                        else
                        {
                            Console.WriteLine("Tx Failed!");
                        }

                        break;
                    }

                    case 6:
                    {
                        Console.WriteLine("**CONTRACT.READ**");


                        Console.Write("KEY: ");
                        var key = Console.ReadLine();

                        var tx = api.CallContract(owner_keys, contractHash, "read", new object[] { owner_keys.address.AddressToScriptHash(), uuid, key });

                        if (tx != null)
                        {
                            Console.WriteLine($"Unconfirmed tx: {tx.Hash}");
                            api.WaitForTransaction(owner_keys, tx);
                            Console.WriteLine($"Confirmed tx: {tx.Hash}");

                            var val = swarm.Read(uuid, key).GetAwaiter().GetResult();
                            if (val != null)
                            {
                                Console.WriteLine("GOT: " + val);
                            }
                            else
                            {
                                Console.WriteLine("Nothing found");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Tx Failed!");
                        }

                        break;
                    }


                    case 7:
                    {
                        Console.WriteLine("**CONTRACT.DEPLOY**");

                        var tx = api.DeployContract(owner_keys, contractBytes, new byte[] { 0x07, 0x10 }, 0x05, ContractPropertyState.HasStorage, "Bluzelle", "v1.0", "Bluzelle", "*****@*****.**", "contract");
                        if (tx != null)
                        {
                            Console.WriteLine($"Unconfirmed tx: {tx.Hash}");
                            api.WaitForTransaction(owner_keys, tx);
                            Console.WriteLine($"Confirmed tx: {tx.Hash}");
                        }
                        else
                        {
                            Console.WriteLine("Tx Failed!");
                        }

                        break;
                    }
                    }
                }
                else
                {
                    Console.WriteLine("Invalid option");
                }
            } while (true);
        }