Beispiel #1
0
    private IEnumerator TryClaimRewards(int amount)
    {
        yield return(null);

        try
        {
            Debug.Log("Start claim NEP5 token reward");
            //var tx = neoManager.API.SendAsset(neoManager.MasterKeyPair, neoManager.PlayerKeyPair.Value.address, NEOManager.AssetSymbol, (decimal)amount);
            UInt160    scScriptHash = new UInt160(NeoAPI.GetScriptHashFromString(this.ContractHash));
            byte[]     addressBytes = LuxUtils.GetScriptHashFromAddress(neoManager.PlayerKeyPair.Value.address);
            BigInteger nepAmt       = new BigInteger(amount);
            var        tx           = neoManager.API.CallContract(neoManager.PlayerKeyPair.Value, scScriptHash, "claimRewards", new object[] { addressBytes, nepAmt });

            if (tx == null)
            {
                Debug.LogError("Null Transaction returned");
                Time.timeScale = 1;
            }
            else
            {
                Debug.Log(tx);
                Observable.FromCoroutine(SyncBalance).Subscribe().AddTo(this);
            }
        }
        catch (NullReferenceException ee)
        {
            Debug.LogError("There was a problem..." + ee);
            Time.timeScale = 1;
        }
        catch (Exception ee)
        {
            Debug.LogError("There was a problem..." + ee);
            Time.timeScale = 1;
        }
    }
Beispiel #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());
        }
Beispiel #3
0
        static void Main()
        {
            string fileName = null;

            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 RemoteRPCNode(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);

            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
                    {
                        tx = api.CallContract(keys, token.ScriptHash, "whitelistAdd", scripts.ToArray());
                        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, $"{tx.Hash},{batchContent}\n");

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

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

            Console.WriteLine("Finished.");
            Console.ReadLine();
        }
Beispiel #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
                };
            }

            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 = 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);

            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
                    {
                        var result = token.Transfer(keys, address, amount);
                        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, $"{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();
        }