Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optionnal parameter maxSupportedTransactionVersion to support ver… #428

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 99 additions & 99 deletions src/Solnet.Extensions/Models/TokenWallet/TokenQuantity.cs
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
using Solnet.Extensions.TokenMint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Solnet.Extensions
{
/// <summary>
/// Represents a token quantity of a known mint with a known number of decimal places.
/// </summary>
public class TokenQuantity
{

/// <summary>
/// Constructs a TokenQuantity instance.
/// </summary>
/// <param name="tokenDef">A TokenDef instance that describes this token.</param>
/// <param name="balanceDecimal">Token balance in decimal.</param>
/// <param name="balanceRaw">Token balance in raw ulong.</param>
internal TokenQuantity(TokenDef tokenDef,
decimal balanceDecimal,
ulong balanceRaw)
{
TokenDef = tokenDef ?? throw new ArgumentNullException(nameof(tokenDef));
Symbol = tokenDef.Symbol;
TokenName = tokenDef.TokenName;
TokenMint = tokenDef.TokenMint;
DecimalPlaces = tokenDef.DecimalPlaces;
QuantityDecimal = balanceDecimal;
QuantityRaw = balanceRaw;
}

/// <summary>
/// The origin TokenDef instance
/// </summary>
public TokenDef TokenDef { get; init; }

/// <summary>
/// The token mint public key address.
/// </summary>
public string TokenMint { get; init; }

/// <summary>
/// The symbol this token uses.
/// </summary>
public string Symbol { get; init; }

/// <summary>
/// The name of this token.
/// </summary>
public string TokenName { get; init; }

/// <summary>
/// The number of decimal places this token uses.
/// </summary>
public int DecimalPlaces { get; init; }

/// <summary>
/// Token balance in decimal.
/// </summary>
public decimal QuantityDecimal { get; init; }

/// <summary>
/// Token balance in raw ulong.
/// </summary>
public ulong QuantityRaw { get; init; }

/// <summary>
/// Provide a friendly to read balance with symbol and name.
/// </summary>
/// <returns></returns>
public override string ToString()
{
if (Symbol == TokenName)
return $"{QuantityDecimal} {Symbol}";
else
return $"{QuantityDecimal} {Symbol} ({TokenName})";
}

/// <summary>
/// Add the value of another TokenQuantity to this TokenQuantity.
/// </summary>
/// <param name="valueDecimal">Number of tokens as decimal to add to this TokenQuantity.</param>
/// <param name="valueRaw">Number of tokens as ulong to add to this TokenQuantity.</param>
/// <returns>A new instance with this TokenQuantity added to the accumulators.</returns>
internal TokenQuantity AddQuantity(decimal valueDecimal,
ulong valueRaw)
{

return new TokenQuantity(this.TokenDef,
QuantityDecimal + valueDecimal,
QuantityRaw + valueRaw);

}

}

using Solnet.Extensions.TokenMint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Solnet.Extensions
{
/// <summary>
/// Represents a token quantity of a known mint with a known number of decimal places.
/// </summary>
public class TokenQuantity
{
/// <summary>
/// Constructs a TokenQuantity instance.
/// </summary>
/// <param name="tokenDef">A TokenDef instance that describes this token.</param>
/// <param name="balanceDecimal">Token balance in decimal.</param>
/// <param name="balanceRaw">Token balance in raw ulong.</param>
internal TokenQuantity(TokenDef tokenDef,
decimal balanceDecimal,
ulong balanceRaw)
{
TokenDef = tokenDef ?? throw new ArgumentNullException(nameof(tokenDef));
Symbol = tokenDef.Symbol;
TokenName = tokenDef.TokenName;
TokenMint = tokenDef.TokenMint;
DecimalPlaces = tokenDef.DecimalPlaces;
QuantityDecimal = balanceDecimal;
QuantityRaw = balanceRaw;
}
/// <summary>
/// The origin TokenDef instance
/// </summary>
public TokenDef TokenDef { get; init; }
/// <summary>
/// The token mint public key address.
/// </summary>
public string TokenMint { get; init; }
/// <summary>
/// The symbol this token uses.
/// </summary>
public string Symbol { get; init; }
/// <summary>
/// The name of this token.
/// </summary>
public string TokenName { get; init; }
/// <summary>
/// The number of decimal places this token uses.
/// </summary>
public int DecimalPlaces { get; init; }
/// <summary>
/// Token balance in decimal.
/// </summary>
public decimal QuantityDecimal { get; init; }
/// <summary>
/// Token balance in raw ulong.
/// </summary>
public ulong QuantityRaw { get; init; }
/// <summary>
/// Provide a friendly to read balance with symbol and name.
/// </summary>
/// <returns></returns>
public override string ToString()
{
if (Symbol == TokenName)
return $"{QuantityDecimal.ToString(System.Globalization.CultureInfo.InvariantCulture)} {Symbol}";
else
return $"{QuantityDecimal.ToString(System.Globalization.CultureInfo.InvariantCulture)} {Symbol} ({TokenName})";
}
/// <summary>
/// Add the value of another TokenQuantity to this TokenQuantity.
/// </summary>
/// <param name="valueDecimal">Number of tokens as decimal to add to this TokenQuantity.</param>
/// <param name="valueRaw">Number of tokens as ulong to add to this TokenQuantity.</param>
/// <returns>A new instance with this TokenQuantity added to the accumulators.</returns>
internal TokenQuantity AddQuantity(decimal valueDecimal,
ulong valueRaw)
{
return new TokenQuantity(this.TokenDef,
QuantityDecimal + valueDecimal,
QuantityRaw + valueRaw);
}
}
}
30 changes: 22 additions & 8 deletions src/Solnet.Rpc/IRpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@ RequestResult<ResponseValue<AccountInfo>> GetAccountInfo(string pubKey, Commitme
/// </summary>
/// <param name="slot">The slot.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <param name="maxSupportedTransactionVersion">max supported transaction version</param>
/// <param name="transactionDetails">The level of transaction detail to return, see <see cref="TransactionDetailsFilterType"/>.</param>
/// <param name="blockRewards">Whether to populate the <c>rewards</c> array, the default includes rewards.</param>
/// <returns>Returns a task that holds the asynchronous operation result and state.</returns>
Task<RequestResult<BlockInfo>> GetBlockAsync(ulong slot, Commitment commitment = Commitment.Finalized,
Task<RequestResult<BlockInfo>> GetBlockAsync(ulong slot, Commitment commitment = Commitment.Finalized, int maxSupportedTransactionVersion = 0,
TransactionDetailsFilterType transactionDetails = TransactionDetailsFilterType.Full, bool blockRewards = false);

/// <summary>
Expand All @@ -152,12 +153,14 @@ Task<RequestResult<BlockInfo>> GetBlockAsync(ulong slot, Commitment commitment =
/// </summary>
/// <param name="slot">The slot.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <param name="maxSupportedTransactionVersion">max supported transaction version</param>
/// <param name="transactionDetails">The level of transaction detail to return, see <see cref="TransactionDetailsFilterType"/>.</param>
/// <param name="blockRewards">Whether to populate the <c>rewards</c> array, the default includes rewards.</param>
/// <returns>Returns a task that holds the asynchronous operation result and state.</returns>
[Obsolete("Please use GetBlockAsync whenever possible instead. This method is expected to be removed in solana-core v1.8.")]
Task<RequestResult<BlockInfo>> GetConfirmedBlockAsync(ulong slot, Commitment commitment = Commitment.Finalized,
TransactionDetailsFilterType transactionDetails = TransactionDetailsFilterType.Full, bool blockRewards = false);
int maxSupportedTransactionVersion = 0, TransactionDetailsFilterType transactionDetails = TransactionDetailsFilterType.Full,
bool blockRewards = false);

/// <summary>
/// Returns identity and transaction information about a block in the ledger.
Expand All @@ -176,11 +179,13 @@ Task<RequestResult<BlockInfo>> GetConfirmedBlockAsync(ulong slot, Commitment com
/// </summary>
/// <param name="slot">The slot.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <param name="maxSupportedTransactionVersion">max supported transaction version</param>
/// <param name="transactionDetails">The level of transaction detail to return, see <see cref="TransactionDetailsFilterType"/>.</param>
/// <param name="blockRewards">Whether to populate the <c>rewards</c> array, the default includes rewards.</param>
/// <returns>Returns an object that wraps the result along with possible errors with the request.</returns>
RequestResult<BlockInfo> GetBlock(ulong slot, Commitment commitment = Commitment.Finalized,
TransactionDetailsFilterType transactionDetails = TransactionDetailsFilterType.Full, bool blockRewards = false);
int maxSupportedTransactionVersion = 0, TransactionDetailsFilterType transactionDetails = TransactionDetailsFilterType.Full,
bool blockRewards = false);

/// <summary>
/// Returns identity and transaction information about a confirmed block in the ledger.
Expand All @@ -199,12 +204,14 @@ RequestResult<BlockInfo> GetBlock(ulong slot, Commitment commitment = Commitment
/// </summary>
/// <param name="slot">The slot.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <param name="maxSupportedTransactionVersion">max supported transaction version</param>
/// <param name="transactionDetails">The level of transaction detail to return, see <see cref="TransactionDetailsFilterType"/>.</param>
/// <param name="blockRewards">Whether to populate the <c>rewards</c> array, the default includes rewards.</param>
/// <returns>Returns an object that wraps the result along with possible errors with the request.</returns>
[Obsolete("Please use GetBlock whenever possible instead. This method is expected to be removed in solana-core v1.8.")]
RequestResult<BlockInfo> GetConfirmedBlock(ulong slot, Commitment commitment = Commitment.Finalized,
TransactionDetailsFilterType transactionDetails = TransactionDetailsFilterType.Full, bool blockRewards = false);
int maxSupportedTransactionVersion = 0, TransactionDetailsFilterType transactionDetails = TransactionDetailsFilterType.Full,
bool blockRewards = false);

/// <summary>
/// Gets the block commitment of a certain block, identified by slot.
Expand Down Expand Up @@ -1075,9 +1082,10 @@ Task<RequestResult<ResponseValue<TokenBalance>>> GetTokenSupplyAsync(string toke
/// </summary>
/// <param name="signature">Transaction signature as base-58 encoded string.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <param name="maxSupportedTransactionVersion">max supported transaction version</param>
/// <returns>Returns a task that holds the asynchronous operation result and state.</returns>
Task<RequestResult<TransactionMetaSlotInfo>> GetTransactionAsync(string signature,
Commitment commitment = Commitment.Finalized);
Commitment commitment = Commitment.Finalized, int maxSupportedTransactionVersion = 0);

/// <summary>
/// Returns transaction details for a confirmed transaction.
Expand All @@ -1089,10 +1097,12 @@ Task<RequestResult<TransactionMetaSlotInfo>> GetTransactionAsync(string signatur
/// </remarks>
/// </summary>
/// <param name="signature">Transaction signature as base-58 encoded string.</param>
/// <param name="maxSupportedTransactionVersion">max supported transaction version</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <returns>Returns an object that wraps the result along with possible errors with the request.</returns>
[Obsolete("Please use GetTransactionAsync whenever possible instead. This method is expected to be removed in solana-core v1.8.")]
Task<RequestResult<TransactionMetaSlotInfo>> GetConfirmedTransactionAsync(string signature, Commitment commitment = Commitment.Finalized);
Task<RequestResult<TransactionMetaSlotInfo>> GetConfirmedTransactionAsync(string signature, Commitment commitment = Commitment.Finalized,
int maxSupportedTransactionVersion = 0);

/// <summary>
/// Returns transaction details for a confirmed transaction.
Expand All @@ -1105,8 +1115,10 @@ Task<RequestResult<TransactionMetaSlotInfo>> GetTransactionAsync(string signatur
/// </summary>
/// <param name="signature">Transaction signature as base-58 encoded string.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <param name="maxSupportedTransactionVersion">max supported transaction version</param>
/// <returns>Returns an object that wraps the result along with possible errors with the request.</returns>
RequestResult<TransactionMetaSlotInfo> GetTransaction(string signature, Commitment commitment = Commitment.Finalized);
RequestResult<TransactionMetaSlotInfo> GetTransaction(string signature, Commitment commitment = Commitment.Finalized,
int maxSupportedTransactionVersion = 0);

/// <summary>
/// Returns transaction details for a confirmed transaction.
Expand All @@ -1119,9 +1131,11 @@ Task<RequestResult<TransactionMetaSlotInfo>> GetTransactionAsync(string signatur
/// </summary>
/// <param name="signature">Transaction signature as base-58 encoded string.</param>
/// <param name="commitment">The state commitment to consider when querying the ledger state.</param>
/// <param name="maxSupportedTransactionVersion">max supported transaction version</param>
/// <returns>Returns an object that wraps the result along with possible errors with the request.</returns>
[Obsolete("Please use GetTransaction whenever possible instead. This method is expected to be removed in solana-core v1.8.")]
RequestResult<TransactionMetaSlotInfo> GetConfirmedTransaction(string signature, Commitment commitment = Commitment.Finalized);
RequestResult<TransactionMetaSlotInfo> GetConfirmedTransaction(string signature, Commitment commitment = Commitment.Finalized,
int maxSupportedTransactionVersion = 0);

/// <summary>
/// Gets the total transaction count of the ledger.
Expand Down
41 changes: 41 additions & 0 deletions src/Solnet.Rpc/Models/AddressLookupTableState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Solnet.Wallet;
using System.Collections.Generic;

namespace Solnet.Rpc.Models
{
public class AddressLookupTableState
{
public long DeactivationSlot { get; set; }
public int LastExtendedSlot { get; set; }
public int LastExtendedSlowStartIndex { get ; set; }
public PublicKey Authority { get; set; }
public List<PublicKey> Addresses { get; set; }
}


public class AddressLookupTableAccount
{
private PublicKey _key;
private AddressLookupTableState _state;

public AddressLookupTableAccount(PublicKey key, AddressLookupTableState state)
{
_key = key;
_state = state;
}

public bool IsActive
{
get
{
return _state.DeactivationSlot == long.MaxValue;
}
}

public static AddressLookupTableState Deserialize(byte[] accountData)
{
var meta = DecodeData()
}

}
}
Loading
Loading