IEntropyConsumer.sol 1.4 KB

123456789101112131415161718192021222324252627282930313233
  1. // SPDX-License-Identifier: Apache 2
  2. pragma solidity ^0.8.0;
  3. abstract contract IEntropyConsumer {
  4. // This method is called by Entropy to provide the random number to the consumer.
  5. // It asserts that the msg.sender is the Entropy contract. It is not meant to be
  6. // override by the consumer.
  7. function _entropyCallback(
  8. uint64 sequence,
  9. address provider,
  10. bytes32 randomNumber
  11. ) external {
  12. address entropy = getEntropy();
  13. require(entropy != address(0), "Entropy address not set");
  14. require(msg.sender == entropy, "Only Entropy can call this function");
  15. entropyCallback(sequence, provider, randomNumber);
  16. }
  17. // getEntropy returns Entropy contract address. The method is being used to check that the
  18. // callback is indeed from Entropy contract. The consumer is expected to implement this method.
  19. // Entropy address can be found here - https://docs.pyth.network/entropy/contract-addresses
  20. function getEntropy() internal view virtual returns (address);
  21. // This method is expected to be implemented by the consumer to handle the random number.
  22. // It will be called by _entropyCallback after _entropyCallback ensures that the call is
  23. // indeed from Entropy contract.
  24. function entropyCallback(
  25. uint64 sequence,
  26. address provider,
  27. bytes32 randomNumber
  28. ) internal virtual;
  29. }