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

feat(faucet): gno address and email/token mapping #153

Merged
merged 2 commits into from
Sep 26, 2023

Conversation

tbruyelle
Copy link
Contributor

@tbruyelle tbruyelle commented Sep 25, 2023

Closes #148

  • Register in redis the gno address as key and email/token as values
  • Add a pseudo endpoint to retrieve email and token from gno adresses

How to test

You need a redis running :

docker run -d --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest

and a redis-cli

docker exec -it redis-stack redis-cli

Prepare a claimable token (this is what the signup page is doing on submit), using redis-cli :

HSET TOKEN:mytoken email [email protected]
HSET TOKEN:mytoken used false

Run the faucet using this command (the default value of --redis-url will match the address of the running docker container, so we don't need to provide it) :

go run main.go -fund-limit 250000000ugnot -send-amount 1000000000ugnot -mnemonic "piano aim fashion palace key scrap write garage avocado royal lounge lumber remove frozen sketch maze tree model half team cook burden pattern choice" -num-accounts 10

Run the node and the gnochess web as usual.

Connect to your gnochess instance with your browser, remove any previous local storage and submit your token:

image

You should have no error.

In redis-cli, ensure that the gno address has been stored :

KEYS GNO:*
1) "GNO:g10trepc80pt9h4ed4tqwm8rgqk4g8rjaer4cqgv"

HGETALL GNO:g10trepc80pt9h4ed4tqwm8rgqk4g8rjaer4cqgv
1) "email"
2) "[email protected]"
3) "token"
4) "nytoken"

Finally take that address (in normal condition, this address should come from the leaderboard) and go to your faucet URL, append the ?addr=g10trepc80pt9h4ed4tqwm8rgqk4g8rjaer4cqgv query string :

$ curl http://localhost:8545/?addr=g10trepc80pt9h4ed4tqwm8rgqk4g8rjaer4cqgv
{"email":"[email protected]","token":"cah3Shohye"}

Please do that testing to ensure that works properly, it's late and I may have made mistakes! thanks in advance 🙏

@netlify
Copy link

netlify bot commented Sep 25, 2023

Deploy Preview for gnochess canceled.

Name Link
🔨 Latest commit 22f83fc
🔍 Latest deploy log https://app.netlify.com/sites/gnochess/deploys/6512e333d9691a0008fea476

@netlify
Copy link

netlify bot commented Sep 25, 2023

Deploy Preview for gnochess-signup-form ready!

Name Link
🔨 Latest commit 22f83fc
🔍 Latest deploy log https://app.netlify.com/sites/gnochess-signup-form/deploys/6512e333102a350008060ebe
😎 Deploy Preview https://deploy-preview-153--gnochess-signup-form.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@albttx
Copy link
Collaborator

albttx commented Sep 25, 2023

copy of #152 ... 😂

Closes #148

- Register in redis the gno address as key and email/token as values
- Add a pseudo endpoint to retrieve email and token from gno adresses
@tbruyelle tbruyelle force-pushed the tbruyelle/faucet-serve-email-from-addr branch from ba35228 to 47ebffb Compare September 26, 2023 06:39
@moul
Copy link
Contributor

moul commented Sep 26, 2023

I suggest we use this method instead: #163.

@tbruyelle
Copy link
Contributor Author

tbruyelle commented Sep 26, 2023

I suggest we use this method instead: #163.

@moul I agree this is a way better, but what we tried to achieve here is something that doesn't require additional change in the front. In your proposed solution, who's calling RegisterPlayer ?

@moul
Copy link
Contributor

moul commented Sep 26, 2023

@moul I agree this is a way better, but what we tried to achieve here is something that doesn't require additional change in the front. In your proposed solution, who's calling RegisterPlayer ?

The faucet: switching a gnokey send with a gnokey maketx call Register.

No front change needed.

No dependency on Redis needed (we can keep it for other reason, but we don't depend on it for the competition).

It offers a way to have a whitelist system to prevent Dust Attacks and DOS more easily aswell as having a filtered leaderboard.

And it's about using blockchains instead of databases, which is a part of my job :)

faucet/main.go Outdated
}
}

// getEmail detects the presence of `addr` form value, if present returns the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to put this in a lambda functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, I removed it 22f83fc


// Parse the request to extract the address
// XXX copied from prepareFundMiddleware, don't have time to refactor without unit tests!
var request faucet.Request
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create a function getFaucetRequest() faucet.Request since this ~20 lines are used twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not ideal because it would also have to return the error string and code for http.Error() arguments, I prefer to keep it like that.

@tbruyelle
Copy link
Contributor Author

No dependency on Redis needed (we can keep it for other reason, but we don't depend on it for the competition).

Redis is still required for the signup page to store generated tokens, and for the gnochess faucet to ensure that provided token has been effectively generated by the signup page.

@zivkovicmilos zivkovicmilos merged commit c152a86 into main Sep 26, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Link gno address and token/email
4 participants