Skip to content

Commit fd4a86b

Browse files
feat(ObjectApi): add StatAsync
1 parent ec3af42 commit fd4a86b

File tree

3 files changed

+18
-52
lines changed

3 files changed

+18
-52
lines changed

src/CoreApi/ObjectApi.cs

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,6 @@ class ObjectApi : IObjectApi
1919

2020
IpfsClient ipfs;
2121

22-
/// <summary>
23-
/// TODO
24-
/// </summary>
25-
public class DagInfo
26-
{
27-
/// <summary>
28-
/// TODO
29-
/// </summary>
30-
public string Hash { get; set; }
31-
/// <summary>
32-
/// TODO
33-
/// </summary>
34-
public int NumLinks { get; set; }
35-
/// <summary>
36-
/// TODO
37-
/// </summary>
38-
public long BlockSize { get; set; }
39-
/// <summary>
40-
/// TODO
41-
/// </summary>
42-
public long LinksSize { get; set; }
43-
/// <summary>
44-
/// TODO
45-
/// </summary>
46-
public long DataSize { get; set; }
47-
/// <summary>
48-
/// TODO
49-
/// </summary>
50-
public long CumulativeSize { get; set; }
51-
}
52-
5322
internal ObjectApi(IpfsClient ipfs)
5423
{
5524
this.ipfs = ipfs;
@@ -95,21 +64,6 @@ internal ObjectApi(IpfsClient ipfs)
9564
return GetDagFromJson(json).Links;
9665
}
9766

98-
/// <summary>
99-
/// Get the statistics of a MerkleDAG node.
100-
/// </summary>
101-
/// <param name="id">
102-
/// The <see cref="Cid"/> of the node.
103-
/// </param>
104-
/// <param name="cancel">
105-
/// Is used to stop the task. When cancelled, the <see cref="TaskCanceledException"/> is raised.
106-
/// </param>
107-
/// <returns></returns>
108-
public Task<DagInfo> StatAsync(Cid id, CancellationToken cancel = default(CancellationToken))
109-
{
110-
return ipfs.DoCommandAsync<DagInfo>("object/stat", cancel, id);
111-
}
112-
11367
// TOOD: patch sub API
11468

11569
DagNode GetDagFromJson(string json)
@@ -126,5 +80,20 @@ DagNode GetDagFromJson(string json)
12680
(long)link["Size"]));
12781
return new DagNode(data, links);
12882
}
83+
84+
public async Task<ObjectStat> StatAsync(Cid id, CancellationToken cancel = default(CancellationToken))
85+
{
86+
var json = await ipfs.DoCommandAsync("object/stat", cancel, id);
87+
var r = JObject.Parse(json);
88+
89+
return new ObjectStat
90+
{
91+
LinkCount = (int)r["NumLinks"],
92+
LinkSize = (long)r["LinksSize"],
93+
BlockSize = (long)r["BlockSize"],
94+
DataSize = (long)r["DataSize"],
95+
CumulativeSize = (long)r["CumulativeSize"]
96+
};
97+
}
12998
}
13099
}

src/IpfsHttpClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</PropertyGroup>
2828

2929
<ItemGroup>
30-
<PackageReference Include="Ipfs.Core" Version="0.54.0" />
30+
<PackageReference Include="Ipfs.Core" Version="0.55.0" />
3131
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
3232
<PackageReference Include="System.Net.Http" Version="4.3.3" Condition="'$(TargetFramework)' == 'netstandard14'" />
3333
<PackageReference Include="System.Net.Http" Version="4.3.3" Condition="'$(TargetFramework)' == 'net45'" />

test/CoreApi/ObjectApiTest.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public async Task Links()
9191
Assert.AreEqual(beta.Links.First().Size, links.First().Size);
9292
}
9393

94-
#if falses
9594
[TestMethod]
9695
public async Task Stat()
9796
{
@@ -101,14 +100,12 @@ public async Task Stat()
101100
var node1 = await ipfs.Object.PutAsync(data1,
102101
new[] { node2.ToLink("some-link") });
103102
var info = await ipfs.Object.StatAsync(node1.Id);
104-
Assert.AreEqual("QmPR7W4kaADkAo4GKEVVPQN81EDUFCHJtqejQZ5dEG7pBC", info.Hash);
105-
Assert.AreEqual(1, info.NumLinks);
103+
Assert.AreEqual(1, info.LinkCount);
106104
Assert.AreEqual(64, info.BlockSize);
107-
Assert.AreEqual(53, info.LinksSize);
105+
Assert.AreEqual(53, info.LinkSize);
108106
Assert.AreEqual(11, info.DataSize);
109107
Assert.AreEqual(77, info.CumulativeSize);
110108
}
111-
#endif
112109

113110
[TestMethod]
114111
public async Task Get_Nonexistent()

0 commit comments

Comments
 (0)