Skip to content

Commit bc85712

Browse files
authored
feat: implement --json flag for boost deal and deal-status (#542)
1 parent e19db8e commit bc85712

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

cmd/boost/deal_cmd.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,23 @@ func dealCmdAction(cctx *cli.Context, isOnline bool) error {
261261
return fmt.Errorf("deal proposal rejected: %s", resp.Message)
262262
}
263263

264+
if cctx.Bool("json") {
265+
out := map[string]interface{}{
266+
"dealUuid": dealUuid.String(),
267+
"provider": maddr.String(),
268+
"clientWallet": walletAddr.String(),
269+
"payloadCid": rootCid.String(),
270+
"commp": dealProposal.Proposal.PieceCID.String(),
271+
"startEpoch": dealProposal.Proposal.StartEpoch.String(),
272+
"endEpoch": dealProposal.Proposal.EndEpoch.String(),
273+
"providerCollateral": dealProposal.Proposal.ProviderCollateral.String(),
274+
}
275+
if isOnline {
276+
out["url"] = cctx.String("http-url")
277+
}
278+
return cmd.PrintJson(out)
279+
}
280+
264281
msg := "sent deal proposal"
265282
if !isOnline {
266283
msg += " for offline deal"

cmd/boost/deal_status_cmd.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,32 @@ var dealStatusCmd = &cli.Command{
8585
return fmt.Errorf("send deal status request failed: %w", err)
8686
}
8787

88+
if cctx.Bool("json") {
89+
out := map[string]interface{}{}
90+
if resp.Error != "" {
91+
out["error"] = resp.Error
92+
} else {
93+
out = map[string]interface{}{
94+
"dealUuid": resp.DealUUID.String(),
95+
"provider": maddr.String(),
96+
"clientWallet": walletAddr.String(),
97+
"statusMessage": statusMessage(resp),
98+
}
99+
// resp.DealStatus should always be present if there's no error,
100+
// but check just in case
101+
if resp.DealStatus != nil {
102+
out["label"] = resp.DealStatus.Proposal.Label
103+
out["chainDealId"] = resp.DealStatus.ChainDealID
104+
out["status"] = resp.DealStatus.Status
105+
out["publishCid"] = nil
106+
if resp.DealStatus.PublishCid != nil {
107+
out["publishCid"] = resp.DealStatus.PublishCid.String()
108+
}
109+
}
110+
}
111+
return cmd.PrintJson(out)
112+
}
113+
88114
msg := "got deal status response"
89115
msg += "\n"
90116

0 commit comments

Comments
 (0)