Skip to content

Commit

Permalink
Add maxSupportedTransactionVersion parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
b0l0k committed Aug 5, 2023
1 parent 1870959 commit 9fcb5e7
Show file tree
Hide file tree
Showing 12 changed files with 974 additions and 30 deletions.
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()
}

}
}
136 changes: 136 additions & 0 deletions src/Solnet.Rpc/Models/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public class TransactionMetaSlotInfo : TransactionMetaInfo
/// Estimated block production time.
/// </summary>
public long? BlockTime { get; set; }

/// <summary>
/// Transaction version
/// </summary>
/// <value></value>
public object Version { get ;set; }
}


Expand Down Expand Up @@ -179,6 +185,12 @@ public class TransactionContentInfo
/// List of program instructions that will be executed in sequence and committed in one atomic transaction if all succeed.
/// </summary>
public InstructionInfo[] Instructions { get; set; }

/// <summary>
/// Addresses table lookup
/// </summary>
/// <value></value>
public MessageAddressTableLookup[] AddressTableLookup { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -247,6 +259,12 @@ public class TransactionMeta
/// Array of string log messages or omitted if log message recording was not yet enabled during this transaction.
/// </summary>
public string[] LogMessages { get; set; }

/// <summary>
/// Transaction loaded addresses
/// </summary>
/// <value></value>
public AccountKeysFromLookups LoadedAddresses { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -382,4 +400,122 @@ public class LatestBlockHash
/// </summary>
public ulong LastValidBlockHeight { get; set; }
}

/// <summary>
/// Represents the block info.
/// </summary>
public class BlockVersionedInfo
{
/// <summary>
/// Estimated block production time.
/// </summary>
public long BlockTime { get; set; }

/// <summary>
/// A base-58 encoded public key representing the block hash.
/// </summary>
public string Blockhash { get; set; }

/// <summary>
/// A base-58 encoded public key representing the block hash of this block's parent.
/// <remarks>
/// If the parent block is no longer available due to ledger cleanup, this field will return
/// '11111111111111111111111111111111'
/// </remarks>
/// </summary>
public string PreviousBlockhash { get; set; }

/// <summary>
/// The slot index of this block's parent.
/// </summary>
public ulong ParentSlot { get; set; }

/// <summary>
/// The number of blocks beneath this block.
/// </summary>
public long? BlockHeight { get; set; }

/// <summary>
/// The rewards for this given block.
/// </summary>
public RewardInfo[] Rewards { get; set; }

/// <summary>
/// Collection of transactions and their metadata within this block.
/// </summary>
public TransactionMetaInfo[] Transactions { get; set; }
}

/// <summary>
/// Represents the transaction, metadata and its containing slot.
/// </summary>
public class TransactionMetaSlotVersionedInfo : TransactionMetaVersionedInfo
{
/// <summary>
/// The slot this transaction was processed in.
/// </summary>
public ulong Slot { get; set; }

/// <summary>
/// Estimated block production time.
/// </summary>
public long? BlockTime { get; set; }
}


/// <summary>
/// Represents the tuple transaction and metadata.
/// </summary>
public class TransactionMetaVersionedInfo
{
/// <summary>
/// The transaction information.
/// </summary>
public TransactionVersionedInfo Transaction { get; set; }

/// <summary>
/// The metadata information.
/// </summary>
public TransactionVersionedMeta Meta { get; set; }
}

/// <summary>
/// Represents a transaction.
/// </summary>
public class TransactionVersionedInfo
{
/// <summary>
/// The signatures of this transaction.
/// </summary>
public string[] Signatures { get; set; }

/// <summary>
/// The message contents of the transaction.
/// </summary>
public TransactionContentVersionedInfo Message { get; set; }
}

/// <summary>
/// Represents the contents of the trasaction.
/// </summary>
public class TransactionContentVersionedInfo: TransactionContentInfo
{
/// <summary>
/// Address table lookup for transaction
/// </summary>
/// <value></value>
public MessageAddressTableLookup[] AddressTableLookups { get; set; }
}

/// <summary>
/// Represents the transaction metadata.
/// </summary>
public class TransactionVersionedMeta: TransactionMeta
{
/// <summary>
/// Loaded address for the tranasaction
/// </summary>
/// <value></value>
public AccountKeysFromLookups LoadedAddresses { get; set; }
}
}
55 changes: 55 additions & 0 deletions src/Solnet.Rpc/Models/MessageAccountKeys.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Solnet.Wallet;
using System.Collections.Generic;
using System.Linq;

namespace Solnet.Rpc.Models
{
/// <summary>
/// A wrapper around a list of <see cref="AccountMeta"/>s that takes care of deduplication and ordering according to
/// the wire format specification.
/// </summary>
internal class MessageAccountKeys
{
/// <summary>
/// The static account metas list.
/// </summary>
private readonly List<PublicKey> _staticAccounts;

private AccountKeysFromLookups _accountKeysFromLookups;


internal List<PublicKey> KeySegments
{
get
{
var segments = _staticAccounts.ToList();
if (_accountKeysFromLookups != null)
{
segments.AddRange(_accountKeysFromLookups.Writables);
segments.AddRange(_accountKeysFromLookups.Readonly);
}

return segments;
}
}

/// <summary>
/// Initialize the account keys list for use within transaction building.
/// </summary>
internal MessageAccountKeys(List<PublicKey> staticAccounts, AccountKeysFromLookups accountKeysFromLookups = null)
{
_staticAccounts = staticAccounts;
_accountKeysFromLookups = accountKeysFromLookups;
}

public PublicKey Get(int index)
{
if (index < KeySegments.Count)
{
return KeySegments[index];
}

return null;
}
}
}
Loading

0 comments on commit 9fcb5e7

Please sign in to comment.