mirror of
https://github.com/Rushilwiz/rounded.git
synced 2025-04-09 22:00:18 -04:00
feat(backend): added deso transaction creation
This commit is contained in:
parent
7cad429a2c
commit
076139a82d
|
@ -10,6 +10,7 @@ python-dotenv = "*"
|
|||
djangorestframework = "*"
|
||||
django-cors-headers = "*"
|
||||
djangorestframework-simplejwt = "*"
|
||||
requests = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
|
41
server/Pipfile.lock
generated
41
server/Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "d2db7358afc491233105dbd0ca11ab1f16efa6e70de3e44270a99ce7acde40b6"
|
||||
"sha256": "edc0e33714e869ceb2bf072793d154b82545e005bf908ca2949645b193c13297"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
|
@ -24,6 +24,21 @@
|
|||
"markers": "python_version >= '3.7'",
|
||||
"version": "==3.5.0"
|
||||
},
|
||||
"certifi": {
|
||||
"hashes": [
|
||||
"sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872",
|
||||
"sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569"
|
||||
],
|
||||
"version": "==2021.10.8"
|
||||
},
|
||||
"charset-normalizer": {
|
||||
"hashes": [
|
||||
"sha256:2857e29ff0d34db842cd7ca3230549d1a697f96ee6d3fb071cfa6c7393832597",
|
||||
"sha256:6881edbebdb17b39b4eaaa821b438bf6eddffb4468cf344f09f89def34a8b1df"
|
||||
],
|
||||
"markers": "python_version >= '3'",
|
||||
"version": "==2.0.12"
|
||||
},
|
||||
"django": {
|
||||
"hashes": [
|
||||
"sha256:07c8638e7a7f548dc0acaaa7825d84b7bd42b10e8d22268b3d572946f1e9b687",
|
||||
|
@ -64,6 +79,14 @@
|
|||
"index": "pypi",
|
||||
"version": "==20.1.0"
|
||||
},
|
||||
"idna": {
|
||||
"hashes": [
|
||||
"sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff",
|
||||
"sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"
|
||||
],
|
||||
"markers": "python_version >= '3'",
|
||||
"version": "==3.3"
|
||||
},
|
||||
"pyjwt": {
|
||||
"hashes": [
|
||||
"sha256:b888b4d56f06f6dcd777210c334e69c737be74755d3e5e9ee3fe67dc18a0ee41",
|
||||
|
@ -87,6 +110,14 @@
|
|||
],
|
||||
"version": "==2022.1"
|
||||
},
|
||||
"requests": {
|
||||
"hashes": [
|
||||
"sha256:68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61",
|
||||
"sha256:f22fa1e554c9ddfd16e6e41ac79759e17be9e492b3587efa038054674760e72d"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.27.1"
|
||||
},
|
||||
"sqlparse": {
|
||||
"hashes": [
|
||||
"sha256:0c00730c74263a94e5a9919ade150dfc3b19c574389985446148402998287dae",
|
||||
|
@ -102,6 +133,14 @@
|
|||
],
|
||||
"markers": "sys_platform == 'win32'",
|
||||
"version": "==2022.1"
|
||||
},
|
||||
"urllib3": {
|
||||
"hashes": [
|
||||
"sha256:44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14",
|
||||
"sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e"
|
||||
],
|
||||
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'",
|
||||
"version": "==1.26.9"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
|
|
|
@ -16,7 +16,7 @@ class Wallet (models.Model):
|
|||
class Consumer (models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
wallet = models.OneToOneField(Wallet, null=True, blank=True, on_delete=models.CASCADE)
|
||||
access_token = models.CharField(max_length=100)
|
||||
phone = models.CharField(max_length=32, null=True, blank=True),
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.user.username}\'s profile'
|
||||
|
@ -27,8 +27,9 @@ class Consumer (models.Model):
|
|||
class Foundation (models.Model):
|
||||
wallet = models.OneToOneField(Wallet, on_delete=models.CASCADE)
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=100)
|
||||
description = models.TextField()
|
||||
name = models.CharField(max_length=100, null=True, blank=True)
|
||||
description = models.TextField(null=True, blank=True)
|
||||
hex = models.CharField(max_length=200, null=True, blank=True)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.user.username}\'s foundation'
|
||||
|
|
|
@ -9,9 +9,12 @@ from rest_framework_simplejwt.views import (
|
|||
|
||||
urlpatterns = [
|
||||
path('profile/create', views.ConsumerCreate.as_view()),
|
||||
path('profile/add_wallet', views.ConsumerAddWallet.as_view()),
|
||||
path('profile/update', views.ConsumerUpdate.as_view()),
|
||||
path('profile/', views.ConsumerDetail.as_view()),
|
||||
path('foundation/', views.FoundationViewSet.as_view({'get': 'list', 'post': 'create'})),
|
||||
path('foundation/<int:pk>/', views.FoundationViewSet.as_view({'get': 'retrieve', 'put': 'update', 'delete': 'destroy'})),
|
||||
path('token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
|
||||
path('token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
|
||||
path('generate_order/', views.generate_order),
|
||||
]
|
|
@ -1,5 +1,9 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
from uuid import uuid4
|
||||
|
||||
import requests
|
||||
|
||||
from .models import *
|
||||
from .serializers import *
|
||||
|
||||
|
@ -36,3 +40,37 @@ class ConsumerDetail(APIView):
|
|||
serializer = ConsumerSerializer(profile)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
||||
class ConsumerUpdate(APIView):
|
||||
def post(self, request, format=None):
|
||||
profile = request.user.consumer
|
||||
profile.phone = request.data['phone']
|
||||
profile.save()
|
||||
|
||||
class ConsumerAddWallet(APIView):
|
||||
def post(self, request, format=None):
|
||||
profile = request.user.consumer
|
||||
profile.wallet = Wallet.objects.create(address=request.data['address'])
|
||||
profile.save()
|
||||
|
||||
def generate_order(request):
|
||||
if request.method == 'POST':
|
||||
foundation = User.objects.get(username=request.POST['foundation']).foundation
|
||||
price = int(request.POST['price'])
|
||||
uuid = uuid4()
|
||||
order = FoundationOrder.objects.create(consumer=request.user.consumer, foundation=foundation, price=price, uuid=uuid)
|
||||
|
||||
rate = int(requests.get("https://node.deso.org/api/v0/get-exchange-rate").json()["USDCentsPerBitCloutExchangeRate"])
|
||||
|
||||
price_in_nanos = (((10**9) * price) / rate)
|
||||
|
||||
options = {
|
||||
"SenderPublicKeyBase58Check": request.user.consumer.wallet.address,
|
||||
"RecipientPublicKeyOrUsername": foundation.wallet.address,
|
||||
"AmountNanos": price_in_nanos
|
||||
}
|
||||
|
||||
hex = request.post('https://node.deso.org/api/v0/send-deso', json=options).json()["TransactionHex"]
|
||||
foundation.hex = hex
|
||||
|
||||
foundation.save()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user