mirror of
https://github.com/status-im/snt-gas-relay.git
synced 2025-01-16 17:34:30 +00:00
simplify transaction struct + small fix
This commit is contained in:
parent
036c6285a6
commit
011a923467
@ -26,11 +26,10 @@ contract Identity is ERC725, ERC735, MessageSigned {
|
|||||||
bytes32 recoveryManager;
|
bytes32 recoveryManager;
|
||||||
|
|
||||||
struct Transaction {
|
struct Transaction {
|
||||||
bool valid;
|
uint256 approverCount;
|
||||||
address to;
|
address to;
|
||||||
uint256 value;
|
uint256 value;
|
||||||
bytes data;
|
bytes data;
|
||||||
uint256 approverCount;
|
|
||||||
mapping(bytes32 => bool) approvals;
|
mapping(bytes32 => bool) approvals;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +176,7 @@ contract Identity is ERC725, ERC735, MessageSigned {
|
|||||||
* @param _signature signature of key
|
* @param _signature signature of key
|
||||||
*/
|
*/
|
||||||
function approveMessageSigned(
|
function approveMessageSigned(
|
||||||
uint256 _id,
|
uint256 _txId,
|
||||||
bool _approval,
|
bool _approval,
|
||||||
bytes32 _key,
|
bytes32 _key,
|
||||||
bytes _signature
|
bytes _signature
|
||||||
@ -188,14 +187,14 @@ contract Identity is ERC725, ERC735, MessageSigned {
|
|||||||
keccak256(
|
keccak256(
|
||||||
address(this),
|
address(this),
|
||||||
bytes4(keccak256("approve(uint256,bool)")),
|
bytes4(keccak256("approve(uint256,bool)")),
|
||||||
_id,
|
_txId,
|
||||||
_approval
|
_approval
|
||||||
),
|
),
|
||||||
_signature
|
_signature
|
||||||
)
|
)
|
||||||
returns (bool success)
|
returns (bool success)
|
||||||
{
|
{
|
||||||
return _approveRequest(_key, _id, _approval);
|
return _approveRequest(_key, _txId, _approval);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -314,7 +313,7 @@ contract Identity is ERC725, ERC735, MessageSigned {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
require(hasKeyPurpose(keccak256(msg.sender), CLAIM_SIGNER_KEY));
|
require(hasKeyPurpose(keccak256(msg.sender), CLAIM_SIGNER_KEY));
|
||||||
_requestApproval(address(this), 0, msg.data);
|
_requestApproval(0, address(this), 0, msg.data);
|
||||||
emit ClaimRequested(
|
emit ClaimRequested(
|
||||||
claimHash,
|
claimHash,
|
||||||
_claimType,
|
_claimType,
|
||||||
@ -493,8 +492,7 @@ contract Identity is ERC725, ERC735, MessageSigned {
|
|||||||
txId = txCount++;
|
txId = txCount++;
|
||||||
_commitCall(txId, _to, _value, _data);
|
_commitCall(txId, _to, _value, _data);
|
||||||
} else {
|
} else {
|
||||||
txId = _requestApproval(_to, _value, _data);
|
txId = _requestApproval(_key, _to, _value, _data);
|
||||||
_approveRequest(_key, txId, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -517,6 +515,7 @@ contract Identity is ERC725, ERC735, MessageSigned {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _requestApproval(
|
function _requestApproval(
|
||||||
|
bytes32 _key,
|
||||||
address _to,
|
address _to,
|
||||||
uint256 _value,
|
uint256 _value,
|
||||||
bytes _data
|
bytes _data
|
||||||
@ -525,13 +524,18 @@ contract Identity is ERC725, ERC735, MessageSigned {
|
|||||||
returns (uint256 txId)
|
returns (uint256 txId)
|
||||||
{
|
{
|
||||||
txId = txCount++;
|
txId = txCount++;
|
||||||
|
|
||||||
multisigTx[txCount] = Transaction({
|
multisigTx[txCount] = Transaction({
|
||||||
valid: true,
|
approverCount: _key == 0 ? 0 : 1,
|
||||||
to: _to,
|
to: _to,
|
||||||
value: _value,
|
value: _value,
|
||||||
data: _data,
|
data: _data
|
||||||
approverCount: 0
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (_key != 0) {
|
||||||
|
multisigTx[txId].approvals[_key] = true;
|
||||||
|
}
|
||||||
|
|
||||||
emit ExecutionRequested(txId, _to, _value, _data);
|
emit ExecutionRequested(txId, _to, _value, _data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,33 +545,37 @@ contract Identity is ERC725, ERC735, MessageSigned {
|
|||||||
|
|
||||||
function _approveRequest(
|
function _approveRequest(
|
||||||
bytes32 _key,
|
bytes32 _key,
|
||||||
uint256 _id,
|
uint256 _txId,
|
||||||
bool _approval
|
bool _approval
|
||||||
)
|
)
|
||||||
private
|
private
|
||||||
returns(bool success) //(?) should return approved instead of success?
|
returns(bool success) //(?) should return approved instead of success?
|
||||||
{
|
{
|
||||||
|
|
||||||
Transaction memory approvedTx = multisigTx[_id];
|
Transaction memory approvedTx = multisigTx[_txId];
|
||||||
require(approvedTx.valid);
|
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[_id].approvals[_key] != _approval);
|
require(multisigTx[_txId].approvals[_key] != _approval);
|
||||||
|
|
||||||
emit Approved(_id, _approval);
|
|
||||||
|
|
||||||
if (_approval) {
|
if (_approval) {
|
||||||
if (approvedTx.approverCount + 1 == purposeThreshold[requiredKeyPurpose]) {
|
if (approvedTx.approverCount + 1 == purposeThreshold[requiredKeyPurpose]) {
|
||||||
delete multisigTx[_id];
|
delete multisigTx[_txId];
|
||||||
return _commitCall(_id, approvedTx.to, approvedTx.value, approvedTx.data);
|
emit Approved(_txId, _approval);
|
||||||
|
return _commitCall(_txId, approvedTx.to, approvedTx.value, approvedTx.data);
|
||||||
} else {
|
} else {
|
||||||
multisigTx[_id].approverCount++;
|
multisigTx[_txId].approvals[_key] = true;
|
||||||
|
multisigTx[_txId].approverCount++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
multisigTx[_id].approverCount--;
|
delete multisigTx[_txId].approvals[_key];
|
||||||
|
if (multisigTx[_txId].approverCount == 1) {
|
||||||
|
delete multisigTx[_txId];
|
||||||
|
emit Approved(_txId, _approval);
|
||||||
|
} else {
|
||||||
|
multisigTx[_txId].approverCount--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
multisigTx[_id].approvals[_key] = _approval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _addKey(
|
function _addKey(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user