func walletHistoryAction(c *gcli.Context) error { if c.NArg() > 0 { fmt.Printf("Error: invalid argument\n\n") gcli.ShowSubcommandHelp(c) return nil } f := c.String("f") if f == "" { f = filepath.Join(cfg.WalletDir, cfg.DefaultWalletName) } // check the file extension. if !strings.HasSuffix(f, walletExt) { return errWalletName } // check if file name contains path. if filepath.Base(f) != f { af, err := filepath.Abs(f) if err != nil { return fmt.Errorf("invalid wallet file:%v, err:%v", f, err) } f = af } else { f = filepath.Join(cfg.WalletDir, f) } // get all addresses in the wallet. addrs, err := getAddresses(f) if err != nil { return err } // get all the addresses affected uxouts uxouts, err := getAddrUxOuts(addrs) if err != nil { return err } // transmute the uxout to addrHistory, and sort the items by time in ascend order. totalAddrHis := []addrHistory{} for _, ux := range uxouts { addrHis, err := makeAddrHisArray(ux) if err != nil { return err } totalAddrHis = append(totalAddrHis, addrHis...) } sort.Sort(byTime(totalAddrHis)) // print the addr history v, err := json.MarshalIndent(totalAddrHis, "", " ") if err != nil { return errJSONMarshal } fmt.Println(string(v)) return nil }
func getToAddress(c *gcli.Context) (string, error) { if c.NArg() < 2 { return "", errors.New("invalid argument") } toAddr := c.Args().First() // validate address if _, err := cipher.DecodeBase58Address(toAddr); err != nil { return "", err } return toAddr, nil }
func basics(c *cli.Context) error { if c.NArg() == 0 { return errors.New("no resume specified") } location := c.Args().Get(c.NArg() - 1) resume, err := dresh.FetchResume(location) if err != nil { return err } fmt.Println(dresh.BoxWrap(resume.Basics.Header(), resume.Basics.Content())) return nil }
func gatherAddrs(c *gcli.Context) ([]string, error) { w := c.String("f") var a string if c.NArg() > 0 { a = c.Args().First() if _, err := cipher.DecodeBase58Address(a); err != nil { return []string{}, fmt.Errorf("invalid address: %v", a) } } addrs := []string{} if w == "" && a == "" { // use default wallet w = filepath.Join(cfg.WalletDir, cfg.DefaultWalletName) } if w != "" { if !strings.HasSuffix(w, walletExt) { return []string{}, fmt.Errorf("error wallet file name, must has %v extension", walletExt) } if filepath.Base(w) == w { w = filepath.Join(cfg.WalletDir, w) } else { var err error w, err = filepath.Abs(w) if err != nil { return []string{}, err } } wlt, err := wallet.Load(w) if err != nil { return []string{}, err } addresses := wlt.GetAddresses() for _, a := range addresses { addrs = append(addrs, a.String()) } } if a != "" { addrs = append(addrs, a) } return addrs, nil }
func getAmount(c *gcli.Context) (uint64, error) { if c.NArg() < 2 { return 0, errors.New("invalid argument") } amount := c.Args().Get(1) amt, err := strconv.ParseFloat(amount, 64) if err != nil { return 0, errors.New("error amount") } v := uint64(amt * 1e6) if (v % 1e6) != 0 { return 0, errors.New("skycoin coins must be multiple of 1e6") } return v, nil }
func work(c *cli.Context) error { if c.NArg() == 0 { return errors.New("no resume specified") } location := c.Args().Get(c.NArg() - 1) resume, err := dresh.FetchResume(location) if err != nil { return err } career := resume.Work last := c.Int("last") if last != 0 { date := time.Now().AddDate(-1*last, 0, 0) career = career.Since(date) } since := c.String("since") if since != "" { date, err := time.Parse(dresh.DateLayout, since) if err != nil { return err } career = career.Since(date) } with := c.String("with") if with != "" { skills := strings.Split(with, ",") career = career.WorkingWith(skills) } for _, work := range career { fmt.Println(dresh.BoxWrap(work.Header(), work.Content())) } return nil }