github.com/Synthesix/Sia@v1.3.3-0.20180413141344-f863baeed3ca/cmd/siac/export.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "os" 7 8 "github.com/Synthesix/Sia/node/api" 9 "github.com/Synthesix/Sia/types" 10 11 "github.com/spf13/cobra" 12 ) 13 14 var ( 15 renterExportCmd = &cobra.Command{ 16 Use: "export", 17 Short: "export renter data to various formats", 18 Long: "Export renter data in various formats.", 19 // Run field not provided; export requires a subcommand. 20 } 21 22 renterExportContractTxnsCmd = &cobra.Command{ 23 Use: "contract-txns [destination]", 24 Short: "export the renter's contracts for import to `https://rankings.sia.tech/`", 25 Long: "Export the renter's current contract set in JSON format to the specified " + 26 "file. Intended for upload to `https://rankings.sia.tech/`.", 27 Run: wrap(renterexportcontracttxnscmd), 28 } 29 ) 30 31 // renterexportcontracttxnscmd is the handler for the command `siac renter export contract-txns`. 32 // Exports the current contract set to JSON. 33 func renterexportcontracttxnscmd(destination string) { 34 var cs api.RenterContracts 35 err := getAPI("/renter/contracts", &cs) 36 if err != nil { 37 die("Could not retrieve contracts:", err) 38 } 39 var contractTxns []types.Transaction 40 for _, c := range cs.Contracts { 41 contractTxns = append(contractTxns, c.LastTransaction) 42 } 43 destination = abs(destination) 44 file, err := os.Create(destination) 45 if err != nil { 46 die("Could not export to file:", err) 47 } 48 err = json.NewEncoder(file).Encode(contractTxns) 49 if err != nil { 50 die("Could not export to file:", err) 51 } 52 fmt.Println("Exported contract data to", destination) 53 }