Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exp/state proxy #6644

Draft
wants to merge 4 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nekoyume/Assets/_Scripts/Blockchain/ActionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected GoldBalanceState GetGoldBalanceState<T>(ActionEvaluation<T> evaluation
}

var sheetStates = await agent.GetStateBulkAsync(
ReservedAddresses.LegacyAccount, sheetAddrArr);
agent.BlockTipStateRootHash, ReservedAddresses.LegacyAccount, sheetAddrArr);
var stakeRegularFixedRewardSheet = new StakeRegularFixedRewardSheet();
stakeRegularFixedRewardSheet.Set(
sheetStates[sheetAddrArr[0]].ToDotnetString());
Expand Down
1 change: 1 addition & 0 deletions nekoyume/Assets/_Scripts/Blockchain/RPCAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,7 @@ private AvatarState ResolveAvatarState(byte[] raw)

public async Task<Dictionary<Address, IValue>> GetStateBulkAsync(Address accountAddress, IEnumerable<Address> addressList)
{
throw new NotImplementedException();
var raw =
await _service.GetBulkStateByBlockHash(
BlockTipHash.ToByteArray(),
Expand Down
6 changes: 4 additions & 2 deletions nekoyume/Assets/_Scripts/Extensions/GetStateExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static class GetStateExtensions
ItemSlotState.DeriveAddress(avatarAddress, BattleType.Raid)
};
var itemBulk = await agent.GetStateBulkAsync(
agent.BlockTipStateRootHash,
ReservedAddresses.LegacyAccount,
itemAddresses);
var itemSlotStates = new List<ItemSlotState>();
Expand All @@ -47,6 +48,7 @@ public static class GetStateExtensions
RuneSlotState.DeriveAddress(avatarAddress, BattleType.Raid)
};
var runeBulk = await Game.Game.instance.Agent.GetStateBulkAsync(
Game.Game.instance.Agent.BlockTipStateRootHash,
ReservedAddresses.LegacyAccount,
runeAddresses);
var runeSlotStates = new List<RuneSlotState>();
Expand Down Expand Up @@ -78,7 +80,7 @@ public static async Task<AllCombinationSlotState> GetAllCombinationSlotStateAsyn
{
combinationSlotAddresses.Add(CombinationSlotState.DeriveAddress(avatarAddress, i));
}
var bulkStates = await agent.GetStateBulkAsync(ReservedAddresses.LegacyAccount, combinationSlotAddresses);
var bulkStates = await agent.GetStateBulkAsync(agent.BlockTipStateRootHash, ReservedAddresses.LegacyAccount, combinationSlotAddresses);
allCombinationSlotState = new AllCombinationSlotState();

for (var i = 0; i < AvatarState.DefaultCombinationSlotCount; i++)
Expand Down Expand Up @@ -142,7 +144,7 @@ public static async Task<AllRuneState> GetAllRuneStateAsync(
var runeAddresses = runeListSheet.Values.Select(row =>
RuneState.DeriveAddress(avatarAddress, row.Id));
var stateBulk = await Game.Game.instance.Agent.GetStateBulkAsync(
ReservedAddresses.LegacyAccount, runeAddresses);
Game.Game.instance.Agent.BlockTipStateRootHash, ReservedAddresses.LegacyAccount, runeAddresses);
foreach (var runeSerialized in stateBulk.Values.OfType<List>())
{
allRuneState.AddRuneState(new RuneState(runeSerialized));
Expand Down
17 changes: 9 additions & 8 deletions nekoyume/Assets/_Scripts/State/States.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class States
public FungibleAssetValue CrystalBalance { get; private set; }

public AllRuneState AllRuneState { get; private set; }

public AllCombinationSlotState AllCombinationSlotState { get; private set; }

public readonly ConcurrentDictionary<int, Dictionary<BattleType, RuneSlotState>>
Expand All @@ -86,12 +86,12 @@ public readonly ConcurrentDictionary<int, Dictionary<BattleType, ItemSlotState>>
private class Workshop
{
private readonly ConcurrentDictionary<int, CombinationSlotState> _states = new();

public void UpdateCombinationSlotState(int index, CombinationSlotState state)
{
_states[index] = state;
}

/// <summary>
/// If you want to update the state, use <see cref="UpdateCombinationSlotState"/>.
/// </summary>
Expand Down Expand Up @@ -216,7 +216,7 @@ public void SetAllRuneState(AllRuneState allRuneState)
{
AllRuneState = allRuneState;
}

private void SetAllCombinationSlotState(Address avatarAddress, AllCombinationSlotState allCombinationSlotState)
{
LocalLayer.Instance.InitializeCombinationSlots(allCombinationSlotState);
Expand Down Expand Up @@ -251,7 +251,7 @@ public async UniTask InitRuneSlotStates()
RuneSlotState.DeriveAddress(avatarState.address, BattleType.Arena),
RuneSlotState.DeriveAddress(avatarState.address, BattleType.Raid)
};
var stateBulk = await Game.Game.instance.Agent.GetStateBulkAsync(ReservedAddresses.LegacyAccount, addresses);
var stateBulk = await Game.Game.instance.Agent.GetStateBulkAsync(Game.Game.instance.Agent.BlockTipStateRootHash, ReservedAddresses.LegacyAccount, addresses);
foreach (var value in stateBulk.Values)
{
if (value is List list)
Expand Down Expand Up @@ -321,7 +321,7 @@ public async UniTask InitItemSlotStates()
ItemSlotState.DeriveAddress(avatarState.address, BattleType.Arena),
ItemSlotState.DeriveAddress(avatarState.address, BattleType.Raid)
};
var stateBulk = await agent.GetStateBulkAsync(ReservedAddresses.LegacyAccount, addresses);
var stateBulk = await agent.GetStateBulkAsync(agent.BlockTipStateRootHash, ReservedAddresses.LegacyAccount, addresses);
foreach (var value in stateBulk.Values)
{
if (value is List list)
Expand Down Expand Up @@ -359,7 +359,7 @@ private async UniTask InitItemSlotState(int slotIndex, AvatarState avatarState)
ItemSlotState.DeriveAddress(avatarState.address, BattleType.Raid)
};

var stateBulk = await Game.Game.instance.Agent.GetStateBulkAsync(ReservedAddresses.LegacyAccount, addresses);
var stateBulk = await Game.Game.instance.Agent.GetStateBulkAsync(Game.Game.instance.Agent.BlockTipStateRootHash, ReservedAddresses.LegacyAccount, addresses);
foreach (var value in stateBulk.Values)
{
if (value is List list)
Expand Down Expand Up @@ -726,7 +726,7 @@ public IDictionary<int, CombinationSlotState> GetCombinationSlotState(AvatarStat
{
return !_slotStates.ContainsKey(avatarState.address) ? null : _slotStates[avatarState.address].States;
}

public void SetGameConfigState(GameConfigState state)
{
GameConfigState = state;
Expand Down Expand Up @@ -782,6 +782,7 @@ public void UpdateHammerPointStates(IEnumerable<int> recipeIds)
.ToList();
var states =
await Game.Game.instance.Agent.GetStateBulkAsync(
Game.Game.instance.Agent.BlockTipStateRootHash,
ReservedAddresses.LegacyAccount,
hammerPointStateAddresses.Select(tuple => tuple.Item1));
var joinedStates = states.Join(
Expand Down
Loading