Skip to content

Commit

Permalink
[DX-392] Add support for BatchTransferBalance. (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
v16Studios authored Apr 18, 2024
1 parent 1be6cc7 commit b5747dc
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Numerics;
using System.Text.Json.Serialization;
using JetBrains.Annotations;

namespace Enjin.Platform.Sdk;

/// <summary>
/// This model encapsulates the required parameters for a balance transfer.
/// </summary>
[JsonConverter(typeof(GraphQlParameterJsonConverter<SimpleTransferParams>))]
[PublicAPI]
public class TransferBalanceParams : GraphQlParameter<TransferBalanceParams>,
IHasEncodableTokenId<TransferBalanceParams>
{
/// <summary>
/// Initializes a new instance of the <see cref="TransferBalanceParams"/> class.
/// </summary>
public TransferBalanceParams()
{
}

/// <summary>
/// Sets the value to transfer.
/// </summary>
/// <param name="value">The value.</param>
/// <returns>This parameter for chaining.</returns>
public TransferBalanceParams SetValue(BigInteger value)
{
return SetParameter("value", value);
}

/// <summary>
/// Sets whether the transaction will be kept from failing if the balance drops below the minimum requirement.
/// </summary>
/// <param name="keepAlive">Whether the transaction will be kept from failing.</param>
/// <returns>This parameter for chaining.</returns>
public TransferBalanceParams SetKeepAlive(bool? keepAlive)
{
return SetParameter("keepAlive", keepAlive);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,14 @@ public TransferRecipient SetOperatorParams(OperatorTransferParams? operatorParam
{
return SetParameter("operatorParams", operatorParams);
}

/// <summary>
/// Sets parameters for making a balance transfer.
/// </summary>
/// <param name="transferBalanceParams">The parameters.</param>
/// <returns>This parameter for chaining.</returns>
public TransferRecipient SetTransferBalanceParams(TransferBalanceParams? transferBalanceParams)
{
return SetParameter("transferBalanceParams", transferBalanceParams);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Numerics;
using JetBrains.Annotations;

namespace Enjin.Platform.Sdk;

/// <summary>
/// A request to act as a mutation for transferring multiple balances in one transaction.
/// </summary>
/// <remarks>
/// <para>
/// Up to 250 different transfers per batch may be included.
/// </para>
/// <para>
/// The <c>continueOnFailure</c> flag may be used to allow all valid transfers to complete while skipping transfers
/// which would fail so that they may be fixed and attempted again in another transaction.
/// </para>
/// </remarks>
/// <seealso cref="Transaction"/>
[PublicAPI]
public class BatchTransferBalance : GraphQlRequest<BatchTransferBalance, TransactionFragment>,
IHasContinueOnFailure<BatchTransferBalance>,
IHasIdempotencyKey<BatchTransferBalance>,
IHasSkipValidation<BatchTransferBalance>,
IHasSigningAccount<BatchTransferBalance>
{
/// <summary>
/// Initializes a new instance of the <see cref="BatchTransferBalance"/> class.
/// </summary>
public BatchTransferBalance() : base("BatchTransferBalance", GraphQlRequestType.Mutation)
{
}

/// <summary>
/// Sets the recipients for the transfer.
/// </summary>
/// <param name="recipients">The recipients.</param>
/// <returns>This request for chaining.</returns>
public BatchTransferBalance SetRecipients(params TransferRecipient[]? recipients)
{
return SetVariable("recipients", CoreTypes.TransferRecipientArray, recipients);
}

/// <summary>
/// Sets the signing wallet for the transaction.
/// </summary>
/// <param name="signingAccount">The signing wallet account.</param>
/// <returns>This request for chaining.</returns>
/// <remarks>
/// The account defaults to wallet daemon if not specified.
/// </remarks>
public BatchTransferBalance SetSigningAccount(string? signingAccount)
{
return SetVariable("signingAccount", CoreTypes.String, signingAccount);
}
}

0 comments on commit b5747dc

Please sign in to comment.