Skip to content

Commit 8306650

Browse files
feat(BitswapApi): add LedgerAsync
1 parent 912c604 commit 8306650

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/CoreApi/BitswapApi.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ internal BitswapApi(IpfsClient ipfs)
4646
{
4747
await ipfs.DoCommandAsync("bitswap/unwant", cancel, id);
4848
}
49+
50+
public async Task<BitswapLedger> LedgerAsync(Peer peer, CancellationToken cancel = default(CancellationToken))
51+
{
52+
var json = await ipfs.DoCommandAsync("bitswap/ledger", cancel, peer.Id.ToString());
53+
var o = JObject.Parse(json);
54+
return new BitswapLedger
55+
{
56+
Peer = (string)o["Peer"],
57+
DataReceived = (ulong)o["Sent"],
58+
DataSent = (ulong)o["Recv"],
59+
BlocksExchanged = (ulong)o["Exchanged"]
60+
};
61+
}
4962
}
5063

5164
}

src/IpfsHttpClient.csproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,16 @@
1818
<Description> Provides .Net client access to the InterPlanetary File System.</Description>
1919
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
2020
<PackageReleaseNotes>https://github.com/richardschneider/net-ipfs-http-client/releases</PackageReleaseNotes>
21-
<Copyright>© 2015-2018 Richard Schneider</Copyright>
21+
<Copyright>© 2015-2019 Richard Schneider</Copyright>
2222
<PackageTags>ipfs peer-to-peer distributed file-system</PackageTags>
2323
<IncludeSymbols>True</IncludeSymbols>
24-
<PackageLicenseUrl>https://github.com/richardschneider/net-ipfs-http-client/blob/master/LICENSE</PackageLicenseUrl>
2524
<PackageProjectUrl>https://github.com/richardschneider/net-ipfs-http-client</PackageProjectUrl>
26-
<PackageIconUrl>https://github.com/ipfs/logo/blob/master/platform-icons/osx-menu-bar.png</PackageIconUrl>
25+
<PackageIconUrl>https://raw.githubusercontent.com/richardschneider/net-ipfs-core/master/doc/images/ipfs-cs-logo-64x64.png</PackageIconUrl>
2726
</PropertyGroup>
2827

2928
<ItemGroup>
30-
<PackageReference Include="Ipfs.Core" Version="0.51.1" />
31-
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
29+
<PackageReference Include="Ipfs.Core" Version="0.52.1" />
30+
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
3231
<PackageReference Include="System.Net.Http" Version="4.3.3" Condition="'$(TargetFramework)' == 'netstandard14'" />
3332
<PackageReference Include="System.Net.Http" Version="4.3.3" Condition="'$(TargetFramework)' == 'net45'" />
3433
</ItemGroup>

test/CoreApi/BitswapApiTest.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,14 @@ public async Task Unwant()
6363
break;
6464
}
6565
}
66+
67+
[TestMethod]
68+
public async Task Ledger()
69+
{
70+
var peer = new Peer { Id = "QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3" };
71+
var ledger = await ipfs.Bitswap.LedgerAsync(peer);
72+
Assert.IsNotNull(ledger);
73+
Assert.AreEqual(peer.Id, ledger.Peer.Id);
74+
}
6675
}
6776
}

0 commit comments

Comments
 (0)