Skip to content

Commit

Permalink
Merge pull request #2427 from area363/remove-monster-collection-state
Browse files Browse the repository at this point in the history
remove monster collection
  • Loading branch information
area363 authored Mar 12, 2024
2 parents c989b58 + 89fe8b7 commit 672c823
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public async Task SubscribeBalanceByAgent(int major, int minor, string decimalSt
Currency currency = Currency.Legacy("NCG", 2, null);
#pragma warning restore CS0618
FungibleAssetValue fungibleAssetValue = new FungibleAssetValue(currency, major, minor);
StandaloneContextFx.AgentAddresses[address].balanceSubject.OnNext(fungibleAssetValue.GetQuantityString(true));
StandaloneContextFx.AgentAddresses[address].OnNext(fungibleAssetValue.GetQuantityString(true));
ExecutionResult rawEvents = await stream.Take(1);
var data = ((RootExecutionNode)rawEvents.Data.GetValue()).SubFields![0].Result!;
Assert.Equal(decimalString, data);
Expand Down
40 changes: 6 additions & 34 deletions NineChronicles.Headless/GraphTypes/StandaloneSubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,16 @@ private IObservable<string> SubscribeBalance(IResolveEventStreamContext context)
{
var address = context.GetArgument<Address>("address");

StandaloneContext.AgentAddresses.TryAdd(address,
(new ReplaySubject<MonsterCollectionStatus>(), new ReplaySubject<MonsterCollectionState>(),
new ReplaySubject<string>()));
StandaloneContext.AgentAddresses.TryAdd(address, new ReplaySubject<string>());
StandaloneContext.AgentAddresses.TryGetValue(address, out var subjects);

return Observable.Create<string>(observer =>
{
var subscription = subjects.balanceSubject.Subscribe(observer);
var subscription = subjects?.Subscribe(observer);
return Disposable.Create(() =>
{
subscription.Dispose();
subscription?.Dispose();
StandaloneContext.AgentAddresses.TryRemove(address, out _);
});
});
Expand Down Expand Up @@ -349,16 +347,14 @@ private void RenderBlock((Block OldTip, Block NewTip) pair)
.ForAll(kv =>
{
Address address = kv.Key;
(ReplaySubject<MonsterCollectionStatus> statusSubject, _, ReplaySubject<string> balanceSubject) =
ReplaySubject<string> balanceSubject =
kv.Value;
RenderForAgent(
blockChain,
_tipHeader,
address,
currency,
statusSubject,
balanceSubject,
rewardSheet
balanceSubject
);
});

Expand All @@ -371,34 +367,10 @@ private void RenderForAgent(
BlockHeader tipHeader,
Address address,
Currency currency,
ReplaySubject<MonsterCollectionStatus> statusSubject,
ReplaySubject<string> balanceSubject,
MonsterCollectionRewardSheet rewardSheet)
ReplaySubject<string> balanceSubject)
{
FungibleAssetValue agentBalance = blockChain.GetWorldState(tipHeader.Hash).GetBalance(address, currency);
balanceSubject.OnNext(agentBalance.GetQuantityString(true));
if (blockChain.GetWorldState(tipHeader.Hash).GetAgentState(address) is { } agentState)
{
Address deriveAddress =
MonsterCollectionState.DeriveAddress(address, agentState.MonsterCollectionRound);
if (agentState.avatarAddresses.Any() &&
blockChain.GetWorldState(tipHeader.Hash).GetLegacyState(deriveAddress) is Dictionary collectDict)
{
var monsterCollectionState = new MonsterCollectionState(collectDict);
List<MonsterCollectionRewardSheet.RewardInfo> rewards = monsterCollectionState.CalculateRewards(
rewardSheet,
tipHeader.Index
);

var monsterCollectionStatus = new MonsterCollectionStatus(
agentBalance,
rewards,
tipHeader.Index,
monsterCollectionState.IsLocked(tipHeader.Index)
);
statusSubject.OnNext(monsterCollectionStatus);
}
}
}
}
}
5 changes: 2 additions & 3 deletions NineChronicles.Headless/StandaloneContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ public class StandaloneContext
public NineChroniclesNodeService? NineChroniclesNodeService { get; set; }

public ConcurrentDictionary<Address,
(ReplaySubject<MonsterCollectionStatus> statusSubject, ReplaySubject<MonsterCollectionState> stateSubject, ReplaySubject<string> balanceSubject)>
ReplaySubject<string>>
AgentAddresses
{ get; } = new ConcurrentDictionary<Address,
(ReplaySubject<MonsterCollectionStatus>, ReplaySubject<MonsterCollectionState>, ReplaySubject<string>)>();
{ get; } = new ConcurrentDictionary<Address, ReplaySubject<string>>();

public NodeStatusType NodeStatus => new(this)
{
Expand Down

0 comments on commit 672c823

Please sign in to comment.