连接到本地运行的Django Rest API的LND节点

huangapple go评论55阅读模式
英文:

Connecting to LND Node through a local-running Django Rest API

问题

I am trying to connect to my LND node running on AWS (I know it is not the best case scenario for an LND node but this time I had no other way of doing it) from my local running Django Rest Api. The issue is that it cannot find the admin.macaroon file even though the file is in the mentioned directory. Below I am giving some more detailed information:

view.py

class GetInfo(APIView):
    def get(self, request):
        REST_HOST = "https://ec2-18-195-111-81.eu-central-1.compute.amazonaws.com"
        MACAROON_PATH = "/home/ubuntu/.lnd/data/chain/bitcoin/mainnet/admin.macaroon"
        # url = "https://ec2-18-195-111-81.eu-central-1.compute.amazonaws.com/v1/getinfo"
        TLS_PATH = "/home/ubuntu/.lnd/tls.cert"

        url = f"https//{REST_HOST}/v1/getinfo"
        macaroon = codecs.encode(open(MACAROON_PATH, "rb").read(), "hex")
        headers = {"Grpc-Metadata-macaroon": macaroon}
        r = requests.get(url, headers=headers, verify=TLS_PATH)
        return Response(json.loads(r.text))

The node is running with no problem on AWS. This is what I get when I run lncli getinfo:

$ lncli getinfo:
{
"version": "0.15.5-beta commit=v0.15.5-beta",
"commit_hash": "c0a09209782b1c62c3393fcea0844exxxxxxxxxx",
"identity_pubkey": "mykey",
"alias": "020d4da213770890e1c1",
"color": "#3399ff",
"num_pending_channels": 0,
"num_active_channels": 0,
"num_inactive_channels": 0,
"uris": [....

and the permissions are as below:

$ ls -l
total 138404
-rwxrwxr-x 1 ubuntu ubuntu 293 Feb 6 09:38 admin.macaroon
drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 5 14:48 bin
drwxr-xr-x 6 ubuntu ubuntu 4096 Jan 27 20:17 bitcoin-22.0
drwxrwxr-x 4 ubuntu ubuntu 4096 Feb 1 16:39 go
-rw-rw-r-- 1 ubuntu ubuntu 141702072 Mar 15 2022 go1.18.linux-amd64.tar.gz
drwxrwxr-x 72 ubuntu ubuntu 4096 Feb 1 16:36 lnd
-rw-rw-r-- 1 ubuntu ubuntu 0 Jan 27 20:13 screenlog.0

The error I get is [Errno 2] No such file or directory:'/home/ubuntu/.lnd/data/chain/bitcoin/mainnet/admin.macaroon'

I guess the problem should be how I need to access the node from my API, but I have no idea how to access an EC2 instance from an external api.
Thank you in advance

英文:

I am trying to connect to my LND node running on AWS (I know it is not the best case scenario for an LND node but this time I had no other way of doing it) from my local running Django Rest Api. The issue is that it cannot find the admin.macaroon file even though the file is in the mentioned directory. Below I am giving some more detailed information:

view.py

class GetInfo(APIView):
    def get(self, request):
        REST_HOST = "https://ec2-18-195-111-81.eu-central-1.compute.amazonaws.com"
        MACAROON_PATH = "/home/ubuntu/.lnd/data/chain/bitcoin/mainnet/admin.macaroon"
        # url = "https://ec2-18-195-111-81.eu-central-1.compute.amazonaws.com/v1/getinfo"
        TLS_PATH = "/home/ubuntu/.lnd/tls.cert"

        url = f"https//{REST_HOST}/v1/getinfo"
        macaroon = codecs.encode(open(MACAROON_PATH, "rb").read(), "hex")
        headers = {"Grpc-Metadata-macaroon": macaroon}
        r = requests.get(url, headers=headers, verify=TLS_PATH)
        return Response(json.loads(r.text))

The node is running with no problem on AWS. This is what I get when I run lncli getinfo:

$ lncli getinfo:
{
"version": "0.15.5-beta commit=v0.15.5-beta",
"commit_hash": "c0a09209782b1c62c3393fcea0844exxxxxxxxxx",
"identity_pubkey": "mykey",
"alias": "020d4da213770890e1c1",
"color": "#3399ff",
"num_pending_channels": 0,
"num_active_channels": 0,
"num_inactive_channels": 0,
"uris": [
....

and the permissions are as below:

$ ls -l
total 138404
-rwxrwxr-x 1 ubuntu ubuntu 293 Feb 6 09:38 admin.macaroon
drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 5 14:48 bin
drwxr-xr-x 6 ubuntu ubuntu 4096 Jan 27 20:17 bitcoin-22.0
drwxrwxr-x 4 ubuntu ubuntu 4096 Feb 1 16:39 go
-rw-rw-r-- 1 ubuntu ubuntu 141702072 Mar 15 2022 go1.18.linux-amd64.tar.gz
drwxrwxr-x 72 ubuntu ubuntu 4096 Feb 1 16:36 lnd
-rw-rw-r-- 1 ubuntu ubuntu 0 Jan 27 20:13 screenlog.0

The error I get is [Errno 2] No such file or directory:'/home/ubuntu/.lnd/data/chain/bitcoin/mainnet/admin.macaroon'

I guess the problem should be how I need to access the node from my API, but I have no idea how to access an EC2 instance from an external api.
Thank you in advance

答案1

得分: 0

我需要通过我的API使用SSH连接到EC-2。为此,我使用了boto3和paramiko。

英文:

I needed to connect to the EC-2 through my API using SSH. To do that I used boto3 and paramiko.

huangapple
  • 本文由 发表于 2023年2月6日 19:07:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75360526.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定