Skip to content

Commit

Permalink
Refactor and improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
GulfOfAlaska committed Jul 9, 2018
1 parent a3d8acb commit 641a871
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions neo-cli/Shell/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ private void PersistEventsOnApplicationExecuted(object sender, ApplicationExecut
var transactionHash = e.Transaction.Hash.ToString().Substring(2);
var blockHeight = ((LevelDBBlockchain)sender).Height;
var blockTime = Blockchain.Default.GetBlock(blockHeight).Timestamp;
Console.WriteLine("Executed txn: ${0}, block height: ${1}", transactionHash, blockHeight);
Console.WriteLine("Executed txn: {0}, block height: {1}", transactionHash, blockHeight);

if (e.VMState.HasFlag(VMState.FAULT))
{
Expand Down Expand Up @@ -1077,8 +1077,6 @@ private void PersistEventsOnApplicationExecuted(object sender, ApplicationExecut

private static void WriteToPsql(SmartContractEvent contractEvent)
{
Console.WriteLine(String.Format("Blockheight={0}", contractEvent.blockNumber));

string connString = Environment.GetEnvironmentVariable("DB_CONNECTION_STRING");

using (var conn = new NpgsqlConnection(connString))
Expand All @@ -1087,30 +1085,23 @@ private static void WriteToPsql(SmartContractEvent contractEvent)
try
{
conn.Open();
Console.WriteLine(String.Format("Connection {0}", conn.State));

WriteToEventTable(contractEvent, conn);

if (contractEvent.eventType == "created")
{
WriteToOfferTable(contractEvent, conn);
}

if (contractEvent.eventType == "filled")
else if (contractEvent.eventType == "filled")
{
WriteToTradeTable(contractEvent, conn);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (conn != null && conn.State == System.Data.ConnectionState.Open)
{
conn.Close();
Console.WriteLine(String.Format("Connection {0}", conn.State));
}
}
}
Expand All @@ -1119,7 +1110,7 @@ private static void WriteToPsql(SmartContractEvent contractEvent)

private static void WriteToEventTable(SmartContractEvent contractEvent, NpgsqlConnection conn)
{
Console.WriteLine(String.Format("Event {0} {1}", contractEvent.eventType, contractEvent.eventPayload));
Console.WriteLine(String.Format("Inserting {0} event {1}, block height: {2}", contractEvent.eventType, contractEvent.eventPayload, contractEvent.blockNumber));
try
{
using (var cmd = new NpgsqlCommand(
Expand Down Expand Up @@ -1158,7 +1149,7 @@ private static void WriteToEventTable(SmartContractEvent contractEvent, NpgsqlCo

private static void WriteToOfferTable(SmartContractEvent contractEvent, NpgsqlConnection conn)
{
Console.WriteLine(String.Format("Offer {0}", contractEvent.eventPayload));
Console.WriteLine(String.Format("Inserting Offer {0}, block height: {1}", contractEvent.eventPayload, contractEvent.blockNumber));

try
{
Expand Down Expand Up @@ -1212,7 +1203,7 @@ private static void WriteToOfferTable(SmartContractEvent contractEvent, NpgsqlCo

private static void WriteToTradeTable(SmartContractEvent contractEvent, NpgsqlConnection conn)
{
Console.WriteLine(String.Format("Trade {0}", contractEvent.eventPayload));
Console.WriteLine(String.Format("Inserting {0}, block height: {1}", contractEvent.eventPayload, contractEvent.blockNumber));

string connString = Environment.GetEnvironmentVariable("DB_CONNECTION_STRING");
try
Expand Down

0 comments on commit 641a871

Please sign in to comment.