finalizeTxWait calls FinalizeTx and then waits for confirmation of the transaction. A nil error return means the transaction is confirmed on the blockchain. ErrRejected means a conflicting tx is on the blockchain. context.DeadlineExceeded means ctx is an expiring context that timed out.
(ctx context.Context, txTemplate *txbuilder.Template, waitUntil string)
| 212 | // on the blockchain. context.DeadlineExceeded means ctx is an |
| 213 | // expiring context that timed out. |
| 214 | func (a *API) finalizeTxWait(ctx context.Context, txTemplate *txbuilder.Template, waitUntil string) error { |
| 215 | // Use the current generator height as the lower bound of the block height |
| 216 | // that the transaction may appear in. |
| 217 | generatorHeight, _ := fetch.GeneratorHeight() |
| 218 | localHeight := a.chain.Height() |
| 219 | if localHeight > generatorHeight { |
| 220 | generatorHeight = localHeight |
| 221 | } |
| 222 | |
| 223 | // Remember this height in case we retry this submit call. |
| 224 | height, err := recordSubmittedTx(ctx, a.db, txTemplate.Transaction.ID, generatorHeight) |
| 225 | if err != nil { |
| 226 | return errors.Wrap(err, "saving tx submitted height") |
| 227 | } |
| 228 | |
| 229 | err = txbuilder.FinalizeTx(ctx, a.chain, a.submitter, txTemplate.Transaction) |
| 230 | if err != nil { |
| 231 | return err |
| 232 | } |
| 233 | if waitUntil == "none" { |
| 234 | return nil |
| 235 | } |
| 236 | |
| 237 | height, err = a.waitForTxInBlock(ctx, txTemplate.Transaction, height) |
| 238 | if err != nil { |
| 239 | return err |
| 240 | } |
| 241 | if waitUntil == "confirmed" { |
| 242 | return nil |
| 243 | } |
| 244 | |
| 245 | select { |
| 246 | case <-ctx.Done(): |
| 247 | return ctx.Err() |
| 248 | case <-a.pinStore.AllWaiter(height): |
| 249 | } |
| 250 | |
| 251 | return nil |
| 252 | } |
| 253 | |
| 254 | func (a *API) waitForTxInBlock(ctx context.Context, tx *legacy.Tx, height uint64) (uint64, error) { |
| 255 | for { |
no test coverage detected