Skip to content

Commit eaf630d

Browse files
committed
feat: Add support for synthetic NFD records from account column in CSV files
Enhanced CSV processing to handle "account" column, creating synthetic NFD records when present. Updated validation to ensure either "name/nfd" or "account" columns are required. Adjusted README to document the new behavior.
1 parent 7eb3746 commit eaf630d

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Some of these options conflict with eachother if specified together.
122122
- `note`: An optional note to include with the transaction
123123

124124
**Destination**: This configures the recipients of the assets.
125-
- `csvFile`: Path to CSV file to load NFD names from (makes some options irrelevant). The first row must contain column names - with the column containing the nfd name named either nfd or name.π
125+
- `csvFile`: Path to CSV file to load NFD names from (makes some options irrelevant). The first row must contain column name, either nfd or name (For nfd names), or account. Each row after the header should contain the nfd or account as appropriate (in the right, or only column).
126126
- `segmentsOfRoot`: The root segments of the destination.
127127
- If specified, the NFDs are just those which are segments of a particular root NFD. If not specified, then ALL nfds are the starting point.
128128
- `allowDuplicateAccounts`: Determines whether duplicate accounts are allowed (defaulting to no duplicates)

recips.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,36 @@ func getNfdsToChooseFrom(config *BatchSendConfig) ([]*nfdapi.NfdRecord, error) {
8989
)
9090
csvRecords, err = processCsvFile(config.Destination.CsvFile)
9191
if err == nil {
92-
misc.Infof(logger, "..read %d NFDs from csv file", len(csvRecords))
92+
misc.Infof(logger, "..read %d records from csv file", len(csvRecords))
9393
nfdFetchChan := make(chan *nfdapi.NfdRecord, fanSize)
9494
go func() {
9595
for _, csvRecord := range csvRecords {
96+
if csvRecord["account"] != "" {
97+
account := csvRecord["account"]
98+
// Create a synthetic NFD record with the account address as the NFD name
99+
nfdFetchChan <- &nfdapi.NfdRecord{
100+
CaAlgo: []string{account},
101+
Name: strings.ToLower(csvRecord["account"][:32]) + ".fake",
102+
Category: "premiun",
103+
DepositAccount: account,
104+
Expired: false,
105+
Owner: account,
106+
ParentAppID: 0,
107+
Properties: &nfdapi.NfdProperties{
108+
Internal: map[string]string{},
109+
UserDefined: map[string]string{},
110+
Verified: map[string]string{},
111+
},
112+
State: "owned",
113+
TimeChanged: time.Now(),
114+
TimeCreated: time.Now(),
115+
TimeExpires: time.Now(),
116+
TimePurchased: time.Now(),
117+
}
118+
continue
119+
} else if csvRecord["nfd"] == "" {
120+
continue
121+
}
96122
fanOut.Run(func(val any) error {
97123
nfdName := val.(string)
98124
view := "brief"
@@ -293,18 +319,24 @@ func processCsvFile(csvFile string) ([]map[string]string, error) {
293319

294320
header := records[0]
295321
nameIndex := -1
322+
accountIndex := -1
296323
for i, colName := range header {
297324
if strings.EqualFold(colName, "name") || strings.EqualFold(colName, "nfd") {
298325
nameIndex = i
299326
break
327+
} else if strings.EqualFold(colName, "account") {
328+
accountIndex = i
329+
break
300330
}
301331
}
302332

303-
if nameIndex == -1 {
304-
return nil, errors.New("neither 'name' nor 'nfd' column found in CSV file")
333+
if nameIndex == -1 && accountIndex == -1 {
334+
return nil, errors.New("neither 'name | nfd' or 'account' column found in CSV file")
305335
}
306336
// always convert column to nfd
307-
header[nameIndex] = "nfd"
337+
if nameIndex != -1 {
338+
header[nameIndex] = "nfd"
339+
}
308340

309341
var result []map[string]string
310342
for _, row := range records[1:] {

0 commit comments

Comments
 (0)