Skip to content

Commit

Permalink
refactor: update docs, wallet assoc cmd and cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Cihelka committed May 19, 2023
1 parent dbe1d88 commit 5ee1411
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 38 deletions.
12 changes: 6 additions & 6 deletions api/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func handleAddWallet(c echo.Context, dldm *core.DeltaDM) error {
}

type AssociateWalletBody struct {
Address string `json:"address"`
Datasets []string `json:"datasets"`
Address string `json:"address"`
Datasets []uint `json:"datasets"`
}

// POST /api/wallet/associate
Expand All @@ -166,20 +166,20 @@ func handleAssociateWallet(c echo.Context, dldm *core.DeltaDM) error {
}

var newDatasets []core.Dataset
for _, datasetName := range awb.Datasets {
for _, datasetID := range awb.Datasets {

var dataset core.Dataset
err := dldm.DB.Model(core.Dataset{}).
Where("name = ?", datasetName).
Where("id = ?", datasetID).
Find(&dataset).
Error

if err != nil {
return fmt.Errorf("could not check for dataset %s : %s", datasetName, err)
return fmt.Errorf("could not check for dataset %d : %s", datasetID, err)
}

if dataset.ID == 0 {
return fmt.Errorf("dataset %s does not exist", datasetName)
return fmt.Errorf("dataset %d does not exist", datasetID)
}

newDatasets = append(newDatasets, dataset)
Expand Down
29 changes: 14 additions & 15 deletions cmd/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"fmt"
"io/ioutil"
"net/http"
"strings"
"strconv"

"github.com/application-research/delta-dm/api"
"github.com/urfave/cli/v2"
)

func WalletCmd() []*cli.Command {
var dataset string
var datasetIDs cli.UintSlice
var datasetID uint
var walletAddress string

var walletCmds []*cli.Command
Expand Down Expand Up @@ -128,10 +129,10 @@ func WalletCmd() []*cli.Command {
Usage: "associate wallet with dataset",
UsageText: "delta-dm wallet associate [wallet address]",
Flags: []cli.Flag{
&cli.StringFlag{
&cli.UintSliceFlag{
Name: "datasets",
Usage: "dataset names to associate with wallet (comma separated)",
Destination: &dataset,
Usage: "dataset ids to associate with wallet (comma separated)",
Destination: &datasetIDs,
Required: true,
},
&cli.StringFlag{
Expand All @@ -147,15 +148,13 @@ func WalletCmd() []*cli.Command {
return fmt.Errorf("failed to connect to ddm node: %s", err)
}

datasets := strings.Split(dataset, ",")

if len(datasets) < 1 {
return fmt.Errorf("please provide at least one dataset name")
if len(datasetIDs.Value()) < 1 {
return fmt.Errorf("please provide at least one dataset id")
}

awb := api.AssociateWalletBody{
Address: walletAddress,
Datasets: datasets,
Datasets: datasetIDs.Value(),
}

b, err := json.Marshal(awb)
Expand All @@ -177,10 +176,10 @@ func WalletCmd() []*cli.Command {
Name: "list",
Usage: "list wallets",
Flags: []cli.Flag{
&cli.StringFlag{
&cli.UintFlag{
Name: "dataset",
Usage: "filter wallets by dataset",
Destination: &dataset,
Usage: "filter wallets by dataset id",
Destination: &datasetID,
},
},
Action: func(c *cli.Context) error {
Expand All @@ -191,8 +190,8 @@ func WalletCmd() []*cli.Command {

url := "/api/v1/wallets"

if dataset != "" {
url += "?dataset=" + dataset
if datasetID != 0 {
url += "?dataset=" + strconv.FormatUint(uint64(datasetID), 10)
}

res, closer, err := cmd.MakeRequest(http.MethodGet, url, nil)
Expand Down
16 changes: 9 additions & 7 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ All endpoints (with the exception of `/self-service`) require the `Authorization
### POST /contents/:dataset
- Add content (CAR files) to the dataset
- Accepts three types of input - standard (delta-dm) format, singularity format, or CSV- as defined below
- The :dataset parameter is the ID (uint) of the dataset to add the content to

#### Request Params
```jsonc
/dataset // ID of dataset to add content to
?import_type=<type> // singularity or csv. omit for standard format.
```
Expand Down Expand Up @@ -216,7 +218,7 @@ baga6ea4seaqhf2ymr6ahkxe3i2txmnqbmltzyf65nwcdvq2hvwmcx4eu4wzl4fi,bafybeif2bu5bdq
#### Request Params
```jsonc
:dataset // dataset name to get contents for
/dataset // dataset ID to get contents for
```
Expand All @@ -235,15 +237,15 @@ baga6ea4seaqhf2ymr6ahkxe3i2txmnqbmltzyf65nwcdvq2hvwmcx4eu4wzl4fi,bafybeif2bu5bdq
"payload_cid": "bafybeifyaefzfalorttcqfcvago2rbide3mnm72geau6xxdl6iewc5leki",
"size": 26619574156,
"padded_size": 34359738368,
"dataset_name": "delta-test",
"dataset_id": 1,
"num_replications": 0
},
{
"commp": "baga6ea4seaqaqoogvy2fkicdzm5xbmpcn4vsffapc54tfl4nbrlbfczkqsuxooi",
"payload_cid": "bafybeiaupshs7vgsgs5e4y6n7tqkz4ghuyt3teqmqqad6ee5drlbg6dcfq",
"size": 24389555373,
"padded_size": 34359738368,
"dataset_name": "delta-test",
"dataset_id": 2,
"num_replications": 0
}
]
Expand Down Expand Up @@ -408,7 +410,7 @@ Note the response contains two properties. `totalCount` is the total number of r
"payload_cid": "bafybeifoxwwx5newgdwnvojyotleh3x3sy7ckndwa2ysioe4corv4ixgti",
"size": 18010019221,
"padded_size": 34359738368,
"dataset_name": "delta-test",
"dataset_id": 1,
"num_replications": 1
},
"deal_time": "2023-03-01T19:16:14.956401-08:00",
Expand All @@ -428,7 +430,7 @@ Note the response contains two properties. `totalCount` is the total number of r
"payload_cid": "bafybeiezpv62emncxbe4adoyipxhzcdy2eqzxx3rde6rdzuqxs57gdsp2q",
"size": 18010019221,
"padded_size": 34359738368,
"dataset_name": "delta-test",
"dataset_id": 1,
"num_replications": 1
},
"deal_time": "2023-03-01T19:16:14.962877-08:00",
Expand All @@ -448,7 +450,7 @@ Note the response contains two properties. `totalCount` is the total number of r
"payload_cid": "bafybeiakf666idv6zs4uksckfkjr76jmvrcuu4neidldxlfngo2vh6jvfe",
"size": 18010019222,
"padded_size": 34359738368,
"dataset_name": "delta-test",
"dataset_id": 1,
"num_replications": 3
},
"deal_time": "2023-03-06T11:09:42.185318-08:00",
Expand All @@ -469,7 +471,7 @@ Note the response contains two properties. `totalCount` is the total number of r
"payload_cid": "bafybeiakf666idv6zs4uksckfkjr76jmvrcuu4neidldxlfngo2vh6jvfe",
"size": 18010019222,
"padded_size": 34359738368,
"dataset_name": "delta-test",
"dataset_id": 1,
"num_replications": 3
},
"deal_time": "2023-03-06T11:11:02.723922-08:00",
Expand Down
12 changes: 6 additions & 6 deletions docs/cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,32 @@ Example:

## replication
### Create a replication
`> ./delta-dm replication create --provider <sp-actor-id> -num <num-deals-to-make> [--dataset <dataset-name>] [--delay-start <delay-start-days>]`
`> ./delta-dm replication create --provider <sp-actor-id> -num <num-deals-to-make> [--dataset <dataset-id>] [--delay-start <delay-start-days>]`

Example:
```bash
./delta-dm replication create --provider f01000 --num 3 --dataset delta-test --delay-start 3
./delta-dm replication create --provider f01000 --num 3 --dataset 1 --delay-start 3
```

## content
### Import content to a dataset
`> ./delta-dm content import --dataset <dataset-name> [--json <path-to-json-file>] [--csv <path-to-csv-file>] [--singularity <path-to-singularity-export-json-file>]`
`> ./delta-dm content import --dataset <dataset-id> [--json <path-to-json-file>] [--csv <path-to-csv-file>] [--singularity <path-to-singularity-export-json-file>]`

One of `--json`, `--csv`, or `--singularity` must be provided.

For the expected file format, see the [api docs](api.md##/contents)

Example:
```bash
./delta-dm content import --dataset delta-test --json ./content.json
./delta-dm content import --dataset 1 --json ./content.json
```

### List content in a dataset
`> ./delta-dm content list --dataset <dataset-name>`
`> ./delta-dm content list --dataset <dataset-id>`


## replication profiles
- Note: `replication-profile`/`rp` commands take a `dataset id`, not a `dataset name`- you can run `dataset list` to get the id for a dataset.
- Note: `replication-profile`/`rp` commands take a `dataset id`, you can run `dataset list` to get the id for a dataset.
### Add a replication profile
`> ./delta-dm rp add --spid <sp-id> --dataset <dataset-id> [--unsealed] [--indexed]`

Expand Down
Empty file removed docs/howto.md
Empty file.
6 changes: 3 additions & 3 deletions docs/singularity-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ To do this, ensure your Singularity database is running and you have the `DELTA_

**Script Usage**
```bash
./singularity-import.sh <SINGULARITY datasetName> <DELTA datasetName> <deltaToken>
./singularity-import.sh <SINGULARITY datasetName> <DELTA datasetID> <deltaToken>
```

Where
- SINGULARITY datasetName - the name of the dataset in Singularity (aka the slug)
- DELTA datasetName - the name of the dataset in Delta
- DELTA datasetID - the ID of the dataset in Delta (you can obtain this with `delta-dm dataset list`)
- deltaToken - your delta auth token

**Example**
```bash
./singularity-import.sh common-crawl common-crawl EST-XXX-ARY
./singularity-import.sh common-crawl 1 EST-XXX-ARY
```
2 changes: 1 addition & 1 deletion scripts/singularity-import.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Usage: ./singularity-import.sh <SINGULARITY datasetName> <DELTA datasetName> <deltaToken>
# Usage: ./singularity-import.sh <SINGULARITY datasetName> <DELTA datasetID> <deltaToken>
query="{\"datasetName\": \"$1\", \"pieceSize\": { \"\$gt\": 0 }}"
DELTA_TOKEN="Authorization: Bearer $3"

Expand Down

0 comments on commit 5ee1411

Please sign in to comment.