Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
637c4eb
add is-paused read-only function to contract
Mosas2000 Apr 29, 2026
68e24c9
add is-paused function to legacy contract
Mosas2000 Apr 29, 2026
cb2d568
add tests for is-paused read-only function
Mosas2000 Apr 29, 2026
1728bb8
add is-paused tests for legacy contract
Mosas2000 Apr 29, 2026
e2f3db0
rename is-paused to get-is-paused to avoid naming conflict
Mosas2000 Apr 29, 2026
30797a9
add comprehensive tests for get-is-paused integration
Mosas2000 Apr 29, 2026
c61da20
document get-is-paused function in README
Mosas2000 Apr 29, 2026
6e48511
add migration guide for get-is-paused function
Mosas2000 Apr 29, 2026
40bca38
add example script for querying pause state
Mosas2000 Apr 29, 2026
a99e803
add pause state monitoring example
Mosas2000 Apr 29, 2026
fa5edd7
add examples directory README with integration patterns
Mosas2000 Apr 29, 2026
bf2cace
add CHANGELOG entry for get-is-paused function
Mosas2000 Apr 29, 2026
f061706
add inline documentation for get-is-paused function
Mosas2000 Apr 29, 2026
19b922a
enhance JSDoc documentation for fetchPauseState
Mosas2000 Apr 29, 2026
d734460
add examples to parseClarityValue JSDoc
Mosas2000 Apr 29, 2026
7b2ee51
add TypeScript type definitions for admin contract helpers
Mosas2000 Apr 29, 2026
de3953a
extract function names to constants for maintainability
Mosas2000 Apr 29, 2026
6b4d792
add custom error classes for pause state operations
Mosas2000 Apr 29, 2026
6c203fb
add comprehensive tests for pause state error classes
Mosas2000 Apr 29, 2026
f6a7fa3
add performance optimization guide for pause state queries
Mosas2000 Apr 29, 2026
af3d29a
add quick reference card for pause state function
Mosas2000 Apr 29, 2026
90a75f9
add explanatory comment for pause state tests
Mosas2000 Apr 29, 2026
62b5495
update docs index with pause state documentation
Mosas2000 Apr 29, 2026
d9a043d
verify all contract tests pass with new function
Mosas2000 Apr 29, 2026
ea969ca
add implementation summary document
Mosas2000 Apr 29, 2026
e531f98
add npm script for running pause state tests
Mosas2000 Apr 29, 2026
6b6ee81
mark pause state docs as documentation in git
Mosas2000 Apr 29, 2026
ae668ad
finalize pause state read-only function implementation
Mosas2000 Apr 29, 2026
5eecdad
ready for code review and testing
Mosas2000 Apr 29, 2026
d7f27eb
all acceptance criteria met and verified
Mosas2000 Apr 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
tests/** linguist-vendored
vitest.config.js linguist-vendored
* text=lf
docs/PAUSE_STATE_*.md linguist-documentation
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Added

- Direct read-only function for contract pause state (Issue #345):
- New `get-is-paused` read-only function provides direct access to pause state
- Returns simple boolean response: `(ok true)` for paused, `(ok false)` for running
- Eliminates need to infer pause state from other contract responses
- Frontend helpers updated to use new function for improved clarity
- Comprehensive contract tests for both v2 and legacy contracts
- Frontend integration tests verify correct API usage
- Example scripts for querying and monitoring pause state
- Migration guide for integrators
- Documentation updates across PAUSE_API_REFERENCE, PAUSE_OPERATIONS, and ADMIN_OPERATIONS

- Cancel-pause-change functionality for contract pause operations:
- New `cancel-pause-change` function allows admins to cancel pending pause proposals
- Provides operational symmetry with existing `cancel-fee-change` function
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ constants instead of hard-coding path strings.
| `get-pending-owner` | Pending ownership transfer target |
| `get-pending-fee-change` | Pending fee proposal and execution height |
| `get-pending-pause-change` | Pending pause proposal and execution height |
| `get-is-paused` | Current contract pause state (true = paused, false = running) |
| `get-multisig` | Authorized multisig contract address |
| `get-contract-version` | Contract version and name |

Expand Down Expand Up @@ -184,7 +185,7 @@ constants instead of hard-coding path strings.
| `blocked-users` | Privacy blocking |
| `total-tips-sent` | Global counter (also tip ID) |
| `total-volume` / `platform-fees` | Running totals |
| `is-paused` | Emergency pause |
| `is-paused` | Emergency pause state (accessible via `get-is-paused` read-only function) |
| `current-fee-basis-points` | Fee rate (default 50 = 0.5%) |

### Testing
Expand Down
7 changes: 7 additions & 0 deletions contracts/tipstream-v2.clar
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,13 @@
}
)

;; Returns the current pause state of the contract.
;; When paused, tip operations are disabled.
;; Returns (ok true) if paused, (ok false) if running.
(define-read-only (get-is-paused)
(ok (var-get is-paused))
)

(define-read-only (get-multisig)
(ok (var-get authorized-multisig))
)
Expand Down
7 changes: 7 additions & 0 deletions contracts/tipstream.clar
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,13 @@
}
)

;; Returns the current pause state of the contract.
;; When paused, tip operations are disabled.
;; Returns (ok true) if paused, (ok false) if running.
(define-read-only (get-is-paused)
(ok (var-get is-paused))
)

(define-read-only (get-multisig)
(ok (var-get authorized-multisig))
)
Expand Down
4 changes: 2 additions & 2 deletions docs/ADMIN_OPERATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Quick reference guide for common administrative tasks on TipStream.
| Emergency Pause | `set-paused` (direct) | None | Owner | Seconds |
| Change Owner | `propose-new-owner` → `accept-ownership` | 2-step | Owner → New Owner | 10 min |
| View Fee Rate | `get-current-fee-basis-points` | None (read) | Anyone | Instant |
| View Contract Status | `get-contract-owner` / `is-paused` | None (read) | Anyone | Instant |
| View Contract Status | `get-contract-owner` / `get-is-paused` | None (read) | Anyone | Instant |

## Pre-Administration Checklist

Expand Down Expand Up @@ -315,7 +315,7 @@ Result should be: SP1234...ABC
fetch('https://api.hiro.so/.../get-contract-owner')
// Should return owner address

fetch('https://api.hiro.so/.../is-paused')
fetch('https://api.hiro.so/.../get-is-paused')
// Should return boolean (false = operational)

// 2. Recent Transactions
Expand Down
168 changes: 168 additions & 0 deletions docs/MIGRATION_GUIDE_PAUSE_STATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Migration Guide: Pause State Read-Only Function

## Overview

This guide covers the addition of the `get-is-paused` read-only function to the TipStream contract, which provides direct access to the current pause state.

## What Changed

### Contract Changes

**Added Function:**
```clarity
(define-read-only (get-is-paused)
(ok (var-get is-paused))
)
```

This function provides a direct way to query the current pause state of the contract without having to infer it from other responses.

### Frontend Changes

**Updated Files:**
- `frontend/src/lib/admin-contract.js` - Now calls `get-is-paused` instead of attempting to call non-existent `is-paused`
- `frontend/src/lib/pauseOperations.js` - Updated constant from `IS_PAUSED` to `GET_IS_PAUSED`

## Migration Steps

### For Contract Integrators

If you're integrating with the TipStream contract and need to check the pause state:

**Before:**
```javascript
// Had to infer pause state from get-pending-pause-change or other methods
const pendingData = await callReadOnly('get-pending-pause-change');
// Parse and extract current state from complex response
```

**After:**
```javascript
// Direct pause state query
const pauseData = await callReadOnly('get-is-paused');
const isPaused = parseClarityValue(pauseData.result); // Returns boolean
```

### For Frontend Developers

The `fetchPauseState()` function in `admin-contract.js` now uses the new read-only function internally. No changes needed to your code if you're using this helper.

**Example Usage:**
```javascript
import { fetchPauseState } from '../lib/admin-contract';

const state = await fetchPauseState();
console.log(state.isPaused); // true or false
console.log(state.pendingPause); // Pending proposal value (if any)
console.log(state.effectiveHeight); // When pending proposal becomes executable
```

### For Admin Dashboard Users

No changes required. The admin dashboard automatically uses the new function.

## Response Format

### get-is-paused Response

```clarity
(ok true) // Contract is paused
(ok false) // Contract is running
```

### Clarity Hex Examples

**Paused (true):**
```
0x0703
```

**Running (false):**
```
0x0704
```

## Benefits

1. **Simpler API**: Direct access to pause state without parsing complex tuples
2. **Better Performance**: Single function call instead of inferring from other data
3. **Clearer Intent**: Explicit function name makes code more readable
4. **Consistency**: Follows naming convention of other read-only functions

## Backward Compatibility

This is a **non-breaking change**. The addition of a new read-only function does not affect existing functionality:

- All existing functions continue to work as before
- The `is-paused` data variable remains unchanged
- The `get-pending-pause-change` function still returns current state in its response
- Frontend code that doesn't use the new function will continue to work

## Testing

### Contract Tests

New tests have been added to verify the function works correctly:

```bash
npm test -- tests/tipstream-v2.test.ts
npm test -- tests/tipstream.test.ts
```

### Frontend Tests

Tests verify the integration with the frontend helpers:

```bash
cd frontend
npm test -- pause-state.test.js
npm test -- admin-contract.test.js
```

## Documentation Updates

The following documentation has been updated:

- `README.md` - Added `get-is-paused` to read-only functions table
- `docs/PAUSE_API_REFERENCE.md` - Full API documentation for the new function
- `docs/PAUSE_OPERATIONS.md` - Updated function availability table
- `docs/PAUSE_CONTROL_RUNBOOK.md` - Updated operational procedures
- `docs/ADMIN_OPERATIONS.md` - Updated admin dashboard examples

## Troubleshooting

### Issue: Function not found

**Symptom:** Contract call fails with "function not found" error

**Solution:** Ensure you're calling the correct function name: `get-is-paused` (not `is-paused`)

### Issue: Unexpected response format

**Symptom:** Response doesn't match expected format

**Solution:** The function returns `(ok bool)`, not a raw boolean. Use `parseClarityValue()` to extract the boolean value.

### Issue: Old code still works

**Symptom:** Code using old inference method still works

**Explanation:** This is expected. The old method of inferring pause state from `get-pending-pause-change` still works. The new function is an addition, not a replacement.

## Support

For questions or issues related to this change:

1. Check the [PAUSE_API_REFERENCE.md](./PAUSE_API_REFERENCE.md) for detailed API documentation
2. Review the [PAUSE_OPERATIONS.md](./PAUSE_OPERATIONS.md) for operational guidance
3. Open an issue on GitHub with the `pause-control` label

## Related Changes

This change is part of issue #345: "Add a direct read-only contract function for the current pause state"

**Related Documentation:**
- [PAUSE_API_REFERENCE.md](./PAUSE_API_REFERENCE.md)
- [PAUSE_OPERATIONS.md](./PAUSE_OPERATIONS.md)
- [PAUSE_CONTROL_RUNBOOK.md](./PAUSE_CONTROL_RUNBOOK.md)
- [ADMIN_OPERATIONS.md](./ADMIN_OPERATIONS.md)
6 changes: 3 additions & 3 deletions docs/PAUSE_API_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ Pause proposal pending:

---

### is-paused
### get-is-paused

Returns current contract pause state.

**Function Signature:**
```clarity
(define-read-only (is-paused) ...)
(define-read-only (get-is-paused) ...)
```

**Parameters:** None
Expand All @@ -169,7 +169,7 @@ PAUSE_OPERATIONS = {
EXECUTE_PAUSE: 'execute-pause-change',
CANCEL_PAUSE: 'cancel-pause-change',
GET_PENDING: 'get-pending-pause-change',
IS_PAUSED: 'is-paused'
GET_IS_PAUSED: 'get-is-paused'
}

TIMELOCK_BLOCKS = 144 // ~24 hours
Expand Down
4 changes: 2 additions & 2 deletions docs/PAUSE_CONTROL_RUNBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Before executing any pause change:

### If Pause Executed Unexpectedly

1. Verify pause state: Check `is-paused` returns true
1. Verify pause state: Check `get-is-paused` returns true
2. Determine if intentional
3. If unintentional:
- Call `set-paused(false)` immediately (direct bypass)
Expand All @@ -138,7 +138,7 @@ Before executing any pause change:
### If Unpause Fails

1. Call `set-paused(false)` directly (bypasses timelock)
2. Verify `is-paused` returns false
2. Verify `get-is-paused` returns false
3. Monitor system for issues
4. Investigate failure cause

Expand Down
2 changes: 1 addition & 1 deletion docs/PAUSE_OPERATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Need to pause?
| cancel-pause-change | ✓ | ✗ |
| set-paused (direct) | ✓ | ✗ |
| get-pending-pause-change | ✓ | ✓ |
| is-paused | ✓ | ✓ |
| get-is-paused | ✓ | ✓ |

## Events

Expand Down
Loading
Loading