Skip to content

Commit

Permalink
update talgo_client
Browse files Browse the repository at this point in the history
  • Loading branch information
etzellux committed Jan 31, 2025
1 parent aace011 commit bec5422
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tinyman/liquid_staking/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ def calculate_min_balance(self, accounts=0, assets=0, boxes=None):
def add_key(self, address, key):
self.keys[address] = key

def get_globals(self, app_id=None):
app_id = app_id or self.app_id
gs = self.algod.application_info(app_id)["params"]["global-state"]
global_state = {s["key"]: s["value"] for s in gs}
state = {}
for key in global_state:
k = b64decode(key)
value = global_state[key]
if value["type"] == 2:
state[k] = value["uint"]
else:
state[k] = b64decode(value["bytes"])
state = dict(sorted(state.items(), key=lambda x: x[0]))
return state

def get_global(self, key, default=None, app_id=None):
app_id = app_id or self.app_id
global_state = {s["key"]: s["value"] for s in self.algod.application_info(app_id)["params"]["global-state"]}
Expand Down
19 changes: 19 additions & 0 deletions tinyman/liquid_staking/talgo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ def burn(self, amount):
]
return self._submit(transactions, additional_fees=1)

def get_state(self):
state = self.get_globals()
state[b"account_0"] = encode_address(state[b"account_0"])
state[b"account_1"] = encode_address(state[b"account_1"])
state[b"account_2"] = encode_address(state[b"account_2"])
state[b"account_3"] = encode_address(state[b"account_3"])
state[b"account_4"] = encode_address(state[b"account_4"])
state[b"node_manager_0"] = encode_address(state[b"node_manager_0"])
state[b"node_manager_1"] = encode_address(state[b"node_manager_1"])
state[b"node_manager_2"] = encode_address(state[b"node_manager_2"])
state[b"node_manager_3"] = encode_address(state[b"node_manager_3"])
state[b"node_manager_4"] = encode_address(state[b"node_manager_4"])
state[b"manager"] = encode_address(state[b"manager"])
state[b"stake_manager"] = encode_address(state[b"stake_manager"])
if b"proposed_manager" in state:
state[b"proposed_manager"] = encode_address(state[b"proposed_manager"])
state[b"fee_collector"] = encode_address(state[b"fee_collector"])
return state

def go_online(self, node_index, vote_pk, selection_pk, state_proof_pk, vote_first, vote_last, vote_key_dilution, fee):
account_address = encode_address(self.get_global(b"account_%i" % node_index))
# Use the user keys for signing transactions from the account_address
Expand Down

0 comments on commit bec5422

Please sign in to comment.