feat(soroban): add increment_with_pause example (Refs #1901)#1911
Open
Amit5601 wants to merge 3 commits into
Open
feat(soroban): add increment_with_pause example (Refs #1901)#1911Amit5601 wants to merge 3 commits into
Amit5601 wants to merge 3 commits into
Conversation
…ang#1901) Signed-off-by: Amit Singhmar <abhay.singhmar2@gmail.com>
There was a problem hiding this comment.
Pull request overview
Adds a new Soroban Solidity example intended to mirror the upstream increment_with_pause pattern (an incrementing counter gated by a separate “pause” contract).
Changes:
- Introduces a new
increment_with_pause.solexample with anIPauseinterface and an increment function that reverts when paused. - Stores counter state in Soroban
instancestorage and increments it when unpaused.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+4
to
+20
| interface IPause { | ||
| function paused() external view returns (bool); | ||
| } | ||
|
|
||
| contract IncrementContract { | ||
| IPause private instance pauseContract; | ||
| uint32 private instance count; | ||
|
|
||
| error PausedError(); | ||
|
|
||
| constructor(IPause _pause) { | ||
| pauseContract = _pause; | ||
| } | ||
|
|
||
| function increment() public returns (uint32) { | ||
| // Cross-contract call to check the paused state | ||
| if (pauseContract.paused()) { |
Comment on lines
+1
to
+2
| // SPDX-License-Identifier: Apache-2.0 | ||
| pragma solidity ^0.8.0; |
| function paused() external view returns (bool); | ||
| } | ||
|
|
||
| contract IncrementContract { |
Comment on lines
+4
to
+16
| interface IPause { | ||
| function paused() external view returns (bool); | ||
| } | ||
|
|
||
| contract IncrementContract { | ||
| IPause private instance pauseContract; | ||
| uint32 private instance count; | ||
|
|
||
| error PausedError(); | ||
|
|
||
| constructor(IPause _pause) { | ||
| pauseContract = _pause; | ||
| } |
Signed-off-by: Amit Singhmar <abhay.singhmar2@gmail.com>
Comment on lines
+3
to
+18
| interface IPause { | ||
| function paused() external view returns (bool); | ||
| } | ||
|
|
||
| contract increment_with_pause { | ||
| IPause private instance pauseContract; | ||
| uint32 private instance count; | ||
|
|
||
| error PausedError(); | ||
|
|
||
| constructor(IPause _pause) { | ||
| pauseContract = _pause; | ||
| } | ||
|
|
||
| function increment() public returns (uint32) { | ||
| if (pauseContract.paused()) { |
…support matrix Signed-off-by: Amit Singhmar <abhay.singhmar2@gmail.com>
Comment on lines
+16
to
+22
|
|
||
| // Decode the return value if the call succeeds | ||
| if (ok) { | ||
| bool isPaused = abi.decode(ret, (bool)); | ||
| if (isPaused) { | ||
| revert PausedError(); | ||
| } |
Comment on lines
+30
to
+37
| contract pause { | ||
| bool private instance _isPaused; | ||
|
|
||
| function paused() public view returns (bool) { | ||
| return _isPaused; | ||
| } | ||
|
|
||
| function set(bool p) public { |
| function increment() public returns (uint32) { | ||
| bytes memory payload = abi.encode("paused"); | ||
| (bool ok, bytes memory ret) = pauseAddr.call(payload); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the Solidity equivalent of the increment_with_pause contract to the Soroban examples directory.