Skip to content

Instantly share code, notes, and snippets.

@mathiasrw
Created January 25, 2018 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mathiasrw/af6f4901cf526853f7df5c4c581cc33e to your computer and use it in GitHub Desktop.
Save mathiasrw/af6f4901cf526853f7df5c4c581cc33e to your computer and use it in GitHub Desktop.
Convert hash160 hex strings to bitcoin bae58 address
package main
import (
"bufio"
"encoding/hex"
"fmt"
"github.com/btcsuite/btcutil/base58"
"log"
"os"
)
const hash160Length = 40
func main() {
if len(os.Args) < 2 {
log.Fatal("Please provide filename with one hash160 hex strings on each line")
}
arg := os.Args[1]
// Open the file.
file, err := os.Open(arg)
if err != nil {
log.Fatal(err)
}
// Create a new Scanner for the file.
scanner := bufio.NewScanner(file)
// Loop over all lines in the file
for scanner.Scan() {
line := scanner.Text()
// Check if length is correct
if len(line) != hash160Length {
continue
}
// Decode, and ignore errors
decoded, err := hex.DecodeString(line)
if err != nil {
//log.Fatal(err)
continue
}
base58 := base58.CheckEncode(decoded, 0x00)
fmt.Printf("%s\n", base58)
}
}
@Uvname
Copy link

Uvname commented Sep 15, 2019

Hello, please tell me how to run it?

@mathiasrw
Copy link
Author

Build it with go and run it with a filename as parameter

@kaanalican
Copy link

is there the opposite

@mathiasrw
Copy link
Author

@kaanalican Have a look at github.com/btcsuite/btcutil

@rawrmoto
Copy link

how to run this code in python, any tutorial videos or something thankyouuu.

@rawrmoto
Copy link

its just says that expected package found bufio, how to fix it?/ thankyouuu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment