solace 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18749af83cf5133c767914f6321a473a710caa5b5c3c613529af9547d6fcd079
4
- data.tar.gz: df4de15d443d6033ea92998f7af6450a0bbeae62b5eb389d86fa6ff839ee6f16
3
+ metadata.gz: 669a517f72b280a594613b55fcd3e86c6e0f7ef9ba3d6633b0edfbd5dc5b0a0c
4
+ data.tar.gz: a542d3ce4edaeb81d3c6e8aee35fadfb9df4a4cd5a618f9f643ac46544f4cc65
5
5
  SHA512:
6
- metadata.gz: 8e0aad6a855c4721363f353deeb46ecb68429995db8366f1f475ac98b25fe4caa2616b26f584316e0511e3f8ffb8e0fe7a22d97fea92e1904c6e70834d750477
7
- data.tar.gz: 47b02239af795269f2e287fe598961b265283a303ac4c37fff0f4f29b6758a60511794dd85a85809edd390580b0aee9590c49a3420c1e0b2610bed4903d05017
6
+ metadata.gz: c43a013d3007b0853a5501c96dc7b2e737b0aefa5d35844008127ddcdfd59c0770e4ceaf9db99086aa69c294ae20563b022b3d6e370be84701c9fe8a453ce25d
7
+ data.tar.gz: 42eab84e19bf00741e1c29a50facb39966f3020a005c2baa3ee63d545d6a43bcc267cb86d17ba09cb05be6d64875504c9a557275f9c365f6ce5764ce95501baf
data/CHANGELOG CHANGED
@@ -16,6 +16,28 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
16
16
  ### Fixed
17
17
  ```
18
18
 
19
+ ## [0.0.10] - yyyy-mm-dd
20
+
21
+ ### Added
22
+ 1.
23
+
24
+ ### Changed
25
+ 2. Updated `build_instructions` method on `TransactionComposer` to flatten the array, allowing composers to return multiple instructions when relevant (i.e. creating an account and then writing to it).
26
+ 3. Changed get_latest_blockhash to use the expected comittment level by the connection or passed options and return array (blockhash and lastValidBlockheight)
27
+ 4. Changed default commitment level to `processed` in `Solace::Connection`.
28
+
29
+ ### Fixed
30
+
31
+ ## [0.0.9] - 2025-08-12
32
+
33
+ ### Added
34
+ 1. Added `get_program_accounts` to `Solace::Connection`.
35
+
36
+ ### Changed
37
+
38
+ ### Fixed
39
+ 1. Removed use of the `try` method for supporting non-rails environments.
40
+
19
41
  ## [0.0.8] - 2025-08-11
20
42
 
21
43
  ### Added
@@ -27,7 +49,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
27
49
 
28
50
  ### Changed
29
51
  1. All methods that take a `Solace::Keypair` or `Solace::Pubkey` where an address is needed now also accept a plain string address. This prevents the need of creating instances of the classes when all that is needed is the address. This is with the exception of the low-level instruction builders, which only expect the correct data and indicies with no required casting.
30
- 2. Changed `wait_for_confirmed_signature` method to accept a `timeout`, `interval`, and `commitment` keyword arguments (breaking change on commitment).
52
+ 2. Changed `wait_for_confirmed_signature` method to accept a `timeout`, `interval`, and `commitment` arguments.
31
53
 
32
54
  ### Fixed
33
55
  1. Fixed `get_or_create_address` method in `Solace::Programs::AssociatedTokenAccount` to return the address of the associated token account if it already exists by checking if there is any data at the address.
data/README.md CHANGED
@@ -61,7 +61,7 @@ message = Solace::Message.new(
61
61
  system_program_id
62
62
  ],
63
63
  instructions: [transfer_instruction],
64
- recent_blockhash: connection.get_latest_blockhash,
64
+ recent_blockhash: connection.get_latest_blockhash[0],
65
65
  )
66
66
 
67
67
  # Create and sign transaction
@@ -51,7 +51,7 @@ module Solace
51
51
  # @param [Integer] http_read_timeout The timeout for reading an HTTP response
52
52
  def initialize(
53
53
  rpc_url = 'http://localhost:8899',
54
- commitment: 'confirmed',
54
+ commitment: 'processed',
55
55
  http_open_timeout: 30,
56
56
  http_read_timeout: 60
57
57
  )
@@ -69,23 +69,6 @@ module Solace
69
69
  }
70
70
  end
71
71
 
72
- # Sends a JSON-RPC request to the configured Solana RPC server.
73
- #
74
- # @param method [String] the JSON-RPC method name
75
- # @param params [Array] the parameters for the RPC method
76
- # @return [Hash] the parsed JSON response
77
- # @raise [
78
- # Solace::Errors::HTTPError,
79
- # Solace::Errors::ParseError,
80
- # Solace::Errors::RPCError,
81
- # Solace::Errors::ConfirmationTimeout
82
- # ]
83
- def rpc_request(method, params = [])
84
- request = build_rpc_request(method, params)
85
- response = perform_http_request(request)
86
- handle_rpc_response(response)
87
- end
88
-
89
72
  # Request an airdrop of lamports to a given address
90
73
  #
91
74
  # @param pubkey [String] The public key of the account to receive the airdrop
@@ -103,11 +86,23 @@ module Solace
103
86
  )
104
87
  end
105
88
 
89
+ # Build options for get_latest_blockhash
90
+ #
91
+ # @return [Hash{Symbol => Object}]
92
+ def build_get_latest_blockhash_options
93
+ {
94
+ commitment: default_options[:commitment]
95
+ }
96
+ end
97
+
106
98
  # Get the latest blockhash from the Solana node
107
99
  #
108
- # @return [String] The latest blockhash
100
+ # @return [Array<String, Integer>] The latest blockhash and lastValidBlockHeight
109
101
  def get_latest_blockhash
110
- @rpc_client.rpc_request('getLatestBlockhash').dig('result', 'value', 'blockhash')
102
+ @rpc_client
103
+ .rpc_request('getLatestBlockhash', [build_get_latest_blockhash_options])
104
+ .dig('result', 'value')
105
+ .values_at('blockhash', 'lastValidBlockHeight')
111
106
  end
112
107
 
113
108
  # Get the minimum required lamports for rent exemption
@@ -160,6 +155,16 @@ module Solace
160
155
  [signatures, default_options.merge({ 'searchTransactionHistory' => true })])['result']
161
156
  end
162
157
 
158
+ # Get the program accounts
159
+ #
160
+ # @param program_id [String] The program ID
161
+ # @param filters [Array] The filters
162
+ # @return [Array] The program accounts
163
+ # @param [Hash{Symbol => Object}] options
164
+ def get_program_accounts(program_id, filters)
165
+ @rpc_client.rpc_request('getProgramAccounts', [program_id, default_options.merge(filters: filters)])['result']
166
+ end
167
+
163
168
  # Get the signature status
164
169
  #
165
170
  # @param signature [String] The signature of the transaction
@@ -168,13 +173,26 @@ module Solace
168
173
  get_signature_statuses([signature])
169
174
  end
170
175
 
176
+ # Builds send_tranaction options
177
+ #
178
+ # @params [Hash] The overrides for the options
179
+ # @return [Hash] The options for the send_transaction call
180
+ def build_send_transaction_options(overrides)
181
+ {
182
+ skipPreflight: false,
183
+ encoding: default_options[:encoding],
184
+ commitment: default_options[:commitment],
185
+ preflightCommitment: default_options[:commitment]
186
+ }.merge(overrides)
187
+ end
188
+
171
189
  # Send a transaction to the Solana node
172
190
  #
173
191
  # @param transaction [Solace::Transaction] The transaction to send
192
+ # @param [Hash{Symbol => Object}] overrides
174
193
  # @return [String] The signature of the transaction
175
- # @param [Hash{Symbol => Object}] options
176
- def send_transaction(transaction, options = {})
177
- @rpc_client.rpc_request('sendTransaction', [transaction, default_options.merge(options)])
194
+ def send_transaction(transaction, overrides = {})
195
+ @rpc_client.rpc_request('sendTransaction', [transaction, build_send_transaction_options(overrides)])
178
196
  end
179
197
 
180
198
  # Wait until the yielded signature reaches the desired commitment or timeout.
@@ -1,5 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # The AssociatedTokenAccount program is a Solana program that provides a standardized way to create and manage token accounts.
4
+ #
5
+ # This class provides a Ruby interface to the Associated Token Account program, allowing you to easily
6
+ # find or create associated token accounts for a given wallet and mint.
7
+ #
8
+ # @see https://spl.solana.com/associated-token-account Solana Associated Token Account Program
9
+ #
10
+ # @author Sebastian Scholl
11
+ # @since 0.1.0
3
12
  module Solace
4
13
  module Programs
5
14
  # Client for interacting with the Associated Token Account Program.
@@ -106,20 +115,18 @@ module Solace
106
115
  )
107
116
  ata_address, = get_address(owner: owner, mint: mint)
108
117
 
109
- TransactionComposer.new(connection: connection).try do |tx_composer|
110
- tx_composer.set_fee_payer(payer)
111
-
112
- tx_composer.add_instruction(
113
- Solace::Composers::AssociatedTokenAccountProgramCreateAccountComposer.new(
114
- mint: mint,
115
- owner: owner,
116
- funder: payer,
117
- ata_address: ata_address
118
- )
119
- )
120
-
121
- tx_composer.compose_transaction
122
- end
118
+ ix = Solace::Composers::AssociatedTokenAccountProgramCreateAccountComposer.new(
119
+ mint: mint,
120
+ owner: owner,
121
+ funder: payer,
122
+ ata_address: ata_address
123
+ )
124
+
125
+ TransactionComposer
126
+ .new(connection: connection)
127
+ .set_fee_payer(payer)
128
+ .add_instruction(ix)
129
+ .compose_transaction
123
130
  end
124
131
  end
125
132
  end
@@ -95,7 +95,7 @@ module Solace
95
95
  message = Message.new(
96
96
  header: [2, 0, 3],
97
97
  accounts: accounts,
98
- recent_blockhash: @connection.get_latest_blockhash,
98
+ recent_blockhash: @connection.get_latest_blockhash[0],
99
99
  instructions: [create_account_ix, initialize_mint_ix]
100
100
  )
101
101
 
@@ -153,7 +153,7 @@ module Solace
153
153
  header: [2, 0, 1],
154
154
  accounts: accounts,
155
155
  instructions: [ix],
156
- recent_blockhash: connection.get_latest_blockhash
156
+ recent_blockhash: connection.get_latest_blockhash[0]
157
157
  )
158
158
 
159
159
  tx = Solace::Transaction.new(message: message)
@@ -210,7 +210,7 @@ module Solace
210
210
  header: [2, 0, 1],
211
211
  accounts: accounts,
212
212
  instructions: [ix],
213
- recent_blockhash: connection.get_latest_blockhash
213
+ recent_blockhash: connection.get_latest_blockhash[0]
214
214
  )
215
215
 
216
216
  tx = Solace::Transaction.new(message: message)
@@ -90,7 +90,7 @@ module Solace
90
90
  header: context.header,
91
91
  accounts: context.accounts,
92
92
  instructions: build_instructions,
93
- recent_blockhash: connection.get_latest_blockhash
93
+ recent_blockhash: connection.get_latest_blockhash[0]
94
94
  )
95
95
 
96
96
  Solace::Transaction.new(message: message)
@@ -102,7 +102,7 @@ module Solace
102
102
  #
103
103
  # @return [Array<Solace::Instruction>] The built instructions
104
104
  def build_instructions
105
- instruction_composers.map { _1.build_instruction(context) }
105
+ instruction_composers.map { _1.build_instruction(context) }.flatten
106
106
  end
107
107
 
108
108
  # Merge all accounts from another AccountContext into this one
@@ -105,7 +105,7 @@ module Solace
105
105
  # @param pubkey [String] The pubkey of the account
106
106
  # @return [Boolean] Whether the account is a fee payer
107
107
  def fee_payer?(pubkey)
108
- @pubkey_account_map[pubkey].try { |acc| acc[:fee_payer] }
108
+ @pubkey_account_map.dig(pubkey, :fee_payer)
109
109
  end
110
110
 
111
111
  # Predicate to check if an account is a signer
@@ -113,7 +113,7 @@ module Solace
113
113
  # @param pubkey [String] The pubkey of the account
114
114
  # @return [Boolean] Whether the account is a signer
115
115
  def signer?(pubkey)
116
- @pubkey_account_map[pubkey].try { |acc| acc[:signer] }
116
+ @pubkey_account_map.dig(pubkey, :signer)
117
117
  end
118
118
 
119
119
  # Predicate to check if an account is writable
@@ -121,7 +121,7 @@ module Solace
121
121
  # @param pubkey [String] The pubkey of the account
122
122
  # @return [Boolean] Whether the account is writable
123
123
  def writable?(pubkey)
124
- @pubkey_account_map[pubkey].try { |acc| acc[:writable] }
124
+ @pubkey_account_map.dig(pubkey, :writable)
125
125
  end
126
126
 
127
127
  # Predicate to check if an account is a writable signer
@@ -129,7 +129,7 @@ module Solace
129
129
  # @param pubkey [String] The pubkey of the account
130
130
  # @return [Boolean] Whether the account is a writable signer
131
131
  def writable_signer?(pubkey)
132
- @pubkey_account_map[pubkey].try { |acc| acc[:signer] && acc[:writable] }
132
+ (acc = @pubkey_account_map[pubkey]) && acc[:signer] && acc[:writable]
133
133
  end
134
134
 
135
135
  # Predicate to check if an account is writable and not a signer
@@ -137,7 +137,7 @@ module Solace
137
137
  # @param pubkey [String] The pubkey of the account
138
138
  # @return [Boolean] Whether the account is writable and not a signer
139
139
  def writable_nonsigner?(pubkey)
140
- @pubkey_account_map[pubkey].try { |acc| !acc[:signer] && acc[:writable] }
140
+ (acc = @pubkey_account_map[pubkey]) && !acc[:signer] && acc[:writable]
141
141
  end
142
142
 
143
143
  # Predicate to check if an account is a readonly signer
@@ -145,7 +145,7 @@ module Solace
145
145
  # @param pubkey [String] The pubkey of the account
146
146
  # @return [Boolean] Whether the account is a readonly signer
147
147
  def readonly_signer?(pubkey)
148
- @pubkey_account_map[pubkey].try { |acc| acc[:signer] && !acc[:writable] }
148
+ (acc = @pubkey_account_map[pubkey]) && acc[:signer] && !acc[:writable]
149
149
  end
150
150
 
151
151
  # Predicate to check if an account is readonly and not a signer
@@ -153,7 +153,7 @@ module Solace
153
153
  # @param pubkey [String] The pubkey of the account
154
154
  # @return [Boolean] Whether the account is readonly and not a signer
155
155
  def readonly_nonsigner?(pubkey)
156
- @pubkey_account_map[pubkey].try { |acc| !acc[:signer] && !acc[:writable] }
156
+ (acc = @pubkey_account_map[pubkey]) && !acc[:signer] && !acc[:writable]
157
157
  end
158
158
 
159
159
  # Merge all accounts from another AccountContext into this one
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Solace::VERSION is the version of the Solace gem
4
4
  module Solace
5
- VERSION = '0.0.8'
5
+ VERSION = '0.0.10'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Scholl