Skip to content

Commit

Permalink
Adding Tx Hash to the faucet funding (#1660)
Browse files Browse the repository at this point in the history
* Adding Tx Hash to the faucet funding

* new build job
  • Loading branch information
otherview authored Nov 22, 2023
1 parent 8c83d5e commit 29cae5d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
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})
}
}

Expand Down

0 comments on commit 29cae5d

Please sign in to comment.