Skip to content

Commit

Permalink
Updated comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RyRy79261 committed Oct 25, 2023
1 parent 75d2f66 commit b50d502
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/ChainSafe.Gaming/MultiCall/IMultiCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@

namespace ChainSafe.Gaming.MultiCall
{
/// <summary>
/// Represents an interface for making batched Ethereum function calls using the MultiCall service.
/// </summary>
public interface IMultiCall : ILifecycleParticipant
{
/// <summary>
/// Executes a batch of Ethereum function calls using the MultiCall service asynchronously.
/// </summary>
/// <param name="multiCalls">An array of function calls to execute in a batch.</param>
/// <param name="pageSize">The maximum number of calls per batch request (default is 3000).</param>
/// <returns>A list of results from executing the batched calls.</returns>
public Task<List<Result>> MultiCallAsync(Call3Value[] multiCalls, int pageSize = 3000);
}
}
11 changes: 11 additions & 0 deletions src/ChainSafe.Gaming/MultiCall/IMultiCallConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@

namespace ChainSafe.Gaming.MultiCall
{
/// <summary>
/// Represents a configuration interface for the MultiCall service.
/// </summary>
public interface IMultiCallConfig
{
/// <summary>
/// Gets a dictionary of custom network addresses for the MultiCall service.
/// This allows specifying custom MultiCall contract addresses for specific Ethereum networks.
/// </summary>
/// <remarks>
/// The keys in the dictionary represent Ethereum network identifiers (e.g., chain IDs), and the values
/// represent the corresponding MultiCall contract addresses for those networks.
/// </remarks>
public IReadOnlyDictionary<string, string> CustomNetworks { get; }
}
}
27 changes: 24 additions & 3 deletions src/ChainSafe.Gaming/MultiCall/MultiCall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public class MultiCall : IMultiCall
private const string DefaultDeploymentAddress = "0xcA11bde05977b3631167028862bE2a173976CA11";
private readonly Contract multiCallContract;

/// <summary>
/// Initializes a new instance of the <see cref="MultiCall"/> class.
/// </summary>
/// <param name="builder">An implementation of the contract builder.</param>
/// <param name="chainConfig">The blockchain configuration for the associated chain.</param>
/// <param name="config">The configuration settings for MultiCall.</param>
public MultiCall(IContractBuilder builder, IChainConfig chainConfig, MultiCallConfig config)
{
if (chainConfig.ChainId != null && MultiCallDefaults.DeployedNetworks.Contains(chainConfig.ChainId))
Expand All @@ -34,6 +40,13 @@ public MultiCall(IContractBuilder builder, IChainConfig chainConfig, MultiCallCo
}
}

/// <summary>
/// Executes a batch of Ethereum function calls using the MultiCall contract asynchronously.
/// This utilizes MultiCall V3's implementation and dynamically checks whether to use value calls or not.
/// </summary>
/// <param name="multiCalls">An array of function calls to execute in a batch.</param>
/// <param name="pageSize">The maximum number of calls per batch request.</param>
/// <returns>A list of results from executing the batched calls.</returns>
public async Task<List<Result>> MultiCallAsync(Call3Value[] multiCalls, int pageSize = DefaultCallsPerRequest)
{
if (multiCalls.Any(x => x.Value > 0))
Expand Down Expand Up @@ -87,10 +100,10 @@ public async Task<List<Result>> MultiCallAsync(Call3Value[] multiCalls, int page
}

/// <summary>
/// A small function to extract the Result items into an array.
/// Extracts and formats the results of Multicall function calls into a list of <see cref="Result"/> objects.
/// </summary>
/// <param name="results">Returned response from calling the multicall function.</param>
/// <returns>A neater, formatted array of results.</returns>
/// <param name="results">The response from calling the Multicall function.</param>
/// <returns>A list of <see cref="Result"/> objects with success and return data information.</returns>
private List<Result> ExtractResults(IReadOnlyList<object[]> results)
{
var extracted = results[0][0] as List<List<ParameterOutput>>;
Expand All @@ -104,11 +117,19 @@ private List<Result> ExtractResults(IReadOnlyList<object[]> results)
return parsed;
}

/// <summary>
/// Asynchronously initializes the Multicall service. Does nothing in this implementation.
/// </summary>
/// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
public ValueTask WillStartAsync()
{
return default;
}

/// <summary>
/// Asynchronously cleans up and stops the Multicall service. Does nothing in this implementation.
/// </summary>
/// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
public ValueTask WillStopAsync() => new(Task.CompletedTask);
}
}

0 comments on commit b50d502

Please sign in to comment.