-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## 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.
- Loading branch information
Showing
30 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://www.gnu.org/licenses/>. | ||
|
||
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()) | ||
} |