Example #1
0
        static void ExportChunk(uint chunkID, uint maxBlock, CronAPI api)
        {
            var fileName = "chain/chunk" + chunkID;

            if (File.Exists(fileName))
            {
                var blocks = LoadChunk(fileName);
                if (blocks.Count == chunkSize)
                {
                    return;
                }
            }


            var lines = new List <string>();

            uint startBlock = chunkID * chunkSize;
            uint endBlock   = startBlock + (chunkSize - 1);

            for (uint i = startBlock; i <= endBlock; i++)
            {
                if (i > maxBlock)
                {
                    break;
                }


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

            ExportBlocks(chunkID, startBlock, lines);
        }
Example #2
0
        static void Main(string[] args)
        {
            // NOTE - You can also create an API instance for a specific private net
            var api = CronRPC.ForMainNet();

            // NOTE - Private keys should not be hardcoded in the code, this is just for demonstration purposes!
            var privateKey = "a9e2b5436cab6ff74be2d5c91b8a67053494ab5b454ac2851f872fb0fd30ba5e";

            Console.WriteLine("*Loading NEO address...");
            var keys = new KeyPair(privateKey.HexToBytes());

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

            // it is possible to optionally obtain also token balances with this method
            Console.WriteLine("*Syncing balances...");
            var balances = api.GetAssetBalancesOf(keys.address);

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

            // TestInvokeScript let's us call a smart contract method and get back a result
            // NEP5 https://github.com/neo-project/proposals/issues/3

            api = CronRPC.ForMainNet();
            var redPulse = api.GetToken("RPX");

            // you could also create a NEP5 from a contract script hash
            //var redPulse_contractHash = "ecc6b20d3ccac1ee9ef109af5a7cdb85706b1df9";
            //var redPulse = new NEP5(api, redPulse_contractHash);

            Console.WriteLine("*Querying Symbol from RedPulse contract...");
            //var response = api.TestInvokeScript(redPulse_contractHash, "symbol", new object[] { "" });
            //var symbol = System.Text.Encoding.ASCII.GetString((byte[])response.result);
            var symbol = redPulse.Symbol; // should be "RPX"

            // here we get the RedPulse token balance from an address
            Console.WriteLine("*Querying BalanceOf from RedPulse contract...");

            var balance = redPulse.BalanceOf("AVQ6jAQ3Prd32BXU5r2Vb3QL1gYzTpFhaf");

            Console.WriteLine($"{balance} {symbol}");

            Console.WriteLine("Press any key to quit...");
            Console.ReadKey();
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (privateKeyInput.Text.Length == 52)
            {
                keyPair = KeyPair.FromWIF(privateKeyInput.Text);
            }
            else
            if (privateKeyInput.Text.Length == 64)
            {
                var keyBytes = privateKeyInput.Text.HexToBytes();
                keyPair = new KeyPair(keyBytes);
            }
            else
            {
                MessageBox.Show("Invalid key input, must be 104 or 64 hexdecimal characters.");
                return;
            }

            var net = netComboBox.SelectedItem.ToString();

            switch (net)
            {
            case "Test": api = CronRPC.ForMainNet(); break;

            case "Main": api = CronRPC.ForMainNet(); break;

            default:
            {
                MessageBox.Show("Invalid net.");
                return;
            }
            }


            tabs.TabPages.Remove(loginPage);
            tabs.TabPages.Add(loadingPage);

            timer1.Enabled = true;

            var task = new Task(() => OpenWallet());

            task.Start();
        }
Example #4
0
        static void Main(string[] args)
        {
            if (args.Length < 5)
            {
                Console.WriteLine("neo-sender <Net> <PrivateKey> <DestAddress> <Symbol> <Amount>");
                Console.WriteLine("Net          Can be Main, Test or custom URL");
                Console.WriteLine("PrivateKey   Can be a full hex private key or a WIF private key");
                Console.WriteLine("DestAddress  Must be a valid Cron address");
                Console.WriteLine("Symbol       Must be CRONIUM, CRON or any support token");
                return;
            }

            var keyStr        = args[1];
            var outputAddress = args[2];

            var symbol = args[3].ToUpper();   //"GAS"

            string amountStr = args[4];

            amountStr = amountStr.Replace(",", ".");
            var amount = Decimal.Parse(amountStr, CultureInfo.InvariantCulture);

            if (amount <= 0 || amount > 10000000)
            {
                Console.WriteLine("Invalid amount: " + amount);
                return;
            }

            var fromKey = keyStr.Length == 52 ? KeyPair.FromWIF(keyStr) : new KeyPair(keyStr.HexToBytes());

            Console.WriteLine($"Sending {amount} {symbol} from {fromKey.address} to {outputAddress}");

            var     net = args[0].ToLowerInvariant();
            CronAPI api;

            switch (net)
            {
            case "main":
                api = CronRPC.ForMainNet();
                // api = NeoDB.NewCustomRPC("http://api.wallet.cityofzion.io", "http://seed2.cityofzion.io:8080");
                break;

            default:
                Console.Error.WriteLine("invalid net");
                return;
            }

            Transaction tx = null;

            try
            {
                if (api.IsToken(symbol))
                {
                    var token = api.GetToken(symbol);
                    tx = token.Transfer(fromKey, outputAddress, amount);
                }
                else
                if (api.IsAsset(symbol))
                {
                    tx = api.SendAsset(fromKey, outputAddress, symbol, amount);
                }
                else
                {
                    Console.WriteLine("Unknown symbol.");
                    Environment.Exit(-1);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error executing transaction. " + e.Message);
                Environment.Exit(-1);
            }

            if (tx != null)
            {
                Console.WriteLine("Transaction hash: " + tx.Hash);
            }
            else
            {
                Console.WriteLine("Transaction not accepted by mempool");
            }
        }
Example #5
0
 public void Init()
 {
     api   = CronRPC.ForMainNet();
     token = api.GetToken("RPX");
 }