0

Looking for some help here. I am trying to create a Django Rest API for payments using an LND node. I am following the documentation of the Lnd REST API (https://api.lightning.community/#v1-balance-blockchain), but as I am quite new in both, I am struggling with how to connect to the node through the API. I am guessing we need to override the queryset in order to access the locally running node. But I am not being able to figure out how.This is the information to access my node and view.py:

from rest_framework.response import Response
from rest_framework import status
from rest_framework.response import Response
import os
import base64, codecs, json, requests


@api_view(["GET", "POST"])
def WalletBalance(self, r, *args, **kwargs):
    url = "https://localhost:8080/v1/balance/blockchain"
    cert_path = "~/Library/Application Support/Lnd/tls.cert"
    macaroon = codecs.encode(
        open(
            "$HOME/Library/Application Support/Lnd/data/chain/bitcoin/testnet/admin.macaroon",
            "rb",
        ).read(),
        "hex",
    )
    headers = {"Grpc-Metadata-macaroon": macaroon}
    r = requests.get(url, headers=headers, verify=cert_path)
    return self.list(r, *args, **kwargs)
    queryset = Class.objects.all()
    # serializer_class = ClassesSerializer

And this is the models.py:

from pydoc import describe
from unittest.util import _MAX_LENGTH
from django.db import models


class WalletBalance(models.Model):
    total_balance = models.CharField(max_length=200)
    confirmed_balance = models.CharField(max_length=200)
    unconfirmed_balance = models.CharField(max_length=200)
    locked_balance = models.CharField(max_length=200)
    reserved_balance_anchor_chan = models.CharField(max_length=200)
    confirm_balance = models.CharField(max_length=200)
    uncomfirm_balance = models.CharField(max_length=200)

I would appreciate if you could help me. Thanks a lot in advance.

Pau1aAm7
  • 1
  • 2

0 Answers0