protected override ITxSource CreateTxSourceForProducer(ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv, ReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource) { bool CheckAddPosdaoTransactions(IList <ITxSource> list, long auRaPosdaoTransition) { if (auRaPosdaoTransition < AuRaParameters.TransitionDisabled && _validator is ITxSource validatorSource) { list.Insert(0, validatorSource); return(true); } return(false); } bool CheckAddRandomnessTransactions(IList <ITxSource> list, IDictionary <long, Address> randomnessContractAddress, ISigner signer) { IList <IRandomContract> GetRandomContracts( IDictionary <long, Address> randomnessContractAddressPerBlock, IAbiEncoder abiEncoder, IReadOnlyTransactionProcessorSource txProcessorSource, ISigner signer) => randomnessContractAddressPerBlock .Select(kvp => new RandomContract( abiEncoder, kvp.Value, txProcessorSource, kvp.Key, signer)) .ToArray <IRandomContract>(); if (randomnessContractAddress?.Any() == true) { var randomContractTxSource = new RandomContractTxSource( GetRandomContracts(randomnessContractAddress, _context.AbiEncoder, readOnlyTransactionProcessorSource, signer), new EciesCipher(_context.CryptoRandom), _context.NodeKey, _context.CryptoRandom); list.Insert(0, randomContractTxSource); return(true); } return(false); } if (_context.ChainSpec == null) { throw new StepDependencyException(nameof(_context.ChainSpec)); } if (_context.BlockTree == null) { throw new StepDependencyException(nameof(_context.BlockTree)); } if (_context.Signer == null) { throw new StepDependencyException(nameof(_context.Signer)); } IList <ITxSource> txSources = new List <ITxSource> { base.CreateTxSourceForProducer(readOnlyTxProcessingEnv, readOnlyTransactionProcessorSource) }; bool needSigner = false; needSigner |= CheckAddPosdaoTransactions(txSources, _context.ChainSpec.AuRa.PosdaoTransition); needSigner |= CheckAddRandomnessTransactions(txSources, _context.ChainSpec.AuRa.RandomnessContractAddress, _context.Signer); ITxSource txSource = txSources.Count > 1 ? new CompositeTxSource(txSources.ToArray()) : txSources[0]; if (needSigner) { TxSealer transactionSealer = new TxSealer(_context.Signer, _context.Timestamper); txSource = new GeneratedTxSourceSealer(txSource, transactionSealer, readOnlyTxProcessingEnv.StateReader); } var txPermissionFilter = GetTxPermissionFilter(readOnlyTxProcessingEnv, readOnlyTransactionProcessorSource); if (txPermissionFilter != null) { txSource = new TxFilterTxSource(txSource, txPermissionFilter); } return(txSource); }
protected override ITxSource CreateTxSourceForProducer(ReadOnlyTxProcessingEnv processingEnv, IReadOnlyTxProcessorSource readOnlyTxProcessorSource) { bool CheckAddPosdaoTransactions(IList <ITxSource> list, long auRaPosdaoTransition) { if (auRaPosdaoTransition < AuRaParameters.TransitionDisabled && _validator is ITxSource validatorSource) { list.Insert(0, validatorSource); return(true); } return(false); } bool CheckAddRandomnessTransactions(IList <ITxSource> list, IDictionary <long, Address>?randomnessContractAddress, ISigner signer) { IList <IRandomContract> GetRandomContracts( IDictionary <long, Address> randomnessContractAddressPerBlock, IAbiEncoder abiEncoder, IReadOnlyTxProcessorSource txProcessorSource, ISigner signerLocal) => randomnessContractAddressPerBlock .Select(kvp => new RandomContract( abiEncoder, kvp.Value, txProcessorSource, kvp.Key, signerLocal)) .ToArray <IRandomContract>(); if (randomnessContractAddress?.Any() == true) { var randomContractTxSource = new RandomContractTxSource( GetRandomContracts(randomnessContractAddress, _api.AbiEncoder, readOnlyTxProcessorSource, signer), new EciesCipher(_api.CryptoRandom), signer, _api.NodeKey, _api.CryptoRandom, _api.LogManager); list.Insert(0, randomContractTxSource); return(true); } return(false); } if (_api.ChainSpec == null) { throw new StepDependencyException(nameof(_api.ChainSpec)); } if (_api.BlockTree == null) { throw new StepDependencyException(nameof(_api.BlockTree)); } if (_api.EngineSigner == null) { throw new StepDependencyException(nameof(_api.EngineSigner)); } IList <ITxSource> txSources = new List <ITxSource> { base.CreateTxSourceForProducer(processingEnv, readOnlyTxProcessorSource) }; bool needSigner = false; needSigner |= CheckAddPosdaoTransactions(txSources, _api.ChainSpec.AuRa.PosdaoTransition); needSigner |= CheckAddRandomnessTransactions(txSources, _api.ChainSpec.AuRa.RandomnessContractAddress, _api.EngineSigner); ITxSource txSource = txSources.Count > 1 ? new CompositeTxSource(txSources.ToArray()) : txSources[0]; if (needSigner) { TxSealer transactionSealer = new TxSealer(_api.EngineSigner, _api.Timestamper); txSource = new GeneratedTxSource(txSource, transactionSealer, processingEnv.StateReader, _api.LogManager); } if (_txPermissionFilter != null) { // we now only need to filter generated transactions here, as regular ones are filtered on TxPoolTxSource filter based on CreateTxSourceFilter method txSource = new FilteredTxSource <GeneratedTransaction>(txSource, _txPermissionFilter, _api.LogManager); } return(txSource); }
protected override ITxSource CreateTxSourceForProducer(ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv, ReadOnlyTransactionProcessorSource readOnlyTransactionProcessorSource) { IList <RandomContract> GetRandomContracts( IDictionary <long, Address> randomnessContractAddress, ITransactionProcessor transactionProcessor, IAbiEncoder abiEncoder, IReadOnlyTransactionProcessorSource txProcessorSource, Address nodeAddress) => randomnessContractAddress .Select(kvp => new RandomContract(transactionProcessor, abiEncoder, kvp.Value, txProcessorSource, kvp.Key, nodeAddress)) .ToArray(); if (_context.ChainSpec == null) { throw new StepDependencyException(nameof(_context.ChainSpec)); } if (_context.BlockTree == null) { throw new StepDependencyException(nameof(_context.BlockTree)); } if (_context.NodeKey == null) { throw new StepDependencyException(nameof(_context.NodeKey)); } IList <ITxSource> txSources = new List <ITxSource> { base.CreateTxSourceForProducer(readOnlyTxProcessingEnv, readOnlyTransactionProcessorSource) }; bool needSigner = false; if (_context.ChainSpec.AuRa.RandomnessContractAddress?.Any() == true) { var randomContractTxSource = new RandomContractTxSource( GetRandomContracts(_context.ChainSpec.AuRa.RandomnessContractAddress, readOnlyTxProcessingEnv.TransactionProcessor, _context.AbiEncoder, readOnlyTransactionProcessorSource, _context.NodeKey.Address), new EciesCipher(_context.CryptoRandom), _context.NodeKey, _context.CryptoRandom); txSources.Insert(0, randomContractTxSource); needSigner = true; } ITxSource txSource = txSources.Count > 1 ? new CompositeTxSource(txSources.ToArray()) : txSources[0]; if (needSigner) { txSource = new GeneratedTxSourceApprover(txSource, new BasicWallet(_context.NodeKey), _context.Timestamper, readOnlyTxProcessingEnv.StateReader, _context.BlockTree.ChainId); } var txPermissionFilter = GetTxPermissionFilter(readOnlyTxProcessingEnv, readOnlyTransactionProcessorSource); if (txPermissionFilter != null) { txSource = new TxFilterTxSource(txSource, txPermissionFilter); } return(txSource); }