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

bmresearch / Solnet / 10672350157

02 Sep 2024 07:46PM UTC coverage: 77.453% (+0.2%) from 77.239%
10672350157

push

github

BifrostTitan
Agave v2.0 Migration

Updated the RPC client and removed deprecated code from the SDK.
Cleaned up all the warnings across the solution and added a few sys-vars that were missing.
Generate Seed in Mnemonic class now uses System.Security.Cryptography instead of bouncy castle sdk

1111 of 1682 branches covered (66.05%)

Branch coverage included in aggregate %.

6 of 10 new or added lines in 6 files covered. (60.0%)

18 existing lines in 4 files now uncovered.

5117 of 6359 relevant lines covered (80.47%)

1328281.27 hits per line

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

0.0
/src/Solnet.Rpc/Builders/VersionedMessageBuilder.cs
1
using Solnet.Rpc.Models;
2
using Solnet.Rpc.Utilities;
3
using Solnet.Wallet;
4
using Solnet.Wallet.Utilities;
5
using System;
6
using System.Collections.Generic;
7
using System.IO;
8
using System.Linq;
9
using static Solnet.Rpc.Models.Message;
10

11
namespace Solnet.Rpc.Builders
12
{
13
    /// <summary>
14
    /// A compiled instruction within the message.
15
    /// </summary>
16
    public class VersionedMessageBuilder : MessageBuilder
17
    {
18

19
        /// <summary>
20
        /// Address Table Lookups
21
        /// </summary>
22
        public List<MessageAddressTableLookup> AddressTableLookups { get; set; }
×
23
        /// <summary>
24
        /// Account Keys
25
        /// </summary>
UNCOV
26
        public IList<PublicKey> AccountKeys { get; internal set; }
×
27

28
        /// <summary>
29
        /// Builds the message into the wire format.
30
        /// </summary>
31
        /// <returns>The encoded message.</returns>
32
        internal override byte[] Build()
33
        {
34
            if (RecentBlockHash == null && NonceInformation == null)
×
35
                throw new Exception("recent block hash or nonce information is required");
×
36
            if (Instructions == null)
×
37
                throw new Exception("no instructions provided in the transaction");
×
38

39
            // In case the user specified nonce information, we'll use it.
40
            if (NonceInformation != null)
×
41
            {
42
                RecentBlockHash = NonceInformation.Nonce;
×
43
                _accountKeysList.Add(NonceInformation.Instruction.Keys);
×
44
                _accountKeysList.Add(AccountMeta.ReadOnly(new PublicKey(NonceInformation.Instruction.ProgramId),
×
45
                    false));
×
46
                List<TransactionInstruction> newInstructions = new() { NonceInformation.Instruction };
×
47
                newInstructions.AddRange(Instructions);
×
48
                Instructions = newInstructions;
×
49
            }
50

51
            _messageHeader = new MessageHeader();
×
52

53
            List<AccountMeta> keysList = GetAccountKeys();
×
54
            byte[] accountAddressesLength = ShortVectorEncoding.EncodeLength(keysList.Count);
×
55
            int compiledInstructionsLength = 0;
×
56
            List<CompiledInstruction> compiledInstructions = new();
×
57

58
            foreach (TransactionInstruction instruction in Instructions)
×
59
            {
60
                int keyCount = instruction.Keys.Count;
×
61
                byte[] keyIndices = new byte[keyCount];
×
62

63
                if (instruction.GetType() == typeof(VersionedTransactionInstruction))
×
64
                {
65
                    keyIndices = ((VersionedTransactionInstruction)instruction).KeyIndices;
×
66
                }
67
                else
68
                {
69
                    for (int i = 0; i < keyCount; i++)
×
70
                    {
71
                        keyIndices[i] = FindAccountIndex(keysList, instruction.Keys[i].PublicKey);
×
72
                    }
73
                }
74

75
                CompiledInstruction compiledInstruction = new()
×
76
                {
×
77
                    ProgramIdIndex = FindAccountIndex(keysList, instruction.ProgramId),
×
78
                    KeyIndicesCount = ShortVectorEncoding.EncodeLength(keyIndices.Length),
×
79
                    KeyIndices = keyIndices,
×
80
                    DataLength = ShortVectorEncoding.EncodeLength(instruction.Data.Length),
×
81
                    Data = instruction.Data
×
82
                };
×
83
                compiledInstructions.Add(compiledInstruction);
×
84
                compiledInstructionsLength += compiledInstruction.Length();
×
85
            }
86

87
            int accountKeysBufferSize = _accountKeysList.AccountList.Count * 32;
×
88
            MemoryStream accountKeysBuffer = new MemoryStream(accountKeysBufferSize);
×
89
            byte[] instructionsLength = ShortVectorEncoding.EncodeLength(compiledInstructions.Count);
×
90

91
            foreach (AccountMeta accountMeta in keysList)
×
92
            {
93
                accountKeysBuffer.Write(accountMeta.PublicKeyBytes, 0, accountMeta.PublicKeyBytes.Length);
×
94
                if (accountMeta.IsSigner)
×
95
                {
96
                    _messageHeader.RequiredSignatures += 1;
×
97
                    if (!accountMeta.IsWritable)
×
98
                        _messageHeader.ReadOnlySignedAccounts += 1;
×
99
                }
100
                else
101
                {
102
                    if (!accountMeta.IsWritable)
×
103
                        _messageHeader.ReadOnlyUnsignedAccounts += 1;
×
104
                }
105
            }
106

107
            #region Build Message Body
108

109
            int messageBufferSize = MessageHeader.Layout.HeaderLength + BlockHashLength +
×
110
                                    accountAddressesLength.Length +
×
111
                                    +instructionsLength.Length + compiledInstructionsLength + accountKeysBufferSize;
×
112
            MemoryStream buffer = new MemoryStream(messageBufferSize);
×
113
            byte[] messageHeaderBytes = _messageHeader.ToBytes();
×
114

115
            buffer.Write(new byte[] { 128 }, 0, 1);
×
116
            buffer.Write(messageHeaderBytes, 0, messageHeaderBytes.Length);
×
117
            buffer.Write(accountAddressesLength, 0, accountAddressesLength.Length);
×
118
            buffer.Write(accountKeysBuffer.ToArray(), 0, accountKeysBuffer.ToArray().Length);
×
119
            var encodedRecentBlockHash = Encoders.Base58.DecodeData(RecentBlockHash);
×
120
            buffer.Write(encodedRecentBlockHash, 0, encodedRecentBlockHash.Length);
×
121
            buffer.Write(instructionsLength, 0, instructionsLength.Length);
×
122

123
            foreach (CompiledInstruction compiledInstruction in compiledInstructions)
×
124
            {
125
                buffer.WriteByte(compiledInstruction.ProgramIdIndex);
×
126
                buffer.Write(compiledInstruction.KeyIndicesCount, 0, compiledInstruction.KeyIndicesCount.Length);
×
127
                buffer.Write(compiledInstruction.KeyIndices, 0, compiledInstruction.KeyIndices.Length);
×
128
                buffer.Write(compiledInstruction.DataLength, 0, compiledInstruction.DataLength.Length);
×
129
                buffer.Write(compiledInstruction.Data, 0, compiledInstruction.Data.Length);
×
130
            }
131

132
            #endregion
133

134
            var serializeAddressTableLookups = AddressTableLookupUtils.SerializeAddressTableLookups(AddressTableLookups);
×
135
            buffer.Write(serializeAddressTableLookups, 0, serializeAddressTableLookups.Length);
×
136

137
            return buffer.ToArray();
×
138
        }
139
    }
140
}
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

© 2025 Coveralls, Inc