github.com/mit-dci/lit@v0.0.0-20221102210550-8c3d3b49f2ce/btcutil/base58/genalphabet.go (about)

     1  // Copyright (c) 2015 The btcsuite developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  //+build ignore
     6  
     7  package main
     8  
     9  import (
    10  	"bytes"
    11  	"io"
    12  	"os"
    13  	"strconv"
    14  
    15  	"github.com/mit-dci/lit/logging"
    16  )
    17  
    18  var (
    19  	start = []byte(`// Copyright (c) 2015 The btcsuite developers
    20  // Use of this source code is governed by an ISC
    21  // license that can be found in the LICENSE file.
    22  
    23  // AUTOGENERATED by genalphabet.go; do not edit.
    24  
    25  package base58
    26  
    27  const (
    28  	// alphabet is the modified base58 alphabet used by Bitcoin.
    29  	alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
    30  
    31  	alphabetIdx0 = '1'
    32  )
    33  
    34  var b58 = [256]byte{`)
    35  
    36  	end = []byte(`}`)
    37  
    38  	alphabet = []byte("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
    39  	tab      = []byte("\t")
    40  	invalid  = []byte("255")
    41  	comma    = []byte(",")
    42  	space    = []byte(" ")
    43  	nl       = []byte("\n")
    44  )
    45  
    46  func write(w io.Writer, b []byte) {
    47  	_, err := w.Write(b)
    48  	if err != nil {
    49  		logging.Fatal(err)
    50  	}
    51  }
    52  
    53  func main() {
    54  	fi, err := os.Create("alphabet.go")
    55  	if err != nil {
    56  		logging.Fatal(err)
    57  	}
    58  	defer fi.Close()
    59  
    60  	write(fi, start)
    61  	write(fi, nl)
    62  	for i := byte(0); i < 32; i++ {
    63  		write(fi, tab)
    64  		for j := byte(0); j < 8; j++ {
    65  			idx := bytes.IndexByte(alphabet, i*8+j)
    66  			if idx == -1 {
    67  				write(fi, invalid)
    68  			} else {
    69  				write(fi, strconv.AppendInt(nil, int64(idx), 10))
    70  			}
    71  			write(fi, comma)
    72  			if j != 7 {
    73  				write(fi, space)
    74  			}
    75  		}
    76  		write(fi, nl)
    77  	}
    78  	write(fi, end)
    79  	write(fi, nl)
    80  }