-
Notifications
You must be signed in to change notification settings - Fork 0
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
guoshijiang
authored and
guoshijiang
committed
Mar 4, 2024
1 parent
ab32f76
commit a2964b3
Showing
10 changed files
with
252 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
#encoding=utf-8 | ||
|
||
from django.contrib import admin | ||
from airdrop.models import ( | ||
AirdropUser, | ||
PointsRecord | ||
) | ||
|
||
@admin.register(AirdropUser) | ||
class AddressAmountStatAdmin(admin.ModelAdmin): | ||
list_display = ('id', 'name', 'address', 'points') | ||
|
||
# Register your models here. | ||
@admin.register(PointsRecord) | ||
class ChainAdmin(admin.ModelAdmin): | ||
list_display = ('id', 'address', 'type', 'points') |
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,36 @@ | ||
#encoding=utf-8 | ||
|
||
import pytz | ||
from airdrop.models import AirdropUser, PointsRecord | ||
from services.savour_rpc import airdrop_pb2_grpc, common_pb2, airdrop_pb2 | ||
from django.conf import settings | ||
|
||
tz = pytz.timezone(settings.TIME_ZONE) | ||
|
||
class AirdropServer(airdrop_pb2_grpc.AirdropServiceServicer): | ||
def submitDppLinkPoints(self, request, context) -> airdrop_pb2.DppLinkPointsResponse: | ||
airdrop_user: AirdropUser | ||
type = str(request.type) | ||
address = str(request.address) | ||
points = int(request.points) | ||
airdrop_tmp_user = AirdropUser.objects.filter(address=address).first() | ||
if airdrop_tmp_user is not None: | ||
airdrop_tmp_user.points += points | ||
airdrop_tmp_user.save() | ||
airdrop_user = airdrop_tmp_user | ||
else: | ||
airdrop_user = AirdropUser.objects.create( | ||
address=address, | ||
points=points | ||
) | ||
PointsRecord.objects.create( | ||
user=airdrop_user, | ||
address=address, | ||
type=type, | ||
points=points | ||
) | ||
return airdrop_pb2.DppLinkPointsResponse( | ||
code=common_pb2.SUCCESS, | ||
msg="submit dapplink points success", | ||
) | ||
|
Empty file.
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,20 @@ | ||
#encoding=utf-8 | ||
|
||
import grpc | ||
from django.core.management.base import BaseCommand | ||
from concurrent import futures | ||
from services.savour_rpc import airdrop_pb2_grpc | ||
from airdrop.airdrop_server import AirdropServer | ||
|
||
|
||
class Command(BaseCommand): | ||
def handle(self, *args, **options): | ||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) | ||
airdrop_pb2_grpc.add_AirdropServiceServicer_to_server( | ||
AirdropServer(), | ||
server | ||
) | ||
server.add_insecure_port('[::]:50251') | ||
server.start() | ||
print("airdrop rpc server start") | ||
server.wait_for_termination() |
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,54 @@ | ||
# Generated by Django 4.1.1 on 2024-03-03 03:11 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='AirdropUser', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('uuid', models.CharField(blank=True, max_length=100, null=True, unique=True)), | ||
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)), | ||
('updated_at', models.DateTimeField(auto_now=True, db_index=True)), | ||
('name', models.CharField(default='unknown', max_length=100, unique=True, verbose_name='用户名')), | ||
('photo', models.ImageField(blank=True, null=True, upload_to='symbol/%Y/%m/%d/')), | ||
('address', models.CharField(max_length=100, unique=True, verbose_name='用户地址')), | ||
('email', models.EmailField(blank=True, max_length=254, null=True)), | ||
('points', models.PositiveIntegerField(default=0, verbose_name='积分数量')), | ||
('x_twitter', models.CharField(blank=True, default='', max_length=100, null=True, verbose_name='x')), | ||
('discord', models.CharField(blank=True, default='', max_length=100, null=True, verbose_name='discord')), | ||
('telegram', models.CharField(blank=True, default='', max_length=100, null=True, verbose_name='discord')), | ||
('info', models.CharField(blank=True, default='', max_length=100, null=True, verbose_name='个人介绍')), | ||
], | ||
options={ | ||
'verbose_name': 'User', | ||
'verbose_name_plural': 'User', | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='PointsRecord', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('uuid', models.CharField(blank=True, max_length=100, null=True, unique=True)), | ||
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)), | ||
('updated_at', models.DateTimeField(auto_now=True, db_index=True)), | ||
('address', models.CharField(max_length=100, unique=True, verbose_name='用户地址')), | ||
('type', models.CharField(choices=[('BridgeTransfer', 'BridgeTransfer'), ('BridgeStaking', 'BridgeStaking')], default='BridgeTransfer', max_length=100, verbose_name='交易类别')), | ||
('points', models.PositiveIntegerField(default=0, verbose_name='积分数量')), | ||
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='airdrop_user', to='airdrop.airdropuser', verbose_name='收藏的商家')), | ||
], | ||
options={ | ||
'verbose_name': 'PointsRecord', | ||
'verbose_name_plural': 'PointsRecord', | ||
}, | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
curl --location --request POST 'http://127.0.0.1:8000/api/get_points_by_address' --header 'Content-Type: application/json' --data-raw '{"address": "0xe3b4ECd2EC88026F84cF17fef8bABfD9184C94F0" }' | ||
|
||
|
||
curl --location --request POST 'http://127.0.0.1:8000/api/get_points_record_by_address' --header 'Content-Type: application/json' --data-raw '{"address": "0xe3b4ECd2EC88026F84cF17fef8bABfD9184C94F0" }' |
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,46 @@ | ||
#encoding=utf-8 | ||
|
||
import json | ||
from common.helpers import ( | ||
ok_json, | ||
error_json | ||
) | ||
from airdrop.models import ( | ||
AirdropUser, | ||
PointsRecord | ||
) | ||
|
||
# @check_api_token | ||
def get_points_by_address(request): | ||
params = json.loads(request.body.decode()) | ||
address = params.get("address", None) | ||
if address is None: | ||
return error_json("address is empty", 4000) | ||
airdrop_user = AirdropUser.objects.filter(address=address).first() | ||
if airdrop_user is not None: | ||
return ok_json(airdrop_user.as_dict()) | ||
else: | ||
return error_json("No this user address points", 4000) | ||
|
||
# @check_api_token | ||
def get_points_record_by_address(request): | ||
params = json.loads(request.body.decode()) | ||
address = params.get("address", None) | ||
if address is None: | ||
return error_json("address is empty", 4000) | ||
page = params.get('page', 1) | ||
page_size = params.get('page_size', 20) | ||
start = (page - 1) * page_size | ||
end = start + page_size | ||
points = PointsRecord.objects.filter(address=address).order_by("-id")[start:end] | ||
total = PointsRecord.objects.filter(address=address).order_by("-id").count() | ||
point_list = [] | ||
for point in points: | ||
point_list.append(point.as_dict()) | ||
data = { | ||
"total": total, | ||
"points": point_list, | ||
} | ||
return ok_json(data) | ||
|
||
|
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