|
| 1 | +# List Failed Actions Example |
| 2 | + |
| 3 | +This example demonstrates how to retrieve a paginated list of failed wallet actions and optionally request recovery ("unfail") in the Go Wallet Toolbox SDK. Failed actions are transactions or actions that did not complete successfully. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The process involves several steps: |
| 8 | +1. Creating a wallet instance and establishing database connection. |
| 9 | +2. Configuring pagination and display parameters. |
| 10 | +3. Calling the wallet's `ListFailedActions` method with the configured arguments and an `unfail` flag. |
| 11 | +4. Processing and displaying the returned failed actions, including total count and details. |
| 12 | + |
| 13 | +When `unfail` is set to true, the call requests recovery for the returned failed actions, promoting them to be reprocessed by the unfail workflow. |
| 14 | + |
| 15 | +## Code Walkthrough |
| 16 | + |
| 17 | +### Configuration Parameters |
| 18 | + |
| 19 | +The example uses the following configurable constants: |
| 20 | + |
| 21 | +- **`DefaultLimit`**: Maximum number of actions to return per request (default: `100`) |
| 22 | +- **`DefaultOffset`**: Starting position for pagination (default: `0`) |
| 23 | +- **`DefaultOriginator`**: The originator domain or FQDN allowed to use this permission (default: `"example.com"`) |
| 24 | +- **`DefaultIncludeLabels`**: Whether to include labels in the response (default: `true`) |
| 25 | +- **`DefaultUnfail`**: Whether to request promotion of the listed failed actions to "unfail" (default: `false`) |
| 26 | + |
| 27 | +### Request Parameters |
| 28 | + |
| 29 | +`ListFailedActions` reuses `ListActionsArgs` for pagination and inclusion flags: |
| 30 | + |
| 31 | +- **`Limit`**: Controls how many actions to retrieve in a single request |
| 32 | +- **`Offset`**: Specifies the starting position for pagination |
| 33 | +- **`IncludeLabels`**: Include action labels in the response |
| 34 | + |
| 35 | +### Behavior Notes |
| 36 | + |
| 37 | +- The wallet injects a reserved spec-op label for "failed actions" so storage filters by status = failed. |
| 38 | +- If `unfail = true`, a control label is also included; after fetching results, storage promotes those TXIDs for the unfail processing flow (best-effort). |
| 39 | + |
| 40 | +## Running the Example |
| 41 | + |
| 42 | +To run this example: |
| 43 | + |
| 44 | +```bash |
| 45 | +go run ./examples/wallet_examples/list_failed_actions/list_failed_actions.go |
| 46 | +``` |
| 47 | + |
| 48 | +## Expected Output |
| 49 | + |
| 50 | +```text |
| 51 | +🚀 STARTING: List Failed Actions |
| 52 | +============================================================ |
| 53 | +Using remote storage: http://localhost:8100 |
| 54 | +CreateWallet: 02a675b6767bf17f8d37755d4afb8dcea49f79c0ae696f0f59c0b38154e482520f |
| 55 | +
|
| 56 | +=== STEP === |
| 57 | +Alice is performing: Listing failed actions |
| 58 | +-------------------------------------------------- |
| 59 | +ListFailedActionsArgs: {Labels:[] LabelQueryMode: IncludeLabels:0x7ff7033e34e0 IncludeInputs:<nil> IncludeInputSourceLockingScripts:<nil> IncludeInputUnlockingScripts:<nil> IncludeOutputs:<nil> IncludeOutputLockingScripts:<nil> Limit:0x7ff7033e3548 Offset:0x7ff7042fee4c SeekPermission:<nil>} |
| 60 | +Unfail: true |
| 61 | +============================================================ |
| 62 | +FailedActions: &{TotalActions:2 Actions:[{Txid:225cc7b2be25be0c3cc032d09fd8035128c9d8e2f0d32db6ab7d875648263bb4 Satoshis:-38 Status:failed IsOutgoing:true Description:mintPushDropToken Labels:[mintPushDropToken] Version:1 LockTime:0 Inputs:[] Outputs:[]} {Txid:568f51aa28dca612ee18351695c6a7e3f22a4a468909a5493442ed01e68e922f Satoshis:-38 Status:failed IsOutgoing:true Description:mintPushDropToken Labels:[mintPushDropToken] Version:1 LockTime:0 Inputs:[] Outputs:[]}]} |
| 63 | +============================================================ |
| 64 | +🎉 COMPLETED: List Failed Actions |
| 65 | +``` |
| 66 | + |
| 67 | +## Integration Steps |
| 68 | + |
| 69 | +To integrate failed-action listing into your application: |
| 70 | + |
| 71 | +1. **Configure pagination parameters** based on your UI needs (page size, starting offset). |
| 72 | +2. **Set the originator identifier** to your application's domain or identifier. |
| 73 | +3. **Choose label inclusion** if you need metadata for display or filtering. |
| 74 | +4. **Decide on `unfail` behavior**: set to `true` to request recovery of the listed failed actions. |
| 75 | +5. **Call `ListFailedActions`** on your wallet instance with the arguments and `unfail` flag. |
| 76 | +6. **Handle the response** and show failed actions to the user. |
| 77 | +7. **Monitor recovery**: when `unfail` is requested, the background unfail flow will attempt to move those actions forward. |
| 78 | + |
| 79 | +## Additional Resources |
| 80 | + |
| 81 | +- [List Failed Actions Code](./list_failed_actions.go) - Complete code example for listing failed actions |
| 82 | +- [List Actions Documentation](../list_actions/list_actions.md) - General action listing doc |
| 83 | + |
| 84 | + |
0 commit comments