Skip to content

Commit f5f81ba

Browse files
feat: Implement IBlockRepositoryApi
1 parent 0996705 commit f5f81ba

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed

doc/articles/client.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ string text = await ipfs.FileSystem.ReadAllTextAsync(filename);
3636
| ------- | ------- |
3737
| [Bitswap](xref:Ipfs.CoreApi.IBitswapApi) | Data trading module for IPFS; requests blocks from and sends blocks to other peers |
3838
| [Block](xref:Ipfs.CoreApi.IBlockApi) | Manages the blocks |
39+
| [BlockRepository](xref:Ipfs.CoreApi.IBlockRepositoryApi) | Manages the repository of blocks |
3940
| [Bootstrap](xref:Ipfs.CoreApi.IBootstrapApi) | Trusted peers |
4041
| [Config](xref:Ipfs.CoreApi.IConfigApi) | Manages the configuration of the local peer |
4142
| [Dag](xref:Ipfs.CoreApi.IDagApi) | Manages the IPLD (linked data) Directed Acrylic Graph |

src/CoreApi/BlockRepositoryApi.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Net.Http;
7+
using System.Text;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
using Ipfs.CoreApi;
11+
using System.IO;
12+
13+
namespace Ipfs.Http
14+
{
15+
16+
class BlockRepositoryApi : IBlockRepositoryApi
17+
{
18+
IpfsClient ipfs;
19+
20+
internal BlockRepositoryApi(IpfsClient ipfs)
21+
{
22+
this.ipfs = ipfs;
23+
}
24+
25+
public async Task RemoveGarbageAsync(CancellationToken cancel = default(CancellationToken))
26+
{
27+
await ipfs.DoCommandAsync("repo/gc", cancel);
28+
}
29+
30+
public Task<RepositoryData> StatisticsAsync(CancellationToken cancel = default(CancellationToken))
31+
{
32+
return ipfs.DoCommandAsync<RepositoryData>("repo/stat", cancel);
33+
}
34+
35+
public async Task VerifyAsync(CancellationToken cancel = default(CancellationToken))
36+
{
37+
await ipfs.DoCommandAsync("repo/verify", cancel);
38+
}
39+
40+
public async Task<string> VersionAsync(CancellationToken cancel = default(CancellationToken))
41+
{
42+
var json = await ipfs.DoCommandAsync("repo/version", cancel);
43+
var info = JObject.Parse(json);
44+
return (string)info["Version"];
45+
}
46+
}
47+
}

src/IpfsClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public IpfsClient()
6666
Bootstrap = new BootstrapApi(this);
6767
Bitswap = new BitswapApi(this);
6868
Block = new BlockApi(this);
69+
BlockRepository = new BlockRepositoryApi(this);
6970
Config = new ConfigApi(this);
7071
Pin = new PinApi(this);
7172
Dht = new DhtApi(this);
@@ -138,6 +139,9 @@ public IpfsClient(string host)
138139
/// <inheritdoc />
139140
public IBlockApi Block { get; private set; }
140141

142+
/// <inheritdoc />
143+
public IBlockRepositoryApi BlockRepository { get; private set; }
144+
141145
/// <inheritdoc />
142146
public IConfigApi Config { get; private set; }
143147

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.50.0" />
30+
<PackageReference Include="Ipfs.Core" Version="0.51.1" />
3131
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
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'" />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using Newtonsoft.Json.Linq;
3+
using System;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Ipfs.Http
9+
{
10+
11+
[TestClass]
12+
public class BlockRepositoryTest
13+
{
14+
15+
[TestMethod]
16+
public async Task Stats()
17+
{
18+
var ipfs = TestFixture.Ipfs;
19+
var stats = await ipfs.BlockRepository.StatisticsAsync();
20+
Assert.IsNotNull(stats);
21+
}
22+
23+
[TestMethod]
24+
public async Task Version()
25+
{
26+
var ipfs = TestFixture.Ipfs;
27+
var version = await ipfs.BlockRepository.VersionAsync();
28+
Assert.IsFalse(string.IsNullOrWhiteSpace(version));
29+
}
30+
31+
}
32+
}

0 commit comments

Comments
 (0)