This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
122 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.conf.urls import include | ||
from django.conf.urls import url | ||
|
||
|
||
urlpatterns = [ | ||
url(r'^v1/', include(('api.v1.urls', 'api'), namespace='v1')), | ||
url(r'', include(('api.v1.urls', 'api'), namespace='last')), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from datetime import datetime | ||
|
||
from rest_framework import serializers | ||
|
||
from java_wallet.constants import BLOCK_CHAIN_START_AT, TxSubtypePayment | ||
|
||
|
||
class PendingTxsSerializer(serializers.Serializer): | ||
type = serializers.IntegerField(read_only=True) | ||
subtype = serializers.IntegerField(read_only=True) | ||
timestamp = serializers.SerializerMethodField(read_only=True) | ||
amountNQT = serializers.IntegerField(read_only=True) | ||
feeNQT = serializers.IntegerField(read_only=True) | ||
sender = serializers.IntegerField(read_only=True) | ||
recipient = serializers.IntegerField(read_only=True) | ||
recipients = serializers.SerializerMethodField(read_only=True) | ||
|
||
@staticmethod | ||
def get_timestamp(data): | ||
return datetime.fromtimestamp(data['timestamp'] + BLOCK_CHAIN_START_AT) | ||
|
||
def get_recipients(self, data): | ||
result = [] | ||
|
||
if data['subtype'] == TxSubtypePayment.MULTI_OUT: | ||
for x in data['attachment']['recipients']: | ||
result.append({'address': int(x[0]), 'amount': int(x[1])}) | ||
|
||
elif data['subtype'] == TxSubtypePayment.MULTI_OUT_SAME: | ||
amount = int(data['amountNQT']) / len(data['attachment']['recipients']) | ||
for x in data['attachment']['recipients']: | ||
result.append({'address': int(x), 'amount': amount}) | ||
|
||
return result or None | ||
|
||
def update(self, instance, validated_data): | ||
pass | ||
|
||
def create(self, validated_data): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from rest_framework import routers | ||
|
||
from api.v1 import views | ||
|
||
router = routers.DefaultRouter() | ||
|
||
router.register('pending_txs', views.PendingTxsList, basename='pending_txs') | ||
|
||
urlpatterns = router.urls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.conf import settings | ||
from rest_framework import viewsets | ||
from rest_framework.response import Response | ||
from sentry_sdk import capture_exception | ||
|
||
from burst.api.brs.api import BrsApi | ||
from burst.api.exceptions import APIException | ||
from api.v1.serializers import PendingTxsSerializer | ||
|
||
|
||
class PendingTxsList(viewsets.ViewSet): | ||
@staticmethod | ||
def list(request): | ||
try: | ||
txs = BrsApi(settings.BRS_NODE).get_unconfirmed_transactions() | ||
txs.sort(key=lambda _x: int(_x['feeNQT']), reverse=True) | ||
|
||
serializer = PendingTxsSerializer(txs, many=True) | ||
result = serializer.data | ||
except (APIException, ValueError) as e: | ||
capture_exception(e) | ||
result = [] | ||
|
||
return Response(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters