From 116f62e73e666111b84a52d38b89e4c6345ef2a6 Mon Sep 17 00:00:00 2001 From: benbierens Date: Sun, 22 Oct 2023 11:26:00 +0200 Subject: [PATCH] Adds eth address validation. --- Tools/BiblioTech/Commands/EthAddressOption.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Tools/BiblioTech/Commands/EthAddressOption.cs b/Tools/BiblioTech/Commands/EthAddressOption.cs index e9e57840..6996c79f 100644 --- a/Tools/BiblioTech/Commands/EthAddressOption.cs +++ b/Tools/BiblioTech/Commands/EthAddressOption.cs @@ -1,5 +1,6 @@ using Discord.WebSocket; using GethPlugin; +using Nethereum.Util; namespace BiblioTech.Commands { @@ -18,14 +19,21 @@ namespace BiblioTech.Commands var ethOptionData = command.Data.Options.SingleOrDefault(o => o.Name == Name); if (ethOptionData == null) { - await command.RespondAsync("EthAddress option not received."); + await command.FollowupAsync("EthAddress option not received."); return null; } var ethAddressStr = ethOptionData.Value as string; if (string.IsNullOrEmpty(ethAddressStr)) { - // todo, validate that it is an eth address. - await command.RespondAsync("EthAddress is null or invalid."); + await command.FollowupAsync("EthAddress is null or empty."); + return null; + } + + if (!AddressUtil.Current.IsValidAddressLength(ethAddressStr) || + !AddressUtil.Current.IsValidEthereumAddressHexFormat(ethAddressStr) || + !AddressUtil.Current.IsChecksumAddress(ethAddressStr)) + { + await command.FollowupAsync("EthAddress is not valid."); return null; }