• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

bmresearch / Solnet / 8950601615

04 May 2024 12:47PM UTC coverage: 77.239% (-3.7%) from 80.902%
8950601615

push

github

web-flow
Update dotnet.yml

1123 of 1710 branches covered (65.67%)

Branch coverage included in aggregate %.

5199 of 6475 relevant lines covered (80.29%)

1304486.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.62
/src/Solnet.Rpc/Models/TransactionInstruction.cs
1
using Solnet.Rpc.Utilities;
2
using System;
3
using System.Collections.Generic;
4

5
namespace Solnet.Rpc.Models
6
{
7
    /// <summary>
8
    /// Represents a versioned transaction instruction before being compiled into the transaction's message.
9
    /// </summary>
10
    public class VersionedTransactionInstruction : TransactionInstruction
11
    {
12
        /// <summary>
13
        /// The keys associated with the instruction.
14
        /// </summary>
15
        public byte[] KeyIndices { get; init; }
×
16
    }
17
    /// <summary>
18
    /// Represents a transaction instruction before being compiled into the transaction's message.
19
    /// </summary>
20
    public class TransactionInstruction
21
    {
22
        /// <summary>
23
        /// The program ID associated with the instruction.
24
        /// </summary>
25
        public byte[] ProgramId { get; init; }
357✔
26

27
        /// <summary>
28
        /// The keys associated with the instruction.
29
        /// </summary>
30
        public IList<AccountMeta> Keys { get; init; }
561✔
31

32
        /// <summary>
33
        /// The instruction-specific data.
34
        /// </summary>
35
        public byte[] Data { get; init; }
354✔
36
    }
37

38
    /// <summary>
39
    /// A compiled instruction within the transaction's message.
40
    /// </summary>
41
    public class CompiledInstruction
42
    {
43
        #region Layout
44

45
        /// <summary>
46
        /// Represents the layout of the <see cref="CompiledInstruction"/> encoded values.
47
        /// </summary>
48
        internal static class Layout
49
        {
50
            /// <summary>
51
            /// The offset at which the program's id index value begins.
52
            /// </summary>
53
            internal const int ProgramIdIndexOffset = 0;
54
        }
55

56
        #endregion
57

58
        /// <summary>
59
        /// The index of the program's key in the transaction's account keys.
60
        /// </summary>
61
        public byte ProgramIdIndex { get; init; }
387✔
62

63
        /// <summary>
64
        /// The <see cref="ShortVectorEncoding"/> encoded length representing the number of key indices.
65
        /// </summary>
66
        public byte[] KeyIndicesCount { get; init; }
373✔
67

68
        /// <summary>
69
        /// The indices of the account keys for the instruction as they appear in the transaction.
70
        /// </summary>
71
        public byte[] KeyIndices { get; init; }
495✔
72

73
        /// <summary>
74
        /// The <see cref="ShortVectorEncoding"/> encoded length representing the number of key indices.
75
        /// </summary>
76
        public byte[] DataLength { get; init; }
351✔
77

78
        /// <summary>
79
        /// The instruction data.
80
        /// </summary>
81
        public byte[] Data { get; init; }
463✔
82

83
        /// <summary>
84
        /// Get the length of the compiled instruction.
85
        /// </summary>
86
        /// <returns>The length.</returns>
87
        internal int Length()
88
        {
89
            return 1 + KeyIndicesCount.Length + KeyIndices.Length + DataLength.Length + Data.Length;
77✔
90
        }
91

92
        /// <summary>
93
        /// Attempts to deserialize a compiled instruction from the given data.
94
        /// </summary>
95
        /// <param name="data">The data to deserialize.</param>
96
        public static (CompiledInstruction Instruction, int Length) Deserialize(ReadOnlySpan<byte> data)
97
        {
98
            int instructionLength = 0;
114✔
99
            // Read the programId index
100
            byte programIdIndex = data[Layout.ProgramIdIndexOffset];
114✔
101
            instructionLength += 1; // ProgramIdIndex is zero
114✔
102

103
            // Read the number of keys for the instruction
104
            ReadOnlySpan<byte> encodedKeyIndicesLength =
114✔
105
                data.Slice(instructionLength, ShortVectorEncoding.SpanLength);
114✔
106
            (int keyIndicesLength, int keyIndicesLengthEncodedLength) =
114✔
107
                ShortVectorEncoding.DecodeLength(encodedKeyIndicesLength);
114✔
108
            instructionLength += keyIndicesLengthEncodedLength;
114✔
109

110
            // Read the key indices for the instruction accounts
111
            byte[] keyIndices = new byte[keyIndicesLength];
114✔
112
            for (int j = 0; j < keyIndicesLength; j++)
1,008✔
113
            {
114
                keyIndices[j] = data[instructionLength];
390✔
115
                instructionLength++;
390✔
116
            }
117

118
            // Read the length of the instruction's data
119
            ReadOnlySpan<byte> encodedDataLength =
114✔
120
                data.Length > instructionLength + ShortVectorEncoding.SpanLength ?
114✔
121
                    data.Slice(instructionLength, ShortVectorEncoding.SpanLength)
114✔
122
                    : data.Slice(instructionLength, data.Length - instructionLength);
114✔
123

124
            (int dataLength, int dataLengthEncodedLength) = ShortVectorEncoding.DecodeLength(encodedDataLength);
114✔
125
            instructionLength += dataLengthEncodedLength;
114✔
126

127
            // Read the instruction data
128
            byte[] instructionEncodedData = data.Slice(instructionLength, dataLength).ToArray();
114✔
129
            instructionLength += dataLength;
114✔
130

131
            return (Instruction: new CompiledInstruction
114✔
132
            {
114✔
133
                ProgramIdIndex = programIdIndex,
114✔
134
                KeyIndicesCount = encodedKeyIndicesLength[..keyIndicesLengthEncodedLength].ToArray(),
114✔
135
                KeyIndices = keyIndices,
114✔
136
                DataLength = encodedDataLength[..dataLengthEncodedLength].ToArray(),
114✔
137
                Data = instructionEncodedData
114✔
138
            }, Length: instructionLength);
114✔
139
        }
140
    }
141
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc