[#28] Client: Apply code optimizations

Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
Pavel Gross 2024-11-18 16:57:20 +03:00
parent 766f61a5f7
commit 749000a090
57 changed files with 845 additions and 1116 deletions

View file

@ -16,13 +16,9 @@ internal sealed class ApeManagerServiceProvider : ContextAccessor
_apeManagerServiceClient = apeManagerServiceClient;
}
internal async Task<byte[]> AddChainAsync(PrmApeChainAdd args)
internal async Task<ReadOnlyMemory<byte>> AddChainAsync(PrmApeChainAdd args)
{
var ctx = args.Context!;
ctx.Key ??= ClientContext.Key?.ECDsaKey;
if (ctx.Key == null)
throw new ArgumentNullException(nameof(args), "Key is null");
AddChainRequest request = new()
{
@ -34,22 +30,18 @@ internal sealed class ApeManagerServiceProvider : ContextAccessor
};
request.AddMetaHeader(args.XHeaders);
request.Sign(ctx.Key);
request.Sign(ClientContext.Key.ECDsaKey);
var response = await _apeManagerServiceClient!.AddChainAsync(request, null, ctx.Deadline, ctx.CancellationToken);
Verifier.CheckResponse(response);
return response.Body.ChainId.ToByteArray();
return response.Body.ChainId.Memory;
}
internal async Task RemoveChainAsync(PrmApeChainRemove args)
{
var ctx = args.Context!;
ctx.Key ??= ClientContext.Key?.ECDsaKey;
if (ctx.Key == null)
throw new ArgumentNullException(nameof(args), "Key is null");
RemoveChainRequest request = new()
{
@ -61,7 +53,7 @@ internal sealed class ApeManagerServiceProvider : ContextAccessor
};
request.AddMetaHeader(args.XHeaders);
request.Sign(ctx.Key);
request.Sign(ClientContext.Key.ECDsaKey);
var response = await _apeManagerServiceClient!.RemoveChainAsync(request, null, ctx.Deadline, ctx.CancellationToken);
@ -71,10 +63,6 @@ internal sealed class ApeManagerServiceProvider : ContextAccessor
internal async Task<Chain[]> ListChainAsync(PrmApeChainList args)
{
var ctx = args.Context!;
ctx.Key ??= ClientContext.Key?.ECDsaKey;
if (ctx.Key == null)
throw new ArgumentNullException(nameof(args), "Key is null");
ListChainsRequest request = new()
{
@ -85,7 +73,7 @@ internal sealed class ApeManagerServiceProvider : ContextAccessor
};
request.AddMetaHeader(args.XHeaders);
request.Sign(ctx.Key);
request.Sign(ClientContext.Key.ECDsaKey);
var response = await _apeManagerServiceClient!.ListChainsAsync(request, null, ctx.Deadline, ctx.CancellationToken);