コード例 #1
0
        public async Task <bool> ValidateTransactionAsync(Transaction transaction)
        {
            var deployedContractAddressList = await _deployedContractAddressProvider.GetDeployedContractAddressListAsync();

            if (deployedContractAddressList.Value.Contains(transaction.To))
            {
                return(true);
            }

            Logger.LogError($"Invalid contract address: {transaction}");
            return(false);
        }
コード例 #2
0
        public async Task <bool> ValidateTransactionAsync(Transaction transaction)
        {
            // Skip if the sender is a contract.
            var deployedContractAddressList =
                await _deployedContractAddressProvider.GetDeployedContractAddressListAsync();

            if (deployedContractAddressList.Value.Contains(transaction.From))
            {
                return(true);
            }

            // Skip if this is a system transaction.
            if (IsSystemTransaction(transaction))
            {
                return(true);
            }

            var chain = await _blockchainService.GetChainAsync();

            // Skip this validation at the very beginning of current chain.
            if (chain.LastIrreversibleBlockHeight == Constants.GenesisBlockHeight)
            {
                return(true);
            }

            var tokenStub = _tokenContractReaderFactory.Create(new ChainContext
            {
                BlockHash   = chain.BestChainHash,
                BlockHeight = chain.BestChainHeight
            });
            var balance = (await tokenStub.GetBalance.CallAsync(new GetBalanceInput
            {
                Owner = transaction.From,
                Symbol = await _primaryTokenSymbolProvider.GetPrimaryTokenSymbol()
            }))?.Balance;

            // balance == null means token contract hasn't deployed.
            if (balance == null || balance > 0)
            {
                return(true);
            }

            Logger.LogError($"Empty balance of tx from address: {transaction}");
            return(false);
        }