Skip to content

Commit

Permalink
feat: implement --json flag for boost deal and deal-status (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc authored May 25, 2022
1 parent e19db8e commit bc85712
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/boost/deal_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,23 @@ func dealCmdAction(cctx *cli.Context, isOnline bool) error {
return fmt.Errorf("deal proposal rejected: %s", resp.Message)
}

if cctx.Bool("json") {
out := map[string]interface{}{
"dealUuid": dealUuid.String(),
"provider": maddr.String(),
"clientWallet": walletAddr.String(),
"payloadCid": rootCid.String(),
"commp": dealProposal.Proposal.PieceCID.String(),
"startEpoch": dealProposal.Proposal.StartEpoch.String(),
"endEpoch": dealProposal.Proposal.EndEpoch.String(),
"providerCollateral": dealProposal.Proposal.ProviderCollateral.String(),
}
if isOnline {
out["url"] = cctx.String("http-url")
}
return cmd.PrintJson(out)
}

msg := "sent deal proposal"
if !isOnline {
msg += " for offline deal"
Expand Down
26 changes: 26 additions & 0 deletions cmd/boost/deal_status_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,32 @@ var dealStatusCmd = &cli.Command{
return fmt.Errorf("send deal status request failed: %w", err)
}

if cctx.Bool("json") {
out := map[string]interface{}{}
if resp.Error != "" {
out["error"] = resp.Error
} else {
out = map[string]interface{}{
"dealUuid": resp.DealUUID.String(),
"provider": maddr.String(),
"clientWallet": walletAddr.String(),
"statusMessage": statusMessage(resp),
}
// resp.DealStatus should always be present if there's no error,
// but check just in case
if resp.DealStatus != nil {
out["label"] = resp.DealStatus.Proposal.Label
out["chainDealId"] = resp.DealStatus.ChainDealID
out["status"] = resp.DealStatus.Status
out["publishCid"] = nil
if resp.DealStatus.PublishCid != nil {
out["publishCid"] = resp.DealStatus.PublishCid.String()
}
}
}
return cmd.PrintJson(out)
}

msg := "got deal status response"
msg += "\n"

Expand Down

0 comments on commit bc85712

Please sign in to comment.