Skip to content

Commit

Permalink
Merge pull request #6 from crosschain-alliance/feat/hashi-integration…
Browse files Browse the repository at this point in the history
…-xdai-bridge-resend-hashi-message

feat: add possibility to resend an hashi message [xDAI]
  • Loading branch information
allemanfredi authored Jun 20, 2024
2 parents 3724780 + cb741dd commit e796b47
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
31 changes: 20 additions & 11 deletions contracts/upgradeable_contracts/BasicBridge.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pragma solidity 0.4.24;

import "./Upgradeable.sol";
import "./InitializableBridge.sol";
import "openzeppelin-solidity/contracts/AddressUtils.sol";
Expand Down Expand Up @@ -80,20 +79,30 @@ contract BasicBridge is
boolStorage[keccak256(abi.encodePacked("messagesApprovedByHashi", msgId))] = status;
}

function _maybeRelayDataWithHashi(bytes data) internal {
function resendDataWithHashi(bytes data) external {
require(boolStorage[keccak256(data)]);
_dispatchMessageWithHashi(data);
}

function _maybeSendDataWithHashi(bytes data) internal {
if (HASHI_IS_ENABLED) {
IHashiManager manager = hashiManager();
IYaho(manager.yaho()).dispatchMessage(
manager.targetChainId(),
manager.threshold(),
manager.targetAddress(),
data,
manager.reporters(),
manager.adapters()
);
boolStorage[keccak256(data)] = true;
_dispatchMessageWithHashi(data);
}
}

function _dispatchMessageWithHashi(bytes data) internal {
IHashiManager manager = hashiManager();
IYaho(manager.yaho()).dispatchMessage(
manager.targetChainId(),
manager.threshold(),
manager.targetAddress(),
data,
manager.reporters(),
manager.adapters()
);
}

function _validateHashiMessage(uint256 chainId, uint256 threshold, address sender, address[] adapters) internal {
IHashiManager manager = hashiManager();
require(
Expand Down
3 changes: 2 additions & 1 deletion contracts/upgradeable_contracts/BasicForeignBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ contract BasicForeignBridge is EternalStorage, Validatable, BasicBridge, BasicTo
) external returns (bytes) {
_validateHashiMessage(chainId, threshold, sender, adapters);
bytes32 msgId = keccak256(data);
require(!isApprovedByHashi(msgId));
_setHashiApprovalForMessage(msgId, true);
}

Expand All @@ -61,7 +62,7 @@ contract BasicForeignBridge is EternalStorage, Validatable, BasicBridge, BasicTo
uint256 currentNonce = nonce();
setNonce(currentNonce + 1);
emit UserRequestForAffirmation(_receiver, _amount, bytes32(currentNonce));
_maybeRelayDataWithHashi(abi.encodePacked(_receiver, _amount, bytes32(currentNonce)));
_maybeSendDataWithHashi(abi.encodePacked(_receiver, _amount, bytes32(currentNonce)));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion contracts/upgradeable_contracts/BasicHomeBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ contract BasicHomeBridge is EternalStorage, Validatable, BasicBridge, BasicToken
) external returns (bytes) {
_validateHashiMessage(chainId, threshold, sender, adapters);
bytes32 msgId = keccak256(data);
require(!isApprovedByHashi(msgId));
_setHashiApprovalForMessage(msgId, true);
}

Expand Down Expand Up @@ -121,7 +122,7 @@ contract BasicHomeBridge is EternalStorage, Validatable, BasicBridge, BasicToken
uint256 currentNonce = nonce();
setNonce(currentNonce + 1);
emit UserRequestForSignature(_receiver, _amount, bytes32(currentNonce));
_maybeRelayDataWithHashi(abi.encodePacked(_receiver, _amount, bytes32(currentNonce)));
_maybeSendDataWithHashi(abi.encodePacked(_receiver, _amount, bytes32(currentNonce)));
}

function setMessagesSigned(bytes32 _hash, bool _status) internal {
Expand Down

0 comments on commit e796b47

Please sign in to comment.