Number, API fixes
This commit is contained in:
parent
76d70a5f1a
commit
2cdc16a9f8
|
@ -162,7 +162,7 @@ func main() {
|
|||
|
||||
})
|
||||
|
||||
serveMux.HandleFunc("/api/miner_info/{miner:^[0-9]+|4[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
serveMux.HandleFunc("/api/miner_info/{miner:[0-9]+|4[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
minerId := mux.Vars(request)["miner"]
|
||||
var miner *database.Miner
|
||||
if len(minerId) > 10 && minerId[0] == '4' {
|
||||
|
@ -230,7 +230,7 @@ func main() {
|
|||
_, _ = writer.Write(buf)
|
||||
})
|
||||
|
||||
serveMux.HandleFunc("/api/shares_in_window/{miner:^[0-9]+|4[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
serveMux.HandleFunc("/api/shares_in_window/{miner:[0-9]+|4[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
minerId := mux.Vars(request)["miner"]
|
||||
var miner *database.Miner
|
||||
if len(minerId) > 10 && minerId[0] == '4' {
|
||||
|
@ -319,7 +319,7 @@ func main() {
|
|||
_, _ = writer.Write(buf)
|
||||
})
|
||||
|
||||
serveMux.HandleFunc("/api/payouts/{miner:^[0-9]+|4[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
serveMux.HandleFunc("/api/payouts/{miner:[0-9]+|4[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
minerId := mux.Vars(request)["miner"]
|
||||
var miner *database.Miner
|
||||
if len(minerId) > 10 && minerId[0] == '4' {
|
||||
|
@ -367,10 +367,10 @@ func main() {
|
|||
|
||||
})
|
||||
|
||||
serveMux.HandleFunc("/api/redirect/block/{main_height:^[0-9]+|.?[0-9A-Za-z]+$}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
serveMux.HandleFunc("/api/redirect/block/{main_height:[0-9]+|.?[0-9A-Za-z]+$}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
http.Redirect(writer, request, fmt.Sprintf("https://xmrchain.net/block/%d", utils.DecodeBinaryNumber(mux.Vars(request)["main_height"])), http.StatusFound)
|
||||
})
|
||||
serveMux.HandleFunc("/api/redirect/transaction/{tx_id:^.?[0-9A-Za-z]+$}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
serveMux.HandleFunc("/api/redirect/transaction/{tx_id:.?[0-9A-Za-z]+}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
http.Redirect(writer, request, fmt.Sprintf("https://xmrchain.net/tx/%s", utils.DecodeHexBinaryNumber(mux.Vars(request)["tx_id"])), http.StatusFound)
|
||||
})
|
||||
serveMux.HandleFunc("/api/redirect/block/{coinbase:[0-9]+|.?[0-9A-Za-z]+$}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
|
@ -394,7 +394,7 @@ func main() {
|
|||
}
|
||||
http.Redirect(writer, request, fmt.Sprintf("https://xmrchain.net/tx/%s", b.Coinbase.Id.String()), http.StatusFound)
|
||||
})
|
||||
serveMux.HandleFunc("/api/redirect/share/{height:^[0-9]+|.?[0-9A-Za-z]+$}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
serveMux.HandleFunc("/api/redirect/share/{height:[0-9]+|.?[0-9A-Za-z]+$}", func(writer http.ResponseWriter, request *http.Request) {
|
||||
c := utils.DecodeBinaryNumber(mux.Vars(request)["height"])
|
||||
|
||||
blockHeight := c >> 16
|
||||
|
|
|
@ -427,7 +427,7 @@ func (db *Database) GetUnclesByMinerIdInWindow(minerId uint64, startHeight *uint
|
|||
if startHeight == nil {
|
||||
return db.GetUncleBlocksByQuery("WHERE parent_height > ((SELECT MAX(height) FROM blocks) - $2) AND parent_height <= ((SELECT MAX(height) FROM blocks)) AND height > ((SELECT MAX(height) FROM blocks) - $2) AND height <= ((SELECT MAX(height) FROM blocks)) AND miner = $1 ORDER BY height DESC", minerId, windowSize)
|
||||
} else {
|
||||
return db.GetUncleBlocksByQuery("WHERE parent_height > ($3 - $2) AND parent_height <= ($3) AND height > ($2) AND height <= ($3) AND miner = $1 ORDER BY height DESC", minerId, *startHeight-windowSize, *startHeight)
|
||||
return db.GetUncleBlocksByQuery("WHERE parent_height > ($2) AND parent_height <= ($3) AND height > ($2) AND height <= ($3) AND miner = $1 ORDER BY height DESC", minerId, *startHeight-windowSize, *startHeight)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ func EncodeBinaryNumber(n uint64) string {
|
|||
}
|
||||
|
||||
func DecodeHexBinaryNumber(i string) string {
|
||||
if _, err := hex.DecodeString(i); strings.Index(i, ".") == -1 && err != nil {
|
||||
if _, err := hex.DecodeString(i); strings.Index(i, ".") == -1 && err == nil {
|
||||
return i
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ func DecodeHexBinaryNumber(i string) string {
|
|||
|
||||
func EncodeHexBinaryNumber(v2 string) string {
|
||||
b, _ := hex.DecodeString(v2)
|
||||
v1 := string(encoding.Encode(b))
|
||||
v1 := encoding.EncodeToString(b)
|
||||
|
||||
if !strings.ContainsAny(v1, "GHIJKLMNOPQRSTUVWXYZghijklmnopqrstuvwxyz") {
|
||||
v1 = "." + v1
|
||||
|
@ -62,3 +62,11 @@ func EncodeHexBinaryNumber(v2 string) string {
|
|||
|
||||
return v1
|
||||
}
|
||||
|
||||
func ReverseSlice[S ~[]E, E any](s S) S {
|
||||
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue