Ejemplo n.º 1
0
        public async Task Erc20DetectorTest_IsContractErc20CompatibleSuccess()
        {
            string erc20ContractAddress = "0xce2ef46ecc168226f33b6f6b8a56e90450d0d2c0";
            var    isCompatible         = await _detector.IsContractErc20Compatible(erc20ContractAddress);

            Assert.IsTrue(isCompatible);
        }
Ejemplo n.º 2
0
        public async Task IndexContractAsync(DeployedContractModel deployedContract)
        {
            if (await TransactionExists(deployedContract.TransactionHash) &&
                await _erc20Detector.IsContractErc20Compatible(deployedContract.Address))
            {
                var ethereumContract = _web3.Eth.GetContract(MetadataAbi, deployedContract.Address);
                var erc20Contract    = new Erc20ContractModel
                {
                    Address         = deployedContract.Address,
                    BlockHash       = deployedContract.BlockHash,
                    BlockNumber     = BigInteger.Parse(deployedContract.BlockNumber),
                    BlockTimestamp  = BigInteger.Parse(deployedContract.BlockTimestamp),
                    DeployerAddress = deployedContract.DeployerAddress,
                    TransactionHash = deployedContract.TransactionHash
                };

                if (TryCallFunction(ethereumContract, "name", out string name))
                {
                    erc20Contract.TokenName = name;
                }

                if (TryCallFunction(ethereumContract, "symbol", out string symbol))
                {
                    erc20Contract.TokenSymbol = symbol;
                }

                if (TryCallFunction(ethereumContract, "decimals", out uint decimals))
                {
                    erc20Contract.TokenDecimals = decimals;
                }

                if (TryCallFunction(ethereumContract, "totalSupply", out BigInteger totalSupply))
                {
                    erc20Contract.TokenTotalSupply = totalSupply;
                }

                await _erc20ContractRepository.SaveAsync(erc20Contract);

                await _rabbitQueuePublisher.NotifyAsync(new Lykke.Service.EthereumSamurai.Models.Messages.RabbitContractIndexingMessage()
                {
                    Address             = erc20Contract.Address,
                    BlockHash           = erc20Contract.BlockHash,
                    BlockNumber         = (ulong)erc20Contract.BlockNumber,
                    BlockTimestamp      = (int)erc20Contract.BlockTimestamp,
                    DeployerAddress     = erc20Contract.DeployerAddress,
                    IndexingMessageType = Lykke.Service.EthereumSamurai.Models.Messages.IndexingMessageType.ErcContract,
                    TokenDecimals       = erc20Contract.TokenDecimals,
                    TokenName           = erc20Contract.TokenName,
                    TokenSymbol         = erc20Contract.TokenSymbol,
                    TokenTotalSupply    = erc20Contract.TokenTotalSupply.ToString(),
                    TransactionHash     = erc20Contract.TransactionHash
                });
            }
        }