Skip to content

Commit

Permalink
Merge pull request #2399 from planetarium/fix/action-bugs
Browse files Browse the repository at this point in the history
Fix bugs on actions
  • Loading branch information
OnedgeLee authored Feb 16, 2024
2 parents e1be741 + 0c4e72f commit 324e3cc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 33 deletions.
8 changes: 2 additions & 6 deletions Lib9c/Action/BuyProduct0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,8 @@ private IWorld Buy(IActionContext context, IProductInfo productInfo, Address sel
states = states
.SetLegacyState(productAddress, Null.Value)
.SetLegacyState(productsStateAddress, productsState.Serialize())
.SetLegacyState(sellerAvatarAddress, sellerAvatarState.SerializeV2())
.SetLegacyState(sellerAvatarAddress.Derive(LegacyQuestListKey), sellerAvatarState.questList.Serialize())
.SetLegacyState(ProductReceipt.DeriveAddress(productId), receipt.Serialize())
.SetAvatarState(sellerAvatarAddress, sellerAvatarState)
.TransferAsset(context, context.Signer, feeStoreAddress, tax)
.TransferAsset(context, context.Signer, sellerAgentAddress, taxedPrice);

Expand Down Expand Up @@ -323,10 +322,7 @@ private static IWorld Buy_Order(PurchaseInfo purchaseInfo, IActionContext contex
states = states
.SetLegacyState(digestListAddress, digestList.Serialize())
.SetLegacyState(orderReceiptAddress, orderReceipt.Serialize())
.SetLegacyState(sellerInventoryAddress, sellerAvatarState.inventory.Serialize())
.SetLegacyState(sellerWorldInformationAddress, sellerAvatarState.worldInformation.Serialize())
.SetLegacyState(sellerQuestListAddress, sellerAvatarState.questList.Serialize())
.SetLegacyState(sellerAvatarAddress, MigrationAvatarState.LegacySerializeV2(sellerAvatarState));
.SetAvatarState(sellerAvatarAddress, sellerAvatarState);
states = states.SetLegacyState(shardedShopAddress, shardedShopState.Serialize());
return states;
}
Expand Down
24 changes: 2 additions & 22 deletions Lib9c/Action/MigrationAvatarState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,8 @@ public override IWorld Execute(IActionContext context)

foreach (var rawAvatar in avatarStates)
{
var v1 = new AvatarState(rawAvatar);
var inventoryAddress = v1.address.Derive(LegacyInventoryKey);
var worldInformationAddress = v1.address.Derive(LegacyWorldInformationKey);
var questListAddress = v1.address.Derive(LegacyQuestListKey);
if (states.GetLegacyState(inventoryAddress) is null)
{
states = states.SetLegacyState(inventoryAddress, v1.inventory.Serialize());
}
if (states.GetLegacyState(worldInformationAddress) is null)
{
states = states.SetLegacyState(worldInformationAddress, v1.worldInformation.Serialize());
}
if (states.GetLegacyState(questListAddress) is null)
{
states = states.SetLegacyState(questListAddress, v1.questList.Serialize());
}

var v2 = states.GetAvatarState(v1.address);
if (v2.inventory is null || v2.worldInformation is null || v2.questList is null)
{
throw new FailedLoadStateException(v1.address.ToHex());
}
var avatarState = new AvatarState(rawAvatar);
states = states.SetAvatarState(avatarState.address, avatarState);
}

return states;
Expand Down
2 changes: 1 addition & 1 deletion Lib9c/Action/Sell6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public override IWorld Execute(IActionContext context)
result.id = mail.id;
avatarState.Update(mail);

states = states.SetLegacyState(sellerAvatarAddress, avatarState.Serialize());
states = states.SetAvatarState(sellerAvatarAddress, avatarState);
sw.Stop();
Log.Verbose("{AddressesHex}Sell Set AvatarState: {Elapsed}", addressesHex, sw.Elapsed);
sw.Restart();
Expand Down
2 changes: 1 addition & 1 deletion Lib9c/Action/UnlockEquipmentRecipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override IWorld Execute(IActionContext context)
if (states.TryGetAvatarState(context.Signer, AvatarAddress, out AvatarState avatarState))
{
worldInformation = avatarState.worldInformation;
states.SetAvatarState(AvatarAddress, avatarState);
states = states.SetAvatarState(AvatarAddress, avatarState);
}
else
{
Expand Down
7 changes: 4 additions & 3 deletions Lib9c/Action/UnlockWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public override IWorld Execute(IActionContext context)
}

WorldInformation worldInformation;
if (states.GetWorldInformation(AvatarAddress) is { } worldInfo)

try
{
worldInformation = worldInfo;
worldInformation = states.GetWorldInformation(AvatarAddress);
}
else
catch (FailedLoadStateException)
{
// AvatarState migration required.
if (states.TryGetAvatarState(context.Signer, AvatarAddress, out AvatarState avatarState))
Expand Down

0 comments on commit 324e3cc

Please sign in to comment.