public async Task GetNotApprovedProposalIdListTest() { var proposalId1 = Hash.FromString("proposalId1"); var proposalId2 = Hash.FromString("proposalId2"); var proposalId3 = Hash.FromString("proposalId3"); var proposalId4 = Hash.FromString("proposalId4"); var notApprovedProposalIdList = new List <Hash> { proposalId1, proposalId2, proposalId3, proposalId4 }; _proposalTestHelper.AddNotVotedProposalIdList(notApprovedProposalIdList); var blockHash = Hash.FromString("BlockHash"); var blockHeight = 10; var proposalCacheProvider = GetRequiredService <IProposalProvider>(); proposalCacheProvider.AddProposal(proposalId1, 5); { var queryResultNotApprovedProposalIdList = await _proposalService.GetNotApprovedProposalIdListAsync(NormalAddress, blockHash, blockHeight); queryResultNotApprovedProposalIdList.Count.ShouldBe(1); queryResultNotApprovedProposalIdList.ShouldContain(proposalId1); } proposalCacheProvider.AddProposal(proposalId2, 6); { var queryResultNotApprovedProposalIdList = await _proposalService.GetNotApprovedProposalIdListAsync(NormalAddress, blockHash, blockHeight); queryResultNotApprovedProposalIdList.Count.ShouldBe(2); queryResultNotApprovedProposalIdList.ShouldContain(proposalId1); queryResultNotApprovedProposalIdList.ShouldContain(proposalId2); } }
public async Task <List <Transaction> > GenerateTransactionsAsync(Address from, long preBlockHeight, Hash preBlockHash) { var generatedTransactions = new List <Transaction>(); var chainContext = new ChainContext { BlockHash = preBlockHash, BlockHeight = preBlockHeight }; if (!_transactionPackingOptionProvider.IsTransactionPackable(chainContext)) { return(generatedTransactions); } var parliamentContractAddress = await _smartContractAddressService.GetAddressByContractNameAsync( chainContext, ParliamentSmartContractAddressNameProvider.StringName); 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 = BlockHelper.GetRefBlockPrefix(preBlockHash), Params = new ProposalIdList { ProposalIds = { proposalIdList } }.ToByteString() }; generatedTransactions.Add(generatedTransaction); Logger.LogTrace("Proposal approval transaction generated."); return(generatedTransactions); }
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); }