Пример #1
0
        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));
        }
Пример #2
0
 public ConsensusReaderFactory(ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                               ISmartContractAddressService smartContractAddressService, IConsensusReaderContextService contextService)
 {
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
     _smartContractAddressService         = smartContractAddressService;
     _contextService = contextService;
 }
        internal static async Task <MethodDescriptor> GetContractMethodDescriptorAsync(
            IBlockchainService blockchainService,
            ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService, Address contractAddress,
            string methodName)
        {
            IEnumerable <FileDescriptor> fileDescriptors;

            _blockchainService = blockchainService;
            _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;

            try
            {
                fileDescriptors = await GetFileDescriptorsAsync(contractAddress);
            }
            catch
            {
                throw new UserFriendlyException(Error.Message[Error.InvalidContractAddress],
                                                Error.InvalidContractAddress.ToString());
            }

            foreach (var fileDescriptor in fileDescriptors)
            {
                var method = fileDescriptor.Services.Select(s => s.FindMethodByName(methodName)).FirstOrDefault();
                if (method == null)
                {
                    continue;
                }
                return(method);
            }

            return(null);
        }
Пример #4
0
 public AEDPoSReaderFactory(ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                            ISmartContractAddressService smartContractAddressService, IBlockTimeProvider blockTimeProvider)
 {
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
     _smartContractAddressService         = smartContractAddressService;
     _blockTimeProvider = blockTimeProvider;
 }
Пример #5
0
 public TokenContractMethodStubFactory(ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                                       ISmartContractAddressService smartContractAddressService, IChainContext chainContext)
 {
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
     _smartContractAddressService         = smartContractAddressService;
     _chainContext = chainContext;
 }
Пример #6
0
        public HostSmartContractBridgeContext(ISmartContractBridgeService smartContractBridgeService,
                                              ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService, IAccountService accountService,
                                              IOptionsSnapshot <HostSmartContractBridgeContextOptions> options,
                                              IOptionsSnapshot <ContractOptions> contractOptions)
        {
            _smartContractBridgeService          = smartContractBridgeService;
            _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
            _accountService  = accountService;
            _contractOptions = contractOptions.Value;

            Variables = new ContextVariableDictionary(options.Value.ContextVariables);

            var self = this;

            Address GetAddress() => self.Transaction.To;

            _lazyStateProvider = new Lazy <ICachedStateProvider>(
                () => new CachedStateProvider(
                    new ScopedStateProvider()
            {
                ContractAddress = GetAddress(),
                HostSmartContractBridgeContext = this
            }),
                LazyThreadSafetyMode.PublicationOnly);
        }
 public TransactionReadOnlyExecutionServiceTests()
 {
     _transactionReadOnlyExecutionService = GetRequiredService <ITransactionReadOnlyExecutionService>();
     _smartContractHelper             = GetRequiredService <SmartContractHelper>();
     _kernelTestHelper                = GetRequiredService <KernelTestHelper>();
     _defaultContractZeroCodeProvider = GetRequiredService <IDefaultContractZeroCodeProvider>();
     _smartContractExecutiveProvider  = GetRequiredService <ISmartContractExecutiveProvider>();
 }
Пример #8
0
 public MethodStubFactory(ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                          ISmartContractAddressService smartContractAddressService, IChainContext chainContext, Address sender)
 {
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
     _smartContractAddressService         = smartContractAddressService;
     _chainContext = chainContext;
     FromAddress   = sender ?? Address.FromBytes(new byte[] { }.ComputeHash());
 }
Пример #9
0
 public MethodStubFactory(ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                          ISmartContractAddressService smartContractAddressService, IChainContext chainContext, IBlockTimeProvider blockTimeProvider)
 {
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
     _smartContractAddressService         = smartContractAddressService;
     _chainContext      = chainContext;
     _blockTimeProvider = blockTimeProvider;
 }
Пример #10
0
        public TransactionAppService(ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                                     IBlockchainService blockchainService)
        {
            _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
            _blockchainService = blockchainService;

            LocalEventBus = NullLocalEventBus.Instance;
        }
Пример #11
0
 public SmartContractAddressUpdateService(
     IEnumerable <ISmartContractAddressNameProvider> smartContractAddressNameProviders,
     ISmartContractAddressService smartContractAddressService,
     ITransactionReadOnlyExecutionService transactionExecutingService)
 {
     _smartContractAddressNameProviders = smartContractAddressNameProviders;
     _smartContractAddressService       = smartContractAddressService;
     _transactionExecutingService       = transactionExecutingService;
 }
 public BlockTransactionLimitProvider(ISmartContractAddressService smartContractAddressService,
                                      ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                                      IBlockchainService blockchainService)
 {
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
     _blockchainService           = blockchainService;
     _smartContractAddressService = smartContractAddressService;
     Logger = NullLogger <BlockTransactionLimitProvider> .Instance;
 }
Пример #13
0
 public static async Task <T> ExecuteAsync <T>(
     this ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
     IChainContext chainContext, Transaction transaction,
     DateTime currentBlockTime) where T : class, IMessage <T>, new()
 {
     return(await ExecuteAsync <T>(transactionReadOnlyExecutionService, chainContext, transaction,
                                   currentBlockTime,
                                   true));
 }
Пример #14
0
 public UnitTestSmartContractAddressService(IDefaultContractZeroCodeProvider defaultContractZeroCodeProvider,
                                            ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                                            ISmartContractAddressProvider smartContractAddressProvider,
                                            IEnumerable <ISmartContractAddressNameProvider> smartContractAddressNameProviders,
                                            IBlockchainService blockchainService) : base(defaultContractZeroCodeProvider,
                                                                                         transactionReadOnlyExecutionService, smartContractAddressProvider, smartContractAddressNameProviders,
                                                                                         blockchainService)
 {
 }
Пример #15
0
 public MethodStubFactory(ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                          ISmartContractAddressService smartContractAddressService, IChainContext chainContext,
                          Timestamp currentBlockTime)
 {
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
     _smartContractAddressService         = smartContractAddressService;
     _chainContext    = chainContext;
     CurrentBlockTime = currentBlockTime;
 }
Пример #16
0
        public DPoSInformationGenerationServiceTests()
        {
            _minerKeyPair = CryptoHelpers.GenerateKeyPair();

            _accountService = GetRequiredService <IAccountService>();
            _consensusInformationGenerationService = GetRequiredService <IConsensusInformationGenerationService>();
            _smartContractAddressService           = GetRequiredService <ISmartContractAddressService>();
            _transactionReadOnlyExecutionService   = GetRequiredService <ITransactionReadOnlyExecutionService>();
        }
Пример #17
0
 public DeployedContractAddressService(ISmartContractAddressService smartContractAddressService,
                                       IBlockchainService blockchainService,
                                       ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                                       IDeployedContractAddressProvider deployedContractAddressProvider)
 {
     _smartContractAddressService         = smartContractAddressService;
     _blockchainService                   = blockchainService;
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
     _deployedContractAddressProvider     = deployedContractAddressProvider;
 }
Пример #18
0
        public async Task GlobalSetup()
        {
            _blockchainService = GetRequiredService <IBlockchainService>();
            _transactionReadOnlyExecutionService = GetRequiredService <ITransactionReadOnlyExecutionService>();
            _osTestHelper = GetRequiredService <OSTestHelper>();

            _contractAddress = await _osTestHelper.DeployContract <PerformanceTestContract.PerformanceTestContract>();

            _chain = await _blockchainService.GetChainAsync();
        }
Пример #19
0
 public TransactionResultAppService(ITransactionResultProxyService transactionResultProxyService,
                                    ITransactionManager transactionManager,
                                    IBlockchainService blockchainService,
                                    ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService)
 {
     _transactionResultProxyService       = transactionResultProxyService;
     _transactionManager                  = transactionManager;
     _blockchainService                   = blockchainService;
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
 }
Пример #20
0
        public MethodStubFactory(ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                                 ISmartContractAddressService smartContractAddressService, IChainContext chainContext,
                                 IConsensusReaderContextService contextService)
        {
            _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
            _smartContractAddressService         = smartContractAddressService;
            _chainContext   = chainContext;
            _contextService = contextService;

            FromAddress = AsyncHelper.RunSync(() => _contextService.GetAccountAsync());
        }
Пример #21
0
        public DPoSInformationGenerationService(IAccountService accountService,
                                                ConsensusControlInformation controlInformation, ISmartContractAddressService smartContractAddressService,
                                                ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService)
        {
            _accountService                      = accountService;
            _controlInformation                  = controlInformation;
            _smartContractAddressService         = smartContractAddressService;
            _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;

            Logger = NullLogger <DPoSInformationGenerationService> .Instance;
        }
Пример #22
0
 public SmartContractAddressService(IDefaultContractZeroCodeProvider defaultContractZeroCodeProvider,
                                    ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                                    ISmartContractAddressProvider smartContractAddressProvider,
                                    IEnumerable <ISmartContractAddressNameProvider> smartContractAddressNameProviders,
                                    IBlockchainService blockchainService)
 {
     _defaultContractZeroCodeProvider     = defaultContractZeroCodeProvider;
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
     _smartContractAddressProvider        = smartContractAddressProvider;
     _smartContractAddressNameProviders   = smartContractAddressNameProviders;
     _blockchainService = blockchainService;
 }
Пример #23
0
        public TransactionAppService(ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                                     IBlockchainService blockchainService, IObjectMapper <ChainApplicationWebAppAElfModule> objectMapper,
                                     ITransactionResultStatusCacheProvider transactionResultStatusCacheProvider)
        {
            _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
            _blockchainService = blockchainService;
            _objectMapper      = objectMapper;
            _transactionResultStatusCacheProvider = transactionResultStatusCacheProvider;

            LocalEventBus = NullLocalEventBus.Instance;
            Logger        = NullLogger <TransactionAppService> .Instance;
        }
        public TransactionResultAppService(ITransactionResultProxyService transactionResultProxyService,
                                           ITransactionManager transactionManager,
                                           IBlockchainService blockchainService,
                                           ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                                           IObjectMapper <ChainApplicationWebAppAElfModule> objectMapper,
                                           ITransactionResultStatusCacheProvider transactionResultStatusCacheProvider,
                                           IOptionsMonitor <WebAppOptions> optionsSnapshot)
        {
            _transactionResultProxyService       = transactionResultProxyService;
            _transactionManager                  = transactionManager;
            _blockchainService                   = blockchainService;
            _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
            _objectMapper = objectMapper;
            _transactionResultStatusCacheProvider = transactionResultStatusCacheProvider;
            _webAppOptions = optionsSnapshot.CurrentValue;

            Logger = NullLogger <TransactionResultAppService> .Instance;
        }
Пример #25
0
        public BlockChainAppService(IBlockchainService blockchainService,
                                    ISmartContractAddressService smartContractAddressService,
                                    ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                                    ITransactionManager transactionManager,
                                    ITransactionResultQueryService transactionResultQueryService,
                                    ITxHub txHub,
                                    IBlockchainStateManager blockchainStateManager
                                    )
        {
            _blockchainService                   = blockchainService;
            _smartContractAddressService         = smartContractAddressService;
            _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
            _transactionManager                  = transactionManager;
            _transactionResultQueryService       = transactionResultQueryService;
            _txHub = txHub;
            _blockchainStateManager = blockchainStateManager;

            Logger        = NullLogger <BlockChainAppService> .Instance;
            LocalEventBus = NullLocalEventBus.Instance;
        }
Пример #26
0
 public ParallelTestHelper(IOsBlockchainNodeContextService osBlockchainNodeContextService,
                           IAccountService accountService,
                           IMinerService minerService,
                           IBlockchainService blockchainService,
                           ITxHub txHub,
                           ISmartContractAddressService smartContractAddressService,
                           IBlockAttachService blockAttachService,
                           IStaticChainInformationProvider staticChainInformationProvider,
                           ITransactionResultService transactionResultService,
                           IOptionsSnapshot <ChainOptions> chainOptions,
                           ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService
                           ) : base(osBlockchainNodeContextService, accountService,
                                    minerService, blockchainService, txHub, smartContractAddressService, blockAttachService,
                                    staticChainInformationProvider, transactionResultService, chainOptions)
 {
     _accountService = accountService;
     _staticChainInformationProvider      = staticChainInformationProvider;
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
     _smartContractAddressService         = smartContractAddressService;
 }
        public static async Task <T> ExecuteAsync <T>(
            this ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
            IChainContext chainContext, Transaction transaction,
            Timestamp currentBlockTime, bool failedThrowException) where T : class, IMessage <T>, new()
        {
            var trace = await transactionReadOnlyExecutionService.ExecuteAsync(chainContext, transaction, currentBlockTime);

            if (trace.IsSuccessful())
            {
                var obj = new T();
                obj.MergeFrom(trace.ReturnValue);
                return(obj);
            }

            if (failedThrowException)
            {
                throw new SmartContractExecutingException(trace.Error);
            }

            return(default(T));
        }
Пример #28
0
 public ReaderFactory(ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService,
                      ISmartContractAddressService smartContractAddressService)
 {
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
     _smartContractAddressService         = smartContractAddressService;
 }
 public ContractFileDescriptorSetAppService(IBlockchainService blockchainService,
                                            ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService)
 {
     _blockchainService = blockchainService;
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
 }
Пример #30
0
 public ReadOnlyMethodStubFactory(ITransactionReadOnlyExecutionService transactionReadOnlyExecutionService)
 {
     _transactionReadOnlyExecutionService = transactionReadOnlyExecutionService;
 }