2
2
pragma solidity ^ 0.8.0 ;
3
3
4
4
// Import the entropy SDK in order to interact with the entropy contracts
5
- import "entropy-sdk-solidity/IEntropy .sol " ;
5
+ import "entropy-sdk-solidity/IEntropyV2 .sol " ;
6
6
import "entropy-sdk-solidity/IEntropyConsumer.sol " ;
7
7
8
8
library CoinFlipErrors {
@@ -26,43 +26,38 @@ contract CoinFlip is IEntropyConsumer {
26
26
// Event emitted when the result of the coin flip is known.
27
27
event FlipResult (uint64 sequenceNumber , bool isHeads );
28
28
29
- // Contracts using Pyth Entropy should import the solidity SDK and then store both the Entropy contract
30
- // and a specific entropy provider to use for requests. Each provider commits to a sequence of random numbers.
31
- // Providers are then responsible for fulfilling a request on chain by revealing their random number.
32
- // Users should choose a reliable provider who they trust to uphold these commitments.
33
- // (For the moment, the only available provider is 0x6CC14824Ea2918f5De5C2f75A9Da968ad4BD6344)
34
- IEntropy private entropy;
35
- address private entropyProvider;
29
+ // Contracts using Pyth Entropy should import the solidity SDK and then store the Entropy contract
30
+ // address in the constructor.
31
+ IEntropyV2 private entropy;
36
32
37
- constructor (address _entropy , address _entropyProvider ) {
33
+ constructor (address _entropy ) {
38
34
entropy = IEntropy (_entropy);
39
- entropyProvider = _entropyProvider;
40
35
}
41
36
42
- // Request to flip a coin. The caller should generate and pass in a random number when calling this method.
43
- function requestFlip (bytes32 userRandomNumber ) external payable {
37
+ // Request to flip a coin.
38
+ function requestFlip () external payable {
44
39
// The entropy protocol requires the caller to pay a fee (in native gas tokens) per requested random number.
45
40
// This fee can either be paid by the contract itself or passed on to the end user.
46
41
// This implementation of the requestFlip method passes on the fee to the end user.
47
- uint256 fee = entropy.getFee (entropyProvider );
42
+ uint256 fee = entropy.getFeeV2 ( );
48
43
if (msg .value < fee) {
49
44
revert CoinFlipErrors.InsufficientFee ();
50
45
}
51
46
52
47
// Request the random number from the Entropy protocol. The call returns a sequence number that uniquely
53
48
// identifies the generated random number. Callers can use this sequence number to match which request
54
49
// is being revealed in the next stage of the protocol.
55
- uint64 sequenceNumber = entropy. requestWithCallback {value: fee}(
56
- entropyProvider,
57
- userRandomNumber
58
- );
50
+ //
51
+ // Note that callers can also request a specific gas limit for the callback by passing a gasLimit parameter
52
+ // to this function. See the IEntropyV2 interface for details.
53
+ uint64 sequenceNumber = entropy. requestV2 {value: fee}( );
59
54
60
55
emit FlipRequest (sequenceNumber);
61
56
}
62
57
63
58
// Get the fee to flip a coin. See the comment above about fees.
64
59
function getFlipFee () public view returns (uint256 fee ) {
65
- fee = entropy.getFee (entropyProvider );
60
+ fee = entropy.getFeeV2 ( );
66
61
}
67
62
68
63
// This method is required by the IEntropyConsumer interface.
0 commit comments