This repository has been archived by the owner on Oct 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
256 lines (223 loc) · 9.1 KB
/
main.go
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
package main
// API Details to Match https://www.notion.so/aencoins/API-Interface-1af6611260b04c899f9912e0b12d9344
import (
"fmt"
"github.com/gorilla/mux"
"net/http"
)
var conf = getGlobals()
func main() {
route := mux.NewRouter()
route.HandleFunc("/version" , version ).Methods("GET")
route.HandleFunc("/crypto" , accountGenerate ).Methods("GET")
route.HandleFunc("/crypto/{privateKey}" , accountGenerate ).Methods("GET")
route.HandleFunc("/account/{accountId}" , accountGet ).Methods("GET")
route.HandleFunc("/account/{accountId}" , accountPost ).Methods("POST")
route.HandleFunc("/account/{publicKey}/transactions" , accountTransactionsGet ).Methods("GET")
route.HandleFunc("/account/{publicKey}/transactions/incoming" , accountTransactionsIncomingGet ).Methods("GET")
route.HandleFunc("/account/{publicKey}/transactions/outgoing" , accountTransactionsOutgoingGet ).Methods("GET")
route.HandleFunc("/account/{publicKey}/transactions/unconfirmed" , accountTransactionsUnconfirmedGet ).Methods("GET")
route.HandleFunc("/account/{publicKey}/transactions/partial" , accountTransactionsPartialGet ).Methods("GET")
route.HandleFunc("/account/{accountId}/multisig" , accountMultisigGet ).Methods("GET")
route.HandleFunc("/account/{accountId}/multisig/graph" , accountMultisigGraphGet ).Methods("GET")
route.HandleFunc("/blocks/{height}" , blocksGet ).Methods("GET")
route.HandleFunc("/blocks/{height}/limit/{limit}" , blocksLimitGet ).Methods("GET")
route.HandleFunc("/blocks/{height}/transactions" , blockTransactionsGet ).Methods("GET")
route.HandleFunc("/chain/height" , chainHeightGet ).Methods("GET")
route.HandleFunc("/chain/score" , chainScoreGet ).Methods("GET")
route.HandleFunc("/diagnostic/storage" , diagnosticStorageGet ).Methods("GET")
route.HandleFunc("/mosaic/{mosaicId}" , mosaicGet ).Methods("GET")
route.HandleFunc("/mosaic" , mosaicPost ).Methods("POST")
route.HandleFunc("/namespace/{namespaceId}/mosaics" , namespaceMosaicGet ).Methods("GET")
route.HandleFunc("/mosaic/names" , mosaicNamesPost ).Methods("POST")
route.HandleFunc("/namespace/{namespaceId}" , namespaceGet ).Methods("GET")
route.HandleFunc("/account/{accountId}" , accountNamespacesGet ).Methods("GET")
route.HandleFunc("/account/namespaces" , accountNamespacesPost ).Methods("POST")
route.HandleFunc("/namespace/names" , namespaceNamesPost ).Methods("POST")
route.HandleFunc("/transaction/{transactionId}" , transactionGet ).Methods("GET")
route.HandleFunc("/transaction" , transactionPost ).Methods("POST")
route.HandleFunc("/transaction" , transactionPut ).Methods("PUT")
route.HandleFunc("/transaction/partial" , transactionPartialPut ).Methods("PUT")
route.HandleFunc("/transaction/cosignature" , transactionCosignaturePut ).Methods("PUT")
route.HandleFunc("/transaction/{hash}/status" , transactionStatusGet ).Methods("GET")
route.HandleFunc("/transaction/statuses" , transactionStatusesPost ).Methods("PUT")
route.HandleFunc("/network" , networkGet ).Methods("GET")
route.HandleFunc("/node/info" , nodeInfoGet ).Methods("GET")
route.HandleFunc("/node/time" , nodeTimeGet ).Methods("GET")
route.NotFoundHandler = http.HandlerFunc(NotFound) // If the routing is not found, use this as a default.
http.ListenAndServe(":3001", route) // Set up the listerner for the incoming requests
}
func version(w http.ResponseWriter, r *http.Request) {
var responceText = "Currently we have only 1 version"
responceText += "Version:1"
fmt.Fprint(w, responceText)
}
func accountGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r) //Get the paramters
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Account ID: %v\n", params["accountId"]) //Return the details
}
func accountPost(w http.ResponseWriter, r *http.Request) {
// Incoming:
// {
// "addresses": [
// "SDRDGFTDLLCB67D4HPGIMIHPNSRYRJRT7DOBGWZY",
// "SBCPGZ3S2SCC3YHBBTYDCUZV4ZZEPHM2KGCP4QXX"
// ]
// }
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Account Post")
}
func blocksGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Blocks: [%v]\n", params["height"])
}
func blocksLimitGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Height: [%v] Limit : [%v]\n", params["height"], params["limit"])
}
func blockTransactionsGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Blocks: [%v]\n", params["height"])
}
func chainHeightGet(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `{ "height": ["lower", "higher" ] }`)
}
func chainScoreGet(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `{"scoreHigh": ["lower","higher"],"scoreLow": ["lower","higher"]}`)
}
func diagnosticStorageGet(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `{"numBlocks": 0,"numTransactions": 0,"numAccounts": 0}`)
}
func mosaicGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "mosaicId: %v\n", params["mosaicId"])
}
func mosaicPost(w http.ResponseWriter, r *http.Request) {
// Incoming
// {
// "mosaicIds": [
// "d525ad41d95fcf29"
// ]
// }
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "mosaic Post")
}
func namespaceMosaicGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "mosaicId: %v\n", params["namespaceId"])
}
func mosaicNamesPost(w http.ResponseWriter, r *http.Request) {
// Incoming
//{
// "mosaicIds": [
// "d525ad41d95fcf29"
// ]
//}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "mosaic Names Post")
}
func namespaceGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "namespace Id: %v\n", params["namespaceId"])
}
func accountNamespacesGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "namespace Id: %v\n", params["accountId"])
}
func accountNamespacesPost(w http.ResponseWriter, r *http.Request) {
// Incoming
//{
// "addresses": [
// "SDRDGFTDLLCB67D4HPGIMIHPNSRYRJRT7DOBGWZY",
// "SBCPGZ3S2SCC3YHBBTYDCUZV4ZZEPHM2KGCP4QXX"
// ]
//}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Account names spaces Post")
}
func namespaceNamesPost(w http.ResponseWriter, r *http.Request) {
// Incoming
//{
// "namespaceIds": [
// "84b3552d375ffa4b"
// ]
//}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Namesspaces Names Post")
}
func transactionGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Transaction ID: %v\n", params["transactionId"])
}
func transactionPost(w http.ResponseWriter, r *http.Request) {
// Incoming
//{
// "transactionIds": [
// "59B8DA0F0CB2720001103922",
// "59B8D8E60CB2720001103904"
// ]
//}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Transaction Post")
}
func transactionPut(w http.ResponseWriter, r *http.Request) {
// Incoming
//{
// "payload": "example"
//}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Transaction Put")
}
func transactionPartialPut(w http.ResponseWriter, r *http.Request) {
// Incoming
//{
// "payload": "example"
//}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Transaction Partial Put")
}
func transactionCosignaturePut(w http.ResponseWriter, r *http.Request) {
// Incoming
//{
// "payload": "example"
//}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Transaction Cosignature Put")
}
func transactionStatusGet(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Transaction Hash Status: %v\n", params["hash"])
}
func transactionStatusesPost(w http.ResponseWriter, r *http.Request) {
// Incoming
//{
// "hashes": [
// "5AF72FE39C0515E823903918A0BFE9625DD752C7BD63969C8869F25E9D155DE5"
// ]
//}
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Transaction Post")
}
func nodeInfoGet(w http.ResponseWriter, r *http.Request) {
// params := mux.Vars(r)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Node Info", `{"publicKey": "EB6839C7E6BD0031FDD5F8CB5137E9BC950D7EE7756C46B767E68F3F58C24390", "port": 7900, "networkIdentifier": 144,"version": 0,"roles": 2,"host": "api-node-0","friendlyName": "api-node-0"}`)
}
func nodeTimeGet(w http.ResponseWriter, r *http.Request) {
// params := mux.Vars(r)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "Node Info", `{ "communicationTimestamps": { "sendTimestamp": [], "receiveTimestamp": [] }}`)
}