From dbb892d89f9abc83a438a87487c5ff13d1a3ea50 Mon Sep 17 00:00:00 2001 From: Maciej Witowski Date: Fri, 28 Apr 2023 17:01:11 +0200 Subject: [PATCH] lotus-fountain: make compatible with 0x addresses #10560 --- cmd/lotus-fountain/main.go | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/cmd/lotus-fountain/main.go b/cmd/lotus-fountain/main.go index 780aef916..464251cd3 100644 --- a/cmd/lotus-fountain/main.go +++ b/cmd/lotus-fountain/main.go @@ -7,6 +7,7 @@ import ( "net" "net/http" "os" + "strings" "time" rice "github.com/GeertJohan/go.rice" @@ -19,6 +20,7 @@ import ( "github.com/filecoin-project/lotus/api/v0api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/chain/types/ethtypes" lcli "github.com/filecoin-project/lotus/cli" ) @@ -193,14 +195,34 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - to, err := address.NewFromString(r.FormValue("address")) - if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - if to == address.Undef { - http.Error(w, "empty address", http.StatusBadRequest) - return + var to address.Address + + addressInput := r.FormValue("address") + if strings.HasPrefix(addressInput, "0x") { + ethAddress, err := ethtypes.ParseEthAddress(addressInput) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + 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) + return + } + + to = filecoinAddress } // Limit based on wallet address