MCPcopy Index your code
hub / github.com/chain/Core / submit

Method submit

core/transact.go:299–334  ·  view source on GitHub ↗

POST /submit-transaction

(ctx context.Context, x submitArg)

Source from the content-addressed store, hash-verified

297
298// POST /submit-transaction
299func (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}

Callers

nothing calls this directly

Calls 6

forwardToLeaderMethod · 0.95
submitSingleMethod · 0.95
batchRecoverFunction · 0.85
WaitMethod · 0.80
StateMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected