(ctx context.Context, req *buildRequest)
| 47 | } |
| 48 | |
| 49 | func (a *API) buildSingle(ctx context.Context, req *buildRequest) (*txbuilder.Template, error) { |
| 50 | err := a.filterAliases(ctx, req) |
| 51 | if err != nil { |
| 52 | return nil, err |
| 53 | } |
| 54 | actions := make([]txbuilder.Action, 0, len(req.Actions)) |
| 55 | for i, act := range req.Actions { |
| 56 | typ, ok := act["type"].(string) |
| 57 | if !ok { |
| 58 | return nil, errors.WithDetailf(errBadActionType, "no action type provided on action %d", i) |
| 59 | } |
| 60 | decoder, ok := a.actionDecoder(typ) |
| 61 | if !ok { |
| 62 | return nil, errors.WithDetailf(errBadActionType, "unknown action type %q on action %d", typ, i) |
| 63 | } |
| 64 | |
| 65 | // Remarshal to JSON, the action may have been modified when we |
| 66 | // filtered aliases. |
| 67 | b, err := json.Marshal(act) |
| 68 | if err != nil { |
| 69 | return nil, err |
| 70 | } |
| 71 | a, err := decoder(b) |
| 72 | if err != nil { |
| 73 | return nil, errors.WithDetailf(errBadAction, "%s on action %d", err.Error(), i) |
| 74 | } |
| 75 | actions = append(actions, a) |
| 76 | } |
| 77 | |
| 78 | ttl := req.TTL.Duration |
| 79 | if ttl == 0 { |
| 80 | ttl = defaultTxTTL |
| 81 | } |
| 82 | maxTime := time.Now().Add(ttl) |
| 83 | tpl, err := txbuilder.Build(ctx, req.Tx, actions, maxTime) |
| 84 | if errors.Root(err) == txbuilder.ErrAction { |
| 85 | // Format each of the inner errors contained in the data. |
| 86 | var formattedErrs []httperror.Response |
| 87 | for _, innerErr := range errors.Data(err)["actions"].([]error) { |
| 88 | resp := errorFormatter.Format(innerErr) |
| 89 | formattedErrs = append(formattedErrs, resp) |
| 90 | } |
| 91 | err = errors.WithData(err, "actions", formattedErrs) |
| 92 | } |
| 93 | if err != nil { |
| 94 | return nil, err |
| 95 | } |
| 96 | |
| 97 | // ensure null is never returned for signing instructions |
| 98 | if tpl.SigningInstructions == nil { |
| 99 | tpl.SigningInstructions = []*txbuilder.SigningInstruction{} |
| 100 | } |
| 101 | return tpl, nil |
| 102 | } |
| 103 | |
| 104 | // POST /build-transaction |
| 105 | func (a *API) build(ctx context.Context, buildReqs []*buildRequest) (interface{}, error) { |
no test coverage detected