static void Main(string[] args) { var icxBlock = IconGateway.GetBlockByHeight(17699880); //ICX dividends var trx = icxBlock.ConfirmedTransactionList[1]; var txResult = IconGateway.GetTransactionResult(trx.TxHash); trx.TxResultDetails = txResult; var msgStr = JsonConvert.SerializeObject(trx); var func = new TokenDepositReceivedFunction.Function(); func.ProcessRecordAsync(null, msgStr).Wait(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); //var trxScoreSample = File.ReadAllText("TrxScoreSample.json"); //var trxTransferSample = File.ReadAllText("TrxTransferSample.json"); //var trxTransferSampleError = File.ReadAllText("TrxTransferSampleError.json"); //var icxBlock = IconGateway.GetBlockByHeight(17305133); //Normal transfer var icxBlock = IconGateway.GetBlockByHeight(17564306); //ICX dividends var trx = icxBlock.ConfirmedTransactionList[3]; var txResult = IconGateway.GetTransactionResult(trx.TxHash); trx.TxResultDetails = txResult; var msgStr = JsonConvert.SerializeObject(trx); var func = new ICXDepositReceivedFunction.Function(); func.ProcessRecordAsync(null, msgStr).Wait(); }
private static void ProcessBlock(ICXBlock block, long icxBlockHeight = -1) { BlockProcessedStatus blockStatus = null; ICXBlock icxBlock = block; long blockHeight = 0; try { //Get block height to process if (icxBlockHeight > 0) { blockHeight = icxBlockHeight; } else { blockHeight = block.Height; } //Get block info from Firebase Console.WriteLine($"Starting to Process Block {blockHeight} in thread {System.Threading.Thread.CurrentThread.ManagedThreadId}"); blockStatus = FirebaseGateway.GetBlockProcessed(blockHeight); if (blockStatus == null) { blockStatus = new BlockProcessedStatus() { height = blockHeight, eventsPublished = 0, retryAttempts = 0 }; } else { if (blockStatus.completed == true) { Console.WriteLine($"Block {blockHeight} is already completed, exiting"); return; } blockStatus.retryAttempts++; } //Get the ICX Block if it not provided if (icxBlockHeight > 0) { icxBlock = IconGateway.GetBlockByHeight(icxBlockHeight); } blockStatus.blockTimestamp = Google.Cloud.Firestore.Timestamp.FromDateTimeOffset(icxBlock.GetTimeStamp().AddHours(-8)); // Check ISCORE var rewards = IconGateway.GetAvailableRewards("hxc147caa988765c13eaa6ca43400c27a0372b9436"); if (rewards < oldRewards || oldRewards == -1) { oldRewards = rewards; } else if (rewards > oldRewards) { blockStatus.eventsPublished++; Console.WriteLine($"ISCORE CHANGED, Pushing event update"); publishIScoreChange(); oldRewards = rewards; } var blockTimeStamp = DateTimeOffset.FromUnixTimeMilliseconds(icxBlock.TimeStamp / 1000).AddHours(8); var oldNess = Convert.ToInt32((DateTime.UtcNow.AddHours(8) - icxBlock.GetTimeStamp()).TotalSeconds); //What do we do Console.WriteLine($"block timestamp {icxBlock.GetTimeStamp()}, oldNess {oldNess} seconds, HEIGHT {icxBlock.Height}, transactions {icxBlock.ConfirmedTransactionList.Count}, eventCount {eventCounter}, retries {blockStatus.retryAttempts} in thread {System.Threading.Thread.CurrentThread.ManagedThreadId}"); foreach (var tx in icxBlock.ConfirmedTransactionList) { var txStr = JsonConvert.SerializeObject(tx); if (tx.From != null && tx.From.StartsWith("hx") && tx.To != null && tx.To.StartsWith("hx")) { blockStatus.eventsPublished++; publishTransferMessage(tx); } if (tx.From != null && tx.From.StartsWith("hx") && tx.To != null && tx.To.StartsWith("cx")) { blockStatus.eventsPublished++; var txResult = IconGateway.GetTransactionResult(tx.TxHash); tx.TxResultDetails = txResult; publishContractMethodMessage(tx); } } blockStatus.completed = true; UpdateBlockStatus(blockStatus, icxBlock); Console.WriteLine($"COMPLETED {icxBlock.Height} in thread {System.Threading.Thread.CurrentThread.ManagedThreadId}"); } catch (Exception ex) { Console.WriteLine($"EXCEPTION : Error on block {blockHeight} : {ex.Message} in thread {System.Threading.Thread.CurrentThread.ManagedThreadId}"); blockStatus.completed = false; blockStatus.lastErrorMessage = ex.Message; UpdateBlockStatus(blockStatus, icxBlock); } }