wait-transaction-state.rst (5372B)
1 .. ts:op:: waitTransactionState 2 :read-only: 3 4 Wait until a transaction is in a particular state. The operation 5 blocks until the transaction reaches the requested state, an 6 error occurs, or the timeout expires. 7 8 **Request:** 9 10 The request ``args`` must be a `WaitTransactionStateRequest` 11 object. 12 13 **Response:** 14 15 On success, the result is a `WaitTransactionStateResponse` 16 object. 17 18 **Details:** 19 20 This is a long-polling operation: it returns once the 21 transaction's state matches ``txState``, matches one of the 22 ``bailStates``, or (with ``bailOnError``) an error is recorded 23 for the transaction. The response's ``matched`` field says which 24 of the two sets of states ended the wait. 25 26 The ``txState`` and ``bailStates`` fields are 27 `TestingWaitTxStateSpec` values: a `TransactionStatePattern` or a 28 list of patterns (matching when any pattern matches), a 29 wallet-internal numeric state ID, or one of the shorthands 30 ``nonpending`` (any major state other than ``pending``) and 31 ``final`` (any final major state). In a pattern, ``major``, 32 ``minor`` and ``working`` accept the wildcard ``*``; a pattern 33 without ``minor`` only matches states that have no minor state, 34 while a pattern without ``working`` matches regardless of the 35 flag. 36 37 Without ``bailStates`` or ``bailOnError``, a transaction that 38 reaches a state it will never leave keeps the caller waiting 39 until the ``timeout`` expires; the wait then fails with 40 ``GENERIC_TIMEOUT``. 41 42 If no transaction with the given ``transactionId`` exists, the 43 wait fails with ``WALLET_TRANSACTION_NOT_FOUND`` instead of 44 waiting. 45 46 When ``progressToken`` is set, the wait reports request 47 progress notifications (including recorded transaction errors 48 with their retry counter and remaining retry delay) and can be 49 cancelled with :ts:op:`cancelProgressToken` or nudged with 50 :ts:op:`retryProgressTokenNow`. Cancellation fails the wait 51 with ``WALLET_CORE_REQUEST_CANCELLED``; it stops only the wait, 52 not the transaction. 53 54 .. ts:def:: WaitTransactionStateRequest 55 56 interface WaitTransactionStateRequest { 57 transactionId: TransactionIdStr; 58 59 // Receive request progress notifications and control this wait 60 // via ``cancelProgressToken``/``retryProgressTokenNow``. 61 // Cancellation stops only the wait. Retry-now retries the 62 // transaction if its current state allows it, without 63 // restarting the wait or extending its timeout. Transaction 64 // errors are reported with their recorded retry counter and 65 // remaining delay; without a recorded error retry, the counter 66 // is zero and the delay is "forever". 67 progressToken?: string; 68 69 // Additional identifier that is used in the logs to easily 70 // find the status of the particular wait request. 71 logId?: string; 72 73 // After the timeout has passed, give up on waiting for the 74 // desired state and raise an error instead. 75 timeout?: DurationUnitSpec; 76 77 // If set to true, wait until the desired state is reached 78 // with an error. 79 requireError?: boolean; 80 81 // State(s) to wait for. 82 txState: TestingWaitTxStateSpec; 83 84 // States that end the wait even though they are not the state 85 // that was waited for. The response says which of the two 86 // sets matched. Without this, a transaction that ends up in 87 // a state it will never leave keeps the caller waiting until 88 // the timeout. 89 bailStates?: TestingWaitTxStateSpec; 90 91 // End the wait as soon as an error is recorded for the 92 // transaction. Beware that this includes transient errors of 93 // retried operations, which are cleared again once the 94 // operation succeeds. 95 bailOnError?: boolean; 96 } 97 98 .. ts:def:: WaitTransactionStateResponse 99 100 interface WaitTransactionStateResponse { 101 // Which set of states ended the wait: the requested state or 102 // one of the bail states. 103 matched: "target" | "bail"; 104 105 // State that ended the wait. 106 txState: TransactionState; 107 108 // Wallet-internal state ID, only used for debugging and 109 // testing. 110 stId: number; 111 } 112 113 .. ts:def:: TestingWaitTxStateSpec 114 115 // State(s) to wait for: a plain pattern or a list of patterns 116 // (matching any of them), a wallet-internal numeric state ID, or 117 // one of the shorthands for a category of states. 118 type TestingWaitTxStateSpec = 119 | TransactionStatePattern 120 | TransactionStatePattern[] 121 | number 122 | "nonpending" 123 | "final"; 124 125 .. ts:def:: TransactionStatePattern 126 127 interface TransactionStatePattern { 128 major: TransactionMajorState | TransactionStateWildcard; 129 130 minor?: TransactionMinorState | TransactionStateWildcard; 131 132 // Required value of the "working" flag of the transaction 133 // state. A transaction state without the flag counts as 134 // false. If left undefined, the flag is not taken into 135 // account when matching, i.e. it behaves like a wildcard. 136 working?: boolean | TransactionStateWildcard; 137 } 138 139 .. ts:def:: TransactionStateWildcard 140 141 type TransactionStateWildcard = "*"; 142 143 .. ts:def:: DurationUnitSpec 144 145 // A duration given as a sum of the specified units; used for 146 // timeouts. 147 interface DurationUnitSpec { 148 seconds?: number; 149 150 minutes?: number; 151 152 hours?: number; 153 154 days?: number; 155 156 months?: number; 157 158 years?: number; 159 }