-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: activities token transfer from token indexer
- Loading branch information
Showing
13 changed files
with
315 additions
and
62 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/EoaServer.Application.Contracts/Provider/Dto/Indexer/BaseInput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/EoaServer.Application.Contracts/Provider/Dto/Indexer/IndexerTokenTransferListDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
20 changes: 20 additions & 0 deletions
20
src/EoaServer.Application.Contracts/Provider/Dto/Indexer/SortField.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
43 changes: 43 additions & 0 deletions
43
src/EoaServer.Application.Contracts/Provider/Dto/Indexer/TokenTransferInput.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/EoaServer.Application.Contracts/Provider/IGraphQLProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.