forked from bitcoin-dev-project/warnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend_interface.py
124 lines (105 loc) · 4.11 KB
/
backend_interface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from abc import ABC, abstractmethod
from enum import Enum
from pathlib import Path
class ServiceType(Enum):
BITCOIN = 1
LIGHTNING = 2
CIRCUITBREAKER = 3
class BackendInterface(ABC):
def __init__(self, config_dir: Path) -> None:
self.config_dir = config_dir
self.client = None
@abstractmethod
def build(self) -> bool:
"""
Build a network
e.g. `docker compose build`
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def up(self, warnet) -> bool:
"""
Bring an exsiting network that is down, back up.
e.g. `docker compose -p up -d`
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def down(self, warnet) -> bool:
"""
Bring an exsiting network down.
e.g. `docker compose down`
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def get_status(self, tank_index: int, service: ServiceType):
"""
Get the running status of a tank by [tanks_index]
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def exec_run(self, tank_index: int, service: ServiceType, cmd: str):
"""
Exectute a command on tank [tank_index] in service [service]
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def get_bitcoin_debug_log(self, tank_index: int):
"""
Fetch debug log from tank [tank_index]
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def ln_cli(self, tank, command: list[str]) -> str:
"""
Call `lightning cli` on tank [tank_index] with <command>
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def get_bitcoin_cli(self, tank, method: str, params=None):
"""
Call `bitcoin-cli` on tank [tank_index] with [method] and <params>
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def get_file(self, tank_index: int, service: ServiceType, file_path: str):
"""
Read a file from inside a container
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def get_messages(self, a_index: int, b_index: int, bitcoin_network: str = "regtest"):
"""
Get bitcoin messages between containers [a_index] and [b_index] on [bitcoin_network]
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def logs_grep(self, pattern: str, network: str):
"""
Grep logs from all containers matching [pattern] from [network]
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def generate_deployment_file(self, warnet) -> None:
"""
Generate a deployment configuration file e.g docker-compose.yml
Should set warnet.deployment_file
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def get_tank_ipv4(self, index: int) -> str:
"""
Get the ipv4 address assigned to a bitcoind tank from the backend
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def get_lnnode_hostname(self, index: int) -> str:
"""
Get the hostname assigned to a lnnode attached to a tank from the backend
"""
raise NotImplementedError("This method should be overridden by child class")
@abstractmethod
def wait_for_healthy_tanks(self, warnet, timeout=60) -> bool:
"""
Wait for healthy status on all bitcoind nodes
"""
raise NotImplementedError("This method should be overridden by child class")