Advertisement
Guest User

Untitled

a guest
Nov 24th, 2018
989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 3.23 KB | None | 0 0
  1. //
  2. // YOBA BRAIN v0.1
  3. //
  4.  
  5. package main
  6.  
  7. import (
  8.     "crypto/rand"
  9.     "encoding/json"
  10.     "fmt"
  11.     "github.com/vsergeev/btckeygenie/btckey"
  12.     "io/ioutil"
  13.     "os"
  14.     "net/http"
  15. )
  16.  
  17. func Generate() (string, string, string, error) {
  18.  
  19.     private, err := btckey.GenerateKey(rand.Reader)
  20.     if err != nil {
  21.         return "", "", "", err
  22.     }
  23.    
  24.     addressCompressed := private.ToAddress()
  25.     addressUncompressed := private.ToAddressUncompressed()
  26.     wif := private.ToWIF()
  27.  
  28.     return wif, addressUncompressed, addressCompressed, nil
  29. }
  30.  
  31. func Check(address string) (float64, float64, int, error) {
  32.    
  33.     resp, err := http.Get("https://blockchain.info/balance?active=" + address)
  34.     if err != nil {
  35.         return 0, 0, 0, err
  36.     }
  37.    
  38.     defer resp.Body.Close()
  39.     body, err := ioutil.ReadAll(resp.Body)
  40.     if err != nil {
  41.         return 0, 0, 0, err
  42.     }
  43.    
  44.     var unmarshaled map[string]interface{}
  45.     err = json.Unmarshal(body, &unmarshaled)
  46.     if err != nil {
  47.         return 0, 0, 0, err
  48.     }
  49.    
  50.     unmarshaled = unmarshaled[address].(map[string]interface{})
  51.     finalBalance := unmarshaled["final_balance"].(float64)
  52.     totalReceived := unmarshaled["total_received"].(float64)
  53.     nTx := int(unmarshaled["n_tx"].(float64))
  54.    
  55.     return finalBalance, totalReceived, nTx, nil
  56. }
  57.  
  58. func Log(verbose bool, wif, addressUncompressed, addressCompressed string,
  59.          finalBalance, totalReceived float64, nTx int) {
  60.    
  61.     if finalBalance != 0 || totalReceived != 0 || nTx != 0 {
  62.         output := fmt.Sprintf("[%f/%f/%d] %s %s %s\n",
  63.                              finalBalance, totalReceived, nTx,
  64.                              wif, addressUncompressed, addressCompressed)
  65.         fmt.Printf(output)
  66.         ioutil.WriteFile("brain.txt", []byte(output), os.ModeAppend)
  67.         return
  68.     }
  69.    
  70.     if verbose {
  71.         fmt.Printf("[%f/%f/%d] %s %s %s\n", finalBalance, totalReceived, nTx,
  72.                    wif, addressUncompressed, addressCompressed)
  73.     }
  74. }
  75.  
  76. func main() {
  77.  
  78.     if len(os.Args) > 1 && (os.Args[1] == "-h") {
  79.         fmt.Printf("Usage: %s [-v|-h]\n\n", os.Args[0])
  80.         fmt.Println("YOBA BRAIN v0.1");
  81.         os.Exit(0)
  82.     }
  83.    
  84.     verbose := false
  85.     if len(os.Args) > 1 && (os.Args[1] == "-v") {
  86.         verbose = true
  87.     }
  88.    
  89.     fmt.Println("Ну че, народ, погнали, наxуй!");
  90.  
  91.     for true {
  92.        
  93.         wif, addressUncompressed, addressCompressed, err := Generate()
  94.         if err != nil {
  95.             fmt.Println("Произошла какая-то хуйня, но мне похуй!")
  96.             if verbose == true {
  97.                 fmt.Println("Подробности: ", err)
  98.             }
  99.             continue
  100.         }
  101.        
  102.         finalBalance, nTx, totalReceived, err := Check(addressUncompressed)
  103.         if err != nil {
  104.             fmt.Println("Произошла какая-то хуйня, но мне похуй!")
  105.             if verbose == true {
  106.                 fmt.Println("Подробности: ", err)
  107.             }
  108.             continue
  109.         }
  110.        
  111.         Log(verbose, wif, addressUncompressed, addressCompressed,
  112.             finalBalance, nTx, totalReceived)
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement