示例#1
0
        private void UpdateAtHeight(MySqlClient sqlc, int height)
        {
            Console.WriteLine(DateTime.Now + " Updating at height=" + height);

            dynamic b = wc.GetObject("consensus/blocks?height=" + height);

            // ONLY outputs NOW
            string sql = string.Empty;

            //var minerpayouts = "0";
            //using (var h = new Hastings())
            //{
            //    if (b.minerpayouts != null)
            //        foreach (var v in b.minerpayouts)
            //            h.Add(v.value.Value);
            //    minerpayouts = h.ToString();
            //}

            //var sql = $"INSERT INTO `blocks` VALUES('{b.height}', '{b.id}', '{b.parentid}', '{b.timestamp}', " +
            //    $"'{minerpayouts}', '{b.transactions.Count}');\n"
            //    ;

            foreach (dynamic tx in b.transactions)
            {
                //sql += $"INSERT INTO `txs` VALUES('{tx.id}', '{b.height}', '{tx.siacoininputs.Count}','{tx.siacoinoutputs.Count}'," +
                //    $" '{tx.filecontracts.Count}','{tx.filecontractrevisions.Count}','{tx.storageproofs.Count}','{tx.siafundinputs.Count}'," +
                //    $" '{tx.siafundoutputs.Count}','{tx.minerfees.Count}','{tx.arbitrarydata.Count}','{tx.transactionsignatures.Count}');\n";

                foreach (dynamic output in tx.siacoinoutputs)
                {
                    //using (var h = new Hastings())
                    //{
                    //    h.Add(output.value.Value);
                    //    sql += $"INSERT INTO `siacoinoutputs` VALUES('{output.id}', '{b.height}', '{tx.id}', '{h.ToString()}', '{output.unlockhash}');\n";
                    //}
                    sql += $"UPDATE siacoinoutputs SET unlockhash='{output.unlockhash}' WHERE id='{output.id}';\n";
                }
            }

            //sqlc.ExecuteNonQuery($"START TRANSACTION;\n{sql}COMMIT;");
            if (sql.Length > 0)
            {
                sqlc.ExecuteNonQuery(sql);
            }
        }
示例#2
0
        private void InsertAtHeight(MySqlClient sqlc, int height)
        {
            Console.WriteLine(DateTime.Now + " Writing block height=" + height);

            dynamic b = wc.GetObject("consensus/blocks?height=" + height);

            var minerpayouts = "0";

            using (var h = new Hastings())
            {
                if (b.minerpayouts != null)
                {
                    foreach (var v in b.minerpayouts)
                    {
                        h.Add(v.value.Value);
                    }
                }
                minerpayouts = h.ToString();
            }

            var sql = $"INSERT INTO `blocks` VALUES('{b.height}', '{b.id}', '{b.parentid}', '{b.timestamp}', " +
                      $"'{minerpayouts}', '{b.transactions.Count}');\n"
            ;

            foreach (dynamic tx in b.transactions)
            {
                sql += $"INSERT INTO `txs` VALUES('{tx.id}', '{b.height}', '{tx.siacoininputs.Count}','{tx.siacoinoutputs.Count}'," +
                       $" '{tx.filecontracts.Count}','{tx.filecontractrevisions.Count}','{tx.storageproofs.Count}','{tx.siafundinputs.Count}'," +
                       $" '{tx.siafundoutputs.Count}','{tx.minerfees.Count}','{tx.arbitrarydata.Count}','{tx.transactionsignatures.Count}');\n";

                foreach (dynamic output in tx.siacoinoutputs)
                {
                    using (var h = new Hastings())
                    {
                        h.Add(output.value.Value);
                        sql += $"INSERT INTO `siacoinoutputs` VALUES('{output.id}', '{b.height}', '{tx.id}', '{h.ToString()}', '{output.unlockhash}');\n";
                    }
                }
            }

            //sqlc.ExecuteNonQuery($"START TRANSACTION;\n{sql}COMMIT;");
            sqlc.ExecuteNonQuery(sql);
        }