Skip to content

Commit db8fba2

Browse files
committed
Add LogicV2 contract with counter initialization, increment, decrement, and retrieval functions
1 parent 893e362 commit db8fba2

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

src/LogicV2.sol

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
// Upgraded Logic Contract (Version 2)
5+
contract LogicV2 {
6+
uint256 public counter;
7+
8+
// Initializes the counter, compatible with V1
9+
function initialize(uint256 _initialValue) external {
10+
require(counter == 0, "Already initialized");
11+
counter = _initialValue;
12+
}
13+
14+
// Increments the counter
15+
function increment() external {
16+
counter += 1;
17+
}
18+
19+
// Decrements the counter (new feature)
20+
function decrement() external {
21+
require(counter > 0, "Counter underflow");
22+
counter -= 1;
23+
}
24+
25+
// Returns the counter value
26+
function getCounter() external view returns (uint256) {
27+
return counter;
28+
}
29+
}

0 commit comments

Comments
 (0)