// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; contract Locker { enum bonusStatus { Pending, Withdrawn } struct Bonus { uint amount; uint lockDeadline; bonusStatus status; } address owner; uint lockTime; mapping(address => Bonus[]) userBonuces; modifier onlyOwner() { require(msg.sender == owner); _; } constructor () { owner = msg.sender; lockTime = 100; // in seconds } function transferOwnership(address newOwner) external onlyOwner { owner = newOwner; } function changeLockTime(uint newLockTime) external onlyOwner { lockTime = newLockTime; } function addLockedBonus(address receiver) external payable onlyOwner { userBonuces[receiver].push(Bonus(msg.value, block.timestamp + lockTime, bonusStatus.Pending)); } function withdrawBonus(uint index) external { require(index < userBonuces[msg.sender].length, "bonus index out of bounds"); require(userBonuces[msg.sender][index].status == bonusStatus.Pending, "already withdrawn"); require((block.timestamp - lockTime) > userBonuces[msg.sender][index].lockDeadline, "deadline not reached"); userBonuces[msg.sender][index].status = bonusStatus.Withdrawn; payable(msg.sender).transfer(userBonuces[msg.sender][index].amount); } function getMyBonuces() external view returns (Bonus[] memory) { Bonus[] memory result = new Bonus[](userBonuces[msg.sender].length); for (uint i; i < userBonuces[msg.sender].length; i++) { result[i] = userBonuces[msg.sender][i]; } return result; } }
[{"type": "constructor", "inputs": [], "stateMutability": "nonpayable"}, {"name": "addLockedBonus", "type": "function", "inputs": [{"name": "receiver", "type": "address", "internalType": "address"}], "outputs": [], "stateMutability": "payable"}, {"name": "changeLockTime", "type": "function", "inputs": [{"name": "newLockTime", "type": "uint256", "internalType": "uint256"}], "outputs": [], "stateMutability": "nonpayable"}, {"name": "getMyBonuces", "type": "function", "inputs": [], "outputs": [{"name": "", "type": "tuple[]", "components": [{"name": "amount", "type": "uint256", "internalType": "uint256"}, {"name": "lockDeadline", "type": "uint256", "internalType": "uint256"}, {"name": "status", "type": "uint8", "internalType": "enum Locker.bonusStatus"}], "internalType": "struct Locker.Bonus[]"}], "stateMutability": "view"}, {"name": "transferOwnership", "type": "function", "inputs": [{"name": "newOwner", "type": "address", "internalType": "address"}], "outputs": [], "stateMutability": "nonpayable"}, {"name": "withdrawBonus", "type": "function", "inputs": [{"name": "index", "type": "uint256", "internalType": "uint256"}], "outputs": [], "stateMutability": "nonpayable"}]
0x608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506064600181905550610df6806100686000396000f3fe60806040526004361061004a5760003560e01c806338baa2011461004f57806372d329681461006b57806396cf522714610094578063ddec9011146100bd578063f2fde38b146100e8575b600080fd5b61006960048036038101906100649190610905565b610111565b005b34801561007757600080fd5b50610092600480360381019061008d9190610968565b610255565b005b3480156100a057600080fd5b506100bb60048036038101906100b69190610968565b610597565b005b3480156100c957600080fd5b506100d26105f9565b6040516100df9190610b0c565b60405180910390f35b3480156100f457600080fd5b5061010f600480360381019061010a9190610905565b6107d4565b005b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461016957600080fd5b600260008273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206040518060600160405280348152602001600154426101c79190610b5d565b8152602001600060018111156101e0576101df6109d0565b5b8152509080600181540180825580915050600190039060005260206000209060030201600090919091909150600082015181600001556020820151816001015560408201518160020160006101000a81548160ff0219169083600181111561024b5761024a6109d0565b5b0217905550505050565b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208054905081106102d9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102d090610bee565b60405180910390fd5b600060018111156102ed576102ec6109d0565b5b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020828154811061033e5761033d610c0e565b5b906000526020600020906003020160020160009054906101000a900460ff16600181111561036f5761036e6109d0565b5b146103af576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103a690610c89565b60405180910390fd5b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208181548110610400576103ff610c0e565b5b906000526020600020906003020160010154600154426104209190610ca9565b11610460576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161045790610d29565b60405180910390fd5b6001600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002082815481106104b3576104b2610c0e565b5b906000526020600020906003020160020160006101000a81548160ff021916908360018111156104e6576104e56109d0565b5b02179055503373ffffffffffffffffffffffffffffffffffffffff166108fc600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020838154811061055657610555610c0e565b5b9060005260206000209060030201600001549081150290604051600060405180830381858888f19350505050158015610593573d6000803e3d6000fd5b5050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146105ef57600080fd5b8060018190555050565b60606000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208054905067ffffffffffffffff81111561065957610658610d49565b5b60405190808252806020026020018201604052801561069257816020015b61067f61086f565b8152602001906001900390816106775790505b50905060005b600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020805490508110156107cc57600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020818154811061073357610732610c0e565b5b906000526020600020906003020160405180606001604052908160008201548152602001600182015481526020016002820160009054906101000a900460ff166001811115610785576107846109d0565b5b6001811115610797576107966109d0565b5b815250508282815181106107ae576107ad610c0e565b5b602002602001018190525080806107c490610d78565b915050610698565b508091505090565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461082c57600080fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b604051806060016040528060008152602001600081526020016000600181111561089c5761089b6109d0565b5b81525090565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006108d2826108a7565b9050919050565b6108e2816108c7565b81146108ed57600080fd5b50565b6000813590506108ff816108d9565b92915050565b60006020828403121561091b5761091a6108a2565b5b6000610929848285016108f0565b91505092915050565b6000819050919050565b61094581610932565b811461095057600080fd5b50565b6000813590506109628161093c565b92915050565b60006020828403121561097e5761097d6108a2565b5b600061098c84828501610953565b91505092915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6109ca81610932565b82525050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60028110610a1057610a0f6109d0565b5b50565b6000819050610a21826109ff565b919050565b6000610a3182610a13565b9050919050565b610a4181610a26565b82525050565b606082016000820151610a5d60008501826109c1565b506020820151610a7060208501826109c1565b506040820151610a836040850182610a38565b50505050565b6000610a958383610a47565b60608301905092915050565b6000602082019050919050565b6000610ab982610995565b610ac381856109a0565b9350610ace836109b1565b8060005b83811015610aff578151610ae68882610a89565b9750610af183610aa1565b925050600181019050610ad2565b5085935050505092915050565b60006020820190508181036000830152610b268184610aae565b905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610b6882610932565b9150610b7383610932565b9250828201905080821115610b8b57610b8a610b2e565b5b92915050565b600082825260208201905092915050565b7f626f6e757320696e646578206f7574206f6620626f756e647300000000000000600082015250565b6000610bd8601983610b91565b9150610be382610ba2565b602082019050919050565b60006020820190508181036000830152610c0781610bcb565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f616c72656164792077697468647261776e000000000000000000000000000000600082015250565b6000610c73601183610b91565b9150610c7e82610c3d565b602082019050919050565b60006020820190508181036000830152610ca281610c66565b9050919050565b6000610cb482610932565b9150610cbf83610932565b9250828203905081811115610cd757610cd6610b2e565b5b92915050565b7f646561646c696e65206e6f742072656163686564000000000000000000000000600082015250565b6000610d13601483610b91565b9150610d1e82610cdd565b602082019050919050565b60006020820190508181036000830152610d4281610d06565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6000610d8382610932565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610db557610db4610b2e565b5b60018201905091905056fea2646970667358221220586fc74e74a5deeb24c7baccd0209c355cefc0a7550cf1fe4c18535133f63f3c64736f6c63430008130033