MCPcopy Create free account
hub / github.com/chain/Core / buildSingle

Method buildSingle

core/transact.go:49–102  ·  view source on GitHub ↗
(ctx context.Context, req *buildRequest)

Source from the content-addressed store, hash-verified

47}
48
49func (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
105func (a *API) build(ctx context.Context, buildReqs []*buildRequest) (interface{}, error) {

Callers 1

buildMethod · 0.95

Calls 6

filterAliasesMethod · 0.95
actionDecoderMethod · 0.95
FormatMethod · 0.80
BuildMethod · 0.65
ErrorMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected