Skip to content

Commit

Permalink
register: only register with custom field if attrs are --include'd
Browse files Browse the repository at this point in the history
If include is an empty string, strings.Split returns []string{""} so the
custom field gets set to an ugly strange value: {"":null}

Similarly the attrs field in the AA log gets set to the strange value of
[""]

Now this is fixed by checking for an empty string first.
  • Loading branch information
makew0rld committed Jul 3, 2024
1 parent 3c421b8 commit a627987
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
func Run(args []string) error {
fs := flag.NewFlagSet("register", flag.ContinueOnError)
fs.StringVar(&chain, "on", "", "Chain/network to register asset on (numbers,avalanche,near)")
fs.StringVar(&include, "include", "", "Comma-separated list of attributes to register")
fs.StringVar(&include, "include", "", "Comma-separated list of attributes to register (optional)")
fs.BoolVar(&testnet, "testnet", false, "Register on a test network (if supported)")
fs.BoolVar(&dryRun, "dry-run", false, "show registration info without actually sending it")

Expand All @@ -50,22 +50,24 @@ func Run(args []string) error {
// Currently only one registration API is supported: Numbers Protocol
// Docs: https://docs.numbersprotocol.io/developers/commit-asset-history/commit-via-api

attrNames := strings.Split(include, ",")

metadata := make(map[string]any)
for _, attr := range attrNames {
var err error
metadata[attr], err = getAttValue(cid, attr)
if err != nil {
return err
}
}

requestData := map[string]any{
"assetCid": cid,
"assetCreator": "Starling Lab",
"testnet": testnet,
"custom": metadata,
}

var attrNames []string
if include != "" {
attrNames = strings.Split(include, ",")
metadata := make(map[string]any)
for _, attr := range attrNames {
var err error
metadata[attr], err = getAttValue(cid, attr)
if err != nil {
return err
}
}
requestData["custom"] = metadata
}

// Required fields
Expand All @@ -89,7 +91,7 @@ func Run(args []string) error {
}
tmp2, err := time.Parse(time.RFC3339, timeCreated)
if err != nil {
return fmt.Errorf("schema error: time_created is RFC3339: %w", err)
return fmt.Errorf("schema error: time_created is not RFC3339: %w", err)
}
requestData["assetTimestampCreated"] = tmp2.Unix()

Expand Down

0 comments on commit a627987

Please sign in to comment.