Skip to content

Commit 5992101

Browse files
feat: allow to exclude bc info in oracle api (#352)
* feat: allow to exclude bc info in oracle api * fix: add docs * fix: exclude bc data by default in oracle api * chore: inc ver * fix: added the typo key back and kept the response schema consistent --------- Co-authored-by: Cristi Bleotiu <cristibleotiu@gmail.com>
1 parent 3f5ca02 commit 5992101

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

extensions/business/oracle_management/oracle_api.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def __get_signed_data(self, node_addr : str, epochs : list, epochs_vals : list,
238238
return data
239239

240240

241-
def __get_node_epochs(self, node_addr: str, start_epoch: int = 1, end_epoch: int = None):
241+
def __get_node_epochs(self, node_addr: str, start_epoch: int = 1, end_epoch: int = None, include_bc_info: bool = False):
242242
"""
243243
Get the epochs availabilities for a given node.
244244
@@ -253,6 +253,9 @@ def __get_node_epochs(self, node_addr: str, start_epoch: int = 1, end_epoch: int
253253
end_epoch : int
254254
The last epoch to get the availability for.
255255
256+
include_bc_info : bool
257+
If True, the blockchain license info will be included in the response.
258+
256259
Returns
257260
-------
258261
dict
@@ -357,7 +360,10 @@ def __get_node_epochs(self, node_addr: str, start_epoch: int = 1, end_epoch: int
357360
data['node_is_online'] = self.netmon.network_node_is_online(node_addr)
358361
data['node_version'] = self.netmon.network_node_version(node_addr)
359362
data['node_is_oracle'] = self.netmon.network_node_is_supervisor(node_addr)
360-
data['node_licese_info'] = self.bc.get_node_license_info(node_addr)
363+
node_license_info = self.bc.get_node_license_info(node_addr) if include_bc_info else None
364+
data['node_license_info'] = node_license_info
365+
# Typo key kept for backward compatibility
366+
data['node_licese_info'] = node_license_info
361367
except:
362368
data['node_is_online'] = False
363369
data['node_version'] = "unknown"
@@ -553,7 +559,8 @@ def node_epochs_range(
553559
start_epoch : int,
554560
end_epoch : int,
555561
eth_node_addr : str = None,
556-
node_addr: str = None
562+
node_addr: str = None,
563+
include_bc_info: bool = False,
557564
):
558565
"""
559566
Returns the list of epochs availabilities for a given node in a given range of epochs.
@@ -572,6 +579,9 @@ def node_epochs_range(
572579
end_epoch : int
573580
The last epoch of the range.
574581
582+
include_bc_info : bool
583+
If True, the blockchain license info will be included in the response.
584+
575585
Returns
576586
-------
577587
dict
@@ -600,24 +610,28 @@ def node_epochs_range(
600610
raise ValueError("Please provide either `eth_node_addr` or `node_addr`")
601611

602612
response = self.__get_response(self.__get_node_epochs(
603-
node_addr, start_epoch=start_epoch, end_epoch=end_epoch
613+
node_addr, start_epoch=start_epoch, end_epoch=end_epoch, include_bc_info=include_bc_info
604614
))
605615
return response
606616

607617
@BasePlugin.endpoint(method='POST')
608618
def multi_node_epochs_range(
609619
self,
610620
dct_eth_nodes_request: dict, # {node_addr: [start_epoch, end_epoch]}
621+
include_bc_info: bool = False,
611622
):
612623
"""
613624
Returns the list of epochs availabilities for a list of given nodes each with start-end epochs.
614625
615626
Parameters
616627
----------
617628
618-
dct_node_request : dict
629+
dct_eth_nodes_request : dict
619630
A dictionary where each key is the eth address of a node and the value is a list with start and end epochs.
620631
632+
include_bc_info : bool
633+
If True, the blockchain license info will be included in the response.
634+
621635
Returns
622636
-------
623637
dict
@@ -662,7 +676,8 @@ def multi_node_epochs_range(
662676
node_data = self.__get_node_epochs(
663677
node_addr_internal,
664678
start_epoch=epochs[0],
665-
end_epoch=epochs[1]
679+
end_epoch=epochs[1],
680+
include_bc_info=include_bc_info
666681
)
667682
all_nodes[eth_node_addr] = node_data
668683
# endfor eth_node_addr, epochs in dct_eth_nodes_request.items()
@@ -673,7 +688,7 @@ def multi_node_epochs_range(
673688

674689
@BasePlugin.endpoint
675690
# /node_epochs
676-
def node_epochs(self, eth_node_addr: str = None, node_addr: str = None):
691+
def node_epochs(self, eth_node_addr: str = None, node_addr: str = None, include_bc_info: bool = False):
677692
"""
678693
Returns the list of epochs availabilities for a given node.
679694
@@ -685,6 +700,9 @@ def node_epochs(self, eth_node_addr: str = None, node_addr: str = None):
685700
node_addr : str
686701
The internal address of a node.
687702
703+
include_bc_info : bool
704+
If True, the blockchain license info will be included in the response.
705+
688706
Returns
689707
-------
690708
dict
@@ -701,12 +719,12 @@ def node_epochs(self, eth_node_addr: str = None, node_addr: str = None):
701719
if not isinstance(node_addr, str):
702720
return None
703721

704-
response = self.__get_response(self.__get_node_epochs(node_addr))
722+
response = self.__get_response(self.__get_node_epochs(node_addr, include_bc_info=include_bc_info))
705723
return response
706724

707725
@BasePlugin.endpoint
708726
# /node_epoch
709-
def node_epoch(self, epoch: int, eth_node_addr: str = None, node_addr: str = None):
727+
def node_epoch(self, epoch: int, eth_node_addr: str = None, node_addr: str = None, include_bc_info: bool = False):
710728
"""
711729
Returns the availability of a given node in a given epoch.
712730
@@ -721,6 +739,9 @@ def node_epoch(self, epoch: int, eth_node_addr: str = None, node_addr: str = Non
721739
epoch : int
722740
The target epoch.
723741
742+
include_bc_info : bool
743+
If True, the blockchain license info will be included in the response.
744+
724745
Returns
725746
-------
726747
dict
@@ -742,7 +763,7 @@ def node_epoch(self, epoch: int, eth_node_addr: str = None, node_addr: str = Non
742763
elif node_addr is None:
743764
raise ValueError("Please provide either `eth_node_addr` or `node_addr`")
744765

745-
data = self.__get_node_epochs(node_addr, start_epoch=epoch, end_epoch=epoch)
766+
data = self.__get_node_epochs(node_addr, start_epoch=epoch, end_epoch=epoch, include_bc_info=include_bc_info)
746767
if isinstance(data.get('epochs_vals'), list) and len(data['epochs_vals']) > 0:
747768
epoch_val = data['epochs_vals'][0]
748769
epoch_val_direct = self.netmon.epoch_manager.get_node_epoch(node_addr, epoch)
@@ -761,7 +782,7 @@ def node_epoch(self, epoch: int, eth_node_addr: str = None, node_addr: str = Non
761782

762783
@BasePlugin.endpoint
763784
# /node_last_epoch
764-
def node_last_epoch(self, eth_node_addr: str = None, node_addr: str = None):
785+
def node_last_epoch(self, eth_node_addr: str = None, node_addr: str = None, include_bc_info: bool = False):
765786
"""
766787
Returns the availability of a given node in the last epoch.
767788
@@ -772,6 +793,9 @@ def node_last_epoch(self, eth_node_addr: str = None, node_addr: str = None):
772793
773794
node_addr : str
774795
The internal address of a node.
796+
797+
include_bc_info : bool
798+
If True, the blockchain license info will be included in the response.
775799
776800
Note: Please provide either `eth_node_addr` or `node_addr`.
777801
@@ -798,7 +822,7 @@ def node_last_epoch(self, eth_node_addr: str = None, node_addr: str = None):
798822
raise ValueError("Please provide either `eth_node_addr` or `node_addr`")
799823

800824
epoch = self.__get_synced_epoch()
801-
data = self.__get_node_epochs(node_addr, start_epoch=epoch, end_epoch=epoch)
825+
data = self.__get_node_epochs(node_addr, start_epoch=epoch, end_epoch=epoch, include_bc_info=include_bc_info)
802826
if isinstance(data.get('epochs_vals'), list) and len(data['epochs_vals']) > 0:
803827
epoch_val = data['epochs_vals'][0]
804828
epoch_val_direct = self.netmon.epoch_manager.get_node_epoch(node_addr, epoch)

ver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__VER__ = '2.10.31'
1+
__VER__ = '2.10.32'

0 commit comments

Comments
 (0)