You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

46 lines
1003 B

package main
import (
"net/http"
"strings"
"github.com/bvinc/go-sqlite-lite/sqlite3"
"git.sporestack.com/SporeStack/settlers"
)
func depositOnlyTokenEnabled(depositOnlyToken string, db *sqlite3.Conn) (userErr, err error) {
if userErr = settlers.ValidateToken(depositOnlyToken); userErr != nil {
return
}
statement, err := db.Prepare("SELECT balance FROM balances WHERE combined_deposit_only_token = ?", depositOnlyToken)
if err != nil {
return
}
defer statement.Close()
hasRow, err := statement.Step()
if err != nil {
return
}
if !hasRow {
userErr = settlers.ErrorTokenNotEnabled
return
}
return
}
func httpDepositOnlyTokenEnabled(w http.ResponseWriter, r *http.Request, db *sqlite3.Conn) {
defer r.Body.Close()
pathParts := strings.Split(r.URL.Path, "/")
token := pathParts[len(pathParts)-1]
userErr, err := depositOnlyTokenEnabled(token, db)
if err != nil {
httpHandle500(w, err)
return
}
if userErr != nil {
httpHandle400(w, userErr)
return
}
return
}