Remove legacy /miner_alias API in favor of /miner_signed_action
This commit is contained in:
parent
e2885687b2
commit
c770719d8c
|
@ -938,91 +938,6 @@ func main() {
|
|||
}
|
||||
})
|
||||
|
||||
serveMux.HandleFunc("/api/miner_alias/{miner:4[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
minerId := mux.Vars(request)["miner"]
|
||||
miner := indexDb.GetMinerByStringAddress(minerId)
|
||||
|
||||
if miner == nil {
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
writer.WriteHeader(http.StatusNotFound)
|
||||
buf, _ := utils.MarshalJSON(struct {
|
||||
Error string `json:"error"`
|
||||
}{
|
||||
Error: "not_found",
|
||||
})
|
||||
_, _ = writer.Write(buf)
|
||||
return
|
||||
}
|
||||
|
||||
params := request.URL.Query()
|
||||
|
||||
sig := strings.TrimSpace(params.Get("signature"))
|
||||
|
||||
message := strings.TrimSpace(params.Get("message"))
|
||||
|
||||
if len(message) > 20 || len(message) < 3 || !func() bool {
|
||||
for _, c := range message {
|
||||
if !(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && c != '_' && c != '-' && c != '.' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}() || !unicode.IsLetter(rune(message[0])) {
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
writer.WriteHeader(http.StatusBadRequest)
|
||||
buf, _ := utils.MarshalJSON(struct {
|
||||
Error string `json:"error"`
|
||||
}{
|
||||
Error: "invalid_message",
|
||||
})
|
||||
_, _ = writer.Write(buf)
|
||||
return
|
||||
}
|
||||
|
||||
result := address.VerifyMessage(miner.Address(), []byte(message), sig)
|
||||
if result == address.ResultSuccessSpend {
|
||||
if message == "REMOVE_MINER_ALIAS" {
|
||||
message = ""
|
||||
}
|
||||
if indexDb.SetMinerAlias(miner.Id(), message) != nil {
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
writer.WriteHeader(http.StatusBadRequest)
|
||||
buf, _ := utils.MarshalJSON(struct {
|
||||
Error string `json:"error"`
|
||||
}{
|
||||
Error: "duplicate_message",
|
||||
})
|
||||
_, _ = writer.Write(buf)
|
||||
return
|
||||
} else {
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
writer.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
} else if result == address.ResultSuccessView {
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
writer.WriteHeader(http.StatusBadRequest)
|
||||
buf, _ := utils.MarshalJSON(struct {
|
||||
Error string `json:"error"`
|
||||
}{
|
||||
Error: "view_signature",
|
||||
})
|
||||
_, _ = writer.Write(buf)
|
||||
return
|
||||
} else {
|
||||
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
writer.WriteHeader(http.StatusBadRequest)
|
||||
buf, _ := utils.MarshalJSON(struct {
|
||||
Error string `json:"error"`
|
||||
}{
|
||||
Error: "invalid_signature",
|
||||
})
|
||||
_, _ = writer.Write(buf)
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
serveMux.HandleFunc("/api/side_blocks_in_window", func(writer http.ResponseWriter, request *http.Request) {
|
||||
params := request.URL.Query()
|
||||
|
||||
|
|
Loading…
Reference in a new issue