Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 91c3354

Browse files
committed
Revert "feat: add dag stat method (#297)"
This reverts commit 45de4b3.
1 parent 45de4b3 commit 91c3354

File tree

4 files changed

+1
-147
lines changed

4 files changed

+1
-147
lines changed

Diff for: dag.go

-83
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010

1111
files "github.com/ipfs/boxo/files"
12-
"github.com/ipfs/go-cid"
1312
"github.com/ipfs/go-ipfs-api/options"
1413
)
1514

@@ -38,46 +37,6 @@ type DagImportOutput struct {
3837
Stats *DagImportStats
3938
}
4039

41-
type DagStat struct {
42-
Cid cid.Cid `json:",omitempty"`
43-
Size uint64 `json:",omitempty"`
44-
NumBlocks int64 `json:",omitempty"`
45-
}
46-
47-
type DagStatOutput struct {
48-
redundantSize uint64 `json:"-"`
49-
UniqueBlocks int `json:",omitempty"`
50-
TotalSize uint64 `json:",omitempty"`
51-
SharedSize uint64 `json:",omitempty"`
52-
Ratio float32 `json:",omitempty"`
53-
DagStatsArray []*DagStat `json:"DagStats,omitempty"`
54-
}
55-
56-
func (s *DagStat) UnmarshalJSON(data []byte) error {
57-
/*
58-
We can't rely on cid.Cid.UnmarshalJSON since it uses the {"/": "..."}
59-
format. To make the output consistent and follow the Kubo API patterns
60-
we use the Cid.Parse method
61-
*/
62-
63-
type Alias DagStat
64-
aux := struct {
65-
Cid string `json:"Cid"`
66-
*Alias
67-
}{
68-
Alias: (*Alias)(s),
69-
}
70-
if err := json.Unmarshal(data, &aux); err != nil {
71-
return err
72-
}
73-
Cid, err := cid.Parse(aux.Cid)
74-
if err != nil {
75-
return err
76-
}
77-
s.Cid = Cid
78-
return nil
79-
}
80-
8140
func (s *Shell) DagGet(ref string, out interface{}) error {
8241
return s.Request("dag/get", ref).Exec(context.Background(), out)
8342
}
@@ -192,45 +151,3 @@ func dagToFilesReader(data interface{}) (*files.MultiFileReader, error) {
192151

193152
return fileReader, nil
194153
}
195-
196-
// DagStat gets stats for dag with default options
197-
func (s *Shell) DagStat(data string) (DagStatOutput, error) {
198-
return s.DagStatWithOpts(data)
199-
}
200-
201-
// DagStatWithOpts gets stats for dag
202-
func (s *Shell) DagStatWithOpts(data string, opts ...options.DagStatOption) (DagStatOutput, error) {
203-
var out DagStatOutput
204-
cfg, err := options.DagStatOptions(opts...)
205-
if err != nil {
206-
return out, err
207-
}
208-
209-
resp, err := s.
210-
Request("dag/stat", data).
211-
Option("progress", cfg.Progress).
212-
Send(context.Background())
213-
214-
if err != nil {
215-
return out, err
216-
}
217-
218-
defer resp.Close()
219-
220-
if resp.Error != nil {
221-
return out, resp.Error
222-
}
223-
224-
dec := json.NewDecoder(resp.Output)
225-
for {
226-
var v DagStatOutput
227-
if err := dec.Decode(&v); err == io.EOF {
228-
break
229-
} else if err != nil {
230-
return out, err
231-
}
232-
out = v
233-
}
234-
235-
return out, nil
236-
}

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module github.com/ipfs/go-ipfs-api
55
require (
66
github.com/cheekybits/is v0.0.0-20150225183255-68e9c0620927
77
github.com/ipfs/boxo v0.8.0
8-
github.com/ipfs/go-cid v0.4.0
98
github.com/libp2p/go-libp2p v0.26.3
109
github.com/mitchellh/go-homedir v1.1.0
1110
github.com/multiformats/go-multiaddr v0.8.0
@@ -17,6 +16,7 @@ require (
1716
github.com/benbjohnson/clock v1.3.0 // indirect
1817
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 // indirect
1918
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
19+
github.com/ipfs/go-cid v0.4.0 // indirect
2020
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
2121
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
2222
github.com/libp2p/go-flow-metrics v0.1.0 // indirect

Diff for: options/dag_stat.go

-33
This file was deleted.

Diff for: shell_test.go

-30
Original file line numberDiff line numberDiff line change
@@ -630,33 +630,3 @@ func TestSwarmPeeringAdd(t *testing.T) {
630630
_, err := s.SwarmPeeringAdd(context.Background(), addr)
631631
is.Nil(err)
632632
}
633-
634-
func TestDagStat(t *testing.T) {
635-
is := is.New(t)
636-
s := NewShell(shellUrl)
637-
638-
result, err := s.DagStat("QmUwp4xYq4pt1xavfCnpJ2aoVETf83AsvK3W8KvUGtyzFB")
639-
is.Nil(err)
640-
is.Equal(result.TotalSize, 3383728)
641-
642-
is.Equal(result.DagStatsArray[0].Cid.String(), "QmUwp4xYq4pt1xavfCnpJ2aoVETf83AsvK3W8KvUGtyzFB")
643-
is.Equal(result.UniqueBlocks, 15)
644-
is.Equal(result.redundantSize, 0)
645-
is.Equal(result.SharedSize, 0)
646-
is.Equal(result.Ratio, 1)
647-
}
648-
649-
func TestDagStatWithOpts(t *testing.T) {
650-
is := is.New(t)
651-
s := NewShell(shellUrl)
652-
653-
result, err := s.DagStatWithOpts("QmUwp4xYq4pt1xavfCnpJ2aoVETf83AsvK3W8KvUGtyzFB", options.Dag.Progress(true))
654-
is.Nil(err)
655-
is.Equal(result.TotalSize, 3383728)
656-
657-
is.Equal(result.DagStatsArray[0].Cid.String(), "QmUwp4xYq4pt1xavfCnpJ2aoVETf83AsvK3W8KvUGtyzFB")
658-
is.Equal(result.UniqueBlocks, 15)
659-
is.Equal(result.redundantSize, 0)
660-
is.Equal(result.SharedSize, 0)
661-
is.Equal(result.Ratio, 1)
662-
}

0 commit comments

Comments
 (0)