Description:
Smart contract deployed on Ethereum with Factory features.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"SubscriptionEscrow.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
contract SubscriptionMarketplace is ReentrancyGuard {
uint256 constant BASE_PRICE = 0.001 ether;
uint256 public totalSold = 0;
address public platformOwner;
address public escrowWallet;
struct Listing {
address seller;
address owner;
uint256 createdAt;
bool active;
}
struct Purchase {
address buyer;
address seller;
uint256 price;
uint256 timestamp;
}
mapping(bytes32 => Listing) public listings;
mapping(bytes32 => Purchase) public purchases;
event Listed(bytes32 indexed itemTX, address indexed seller, address indexed owner);
event Purchased(bytes32 indexed itemTX, address indexed buyer, address indexed seller, uint256 price);
event Delisted(bytes32 indexed itemTX, address indexed seller);
constructor(address _escrowWallet) {
platformOwner = msg.sender;
escrowWallet = _escrowWallet;
}
function getCurrentPrice() public view returns (uint256) {
uint256 price = BASE_PRICE;
for (uint256 i = 0; i < totalSold; i++) {
price = (price * 11) / 10;
}
return price;
}
function createListing(bytes32 itemTX, address itemOwner) external {
require(!listings[itemTX].active, "Already listed");
require(itemTX != bytes32(0), "Invalid item");
require(msg.sender == itemOwner, "Not owner");
listings[itemTX] = Listing({
seller: msg.sender,
owner: itemOwner,
createdAt: block.timestamp,
active: true
});
emit Listed(itemTX, msg.sender, itemOwner);
}
function purchase(bytes32 itemTX, address buyer) external payable nonReentrant {
Listing storage listing = listings[itemTX];
require(listing.active, "Not for sale");
require(listing.seller != address(0), "Invalid seller");
uint256 price = getCurrentPrice();
require(msg.value == price, "Wrong price");
address seller = listing.seller;
listing.active = false;
totalSold++;
purchases[itemTX] = Purchase({
buyer: buyer,
seller: seller,
price: price,
timestamp: block.timestamp
});
uint256 sellerAmount = (price * 98) / 100;
(bool success, ) = payable(seller).call{value: sellerAmount}("");
require(success, "Seller transfer failed");
emit Purchased(itemTX, buyer, seller, price);
}
function delist(bytes32 itemTX) external {
Listing storage listing = listings[itemTX];
require(listing.seller == msg.sender, "Not seller");
require(listing.active, "Not active");
listing.active = false;
emit Delisted(itemTX, msg.sender);
}
receive() external payable {}
}"
},
"@openzeppelin/contracts/security/ReentrancyGuard.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": []
}
}}
Submitted on: 2025-11-05 12:25:58
Comments
Log in to comment.
No comments yet.