Exemple #1
0
        internal static async Task UpdateAccount(ExplorerDbContext context, Transaction transaction, string eventDtoEventAddress)
        {
            var account = context.Accounts.SingleOrDefault(p => p.Address.Equals(eventDtoEventAddress));

            if (account != null)
            {
                var accountTx = new AccountTransaction
                {
                    Account     = account,
                    Transaction = transaction
                };

                if (account.AccountTransactions.Any(t => t.Transaction.Hash == transaction.Hash))
                {
                    return;
                }

                account.AccountTransactions.Add(accountTx);
            }
            else
            {
                account = new Account
                {
                    Address = eventDtoEventAddress
                };

                account.AccountTransactions.Add(new AccountTransaction {
                    Account = account, Transaction = transaction
                });

                await context.Accounts.AddAsync(account);
            }

            await context.SaveChangesAsync();
        }
Exemple #2
0
        internal static async Task SyncChains(IList <ChainDto> chains, ExplorerDbContext context)
        {
            foreach (var chainDto in chains)
            {
                if (context.Chains.SingleOrDefault(p => p.Address.Equals(chainDto.Address)) == null)
                {
                    Console.WriteLine($"Sync {chainDto.Name} chain info");

                    var chain = new Chain
                    {
                        Address       = chainDto.Address,
                        Name          = chainDto.Name,
                        Height        = chainDto.Height,
                        ParentAddress = chainDto.ParentAddress,
                        Contracts     = chainDto.Contracts.ToArray()
                    };

                    await context.Accounts.AddAsync(new Account { Address = chain.Address });

                    await context.Chains.AddAsync(chain);
                }
            }

            await context.SaveChangesAsync();
        }
Exemple #3
0
        internal static async Task SyncApps(ExplorerDbContext context, IList <AppDto> appList)
        {
            foreach (var dto in appList)
            {
                if (context.Apps.SingleOrDefault(p => p.Id.Equals(dto.Id)) == null)
                {
                    context.Apps.Add(new App
                    {
                        Id          = dto.Id,
                        Url         = dto.Url,
                        Description = dto.Description,
                        Title       = dto.Title,
                        Icon        = dto.Icon
                    });
                }

                await context.SaveChangesAsync();
            }
        }
Exemple #4
0
        internal static async Task SyncToken(ExplorerDbContext context, IList <TokenDto> tokenList)
        {
            foreach (var tokenDto in tokenList)
            {
                var contextToken = context.Tokens.SingleOrDefault(p => p.Symbol.Equals(tokenDto.Symbol));

                if (contextToken == null)
                {
                    contextToken = new Token
                    {
                        Name          = tokenDto.Name,
                        Symbol        = tokenDto.Symbol,
                        Decimals      = (uint)tokenDto.Decimals,
                        Flags         = tokenDto.Flags,
                        MaxSupply     = tokenDto.MaxSupply,
                        CurrentSupply = tokenDto.CurrentSupply,
                        OwnerAddress  = tokenDto.OwnerAddress,
                    };

                    if (tokenDto.MetadataList != null)
                    {
                        foreach (var metadataDto in tokenDto.MetadataList)
                        {
                            contextToken.MetadataList.Add(new TokenMetadata
                            {
                                Key   = metadataDto.Key,
                                Value = metadataDto.Value
                            });
                        }
                    }

                    context.Tokens.Add(contextToken);
                }
                else
                {
                    if (!AreTokenEqual(tokenDto, contextToken))
                    {
                        contextToken.Name          = tokenDto.Name;
                        contextToken.Decimals      = (uint)tokenDto.Decimals;
                        contextToken.Flags         = tokenDto.Flags;
                        contextToken.MaxSupply     = tokenDto.MaxSupply;
                        contextToken.CurrentSupply = tokenDto.CurrentSupply;
                        contextToken.OwnerAddress  = tokenDto.OwnerAddress;
                    }

                    if (!IsTokenMetadataEqual(tokenDto, contextToken))
                    {
                        contextToken.MetadataList.Clear();//reset

                        foreach (var metadataDto in tokenDto.MetadataList)
                        {
                            contextToken.MetadataList.Add(new TokenMetadata
                            {
                                Key   = metadataDto.Key,
                                Value = metadataDto.Value
                            });
                        }
                    }

                    context.Tokens.Update(contextToken);
                }
            }

            await context.SaveChangesAsync();
        }