Skip to content

Instantly share code, notes, and snippets.

@joe-p

joe-p/main.go Secret

Created July 21, 2022 19:27
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 joe-p/ff3dfd382ccc2a9a0420dcf8c2e6ba60 to your computer and use it in GitHub Desktop.
Save joe-p/ff3dfd382ccc2a9a0420dcf8c2e6ba60 to your computer and use it in GitHub Desktop.
Algorand app address lookup table
package main
import (
"bufio"
"fmt"
"log"
"os"
"time"
"github.com/algorand/go-algorand-sdk/crypto"
"github.com/algorand/go-algorand-sdk/types"
)
var addresses [10_000_000]types.Address
var index int
func getAddr(appID uint64) {
if index == 10_000_000 {
appendToFile()
index = 0
}
addresses[index] = crypto.GetApplicationAddress(appID)
index++
}
func getAddresses(start uint64, end uint64) {
for i := start; i < end; i++ {
getAddr(i)
}
}
func appendToFile() {
file, err := os.OpenFile("table.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatalf("failed creating file: %s", err)
}
datawriter := bufio.NewWriter(file)
for _, addr := range addresses {
_, _ = datawriter.WriteString(addr.String() + "\n")
}
datawriter.Flush()
file.Close()
}
func main() {
start := time.Now()
index = 0
getAddresses(1, 100_000_000)
fmt.Println(time.Since(start))
appendToFile()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment