-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afc30b8
commit 2520bff
Showing
6 changed files
with
74 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Substrate.Gear.Api.Generated; | ||
|
||
namespace Sails.Remoting; | ||
|
||
internal interface INodeClientProvider | ||
{ | ||
/// <summary> | ||
/// Returns connected node client. | ||
/// </summary> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns></returns> | ||
Task<SubstrateClientExt> GetNodeClientAsync(CancellationToken cancellationToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EnsureThat; | ||
using Sails.Remoting.Options; | ||
using Substrate.Gear.Api.Generated; | ||
using Substrate.NetApi.Model.Extrinsics; | ||
|
||
namespace Sails.Remoting; | ||
|
||
internal sealed class NodeClientProvider : IDisposable, INodeClientProvider | ||
{ | ||
public NodeClientProvider(NodeClientOptions options) | ||
{ | ||
EnsureArg.IsNotNull(options, nameof(options)); | ||
EnsureArg.IsNotNull(options.GearNodeUri, nameof(options.GearNodeUri)); | ||
|
||
this.nodeClient = new SubstrateClientExt(options.GearNodeUri, ChargeTransactionPayment.Default()); | ||
} | ||
|
||
private readonly SubstrateClientExt nodeClient; | ||
|
||
/// <inheritdoc/> | ||
public void Dispose() | ||
{ | ||
this.nodeClient.Dispose(); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task<SubstrateClientExt> GetNodeClientAsync(CancellationToken cancellationToken) | ||
{ | ||
await this.nodeClient.ConnectAsync(cancellationToken).ConfigureAwait(false); | ||
return this.nodeClient; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters