Skip to content

Commit d640ea3

Browse files
authored
Merge pull request #98 from Merit-Systems/shafu/account-exists
Add existence flag for account in Escrow contract
2 parents 54cda96 + 7376bc0 commit d640ea3

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/Escrow.sol

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ contract Escrow is Owned, IEscrow {
3232
struct Account {
3333
mapping(address => uint) balance; // token → balance
3434
bool hasDistributions; // whether any distributions have occurred
35-
address admin; // admin
35+
address admin;
3636
mapping(address => bool) distributors; // distributor → authorized?
37+
bool exists;
3738
}
3839

3940
struct Distribution {
@@ -144,9 +145,11 @@ contract Escrow is Owned, IEscrow {
144145
bytes32 r,
145146
bytes32 s
146147
) external {
147-
require(accounts[repoId][accountId].admin == address(0), Errors.REPO_ALREADY_INITIALIZED);
148-
require(admin != address(0), Errors.INVALID_ADDRESS);
149-
require(block.timestamp <= deadline, Errors.SIGNATURE_EXPIRED);
148+
Account storage account = accounts[repoId][accountId];
149+
150+
require(!account.exists, Errors.REPO_ALREADY_INITIALIZED);
151+
require(admin != address(0), Errors.INVALID_ADDRESS);
152+
require(block.timestamp <= deadline, Errors.SIGNATURE_EXPIRED);
150153

151154
bytes32 digest = keccak256(
152155
abi.encodePacked(
@@ -165,9 +168,9 @@ contract Escrow is Owned, IEscrow {
165168
require(ECDSA.recover(digest, v, r, s) == owner, Errors.INVALID_SIGNATURE);
166169

167170
ownerNonce++;
168-
address oldAdmin = accounts[repoId][accountId].admin;
169-
accounts[repoId][accountId].admin = admin;
170-
emit AdminSet(repoId, accountId, oldAdmin, admin);
171+
account.exists = true;
172+
account.admin = admin;
173+
emit AdminSet(repoId, accountId, address(0), admin);
171174
}
172175

173176
/* -------------------------------------------------------------------------- */

0 commit comments

Comments
 (0)