Skip to content

Commit

Permalink
Add tex command to translate T to TEX addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Jun 1, 2024
1 parent c2b8ea7 commit 514457f
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Nerdbank.Zcash.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
NewAccountCommand.BuildCommand(),
ImportAccountCommand.BuildCommand(),
UACommand.BuildCommand(),
TexCommand.BuildCommand(),
SyncCommand.BuildCommand(),
BalanceCommand.BuildCommand(),
HistoryCommand.BuildCommand(),
Expand Down
9 changes: 9 additions & 0 deletions src/Nerdbank.Zcash.Cli/Strings.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@
<data name="TestNetOptionDescription" xml:space="preserve">
<value>Indica que la cuenta se utilizará en una red de prueba en lugar de en una red principal.</value>
</data>
<data name="TexCommandDescription" xml:space="preserve">
<value>Convierte una dirección transparente en una dirección TEX.</value>
</data>
<data name="TexTransparentAddressArgumentDescription" xml:space="preserve">
<value>La dirección transparente para convertir.</value>
</data>
<data name="TransparentP2PKHAddressRequired" xml:space="preserve">
<value>Se requiere una dirección transparente P2PKH.</value>
</data>
<data name="UACommandDescription" xml:space="preserve">
<value>Codifica o decodifica direcciones UA.</value>
</data>
Expand Down
11 changes: 10 additions & 1 deletion src/Nerdbank.Zcash.Cli/Strings.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@
<data name="TestNetOptionDescription" xml:space="preserve">
<value>Indique que le compte sera utilisé sur un testnet au lieu de mainnet.</value>
</data>
<data name="TexCommandDescription" xml:space="preserve">
<value>Convertit une adresse transparente en une adresse Tex.</value>
</data>
<data name="TexTransparentAddressArgumentDescription" xml:space="preserve">
<value>L'adresse transparente à convertir.</value>
</data>
<data name="TransparentP2PKHAddressRequired" xml:space="preserve">
<value>Une adresse transparente P2PKH est requise.</value>
</data>
<data name="UACommandDescription" xml:space="preserve">
<value>Encode ou décode les adresses UA.</value>
</data>
Expand All @@ -273,4 +282,4 @@
<data name="WalletPathArgumentDescription" xml:space="preserve">
<value>Le chemin d'accès au fichier de portefeuille.</value>
</data>
</root>
</root>
11 changes: 10 additions & 1 deletion src/Nerdbank.Zcash.Cli/Strings.ko.resx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@
<data name="TestNetOptionDescription" xml:space="preserve">
<value>메인넷 대신 테스트넷에서 계정을 사용할 것을 나타냅니다.</value>
</data>
<data name="TexCommandDescription" xml:space="preserve">
<value>투명한 주소를 TEX 주소로 변환합니다.</value>
</data>
<data name="TexTransparentAddressArgumentDescription" xml:space="preserve">
<value>변환 할 투명한 주소.</value>
</data>
<data name="TransparentP2PKHAddressRequired" xml:space="preserve">
<value>P2PKH 투명 주소가 필요합니다.</value>
</data>
<data name="UACommandDescription" xml:space="preserve">
<value>UA 주소를 인코딩하거나 디코딩합니다.</value>
</data>
Expand All @@ -273,4 +282,4 @@
<data name="WalletPathArgumentDescription" xml:space="preserve">
<value>지갑 파일의 경로입니다.</value>
</data>
</root>
</root>
11 changes: 10 additions & 1 deletion src/Nerdbank.Zcash.Cli/Strings.pt.resx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@
<data name="TestNetOptionDescription" xml:space="preserve">
<value>Indica que a conta será usada em uma testnet em vez de mainnet.</value>
</data>
<data name="TexCommandDescription" xml:space="preserve">
<value>Converte um endereço transparente em um endereço TEX.</value>
</data>
<data name="TexTransparentAddressArgumentDescription" xml:space="preserve">
<value>O endereço transparente para converter.</value>
</data>
<data name="TransparentP2PKHAddressRequired" xml:space="preserve">
<value>É necessário um endereço transparente P2PKH.</value>
</data>
<data name="UACommandDescription" xml:space="preserve">
<value>Codifica ou decodifica endereços UA.</value>
</data>
Expand All @@ -273,4 +282,4 @@
<data name="WalletPathArgumentDescription" xml:space="preserve">
<value>O caminho para o arquivo da carteira.</value>
</data>
</root>
</root>
9 changes: 9 additions & 0 deletions src/Nerdbank.Zcash.Cli/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@
<data name="TestNetOptionDescription" xml:space="preserve">
<value>Indicates the account will be used on a testnet instead of mainnet.</value>
</data>
<data name="TexCommandDescription" xml:space="preserve">
<value>Converts a transparent address into a TEX address.</value>
</data>
<data name="TexTransparentAddressArgumentDescription" xml:space="preserve">
<value>The transparent address to convert.</value>
</data>
<data name="TransparentP2PKHAddressRequired" xml:space="preserve">
<value>A P2PKH transparent address is required.</value>
</data>
<data name="UACommandDescription" xml:space="preserve">
<value>Encodes or decodes UA addresses.</value>
</data>
Expand Down
9 changes: 9 additions & 0 deletions src/Nerdbank.Zcash.Cli/Strings.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@
<data name="TestNetOptionDescription" xml:space="preserve">
<value>Указывает, что учетная запись будет использоваться в Testnet вместо Mainnet.</value>
</data>
<data name="TexCommandDescription" xml:space="preserve">
<value>Преобразует прозрачный адрес в адрес TEX.</value>
</data>
<data name="TexTransparentAddressArgumentDescription" xml:space="preserve">
<value>Прозрачный адрес для конвертации.</value>
</data>
<data name="TransparentP2PKHAddressRequired" xml:space="preserve">
<value>Требуется прозрачный адрес P2PKH.</value>
</data>
<data name="UACommandDescription" xml:space="preserve">
<value>Кодирует или декодирует адреса UA.</value>
</data>
Expand Down
11 changes: 10 additions & 1 deletion src/Nerdbank.Zcash.Cli/Strings.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@
<data name="TestNetOptionDescription" xml:space="preserve">
<value>指示该账户将在测试网而不是主网上使用。</value>
</data>
<data name="TexCommandDescription" xml:space="preserve">
<value>将透明的地址转换为TEX地址。</value>
</data>
<data name="TexTransparentAddressArgumentDescription" xml:space="preserve">
<value>转换的透明地址。</value>
</data>
<data name="TransparentP2PKHAddressRequired" xml:space="preserve">
<value>需要P2PKH透明地址。</value>
</data>
<data name="UACommandDescription" xml:space="preserve">
<value>编码或解码 UA 地址。</value>
</data>
Expand All @@ -273,4 +282,4 @@
<data name="WalletPathArgumentDescription" xml:space="preserve">
<value>钱包文件的路径。</value>
</data>
</root>
</root>
52 changes: 52 additions & 0 deletions src/Nerdbank.Zcash.Cli/TexCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Andrew Arnott. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.CommandLine;
using System.CommandLine.IO;

namespace Nerdbank.Zcash.Cli;

internal class TexCommand
{
internal required IConsole Console { get; init; }

internal required string TransparentAddress { get; init; }

internal static Command BuildCommand()
{
Argument<string> transparentAddressArgument = new("transparentAddress", Strings.TexTransparentAddressArgumentDescription) { Arity = ArgumentArity.ExactlyOne };
Command command = new Command("tex", Strings.TexCommandDescription)
{
transparentAddressArgument,
};

command.SetHandler(ctxt =>
{
ctxt.ExitCode = new TexCommand
{
Console = ctxt.Console,
TransparentAddress = ctxt.ParseResult.GetValueForArgument(transparentAddressArgument),
}.Execute(ctxt.GetCancellationToken());
});
return command;
}

private int Execute(CancellationToken cancellationToken)
{
if (!ZcashAddress.TryDecode(this.TransparentAddress, out _, out string? errorMessage, out ZcashAddress? result))
{
this.Console.Error.WriteLine(errorMessage);
return 1;
}

if (result is not TransparentP2PKHAddress tAddr)
{
this.Console.Error.WriteLine(Strings.TransparentP2PKHAddressRequired);
return 2;
}

TexAddress tex = new(tAddr);
this.Console.WriteLine(tex);
return 0;
}
}

0 comments on commit 514457f

Please sign in to comment.