Skip to content

Commit

Permalink
Extract GetFeeAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Dec 31, 2024
1 parent 1b5b3c7 commit 286c30d
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 193 deletions.
10 changes: 1 addition & 9 deletions Lib9c/Action/AuraSummon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,7 @@ public override IWorld Execute(IActionContext context)
// Transfer Cost NCG first for fast-fail
if (summonRow.CostNcg > 0L)
{
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(
context,
Expand Down
8 changes: 1 addition & 7 deletions Lib9c/Action/BattleArena.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,7 @@ public override IWorld Execute(IActionContext context)

purchasedCountDuringInterval++;

var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
feeAddress = ArenaHelper.DeriveArenaAddress(roundData.ChampionshipId, roundData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states
.TransferAsset(context, context.Signer, feeAddress, ticketBalance)
Expand Down
11 changes: 2 additions & 9 deletions Lib9c/Action/Buy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Libplanet.Types.Assets;
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Arena;
using Nekoyume.Extensions;
using Nekoyume.Model.EnumType;
using Nekoyume.Model.Mail;
using Nekoyume.Model.State;
Expand Down Expand Up @@ -251,15 +252,7 @@ public override IWorld Execute(IActionContext context)
var taxedPrice = order.Price - tax;

// Transfer tax.
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states
.TransferAsset(context, context.Signer, feeAddress, tax);
Expand Down
21 changes: 3 additions & 18 deletions Lib9c/Action/BuyProduct.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Nekoyume.Action.Guild.Migration.LegacyModels;
using Nekoyume.Arena;
using Nekoyume.Battle;
using Nekoyume.Extensions;
using Nekoyume.Model.EnumType;
using Nekoyume.Model.Item;
using Nekoyume.Model.Mail;
Expand Down Expand Up @@ -176,15 +177,7 @@ private IWorld Buy(IActionContext context, IProductInfo productInfo, Address sel
var receipt = new ProductReceipt(productId, sellerAvatarAddress, buyerAvatarState.address, product.Price,
context.BlockIndex);

var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states
.RemoveLegacyState(productAddress)
Expand Down Expand Up @@ -308,15 +301,7 @@ private static IWorld Buy_Order(PurchaseInfo purchaseInfo, IActionContext contex
var taxedPrice = order.Price - tax;

// Transfer tax.
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(
context,
Expand Down
11 changes: 1 addition & 10 deletions Lib9c/Action/CombinationEquipment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,7 @@ public override IWorld Execute(IActionContext context)
if (costNcg > 0L)
{
// Transfer tax.
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}

var feeAddress = states.GetFeeAddress(context.BlockIndex);
states = states.TransferAsset(
context,
context.Signer,
Expand Down
10 changes: 1 addition & 9 deletions Lib9c/Action/CostumeSummon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,7 @@ public override IWorld Execute(IActionContext context)
// Transfer Cost NCG first for fast-fail
if (summonRow.CostNcg > 0L)
{
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(
context,
Expand Down
10 changes: 1 addition & 9 deletions Lib9c/Action/CustomEquipmentCraft/CustomEquipmentCraft.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,7 @@ public override IWorld Execute(IActionContext context)

if (ncgCost > 0)
{
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);
states = states.TransferAsset(context, context.Signer, feeAddress, ncgCost * states.GetGoldCurrency());
}

Expand Down
10 changes: 1 addition & 9 deletions Lib9c/Action/ItemEnhancement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,7 @@ public override IWorld Execute(IActionContext context)
var requiredNcg = targetCostRow.Cost - startCostRow.Cost;
if (requiredNcg > 0)
{
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(ctx, ctx.Signer, feeAddress,
states.GetGoldCurrency() * requiredNcg);
Expand Down
10 changes: 1 addition & 9 deletions Lib9c/Action/ItemEnhancement11.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,7 @@ public override IWorld Execute(IActionContext context)
var requiredNcg = row.Cost;
if (requiredNcg > 0)
{
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(ctx, ctx.Signer, feeAddress, states.GetGoldCurrency() * requiredNcg);
}
Expand Down
10 changes: 1 addition & 9 deletions Lib9c/Action/ItemEnhancement12.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,7 @@ public override IWorld Execute(IActionContext context)
var requiredNcg = targetCostRow.Cost - startCostRow.Cost;
if (requiredNcg > 0)
{
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(ctx, ctx.Signer, feeAddress,
states.GetGoldCurrency() * requiredNcg);
Expand Down
10 changes: 1 addition & 9 deletions Lib9c/Action/ItemEnhancement13.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,7 @@ public override IWorld Execute(IActionContext context)
var requiredNcg = targetCostRow.Cost - startCostRow.Cost;
if (requiredNcg > 0)
{
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(ctx, ctx.Signer, feeAddress,
states.GetGoldCurrency() * requiredNcg);
Expand Down
10 changes: 2 additions & 8 deletions Lib9c/Action/JoinArena.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public override IWorld Execute(IActionContext context)
$"[{nameof(JoinArena)}] Aborted as the avatar state of the signer was failed to load.");
}

// check the avatar already joined the arena.
// check the avatar already joined the arena.
if (states.GetArenaParticipant(championshipId, round, avatarAddress) is not null)
{
throw new AlreadyJoinedArenaException(championshipId, round, avatarAddress);
Expand Down Expand Up @@ -174,13 +174,7 @@ public override IWorld Execute(IActionContext context)
$"required {fee}, but balance is {crystalBalance}");
}

var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
feeAddress = ArenaHelper.DeriveArenaAddress(roundData.ChampionshipId, roundData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(context, context.Signer, feeAddress, fee);
}
Expand Down
8 changes: 1 addition & 7 deletions Lib9c/Action/JoinArena1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,7 @@ public override IWorld Execute(IActionContext context)
$"required {fee}, but balance is {crystalBalance}");
}

var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
feeAddress = ArenaHelper.DeriveArenaAddress(roundData.ChampionshipId, roundData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(context, context.Signer, feeAddress, fee);
}
Expand Down
8 changes: 1 addition & 7 deletions Lib9c/Action/JoinArena3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,7 @@ public override IWorld Execute(IActionContext context)
$"required {fee}, but balance is {crystalBalance}");
}

var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
feeAddress = ArenaHelper.DeriveArenaAddress(roundData.ChampionshipId, roundData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(context, context.Signer, feeAddress, fee);
}
Expand Down
10 changes: 1 addition & 9 deletions Lib9c/Action/PetEnhancement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,7 @@ public override IWorld Execute(IActionContext context)
currentNcg);
}

var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(context, context.Signer, feeAddress, ncgCost);
}
Expand Down
10 changes: 1 addition & 9 deletions Lib9c/Action/Raid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,7 @@ public override IWorld Execute(IActionContext context)
}
var goldCurrency = states.GetGoldCurrency();

var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(context, context.Signer, feeAddress,
WorldBossHelper.CalculateTicketPrice(row, raiderState, goldCurrency));
Expand Down
10 changes: 1 addition & 9 deletions Lib9c/Action/RuneEnhancement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,7 @@ public override IWorld Execute(IActionContext context)
runeState.LevelUp(levelUpResult.LevelUpCount);
states = states.SetRuneState(AvatarAddress, allRuneState);

var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

// Burn costs
if (levelUpResult.NcgCost > 0)
Expand Down
10 changes: 1 addition & 9 deletions Lib9c/Action/RuneSummon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,7 @@ public override IWorld Execute(IActionContext context)
// Transfer Cost NCG first for fast-fail
if (summonRow.CostNcg > 0L)
{
var feeAddress = Addresses.RewardPool;
// TODO: [GuildMigration] Remove this after migration
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& context.BlockIndex < migrationHeight)
{
var arenaSheet = states.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(context.BlockIndex);
feeAddress = ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
var feeAddress = states.GetFeeAddress(context.BlockIndex);

states = states.TransferAsset(
context,
Expand Down
20 changes: 1 addition & 19 deletions Lib9c/Action/UnlockCombinationSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public override IWorld Execute(IActionContext context)
throw new SlotAlreadyUnlockedException($"[{nameof(UnlockRuneSlot)}] Index : {SlotIndex}");
}

var feeStoreAddress = GetFeeStoreAddress(states, context.BlockIndex);
var feeStoreAddress = states.GetFeeAddress(context.BlockIndex);
var costSheet = sheets.GetSheet<UnlockCombinationSlotCostSheet>();

if (!costSheet.ContainsKey(SlotIndex))
Expand Down Expand Up @@ -175,23 +175,5 @@ public override IWorld Execute(IActionContext context)
allSlotState.UnlockSlot(AvatarAddress, SlotIndex);
return states.SetCombinationSlotState(AvatarAddress, allSlotState);
}

private Address GetFeeStoreAddress(IWorld states, long blockIndex)
{
if (states.GetDelegationMigrationHeight() is long migrationHeight
&& blockIndex < migrationHeight)
{
var sheets = states.GetSheets(
sheetTypes: new[]
{
typeof(ArenaSheet),
});

var arenaSheet = sheets.GetSheet<ArenaSheet>();
var arenaData = arenaSheet.GetRoundByBlockIndex(blockIndex);
return ArenaHelper.DeriveArenaAddress(arenaData.ChampionshipId, arenaData.Round);
}
return Addresses.RewardPool;
}
}
}
Loading

0 comments on commit 286c30d

Please sign in to comment.