remove txCount, nonce++ in execute submit, pendingTx was multisigTx

This commit is contained in:
Ricardo Guilherme Schmidt 2018-05-10 00:29:52 -03:00
parent 011a923467
commit ce79a64424

View File

@ -17,11 +17,10 @@ contract Identity is ERC725, ERC735, MessageSigned {
mapping (uint256 => bytes32[]) claimsByType; mapping (uint256 => bytes32[]) claimsByType;
mapping (bytes32 => uint256) indexes; mapping (bytes32 => uint256) indexes;
mapping (uint256 => Transaction) multisigTx; mapping (uint256 => Transaction) pendingTx;
mapping (uint256 => uint256) purposeThreshold; mapping (uint256 => uint256) purposeThreshold;
uint256 txCount; uint256 public nonce;
uint256 nonce;
address recoveryContract; address recoveryContract;
bytes32 recoveryManager; bytes32 recoveryManager;
@ -81,7 +80,7 @@ contract Identity is ERC725, ERC735, MessageSigned {
* @notice constructor builds identity with first key as `msg.sender` * @notice constructor builds identity with first key as `msg.sender`
*/ */
constructor(bytes32 _key) public { constructor(bytes32 _key) public {
_constructIdentity(keccak256(msg.sender)); _constructIdentity(_key);
} }
/** /**
@ -136,7 +135,7 @@ contract Identity is ERC725, ERC735, MessageSigned {
* @param _to destination of call * @param _to destination of call
* @param _value amount of ETH in call * @param _value amount of ETH in call
* @param _data data * @param _data data
* @param _txCount current txCount * @param _nonce current nonce
* @param _key key authorizing the call * @param _key key authorizing the call
* @param _signature signature of key * @param _signature signature of key
*/ */
@ -144,7 +143,7 @@ contract Identity is ERC725, ERC735, MessageSigned {
address _to, address _to,
uint256 _value, uint256 _value,
bytes _data, bytes _data,
uint256 _txCount, uint256 _nonce,
bytes32 _key, bytes32 _key,
bytes _signature bytes _signature
) )
@ -157,13 +156,13 @@ contract Identity is ERC725, ERC735, MessageSigned {
_to, _to,
_value, _value,
_data, _data,
_txCount _nonce
), ),
_signature _signature
) )
returns (uint256 txId) returns (uint256 txId)
{ {
require(_txCount == txCount); require(_nonce == nonce);
txId = _execute(_key, _to, _value, _data); txId = _execute(_key, _to, _value, _data);
} }
@ -489,7 +488,7 @@ contract Identity is ERC725, ERC735, MessageSigned {
uint256 requiredPurpose = _to == address(this) ? MANAGEMENT_KEY : ACTION_KEY; uint256 requiredPurpose = _to == address(this) ? MANAGEMENT_KEY : ACTION_KEY;
require(hasKeyPurpose(_key, requiredPurpose)); require(hasKeyPurpose(_key, requiredPurpose));
if (purposeThreshold[requiredPurpose] == 1) { if (purposeThreshold[requiredPurpose] == 1) {
txId = txCount++; txId = nonce++;
_commitCall(txId, _to, _value, _data); _commitCall(txId, _to, _value, _data);
} else { } else {
txId = _requestApproval(_key, _to, _value, _data); txId = _requestApproval(_key, _to, _value, _data);
@ -505,7 +504,6 @@ contract Identity is ERC725, ERC735, MessageSigned {
internal internal
returns(bool success) returns(bool success)
{ {
nonce++;
success = _to.call.value(_value)(_data); success = _to.call.value(_value)(_data);
if (success) { if (success) {
emit Executed(_txId, _to, _value, _data); emit Executed(_txId, _to, _value, _data);
@ -523,9 +521,9 @@ contract Identity is ERC725, ERC735, MessageSigned {
internal internal
returns (uint256 txId) returns (uint256 txId)
{ {
txId = txCount++; txId = nonce++;
multisigTx[txCount] = Transaction({ pendingTx[txId] = Transaction({
approverCount: _key == 0 ? 0 : 1, approverCount: _key == 0 ? 0 : 1,
to: _to, to: _to,
value: _value, value: _value,
@ -533,7 +531,7 @@ contract Identity is ERC725, ERC735, MessageSigned {
}); });
if (_key != 0) { if (_key != 0) {
multisigTx[txId].approvals[_key] = true; pendingTx[txId].approvals[_key] = true;
} }
emit ExecutionRequested(txId, _to, _value, _data); emit ExecutionRequested(txId, _to, _value, _data);
@ -552,28 +550,28 @@ contract Identity is ERC725, ERC735, MessageSigned {
returns(bool success) //(?) should return approved instead of success? returns(bool success) //(?) should return approved instead of success?
{ {
Transaction memory approvedTx = multisigTx[_txId]; Transaction memory approvedTx = pendingTx[_txId];
require(approvedTx.approverCount > 0); require(approvedTx.approverCount > 0);
uint256 requiredKeyPurpose = approvedTx.to == address(this) ? MANAGEMENT_KEY : ACTION_KEY; uint256 requiredKeyPurpose = approvedTx.to == address(this) ? MANAGEMENT_KEY : ACTION_KEY;
require(hasKeyPurpose(_key, requiredKeyPurpose)); require(hasKeyPurpose(_key, requiredKeyPurpose));
require(multisigTx[_txId].approvals[_key] != _approval); require(pendingTx[_txId].approvals[_key] != _approval);
if (_approval) { if (_approval) {
if (approvedTx.approverCount + 1 == purposeThreshold[requiredKeyPurpose]) { if (approvedTx.approverCount + 1 == purposeThreshold[requiredKeyPurpose]) {
delete multisigTx[_txId]; delete pendingTx[_txId];
emit Approved(_txId, _approval); emit Approved(_txId, _approval);
return _commitCall(_txId, approvedTx.to, approvedTx.value, approvedTx.data); return _commitCall(_txId, approvedTx.to, approvedTx.value, approvedTx.data);
} else { } else {
multisigTx[_txId].approvals[_key] = true; pendingTx[_txId].approvals[_key] = true;
multisigTx[_txId].approverCount++; pendingTx[_txId].approverCount++;
} }
} else { } else {
delete multisigTx[_txId].approvals[_key]; delete pendingTx[_txId].approvals[_key];
if (multisigTx[_txId].approverCount == 1) { if (pendingTx[_txId].approverCount == 1) {
delete multisigTx[_txId]; delete pendingTx[_txId];
emit Approved(_txId, _approval); emit Approved(_txId, _approval);
} else { } else {
multisigTx[_txId].approverCount--; pendingTx[_txId].approverCount--;
} }
} }
} }