Skip to content

Instantly share code, notes, and snippets.

@Shadow0ps
Forked from mathiasrw/hash160-to-base58.go
Created April 10, 2019 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shadow0ps/2da8d2e8a4cb48d92763b287cfc6966d to your computer and use it in GitHub Desktop.
Save Shadow0ps/2da8d2e8a4cb48d92763b287cfc6966d 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)
}
}
@peterzion45
Copy link

hash160:d5a29167b6a63e1918bdaec5ca95e861bd253d49 (M/1H/0/21)

@peterzion45
Copy link

hash160:d5a29167b6a63e1918bdaec5ca95e861bd253d49 (M/1H/0/21)

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