public static async Task <MethodDescriptor> GetContractMethodDescriptorAsync( this ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService, IChainContext chainContext, Address contractAddress, string methodName, bool throwException = true) { IEnumerable <FileDescriptor> fileDescriptors; try { fileDescriptors = await transactionReadOnlyExecutionService.GetFileDescriptorsAsync(chainContext, contractAddress); } catch { if (throwException) { throw new UserFriendlyException(Error.Message[Error.InvalidContractAddress], Error.InvalidContractAddress.ToString()); } return(null); } return(fileDescriptors .Select(fileDescriptor => fileDescriptor.Services.Select(s => s.FindMethodByName(methodName)).FirstOrDefault()) .FirstOrDefault(method => method != null)); }
private static async Task <IEnumerable <FileDescriptor> > GetFileDescriptorsAsync(Address address) { var chain = await _blockchainService.GetChainAsync(); var chainContext = new ChainContext() { BlockHash = chain.BestChainHash, BlockHeight = chain.BestChainHeight }; return(await _transactionReadOnlyExecutionService.GetFileDescriptorsAsync(chainContext, address)); }
public async Task GetFileDescriptorsAsync_Test() { var chain = await _smartContractHelper.CreateChainWithGenesisContractAsync(); var chainContext = new ChainContext { BlockHash = chain.BestChainHash, BlockHeight = chain.BestChainHeight }; _transactionReadOnlyExecutionService.GetFileDescriptorsAsync(chainContext, SampleAddress.AddressList[0]) .ShouldThrow <SmartContractFindRegistrationException>(); _smartContractExecutiveProvider.GetPool(_defaultContractZeroCodeProvider.ContractZeroAddress).Single() .ContractHash.ShouldBe(_defaultContractZeroCodeProvider.DefaultContractZeroRegistration.CodeHash); var fileDescriptors = await _transactionReadOnlyExecutionService.GetFileDescriptorsAsync(chainContext, _defaultContractZeroCodeProvider.ContractZeroAddress); fileDescriptors.Count().ShouldBeGreaterThan(0); _smartContractExecutiveProvider.GetPool(_defaultContractZeroCodeProvider.ContractZeroAddress).Single() .ContractHash.ShouldBe(_defaultContractZeroCodeProvider.DefaultContractZeroRegistration.CodeHash); }