diff --git a/NineChronicles.DataProvider/RenderSubscriber.cs b/NineChronicles.DataProvider/RenderSubscriber.cs index 177ae7fd..a00462fa 100644 --- a/NineChronicles.DataProvider/RenderSubscriber.cs +++ b/NineChronicles.DataProvider/RenderSubscriber.cs @@ -348,6 +348,33 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) } }); + _actionRenderer.EveryRender() + .Subscribe(ev => + { + try + { + if (ev.Exception == null && ev.Action is { } has) + { + var start = DateTimeOffset.UtcNow; + var inputState = new Account(_blockChainStates.GetAccountState(ev.PreviousState)); + var outputState = new Account(_blockChainStates.GetAccountState(ev.OutputState)); + _avatarList.Add(AvatarData.GetAvatarInfo(outputState, ev.Signer, has.AvatarAddress, has.RuneInfos, _blockTimeOffset)); + _hasList.Add(HackAndSlashData.GetHackAndSlashInfo(inputState, outputState, ev.Signer, has.AvatarAddress, has.StageId, has.Id, ev.BlockIndex, _blockTimeOffset)); + if (has.StageBuffId.HasValue) + { + _hasWithRandomBuffList.Add(HasWithRandomBuffData.GetHasWithRandomBuffInfo(inputState, outputState, ev.Signer, has.AvatarAddress, has.StageId, has.StageBuffId, has.Id, ev.BlockIndex, _blockTimeOffset)); + } + + var end = DateTimeOffset.UtcNow; + Log.Debug("Stored HackAndSlash action in block #{index}. Time Taken: {time} ms.", ev.BlockIndex, (end - start).Milliseconds); + } + } + catch (Exception ex) + { + Log.Error("RenderSubscriber: {message}", ex.Message); + } + }); + _actionRenderer.EveryRender() .Subscribe(ev => { @@ -383,6 +410,41 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) } }); + _actionRenderer.EveryRender() + .Subscribe(ev => + { + try + { + if (ev.Exception == null && ev.Action is { } hasSweep) + { + var start = DateTimeOffset.UtcNow; + var inputState = new Account(_blockChainStates.GetAccountState(ev.PreviousState)); + var outputState = new Account(_blockChainStates.GetAccountState(ev.OutputState)); + _avatarList.Add(AvatarData.GetAvatarInfo(outputState, ev.Signer, hasSweep.avatarAddress, hasSweep.runeInfos, _blockTimeOffset)); + _hasSweepList.Add(HackAndSlashSweepData.GetHackAndSlashSweepInfo( + inputState, + outputState, + ev.Signer, + hasSweep.avatarAddress, + hasSweep.stageId, + hasSweep.worldId, + hasSweep.apStoneCount, + hasSweep.actionPoint, + hasSweep.costumes.Count, + hasSweep.equipments.Count, + hasSweep.Id, + ev.BlockIndex, + _blockTimeOffset)); + var end = DateTimeOffset.UtcNow; + Log.Debug("Stored HackAndSlashSweep action in block #{index}. Time Taken: {time} ms.", ev.BlockIndex, (end - start).Milliseconds); + } + } + catch (Exception ex) + { + Log.Error("RenderSubscriber: {message}", ex.Message); + } + }); + _actionRenderer.EveryRender() .Subscribe(ev => { @@ -413,6 +475,36 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) } }); + _actionRenderer.EveryRender() + .Subscribe(ev => + { + try + { + if (ev.Exception == null && ev.Action is { } combinationConsumable) + { + var start = DateTimeOffset.UtcNow; + var inputState = new Account(_blockChainStates.GetAccountState(ev.PreviousState)); + var outputState = new Account(_blockChainStates.GetAccountState(ev.OutputState)); + _ccList.Add(CombinationConsumableData.GetCombinationConsumableInfo( + inputState, + outputState, + ev.Signer, + combinationConsumable.avatarAddress, + combinationConsumable.recipeId, + combinationConsumable.slotIndex, + combinationConsumable.Id, + ev.BlockIndex, + _blockTimeOffset)); + var end = DateTimeOffset.UtcNow; + Log.Debug("Stored CombinationConsumable action in block #{index}. Time Taken: {time} ms.", ev.BlockIndex, (end - start).Milliseconds); + } + } + catch (Exception ex) + { + Log.Error("RenderSubscriber: {message}", ex.Message); + } + }); + _actionRenderer.EveryRender() .Subscribe(ev => { @@ -488,6 +580,81 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) } }); + _actionRenderer.EveryRender() + .Subscribe(ev => + { + try + { + if (ev.Exception == null && ev.Action is { } combinationEquipment) + { + var start = DateTimeOffset.UtcNow; + var inputState = new Account(_blockChainStates.GetAccountState(ev.PreviousState)); + var outputState = new Account(_blockChainStates.GetAccountState(ev.OutputState)); + _ceList.Add(CombinationEquipmentData.GetCombinationEquipmentInfo( + inputState, + outputState, + ev.Signer, + combinationEquipment.avatarAddress, + combinationEquipment.recipeId, + combinationEquipment.slotIndex, + combinationEquipment.subRecipeId, + combinationEquipment.Id, + ev.BlockIndex, + _blockTimeOffset)); + if (combinationEquipment.payByCrystal) + { + var replaceCombinationEquipmentMaterialList = ReplaceCombinationEquipmentMaterialData + .GetReplaceCombinationEquipmentMaterialInfo( + inputState, + outputState, + ev.Signer, + combinationEquipment.avatarAddress, + combinationEquipment.recipeId, + combinationEquipment.subRecipeId, + combinationEquipment.payByCrystal, + combinationEquipment.Id, + ev.BlockIndex, + _blockTimeOffset); + foreach (var replaceCombinationEquipmentMaterial in replaceCombinationEquipmentMaterialList) + { + _replaceCombinationEquipmentMaterialList.Add(replaceCombinationEquipmentMaterial); + } + } + + var end = DateTimeOffset.UtcNow; + Log.Debug( + "Stored CombinationEquipment action in block #{index}. Time Taken: {time} ms.", + ev.BlockIndex, + (end - start).Milliseconds); + start = DateTimeOffset.UtcNow; + + var slotState = outputState.GetCombinationSlotState( + combinationEquipment.avatarAddress, + combinationEquipment.slotIndex); + + if (slotState?.Result.itemUsable.ItemType is ItemType.Equipment) + { + _eqList.Add(EquipmentData.GetEquipmentInfo( + ev.Signer, + combinationEquipment.avatarAddress, + (Equipment)slotState.Result.itemUsable, + _blockTimeOffset)); + } + + end = DateTimeOffset.UtcNow; + Log.Debug( + "Stored avatar {address}'s equipment in block #{index}. Time Taken: {time} ms.", + combinationEquipment.avatarAddress, + ev.BlockIndex, + (end - start).Milliseconds); + } + } + catch (Exception ex) + { + Log.Error("RenderSubscriber: {message}", ex.Message); + } + }); + _actionRenderer.EveryRender() .Subscribe(ev => { @@ -556,6 +723,74 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) } }); + _actionRenderer.EveryRender() + .Subscribe(ev => + { + try + { + if (ev.Exception == null && ev.Action is { } itemEnhancement) + { + var start = DateTimeOffset.UtcNow; + var inputState = new Account(_blockChainStates.GetAccountState(ev.PreviousState)); + var outputState = new Account(_blockChainStates.GetAccountState(ev.OutputState)); + if (ItemEnhancementFailData.GetItemEnhancementFailInfo( + inputState, + outputState, + ev.Signer, + itemEnhancement.avatarAddress, + Guid.Empty, + itemEnhancement.materialIds, + itemEnhancement.itemId, + itemEnhancement.Id, + ev.BlockIndex, + _blockTimeOffset) is { } itemEnhancementFailModel) + { + _itemEnhancementFailList.Add(itemEnhancementFailModel); + } + + _ieList.Add(ItemEnhancementData.GetItemEnhancementInfo( + inputState, + outputState, + ev.Signer, + itemEnhancement.avatarAddress, + itemEnhancement.slotIndex, + Guid.Empty, + itemEnhancement.materialIds, + itemEnhancement.itemId, + itemEnhancement.Id, + ev.BlockIndex, + _blockTimeOffset)); + var end = DateTimeOffset.UtcNow; + Log.Debug("Stored ItemEnhancement action in block #{index}. Time Taken: {time} ms.", ev.BlockIndex, (end - start).Milliseconds); + start = DateTimeOffset.UtcNow; + + var slotState = outputState.GetCombinationSlotState( + itemEnhancement.avatarAddress, + itemEnhancement.slotIndex); + + if (slotState?.Result.itemUsable.ItemType is ItemType.Equipment) + { + _eqList.Add(EquipmentData.GetEquipmentInfo( + ev.Signer, + itemEnhancement.avatarAddress, + (Equipment)slotState.Result.itemUsable, + _blockTimeOffset)); + } + + end = DateTimeOffset.UtcNow; + Log.Debug( + "Stored avatar {address}'s equipment in block #{index}. Time Taken: {time} ms.", + itemEnhancement.avatarAddress, + ev.BlockIndex, + (end - start).Milliseconds); + } + } + catch (Exception ex) + { + Log.Error("RenderSubscriber: {message}", ex.Message); + } + }); + _actionRenderer.EveryRender() .Subscribe(ev => {