Hello OpenZeppelin community,
I'm working on upgrading a smart contract and need advice on the best architectural approach for handling multiple minting functions.
Current situation:
- I have an existing function called
mintReservation()
- I want to add a new function called
mintWithPOI()
- Both functions share significant common logic
- They emit the same event:
emit Minted(uint256 tokenId, address minter)
I'm considering two approaches:
1. Separate Functions with Shared Internal Logic:
function mintReservation() external {
// Reservation-specific logic
_commonMintLogic();
}
function mintWithPOI() external {
// POI-specific logic
_commonMintLogic();
}
function _commonMintLogic() internal {
// Shared implementation
}
2. Single Generic Function with Conditional Logic:
function genericMint(MintType mintType) external {
if (mintType == MintType.RESERVATION) {
// Reservation-specific logic
} else if (mintType == MintType.POI) {
// POI-specific logic
}
// Common logic here
}
Additional context:
- Future upgrades might require adding more minting methods
- Gas efficiency and code maintainability are important considerations
Which approach would you recommend considering best practices for upgradeable contracts? Are there other patterns I should consider?