From 22a5ebbbe9707f9cce706bcff11347bcf7217e06 Mon Sep 17 00:00:00 2001 From: Will Winder Date: Mon, 20 Dec 2021 08:35:53 -0500 Subject: [PATCH] Add convertAddress tool. (#3304) ## Summary New tool: convertAddress I share this tool with someone every few months, putting it in the repo along with some documentation should make it easier to share and encourage people to share it amongst themselves if it's useful. Merge `debug` into `tools` to make it easier to organize these miscellaneous tools. --- README.md | 5 +- tools/README.md | 20 ++++++++ {debug => tools/debug}/carpenter/main.go | 0 {debug => tools/debug}/coroner/main.go | 0 {debug => tools/debug}/doberman/logo.go | 0 {debug => tools/debug}/doberman/main.go | 0 .../debug}/genconsensusconfig/main.go | 0 {debug => tools/debug}/jslog | 0 {debug => tools/debug}/logfilter/example1.in | 0 .../debug}/logfilter/example1.out.expected | 0 {debug => tools/debug}/logfilter/example2.in | 0 .../debug}/logfilter/example2.out.expected | 0 {debug => tools/debug}/logfilter/example3.in | 0 .../debug}/logfilter/example3.out.expected | 0 {debug => tools/debug}/logfilter/example4.in | 0 .../debug}/logfilter/example4.out.expected | 0 {debug => tools/debug}/logfilter/example5.in | 0 .../debug}/logfilter/example5.out.expected | 0 {debug => tools/debug}/logfilter/example6.in | 0 .../debug}/logfilter/example6.out.expected | 0 {debug => tools/debug}/logfilter/example7.in | 0 .../debug}/logfilter/example7.out.expected | 0 {debug => tools/debug}/logfilter/example8.in | 0 .../debug}/logfilter/example8.out.expected | 0 {debug => tools/debug}/logfilter/main.go | 0 {debug => tools/debug}/logfilter/main_test.go | 0 {debug => tools/debug}/net.py | 0 {debug => tools/debug}/showchains.py | 0 tools/misc/README.md | 31 +++++++++++ tools/misc/convertAddress.go | 51 +++++++++++++++++++ 30 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 tools/README.md rename {debug => tools/debug}/carpenter/main.go (100%) rename {debug => tools/debug}/coroner/main.go (100%) rename {debug => tools/debug}/doberman/logo.go (100%) rename {debug => tools/debug}/doberman/main.go (100%) rename {debug => tools/debug}/genconsensusconfig/main.go (100%) rename {debug => tools/debug}/jslog (100%) rename {debug => tools/debug}/logfilter/example1.in (100%) rename {debug => tools/debug}/logfilter/example1.out.expected (100%) rename {debug => tools/debug}/logfilter/example2.in (100%) rename {debug => tools/debug}/logfilter/example2.out.expected (100%) rename {debug => tools/debug}/logfilter/example3.in (100%) rename {debug => tools/debug}/logfilter/example3.out.expected (100%) rename {debug => tools/debug}/logfilter/example4.in (100%) rename {debug => tools/debug}/logfilter/example4.out.expected (100%) rename {debug => tools/debug}/logfilter/example5.in (100%) rename {debug => tools/debug}/logfilter/example5.out.expected (100%) rename {debug => tools/debug}/logfilter/example6.in (100%) rename {debug => tools/debug}/logfilter/example6.out.expected (100%) rename {debug => tools/debug}/logfilter/example7.in (100%) rename {debug => tools/debug}/logfilter/example7.out.expected (100%) rename {debug => tools/debug}/logfilter/example8.in (100%) rename {debug => tools/debug}/logfilter/example8.out.expected (100%) rename {debug => tools/debug}/logfilter/main.go (100%) rename {debug => tools/debug}/logfilter/main_test.go (100%) rename {debug => tools/debug}/net.py (100%) rename {debug => tools/debug}/showchains.py (100%) create mode 100644 tools/misc/README.md create mode 100644 tools/misc/convertAddress.go diff --git a/README.md b/README.md index a5c0487c35..664bd207d6 100644 --- a/README.md +++ b/README.md @@ -164,13 +164,14 @@ The following packages allow developers to interface with the Algorand system: - `cmd/catchupsrv` ([README](cmd/catchupsrv/README.md)) is a tool to assist with processing historic blocks on a new node. - `libgoal` exports a Go interface useful for developers of Algorand clients. - - `debug` holds secondary commands which assist developers during debugging. + - `tools` ([README](tools/README.md)) various tools and utilities without a better place to go. + - `tools/debug` holds secondary commands which assist developers during debugging. + - `tools/misc` ([README](tools/misc/README.md)) small tools that are sometimes handy in a pinch. The following packages contain tools to help Algorand developers deploy networks of their own: - `nodecontrol` - - `tools` - `docker` - `commandandcontrol` ([README](test/commandandcontrol/README.md)) is a tool to automate a network of algod instances. diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 0000000000..b8394ac775 --- /dev/null +++ b/tools/README.md @@ -0,0 +1,20 @@ +# Misfit Tools + +Various tools and utilities that don't have a better place to go. + +### debug + +Tools for debugging algod. These were really useful before launch when we spent a lot of time analyzing node behavior, but aren't needed as much recently. + +### misc + +Small tools that are useful in niche situations. + +### network + +This is a go package used by some of the CLI commands. + +### TEAL + +Some of the earliest tools we built for working with TEAL programs. A lot of these are workarounds for things that no longer need to be worked around, but these are still nice examples of what TEAL can do. + diff --git a/debug/carpenter/main.go b/tools/debug/carpenter/main.go similarity index 100% rename from debug/carpenter/main.go rename to tools/debug/carpenter/main.go diff --git a/debug/coroner/main.go b/tools/debug/coroner/main.go similarity index 100% rename from debug/coroner/main.go rename to tools/debug/coroner/main.go diff --git a/debug/doberman/logo.go b/tools/debug/doberman/logo.go similarity index 100% rename from debug/doberman/logo.go rename to tools/debug/doberman/logo.go diff --git a/debug/doberman/main.go b/tools/debug/doberman/main.go similarity index 100% rename from debug/doberman/main.go rename to tools/debug/doberman/main.go diff --git a/debug/genconsensusconfig/main.go b/tools/debug/genconsensusconfig/main.go similarity index 100% rename from debug/genconsensusconfig/main.go rename to tools/debug/genconsensusconfig/main.go diff --git a/debug/jslog b/tools/debug/jslog similarity index 100% rename from debug/jslog rename to tools/debug/jslog diff --git a/debug/logfilter/example1.in b/tools/debug/logfilter/example1.in similarity index 100% rename from debug/logfilter/example1.in rename to tools/debug/logfilter/example1.in diff --git a/debug/logfilter/example1.out.expected b/tools/debug/logfilter/example1.out.expected similarity index 100% rename from debug/logfilter/example1.out.expected rename to tools/debug/logfilter/example1.out.expected diff --git a/debug/logfilter/example2.in b/tools/debug/logfilter/example2.in similarity index 100% rename from debug/logfilter/example2.in rename to tools/debug/logfilter/example2.in diff --git a/debug/logfilter/example2.out.expected b/tools/debug/logfilter/example2.out.expected similarity index 100% rename from debug/logfilter/example2.out.expected rename to tools/debug/logfilter/example2.out.expected diff --git a/debug/logfilter/example3.in b/tools/debug/logfilter/example3.in similarity index 100% rename from debug/logfilter/example3.in rename to tools/debug/logfilter/example3.in diff --git a/debug/logfilter/example3.out.expected b/tools/debug/logfilter/example3.out.expected similarity index 100% rename from debug/logfilter/example3.out.expected rename to tools/debug/logfilter/example3.out.expected diff --git a/debug/logfilter/example4.in b/tools/debug/logfilter/example4.in similarity index 100% rename from debug/logfilter/example4.in rename to tools/debug/logfilter/example4.in diff --git a/debug/logfilter/example4.out.expected b/tools/debug/logfilter/example4.out.expected similarity index 100% rename from debug/logfilter/example4.out.expected rename to tools/debug/logfilter/example4.out.expected diff --git a/debug/logfilter/example5.in b/tools/debug/logfilter/example5.in similarity index 100% rename from debug/logfilter/example5.in rename to tools/debug/logfilter/example5.in diff --git a/debug/logfilter/example5.out.expected b/tools/debug/logfilter/example5.out.expected similarity index 100% rename from debug/logfilter/example5.out.expected rename to tools/debug/logfilter/example5.out.expected diff --git a/debug/logfilter/example6.in b/tools/debug/logfilter/example6.in similarity index 100% rename from debug/logfilter/example6.in rename to tools/debug/logfilter/example6.in diff --git a/debug/logfilter/example6.out.expected b/tools/debug/logfilter/example6.out.expected similarity index 100% rename from debug/logfilter/example6.out.expected rename to tools/debug/logfilter/example6.out.expected diff --git a/debug/logfilter/example7.in b/tools/debug/logfilter/example7.in similarity index 100% rename from debug/logfilter/example7.in rename to tools/debug/logfilter/example7.in diff --git a/debug/logfilter/example7.out.expected b/tools/debug/logfilter/example7.out.expected similarity index 100% rename from debug/logfilter/example7.out.expected rename to tools/debug/logfilter/example7.out.expected diff --git a/debug/logfilter/example8.in b/tools/debug/logfilter/example8.in similarity index 100% rename from debug/logfilter/example8.in rename to tools/debug/logfilter/example8.in diff --git a/debug/logfilter/example8.out.expected b/tools/debug/logfilter/example8.out.expected similarity index 100% rename from debug/logfilter/example8.out.expected rename to tools/debug/logfilter/example8.out.expected diff --git a/debug/logfilter/main.go b/tools/debug/logfilter/main.go similarity index 100% rename from debug/logfilter/main.go rename to tools/debug/logfilter/main.go diff --git a/debug/logfilter/main_test.go b/tools/debug/logfilter/main_test.go similarity index 100% rename from debug/logfilter/main_test.go rename to tools/debug/logfilter/main_test.go diff --git a/debug/net.py b/tools/debug/net.py similarity index 100% rename from debug/net.py rename to tools/debug/net.py diff --git a/debug/showchains.py b/tools/debug/showchains.py similarity index 100% rename from debug/showchains.py rename to tools/debug/showchains.py diff --git a/tools/misc/README.md b/tools/misc/README.md new file mode 100644 index 0000000000..8a94102b08 --- /dev/null +++ b/tools/misc/README.md @@ -0,0 +1,31 @@ +# Misc Tools + +Collection of various tools that are useful enough to save, but niche enough that they don't belong in goal. + + +### convertAddress + +It's sometimes useful to convert addresses between the public "Stripped Base32 /w checksum" format, and the Base64 encoded 32 byte format. This tool converts the two formats. + +There is only very minor error checking, results from this tool to not ensure valid inputs. + +```sh +# Address to Base64 encoded bytes. +~$ go run convertAddress.go -addr E33YVTQNYH2BHI33OCYL7JQQSEMXD4EN74CZQ37FC6EZFHIBCNWOWXIZ5M +JveKzg3B9BOje3Cwv6YQkRlx8I3/BZhv5ReJkp0BE2w= + +# Base64 encoded bytes to Address. +~$ go run convertAddress.go -addr JveKzg3B9BOje3Cwv6YQkRlx8I3/BZhv5ReJkp0BE2w= +E33YVTQNYH2BHI33OCYL7JQQSEMXD4EN74CZQ37FC6EZFHIBCNWOWXIZ5M + +``` + +If you want to run it more than once, it may be useful to compile a binary rather than building with `go run` on each invokation: +```sh +# Build binary. +~$ go build convertAddress.go + +# Use binary. +~$ ./convertAddress -addr JveKzg3B9BOje3Cwv6YQkRlx8I3/BZhv5ReJkp0BE2w= +E33YVTQNYH2BHI33OCYL7JQQSEMXD4EN74CZQ37FC6EZFHIBCNWOWXIZ5M +``` diff --git a/tools/misc/convertAddress.go b/tools/misc/convertAddress.go new file mode 100644 index 0000000000..90cdf74b1f --- /dev/null +++ b/tools/misc/convertAddress.go @@ -0,0 +1,51 @@ +// Copyright (C) 2019-2021 Algorand, Inc. +// This file is part of go-algorand +// +// go-algorand is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// go-algorand is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with go-algorand. If not, see . + +package main + +import ( + "encoding/base64" + "flag" + "fmt" + + "github.com/algorand/go-algorand/data/basics" +) + +func main() { + var addrInput string + flag.StringVar(&addrInput, "addr", "", "base64/algorand address to convert to the other") + flag.Parse() + + if addrInput == "" { + fmt.Println("provide input with '-addr' flag.") + return + } + + addrBytes, err := base64.StdEncoding.DecodeString(addrInput) + if err != nil { + // Failed to base64 decode, check for Algorand address format. + a, err := basics.UnmarshalChecksumAddress(addrInput) + if err != nil { + fmt.Println(err) + return + } + fmt.Println(base64.StdEncoding.EncodeToString(a[:])) + return + } + var addr basics.Address + copy(addr[:], addrBytes) + fmt.Println(addr.String()) +}