Adds eth address validation.

This commit is contained in:
benbierens 2023-10-22 11:26:00 +02:00
parent 8ef2e6023e
commit 116f62e73e
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA

View File

@ -1,5 +1,6 @@
using Discord.WebSocket; using Discord.WebSocket;
using GethPlugin; using GethPlugin;
using Nethereum.Util;
namespace BiblioTech.Commands namespace BiblioTech.Commands
{ {
@ -18,14 +19,21 @@ namespace BiblioTech.Commands
var ethOptionData = command.Data.Options.SingleOrDefault(o => o.Name == Name); var ethOptionData = command.Data.Options.SingleOrDefault(o => o.Name == Name);
if (ethOptionData == null) if (ethOptionData == null)
{ {
await command.RespondAsync("EthAddress option not received."); await command.FollowupAsync("EthAddress option not received.");
return null; return null;
} }
var ethAddressStr = ethOptionData.Value as string; var ethAddressStr = ethOptionData.Value as string;
if (string.IsNullOrEmpty(ethAddressStr)) if (string.IsNullOrEmpty(ethAddressStr))
{ {
// todo, validate that it is an eth address. await command.FollowupAsync("EthAddress is null or empty.");
await command.RespondAsync("EthAddress is null or invalid."); return null;
}
if (!AddressUtil.Current.IsValidAddressLength(ethAddressStr) ||
!AddressUtil.Current.IsValidEthereumAddressHexFormat(ethAddressStr) ||
!AddressUtil.Current.IsChecksumAddress(ethAddressStr))
{
await command.FollowupAsync("EthAddress is not valid.");
return null; return null;
} }