def get_queryset(self): if self.request.GET.get("account"): return Wallet.objects.filter( account__name=self.request.GET.get("account")) else: return Wallet.objects.filter(account__name=get_default_account())
def params(self, request, *args, **kwargs): """ Вернуть настройки json RPC для ноды """ params = ("login", "password", "IP", "port") res = [] for param in params: res.append({ "key": param, "value": getattr(config, "NODE_{}".format(param.upper())) }) res.append({"key": "default_account", "value": get_default_account()}) return Response({"settings": res})
def create(self, request): """POST методы - проверить баланс, создать BTC кошелек на ноде""" method = request.data.get("method") if method and method == "create_wallet": conn = get_node_connect() account = self.request.data.get("account") or get_default_account() acc_obj = BTCAccount.objects.filter(name=account).first() if not acc_obj: raise ValidationError( "Incorrect account name {}".format(account)) new_wallet = create_wallet(conn, account) Wallet.objects.create(account=acc_obj, wallet=new_wallet) return Response({"wallet_created": new_wallet, "account": account}) return Response({ "method": method, "available_methods": ["create_wallet"] })
class ListWalletsView(ModelViewSet): authentication_classes = (SessionAuthentication, BasicAuthentication) permission_classes = (permissions.IsAuthenticated, ) serializer_class = WalletSerializer queryset = Wallet.objects.filter(account__name=get_default_account()) def get_queryset(self): if self.request.GET.get("account"): return Wallet.objects.filter( account__name=self.request.GET.get("account")) else: return Wallet.objects.filter(account__name=get_default_account()) def create(self, request): """POST методы - проверить баланс, создать BTC кошелек на ноде""" method = request.data.get("method") if method and method == "create_wallet": conn = get_node_connect() account = self.request.data.get("account") or get_default_account() acc_obj = BTCAccount.objects.filter(name=account).first() if not acc_obj: raise ValidationError( "Incorrect account name {}".format(account)) new_wallet = create_wallet(conn, account) Wallet.objects.create(account=acc_obj, wallet=new_wallet) return Response({"wallet_created": new_wallet, "account": account}) return Response({ "method": method, "available_methods": ["create_wallet"] })
def default(self, request, *args, **kwargs): """ Вернуть accоunt по умолчанию """ account = get_default_account() return Response({"default_account": account})