public async Task CompareAddressBalances()
        {
            IAddressInfoService addressInfoService = Instantiate <IAddressInfoService>();
            IBlockchainClient   blockchainClient   = Instantiate <IBlockchainClient>();

            IEnumerable <string> addresses = new List <string>();

            using (var uow = NewUnitOfWork())
            {
                addresses = NewRepository <Address>(uow).GetAs(a => true, a => a.BlockchainAddress);
            }

            foreach (var address in addresses)
            {
                var databaseResult = addressInfoService.GetAddressInfo(address);
                Assert.True(databaseResult.Successful, $"Retrieving address {address} from database failed.");

                var blockchainResult = await blockchainClient.GetAddressInfo(address);

                Assert.True(blockchainResult.Successful, $"Retrieving address {address} from blockchain failed.");

                var addressInfoDto       = databaseResult.Data;
                var addressBlockchainDto = blockchainResult.Data;

                Assert.True(addressBlockchainDto.Balance.Available == addressInfoDto.ChxBalanceInfo.AvailableBalance, $"Available CHX for {address} does not match.");
                Assert.True(addressBlockchainDto.Balance.Deposit == addressInfoDto.ChxBalanceInfo.ValidatorDeposit, $"Deposited CHX for {address} does not match.");
                Assert.True(addressBlockchainDto.Balance.Staked == addressInfoDto.ChxBalanceInfo.DelegatedStakes, $"Staked CHX for {address} does not match.");
            }
        }
示例#2
0
        public Result <object> Search(string hash)
        {
            using (var uow = NewUnitOfWork())
            {
                if (NewRepository <Address>(uow).Exists(a => a.BlockchainAddress == hash))
                {
                    return(ProcessSearchResult(_addressInfoService.GetAddressInfo(hash)));
                }
                else if (NewRepository <Account>(uow).Exists(a => a.Hash == hash))
                {
                    return(ProcessSearchResult(GetAccountInfo(hash)));
                }
                else if (NewRepository <Asset>(uow).Exists(a => a.Hash == hash))
                {
                    return(ProcessSearchResult(GetAssetInfo(hash)));
                }
                else if (NewRepository <Transaction>(uow).Exists(t => t.Hash == hash))
                {
                    return(ProcessSearchResult(_txInfoService.GetTxInfo(hash)));
                }
                else if (NewRepository <Equivocation>(uow).Exists(e => e.EquivocationProofHash == hash))
                {
                    return(ProcessSearchResult(GetEquivocationInfo(hash)));
                }
                else
                {
                    if (long.TryParse(hash, out long number))
                    {
                        if (NewRepository <Block>(uow).Exists(a => a.BlockNumber == number))
                        {
                            return(ProcessSearchResult(_blockInfoService.GetBlockInfo(number)));
                        }
                    }
                }

                return(Result.Failure <object>("Not found."));
            }
        }
示例#3
0
 public IActionResult GetAddressInfo(string blockchainAddress)
 {
     return(ApiResult(_addressInfoService.GetAddressInfo(blockchainAddress), r => NotFound(r)));
 }