using System; using Nethereum.ABI.FunctionEncoding.Attributes; using Nethereum.Contracts.ContractHandlers; using Nethereum.Contracts.CQS; using Nethereum.Contracts.QueryHandlers.MultiCall; using Nethereum.JsonRpc.Client; using Nethereum.RPC; using Nethereum.RPC.Eth.Transactions; using Nethereum.RPC.TransactionManagers; namespace Nethereum.Contracts.Services { public class EthApiContractService : EthApiService, IEthApiContractService { public EthApiContractService(IClient client) : base(client) { #if !DOTNET35 GetContractTransactionErrorReason = new EthGetContractTransactionErrorReason(Transactions); #endif } public EthApiContractService(IClient client, ITransactionManager transactionManager) : base(client, transactionManager) { #if !DOTNET35 GetContractTransactionErrorReason = new EthGetContractTransactionErrorReason(Transactions); #endif } public IDeployContract DeployContract => new DeployContract(TransactionManager); public Contract GetContract(string abi, string contractAddress) { return new Contract(this, abi, contractAddress); } public Contract GetContract(string contractAddress) { return new Contract(this, typeof(TContractMessage), contractAddress); } public Event GetEvent() where TEventType : IEventDTO, new() { if (!EventAttribute.IsEventType(typeof(TEventType))) throw new ArgumentException("The type given is not a valid Event"); ; return new Event(Client); } public Event GetEvent(string contractAddress) where TEventType : IEventDTO, new() { if (!EventAttribute.IsEventType(typeof(TEventType))) throw new ArgumentException("The type given is not a valid Event"); return new Event(Client, contractAddress); } #if !DOTNET35 public ContractHandler GetContractHandler(string contractAddress) { string address = null; if (TransactionManager != null) if (TransactionManager.Account != null) address = TransactionManager.Account.Address; return new ContractHandler(contractAddress, this, address); } public IContractDeploymentTransactionHandler GetContractDeploymentHandler< TContractDeploymentMessage>() where TContractDeploymentMessage : ContractDeploymentMessage, new() { return new ContractDeploymentTransactionHandler(this.TransactionManager); } public IContractTransactionHandler GetContractTransactionHandler< TContractFunctionMessage>() where TContractFunctionMessage : FunctionMessage, new() { return new ContractTransactionHandler(this.TransactionManager); } /// /// Multicall using the contract https://github.com/makerdao/multicall/blob/master/src/Multicall.sol /// /// The contracts address of the deployed contract /// public MultiQueryHandler GetMultiQueryHandler(string multiContractAdress = "0xeefBa1e63905eF1D7ACbA5a8513c70307C1cE441") { return new MultiQueryHandler(Client, multiContractAdress, TransactionManager?.Account?.Address, DefaultBlock); } public IEthGetContractTransactionErrorReason GetContractTransactionErrorReason { get; } public IContractQueryHandler GetContractQueryHandler() where TContractFunctionMessage : FunctionMessage, new() { return new ContractQueryEthCallHandler(Transactions.Call, TransactionManager?.Account?.Address, DefaultBlock); } #endif } }