From b50d502f6baff6484d4be2a22e3ad55b38cd163b Mon Sep 17 00:00:00 2001 From: Ryan Noble Date: Wed, 25 Oct 2023 12:58:45 +0200 Subject: [PATCH] Updated comments --- src/ChainSafe.Gaming/MultiCall/IMultiCall.cs | 9 +++++++ .../MultiCall/IMultiCallConfig.cs | 11 ++++++++ src/ChainSafe.Gaming/MultiCall/MultiCall.cs | 27 ++++++++++++++++--- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/ChainSafe.Gaming/MultiCall/IMultiCall.cs b/src/ChainSafe.Gaming/MultiCall/IMultiCall.cs index 11733be9d..cddce0c9d 100644 --- a/src/ChainSafe.Gaming/MultiCall/IMultiCall.cs +++ b/src/ChainSafe.Gaming/MultiCall/IMultiCall.cs @@ -5,8 +5,17 @@ namespace ChainSafe.Gaming.MultiCall { + /// + /// Represents an interface for making batched Ethereum function calls using the MultiCall service. + /// public interface IMultiCall : ILifecycleParticipant { + /// + /// Executes a batch of Ethereum function calls using the MultiCall service asynchronously. + /// + /// An array of function calls to execute in a batch. + /// The maximum number of calls per batch request (default is 3000). + /// A list of results from executing the batched calls. public Task> MultiCallAsync(Call3Value[] multiCalls, int pageSize = 3000); } } \ No newline at end of file diff --git a/src/ChainSafe.Gaming/MultiCall/IMultiCallConfig.cs b/src/ChainSafe.Gaming/MultiCall/IMultiCallConfig.cs index b88ec504f..761a618d8 100644 --- a/src/ChainSafe.Gaming/MultiCall/IMultiCallConfig.cs +++ b/src/ChainSafe.Gaming/MultiCall/IMultiCallConfig.cs @@ -2,8 +2,19 @@ namespace ChainSafe.Gaming.MultiCall { + /// + /// Represents a configuration interface for the MultiCall service. + /// public interface IMultiCallConfig { + /// + /// Gets a dictionary of custom network addresses for the MultiCall service. + /// This allows specifying custom MultiCall contract addresses for specific Ethereum networks. + /// + /// + /// 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. + /// public IReadOnlyDictionary CustomNetworks { get; } } } \ No newline at end of file diff --git a/src/ChainSafe.Gaming/MultiCall/MultiCall.cs b/src/ChainSafe.Gaming/MultiCall/MultiCall.cs index d098e999e..a9ea6a141 100644 --- a/src/ChainSafe.Gaming/MultiCall/MultiCall.cs +++ b/src/ChainSafe.Gaming/MultiCall/MultiCall.cs @@ -19,6 +19,12 @@ public class MultiCall : IMultiCall private const string DefaultDeploymentAddress = "0xcA11bde05977b3631167028862bE2a173976CA11"; private readonly Contract multiCallContract; + /// + /// Initializes a new instance of the class. + /// + /// An implementation of the contract builder. + /// The blockchain configuration for the associated chain. + /// The configuration settings for MultiCall. public MultiCall(IContractBuilder builder, IChainConfig chainConfig, MultiCallConfig config) { if (chainConfig.ChainId != null && MultiCallDefaults.DeployedNetworks.Contains(chainConfig.ChainId)) @@ -34,6 +40,13 @@ public MultiCall(IContractBuilder builder, IChainConfig chainConfig, MultiCallCo } } + /// + /// 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. + /// + /// An array of function calls to execute in a batch. + /// The maximum number of calls per batch request. + /// A list of results from executing the batched calls. public async Task> MultiCallAsync(Call3Value[] multiCalls, int pageSize = DefaultCallsPerRequest) { if (multiCalls.Any(x => x.Value > 0)) @@ -87,10 +100,10 @@ public async Task> MultiCallAsync(Call3Value[] multiCalls, int page } /// - /// A small function to extract the Result items into an array. + /// Extracts and formats the results of Multicall function calls into a list of objects. /// - /// Returned response from calling the multicall function. - /// A neater, formatted array of results. + /// The response from calling the Multicall function. + /// A list of objects with success and return data information. private List ExtractResults(IReadOnlyList results) { var extracted = results[0][0] as List>; @@ -104,11 +117,19 @@ private List ExtractResults(IReadOnlyList results) return parsed; } + /// + /// Asynchronously initializes the Multicall service. Does nothing in this implementation. + /// + /// A representing the asynchronous operation. public ValueTask WillStartAsync() { return default; } + /// + /// Asynchronously cleans up and stops the Multicall service. Does nothing in this implementation. + /// + /// A representing the asynchronous operation. public ValueTask WillStopAsync() => new(Task.CompletedTask); } } \ No newline at end of file