Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/safe_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,16 @@ def default_attended_mode(

def _is_safe_cli_default_command(arguments: List[str]) -> bool:
# safe-cli
if len(sys.argv) == 1:
if len(arguments) == 1:
return True

if sys.argv[1] == "--help":
if arguments[1] == "--help":
return True

# Only added if is not a valid command, and it is an address. safe-cli 0xaddress http://url
if sys.argv[1] not in [
if arguments[1] not in [
get_command_name(key) for key in get_command(app).commands.keys()
] and Web3.is_checksum_address(sys.argv[1]):
] and Web3.is_checksum_address(arguments[1]):
return True

return False
Expand Down
103 changes: 56 additions & 47 deletions src/safe_cli/operators/safe_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,13 @@ def load_cli_owners_from_words(self, words: List[str]):
words = os.environ.get(words[0], default="").strip().split(" ")
parsed_words = " ".join(words)
try:
for index in range(100): # Try first accounts of seed phrase
accounts = []
for index in range(100): # Try first 100 accounts of seed phrase
account = get_account_from_words(parsed_words, index=index)
if account.address in self.safe_cli_info.owners:
self.load_cli_owners([to_0x_hex_str(account.key)])
if not index:
accounts.append(account)
if not accounts:
print_formatted_text(
HTML(
"<ansired>Cannot generate any valid owner for this Safe</ansired>"
Expand Down Expand Up @@ -416,58 +418,57 @@ def show_cli_owners(self):
)

def approve_hash(self, hash_to_approve: HexBytes, sender: str) -> bool:
sender_account = [
sender_accounts = [
account for account in self.accounts if account.address == sender
]
if not sender_account:
if not sender_accounts:
raise AccountNotLoadedException(sender)
elif sender not in self.safe_cli_info.owners:

sender_account = sender_accounts[0]
sender_account_address = sender_account.address
if sender_account_address not in self.safe_cli_info.owners:
raise NonExistingOwnerException(sender)
elif self.safe.retrieve_is_hash_approved(
self.default_sender.address, hash_to_approve
sender_account_address, hash_to_approve
):
raise HashAlreadyApproved(hash_to_approve, self.default_sender.address)
raise HashAlreadyApproved(hash_to_approve, sender)
transaction_to_send = self.safe_contract.functions.approveHash(
hash_to_approve
).build_transaction(
{
"from": sender_account_address,
"nonce": self.ethereum_client.get_nonce_for_account(
sender_account_address
),
}
)
if self.ethereum_client.is_eip1559_supported():
transaction_to_send = self.ethereum_client.set_eip1559_fees(
transaction_to_send
)
call_result = self.ethereum_client.w3.eth.call(transaction_to_send)
if call_result: # There's revert message
return False
else:
sender_account = sender_account[0]
transaction_to_send = self.safe_contract.functions.approveHash(
hash_to_approve
).build_transaction(
{
"from": sender_account.address,
"nonce": self.ethereum_client.get_nonce_for_account(
sender_account.address
),
}
signed_transaction = sender_account.sign_transaction(transaction_to_send)
tx_hash = self.ethereum_client.send_raw_transaction(
signed_transaction["raw_transaction"]
)
if self.ethereum_client.is_eip1559_supported():
transaction_to_send = self.ethereum_client.set_eip1559_fees(
transaction_to_send
print_formatted_text(
HTML(
f"<ansigreen>Sent tx with tx-hash {to_0x_hex_str(tx_hash)} from owner "
f"{sender_account_address}, waiting for receipt</ansigreen>"
)
call_result = self.ethereum_client.w3.eth.call(transaction_to_send)
if call_result: # There's revert message
return False
)
if self.ethereum_client.get_transaction_receipt(tx_hash, timeout=120):
return True
else:
signed_transaction = sender_account.sign_transaction(
transaction_to_send
)
tx_hash = self.ethereum_client.send_raw_transaction(
signed_transaction["raw_transaction"]
)
print_formatted_text(
HTML(
f"<ansigreen>Sent tx with tx-hash {to_0x_hex_str(tx_hash)} from owner "
f"{self.default_sender.address}, waiting for receipt</ansigreen>"
f"<ansired>Tx with tx-hash {to_0x_hex_str(tx_hash)} still not mined</ansired>"
)
)
if self.ethereum_client.get_transaction_receipt(tx_hash, timeout=120):
return True
else:
print_formatted_text(
HTML(
f"<ansired>Tx with tx-hash {to_0x_hex_str(tx_hash)} still not mined</ansired>"
)
)
return False
return False

def sign_message(
self,
Expand All @@ -489,7 +490,9 @@ def sign_message(
sign_message_lib_address = get_last_sign_message_lib_address(
self.ethereum_client
)
contract = get_sign_message_lib_contract(self.ethereum_client.w3, self.address)
contract = get_sign_message_lib_contract(
self.ethereum_client.w3, sign_message_lib_address
)
sign_message_data = HexBytes(
contract.functions.signMessage(message_bytes).build_transaction(
get_empty_tx_params(),
Expand Down Expand Up @@ -907,14 +910,20 @@ def get_safe_cli_info(self) -> SafeCliInfo:
safe_info.version,
)

def get_threshold(self):
print_formatted_text(self.safe.retrieve_threshold())
def get_threshold(self) -> int:
threshold = self.safe.retrieve_threshold()
print_formatted_text(threshold)
return threshold

def get_nonce(self):
print_formatted_text(self.safe.retrieve_nonce())
def get_nonce(self) -> int:
nonce = self.safe.retrieve_nonce()
print_formatted_text(nonce)
return nonce

def get_owners(self):
print_formatted_text(self.safe.retrieve_owners())
def get_owners(self) -> List[ChecksumAddress]:
owners = self.safe.retrieve_owners()
print_formatted_text(owners)
return owners

def execute_safe_internal_transaction(self, data: bytes) -> bool:
return self.prepare_and_execute_safe_transaction(self.address, 0, data)
Expand Down
1 change: 1 addition & 0 deletions src/safe_cli/operators/safe_tx_service_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def batch_txs(self, safe_nonce: int, safe_tx_hashes: Sequence[bytes]) -> bool:
"batching txs</ansired>"
)
)
return False

multisend_txs = []
for safe_tx_hash in safe_tx_hashes:
Expand Down