github.com/aidoskuneen/adk-node@v0.0.0-20220315131952-2e32567cb7f4/adkgo-GENESIS/known_addresses/load-known.go (about) 1 // Copyright 2021 The adkgo Authors 2 // This file is part of adkgo. 3 // 4 // adkgo is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // adkgo is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with adkgo. If not, see <http://www.gnu.org/licenses/>. 16 17 package main 18 19 import ( 20 "fmt" 21 "os" 22 "log" 23 "bufio" 24 "github.com/AidosKuneen/gadk" 25 ) 26 27 type AddressValue struct { 28 Address string `json:"Address"` 29 Value string `json:"Value"` 30 } 31 32 type RichList struct { 33 CreatedOn string `json:"CreatedOn"` 34 UpdatingEvery string `json:"UpdatingEvery"` 35 Lists []AddressValue `json:"Lists"` 36 Total float64 `json:"Total"` 37 } 38 39 func main() { 40 41 file, err := os.Open("known_addresses_at_genesis.txt") 42 if err != nil { 43 log.Fatal(err) 44 } 45 defer file.Close() 46 47 scanner := bufio.NewScanner(file) 48 //dummy transaction 49 var trs9 string; 50 trs9 = "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"; 51 52 //_, pow := gadk.GetBestPoW() 53 54 var addrs []string 55 var trxs []string 56 var bundles []string 57 58 cnt := 0 59 for scanner.Scan() { 60 addrs = append(addrs, scanner.Text()[0:81]) 61 62 dummyTransaction := trs9[:2187]+scanner.Text()+trs9[2268:2349]+"MIGRATED"+scanner.Text()[8:]+trs9[2349+81:] 63 fmt.Println(scanner.Text(), len(dummyTransaction)) 64 cnt++ 65 trytes2,err2:=gadk.ToTrytes(dummyTransaction) 66 if err2 != nil { 67 log.Fatal(err2) 68 } 69 //transaction 70 tx,err3:=gadk.NewTransaction(trytes2) 71 72 bundleHash := GetBundleHash(*tx) // calculate bundle hash 73 tx.Bundle = bundleHash 74 75 if err3 != nil { 76 log.Fatal(err3) 77 } 78 trxs = append(trxs,(string(tx.Hash()))[0:81]) 79 bundles = append( bundles, (string(tx.Bundle))) 80 //} 81 fmt.Println("Transaction",cnt, tx.Hash()) 82 } 83 84 if err := scanner.Err(); err != nil { 85 log.Fatal(err) 86 } 87 88 fmt.Print("writing to file template.txt") 89 90 f, err5 := os.OpenFile("template.txt", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) 91 if err5 != nil { 92 log.Fatal(err5) 93 } 94 defer f.Close() 95 96 if (len(addrs) != len(trxs) || len(addrs) != len(bundles) ){ 97 log.Fatal("len missmatch") 98 } 99 100 //fmt.Fprintf(f, "%d", len(b)) 101 fmt.Fprintf(f, "package main\n\n") 102 fmt.Fprintf(f, "var knownAddressesStr string = `\n") 103 for _, line := range addrs { 104 fmt.Fprintf(f, line) 105 fmt.Fprintf(f, "\n") 106 } 107 fmt.Fprintf(f, "`") 108 fmt.Fprintf(f, "\n") 109 fmt.Fprintf(f, "\n") 110 fmt.Fprintf(f, "var knownAddressesTransactions string = `\n") 111 for _, line2 := range trxs { 112 fmt.Fprintf(f, line2) 113 fmt.Fprintf(f, "\n") 114 } 115 fmt.Fprintf(f, "`") 116 fmt.Fprintf(f, "\n") 117 118 fmt.Fprintf(f, "var knownBundleStr string = `\n") 119 for _, line3 := range bundles { 120 fmt.Fprintf(f, line3) 121 fmt.Fprintf(f, "\n") 122 } 123 fmt.Fprintf(f, "`") 124 fmt.Fprintf(f, "\n") 125 fmt.Fprintf(f, "\n") 126 127 fmt.Print("completed") 128 } 129 130 func GetBundleHash(b gadk.Transaction) gadk.Trytes { 131 c := gadk.NewCurl() 132 buf := make(gadk.Trits, 243+81*3) 133 134 copy(buf, gadk.Trytes(b.Address).Trits()) 135 copy(buf[243:], gadk.Int2Trits(b.Value, 81)) 136 copy(buf[243+81:], b.Tag.Trits()) 137 copy(buf[243+81+81:], gadk.Int2Trits(b.Timestamp.Unix(), 27)) 138 copy(buf[243+81+81+27:], gadk.Int2Trits(int64(0), 27)) //CurrentIndex 139 copy(buf[243+81+81+27+27:], gadk.Int2Trits(int64(0), 27)) //LastIndex 140 c.Absorb(buf.Trytes()) 141 142 return c.Squeeze() 143 }