-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouterRegistry.sol
More file actions
51 lines (40 loc) · 1.7 KB
/
Copy pathRouterRegistry.sol
File metadata and controls
51 lines (40 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import "./interfaces/IRouterRegistry.sol";
import "./lib/AgentPayErrors.sol";
/**
* @title RouterRegistry
* @notice Optional global registry where relay-router operators advertise themselves
* to the AgentPay network. Each registered router stores the unix timestamp
* (seconds) of its most recent registration or refresh; off-chain consumers may
* use this for liveness signaling and router discovery.
* @dev See {IRouterRegistry} for canonical NatSpec on each function.
*/
contract RouterRegistry is IRouterRegistry {
/// @notice Registered router addresses → unix timestamp (seconds) of most recent register/refresh.
mapping(address => uint256) public routerInfo;
/**
* @notice An external router could register to join the AgentPay Network
*/
function registerRouter() external {
require(routerInfo[msg.sender] == 0, AgentPayErrors.RouterAlreadyRegistered());
routerInfo[msg.sender] = block.timestamp;
emit RouterUpdated(RouterOperation.Add, msg.sender);
}
/**
* @notice An in-network router could deregister to leave the network
*/
function deregisterRouter() external {
require(routerInfo[msg.sender] != 0, AgentPayErrors.RouterNotRegistered());
delete routerInfo[msg.sender];
emit RouterUpdated(RouterOperation.Remove, msg.sender);
}
/**
* @notice Refresh the existed router's stored timestamp
*/
function refreshRouter() external {
require(routerInfo[msg.sender] != 0, AgentPayErrors.RouterNotRegistered());
routerInfo[msg.sender] = block.timestamp;
emit RouterUpdated(RouterOperation.Refresh, msg.sender);
}
}