diff --git a/Lib9c/Action/SellCancellation7.cs b/Lib9c/Action/SellCancellation7.cs deleted file mode 100644 index 2b0a439da3..0000000000 --- a/Lib9c/Action/SellCancellation7.cs +++ /dev/null @@ -1,181 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Diagnostics; -using System.Linq; -using Bencodex.Types; -using Lib9c.Abstractions; -using Lib9c.Model.Order; -using Libplanet.Action; -using Libplanet.Action.State; -using Libplanet.Crypto; -using Nekoyume.Model.Item; -using Nekoyume.Model.Mail; -using Nekoyume.Model.State; -using Nekoyume.Module; -using Serilog; -using BxDictionary = Bencodex.Types.Dictionary; -using static Lib9c.SerializeKeys; - -namespace Nekoyume.Action -{ - [Serializable] - [ActionObsolete(ActionObsoleteConfig.V200020AccidentObsoleteIndex)] - [ActionType("sell_cancellation7")] - public class SellCancellation7 : GameAction, ISellCancellationV3 - { - public Guid orderId; - public Guid tradableId; - public Address sellerAvatarAddress; - public ItemSubType itemSubType; - - Guid ISellCancellationV3.OrderId => orderId; - Guid ISellCancellationV3.TradableId => tradableId; - Address ISellCancellationV3.SellerAvatarAddress => sellerAvatarAddress; - string ISellCancellationV3.ItemSubType => itemSubType.ToString(); - - [Serializable] - public class Result : AttachmentActionResult - { - public ShopItem shopItem; - public Guid id; - - protected override string TypeId => "sellCancellation.result"; - - public Result() - { - } - - public Result(BxDictionary serialized) : base(serialized) - { - shopItem = new ShopItem((BxDictionary) serialized["shopItem"]); - id = serialized["id"].ToGuid(); - } - - public override IValue Serialize() => -#pragma warning disable LAA1002 - new BxDictionary(new Dictionary - { - [(Text) "shopItem"] = shopItem.Serialize(), - [(Text) "id"] = id.Serialize() - }.Union((BxDictionary) base.Serialize())); -#pragma warning restore LAA1002 - } - - protected override IImmutableDictionary PlainValueInternal => new Dictionary - { - [ProductIdKey] = orderId.Serialize(), - [SellerAvatarAddressKey] = sellerAvatarAddress.Serialize(), - [ItemSubTypeKey] = itemSubType.Serialize(), - [TradableIdKey] = tradableId.Serialize(), - }.ToImmutableDictionary(); - - protected override void LoadPlainValueInternal(IImmutableDictionary plainValue) - { - orderId = plainValue[ProductIdKey].ToGuid(); - sellerAvatarAddress = plainValue[SellerAvatarAddressKey].ToAddress(); - itemSubType = plainValue[ItemSubTypeKey].ToEnum(); - if (plainValue.ContainsKey(TradableIdKey)) - { - tradableId = plainValue[TradableIdKey].ToGuid(); - } - } - - public override IWorld Execute(IActionContext context) - { - context.UseGas(1); - var states = context.PreviousState; - var shardedShopAddress = ShardedShopStateV2.DeriveAddress(itemSubType, orderId); - var orderDigestListAddress = OrderDigestListState.DeriveAddress(sellerAvatarAddress); - var itemAddress = Addresses.GetItemAddress(tradableId); - - CheckObsolete(ActionObsoleteConfig.V100080ObsoleteIndex, context); - - var addressesHex = GetSignerAndOtherAddressesHex(context, sellerAvatarAddress); - var sw = new Stopwatch(); - sw.Start(); - var started = DateTimeOffset.UtcNow; - Log.Verbose("{AddressesHex}Sell Cancel exec started", addressesHex); - - if (!states.TryGetAvatarState(context.Signer, sellerAvatarAddress, out var avatarState)) - { - throw new FailedLoadStateException( - $"{addressesHex}Aborted as the avatar state of the seller failed to load."); - } - - sw.Stop(); - Log.Verbose("{AddressesHex}Sell Cancel Get AgentAvatarStates: {Elapsed}", addressesHex, sw.Elapsed); - sw.Restart(); - - if (!avatarState.worldInformation.IsStageCleared(GameConfig.RequireClearedStageLevel.ActionsInShop)) - { - avatarState.worldInformation.TryGetLastClearedStageId(out var current); - throw new NotEnoughClearedStageLevelException(addressesHex, - GameConfig.RequireClearedStageLevel.ActionsInShop, current); - } - - if (!states.TryGetLegacyState(shardedShopAddress, out BxDictionary shopStateDict)) - { - throw new FailedLoadStateException($"{addressesHex}failed to load {nameof(ShardedShopStateV2)}({shardedShopAddress})."); - } - - sw.Stop(); - Log.Verbose("{AddressesHex}Sell Cancel Get ShopState: {Elapsed}", addressesHex, sw.Elapsed); - sw.Restart(); - - if (!states.TryGetLegacyState(Order.DeriveAddress(orderId), out Dictionary orderDict)) - { - throw new FailedLoadStateException($"{addressesHex}failed to load {nameof(Order)}({Order.DeriveAddress(orderId)})."); - } - - Order order = OrderFactory.Deserialize(orderDict); - order.ValidateCancelOrder2(avatarState, tradableId); - ITradableItem sellItem = order.Cancel2(avatarState, context.BlockIndex); - var shardedShopState = new ShardedShopStateV2(shopStateDict); - shardedShopState.Remove(order, context.BlockIndex); - states = states.SetLegacyState(shardedShopAddress, shardedShopState.Serialize()); - if (!states.TryGetLegacyState(orderDigestListAddress, out Dictionary rawList)) - { - throw new FailedLoadStateException($"{addressesHex}failed to load {nameof(OrderDigest)}({orderDigestListAddress})."); - } - var digestList = new OrderDigestListState(rawList); - digestList.Remove(order.OrderId); - - var expirationMail = avatarState.mailBox.OfType() - .FirstOrDefault(m => m.OrderId.Equals(orderId)); - if (!(expirationMail is null)) - { - avatarState.mailBox.Remove(expirationMail); - } - - var mail = new CancelOrderMail( - context.BlockIndex, - orderId, - context.BlockIndex, - orderId - ); - avatarState.Update(mail); - - avatarState.updatedAt = context.BlockIndex; - avatarState.blockIndex = context.BlockIndex; - - sw.Stop(); - Log.Verbose("{AddressesHex}Sell Cancel Update AvatarState: {Elapsed}", addressesHex, sw.Elapsed); - sw.Restart(); - - states = states - .SetLegacyState(itemAddress, sellItem.Serialize()) - .SetLegacyState(orderDigestListAddress, digestList.Serialize()) - .SetAvatarState(sellerAvatarAddress, avatarState); - sw.Stop(); - Log.Verbose("{AddressesHex}Sell Cancel Set AvatarState: {Elapsed}", addressesHex, sw.Elapsed); - sw.Restart(); - - sw.Stop(); - var ended = DateTimeOffset.UtcNow; - Log.Verbose("{AddressesHex}Sell Cancel Set ShopState: {Elapsed}", addressesHex, sw.Elapsed); - Log.Verbose("{AddressesHex}Sell Cancel Total Executed Time: {Elapsed}", addressesHex, ended - started); - return states; - } - } -} diff --git a/Lib9c/Action/SellCancellation8.cs b/Lib9c/Action/SellCancellation8.cs deleted file mode 100644 index 813ec07c99..0000000000 --- a/Lib9c/Action/SellCancellation8.cs +++ /dev/null @@ -1,199 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.Immutable; -using System.Diagnostics; -using System.Linq; -using Bencodex.Types; -using Lib9c.Abstractions; -using Lib9c.Model.Order; -using Libplanet.Action; -using Libplanet.Action.State; -using Libplanet.Crypto; -using Nekoyume.Model.Item; -using Nekoyume.Model.Mail; -using Nekoyume.Model.State; -using Nekoyume.Module; -using Serilog; -using BxDictionary = Bencodex.Types.Dictionary; -using static Lib9c.SerializeKeys; - -namespace Nekoyume.Action -{ - [Serializable] - [ActionObsolete(ActionObsoleteConfig.V200020AccidentObsoleteIndex)] - [ActionType("sell_cancellation8")] - public class SellCancellation8 : GameAction, ISellCancellationV3 - { - public Guid orderId; - public Guid tradableId; - public Address sellerAvatarAddress; - public ItemSubType itemSubType; - - Guid ISellCancellationV3.OrderId => orderId; - Guid ISellCancellationV3.TradableId => tradableId; - Address ISellCancellationV3.SellerAvatarAddress => sellerAvatarAddress; - string ISellCancellationV3.ItemSubType => itemSubType.ToString(); - - [Serializable] - public class Result : AttachmentActionResult - { - public ShopItem shopItem; - public Guid id; - - protected override string TypeId => "sellCancellation.result"; - - public Result() - { - } - - public Result(BxDictionary serialized) : base(serialized) - { - shopItem = new ShopItem((BxDictionary) serialized["shopItem"]); - id = serialized["id"].ToGuid(); - } - - public override IValue Serialize() => -#pragma warning disable LAA1002 - new BxDictionary(new Dictionary - { - [(Text) "shopItem"] = shopItem.Serialize(), - [(Text) "id"] = id.Serialize() - }.Union((BxDictionary) base.Serialize())); -#pragma warning restore LAA1002 - } - - protected override IImmutableDictionary PlainValueInternal => new Dictionary - { - [ProductIdKey] = orderId.Serialize(), - [SellerAvatarAddressKey] = sellerAvatarAddress.Serialize(), - [ItemSubTypeKey] = itemSubType.Serialize(), - [TradableIdKey] = tradableId.Serialize(), - }.ToImmutableDictionary(); - - protected override void LoadPlainValueInternal(IImmutableDictionary plainValue) - { - orderId = plainValue[ProductIdKey].ToGuid(); - sellerAvatarAddress = plainValue[SellerAvatarAddressKey].ToAddress(); - itemSubType = plainValue[ItemSubTypeKey].ToEnum(); - if (plainValue.ContainsKey(TradableIdKey)) - { - tradableId = plainValue[TradableIdKey].ToGuid(); - } - } - - public override IWorld Execute(IActionContext context) - { - context.UseGas(1); - var states = context.PreviousState; - var shardedShopAddress = ShardedShopStateV2.DeriveAddress(itemSubType, orderId); - var digestListAddress = OrderDigestListState.DeriveAddress(sellerAvatarAddress); - var itemAddress = Addresses.GetItemAddress(tradableId); - - CheckObsolete(ActionObsoleteConfig.V100080ObsoleteIndex, context); - - var addressesHex = GetSignerAndOtherAddressesHex(context, sellerAvatarAddress); - var sw = new Stopwatch(); - sw.Start(); - var started = DateTimeOffset.UtcNow; - Log.Verbose("{AddressesHex}Sell Cancel exec started", addressesHex); - - if (!states.TryGetAvatarState(context.Signer, sellerAvatarAddress, out var avatarState)) - { - throw new FailedLoadStateException( - $"{addressesHex}Aborted as the avatar state of the seller failed to load."); - } - - sw.Stop(); - Log.Verbose("{AddressesHex}Sell Cancel Get AgentAvatarStates: {Elapsed}", addressesHex, sw.Elapsed); - sw.Restart(); - - if (!avatarState.worldInformation.IsStageCleared(GameConfig.RequireClearedStageLevel.ActionsInShop)) - { - avatarState.worldInformation.TryGetLastClearedStageId(out var current); - throw new NotEnoughClearedStageLevelException(addressesHex, - GameConfig.RequireClearedStageLevel.ActionsInShop, current); - } - - if (!states.TryGetLegacyState(shardedShopAddress, out BxDictionary shopStateDict)) - { - throw new FailedLoadStateException($"{addressesHex}failed to load {nameof(ShardedShopStateV2)}({shardedShopAddress})."); - } - - sw.Stop(); - Log.Verbose("{AddressesHex}Sell Cancel Get ShopState: {Elapsed}", addressesHex, sw.Elapsed); - sw.Restart(); - - avatarState.updatedAt = context.BlockIndex; - avatarState.blockIndex = context.BlockIndex; - - if (!states.TryGetLegacyState(digestListAddress, out Dictionary rawList)) - { - throw new FailedLoadStateException($"{addressesHex}failed to load {nameof(OrderDigest)}({digestListAddress})."); - } - var digestList = new OrderDigestListState(rawList); - - digestList.Remove(orderId); - - if (!states.TryGetLegacyState(Order.DeriveAddress(orderId), out Dictionary orderDict)) - { - throw new FailedLoadStateException($"{addressesHex}failed to load {nameof(Order)}({Order.DeriveAddress(orderId)})."); - } - - Order order = OrderFactory.Deserialize(orderDict); - bool fromPreviousAction = false; - try - { - order.ValidateCancelOrder(avatarState, tradableId); - } - catch (Exception) - { - order.ValidateCancelOrder2(avatarState, tradableId); - fromPreviousAction = true; - } - - var sellItem = fromPreviousAction - ? order.Cancel2(avatarState, context.BlockIndex) - : order.Cancel(avatarState, context.BlockIndex); - - if (context.BlockIndex < order.ExpiredBlockIndex) - { - var shardedShopState = new ShardedShopStateV2(shopStateDict); - shardedShopState.Remove(order, context.BlockIndex); - states = states.SetLegacyState(shardedShopAddress, shardedShopState.Serialize()); - } - - var expirationMail = avatarState.mailBox.OfType() - .FirstOrDefault(m => m.OrderId.Equals(orderId)); - if (!(expirationMail is null)) - { - avatarState.mailBox.Remove(expirationMail); - } - - var mail = new CancelOrderMail( - context.BlockIndex, - orderId, - context.BlockIndex, - orderId - ); - avatarState.Update(mail); - - sw.Stop(); - Log.Verbose("{AddressesHex}Sell Cancel Update AvatarState: {Elapsed}", addressesHex, sw.Elapsed); - sw.Restart(); - - states = states - .SetLegacyState(itemAddress, sellItem.Serialize()) - .SetLegacyState(digestListAddress, digestList.Serialize()) - .SetAvatarState(sellerAvatarAddress, avatarState); - sw.Stop(); - Log.Verbose("{AddressesHex}Sell Cancel Set AvatarState: {Elapsed}", addressesHex, sw.Elapsed); - sw.Restart(); - - sw.Stop(); - var ended = DateTimeOffset.UtcNow; - Log.Verbose("{AddressesHex}Sell Cancel Set ShopState: {Elapsed}", addressesHex, sw.Elapsed); - Log.Verbose("{AddressesHex}Sell Cancel Total Executed Time: {Elapsed}", addressesHex, ended - started); - return states; - } - } -} diff --git a/Lib9c/Extensions/CombinationSlotStateExtensions.cs b/Lib9c/Extensions/CombinationSlotStateExtensions.cs index 6d2b906aa6..b5765aa836 100644 --- a/Lib9c/Extensions/CombinationSlotStateExtensions.cs +++ b/Lib9c/Extensions/CombinationSlotStateExtensions.cs @@ -27,7 +27,7 @@ public static void ValidateFromAction( $"{addressesHex}Aborted as the slot state is invalid: {slotState} @ {slotIndex}"); } } - + public static bool TryGetResultId(this CombinationSlotState state, out Guid resultId) { if (state?.Result is null) @@ -74,67 +74,6 @@ public static bool TryGetResultId(this CombinationSlotState state, out Guid resu case SellCancellation.Result r: resultId = r.id; break; - case SellCancellation7.Result r: - resultId = r.id; - break; - case SellCancellation8.Result r: - resultId = r.id; - break; - default: - resultId = default(Guid); - return false; - } - - return true; - } - - [Obsolete("Use TryGetResultId instead")] - public static bool TryGetResultIdV1(this CombinationSlotState state, out Guid resultId) - { - if (state?.Result is null) - { - resultId = default(Guid); - return false; - } - - switch (state.Result) - { - case Buy7.BuyerResult r: - resultId = r.id; - break; - case Buy7.SellerResult r: - resultId = r.id; - break; - case DailyReward2.DailyRewardResult r: - resultId = r.id; - break; - case ItemEnhancement13.ResultModel r: - resultId = r.id; - break; - case ItemEnhancement7.ResultModel r: - resultId = r.id; - break; - case ItemEnhancement11.ResultModel r: - resultId = r.id; - break; - case MonsterCollectionResult r: - resultId = r.id; - break; - case CombinationConsumable5.ResultModel r: - resultId = r.id; - break; - case RapidCombination5.ResultModel r: - resultId = r.id; - break; - case SellCancellation.Result r: - resultId = r.id; - break; - case SellCancellation7.Result r: - resultId = r.id; - break; - case SellCancellation8.Result r: - resultId = r.id; - break; default: resultId = default(Guid); return false; @@ -206,56 +145,5 @@ public static bool TryGetMail( return false; } } - - [Obsolete("Use TryGetMail instead")] - public static bool TryGetMailV1( - this CombinationSlotState state, - long blockIndex, - long requiredBlockIndex, - out CombinationMail combinationMail, - out ItemEnhanceMail itemEnhanceMail) - { - combinationMail = null; - itemEnhanceMail = null; - - if (!state.TryGetResultIdV1(out var resultId)) - { - return false; - } - - switch (state.Result) - { - case ItemEnhancement13.ResultModel r: - itemEnhanceMail = new ItemEnhanceMail( - r, - blockIndex, - resultId, - requiredBlockIndex); - return true; - case ItemEnhancement7.ResultModel r: - itemEnhanceMail = new ItemEnhanceMail( - r, - blockIndex, - resultId, - requiredBlockIndex); - return true; - case ItemEnhancement11.ResultModel r: - itemEnhanceMail = new ItemEnhanceMail( - r, - blockIndex, - resultId, - requiredBlockIndex); - return true; - case CombinationConsumable5.ResultModel r: - combinationMail = new CombinationMail( - r, - blockIndex, - resultId, - requiredBlockIndex); - return true; - default: - return false; - } - } } }