-
-
Save Shadow0ps/2da8d2e8a4cb48d92763b287cfc6966d to your computer and use it in GitHub Desktop.
Convert hash160 hex strings to bitcoin bae58 address
This file contains hidden or 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
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) | |
} | |
} |
hash160:d5a29167b6a63e1918bdaec5ca95e861bd253d49 (M/1H/0/21)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hash160:d5a29167b6a63e1918bdaec5ca95e861bd253d49 (M/1H/0/21)