-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateAccounts_Web.go
More file actions
120 lines (100 loc) · 2.73 KB
/
CreateAccounts_Web.go
File metadata and controls
120 lines (100 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"fmt"
"stellarTools/changeTrust"
"stellarTools/setOptions"
"github.com/julienschmidt/httprouter"
"github.com/rs/cors"
"github.com/stellar/go/keypair"
"io/ioutil"
"log"
"net/http"
)
var account1_PubW, account1_PriW, account1W string
var account2_PubW, account2_PriW, account2W string
func CreateAccount5(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
/**
Get the Seed and Key for account1
*/
pair, err := keypair.Random()
if err != nil {
log.Fatal(err)
}
fmt.Fprint(w,"Account1 Public Key: ", pair.Address())
fmt.Fprint(w,"Account1 Private Key: ", pair.Seed())
log.Println()
account1_PriW = pair.Seed()
account1_PubW = pair.Address()
/**
Get the Seed and Key for account2
*/
pair2, err := keypair.Random()
if err != nil {
log.Fatal(err)
}
fmt.Fprint(w,"Account2 Public Key: ", pair2.Address())
fmt.Fprint(w,"Account2 Private Key: ", pair2.Seed())
log.Println()
account2_PriW = pair2.Seed()
account2_PubW = pair2.Address()
/*#############################################################################################*/
/**
Create account1
*/
// pair is the pair that was generated from previous example, or create a pair based on
// existing keys.
//address := pair.Address()
rresp, err := http.Get("https://friendbot.stellar.org/?addr=" + account1_PubW)
if err != nil {
log.Fatal(err)
}
defer rresp.Body.Close()
body, err := ioutil.ReadAll(rresp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Fprint(w,"Account1 info: ", string(body))
account1W = string(body)
fmt.Println()
/**
Create account2
*/
// pair is the pair that was generated from previous example, or create a pair based on
// existing keys.
//address := pair.Address()
rresp2, err := http.Get("https://friendbot.stellar.org/?addr=" + account2_PubW)
if err != nil {
log.Fatal(err)
}
defer rresp2.Body.Close()
body2, err := ioutil.ReadAll(rresp2.Body)
if err != nil {
log.Fatal(err)
}
fmt.Fprint(w,"Account2 info: ", string(body2))
account2W = string(body2)
fmt.Println()
/*
##############################################################
*/
// Build the trust line for account1
fmt.Fprint(w,"Account1: ")
changeTrust.BuildTrustLine(account1_PubW, account1_PriW)
fmt.Println()
// Build the trust line for account2
fmt.Fprint(w,"Account2: ")
changeTrust.BuildTrustLine(account2_PubW, account2_PriW)
fmt.Println()
/*
##############################################################
*/
// set up the security key for account2
setOptions.SetSecureMasterKey(account2_PubW, account2_PriW)
}
func main() {
router := httprouter.New()
router.POST("/create", CreateAccount5)
log.Print("Listening...8080");
handler := cors.Default().Handler(router)
http.ListenAndServe(":8080", handler)
}