private void AddToTrxActions(IList <TrxAction> trxActions, BsonDocument actionDoc) { string act_digest = actionDoc.GetValue("block_num").AsInt32.ToString() + "-" + actionDoc.GetValue("receipt").AsBsonDocument.GetValue("act_digest").AsString; BsonDocument asBsonDocument = actionDoc.GetValue("act").AsBsonDocument; string account = asBsonDocument.GetValue("account").AsString; string name = asBsonDocument.GetValue("name").AsString; string data_hex = string.Empty; MongoDB.Bson.BsonValue data = MongoDB.Bson.BsonNull.Value; BsonValue dataValue; BsonValue hexDataValue; if (asBsonDocument.TryGetValue("hex_data", out hexDataValue) && asBsonDocument.TryGetValue("data", out dataValue)) { data = dataValue; data_hex = hexDataValue.AsString; } else if (asBsonDocument.TryGetValue("hex_data", out hexDataValue)) { data_hex = hexDataValue.AsString; } else if (asBsonDocument.TryGetValue("data", out dataValue)) { data_hex = dataValue.AsString; } string trx_id = actionDoc.GetValue("trx_id").AsString; int block_num = actionDoc.GetValue("block_num").AsInt32; string block_time = actionDoc.GetValue("block_time").AsString; TrxAction trxAction = new TrxAction() { act_digest = act_digest, trx_id = trx_id, block_num = (long)block_num, block_time = block_time, account = account, name = name, data = data, data_hex = data_hex }; if (trxActions.Any <TrxAction>((Func <TrxAction, bool>)(ad => ad.act_digest == act_digest))) { return; } trxActions.Add(trxAction); }
public async Task SetAppliedTransactionAsync(string json) { var doc = BsonDocument.Parse(json); var trxActionList = new List <TrxAction>(); this.ActionFilterInclude(doc, (IList <TrxAction>)trxActionList); if (trxActionList.Count == 0) { return; } string status = "none"; MongoDB.Bson.BsonValue statusValue; if (doc.TryGetValue("receipt", out statusValue) || (doc.TryGetValue("trx", out BsonValue trxValue) && trxValue.AsBsonDocument.TryGetValue("receipt", out statusValue))) { status = statusValue.AsBsonDocument.GetValue("status").AsString; } var builder = Builders <TrxAction> .Filter; var trxActionCollections = this.m_Database.GetCollection <TrxAction>(this.m_TrxActionsCollectionName); foreach (TrxAction trxAction in trxActionList) { TrxAction ta = trxAction; ta.status = status; bool has_hex = !string.IsNullOrEmpty(ta.data_hex); if (has_hex) { string async = await this.m_ABIService.ParseAsync(ta.account, ta.name, ta.data_hex); if (!string.IsNullOrEmpty(async)) { ta.data = BsonDocument.Parse(async).GetValue("args"); } } ta.data_error = has_hex && ta.data == (MongoDB.Bson.BsonValue)BsonNull.Value; await trxActionCollections.ReplaceOneAsync(builder.Eq <string>("act_digest", ta.act_digest), ta, this.m_UpdateOptions); ta = (TrxAction)null; } await this.m_Database.GetCollection <BsonDocument>(this.m_AppliedTransactionCollectionName) .ReplaceOneAsync(new BsonDocument("id", doc.GetValue("id").AsString), doc, this.m_UpdateOptions); }