lotus-fountain: make compatible with 0x addresses #10560
This commit is contained in:
parent
b4ea0db04f
commit
dbb892d89f
@ -7,6 +7,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
rice "github.com/GeertJohan/go.rice"
|
rice "github.com/GeertJohan/go.rice"
|
||||||
@ -19,6 +20,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/api/v0api"
|
"github.com/filecoin-project/lotus/api/v0api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types/ethtypes"
|
||||||
lcli "github.com/filecoin-project/lotus/cli"
|
lcli "github.com/filecoin-project/lotus/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -193,16 +195,36 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
to, err := address.NewFromString(r.FormValue("address"))
|
var to address.Address
|
||||||
|
|
||||||
|
addressInput := r.FormValue("address")
|
||||||
|
if strings.HasPrefix(addressInput, "0x") {
|
||||||
|
ethAddress, err := ethtypes.ParseEthAddress(addressInput)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if to == address.Undef {
|
|
||||||
|
filecoinAddress, err := ethAddress.ToFilecoinAddress()
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
to = filecoinAddress
|
||||||
|
} else {
|
||||||
|
filecoinAddress, err := address.NewFromString(addressInput)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if filecoinAddress == address.Undef {
|
||||||
http.Error(w, "empty address", http.StatusBadRequest)
|
http.Error(w, "empty address", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
to = filecoinAddress
|
||||||
|
}
|
||||||
|
|
||||||
// Limit based on wallet address
|
// Limit based on wallet address
|
||||||
limiter := h.limiter.GetWalletLimiter(to.String())
|
limiter := h.limiter.GetWalletLimiter(to.String())
|
||||||
if !limiter.Allow() {
|
if !limiter.Allow() {
|
||||||
|
Loading…
Reference in New Issue
Block a user