Commit 6b67dc7c authored by Maurelian's avatar Maurelian

feat(ctb): Emit SignersRecorded event

parent 8e2a6dec
...@@ -7,6 +7,10 @@ import { SignatureDecoder } from "safe-contracts/common/SignatureDecoder.sol"; ...@@ -7,6 +7,10 @@ import { SignatureDecoder } from "safe-contracts/common/SignatureDecoder.sol";
import { Enum } from "safe-contracts/common/Enum.sol"; import { Enum } from "safe-contracts/common/Enum.sol";
contract LivenessGuard is SignatureDecoder, BaseGuard { contract LivenessGuard is SignatureDecoder, BaseGuard {
/// @notice Emitted when a new set of signers is recorded.
/// @param signers An arrary of signer addresses.
event SignersRecorded(bytes32 indexed txHash, address[] signers);
Safe public safe; Safe public safe;
mapping(address => uint256) public lastSigned; mapping(address => uint256) public lastSigned;
...@@ -41,7 +45,8 @@ contract LivenessGuard is SignatureDecoder, BaseGuard { ...@@ -41,7 +45,8 @@ contract LivenessGuard is SignatureDecoder, BaseGuard {
// TODO(Maurelian): Figure out how to best address this. // TODO(Maurelian): Figure out how to best address this.
} }
// This is a bit of a hack, maybe just replicate the functionality here rather than calling home // This call will reenter to the Safe which is calling it. This is OK because it is only reading the
// nonce, and using the getTransactionHash() method.
bytes32 txHash = Safe(payable(msg.sender)).getTransactionHash( bytes32 txHash = Safe(payable(msg.sender)).getTransactionHash(
// Transaction info // Transaction info
to, to,
...@@ -55,11 +60,13 @@ contract LivenessGuard is SignatureDecoder, BaseGuard { ...@@ -55,11 +60,13 @@ contract LivenessGuard is SignatureDecoder, BaseGuard {
gasToken, gasToken,
refundReceiver, refundReceiver,
// Signature info // Signature info
Safe(payable(msg.sender)).nonce() - 1
); );
address[] memory signers = _getNSigners(txHash, signatures); address[] memory signers = _getNSigners(txHash, signatures);
for (uint256 i = 0; i < signers.length; i++) { for (uint256 i = 0; i < signers.length; i++) {
lastSigned[signers[i]] = block.timestamp; lastSigned[signers[i]] = block.timestamp;
} }
emit SignersRecorded(txHash, signers);
} }
/// @notice Exctract the signers from a set of signatures. /// @notice Exctract the signers from a set of signatures.
......
...@@ -21,6 +21,8 @@ import { LivenessGuard } from "src/Safe/LivenessGuard.sol"; ...@@ -21,6 +21,8 @@ import { LivenessGuard } from "src/Safe/LivenessGuard.sol";
contract LivnessGuard_TestInit is Test, SafeTestTools { contract LivnessGuard_TestInit is Test, SafeTestTools {
using SafeTestLib for SafeInstance; using SafeTestLib for SafeInstance;
event SignersRecorded(bytes32 indexed txHash, address[] signers);
LivenessGuard livenessGuard; LivenessGuard livenessGuard;
SafeInstance safeInstance; SafeInstance safeInstance;
...@@ -35,6 +37,9 @@ contract LivnessGuard_TestCheckTx is LivnessGuard_TestInit { ...@@ -35,6 +37,9 @@ contract LivnessGuard_TestCheckTx is LivnessGuard_TestInit {
using SafeTestLib for SafeInstance; using SafeTestLib for SafeInstance;
function test_checkTransaction_succeeds() external { function test_checkTransaction_succeeds() external {
// Don't check topic1 so that we can avoid the ugly txHash calculation.
vm.expectEmit(false, true, true, true, address(livenessGuard));
emit SignersRecorded(0x0, safeInstance.owners);
safeInstance.execTransaction({ to: address(1111), value: 0, data: hex"abba" }); safeInstance.execTransaction({ to: address(1111), value: 0, data: hex"abba" });
for (uint256 i; i < safeInstance.owners.length; i++) { for (uint256 i; i < safeInstance.owners.length; i++) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment