Skip to content

Commit

Permalink
feat: method for rpc call
Browse files Browse the repository at this point in the history
  • Loading branch information
markettes authored and RodriFS committed Jul 1, 2024
1 parent 5345449 commit 14b979a
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion src/Rpc/NodeGuardService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Task<GetNewWalletAddressResponse> GetNewWalletAddress(GetNewWalletAddressRequest
Task<GetWithdrawalsRequestStatusResponse> GetWithdrawalsRequestStatus(GetWithdrawalsRequestStatusRequest request, ServerCallContext context);

Task<GetChannelResponse> GetChannel(GetChannelRequest request, ServerCallContext context);

Task<AddTagsResponse> AddTags(AddTagsRequest request, ServerCallContext context);
}

/// <summary>
Expand Down Expand Up @@ -994,7 +996,45 @@ public override async Task<GetChannelResponse> GetChannel(GetChannelRequest requ

return result;
}


public async Task<AddTagsResponse> AddTags(AddTagsRequest request, ServerCallContext context)

Check warning on line 1000 in src/Rpc/NodeGuardService.cs

View workflow job for this annotation

GitHub Actions / build-and-test

'NodeGuardService.AddTags(AddTagsRequest, ServerCallContext)' hides inherited member 'NodeGuardService.NodeGuardServiceBase.AddTags(AddTagsRequest, ServerCallContext)'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.
{
if (request.Tags.Count == 0)
{
throw new RpcException(new Status(StatusCode.InvalidArgument, "Tags are required"));
}

foreach (var tag in request.Tags)
{
var utxo = tag.UtxoOutpoint.Split("-");
if (utxo.Length != 2)
{
throw new RpcException(new Status(StatusCode.InvalidArgument, $"Invalid outpoint {tag.UtxoOutpoint}"));
}

if (!uint.TryParse(utxo[1], out _))
{
throw new RpcException(new Status(StatusCode.InvalidArgument, $"Invalid output index {tag.UtxoOutpoint}"));
}
}

var tags = request.Tags.Select(tag => new UTXOTag
{
Outpoint = tag.UtxoOutpoint,
Key = tag.Key,
Value = tag.Value
}).ToList();

var result = await _utxoTagRepository.AddRangeAsync(tags);

if (!result.Item1)
{
throw new RpcException(new Status(StatusCode.Internal, "Error adding tags"));
}

return new AddTagsResponse();
}

private bool ValidateBitcoinAddress(string address)
{
try
Expand Down

0 comments on commit 14b979a

Please sign in to comment.