Skip to content
Merged
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 PlatformSampleGameServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Enjin.Platform.Sdk" Version="3.0.3" />
<PackageReference Include="Enjin.Platform.Sdk" Version="3.0.4" />
</ItemGroup>
</Project>
34 changes: 32 additions & 2 deletions Services/EnjinService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ namespace PlatformSampleGameServer.Services;
//
// - There are no event subscriptions in v3. After submitting a transaction
// we poll GetTransaction until State is terminal
// (Finalized | Failed | Abandoned | Timeout).
// (Finalized | Failed | Abandoned | Timeout). Finalized alone does not mean
// success: a batch extrinsic still finalizes on-chain when wrapped items
// fail to dispatch, so we also require Error to be null.
//
// - The daemon wallet (configured DaemonWalletAddress) owns the collection
// and mints tokens to player wallets. Per-player melts and transfers are
Expand Down Expand Up @@ -625,7 +627,11 @@ CancellationToken ct
ct.ThrowIfCancellationRequested();

var query = new QueryQueryBuilder().WithGetTransaction(
new TransactionQueryBuilder().WithUuid().WithState(),
new TransactionQueryBuilder()
.WithUuid()
.WithState()
.WithError()
.WithFailedItemIndexes(),
_network,
_chain,
uuid: uuid
Expand All @@ -642,6 +648,17 @@ CancellationToken ct
switch (txn.State)
{
case TransactionStateEnum.Finalized:
// A non-null Error under Finalized means the extrinsic made it
// on-chain but one or more wrapped batch items did not dispatch,
// so the requested work did not fully happen.
if (!string.IsNullOrEmpty(txn.Error))
{
throw new InvalidOperationException(
$"Transaction {uuid} ({description}) finalized but reported an error: "
+ $"{txn.Error}{DescribeFailedItems(txn.FailedItemIndexes)}"
);
}

_log.LogInformation(
"Transaction {Uuid} ({Desc}) finalized after {Elapsed:F0}s.",
uuid,
Expand All @@ -655,6 +672,12 @@ CancellationToken ct
case TransactionStateEnum.Timeout:
throw new InvalidOperationException(
$"Transaction {uuid} ({description}) ended in terminal state {txn.State}."
+ (
string.IsNullOrEmpty(txn.Error)
? string.Empty
: $" Error: {txn.Error}"
)
+ DescribeFailedItems(txn.FailedItemIndexes)
);

default:
Expand Down Expand Up @@ -700,6 +723,13 @@ await Task.Delay(
// Helpers
// ------------------------------------------------------------------

// Zero-based positions of the batch items that failed to dispatch, when the
// platform reports them (CONTINUE_ON_ERROR batches only).
private static string DescribeFailedItems(ICollection<int>? failedItemIndexes) =>
failedItemIndexes is { Count: > 0 }
? $" Failed batch items: {string.Join(", ", failedItemIndexes)}."
: string.Empty;

private BigInteger RequireCollectionId() =>
_state.CollectionId
?? throw new InvalidOperationException(
Expand Down
Loading