Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Hello this is Liugnum
- we're gonna write a program
- cleaned by 1lann
- @author Lignum
- @date 27/08/2017
- */
- package main
- import (
- "bufio"
- "bytes"
- "encoding/json"
- "fmt"
- "io"
- "net/http"
- "os"
- "strings"
- )
- const Header = "KCH"
- const Password = "dljkqwndw"
- func printBanner() {
- fmt.Println("KristChatGo booting up like afuckign rocket flies into spice...")
- }
- func readMessageLoop() {
- type TransactionResponse struct {
- Ok bool
- Transactions []struct {
- From string
- To string
- Value int
- Metadata string
- }
- }
- resp, err := http.Get("https://krist.ceriat.net/transactions/latest")
- if err != nil {
- panic(err)
- }
- defer resp.Body.Close()
- var response TransactionResponse
- if err := json.NewDecoder(resp.Body).Decode(&response); err != nil {
- panic(err)
- }
- for _, tr := range response.Transactions {
- if strings.HasPrefix(tr.Metadata, Header) {
- fmt.Println(strings.TrimPrefix(tr.Metadata, Header))
- }
- }
- }
- func messageSend() {
- type SendTransaction struct {
- PrivateKey string `json:"privatekey"`
- To string `json:"to"`
- Amount int `json:"amount"`
- Metadata string `json:"metadata"`
- }
- fmt.Println("address")
- var address string
- if _, err := fmt.Scanf("%s\n", &address); err != nil {
- panic("ok bye")
- }
- fmt.Println("message")
- var message string
- if _, err := fmt.Scanf("%s\n", &message); err != nil {
- panic("ok bye")
- }
- txJSON, _ := json.Marshal(SendTransaction{
- To: address,
- PrivateKey: Password,
- Amount: 1,
- Metadata: Header + message,
- })
- fmt.Println(string(txJSON))
- resp, err := http.Post("https://krist.ceriat.net/transactions",
- "application/json", bytes.NewReader(txJSON))
- if err != nil {
- panic(err)
- }
- defer resp.Body.Close()
- if _, err := io.Copy(os.Stdout, resp.Body); err != nil {
- panic(err)
- }
- os.Stdout.Write([]byte{'\n'})
- }
- func main() {
- printBanner()
- scanner := bufio.NewScanner(os.Stdin)
- for scanner.Scan() {
- fmt.Println("type read or send")
- switch scanner.Text() {
- case "read":
- readMessageLoop()
- case "send":
- messageSend()
- default:
- panic("panic")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement