POST /submit-transaction
(ctx context.Context, x submitArg)
| 297 | |
| 298 | // POST /submit-transaction |
| 299 | func (a *API) submit(ctx context.Context, x submitArg) (interface{}, error) { |
| 300 | if a.leader.State() != leader.Leading { |
| 301 | var resp json.RawMessage |
| 302 | err := a.forwardToLeader(ctx, "/submit-transaction", x, &resp) |
| 303 | return resp, err |
| 304 | } |
| 305 | |
| 306 | // Setup a timeout for the provided wait duration. |
| 307 | timeout := x.wait.Duration |
| 308 | if timeout <= 0 { |
| 309 | timeout = 30 * time.Second |
| 310 | } |
| 311 | ctx, cancel := context.WithTimeout(ctx, timeout) |
| 312 | defer cancel() |
| 313 | |
| 314 | responses := make([]interface{}, len(x.Transactions)) |
| 315 | var wg sync.WaitGroup |
| 316 | wg.Add(len(responses)) |
| 317 | for i := range responses { |
| 318 | go func(i int) { |
| 319 | subctx := reqid.NewSubContext(ctx, reqid.New()) |
| 320 | defer wg.Done() |
| 321 | defer batchRecover(subctx, &responses[i]) |
| 322 | |
| 323 | tx, err := a.submitSingle(subctx, &x.Transactions[i], x.WaitUntil) |
| 324 | if err != nil { |
| 325 | responses[i] = err |
| 326 | } else { |
| 327 | responses[i] = tx |
| 328 | } |
| 329 | }(i) |
| 330 | } |
| 331 | |
| 332 | wg.Wait() |
| 333 | return responses, nil |
| 334 | } |
nothing calls this directly
no test coverage detected