Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Tx Hash to the faucet funding #1660

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion integration/faucet/faucet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func createObscuroNetwork(t *testing.T, startPort int) {
}

func fundWallet(port int, w wallet.Wallet) error {
url := fmt.Sprintf("http://localhost:%d/fund/eth", port)
url := fmt.Sprintf("http://localhost:%d/auth/fund/eth", port)
method := "POST"

payload := strings.NewReader(fmt.Sprintf(`{"address":"%s"}`, w.Address()))
Expand All @@ -122,6 +122,7 @@ func fundWallet(port int, w wallet.Wallet) error {
return err
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.xDOI1Cc30Zuj7VYKiRTqB2VntEKpZ5SkJW1heSsvzFw")

res, err := client.Do(req)
if err != nil {
Expand Down
13 changes: 6 additions & 7 deletions tools/faucet/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,33 @@ func NewFaucet(rpcURL string, chainID int64, pkString string) (*Faucet, error) {
}, nil
}

func (f *Faucet) Fund(address *common.Address, token string, amount *big.Int) error {
func (f *Faucet) Fund(address *common.Address, token string, amount *big.Int) (string, error) {
var err error
var signedTx *types.Transaction

if token == NativeToken || token == DeprecatedNativeToken {
signedTx, err = f.fundNativeToken(address, amount)
} else {
return fmt.Errorf("token not fundable atm")
// signedTx, err = f.fundERC20Token(address, token)
return "", fmt.Errorf("token not fundable atm")
// todo implement this when contracts are deployable somewhere
}
if err != nil {
return err
return "", err
}

// the faucet should be the only user of the faucet pk
txMarshal, err := json.Marshal(signedTx)
if err != nil {
return err
return "", err
}
f.Logger.Info(fmt.Sprintf("Funded address: %s - tx: %+v\n", address.Hex(), string(txMarshal)))
// todo handle tx receipt

if err := f.validateTx(signedTx); err != nil {
return fmt.Errorf("unable to validate tx %s: %w", signedTx.Hash(), err)
return "", fmt.Errorf("unable to validate tx %s: %w", signedTx.Hash(), err)
}

return nil
return signedTx.Hash().Hex(), nil
}

func (f *Faucet) validateTx(tx *types.Transaction) error {
Expand Down
5 changes: 3 additions & 2 deletions tools/faucet/webserver/web_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ func fundingHandler(faucetServer *faucet.Faucet, defaultAmount *big.Int) gin.Han

// fund the address
addr := common.HexToAddress(req.Address)
if err := faucetServer.Fund(&addr, token, defaultAmount); err != nil {
hash, err := faucetServer.Fund(&addr, token, defaultAmount)
if err != nil {
errorHandler(c, fmt.Errorf("unable to fund request %w", err), faucetServer.Logger)
return
}

c.JSON(http.StatusOK, gin.H{"status": "ok"})
c.JSON(http.StatusOK, gin.H{"status": "ok", "tx": hash})
otherview marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading