예제 #1
0
        public static async Task ProcessOfferFinalised(MySqlConnection connection, int blockchainID, Web3 cl,
                                                       string contractAddress, EventLog <List <ParameterOutput> > eventLog)
        {
            using (await LockManager.GetLock(LockType.OfferFinalised).Lock())
            {
                var offerId =
                    HexHelper.ByteArrayToString((byte[])eventLog.Event
                                                .First(e => e.Parameter.Name == "offerId").Result);

                if (!OTContract_Holding_OfferCreated.Exists(connection, offerId, blockchainID))
                {
                    //Lets get this via syncing later on as we've missed the creation of the job
                    return;
                }

                if (OTContract_Holding_OfferFinalized.Exists(connection, offerId, blockchainID))
                {
                    return;
                }

                var block = await BlockHelper.GetBlock(connection, eventLog.Log.BlockHash, eventLog.Log.BlockNumber,
                                                       cl, blockchainID);


                var holder1 = (string)eventLog.Event.FirstOrDefault(e => e.Parameter.Name == "holder1")
                              .Result;
                var holder2 = (string)eventLog.Event.FirstOrDefault(e => e.Parameter.Name == "holder2")
                              .Result;
                var holder3 = (string)eventLog.Event.FirstOrDefault(e => e.Parameter.Name == "holder3")
                              .Result;

                var receipt = cl.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(eventLog.Log.TransactionHash);

                var transaction =
                    cl.Eth.Transactions.GetTransactionByHash.SendRequestAsync(eventLog.Log.TransactionHash);

                await transaction;
                await receipt;

                var row = new OTContract_Holding_OfferFinalized
                {
                    TransactionHash = eventLog.Log.TransactionHash,
                    BlockNumber     = (UInt64)eventLog.Log.BlockNumber.Value,
                    Timestamp       = block.Timestamp,
                    OfferID         = offerId,
                    Holder1         = holder1,
                    Holder2         = holder2,
                    Holder3         = holder3,
                    ContractAddress = contractAddress,
                    GasUsed         = (UInt64)receipt.Result.GasUsed.Value,
                    Data            = eventLog.Log.Data,
                    GasPrice        = (UInt64)transaction.Result.GasPrice.Value,
                    BlockchainID    = blockchainID
                };

                OTContract_Holding_OfferFinalized.InsertIfNotExist(connection, row);
            }
        }
예제 #2
0
        public static async Task ProcessOfferCreated(MySqlConnection connection, int blockchainID, Web3 cl,
                                                     string contractAddress, EventLog <Models.Program.OfferCreated> eventLog)
        {
            using (await LockManager.GetLock(LockType.OfferCreated).Lock())
            {
                string offerID = HexHelper.ByteArrayToString(eventLog.Event.offerId);

                if (OTContract_Holding_OfferCreated.Exists(connection, offerID, blockchainID))
                {
                    return;
                }

                var block = await BlockHelper.GetBlock(connection, eventLog.Log.BlockHash, eventLog.Log.BlockNumber, cl, blockchainID);

                var receipt = cl.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(eventLog.Log.TransactionHash);

                var transaction = cl.Eth.Transactions.GetTransactionByHash.SendRequestAsync(eventLog.Log.TransactionHash);

                await transaction;
                await receipt;


                var row = new OTContract_Holding_OfferCreated
                {
                    Timestamp = block.Timestamp,
                    LitigationIntervalInMinutes = (UInt64)eventLog.Event.litigationIntervalInMinutes,
                    DCNodeId             = HexHelper.ByteArrayToString(eventLog.Event.dcNodeId, false),
                    DataSetId            = HexHelper.ByteArrayToString(eventLog.Event.dataSetId),
                    HoldingTimeInMinutes = (UInt64)eventLog.Event.holdingTimeInMinutes,
                    TokenAmountPerHolder = Web3.Convert.FromWei(eventLog.Event.tokenAmountPerHolder),
                    TransactionIndex     = (UInt64)eventLog.Log.TransactionIndex.Value,
                    TransactionHash      = eventLog.Log.TransactionHash,
                    BlockNumber          = (UInt64)eventLog.Log.BlockNumber.Value,
                    OfferID            = offerID,
                    DataSetSizeInBytes = (UInt64)eventLog.Event.dataSetSizeInBytes,
                    ContractAddress    = contractAddress,
                    GasUsed            = (UInt64)receipt.Result.GasUsed.Value,
                    GasPrice           = (UInt64)transaction.Result.GasPrice.Value,
                    Data         = eventLog.Log.Data,
                    BlockchainID = blockchainID
                };

                if (row.DCNodeId.Length > 40)
                {
                    row.DCNodeId = row.DCNodeId.Substring(row.DCNodeId.Length - 40);
                }

                OTContract_Holding_OfferCreated.InsertIfNotExist(connection, row);
            }
        }