Created
January 25, 2018 09:48
-
-
Save mathiasrw/af6f4901cf526853f7df5c4c581cc33e to your computer and use it in GitHub Desktop.
Convert hash160 hex strings to bitcoin bae58 address
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
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) | |
} | |
} |
Build it with go and run it with a filename as parameter
is there the opposite
@kaanalican Have a look at github.com/btcsuite/btcutil
how to run this code in python, any tutorial videos or something thankyouuu.
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
Hello, please tell me how to run it?