|
|
|
@ -9,20 +9,32 @@ contract Home is MerkleTreeManager, QueueManager, Common { |
|
|
|
|
using QueueLib for QueueLib.Queue; |
|
|
|
|
using MerkleLib for MerkleLib.Tree; |
|
|
|
|
|
|
|
|
|
mapping(uint32 => uint32) public sequences; |
|
|
|
|
|
|
|
|
|
uint256 constant BOND_SIZE = 50 ether; |
|
|
|
|
|
|
|
|
|
event Message( |
|
|
|
|
uint32 indexed destination, |
|
|
|
|
uint32 indexed sequence, |
|
|
|
|
// the message is after this root. Some future update will contain it. |
|
|
|
|
bytes32 indexed current, |
|
|
|
|
bytes message |
|
|
|
|
); |
|
|
|
|
event ImproperUpdate(); |
|
|
|
|
|
|
|
|
|
constructor(uint32 _originSLIP44, address _updater) |
|
|
|
|
constructor( |
|
|
|
|
uint32 _originSLIP44, |
|
|
|
|
address _updater, |
|
|
|
|
bytes32 _current |
|
|
|
|
) |
|
|
|
|
payable |
|
|
|
|
MerkleTreeManager() |
|
|
|
|
QueueManager() |
|
|
|
|
Common(_originSLIP44, _updater) |
|
|
|
|
Common(_originSLIP44, _updater, _current) |
|
|
|
|
{ |
|
|
|
|
require(msg.value >= BOND_SIZE, "insufficient bond"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO |
|
|
|
|
function fail() internal override { |
|
|
|
|
_setFailed(); |
|
|
|
|
msg.sender.transfer(address(this).balance / 2); |
|
|
|
@ -33,11 +45,15 @@ contract Home is MerkleTreeManager, QueueManager, Common { |
|
|
|
|
bytes32 recipient, |
|
|
|
|
bytes memory body |
|
|
|
|
) external notFailed { |
|
|
|
|
uint32 sequence = sequences[destination] + 1; |
|
|
|
|
sequences[destination] = sequence; |
|
|
|
|
|
|
|
|
|
bytes32 _digest = |
|
|
|
|
keccak256( |
|
|
|
|
abi.encodePacked( |
|
|
|
|
originSLIP44, |
|
|
|
|
bytes32(uint256(uint160(msg.sender))), |
|
|
|
|
sequence, |
|
|
|
|
destination, |
|
|
|
|
recipient, |
|
|
|
|
body |
|
|
|
@ -46,6 +62,7 @@ contract Home is MerkleTreeManager, QueueManager, Common { |
|
|
|
|
|
|
|
|
|
tree.insert(_digest); |
|
|
|
|
queue.enqueue(root()); |
|
|
|
|
emit Message(destination, sequence, current, body); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function update( |
|
|
|
@ -67,6 +84,7 @@ contract Home is MerkleTreeManager, QueueManager, Common { |
|
|
|
|
bytes memory _signature |
|
|
|
|
) public notFailed returns (bool) { |
|
|
|
|
require(Common.checkSig(_newRoot, _oldRoot, _signature), "bad sig"); |
|
|
|
|
require(_oldRoot == current, "Not a current update"); |
|
|
|
|
if (!queue.contains(_newRoot)) { |
|
|
|
|
fail(); |
|
|
|
|
emit ImproperUpdate(); |
|
|
|
|