private bool IsSystemTransaction(Transaction transaction) { var systemTransactionMethodNameList = _coreTransactionMethodNameListProvider.GetSystemTransactionMethodNameList(); var consensusContractAddress = _smartContractAddressService.GetAddressByContractName( SmartContractConstants.ConsensusContractSystemName); if (transaction.To == consensusContractAddress && systemTransactionMethodNameList.Contains(transaction.MethodName)) { return(true); } var tokenContractAddress = _smartContractAddressService.GetAddressByContractName(SmartContractConstants.TokenContractSystemName); if (transaction.To == tokenContractAddress && systemTransactionMethodNameList.Contains(transaction.MethodName)) { return(true); } var crossChainContractAddress = _smartContractAddressService.GetAddressByContractName(SmartContractConstants .CrossChainContractSystemName); if (transaction.To == crossChainContractAddress && systemTransactionMethodNameList.Contains(transaction.MethodName)) { return(true); } return(false); }
public Task <bool> ValidateTransactionAsync(Transaction transaction) { var economicContractAddress = _smartContractAddressService.GetAddressByContractName(EconomicSmartContractAddressNameProvider.Name); if (transaction.To == economicContractAddress) { return(Task.FromResult(false)); } var consensusContractAddress = _smartContractAddressService.GetAddressByContractName(ConsensusSmartContractAddressNameProvider.Name); if (transaction.To != consensusContractAddress) { return(Task.FromResult(true)); } var systemTxs = new List <string> { nameof(AEDPoSContractContainer.AEDPoSContractStub.InitialAElfConsensusContract), nameof(AEDPoSContractContainer.AEDPoSContractStub.FirstRound), nameof(AEDPoSContractContainer.AEDPoSContractStub.UpdateValue), nameof(AEDPoSContractContainer.AEDPoSContractStub.UpdateTinyBlockInformation), nameof(AEDPoSContractContainer.AEDPoSContractStub.NextRound), nameof(AEDPoSContractContainer.AEDPoSContractStub.NextTerm), nameof(AEDPoSContractContainer.AEDPoSContractStub.UpdateConsensusInformation), }; return(Task.FromResult(!systemTxs.Contains(transaction.MethodName))); }
private Bloom GetSideChainBlockDataIndexedEventBloom() { var contractAddress = _smartContractAddressService.GetAddressByContractName(CrossChainSmartContractAddressNameProvider.Name); var logEvent = new SideChainBlockDataIndexed().ToLogEvent(contractAddress); return(logEvent.GetBloom()); }
public List <Transaction> GenerateTransferFromTransactionsWithoutConflictWithMultiSender(List <ECKeyPair> keyPairs, int count = 1) { var transactions = new List <Transaction>(); foreach (var keyPair in keyPairs) { var from = Address.FromPublicKey(keyPair.PublicKey); for (var i = 0; i < count; i++) { var to = CryptoHelper.GenerateKeyPair(); var transaction = GenerateTransaction(from, _smartContractAddressService.GetAddressByContractName( TokenSmartContractAddressNameProvider.Name), nameof(TokenContractContainer.TokenContractStub.TransferFrom), new TransferFromInput { From = from, To = Address.FromPublicKey(to.PublicKey), Amount = 1, Symbol = "ELF" }); var signature = CryptoHelper.SignWithPrivateKey(keyPair.PrivateKey, transaction.GetHash().ToByteArray()); transaction.Signature = ByteString.CopyFrom(signature); transactions.Add(transaction); } } return(transactions); }
public async Task Validate_EconomicAddress_Test() { var tx = _kernelTestHelper.GenerateTransaction(); var economicAddress = _smartContractAddressService.GetAddressByContractName(EconomicSmartContractAddressNameProvider.Name); tx.To = economicAddress; var result = await _validationProvider.ValidateTransactionAsync(tx); result.ShouldBeFalse(); }
public bool Validate(Transaction transaction) { var tokenContractAddress = _smartContractAddressService.GetAddressByContractName(TokenSmartContractAddressNameProvider.Name); if (transaction.To != tokenContractAddress || transaction.MethodName != "TransferFrom") { return(true); } return(transaction.From == _smartContractAddressService.GetAddressByContractName( CrossChainSmartContractAddressNameProvider.Name)); }
private void PrepareBloomForIrreversibleBlockFound() { if (_bloomOfLibFound != null) { // already prepared return; } _contractAddress = _smartContractAddressService.GetAddressByContractName(ConsensusSmartContractAddressNameProvider.Name); _logEventOfLibFound = new IrreversibleBlockFound().ToLogEvent(_contractAddress); _bloomOfLibFound = _logEventOfLibFound.GetBloom(); }
public ConstrainedAEDPoSTransactionValidationProvider(ISmartContractAddressService smartContractAddressService) { _consensusContractAddress = smartContractAddressService.GetAddressByContractName(ConsensusSmartContractAddressNameProvider.Name); Logger = NullLogger <ConstrainedAEDPoSTransactionValidationProvider> .Instance; }
public void GenerateTransactions(Address @from, long preBlockHeight, Hash preBlockHash, ref List <Transaction> generatedTransactions) { if (preBlockHeight < Constants.GenesisBlockHeight) { return; } var tokenContractAddress = _smartContractAddressService.GetAddressByContractName( TokenSmartContractAddressNameProvider.Name); if (tokenContractAddress == null) { return; } generatedTransactions.AddRange(new List <Transaction> { new Transaction { From = from, MethodName = nameof(TokenContractContainer.TokenContractStub.DonateResourceToken), To = tokenContractAddress, RefBlockNumber = preBlockHeight, RefBlockPrefix = ByteString.CopyFrom(preBlockHash.Value.Take(4).ToArray()), Params = new Empty().ToByteString() } }); }
public ConstrainedAEDPoSTransactionValidationProvider(ISmartContractAddressService smartContractAddressService, ISystemTransactionMethodNameListProvider coreTransactionMethodNameListProvider) { _coreTransactionMethodNameListProvider = coreTransactionMethodNameListProvider; _consensusContractAddress = smartContractAddressService.GetAddressByContractName(ConsensusSmartContractAddressNameProvider.Name); }
/// <summary> /// Compare /// </summary> /// <param name="block"></param> /// <returns></returns> public async Task<bool> ValidateBlockAfterExecuteAsync(IBlock block) { var tokenContractAddress = _smartContractAddressService.GetAddressByContractName(TokenSmartContractAddressNameProvider.Name); if (tokenContractAddress == null) { return true; } var hashFromState = await _tokenReaderFactory.Create(block.GetHash(), block.Header.Height) .GetLatestTotalResourceTokensMapsHash.CallAsync(new Empty()); var totalResourceTokensMapsFromProvider = await _totalResourceTokensMapsProvider.GetTotalResourceTokensMapsAsync(new ChainContext { BlockHash = block.GetHash(), BlockHeight = block.Header.Height }); if (totalResourceTokensMapsFromProvider == null) { Logger.LogInformation("totalResourceTokensMapsFromProvider == null"); return hashFromState.Value.IsEmpty || hashFromState == Hash.FromMessage(TotalResourceTokensMaps.Parser.ParseFrom(ByteString.Empty)); } var hashFromProvider = Hash.FromMessage(totalResourceTokensMapsFromProvider); var result = hashFromProvider.Value.Equals(hashFromState.Value); if (!result) { Logger.LogError($"Hash from provider: {hashFromProvider}\nHash from state: {hashFromState}"); } return result; }
private bool TryDiscoverIndexedSideChainBlockData(IBlock block) { var crossChainContractAddress = _smartContractAddressService.GetAddressByContractName(CrossChainSmartContractAddressNameProvider.Name); return(new SideChainBlockDataIndexed().ToLogEvent(crossChainContractAddress).GetBloom() .IsIn(new Bloom(block.Header.Bloom.ToByteArray()))); }
public async Task <IEnumerable <Transaction> > GetPostTransactionsAsync( IReadOnlyList <ServiceDescriptor> descriptors, ITransactionContext transactionContext) { return(transactionContext.Transaction.To == _smartContractAddressService.GetAddressByContractName(ConsensusSmartContractAddressNameProvider.Name) ? await _transactionListProvider.GetTransactionListAsync() : new List <Transaction>()); }
public Task <bool> ValidateTransactionAsync(Transaction transaction) { var parliamentContractAddress = _smartContractAddressService.GetAddressByContractName(ParliamentSmartContractAddressNameProvider.Name); return(Task.FromResult(transaction.To != parliamentContractAddress || transaction.MethodName != nameof(ParliamentContractContainer.ParliamentContractStub .ApproveMultiProposals))); }
public Task <bool> ValidateTransactionAsync(Transaction transaction) { var crossChainContractAddress = _smartContractAddressService.GetAddressByContractName(CrossChainSmartContractAddressNameProvider.Name); return(Task.FromResult(transaction.To != crossChainContractAddress || transaction.MethodName != nameof(CrossChainContractContainer.CrossChainContractStub.RecordCrossChainData))); }
public async Task <Transaction> GenerateTransferTransaction() { var newUserKeyPair = CryptoHelper.GenerateKeyPair(); var accountAddress = await _accountService.GetAccountAsync(); var transaction = GenerateTransaction(accountAddress, _smartContractAddressService.GetAddressByContractName(TokenSmartContractAddressNameProvider.Name), nameof(TokenContractContainer.TokenContractStub.Transfer), new TransferInput { To = Address.FromPublicKey(newUserKeyPair.PublicKey), Amount = 10, Symbol = "ELF" }); var signature = await _accountService.SignAsync(transaction.GetHash().ToByteArray()); transaction.Signature = ByteString.CopyFrom(signature); return(transaction); }
public Task <bool> ValidateTransactionAsync(Transaction transaction) { var crossChainContractAddress = _smartContractAddressService.GetAddressByContractName(CrossChainSmartContractAddressNameProvider.Name); return(Task.FromResult(transaction.To != crossChainContractAddress || CrossChainContractPrivilegeMethodNameProvider.PrivilegeMethodNames.All(methodName => methodName != transaction.MethodName))); }
private LogEvent GetInterestedEvent() { if (_interestedEvent != null) return _interestedEvent; var address = _smartContractAddressService.GetAddressByContractName(CrossChainSmartContractAddressNameProvider .Name); _interestedEvent = new CrossChainIndexingDataProposedEvent().ToLogEvent(address); return _interestedEvent; }
public async Task HandleEventAsync(NewIrreversibleBlockFoundEvent eventData) { var tokenContractAddress = _smartContractAddressService.GetAddressByContractName(TokenSmartContractAddressNameProvider.Name); var txFeeUnitPrice = (await _transactionSizeFeeUnitPriceUpdatedDiscoveryService.GetEventMessagesAsync(eventData.BlockHash, tokenContractAddress)).FirstOrDefault()?.UnitPrice; if (txFeeUnitPrice != null) { _transactionSizeFeeUnitPriceProvider.SetUnitPrice(txFeeUnitPrice.Value); } }
/// <summary> /// Create a txn with provided data. /// </summary> /// <param name="from"></param> /// <param name="methodName"></param> /// <param name="refBlockNumber"></param> /// <param name="refBlockPrefix"></param> /// <param name="bytes"></param> /// <returns></returns> private Transaction GenerateNotSignedTransaction(Address from, string methodName, long refBlockNumber, byte[] refBlockPrefix, ByteString bytes) { return(new Transaction { From = from, To = _smartContractAddressService.GetAddressByContractName( CrossChainSmartContractAddressNameProvider.Name), RefBlockNumber = refBlockNumber, RefBlockPrefix = ByteString.CopyFrom(refBlockPrefix), MethodName = methodName, Params = bytes, }); }
public async Task <T> ExecuteContractAsync <T>(IChainContext chainContext, string consensusMethodName, IMessage input, DateTime dateTime) where T : class, IMessage <T>, new() { var tx = new Transaction { From = Address.Generate(), To = _smartContractAddressService.GetAddressByContractName(ConsensusSmartContractAddressNameProvider .Name), MethodName = consensusMethodName, Params = input?.ToByteString() ?? ByteString.Empty }; return(await _transactionReadOnlyExecutionService.ExecuteAsync <T>(chainContext, tx, dateTime)); }
public async Task <long> QueryBalanceAsync(Address address, string symbol, Hash blockHash, long blockHeight) { var accountAddress = await _accountService.GetAccountAsync(); var transaction = GenerateTransaction(accountAddress, _smartContractAddressService.GetAddressByContractName(TokenSmartContractAddressNameProvider.Name), nameof(TokenContractContainer.TokenContractStub.GetBalance), new GetBalanceInput { Owner = address, Symbol = symbol }); var returnValue = await ExecuteReadOnlyAsync(transaction, blockHash, blockHeight); return(GetBalanceOutput.Parser.ParseFrom(returnValue).Balance); }
private void PrepareBloom() { if (_bloom != null) { // already prepared return; } _contractAddress = _smartContractAddressService.GetAddressByContractName(ConsensusSmartContractAddressNameProvider.Name); _interestedEvent = new IrreversibleBlockFound(); _logEvent = _interestedEvent.ToLogEvent(_contractAddress); _bloom = _logEvent.GetBloom(); }
public async Task <List <Transaction> > GenerateTransactionsAsync(Address @from, long preBlockHeight, Hash preBlockHash) { var generatedTransactions = new List <Transaction>(); if (preBlockHeight < AElfConstants.GenesisBlockHeight) { return(generatedTransactions); } var tokenContractAddress = _smartContractAddressService.GetAddressByContractName( TokenSmartContractAddressNameProvider.Name); if (tokenContractAddress == null) { return(generatedTransactions); } var totalTxFeesMap = await _totalTransactionFeesMapProvider.GetTotalTransactionFeesMapAsync(new ChainContext { BlockHash = preBlockHash, BlockHeight = preBlockHeight }); if (totalTxFeesMap == null || !totalTxFeesMap.Value.Any() || totalTxFeesMap.BlockHeight != preBlockHeight || totalTxFeesMap.BlockHash != preBlockHash) { Logger.LogInformation( "Won't generate ClaimTransactionFees because no tx fee charged in previous block."); // If previous block doesn't contain logEvent named TransactionFeeCharged, won't generate this tx. return(new List <Transaction>()); } generatedTransactions.AddRange(new List <Transaction> { new Transaction { From = from, MethodName = nameof(TokenContractImplContainer.TokenContractImplStub.ClaimTransactionFees), To = tokenContractAddress, RefBlockNumber = preBlockHeight, RefBlockPrefix = BlockHelper.GetRefBlockPrefix(preBlockHash), Params = totalTxFeesMap.ToByteString() } }); Logger.LogInformation("Tx ClaimTransactionFees generated."); return(generatedTransactions); }
public Task <bool> ValidateTransactionAsync(Transaction transaction) { var tokenContractAddress = _smartContractAddressService.GetAddressByContractName(TokenSmartContractAddressNameProvider.Name); if (transaction.To != tokenContractAddress) { return(Task.FromResult(true)); } var systemTxs = new List <string> { nameof(TokenContractContainer.TokenContractStub.ClaimTransactionFees), nameof(TokenContractContainer.TokenContractStub.DonateResourceToken), }; return(Task.FromResult(!systemTxs.Contains(transaction.MethodName))); }
public async Task <IEnumerable <Transaction> > GetPostTransactionsAsync( IReadOnlyList <ServiceDescriptor> descriptors, ITransactionContext transactionContext) { return(transactionContext.Transaction.To == _smartContractAddressService.GetAddressByContractName( ConsensusSmartContractAddressNameProvider.Name) && new List <string> { "FirstRound", "UpdateValue", "UpdateTinyBlockInformation", "NextRound", "NextTerm" }.Contains(transactionContext.Transaction.MethodName) ? await _transactionListProvider.GetTransactionListAsync() : new List <Transaction>()); }
private List <Transaction> GenerateTwoInitializeTransaction() { var transactionList = new List <Transaction>(); var newUserKeyPair = CryptoHelpers.GenerateKeyPair(); for (int i = 0; i < 2; i++) { var transaction = _osTestHelper.GenerateTransaction(Address.FromPublicKey(newUserKeyPair.PublicKey), _smartContractAddressService.GetAddressByContractName(TokenSmartContractAddressNameProvider.Name), nameof(TokenContract.Create), new CreateInput { Symbol = $"ELF", TokenName = $"elf token {i}", TotalSupply = 1000_0000, Decimals = 2, Issuer = Address.Generate(), IsBurnable = true });
private void SetEventBloom() { if (_crossChainContractAddress == null) { _crossChainContractAddress = _smartContractAddressService.GetAddressByContractName(CrossChainSmartContractAddressNameProvider .Name); } if (_parentChainBlockIndexedEventBloom == null) { _parentChainBlockIndexedEventBloom = new ParentChainBlockDataIndexed() .ToLogEvent(_crossChainContractAddress).GetBloom(); } if (_sideChainBlockDataIndexedEventBloom == null) { _sideChainBlockDataIndexedEventBloom = new SideChainBlockDataIndexed().ToLogEvent(_crossChainContractAddress).GetBloom(); } }
public async Task <List <Transaction> > GenerateTransactionsAsync(Address from, long preBlockHeight, Hash preBlockHash) { var generatedTransactions = new List <Transaction>(); if (!_transactionPackingOptions.IsTransactionPackable) { return(generatedTransactions); } var parliamentContractAddress = _smartContractAddressService.GetAddressByContractName( ParliamentSmartContractAddressNameProvider.Name); if (parliamentContractAddress == null) { return(generatedTransactions); } var proposalIdList = await _proposalService.GetNotApprovedProposalIdListAsync(from, preBlockHash, preBlockHeight); if (proposalIdList == null || proposalIdList.Count == 0) { return(generatedTransactions); } var generatedTransaction = new Transaction { From = from, MethodName = nameof(ParliamentContractContainer.ParliamentContractStub.ApproveMultiProposals), To = parliamentContractAddress, RefBlockNumber = preBlockHeight, RefBlockPrefix = ByteString.CopyFrom(preBlockHash.Value.Take(4).ToArray()), Params = new ProposalIdList { ProposalIds = { proposalIdList } }.ToByteString() }; generatedTransactions.Add(generatedTransaction); Logger.LogInformation("Proposal approval transaction generated."); return(generatedTransactions); }
public async Task <Transaction> GenerateTransactionAsync(Hash contractName, string methodName, ByteString param) { var pubkey = await _accountService.GetPublicKeyAsync(); var chain = await _blockchainService.GetChainAsync(); var transaction = new Transaction { From = Address.FromPublicKey(pubkey), To = _smartContractAddressService.GetAddressByContractName(contractName), MethodName = methodName, Params = param, RefBlockNumber = chain.BestChainHeight, RefBlockPrefix = ByteString.CopyFrom(chain.BestChainHash.Value.Take(4).ToArray()) }; Logger.LogDebug($"[Boilerplate]Generated test tx: {transaction}. tx id: {transaction.GetHash()}"); return(transaction); }