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