Skip to content

Commit

Permalink
feat(cli): support "bitswap ledger"
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jun 17, 2019
1 parent 527791d commit c0a9ae5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions IpfsCli/Commands/BitswapCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Ipfs.Cli
[Command(Description = "Manage swapped blocks")]
[Subcommand("wantlist", typeof(BitswapWantListCommand))]
[Subcommand("unwant", typeof(BitswapUnwantCommand))]
[Subcommand("ledger", typeof(BitswapLedgerCommand))]
class BitswapCommand : CommandBase
{
public Program Parent { get; set; }
Expand Down Expand Up @@ -57,4 +58,21 @@ protected override async Task<int> OnExecute(CommandLineApplication app)
}
}

[Command(Description = "Show the current ledger for a peer")]
class BitswapLedgerCommand : CommandBase
{
[Argument(0, "peerid", "The PeerID (B58) of the ledger to inspect")]
[Required]
public string PeerId { get; set; }

BitswapCommand Parent { get; set; }

protected override async Task<int> OnExecute(CommandLineApplication app)
{
var Program = Parent.Parent;
var peer = new Peer { Id = PeerId };
var ledger = await Program.CoreApi.Bitswap.LedgerAsync(peer);
return Program.Output(app, ledger, null);
}
}
}
2 changes: 1 addition & 1 deletion IpfsCli/IpfsCli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<ItemGroup>
<PackageReference Include="Common.Logging" Version="3.4.1" />
<PackageReference Include="Ipfs.Http.Client" Version="0.29.0" />
<PackageReference Include="Ipfs.Http.Client" Version="0.30.0" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.2.5" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.9.0" />
Expand Down
2 changes: 1 addition & 1 deletion IpfsServer/HttpApi/V0/BitswapController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task Unwants(string arg)
/// The blocks that are needed by a peer.
/// </summary>
/// <param name="arg">
/// A peer ID or empty for self.
/// A peer ID.
/// </param>
[HttpGet, HttpPost, Route("bitswap/ledger")]
public async Task<BitswapLedgerDto> Ledger(string arg)
Expand Down

0 comments on commit c0a9ae5

Please sign in to comment.