Skip to content

Commit

Permalink
merge bee 1.5.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Mar 23, 2022
2 parents 02a6218 + 435bc3b commit c9488bc
Show file tree
Hide file tree
Showing 46 changed files with 13,858 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/BeeNet/BeeNodeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public BeeNodeClient(
string baseUrl = "http://localhost/",
int? gatewayApiPort = 1633,
int? debugApiPort = 1635,
GatewayApiVersion gatewayApiVersion = GatewayApiVersion.v2_0_0,
DebugApiVersion debugApiVersion = DebugApiVersion.v1_2_0)
GatewayApiVersion gatewayApiVersion = GatewayApiVersion.v3_0_0,
DebugApiVersion debugApiVersion = DebugApiVersion.v2_0_0)
{
httpClient = new HttpClient();

Expand Down
79 changes: 65 additions & 14 deletions src/BeeNet/Clients/DebugApi/BeeDebugClient.cs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/BeeNet/Clients/DebugApi/DebugApiVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Etherna.BeeNet.Clients.DebugApi
public enum DebugApiVersion
{
v1_2_0,
v1_2_1
v1_2_1,
v2_0_0
}
}
53 changes: 53 additions & 0 deletions src/BeeNet/Clients/DebugApi/DtoFixer/PostageBatchDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace Etherna.BeeNet.Clients.DebugApi.DtoFixer
{
public class PostageBatchDto
{
/// <summary>
/// Internal debugging property. It indicates if the batch is expired.
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("exists")]
public bool Exists { get; set; } = default!;

/// <summary>
/// The time (in seconds) remaining until the batch expires; -1 signals that the batch never expires; 0 signals that the batch has already expired.
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("batchTTL")]
public int BatchTTL { get; set; } = default!;

[System.Text.Json.Serialization.JsonPropertyName("batchID")]
public string BatchID { get; set; } = default!;

[System.Text.Json.Serialization.JsonPropertyName("utilization")]
public int Utilization { get; set; } = default!;

/// <summary>
/// Indicate that the batch was discovered by the Bee node, but it awaits enough on-chain confirmations before declaring the batch as usable.
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("usable")]
public bool Usable { get; set; } = default!;

[System.Text.Json.Serialization.JsonPropertyName("label")]
public string Label { get; set; } = default!;

[System.Text.Json.Serialization.JsonPropertyName("depth")]
public int Depth { get; set; } = default!;

/// <summary>
/// Numeric string that represents integer which might exceeds `Number.MAX_SAFE_INTEGER` limit (2^53-1)
/// </summary>

[System.Text.Json.Serialization.JsonPropertyName("amount")]
public string Amount { get; set; } = default!;

[System.Text.Json.Serialization.JsonPropertyName("bucketDepth")]
public int BucketDepth { get; set; } = default!;

[System.Text.Json.Serialization.JsonPropertyName("blockNumber")]
public int BlockNumber { get; set; } = default!;

[System.Text.Json.Serialization.JsonPropertyName("immutableFlag")]
public bool ImmutableFlag { get; set; } = default!;
}
}
2 changes: 1 addition & 1 deletion src/BeeNet/Clients/DebugApi/IBeeDebugClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ Task<string> DepositIntoChequeBookAsync(
/// <returns></returns>
/// <returns>Returns an array of all available and currently valid postage batches.</returns>
/// <exception cref="BeeNetDebugApiException">A server side error occurred.</exception>
Task<IEnumerable<PostageBatchDto>> GetAllValidPostageBatchesFromAllNodesAsync();
Task<IEnumerable<BatchDto>> GetAllValidPostageBatchesFromAllNodesAsync();

/// <summary>Get the balances with a specific peer including prepaid services</summary>
/// <param name="address">Swarm address of peer</param>
Expand Down
7,317 changes: 7,317 additions & 0 deletions src/BeeNet/Clients/DebugApi/V2_0_0/BeeDebugClient_2_0_0.cs

Large diffs are not rendered by default.

79 changes: 74 additions & 5 deletions src/BeeNet/Clients/GatewayApi/BeeGatewayClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

using Etherna.BeeNet.Clients.GatewayApi.V2_0_0;
using Etherna.BeeNet.Clients.GatewayApi.V3_0_0;
using Etherna.BeeNet.DtoModels;
using Etherna.BeeNet.InputModels;
using System;
Expand All @@ -29,6 +30,7 @@ public class BeeGatewayClient : IBeeGatewayClient
{
// Fields.
private readonly IBeeGatewayClient_2_0_0 beeGatewayApiClient_2_0_0;
private readonly IBeeGatewayClient_3_0_0 beeGatewayApiClient_3_0_0;

// Constructors.
public BeeGatewayClient(HttpClient httpClient, Uri baseUrl, GatewayApiVersion apiVersion)
Expand All @@ -37,6 +39,7 @@ public BeeGatewayClient(HttpClient httpClient, Uri baseUrl, GatewayApiVersion ap
throw new ArgumentNullException(nameof(baseUrl));

beeGatewayApiClient_2_0_0 = new BeeGatewayClient_2_0_0(httpClient) { BaseUrl = baseUrl.ToString() };
beeGatewayApiClient_3_0_0 = new BeeGatewayClient_3_0_0(httpClient) { BaseUrl = baseUrl.ToString() };
CurrentApiVersion = apiVersion;
}

Expand All @@ -48,7 +51,13 @@ public async Task<AuthDto> AuthenticateAsync(string role, int expiry) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => new AuthDto(await beeGatewayApiClient_2_0_0.AuthAsync(
new Body
new V2_0_0.Body
{
Role = role,
Expiry = expiry
}).ConfigureAwait(false)),
GatewayApiVersion.v3_0_0 => new AuthDto(await beeGatewayApiClient_3_0_0.AuthAsync(
new V3_0_0.Body
{
Role = role,
Expiry = expiry
Expand All @@ -60,6 +69,7 @@ public async Task<StewardShipGetDto> CheckIsContentAvailableAsync(string referen
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => new StewardShipGetDto(await beeGatewayApiClient_2_0_0.StewardshipGetAsync(reference).ConfigureAwait(false)),
GatewayApiVersion.v3_0_0 => new StewardShipGetDto(await beeGatewayApiClient_3_0_0.StewardshipGetAsync(reference).ConfigureAwait(false)),
_ => throw new InvalidOperationException()
};

Expand All @@ -72,21 +82,28 @@ public async Task<string> CreateFeedAsync(
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => (await beeGatewayApiClient_2_0_0.FeedsPostAsync(owner, topic, swarmPostageBatchId, type, swarmPin).ConfigureAwait(false)).Reference,
GatewayApiVersion.v3_0_0 => (await beeGatewayApiClient_3_0_0.FeedsPostAsync(owner, topic, swarmPostageBatchId, type, swarmPin).ConfigureAwait(false)).Reference,
_ => throw new InvalidOperationException()
};

public async Task<MessageResponseDto> CreatePinAsync(string reference) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => new MessageResponseDto(await beeGatewayApiClient_2_0_0.PinsPostAsync(reference).ConfigureAwait(false)),
GatewayApiVersion.v3_0_0 => new MessageResponseDto(await beeGatewayApiClient_3_0_0.PinsPostAsync(reference).ConfigureAwait(false)),
_ => throw new InvalidOperationException()
};

public async Task<TagInfoDto> CreateTagAsync(string address) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => new TagInfoDto(await beeGatewayApiClient_2_0_0.TagsPostAsync(
new Body3
new V2_0_0.Body3
{
Address = address
}).ConfigureAwait(false)),
GatewayApiVersion.v3_0_0 => new TagInfoDto(await beeGatewayApiClient_3_0_0.TagsPostAsync(
new V3_0_0.Body3
{
Address = address
}).ConfigureAwait(false)),
Expand All @@ -97,34 +114,39 @@ public async Task<MessageResponseDto> DeletePinAsync(string reference) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => new MessageResponseDto(await beeGatewayApiClient_2_0_0.PinsDeleteAsync(reference).ConfigureAwait(false)),
GatewayApiVersion.v3_0_0 => new MessageResponseDto(await beeGatewayApiClient_3_0_0.PinsDeleteAsync(reference).ConfigureAwait(false)),
_ => throw new InvalidOperationException()
};

public Task DeleteTagAsync(int uid) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => beeGatewayApiClient_2_0_0.TagsDeleteAsync(uid),
GatewayApiVersion.v3_0_0 => beeGatewayApiClient_3_0_0.TagsDeleteAsync(uid),
_ => throw new InvalidOperationException()
};

public async Task<IEnumerable<string>> GetAllPinsAsync() =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => (await beeGatewayApiClient_2_0_0.PinsGetAsync().ConfigureAwait(false)).Addresses ?? Array.Empty<string>(),
GatewayApiVersion.v3_0_0 => (await beeGatewayApiClient_3_0_0.PinsGetAsync().ConfigureAwait(false)).References,
_ => throw new InvalidOperationException()
};

public async Task<Stream> GetChunkStreamAsync(string reference, string? targets = null) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => (await beeGatewayApiClient_2_0_0.ChunksGetAsync(reference, targets).ConfigureAwait(false)).Stream,
GatewayApiVersion.v3_0_0 => (await beeGatewayApiClient_3_0_0.ChunksGetAsync(reference, targets).ConfigureAwait(false)).Stream,
_ => throw new InvalidOperationException()
};

public async Task<Stream> GetDataAsync(string reference) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => (await beeGatewayApiClient_2_0_0.BytesGetAsync(reference).ConfigureAwait(false)).Stream,
GatewayApiVersion.v3_0_0 => (await beeGatewayApiClient_3_0_0.BytesGetAsync(reference).ConfigureAwait(false)).Stream,
_ => throw new InvalidOperationException()
};

Expand All @@ -136,49 +158,61 @@ public async Task<string> GetFeedAsync(
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => (await beeGatewayApiClient_2_0_0.FeedsGetAsync(owner, topic, at, type).ConfigureAwait(false)).Reference,
GatewayApiVersion.v3_0_0 => (await beeGatewayApiClient_3_0_0.FeedsGetAsync(owner, topic, at, type).ConfigureAwait(false)).Reference,
_ => throw new InvalidOperationException()
};

public async Task<Stream> GetFileAsync(string reference, string path, string? targets = null) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => (await beeGatewayApiClient_2_0_0.BzzGetAsync(reference, path, targets).ConfigureAwait(false)).Stream,
GatewayApiVersion.v3_0_0 => (await beeGatewayApiClient_3_0_0.BzzGetAsync(reference, path, targets).ConfigureAwait(false)).Stream,
_ => throw new InvalidOperationException()
};

public async Task<Stream> GetFileAsync(string reference, string? targets = null) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => (await beeGatewayApiClient_2_0_0.BzzGetAsync(reference, targets, CancellationToken.None).ConfigureAwait(false)).Stream,
GatewayApiVersion.v3_0_0 => (await beeGatewayApiClient_3_0_0.BzzGetAsync(reference, targets, CancellationToken.None).ConfigureAwait(false)).Stream,
_ => throw new InvalidOperationException()
};

public async Task<string> GetPinStatusAsync(string reference) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => await beeGatewayApiClient_2_0_0.PinsGetAsync(reference).ConfigureAwait(false),
GatewayApiVersion.v3_0_0 => await beeGatewayApiClient_3_0_0.PinsGetAsync(reference).ConfigureAwait(false),
_ => throw new InvalidOperationException()
};

public async Task<TagInfoDto> GetTagInfoAsync(int uid) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => new TagInfoDto(await beeGatewayApiClient_2_0_0.TagsGetAsync(uid).ConfigureAwait(false)),
GatewayApiVersion.v3_0_0 => new TagInfoDto(await beeGatewayApiClient_3_0_0.TagsGetAsync(uid).ConfigureAwait(false)),
_ => throw new InvalidOperationException()
};

public async Task<IEnumerable<TagInfoDto>> GetTagsListAsync(int? offset = null, int? limit = null) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => (await beeGatewayApiClient_2_0_0.TagsGetAsync(offset, limit).ConfigureAwait(false)).Tags.Select(i => new TagInfoDto(i)),
GatewayApiVersion.v3_0_0 => (await beeGatewayApiClient_3_0_0.TagsGetAsync(offset, limit).ConfigureAwait(false)).Tags.Select(i => new TagInfoDto(i)),
_ => throw new InvalidOperationException()
};

public async Task<string> RefreshAuthAsync(string role, int expiry) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => (await beeGatewayApiClient_2_0_0.RefreshAsync(
new Body2
new V2_0_0.Body2
{
Role = role,
Expiry = expiry
}).ConfigureAwait(false)).Key,
GatewayApiVersion.v3_0_0 => (await beeGatewayApiClient_3_0_0.RefreshAsync(
new V3_0_0.Body2
{
Role = role,
Expiry = expiry
Expand All @@ -190,6 +224,7 @@ public Task ReuploadContentAsync(string reference) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => beeGatewayApiClient_2_0_0.StewardshipPutAsync(reference),
GatewayApiVersion.v3_0_0 => beeGatewayApiClient_3_0_0.StewardshipPutAsync(reference),
_ => throw new InvalidOperationException()
};

Expand All @@ -201,13 +236,15 @@ public Task SendPssAsync(
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => beeGatewayApiClient_2_0_0.PssSendAsync(topic, targets, swarmPostageBatchId, recipient),
GatewayApiVersion.v3_0_0 => beeGatewayApiClient_3_0_0.PssSendAsync(topic, targets, swarmPostageBatchId, recipient),
_ => throw new InvalidOperationException()
};

public Task SubscribeToPssAsync(string topic) =>
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => beeGatewayApiClient_2_0_0.PssSubscribeAsync(topic),
GatewayApiVersion.v3_0_0 => beeGatewayApiClient_3_0_0.PssSubscribeAsync(topic),
_ => throw new InvalidOperationException()
};

Expand All @@ -218,7 +255,12 @@ public async Task<VersionDto> UpdateTagAsync(int uid, string? address = null) =>
uid,
address is null ?
null :
new Body4 { Address = address }).ConfigureAwait(false)),
new V2_0_0.Body4 { Address = address }).ConfigureAwait(false)),
GatewayApiVersion.v3_0_0 => new VersionDto(await beeGatewayApiClient_3_0_0.TagsPatchAsync(
uid,
address is null ?
null :
new V3_0_0.Body4 { Address = address }).ConfigureAwait(false)),
_ => throw new InvalidOperationException()
};

Expand All @@ -236,6 +278,12 @@ public async Task<VersionDto> UploadChunkAsync(
swarmPin,
swarmDeferredUpload,
body).ConfigureAwait(false)),
GatewayApiVersion.v3_0_0 => new VersionDto(await beeGatewayApiClient_3_0_0.ChunksPostAsync(
swarmPostageBatchId,
swarmTag,
swarmPin,
swarmDeferredUpload,
body).ConfigureAwait(false)),
_ => throw new InvalidOperationException()
};

Expand All @@ -246,6 +294,7 @@ public Task UploadChunksStreamAsync(
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => beeGatewayApiClient_2_0_0.ChunksStreamAsync(swarmPostageBatchId, swarmTag, swarmPin),
GatewayApiVersion.v3_0_0 => beeGatewayApiClient_3_0_0.ChunksStreamAsync(swarmPostageBatchId, swarmTag, swarmPin),
_ => throw new InvalidOperationException()
};

Expand All @@ -265,6 +314,13 @@ public async Task<string> UploadDataAsync(
swarmEncrypt,
swarmDeferredUpload,
body).ConfigureAwait(false)).Reference,
GatewayApiVersion.v3_0_0 => (await beeGatewayApiClient_3_0_0.BytesPostAsync(
swarmPostageBatchId,
swarmTag,
swarmPin,
swarmEncrypt,
swarmDeferredUpload,
body).ConfigureAwait(false)).Reference,
_ => throw new InvalidOperationException()
};

Expand Down Expand Up @@ -293,7 +349,19 @@ public async Task<string> UploadFileAsync(
swarmIndexDocument,
swarmErrorDocument,
swarmDeferredUpload,
file.Select(f => new FileParameter(f.Data, f.FileName, f.ContentType))).ConfigureAwait(false)).Reference,
file.Select(f => new V2_0_0.FileParameter(f.Data, f.FileName, f.ContentType))).ConfigureAwait(false)).Reference,
GatewayApiVersion.v3_0_0 => (await beeGatewayApiClient_3_0_0.BzzPostAsync(
swarmPostageBatchId,
name,
swarmTag,
swarmPin,
swarmEncrypt,
contentType,
swarmCollection,
swarmIndexDocument,
swarmErrorDocument,
swarmDeferredUpload,
file.Select(f => new V3_0_0.FileParameter(f.Data, f.FileName, f.ContentType))).ConfigureAwait(false)).Reference,
_ => throw new InvalidOperationException()
};

Expand All @@ -305,6 +373,7 @@ public async Task<string> UploadSocAsync(
CurrentApiVersion switch
{
GatewayApiVersion.v2_0_0 => (await beeGatewayApiClient_2_0_0.SocAsync(owner, id, sig, swarmPin).ConfigureAwait(false)).Reference,
GatewayApiVersion.v3_0_0 => (await beeGatewayApiClient_3_0_0.SocAsync(owner, id, sig, swarmPin).ConfigureAwait(false)).Reference,
_ => throw new InvalidOperationException()
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/BeeNet/Clients/GatewayApi/GatewayApiVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Etherna.BeeNet.Clients.GatewayApi
{
public enum GatewayApiVersion
{
v2_0_0
v2_0_0,
v3_0_0
}
}
Loading

0 comments on commit c9488bc

Please sign in to comment.