71 lines
2.2 KiB
Solidity
71 lines
2.2 KiB
Solidity
// contracts/Implementation.sol
|
|
// SPDX-License-Identifier: Apache 2
|
|
|
|
pragma solidity ^0.8.0;
|
|
pragma experimental ABIEncoderV2;
|
|
|
|
import "./Governance.sol";
|
|
|
|
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol";
|
|
|
|
contract Implementation is Governance {
|
|
event LogMessagePublished(address indexed sender, uint64 sequence, uint32 nonce, bytes payload, bool persistMessage, uint8 consistencyLevel);
|
|
|
|
// Publish a message to be attested by the Wormhole network
|
|
function publishMessage(
|
|
uint32 nonce,
|
|
bytes memory payload,
|
|
bool persistMessage,
|
|
uint8 consistencyLevel
|
|
) public payable {
|
|
// check fee
|
|
if( persistMessage ) {
|
|
require(msg.value == persistedMessageFee(), "invalid fee");
|
|
} else {
|
|
require(msg.value == messageFee(), "invalid fee");
|
|
}
|
|
|
|
// emit log
|
|
emit LogMessagePublished(msg.sender, useSequence(msg.sender), nonce, payload, persistMessage, consistencyLevel);
|
|
}
|
|
|
|
function useSequence(address emitter) internal returns (uint64 sequence) {
|
|
sequence = nextSequence(emitter);
|
|
setNextSequence(emitter, sequence + 1);
|
|
}
|
|
|
|
function initialize(address[] memory initialGuardians, uint16 chainId, uint16 governanceChainId, bytes32 governanceContract) initializer public {
|
|
require(initialGuardians.length > 0, "no guardians specified");
|
|
|
|
Structs.GuardianSet memory initialGuardianSet = Structs.GuardianSet({
|
|
keys : initialGuardians,
|
|
expirationTime : 0
|
|
});
|
|
|
|
storeGuardianSet(initialGuardianSet, 0);
|
|
// initial guardian set index is 0, which is the default value of the storage slot anyways
|
|
|
|
setChainId(chainId);
|
|
|
|
setGovernanceChainId(governanceChainId);
|
|
setGovernanceContract(governanceContract);
|
|
}
|
|
|
|
modifier initializer() {
|
|
address implementation = ERC1967Upgrade._getImplementation();
|
|
|
|
require(
|
|
!isInitialized(implementation),
|
|
"already initialized"
|
|
);
|
|
|
|
setInitialized(implementation);
|
|
|
|
_;
|
|
}
|
|
|
|
fallback() external payable {revert("unsupported");}
|
|
|
|
receive() external payable {revert("the Wormhole contract does not accept assets");}
|
|
}
|