forked from Onyx-Protocol/Onyx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request.go
46 lines (40 loc) · 1.15 KB
/
request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package core
import (
"context"
"chain/encoding/json"
"chain/errors"
"chain/protocol/bc/legacy"
)
var (
errBadActionType = errors.New("bad action type")
errBadAlias = errors.New("bad alias")
errBadAction = errors.New("bad action object")
)
type buildRequest struct {
Tx *legacy.TxData `json:"base_transaction"`
Actions []map[string]interface{} `json:"actions"`
TTL json.Duration `json:"ttl"`
}
func (a *API) filterAliases(ctx context.Context, br *buildRequest) error {
for i, m := range br.Actions {
id, _ := m["assset_id"].(string)
alias, _ := m["asset_alias"].(string)
if id == "" && alias != "" {
asset, err := a.assets.FindByAlias(ctx, alias)
if err != nil {
return errors.WithDetailf(err, "invalid asset alias %s on action %d", alias, i)
}
m["asset_id"] = asset.AssetID
}
id, _ = m["account_id"].(string)
alias, _ = m["account_alias"].(string)
if id == "" && alias != "" {
acc, err := a.accounts.FindByAlias(ctx, alias)
if err != nil {
return errors.WithDetailf(err, "invalid account alias %s on action %d", alias, i)
}
m["account_id"] = acc.ID
}
}
return nil
}