// Initialise big numbers with small numbers
count, one := big.NewInt(0), big.NewInt(10000)
// Create a slice to pad our count to 32 bytes
padded := make([]byte, 32)
// Loop forever because we're never going to hit the end anyway
for {
// Increment our counter
count.Add(count, one)
// Copy count value's bytes to padded slice
copy(padded[32-len(count.Bytes()):], count.Bytes())
// Get public key
_, public := btcec.PrivKeyFromBytes(btcec.S256(), padded)
// Get compressed and uncompressed addresses
caddr, _ := btcutil.NewAddressPubKey(public.SerializeCompressed(), &chaincfg.MainNetParams)
decoded, version, err := base58.CheckDecode(caddr.EncodeAddress())
if err != nil {
fmt.Println(err)
return
}
// Print keys
fmt.Printf("%x %34s %49s", padded, caddr.EncodeAddress(), big.NewInt(0).SetBytes(decoded))
fmt.Println("", version)
}
In the example that you have provided, you will loop forever so you can not just write an infinite loop to a file without running out of space.
Here is an example of how you can write a formatted string to a file once you work out what you are actually trying to store:
package main
import (
"fmt"
"log"
"os"
)
func main() {
// Create a formatted string to write to a file.
str := fmt.Sprintf("%64s %34s %49s", "Private", "Public", "decoded")
// Create a new file called file.txt.
f, err := os.Create("file.txt")
if err != nil {
log.Fatalln(err)
}
// Close the file when we're done.
defer f.Close()
// Write the string str to the file.
_, err = f.WriteString(str)
if err != nil {
log.Fatalln(err)
}
}
Lastly, based on your 2 questions here so far, I suggest that you go through A Tour of Go and also at least something else like Go by Example so you can learn to understand the basics of Go a little bit better.
If my previous reply is too difficult to understand, here’s an easier helper method to write a string to a file, but I still suggest you trying to learn from the 2 links that I posted above:
package main
import (
"fmt"
"io/ioutil"
"log"
)
func main() {
// Create a formatted string to write to a file.
str := fmt.Sprintf("%64s %34s %49s", "Private", "Public", "decoded")
// Create and write to a new file called file.txt.
if err := ioutil.WriteFile("file.txt", []byte(str), 0644); err != nil {
log.Fatalln(err)
}
}
If you cannot see why your for loop produces this output, I strongly suggest following Benjamin’s advice and learn the basics of the language from a good tutorial or course. It may cost you a little time now but it will pay enormously in the long run.