kalepail / stellar-quest-bounties

Stellar Quest Bounties is an extension of the traditional, series based Stellar Quest challenges allowing seasoned and passionate Stellar Questers to continue their journey of education and earning during the "lean times" between Stellar Quest series.
https://quest.stellar.org/bounties
23 stars 27 forks source link

Stellar Account as a Service #145

Closed w00kie closed 2 years ago

w00kie commented 2 years ago

Link the bounty file

https://github.com/tyvdh/stellar-quest-bounties/blob/main/bounties/level-2/stellar-accounts-as-a-service.md

Mark your progress

Provide relevant details

Did a python implementation with Django and Django REST Framework.

Repo: https://github.com/w00kie/saas-bounty-django

Live on: https://saas-django.w00kie.com/

rahimklaber commented 2 years ago

Calling the pay endpoint with curl:

 curl --request POST \
>   --url https://saas-django.w00kie.com/pay \
>   --header 'Authorization: Bearer 495fcacabf97206183c7ccc1787900fe687521ef' \
>   --header 'Content-Type: application/json' \
>   --data '{
> "destination" :"MABY3C7LM4NTZJFEMUX374JNFBJC3JI3U7HOATRZRD2AANGYBR7Z2AAAAAAAAAAAAPB4M",
> "amount" : "10.0000001"
> }'

gives this error: curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)

Same thing happens with the register endpoint.

Making a request with Java, gives this error: unexpected content length header with 204 response. The response seems to go against the Http spec : https://github.com/OasisLMF/OasisPlatform/issues/67

w00kie commented 2 years ago

Yeah, I was returning a message when 204s should have no content at all. Fixed now.

I also fixed a race condition when you pay yourself.

rahimklaber commented 2 years ago

Everything seems to work. I think you can mark it as completed unless you want someone else to review.

Though, I am curious how you made it so multiple people can pay at the same time. I didn't see anywhere where that was handled and yet it worked fine.

w00kie commented 2 years ago

Yeah, after reading the review on other proposals I realized there was gonna be an issue here. But the beauty of being stingy with memory on my production server is that I set it up the service with just a single gunicorn runner, so nginx makes you wait in line for payment automatically 😁

Now if I had to do it in production, I'd probably decrease the user's balance on the spot, store pending payments in the DB setup a quick celery worker that runs every 10s and grabs up to 100 payments to batch in a single tx.

kalepail commented 2 years ago

Works flawlessly for the tests I put it through. Well done. Can you add your Stellar address you want the award sent to as a PR to this file? https://github.com/tyvdh/stellar-quest-bounties/blob/main/ADDRESSES.yml Thanks!

w00kie commented 2 years ago

Sorry, forgot to add my address. The PR is open now.

kalepail commented 2 years ago

3d5b69601e46683a86a311ae3e715e180f1c7258d8ca0d326d1e8d8e920feab3