• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

renproject / darknode-sol / cb0c000c-08ed-4fae-b264-72d86dd92fdc

pending completion
cb0c000c-08ed-4fae-b264-72d86dd92fdc

push

circleci

Jaz Gulati
feat: upgrade testnet dnr for subnet support

49 of 244 branches covered (20.08%)

Branch coverage included in aggregate %.

221 of 559 relevant lines covered (39.53%)

6.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.33
/contracts/DarknodeRegistry/DarknodeRegistryStore.sol
1
pragma solidity 0.5.17;
2

3
import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
4

5
import "../Governance/Claimable.sol";
6
import "../libraries/LinkedList.sol";
7
import "../RenToken/RenToken.sol";
8
import "../libraries/CanReclaimTokens.sol";
9

10
/// @notice This contract stores data and funds for the DarknodeRegistry
11
/// contract. The data / fund logic and storage have been separated to improve
12
/// upgradability.
13
contract DarknodeRegistryStore is Claimable, CanReclaimTokens {
14
    using SafeMath for uint256;
15

16
    string public VERSION; // Passed in as a constructor parameter.
17

18
    /// @notice Darknodes are stored in the darknode struct. The owner is the
19
    /// address that registered the darknode, the bond is the amount of REN that
20
    /// was transferred during registration, and the public key is the
21
    /// encryption key that should be used when sending sensitive information to
22
    /// the darknode.
23
    struct Darknode {
24
        // The owner of a Darknode is the address that called the register
25
        // function. The owner is the only address that is allowed to
26
        // deregister the Darknode, unless the Darknode is slashed for
27
        // malicious behavior.
28
        address payable owner;
29
        // The bond is the amount of REN submitted as a bond by the Darknode.
30
        // This amount is reduced when the Darknode is slashed for malicious
31
        // behavior.
32
        uint256 bond;
33
        // The block number at which the Darknode is considered registered.
34
        uint256 registeredAt;
35
        // The block number at which the Darknode is considered deregistered.
36
        uint256 deregisteredAt;
37
        // The public key used by this Darknode for encrypting sensitive data
38
        // off chain. It is assumed that the Darknode has access to the
39
        // respective private key, and that there is an agreement on the format
40
        // of the public key.
41
        bytes publicKey;
42
    }
43

44
    /// Registry data.
45
    mapping(address => Darknode) private darknodeRegistry;
46
    LinkedList.List private darknodes;
47

48
    // RenToken.
49
    RenToken public ren;
50

51
    /// @notice The contract constructor.
52
    ///
53
    /// @param _VERSION A string defining the contract version.
54
    /// @param _ren The address of the RenToken contract.
55
    constructor(string memory _VERSION, RenToken _ren) public {
56
        Claimable.initialize(msg.sender);
4✔
57
        CanReclaimTokens.initialize(msg.sender);
4✔
58
        VERSION = _VERSION;
4✔
59
        ren = _ren;
4✔
60
        blacklistRecoverableToken(address(ren));
4✔
61
    }
62

63
    /// @notice Instantiates a darknode and appends it to the darknodes
64
    /// linked-list.
65
    ///
66
    /// @param _darknodeID The darknode's ID.
67
    /// @param _darknodeOperator The darknode's owner's address.
68
    /// @param _bond The darknode's bond value.
69
    /// @param _publicKey The darknode's public key.
70
    /// @param _registeredAt The time stamp when the darknode is registered.
71
    /// @param _deregisteredAt The time stamp when the darknode is deregistered.
72
    function appendDarknode(
73
        address _darknodeID,
74
        address payable _darknodeOperator,
75
        uint256 _bond,
76
        bytes calldata _publicKey,
77
        uint256 _registeredAt,
78
        uint256 _deregisteredAt
79
    ) external onlyOwner {
80
        Darknode memory darknode =
40✔
81
            Darknode({
82
                owner: _darknodeOperator,
83
                bond: _bond,
84
                publicKey: _publicKey,
85
                registeredAt: _registeredAt,
86
                deregisteredAt: _deregisteredAt
87
            });
88
        darknodeRegistry[_darknodeID] = darknode;
40✔
89
        LinkedList.append(darknodes, _darknodeID);
40✔
90
    }
91

92
    /// @notice Returns the address of the first darknode in the store.
93
    function begin() external view onlyOwner returns (address) {
94
        return LinkedList.begin(darknodes);
2✔
95
    }
96

97
    /// @notice Returns the address of the next darknode in the store after the
98
    /// given address.
99
    function next(address darknodeID)
100
        external
101
        view
102
        onlyOwner
103
        returns (address)
104
    {
105
        return LinkedList.next(darknodes, darknodeID);
×
106
    }
107

108
    /// @notice Removes a darknode from the store and transfers its bond to the
109
    /// owner of this contract.
110
    function removeDarknode(address darknodeID) external onlyOwner {
111
        uint256 bond = darknodeRegistry[darknodeID].bond;
40✔
112
        delete darknodeRegistry[darknodeID];
40✔
113
        LinkedList.remove(darknodes, darknodeID);
40✔
114
        require(
40!
115
            ren.transfer(owner(), bond),
116
            "DarknodeRegistryStore: bond transfer failed"
117
        );
118
    }
119

120
    /// @notice Updates the bond of a darknode. The new bond must be smaller
121
    /// than the previous bond of the darknode.
122
    function updateDarknodeBond(address darknodeID, uint256 decreasedBond)
123
        external
124
        onlyOwner
125
    {
126
        uint256 previousBond = darknodeRegistry[darknodeID].bond;
×
127
        require(
×
128
            decreasedBond < previousBond,
129
            "DarknodeRegistryStore: bond not decreased"
130
        );
131
        darknodeRegistry[darknodeID].bond = decreasedBond;
×
132
        require(
×
133
            ren.transfer(owner(), previousBond.sub(decreasedBond)),
134
            "DarknodeRegistryStore: bond transfer failed"
135
        );
136
    }
137

138
    /// @notice Updates the deregistration timestamp of a darknode.
139
    function updateDarknodeDeregisteredAt(
140
        address darknodeID,
141
        uint256 deregisteredAt
142
    ) external onlyOwner {
143
        darknodeRegistry[darknodeID].deregisteredAt = deregisteredAt;
40✔
144
    }
145

146
    /// @notice Returns the owner of a given darknode.
147
    function darknodeOperator(address darknodeID)
148
        external
149
        view
150
        onlyOwner
151
        returns (address payable)
152
    {
153
        return darknodeRegistry[darknodeID].owner;
120✔
154
    }
155

156
    /// @notice Returns the bond of a given darknode.
157
    function darknodeBond(address darknodeID)
158
        external
159
        view
160
        onlyOwner
161
        returns (uint256)
162
    {
163
        return darknodeRegistry[darknodeID].bond;
40✔
164
    }
165

166
    /// @notice Returns the registration time of a given darknode.
167
    function darknodeRegisteredAt(address darknodeID)
168
        external
169
        view
170
        onlyOwner
171
        returns (uint256)
172
    {
173
        return darknodeRegistry[darknodeID].registeredAt;
80✔
174
    }
175

176
    /// @notice Returns the deregistration time of a given darknode.
177
    function darknodeDeregisteredAt(address darknodeID)
178
        external
179
        view
180
        onlyOwner
181
        returns (uint256)
182
    {
183
        return darknodeRegistry[darknodeID].deregisteredAt;
181✔
184
    }
185

186
    /// @notice Returns the encryption public key of a given darknode.
187
    function darknodePublicKey(address darknodeID)
188
        external
189
        view
190
        onlyOwner
191
        returns (bytes memory)
192
    {
193
        return darknodeRegistry[darknodeID].publicKey;
×
194
    }
195
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc