Example #1
0
func postProcess(do *definitions.Do) error {
	switch do.DefaultOutput {
	case "csv":
		for _, job := range do.Package.Jobs {
			if err := util.WriteJobResultCSV(job.JobName, job.JobResult); err != nil {
				return err
			}
		}
	case "json":
		results := make(map[string]string)
		for _, job := range do.Package.Jobs {
			results[job.JobName] = job.JobResult
		}
		return util.WriteJobResultJSON(results)
	}

	if do.SummaryTable {
		// TableWriter goes here.
	}

	return nil
}
Example #2
0
func RegisterNameJob(name *definitions.RegisterName, do *definitions.Do) (string, error) {
	// Process Variables
	name.DataFile, _ = util.PreProcess(name.DataFile, do)

	// If a data file is given it should be in csv format and
	// it will be read first. Once the file is parsed and sent
	// to the chain then a single nameRegTx will be sent if that
	// has been populated.
	if name.DataFile != "" {
		// open the file and use a reader
		fileReader, err := os.Open(name.DataFile)
		if err != nil {
			log.Error("ERROR =>")
			return "", err
		}

		defer fileReader.Close()
		r := csv.NewReader(fileReader)

		// loop through the records
		for {
			// Read the record
			record, err := r.Read()

			// Catch the errors
			if err == io.EOF {
				break
			}
			if err != nil {
				log.Error("ERROR =>")
				return "", err
			}

			// Sink the Amount into the third slot in the record if
			// it doesn't exist
			if len(record) <= 2 {
				record = append(record, name.Amount)
			}

			// Send an individual Tx for the record
			// [TODO]: move these to async using goroutines?
			r, err := registerNameTx(&definitions.RegisterName{
				Source: name.Source,
				Name:   record[0],
				Data:   record[1],
				Amount: record[2],
				Fee:    name.Fee,
				Nonce:  name.Nonce,
				Wait:   name.Wait,
			}, do)

			if err != nil {
				log.Error("ERROR =>")
				return "", err
			}

			n := fmt.Sprintf("%s:%s", record[0], record[1])
			// TODO: fix this... simple and naive result just now.
			if err = util.WriteJobResultCSV(n, r); err != nil {
				log.Error("ERROR =>")
				return "", err
			}
		}
	}

	// If the data field is populated then there is a single
	// nameRegTx to send. So do that *now*.
	if name.Data != "" {
		return registerNameTx(name, do)
	} else {
		return "data_file_parsed", nil
	}
}