mirror of
https://github.com/fusion44/blitz_api.git
synced 2026-08-13 11:52:45 +02:00
28 lines
868 B
Python
28 lines
868 B
Python
import requests
|
|
import json
|
|
from decouple import config
|
|
|
|
BITCOIND_IP = config("bitcoind_ip")
|
|
BITCOIND_PORT = config("bitcoind_port")
|
|
BITCOIND_USER = config("bitcoind_user")
|
|
BITCOIND_PW = config("bitcoind_pw")
|
|
|
|
|
|
def bitcoin_rpc(method: str, params: list = []) -> requests.Response:
|
|
"""Make an RPC request to the Bitcoin daemon
|
|
|
|
Connection parameters are read from the .env file.
|
|
|
|
Parameters
|
|
----------
|
|
method : str
|
|
The method to call.
|
|
params : list, optional
|
|
Any parameters to include with the call
|
|
"""
|
|
url = f"http://{BITCOIND_IP}:{BITCOIND_PORT}"
|
|
auth = (BITCOIND_USER, BITCOIND_PW)
|
|
headers = {"Content-type": "text/plain"}
|
|
data = '{"jsonrpc": "2.0", "method": "' + \
|
|
method + '", "id":"0", "params":' + json.dumps(params) + '}'
|
|
return requests.post(url, auth=auth, headers=headers, data=data)
|