Skip to content

Commit

Permalink
- update IChainmanager and implementation.
Browse files Browse the repository at this point in the history
- add chain not supported response
  • Loading branch information
ArdenHide committed Jun 21, 2024
1 parent b9e6dc7 commit 61db4cc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/MetaDataAPI/LambdaFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ public LambdaResponse FunctionHandler(LambdaRequest request, ILambdaLogger logge
{
try
{
if (request.ValidationResult != null) return new ValidationErrorResponse(request.ValidationResult);

var chainInfo = chainManager.FetchChainInfo(request.ChainId);
if (request.ValidationResult != null)
{
return new ValidationErrorResponse(request.ValidationResult);
}

if (!chainManager.TryFetchChainInfo(request.ChainId, out var chainInfo))
{
return new ChainNotSupportedResponse(request.ChainId);
}

var poolsInfo = AbstractProvider.FetchPoolInfo(request.PoolId, chainInfo);

Expand Down
14 changes: 14 additions & 0 deletions src/MetaDataAPI/Response/ChainNotSupportedResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Net;
using System.Numerics;

namespace MetaDataAPI.Response;

public class ChainNotSupportedResponse : LambdaResponse
{
public ChainNotSupportedResponse(BigInteger chainId)
: base(
body: $"ChainID {chainId} is not supported.",
statusCode: HttpStatusCode.NotImplemented
)
{ }
}
3 changes: 2 additions & 1 deletion src/MetaDataAPI/Services/ChainsInfo/IChainManager.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Numerics;
using System.Diagnostics.CodeAnalysis;

namespace MetaDataAPI.Services.ChainsInfo;

public interface IChainManager
{
public ChainInfo FetchChainInfo(BigInteger chainId);
public bool TryFetchChainInfo(BigInteger chainId, [MaybeNullWhen(false)] out ChainInfo chainInfo);
}
5 changes: 3 additions & 2 deletions src/MetaDataAPI/Services/ChainsInfo/LocalChainManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Numerics;
using System.Diagnostics.CodeAnalysis;

namespace MetaDataAPI.Services.ChainsInfo;

Expand All @@ -9,8 +10,8 @@ public class LocalChainManager : IChainManager
{ 97, new ChainInfo(97, "https://data-seed-prebsc-1-s1.binance.org:8545/", "0xe42876a77108E8B3B2af53907f5e533Cba2Ce7BE") }
};

public ChainInfo FetchChainInfo(BigInteger chainId)
public bool TryFetchChainInfo(BigInteger chainId, [MaybeNullWhen(false)] out ChainInfo chainInfo)
{
return localChainInfo[chainId];
return localChainInfo.TryGetValue(chainId, out chainInfo);
}
}

0 comments on commit 61db4cc

Please sign in to comment.