Skip to content

Commit

Permalink
Merge pull request #293 from planetarium/fix-battle-arena-handler
Browse files Browse the repository at this point in the history
bugfix: `ArgumentNullException` of `BattleArenaHandler`
  • Loading branch information
boscohyun authored Aug 23, 2024
2 parents a10702c + d02b1a8 commit 20cf1a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 26 deletions.
26 changes: 12 additions & 14 deletions Mimir.Worker/ActionHandler/BattleArenaHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,50 +61,48 @@ private async Task ProcessArena(
CancellationToken stoppingToken = default
)
{
var roundData = await StateGetter.GetArenaRoundData(blockIndex, stoppingToken);

var myArenaScore = await StateGetter.GetArenaScoreAsync(
battleArena.MyAvatarAddress,
roundData.ChampionshipId,
roundData.Round,
battleArena.ChampionshipId,
battleArena.Round,
stoppingToken
);
var myArenaInfo = await StateGetter.GetArenaInformationAsync(
battleArena.MyAvatarAddress,
roundData.ChampionshipId,
roundData.Round,
battleArena.ChampionshipId,
battleArena.Round,
stoppingToken
);
await ArenaCollectionUpdater.UpsertAsync(
Store,
myArenaScore,
myArenaInfo,
battleArena.MyAvatarAddress,
roundData.ChampionshipId,
roundData.Round,
battleArena.ChampionshipId,
battleArena.Round,
session,
stoppingToken
);

var enemyArenaScore = await StateGetter.GetArenaScoreAsync(
battleArena.EnemyAvatarAddress,
roundData.ChampionshipId,
roundData.Round,
battleArena.ChampionshipId,
battleArena.Round,
stoppingToken
);
var enemyArenaInfo = await StateGetter.GetArenaInformationAsync(
battleArena.EnemyAvatarAddress,
roundData.ChampionshipId,
roundData.Round,
battleArena.ChampionshipId,
battleArena.Round,
stoppingToken
);
await ArenaCollectionUpdater.UpsertAsync(
Store,
enemyArenaScore,
enemyArenaInfo,
battleArena.EnemyAvatarAddress,
roundData.ChampionshipId,
roundData.Round,
battleArena.ChampionshipId,
battleArena.Round,
session,
stoppingToken
);
Expand Down
6 changes: 3 additions & 3 deletions Mimir.Worker/Services/HeadlessStateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public class HeadlessStateService(IHeadlessGQLClient client) : IStateService
address,
stoppingToken
);

return Codec.Decode(Convert.FromHexString(result.State));
return result.State is null
? null
: Codec.Decode(Convert.FromHexString(result.State));
}

public async Task<long> GetLatestIndex(CancellationToken stoppingToken = default, Address? accountAddress = null)
{
var result = await client.GetTipAsync(stoppingToken, accountAddress);

return result.NodeStatus.Tip.Index;
}
}
9 changes: 0 additions & 9 deletions Mimir.Worker/Util/StateGetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,4 @@ public async Task<PetState> GetPetState(
) =>
await _service.GetState(avatarAddress, accountAddress, stoppingToken)
?? await _service.GetState(legacyAddress, stoppingToken);

public async Task<ArenaSheet.RoundData> GetArenaRoundData(
long index,
CancellationToken stoppingToken = default
)
{
var arenaSheet = await GetSheet<ArenaSheet>(stoppingToken);
return arenaSheet.GetRoundByBlockIndex(index);
}
}

0 comments on commit 20cf1a0

Please sign in to comment.