Skip to content

Commit

Permalink
feat: activities token transfer from token indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
mixhsnhd committed Jan 2, 2025
1 parent 2918bb8 commit 8facf10
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using System.Linq;
using MongoDB.Driver;

namespace EoaServer.Provider.Dto.Indexer;

public class BaseInput : OrderInfo
{
public string ChainId { get; set; } = "";
public long SkipCount { get; set; }
public long MaxResultCount { get; set; } = 10;
public List<OrderInfo> OrderInfos { get; set; }
public List<string> SearchAfter { get; set; }

public void OfOrderInfos(params (SortField sortField, SortDirection sortDirection)[] orderInfos)
{
OrderInfos = BuildOrderInfos(orderInfos);
}
}

public class OrderInfo
{
public string OrderBy { get; set; }

public string Sort { get; set; }

public static List<OrderInfo> BuildOrderInfos(
params (SortField sortField, SortDirection sortDirection)[] orderInfos)
{
return orderInfos.Select(info => new OrderInfo
{
OrderBy = info.sortField.ToString(),
Sort = info.sortDirection.ToString()
}).ToList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using EoaServer.Token.Dto;

namespace EoaServer.Provider.Dto.Indexer;

public class IndexerTokenTransfersDto
{
public IndexerTokenTransferListDto TransferInfo { get; set; }
}

public class IndexerTokenTransferListDto
{
public long TotalCount { get; set; }
public List<IndexerTransferInfoDto> Items { get; set; } = new();
}

public class IndexerTransferInfoDto
{
public string TransactionId { get; set; }
public MetadataDto Metadata { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace EoaServer.Provider.Dto.Indexer;

public enum SortField
{
Id,
BlockTime,
BlockHeight,
HolderCount,
TransferCount,
Symbol,
FormatAmount,
Address,
TransactionId
}

public enum SortDirection
{
Asc,
Desc
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using EoaServer.Token.Dto;
using MongoDB.Driver;

namespace EoaServer.Provider.Dto.Indexer;

public class TokenTransferInput : BaseInput

{
public string Symbol { get; set; } = "";
public string Search { get; set; } = "";
public string CollectionSymbol { get; set; } = "";

public string Address { get; set; } = "";

public List<SymbolType> Types { get; set; } = new() { SymbolType.Token };

public string FuzzySearch { get; set; } = "";

public DateTime? BeginBlockTime { get; set; }

public void SetDefaultSort()
{
if (!OrderBy.IsNullOrEmpty() || !OrderInfos.IsNullOrEmpty())
{
return;
}

OfOrderInfos((SortField.BlockTime, SortDirection.Desc), (SortField.TransactionId, SortDirection.Desc));
}


public void SetBlockTimeSort()
{
if (!OrderBy.IsNullOrEmpty() || !OrderInfos.IsNullOrEmpty())
{
return;
}

OfOrderInfos((SortField.BlockTime, SortDirection.Desc), (SortField.TransactionId, SortDirection.Desc));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;
using EoaServer.Provider.Dto.Indexer;

namespace EoaServer.Provider;

public interface IGraphQLProvider
{
public Task<IndexerTokenTransferListDto> GetTokenTransferInfoAsync(TokenTransferInput input);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ActivityBase
public string ToChainId { get; set; }
public string ToChainIdUpdated { get; set; }
public string ToChainIcon { get; set; }
public List<TransactionFee> TransactionFees { get; set; }
public List<TransactionFee> TransactionFees { get; set; } = new();
public string PriceInUsd { get; set; }
public bool IsDelegated { get; set; }
public bool IsSystem { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class GetActivitiesRequestDto : PagedResultRequestDto
public List<AddressInfo> AddressInfos { get; set; }
public List<string> TransactionTypes { get; set; }
public string ChainId { get; set; }
public string Symbol { get; set; }
public string Symbol { get; set; } = "";

public int Width { get; set; }

Expand Down
1 change: 1 addition & 0 deletions src/EoaServer.Application/EoaServerApplicationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ public override void ConfigureServices(ServiceConfigurationContext context)
Configure<DepositOptions>(configuration.GetSection("Deposit"));
Configure<CoinGeckoOptions>(configuration.GetSection("CoinGecko"));
Configure<AwsThumbnailOptions>(configuration.GetSection("AWSThumbnail"));
Configure<GraphQLOptions>(configuration.GetSection("GraphQLOptions"));
}
}
13 changes: 13 additions & 0 deletions src/EoaServer.Application/Options/GraphQLOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;

namespace EoaServer.Options;

public class GraphQLOptions
{
public Dictionary<string, IndexerOption> IndexerOptions { get; set; }
}

public class IndexerOption
{
public string BaseUrl { get; set; }
}
78 changes: 78 additions & 0 deletions src/EoaServer.Application/Provider/GraphQLProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using EoaServer.Options;
using EoaServer.Provider.Dto.Indexer;
using EoaServer.Token;
using EoaServer.Token.Dto;
using GraphQL;
using GraphQL.Client.Http;
using GraphQL.Client.Serializer.Newtonsoft;
using Microsoft.Extensions.Options;
using Orleans;
using Serilog;
using Volo.Abp.DependencyInjection;

namespace EoaServer.Provider;

public class GraphQLProvider : IGraphQLProvider, ISingletonDependency
{
private readonly GraphQLOptions _graphQLOptions;
private readonly GraphQLHttpClient _blockChainIndexerClient;
private readonly GraphQLHttpClient _tokenIndexerClient;
private readonly IClusterClient _clusterClient;
private readonly ILogger _logger;
private readonly ITokenAppService _tokenAppService;

public const string TokenIndexer = "TokenIndexer";
public const string BlockChainIndexer = "BlockChainIndexer";

public GraphQLProvider(IClusterClient clusterClient,
ITokenAppService tokenAppService,
IOptionsSnapshot<GraphQLOptions> graphQLOptions)
{
_logger = Log.ForContext<GraphQLProvider>();
_clusterClient = clusterClient;
_graphQLOptions = graphQLOptions.Value;
_blockChainIndexerClient = new GraphQLHttpClient(_graphQLOptions.IndexerOptions[BlockChainIndexer].BaseUrl, new NewtonsoftJsonSerializer());
_tokenIndexerClient = new GraphQLHttpClient(_graphQLOptions.IndexerOptions[TokenIndexer].BaseUrl, new NewtonsoftJsonSerializer());
_tokenAppService = tokenAppService;
}

public async Task<IndexerTokenTransferListDto> GetTokenTransferInfoAsync(TokenTransferInput input)
{
input.SetDefaultSort();
var indexerResult = await _tokenIndexerClient.SendQueryAsync<IndexerTokenTransfersDto>(new GraphQLRequest
{
Query =
@"query($chainId:String!,$symbol:String!,$address:String,$collectionSymbol:String,
$search:String,$skipCount:Int!,$maxResultCount:Int!,$types:[SymbolType!],$beginBlockTime:DateTime,
$fuzzySearch:String,$sort:String,$orderBy:String,$searchAfter:[String],$orderInfos:[OrderInfo]){
transferInfo(input: {chainId:$chainId,symbol:$symbol,collectionSymbol:$collectionSymbol,address:$address,types:$types,beginBlockTime:$beginBlockTime,search:$search,
skipCount:$skipCount,maxResultCount:$maxResultCount,fuzzySearch:$fuzzySearch,sort:$sort,orderBy:$orderBy,searchAfter:$searchAfter,orderInfos:$orderInfos}){
totalCount,
items{
transactionId
metadata {
chainId
block {
blockHash
blockHeight
blockTime
}
}
}
}
}",
Variables = new
{
chainId = input.ChainId, symbol = input.Symbol, address = input.Address, search = input.Search,
skipCount = input.SkipCount, maxResultCount = input.MaxResultCount,
collectionSymbol = input.CollectionSymbol,
sort = input.Sort, fuzzySearch = input.FuzzySearch,
orderInfos = input.OrderInfos, searchAfter = input.SearchAfter, beginBlockTime = input.BeginBlockTime
}
});
return indexerResult == null || indexerResult.Data == null ?
new IndexerTokenTransferListDto() : indexerResult.Data.TransferInfo;
}
}
Loading

0 comments on commit 8facf10

Please sign in to comment.