Skip to content

Commit

Permalink
Add submit signature with ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 committed Oct 26, 2023
1 parent e0ca8e8 commit 0e7a964
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions safe_cli/operators/safe_tx_service_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ def submit_signatures(self, safe_tx_hash: bytes) -> bool:
for account in self.accounts:
if account.address in owners:
safe_tx.sign(account.key)
# Check if there is ledger signers
if self.ledger_manager:
selected_ledger_accounts = []
for ledger_account in self.ledger_manager.accounts:
if ledger_account.address in owners:
selected_ledger_accounts.append(ledger_account)
if len(selected_ledger_accounts) > 0:
safe_tx = self.ledger_manager.sign_eip712(
safe_tx, selected_ledger_accounts
)

if safe_tx.signers:
self.safe_tx_service.post_signatures(safe_tx_hash, safe_tx.signatures)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_safe_tx_service_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from eth_account import Account
from hexbytes import HexBytes
from ledgereth.objects import LedgerAccount
from web3 import Web3

from gnosis.eth import EthereumClient
Expand Down Expand Up @@ -134,6 +135,24 @@ def test_submit_signatures(
get_safe_transaction_mock.return_value = GetMultisigTxRequestMock(executed=True)
self.assertFalse(safe_operator.submit_signatures(safe_tx_hash))

# Test ledger signers
with mock.patch.object(
SafeTx, "signers", return_value=["signer"], new_callable=mock.PropertyMock
) as mock_safe_tx:
safe_operator.ledger_manager.sign_eip712 = MagicMock(
return_value=mock_safe_tx
)
get_safe_transaction_mock.return_value = GetMultisigTxRequestMock(
executed=False
)
safe_operator.ledger_manager.accounts.add(
LedgerAccount("44'/60'/0'/0", Account.create().address)
)
get_permitted_signers_mock.return_value = {
list(safe_operator.ledger_manager.accounts)[0].address
}
self.assertTrue(safe_operator.submit_signatures(safe_tx_hash))

@mock.patch.object(TransactionServiceApi, "post_transaction", return_value=True)
@mock.patch.object(
SafeTx, "safe_version", return_value="1.4.1", new_callable=mock.PropertyMock
Expand Down

0 comments on commit 0e7a964

Please sign in to comment.