diff --git a/core/coreapi/dag.go b/core/coreapi/dag.go index de796bd4dc9..c5d59bc1395 100644 --- a/core/coreapi/dag.go +++ b/core/coreapi/dag.go @@ -19,7 +19,7 @@ type DagAPI struct { *caopts.DagOptions } -func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPutOption) ([]coreiface.Node, error) { +func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPutOption) (coreiface.Path, error) { settings, err := caopts.DagPutOptions(opts...) if err != nil { return nil, err @@ -38,16 +38,12 @@ func (api *DagAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.DagPut return nil, fmt.Errorf("no node returned from ParseInputs") } - out := make([]coreiface.Node, len(nds)) - for n, nd := range nds { - _, err := api.node.DAG.Add(nd) - if err != nil { - return nil, err - } - out[n] = nd + _, err = api.node.DAG.Add(nds[0]) + if err != nil { + return nil, err } - return out, nil + return ParseCid(nds[0].Cid()), nil } func (api *DagAPI) Get(ctx context.Context, path coreiface.Path) (coreiface.Node, error) { diff --git a/core/coreapi/dag_test.go b/core/coreapi/dag_test.go index b528afbaa15..43ddc26e6b8 100644 --- a/core/coreapi/dag_test.go +++ b/core/coreapi/dag_test.go @@ -33,8 +33,8 @@ func TestPut(t *testing.T) { t.Error(err) } - if res[0].Cid().String() != "zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv" { - t.Errorf("got wrong cid: %s", res[0].Cid().String()) + if res.Cid().String() != "zdpuAqckYF3ToF3gcJNxPZXmnmGuXd3gxHCXhq81HGxBejEvv" { + t.Errorf("got wrong cid: %s", res.Cid().String()) } } @@ -50,8 +50,8 @@ func TestPutWithHash(t *testing.T) { t.Error(err) } - if res[0].Cid().String() != "z5hRLNd2sv4z1c" { - t.Errorf("got wrong cid: %s", res[0].Cid().String()) + if res.Cid().String() != "z5hRLNd2sv4z1c" { + t.Errorf("got wrong cid: %s", res.Cid().String()) } } @@ -67,12 +67,12 @@ func TestPath(t *testing.T) { t.Error(err) } - res, err := api.Dag().Put(ctx, strings.NewReader(`{"lnk": {"/": "`+sub[0].Cid().String()+`"}}`)) + res, err := api.Dag().Put(ctx, strings.NewReader(`{"lnk": {"/": "`+sub.Cid().String()+`"}}`)) if err != nil { t.Error(err) } - p, err := coreapi.ParsePath(path.Join(res[0].Cid().String(), "lnk")) + p, err := coreapi.ParsePath(path.Join(res.Cid().String(), "lnk")) if err != nil { t.Error(err) } @@ -82,8 +82,8 @@ func TestPath(t *testing.T) { t.Error(err) } - if nd.Cid().String() != sub[0].Cid().String() { - t.Errorf("got unexpected cid %s, expected %s", nd.Cid().String(), sub[0].Cid().String()) + if nd.Cid().String() != sub.Cid().String() { + t.Errorf("got unexpected cid %s, expected %s", nd.Cid().String(), sub.Cid().String()) } } @@ -99,7 +99,7 @@ func TestTree(t *testing.T) { t.Error(err) } - lst := res[0].Tree("", -1) + lst := res.Tree("", -1) if len(lst) != len(treeExpected) { t.Errorf("tree length of %d doesn't match expected %d", len(lst), len(treeExpected)) } diff --git a/core/coreapi/interface/interface.go b/core/coreapi/interface/interface.go index f43700e9cb7..e51888e6012 100644 --- a/core/coreapi/interface/interface.go +++ b/core/coreapi/interface/interface.go @@ -61,8 +61,9 @@ type UnixfsAPI interface { // DagAPI specifies the interface to IPLD type DagAPI interface { // Put inserts data using specified format and input encoding. - // If format is not specified (nil), default dag-cbor/sha256 is used - Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) ([]Node, error) + // Unless used with WithCodec or WithHash, the defaults "dag-cbor" and + // "sha256" are used. + Put(ctx context.Context, src io.Reader, opts ...options.DagPutOption) (Path, error) // WithInputEnc is an option for Put which specifies the input encoding of the // data. Default is "json", most formats/codecs support "raw"