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

EnsureOrdered = true #23

Merged
merged 2 commits into from
May 29, 2024
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
19 changes: 8 additions & 11 deletions Circles.Index.Query.Tests/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,18 @@ public IDbDataParameter CreateParameter(string? name, object? value)
}
}

public class TestDbDataParameter : IDbDataParameter
public class TestDbDataParameter(string? name, object? value) : IDbDataParameter
{
public TestDbDataParameter(string? name, object? value)
{
ParameterName = name;
Value = value;
}

public DbType DbType { get; set; }
public ParameterDirection Direction { get; set; }
public bool IsNullable { get; }
public string ParameterName { get; set; }
public string SourceColumn { get; set; }
public bool IsNullable => false;

#pragma warning disable CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes).
public string ParameterName { get; set; } = name ?? "";
public string SourceColumn { get; set; } = "";
#pragma warning restore CS8767 // Nullability of reference types in type of parameter doesn't match implicitly implemented member (possibly because of nullability attributes).
public DataRowVersion SourceVersion { get; set; }
public object? Value { get; set; }
public object? Value { get; set; } = value;
public byte Precision { get; set; }
public byte Scale { get; set; }
public int Size { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions Circles.Index.Query/Dto/FilterPredicateDtoConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override IFilterPredicateDto[] Read(ref Utf8JsonReader reader, Type typeT
_ => throw new NotSupportedException($"Unknown filter predicate type: {type}")
};

predicates[i++] = result;
predicates[i++] = result ?? throw new JsonException("Failed to deserialize filter predicate.");
}

return predicates;
Expand All @@ -77,7 +77,7 @@ public override object Read(ref Utf8JsonReader reader, Type typeToConvert, JsonS
switch (reader.TokenType)
{
case JsonTokenType.String:
return reader.GetString();
return reader.GetString() ?? throw new JsonException("Unexpected null string value.");
case JsonTokenType.Number:
if (reader.TryGetInt32(out int intValue))
{
Expand Down
22 changes: 11 additions & 11 deletions Circles.Index.Rpc/CirclesRpcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public Task<ResultWrapper<CirclesTrustRelations>> circles_getTrustRelations(Addr

foreach (var resultRow in result.Rows)
{
var user = new Address(resultRow[0].ToString() ?? throw new Exception("A user in the result set is null"));
var canSendTo = new Address(resultRow[1].ToString() ??
var user = new Address(resultRow[0]?.ToString() ?? throw new Exception("A user in the result set is null"));
var canSendTo = new Address(resultRow[1]?.ToString() ??
throw new Exception("A canSendTo in the result set is null"));
var limit = int.Parse(resultRow[2].ToString() ?? throw new Exception("A limit in the result set is null"));
var limit = int.Parse(resultRow[2]?.ToString() ?? throw new Exception("A limit in the result set is null"));

if (user == address)
{
Expand Down Expand Up @@ -112,7 +112,7 @@ public Task<ResultWrapper<string>> circlesV2_getTotalBalance(Address address, bo

private string TotalBalanceV2(IEthRpcModule rpcModule, Address address, bool asTimeCircles)
{
IEnumerable<UInt256> tokenIds = V2TokenIdsForAccount(_pluginLogger, address);
IEnumerable<UInt256> tokenIds = V2TokenIdsForAccount(address);

// Call the erc1155's balanceOf function for each token using _ethRpcModule.eth_call().
// Solidity function signature: balanceOf(address _account, uint256 _id) public view returns (uint256)
Expand Down Expand Up @@ -156,7 +156,7 @@ public async Task<ResultWrapper<CirclesTokenBalanceV2[]>> circlesV2_getTokenBala
await rentedEthRpcModule.Rent();

var balances =
V2CirclesTokenBalances(_pluginLogger, rentedEthRpcModule.RpcModule!, address,
V2CirclesTokenBalances(rentedEthRpcModule.RpcModule!, address,
_indexerContext.Settings.CirclesV2HubAddress, asTimeCircles);

return ResultWrapper<CirclesTokenBalanceV2[]>.Success(balances.ToArray());
Expand Down Expand Up @@ -203,7 +203,7 @@ private IEnumerable<Address> TokenAddressesForAccount(Address circlesAccount)
return _indexerContext.Database
.Select(sql)
.Rows
.Select(o => new Address(o[0].ToString()
.Select(o => new Address(o[0]?.ToString()
?? throw new Exception("A token address in the result set is null"))
);
}
Expand All @@ -230,8 +230,8 @@ private IDictionary<string, string> GetTokenOwners(string[] tokenAddresses)
var tokenOwners = new Dictionary<string, string>();
foreach (var row in result.Rows)
{
var avatar = row[0].ToString() ?? throw new Exception("An avatar in the result set is null");
var tokenId = row[1].ToString() ?? throw new Exception("A tokenId in the result set is null");
var avatar = row[0]?.ToString() ?? throw new Exception("An avatar in the result set is null");
var tokenId = row[1]?.ToString() ?? throw new Exception("A tokenId in the result set is null");
tokenOwners[tokenId] = avatar;
}

Expand Down Expand Up @@ -302,10 +302,10 @@ private static string FormatTimeCircles(UInt256 tokenBalance)
: ether.ToString(CultureInfo.InvariantCulture);
}

private List<CirclesTokenBalanceV2> V2CirclesTokenBalances(ILogger logger, IEthRpcModule rpcModule, Address address,
private List<CirclesTokenBalanceV2> V2CirclesTokenBalances(IEthRpcModule rpcModule, Address address,
Address hubAddress, bool asTimeCircles)
{
IEnumerable<UInt256> tokenIds = V2TokenIdsForAccount(logger, address);
IEnumerable<UInt256> tokenIds = V2TokenIdsForAccount(address);

// Call the erc1155's balanceOf function for each token using _ethRpcModule.eth_call().
// Solidity function signature: balanceOf(address _account, uint256 _id) public view returns (uint256)
Expand Down Expand Up @@ -350,7 +350,7 @@ private List<CirclesTokenBalanceV2> V2CirclesTokenBalances(ILogger logger, IEthR
return balances;
}

private IEnumerable<UInt256> V2TokenIdsForAccount(ILogger logger, Address address)
private IEnumerable<UInt256> V2TokenIdsForAccount(Address address)
{
var select = new Select(
"V_CrcV2"
Expand Down
2 changes: 1 addition & 1 deletion Circles.Index/BlockIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CancellationToken cancellationToken
new()
{
MaxDegreeOfParallelism = parallelism > -1 ? parallelism : Environment.ProcessorCount,
EnsureOrdered = false,
EnsureOrdered = true,
CancellationToken = cancellationToken,
BoundedCapacity = boundedCapacity
};
Expand Down
Loading