コード例 #1
0
ファイル: Program.cs プロジェクト: mwherman2000/neo-1
        static void Main(string[] args)
        {
            var api = new LocalRPCNode(10332, "http://neoscan.io");

            //var api = new RemoteRPCNode(10332, "http://neoscan.io");
            //var api = new CustomRPCNode();

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

            // test public address = AHKPx5dZYnwAweQUJQH3UefoswKm6beEz2
            var manager = new BridgeManager(api, new TestSwarm(), "L3Vo5HcJhDoL7s81i4PSDTPfbUpVPrFHQ3V1GwSESkQtF4LW2vvJ", @"..\..\bin\Debug\BluzelleContract.avm");

            manager.Run();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // Setup node
            var rpcNode = new LocalRPCNode(49332, "http://127.0.0.1:49332");

            // Setup key
            var privateKey = "{put-your-private-key-here}";
            var key        = new KeyPair(privateKey.HexToBytes());

            // Get balances
            var balances = rpcNode.GetAssetBalancesOf(key.address);

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

            // Query 'Tom Holland'
            var scriptHash = new UInt160(NeoAPI.GetScriptHashFromString("0x9948548f6e742c27d61c67a34b0ba2601b6f882b"));
            var response   = rpcNode.InvokeScript(scriptHash, "query", new object[] { "Tom Holland" });

            Console.WriteLine(response.result.GetString());
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: didlie/PhantasmaAudit
        static void Main(string[] args)
        {
            uint startBlock = 2298101;
            uint endblock   = 2299480;

            string transactions_output_filename = "phantasma_transactions.csv";
            string total_output_filename        = "phantasma_totals.csv";

            var soul_scripthash = new UInt160(LuxUtils.ReverseHex("4b4f63919b9ecfd2483f0c72ff46ed31b5bbb7a4").HexToBytes());

            Console.WriteLine("Generating sale audit. This can take several minutes, please be patient.");

            var start_time = Environment.TickCount;

            var api = new LocalRPCNode(10332, "http://neoscan.io");

            var blockCount = api.GetBlockHeight();

            var balances = new Dictionary <string, decimal>();

            var total_output       = new List <string>();
            var transaction_output = new List <string>();

            var extra_refunds = new Dictionary <string, decimal>();

            transaction_output.Add($"Tx type,Tx hash,Address,NEO sent");
            for (uint height = startBlock; height <= endblock; height++)
            {
                var block = api.GetBlock(height);

                foreach (var tx in block.transactions)
                {
                    foreach (var output in tx.outputs)
                    {
                        if (output.scriptHash == soul_scripthash)
                        {
                            Transaction other = null;
                            foreach (var input in tx.inputs)
                            {
                                other = api.GetTransaction(input.prevHash);
                                UInt160 src = other.outputs[input.prevIndex].scriptHash;

                                var src_addr = src.ToAddress();
                                var ss       = tx.type.ToString().Replace("Transaction", "");

                                var balance = balances.ContainsKey(src_addr) ? balances[src_addr] : 0;

                                if (tx.type == TransactionType.InvocationTransaction)
                                {
                                    balance += output.value;
                                }
                                else
                                {
                                    var extra = extra_refunds.ContainsKey(src_addr) ? extra_refunds[src_addr] : 0;
                                    extra += output.value;
                                    extra_refunds[src_addr] = extra;
                                }

                                balances[src_addr] = balance;

                                transaction_output.Add($"{ss},{tx.Hash},{src_addr},{output.value}");

                                break;
                            }


                            break;
                        }
                    }
                }
            }

            total_output.Add($"Address,SOUL received,NEO sent,NEO to be refunded");
            foreach (KeyValuePair <string, decimal> entry in balances.OrderBy(x => x.Value))
            {
                var total_sent    = entry.Value;
                var refund_amount = entry.Value > 10 ? entry.Value - 10 : 0;
                var token_amount  = (entry.Value > 10 ? 10 : entry.Value) * 273;

                if (extra_refunds.ContainsKey(entry.Key))
                {
                    var refund_value = extra_refunds[entry.Key];
                    refund_amount += refund_value;
                    total_sent    += refund_value;
                }

                total_output.Add($"{entry.Key},{token_amount},{total_sent},{refund_amount}");
            }

            File.WriteAllLines(total_output_filename, total_output.ToArray());
            File.WriteAllLines(transactions_output_filename, transaction_output.ToArray());

            var total_blocks = (endblock - startBlock) + 1;

            var end_time = Environment.TickCount;
            var delta    = (end_time - start_time) / 1000;

            Console.WriteLine("Finished in " + delta + " seconds, loaded " + total_blocks + " blocks");
        }
コード例 #4
0
        static void Main()
        {
            string fileName;

            do
            {
                Console.Write("Enter whitelist file name or NEO address: ");
                fileName = Console.ReadLine();

                if (!fileName.Contains("."))
                {
                    break;
                }

                if (File.Exists(fileName))
                {
                    break;
                }
            } while (true);

            List <string> lines;

            if (fileName.Contains("."))
            {
                lines = File.ReadAllLines(fileName).ToList();
            }
            else
            {
                lines = new List <string>()
                {
                    fileName
                };
            }

            var ext             = Path.GetExtension(fileName);
            var result_filename = fileName.Replace(ext, "_result" + ext);

            if (File.Exists(result_filename))
            {
                var finishedLines     = File.ReadAllLines(result_filename);
                var finishedAddresses = new HashSet <string>();
                foreach (var entry in finishedLines)
                {
                    var temp = entry.Split(',');
                    for (int i = 1; i < temp.Length; i++)
                    {
                        finishedAddresses.Add(temp[i]);
                    }
                }

                var previousTotal = lines.Count;

                lines = lines.Where(x => !finishedAddresses.Contains(x)).ToList();

                var skippedTotal = previousTotal - lines.Count;

                Console.WriteLine($"Skipping {skippedTotal} addresses...");
            }

            int done = 0;

            //var api = NeoDB.ForMainNet();
            var api = new LocalRPCNode(10332, "http://neoscan.io");

            //var api = new CustomRPCNode();

            api.SetLogger(x =>
            {
                ColorPrint(ConsoleColor.DarkGray, x);
            });

            string privateKey;

            byte[] scriptHash = null;

            do
            {
                Console.Write("Enter WIF private key: ");
                privateKey = Console.ReadLine();

                if (privateKey.Length == 52)
                {
                    break;
                }
            } while (true);

            var keys = KeyPair.FromWIF(privateKey);

            Console.WriteLine("Public address: " + keys.address);

            do
            {
                Console.Write("Enter contract script hash or token symbol: ");
                var temp = Console.ReadLine();

                scriptHash = NeoAPI.GetScriptHashFromSymbol(temp);

                if (scriptHash == null && temp.Length == 40)
                {
                    scriptHash = NeoAPI.GetScriptHashFromString(temp);
                }
            } while (scriptHash == null);


            var token = new NEP5(api, scriptHash);

            var dtx = token.Deploy(keys);

            Console.WriteLine(dtx.transaction.Hash);

            Console.WriteLine($"Starting whitelisting of {token.Name} addresses...");

            var batch = new List <string>();

            foreach (var temp in lines)
            {
                var address = temp.Trim();
                if (!address.IsValidAddress())
                {
                    ColorPrint(ConsoleColor.Yellow, "Invalid address: " + address);
                    continue;
                }

                batch.Add(address);

                if (batch.Count < 5)
                {
                    continue;
                }

                Console.WriteLine($"New address batch...");

                var scripts = new List <object>();

                var batchContent = "";

                foreach (var entry in batch)
                {
                    Console.WriteLine($"\t{entry}");

                    if (batchContent.Length > 0)
                    {
                        batchContent += ",";
                    }

                    batchContent += entry;

                    var hash = entry.GetScriptHashFromAddress();
                    scripts.Add(hash);
                }


                Console.WriteLine($"Sending batch to contract...");
                Transaction tx = null;

                int failCount = 0;
                int failLimit = 20;
                do
                {
                    int tryCount = 0;
                    int tryLimit = 3;
                    do
                    {
                        var result = api.CallContract(keys, token.ContractHash, "whitelistAdd", scripts.ToArray());
                        Thread.Sleep(1000);

                        if (result != null)
                        {
                            tx = result.transaction;
                            break;
                        }

                        Console.WriteLine("Tx failed, retrying...");

                        tryCount++;
                    } while (tryCount < tryLimit);


                    if (tx != null)
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Changing RPC server...");
                        Thread.Sleep(2000);
                        api.rpcEndpoint = null;
                        failCount++;
                    }
                } while (failCount < failLimit);

                if (failCount >= failLimit || tx == null)
                {
                    ColorPrint(ConsoleColor.Red, "Try limit reached, internal problem maybe?");
                    break;
                }

                Console.WriteLine("Unconfirmed transaction: " + tx.Hash);

                api.WaitForTransaction(keys, tx);

                ColorPrint(ConsoleColor.Green, "Confirmed transaction: " + tx.Hash);

                File.AppendAllText(result_filename, $"{tx.Hash},{batchContent}\n");

                done += batch.Count;
                batch.Clear();
            }

            Console.WriteLine($"Activated {done} addresses.");

            Console.WriteLine("Finished.");
            Console.ReadLine();
        }
コード例 #5
0
        static void Main(string[] args)
        {
            var cc   = "0040998ee2e92b6da874d1e7c574b63c561fbc5a08fa38b296a59cecabf0237e779274c11894241b8030215c7ef48943ecb999a0bf5fb3143f00e401ac1ff3d42d22".HexToBytes();
            var inst = Neo.Lux.Debugger.NeoTools.Disassemble(cc);

            foreach (var entry in inst)
            {
                var tt = "";

                if (entry.data != null && entry.data.Length > 0)
                {
                    tt = entry.data.ByteToHex();
                }

                Console.WriteLine(entry.opcode + " " + tt);
            }
            Console.ReadLine();
            return;

            /*var files = Directory.EnumerateFiles("chain").OrderBy(c =>
             * {
             *  var temp = c.Replace("chain\\chunk", "");
             *  return int.Parse(temp);
             * }).ToList();
             *
             * foreach (var file in files)
             * {
             *  Console.WriteLine("Loading " + file);
             *  startBlock = LoadChunk(file) + 1;
             *  chunk++;
             * }
             *
             * Console.WriteLine("Finished in "+delta+" seconds");
             * Console.ReadLine();
             * return;*/


            var api        = new LocalRPCNode(10332, "http://neoscan.io");
            var blockCount = api.GetBlockHeight();
            var chunkCount = blockCount / chunkSize;

            var avg = 0;

            for (uint i = 0; i < chunkCount; i++)
            {
                var startT = Environment.TickCount;
                ExportChunk(i, blockCount, api);
                var endT  = Environment.TickCount;
                var delta = (endT - startT) / 1000;

                avg = (delta * 3 + avg) / 4;

                var left           = (chunkCount - (i - 1));
                var estimated_time = left * avg;

                string ss;
                if (estimated_time < 60)
                {
                    ss = estimated_time + "s";
                }
                else
                if (estimated_time < 60 * 60)
                {
                    ss = estimated_time / 60 + "m";
                }
                else
                {
                    ss = (estimated_time / (60f * 60f)).ToString("0.00") + "h";
                }

                Console.WriteLine($"{left} left, {delta}s block time, total estimated time: " + ss);
            }

            Console.WriteLine("Finished");
            Console.ReadLine();
        }
コード例 #6
0
        static void Main(string[] args)
        {
            var files = Directory.EnumerateFiles("chain").OrderBy(c =>
            {
                var temp = c.Replace("chain\\chunk", "");
                return(int.Parse(temp));
            }).ToList();

            uint startBlock = 0;

            var chunk = 0;

            var startT = Environment.TickCount;

            foreach (var file in files)
            {
                Console.WriteLine("Loading " + file);
                startBlock = LoadChunk(file) + 1;
                chunk++;
            }

            var endT  = Environment.TickCount;
            var delta = (endT - startT) / 1000;

            Console.WriteLine("Finished in " + delta + " seconds");
            Console.ReadLine();
            return;

            var lines = new List <string>();

            var api        = new LocalRPCNode(10332, "http://neoscan.io");
            var blockCount = api.GetBlockHeight();

            BigInteger lastP = 0;

            for (uint i = 0; i <= blockCount; i++)
            {
                if (lines.Count == 2500)
                {
                    ExportBlocks(chunk, startBlock, lines);

                    chunk++;
                    startBlock = i;
                }

                var response  = api.QueryRPC("getblock", new object[] { i });
                var blockData = response.GetString("result");
                lines.Add(blockData);

                if (i == 2477)
                {
                    Console.WriteLine(blockData);
                }

                BigInteger p = (i * 100) / blockCount;
                if (p != lastP)
                {
                    lastP = p;
                    Console.WriteLine(p + "%");
                }
            }

            ExportBlocks(chunk, startBlock, lines);

            /*
             * var block = GetBlock(api, 2193680);
             *
             * Console.WriteLine("Block hash: " + block.Hash.ByteToHex());
             * foreach(var tx in block.transactions)
             * {
             *  Console.WriteLine($"{tx.Hash} => {tx.type}");
             * }*/

            Console.WriteLine("Finished");
            Console.ReadLine();
        }
コード例 #7
0
        static void Main(string[] args)
        {
            var api = new LocalRPCNode(10332, "http://neoscan.io");
            //var api = new RemoteRPCNode(10332, "http://neoscan.io");

            // initialize a logger
            var log = new Logger();

            var settings = new ServerSettings()
            {
                environment = ServerEnvironment.Prod, host = "phantasma.io", path = ".", port = 7733
            };

            var server = new HTTPServer(log, settings);

            /*var ips = DNSUtils.LookUp("gmail.com", DNSUtils.DNSKind.MX);
             * foreach (var ip in ips)
             * {
             *  Console.WriteLine(ip);
             * }*/

            // instantiate a new site, the second argument is the file path where the public site contents will be found
            var site = new Site(server, "public");

            Console.WriteLine("Initializing Phantasma bridge...");
            var tx     = api.GetTransaction("d56d553f38234d73d04deacd9fd5f110d572898e8bd9c62333bbf7c31e1d1658");
            var bridge = new ChainListener(api, tx, /*2313808*/ 2350860, log);

            var bridgeThread = new Thread(() => {
                Console.WriteLine("Running Phantasma bridge...");
                bridge.Run();
            });

            bridgeThread.IsBackground = true;
            bridgeThread.Start();

            site.Get("/", (request) =>
            {
                return(HTTPResponse.FromString("Phantasma Bridge API"));
            });

            site.Get("/api/mailboxes", (request) =>
            {
                var root = DataNode.CreateArray("mailboxes");
                foreach (var mailbox in bridge.Mailboxes)
                {
                    var node = DataNode.CreateObject("box");
                    node.AddField("address", mailbox.address);
                    node.AddField("name", mailbox.name);
                    root.AddNode(node);
                }
                return(root);
            });

            Console.CancelKeyPress += delegate {
                Console.WriteLine("Stopping Phantasma bridge...");
                server.Stop();
                bridge.Stop();
                Environment.Exit(0);
            };

            server.Run();
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: simplitech/neo-lux
        static void Main()
        {
            string fileName;

            do
            {
                Console.Write("Enter whitelist file name or NEO address: ");
                fileName = Console.ReadLine();

                if (!fileName.Contains("."))
                {
                    break;
                }

                if (File.Exists(fileName))
                {
                    break;
                }
            } while (true);

            List <string> lines;

            if (fileName.Contains("."))
            {
                lines = File.ReadAllLines(fileName).ToList();
            }
            else
            {
                lines = new List <string>()
                {
                    fileName
                };
            }

            if (File.Exists(result_fileName))
            {
                var finishedLines     = File.ReadAllLines(result_fileName);
                var finishedAddresses = new HashSet <string>();
                foreach (var entry in finishedLines)
                {
                    var temp = entry.Split(',');
                    finishedAddresses.Add(temp[0]);
                }

                var previousTotal = lines.Count;

                lines = lines.Where(x => !finishedAddresses.Contains(x)).ToList();

                var skippedTotal = previousTotal - lines.Count;

                Console.WriteLine($"Skipping {skippedTotal} addresses...");
            }

            var api = new LocalRPCNode(10332, "http://neoscan.io");

            api.SetLogger(x =>
            {
                ColorPrint(ConsoleColor.DarkGray, x);
            });

            string privateKey;

            byte[] scriptHash = null;

            do
            {
                Console.Write("Enter WIF private key: ");
                privateKey = Console.ReadLine();

                if (privateKey.Length == 52)
                {
                    break;
                }
            } while (true);

            var keys = KeyPair.FromWIF(privateKey);

            Console.WriteLine("Public address: " + keys.address);

            do
            {
                Console.Write("Enter contract script hash or token symbol: ");
                var temp = Console.ReadLine();

                scriptHash = NeoAPI.GetScriptHashFromSymbol(temp);

                if (scriptHash == null && temp.Length == 40)
                {
                    scriptHash = NeoAPI.GetScriptHashFromString(temp);
                }
            } while (scriptHash == null);


            var token = new NEP5(api, scriptHash);

            decimal amount;

            Console.WriteLine($"Write amount of {token.Symbol} to distribute to each address:");
            do
            {
                if (decimal.TryParse(Console.ReadLine(), out amount) && amount > 0)
                {
                    break;
                }
            } while (true);

            int skip = 0;
            int done = 0;

            Console.WriteLine($"Initializing {token.Name} airdrop...");

            var srcBalance = token.BalanceOf(keys);

            Console.WriteLine($"Balance of {keys.address} is {srcBalance} {token.Symbol}");

            var minimum = lines.Count * amount;

            if (srcBalance < minimum)
            {
                ColorPrint(ConsoleColor.Red, $"Error: For this Airdrop you need at least {minimum} {token.Symbol} at {keys.address}");
                Console.ReadLine();
                return;
            }

            foreach (var temp in lines)
            {
                var address = temp.Trim();
                if (!address.IsValidAddress())
                {
                    skip++;
                    ColorPrint(ConsoleColor.Yellow, "Invalid address: " + address);
                    continue;
                }

                var hash    = address.GetScriptHashFromAddress();
                var balance = token.BalanceOf(hash);

                Console.WriteLine($"Found {address}: {balance} {token.Symbol}");

                Console.WriteLine($"Sending {token.Symbol} to  {address}");
                Transaction tx = null;

                int failCount = 0;
                int failLimit = 20;
                do
                {
                    int tryCount = 0;
                    int tryLimit = 3;
                    do
                    {
                        tx = token.Transfer(keys, address, amount);
                        Thread.Sleep(1000);

                        if (tx != null)
                        {
                            break;
                        }

                        Console.WriteLine("Tx failed, retrying...");

                        tryCount++;
                    } while (tryCount < tryLimit);


                    if (tx != null)
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Changing RPC server...");
                        Thread.Sleep(2000);
                        api.rpcEndpoint = null;
                        failCount++;
                    }
                } while (failCount < failLimit);

                if (failCount >= failLimit || tx == null)
                {
                    ColorPrint(ConsoleColor.Red, "Try limit reached, internal problem maybe?");
                    break;
                }

                Console.WriteLine("Unconfirmed transaction: " + tx.Hash);

                api.WaitForTransaction(keys, tx);

                ColorPrint(ConsoleColor.Green, "Confirmed transaction: " + tx.Hash);

                File.AppendAllText(result_fileName, $"{address},{tx.Hash}\n");

                done++;
            }

            Console.WriteLine($"Skipped {skip} invalid addresses.");
            Console.WriteLine($"Airdropped {amount} {token.Symbol} to {done} addresses.");

            Console.WriteLine("Finished.");
            Console.ReadLine();
        }