solana-ruby-kit 7.1.1 → 7.1.1.2
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 +4 -4
- data/lib/solana/ruby/kit/codecs/bytes.rb +5 -1
- data/lib/solana/ruby/kit/codecs/data_structures.rb +5 -1
- data/lib/solana/ruby/kit/codecs/numbers.rb +5 -1
- data/lib/solana/ruby/kit/codecs/strings.rb +5 -1
- data/lib/solana/ruby/kit/codecs.rb +3 -1
- data/lib/solana/ruby/kit/errors.rb +2 -0
- data/lib/solana/ruby/kit/functional.rb +1 -1
- data/lib/solana/ruby/kit/instruction_plans/instruction_plan.rb +13 -1
- data/lib/solana/ruby/kit/instruction_plans/transaction_plan.rb +9 -0
- data/lib/solana/ruby/kit/instruction_plans/transaction_plan_executor.rb +13 -3
- data/lib/solana/ruby/kit/instruction_plans/transaction_plan_result.rb +18 -0
- data/lib/solana/ruby/kit/instruction_plans/transaction_planner.rb +24 -2
- data/lib/solana/ruby/kit/rpc/api/get_account_info.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_balance.rb +4 -0
- data/lib/solana/ruby/kit/rpc/api/get_block_height.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_block_time.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_epoch_info.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_epoch_schedule.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_inflation_reward.rb +6 -1
- data/lib/solana/ruby/kit/rpc/api/get_latest_blockhash.rb +4 -0
- data/lib/solana/ruby/kit/rpc/api/get_minimum_balance_for_rent_exemption.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_multiple_accounts.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_program_accounts.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_signature_statuses.rb +4 -0
- data/lib/solana/ruby/kit/rpc/api/get_signatures_for_address.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_slot.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_token_account_balance.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_token_accounts_by_owner.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_token_supply.rb +43 -0
- data/lib/solana/ruby/kit/rpc/api/get_transaction.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_transactions_for_address.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/get_vote_accounts.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/has_transport.rb +25 -0
- data/lib/solana/ruby/kit/rpc/api/is_blockhash_valid.rb +4 -0
- data/lib/solana/ruby/kit/rpc/api/request_airdrop.rb +4 -0
- data/lib/solana/ruby/kit/rpc/api/send_transaction.rb +5 -0
- data/lib/solana/ruby/kit/rpc/api/simulate_transaction.rb +5 -0
- data/lib/solana/ruby/kit/rpc/client.rb +6 -1
- data/lib/solana/ruby/kit/rpc_subscriptions/api/account_notifications.rb +5 -0
- data/lib/solana/ruby/kit/rpc_subscriptions/api/has_transport.rb +35 -0
- data/lib/solana/ruby/kit/rpc_subscriptions/api/logs_notifications.rb +5 -0
- data/lib/solana/ruby/kit/rpc_subscriptions/api/program_notifications.rb +5 -0
- data/lib/solana/ruby/kit/rpc_subscriptions/api/root_notifications.rb +5 -0
- data/lib/solana/ruby/kit/rpc_subscriptions/api/signature_notifications.rb +5 -0
- data/lib/solana/ruby/kit/rpc_subscriptions/api/slot_notifications.rb +5 -0
- data/lib/solana/ruby/kit/rpc_subscriptions/client.rb +5 -2
- data/lib/solana/ruby/kit/rpc_types/sol.rb +8 -6
- data/lib/solana/ruby/kit/subscribable/reactive_action_store.rb +6 -6
- data/lib/solana/ruby/kit/subscribable/reactive_stream_store.rb +4 -4
- data/lib/solana/ruby/kit/transaction_messages/compute_budget.rb +4 -4
- data/lib/solana/ruby/kit/version.rb +1 -1
- data/lib/solana/ruby/kit/wallet_standard.rb +4 -4
- data/solana-ruby-kit.gemspec +6 -0
- metadata +24 -3
- data/lib/core_extensions/tapioca/name_patch.rb +0 -32
- data/lib/core_extensions/tapioca/required_ancestors.rb +0 -13
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
module Solana::Ruby::Kit
|
|
5
7
|
module Rpc
|
|
6
8
|
module Api
|
|
@@ -8,6 +10,9 @@ module Solana::Ruby::Kit
|
|
|
8
10
|
# Mirrors TypeScript's `GetSlotApi.getSlot()`.
|
|
9
11
|
module GetSlot
|
|
10
12
|
extend T::Sig
|
|
13
|
+
extend T::Helpers
|
|
14
|
+
|
|
15
|
+
requires_ancestor { HasTransport }
|
|
11
16
|
|
|
12
17
|
sig do
|
|
13
18
|
params(
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
module Solana::Ruby::Kit
|
|
5
7
|
module Rpc
|
|
6
8
|
module Api
|
|
@@ -8,6 +10,9 @@ module Solana::Ruby::Kit
|
|
|
8
10
|
# Mirrors TypeScript's GetTokenAccountBalanceApi.getTokenAccountBalance.
|
|
9
11
|
module GetTokenAccountBalance
|
|
10
12
|
extend T::Sig
|
|
13
|
+
extend T::Helpers
|
|
14
|
+
|
|
15
|
+
requires_ancestor { HasTransport }
|
|
11
16
|
|
|
12
17
|
sig do
|
|
13
18
|
params(
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
module Solana::Ruby::Kit
|
|
5
7
|
module Rpc
|
|
6
8
|
module Api
|
|
@@ -10,6 +12,9 @@ module Solana::Ruby::Kit
|
|
|
10
12
|
# { 'programId' => program_id }
|
|
11
13
|
module GetTokenAccountsByOwner
|
|
12
14
|
extend T::Sig
|
|
15
|
+
extend T::Helpers
|
|
16
|
+
|
|
17
|
+
requires_ancestor { HasTransport }
|
|
13
18
|
|
|
14
19
|
sig do
|
|
15
20
|
params(
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
6
|
+
module Solana::Ruby::Kit
|
|
7
|
+
module Rpc
|
|
8
|
+
module Api
|
|
9
|
+
# Fetch the total supply of an SPL Token mint.
|
|
10
|
+
# Mirrors TypeScript's GetTokenSupplyApi.getTokenSupply.
|
|
11
|
+
module GetTokenSupply
|
|
12
|
+
extend T::Sig
|
|
13
|
+
extend T::Helpers
|
|
14
|
+
|
|
15
|
+
requires_ancestor { HasTransport }
|
|
16
|
+
|
|
17
|
+
sig do
|
|
18
|
+
params(
|
|
19
|
+
token_mint: String,
|
|
20
|
+
commitment: T.nilable(Symbol)
|
|
21
|
+
).returns(RpcTypes::RpcContextualValue)
|
|
22
|
+
end
|
|
23
|
+
def get_token_supply(token_mint, commitment: nil)
|
|
24
|
+
config = {}
|
|
25
|
+
config['commitment'] = commitment.to_s if commitment
|
|
26
|
+
|
|
27
|
+
result = transport.request('getTokenSupply', [token_mint, config].tap { |a| a.pop if a.last.empty? })
|
|
28
|
+
slot = Kernel.Integer(result['context']['slot'])
|
|
29
|
+
raw = result['value']
|
|
30
|
+
|
|
31
|
+
value = {
|
|
32
|
+
amount: raw['amount'],
|
|
33
|
+
decimals: Kernel.Integer(raw['decimals']),
|
|
34
|
+
ui_amount: raw['uiAmount'],
|
|
35
|
+
ui_amount_string: raw['uiAmountString']
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
RpcTypes::RpcContextualValue.new(slot: slot, value: value)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
module Solana::Ruby::Kit
|
|
5
7
|
module Rpc
|
|
6
8
|
module Api
|
|
@@ -9,6 +11,9 @@ module Solana::Ruby::Kit
|
|
|
9
11
|
# Returns the raw JSON hash (nil if not found / not yet confirmed).
|
|
10
12
|
module GetTransaction
|
|
11
13
|
extend T::Sig
|
|
14
|
+
extend T::Helpers
|
|
15
|
+
|
|
16
|
+
requires_ancestor { HasTransport }
|
|
12
17
|
|
|
13
18
|
sig do
|
|
14
19
|
params(
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
module Solana::Ruby::Kit
|
|
5
7
|
module Rpc
|
|
6
8
|
module Api
|
|
@@ -54,6 +56,9 @@ module Solana::Ruby::Kit
|
|
|
54
56
|
# See https://solana.com/docs/rpc/http/gettransactionsforaddress
|
|
55
57
|
module GetTransactionsForAddress
|
|
56
58
|
extend T::Sig
|
|
59
|
+
extend T::Helpers
|
|
60
|
+
|
|
61
|
+
requires_ancestor { HasTransport }
|
|
57
62
|
|
|
58
63
|
# Maps the snake_case keys of a Ruby +filters+ hash onto the wire names.
|
|
59
64
|
# Comparison operators (:eq, :gt, :gte, :lt, :lte) pass through as-is.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
module Solana::Ruby::Kit
|
|
5
7
|
module Rpc
|
|
6
8
|
module Api
|
|
@@ -25,6 +27,9 @@ module Solana::Ruby::Kit
|
|
|
25
27
|
# Returns { current: [], delinquent: [] }.
|
|
26
28
|
module GetVoteAccounts
|
|
27
29
|
extend T::Sig
|
|
30
|
+
extend T::Helpers
|
|
31
|
+
|
|
32
|
+
requires_ancestor { HasTransport }
|
|
28
33
|
|
|
29
34
|
sig do
|
|
30
35
|
params(
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Solana::Ruby::Kit
|
|
5
|
+
module Rpc
|
|
6
|
+
module Api
|
|
7
|
+
# Interface supplying the JSON-RPC connection that every API mixin uses.
|
|
8
|
+
#
|
|
9
|
+
# The mixins in this namespace are not usable on their own — each one
|
|
10
|
+
# issues its request through `transport`, which is provided by the object
|
|
11
|
+
# they are mixed into (`Rpc::Client`). Declaring that requirement here,
|
|
12
|
+
# and having each mixin `requires_ancestor { HasTransport }`, lets Sorbet
|
|
13
|
+
# resolve `transport` inside the mixins instead of reporting it missing.
|
|
14
|
+
module HasTransport
|
|
15
|
+
extend T::Sig
|
|
16
|
+
extend T::Helpers
|
|
17
|
+
interface!
|
|
18
|
+
|
|
19
|
+
# The HTTP connection used to issue JSON-RPC requests.
|
|
20
|
+
sig { abstract.returns(Transport) }
|
|
21
|
+
def transport; end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
4
5
|
require_relative '../../rpc_types/account_info'
|
|
5
6
|
|
|
6
7
|
module Solana::Ruby::Kit
|
|
@@ -14,6 +15,9 @@ module Solana::Ruby::Kit
|
|
|
14
15
|
# .value — Boolean
|
|
15
16
|
module IsBlockhashValid
|
|
16
17
|
extend T::Sig
|
|
18
|
+
extend T::Helpers
|
|
19
|
+
|
|
20
|
+
requires_ancestor { HasTransport }
|
|
17
21
|
|
|
18
22
|
sig do
|
|
19
23
|
params(
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
4
5
|
require_relative '../../keys/signatures'
|
|
5
6
|
|
|
6
7
|
module Solana::Ruby::Kit
|
|
@@ -13,6 +14,9 @@ module Solana::Ruby::Kit
|
|
|
13
14
|
# Returns the transaction `Signature` of the airdrop.
|
|
14
15
|
module RequestAirdrop
|
|
15
16
|
extend T::Sig
|
|
17
|
+
extend T::Helpers
|
|
18
|
+
|
|
19
|
+
requires_ancestor { HasTransport }
|
|
16
20
|
|
|
17
21
|
sig do
|
|
18
22
|
params(
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
require 'base64'
|
|
5
7
|
require_relative '../../keys/signatures'
|
|
6
8
|
require_relative '../../transactions/compiler'
|
|
@@ -21,6 +23,9 @@ module Solana::Ruby::Kit
|
|
|
21
23
|
# NOT wait for confirmation. Use `get_signature_statuses` to poll for commitment.
|
|
22
24
|
module SendTransaction
|
|
23
25
|
extend T::Sig
|
|
26
|
+
extend T::Helpers
|
|
27
|
+
|
|
28
|
+
requires_ancestor { HasTransport }
|
|
24
29
|
|
|
25
30
|
sig do
|
|
26
31
|
params(
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
module Solana::Ruby::Kit
|
|
5
7
|
module Rpc
|
|
6
8
|
module Api
|
|
@@ -9,6 +11,9 @@ module Solana::Ruby::Kit
|
|
|
9
11
|
# Returns an RpcContextualValue whose value is the simulation result hash.
|
|
10
12
|
module SimulateTransaction
|
|
11
13
|
extend T::Sig
|
|
14
|
+
extend T::Helpers
|
|
15
|
+
|
|
16
|
+
requires_ancestor { HasTransport }
|
|
12
17
|
|
|
13
18
|
sig do
|
|
14
19
|
params(
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require_relative 'transport'
|
|
5
|
+
require_relative 'api/has_transport'
|
|
5
6
|
require_relative 'api/get_slot'
|
|
6
7
|
require_relative 'api/get_balance'
|
|
7
8
|
require_relative 'api/get_latest_blockhash'
|
|
@@ -17,6 +18,7 @@ require_relative 'api/get_program_accounts'
|
|
|
17
18
|
require_relative 'api/get_transaction'
|
|
18
19
|
require_relative 'api/get_token_account_balance'
|
|
19
20
|
require_relative 'api/get_token_accounts_by_owner'
|
|
21
|
+
require_relative 'api/get_token_supply'
|
|
20
22
|
require_relative 'api/get_epoch_info'
|
|
21
23
|
require_relative 'api/get_vote_accounts'
|
|
22
24
|
require_relative 'api/simulate_transaction'
|
|
@@ -43,6 +45,8 @@ module Solana::Ruby::Kit
|
|
|
43
45
|
class Client
|
|
44
46
|
extend T::Sig
|
|
45
47
|
|
|
48
|
+
include Api::HasTransport
|
|
49
|
+
|
|
46
50
|
include Api::GetSlot
|
|
47
51
|
include Api::GetBalance
|
|
48
52
|
include Api::GetLatestBlockhash
|
|
@@ -58,6 +62,7 @@ module Solana::Ruby::Kit
|
|
|
58
62
|
include Api::GetTransaction
|
|
59
63
|
include Api::GetTokenAccountBalance
|
|
60
64
|
include Api::GetTokenAccountsByOwner
|
|
65
|
+
include Api::GetTokenSupply
|
|
61
66
|
include Api::GetEpochInfo
|
|
62
67
|
include Api::GetVoteAccounts
|
|
63
68
|
include Api::SimulateTransaction
|
|
@@ -67,7 +72,7 @@ module Solana::Ruby::Kit
|
|
|
67
72
|
include Api::GetSignaturesForAddress
|
|
68
73
|
include Api::GetTransactionsForAddress
|
|
69
74
|
|
|
70
|
-
sig { returns(Transport) }
|
|
75
|
+
sig { override.returns(Transport) }
|
|
71
76
|
attr_reader :transport
|
|
72
77
|
|
|
73
78
|
# @param cluster_url [RpcTypes::ClusterUrl, String] endpoint to connect to.
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
module Solana::Ruby::Kit
|
|
5
7
|
module RpcSubscriptions
|
|
6
8
|
module Api
|
|
@@ -8,6 +10,9 @@ module Solana::Ruby::Kit
|
|
|
8
10
|
# Mirrors TypeScript's AccountNotificationsApi.accountSubscribe.
|
|
9
11
|
module AccountNotifications
|
|
10
12
|
extend T::Sig
|
|
13
|
+
extend T::Helpers
|
|
14
|
+
|
|
15
|
+
requires_ancestor { HasTransport }
|
|
11
16
|
|
|
12
17
|
sig do
|
|
13
18
|
params(
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Solana::Ruby::Kit
|
|
5
|
+
module RpcSubscriptions
|
|
6
|
+
module Api
|
|
7
|
+
# Interface supplying the WebSocket connection and subscription plumbing
|
|
8
|
+
# that every notification mixin uses.
|
|
9
|
+
#
|
|
10
|
+
# The mixins in this namespace are not usable on their own — each one
|
|
11
|
+
# opens its subscription through `transport` and wraps it with
|
|
12
|
+
# `_build_subscription`, both provided by the object they are mixed into
|
|
13
|
+
# (`RpcSubscriptions::Client`). Declaring that requirement here, and
|
|
14
|
+
# having each mixin `requires_ancestor { HasTransport }`, lets Sorbet
|
|
15
|
+
# resolve those calls inside the mixins instead of reporting them missing.
|
|
16
|
+
module HasTransport
|
|
17
|
+
extend T::Sig
|
|
18
|
+
extend T::Helpers
|
|
19
|
+
abstract!
|
|
20
|
+
|
|
21
|
+
# The WebSocket connection used to issue JSON-RPC subscription requests.
|
|
22
|
+
sig { abstract.returns(Transport) }
|
|
23
|
+
def transport; end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
# Wrap a server-assigned subscription id in a `Subscription` that
|
|
28
|
+
# unsubscribes via `unsub_method` when closed. Private, matching the
|
|
29
|
+
# visibility it has on `RpcSubscriptions::Client`.
|
|
30
|
+
sig { abstract.params(sub_id: T.untyped, unsub_method: String).returns(Subscription) }
|
|
31
|
+
def _build_subscription(sub_id, unsub_method); end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
module Solana::Ruby::Kit
|
|
5
7
|
module RpcSubscriptions
|
|
6
8
|
module Api
|
|
@@ -8,6 +10,9 @@ module Solana::Ruby::Kit
|
|
|
8
10
|
# +filter+ may be 'all', 'allWithVotes', or { 'mentions' => [pubkey] }.
|
|
9
11
|
module LogsNotifications
|
|
10
12
|
extend T::Sig
|
|
13
|
+
extend T::Helpers
|
|
14
|
+
|
|
15
|
+
requires_ancestor { HasTransport }
|
|
11
16
|
|
|
12
17
|
sig do
|
|
13
18
|
params(
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
module Solana::Ruby::Kit
|
|
5
7
|
module RpcSubscriptions
|
|
6
8
|
module Api
|
|
7
9
|
# Subscribe to program account change notifications.
|
|
8
10
|
module ProgramNotifications
|
|
9
11
|
extend T::Sig
|
|
12
|
+
extend T::Helpers
|
|
13
|
+
|
|
14
|
+
requires_ancestor { HasTransport }
|
|
10
15
|
|
|
11
16
|
sig do
|
|
12
17
|
params(
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
module Solana::Ruby::Kit
|
|
5
7
|
module RpcSubscriptions
|
|
6
8
|
module Api
|
|
7
9
|
# Subscribe to root change notifications.
|
|
8
10
|
module RootNotifications
|
|
9
11
|
extend T::Sig
|
|
12
|
+
extend T::Helpers
|
|
13
|
+
|
|
14
|
+
requires_ancestor { HasTransport }
|
|
10
15
|
|
|
11
16
|
sig { returns(Subscription) }
|
|
12
17
|
def root_subscribe
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
module Solana::Ruby::Kit
|
|
5
7
|
module RpcSubscriptions
|
|
6
8
|
module Api
|
|
@@ -8,6 +10,9 @@ module Solana::Ruby::Kit
|
|
|
8
10
|
# The subscription auto-unsubscribes once the signature is confirmed.
|
|
9
11
|
module SignatureNotifications
|
|
10
12
|
extend T::Sig
|
|
13
|
+
extend T::Helpers
|
|
14
|
+
|
|
15
|
+
requires_ancestor { HasTransport }
|
|
11
16
|
|
|
12
17
|
sig do
|
|
13
18
|
params(
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# typed: strict
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
|
+
require_relative 'has_transport'
|
|
5
|
+
|
|
4
6
|
module Solana::Ruby::Kit
|
|
5
7
|
module RpcSubscriptions
|
|
6
8
|
module Api
|
|
7
9
|
# Subscribe to slot change notifications.
|
|
8
10
|
module SlotNotifications
|
|
9
11
|
extend T::Sig
|
|
12
|
+
extend T::Helpers
|
|
13
|
+
|
|
14
|
+
requires_ancestor { HasTransport }
|
|
10
15
|
|
|
11
16
|
sig { returns(Subscription) }
|
|
12
17
|
def slot_subscribe
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
require_relative 'transport'
|
|
5
5
|
require_relative 'subscription'
|
|
6
|
+
require_relative 'api/has_transport'
|
|
6
7
|
require_relative 'autopinger'
|
|
7
8
|
require_relative 'api/account_notifications'
|
|
8
9
|
require_relative 'api/logs_notifications'
|
|
@@ -23,6 +24,8 @@ module Solana::Ruby::Kit
|
|
|
23
24
|
class Client
|
|
24
25
|
extend T::Sig
|
|
25
26
|
|
|
27
|
+
include Api::HasTransport
|
|
28
|
+
|
|
26
29
|
include Api::AccountNotifications
|
|
27
30
|
include Api::LogsNotifications
|
|
28
31
|
include Api::ProgramNotifications
|
|
@@ -30,7 +33,7 @@ module Solana::Ruby::Kit
|
|
|
30
33
|
include Api::SignatureNotifications
|
|
31
34
|
include Api::SlotNotifications
|
|
32
35
|
|
|
33
|
-
sig { returns(Transport) }
|
|
36
|
+
sig { override.returns(Transport) }
|
|
34
37
|
attr_reader :transport
|
|
35
38
|
|
|
36
39
|
sig do
|
|
@@ -56,7 +59,7 @@ module Solana::Ruby::Kit
|
|
|
56
59
|
|
|
57
60
|
# Build a Subscription wrapping an AsyncIterable enumerator and
|
|
58
61
|
# an auto-unsubscribe on close.
|
|
59
|
-
sig { params(sub_id: T.untyped, unsub_method: String).returns(Subscription) }
|
|
62
|
+
sig { override.params(sub_id: T.untyped, unsub_method: String).returns(Subscription) }
|
|
60
63
|
def _build_subscription(sub_id, unsub_method)
|
|
61
64
|
publisher = @transport.publisher
|
|
62
65
|
enumerator = Subscribable::AsyncIterable.from_publisher(
|
|
@@ -40,7 +40,9 @@ module Solana::Ruby::Kit
|
|
|
40
40
|
|
|
41
41
|
sig { params(other: T.untyped).returns(T::Boolean) }
|
|
42
42
|
def ==(other)
|
|
43
|
-
other.is_a?(Sol)
|
|
43
|
+
return false unless other.is_a?(Sol)
|
|
44
|
+
|
|
45
|
+
@raw == other.raw
|
|
44
46
|
end
|
|
45
47
|
|
|
46
48
|
sig { returns(Integer) }
|
|
@@ -50,8 +52,8 @@ module Solana::Ruby::Kit
|
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
SOL_DECIMALS = T.let(9, Integer)
|
|
53
|
-
SOL_SCALE = T.let(
|
|
54
|
-
SOL_RAW_MAX = T.let(2**64 - 1, Integer)
|
|
55
|
+
SOL_SCALE = T.let(1_000_000_000, Integer)
|
|
56
|
+
SOL_RAW_MAX = T.let(Kernel.Integer(2**64 - 1), Integer)
|
|
55
57
|
|
|
56
58
|
module_function
|
|
57
59
|
|
|
@@ -66,17 +68,17 @@ module Solana::Ruby::Kit
|
|
|
66
68
|
# Mirrors TypeScript's sol(value, rounding?).
|
|
67
69
|
sig { params(value: String).returns(Sol) }
|
|
68
70
|
def sol(value)
|
|
69
|
-
bd = BigDecimal(value)
|
|
71
|
+
bd = Kernel.BigDecimal(value)
|
|
70
72
|
Kernel.raise SolanaError.new(SolanaError::FIXED_POINTS__STRICT_MODE_PRECISION_LOSS) if bd < 0
|
|
71
73
|
|
|
72
74
|
scaled = bd * SOL_SCALE
|
|
73
75
|
raw = scaled.to_i
|
|
74
76
|
|
|
75
|
-
unless scaled == BigDecimal(raw.to_s)
|
|
77
|
+
unless scaled == Kernel.BigDecimal(raw.to_s)
|
|
76
78
|
Kernel.raise SolanaError.new(SolanaError::FIXED_POINTS__STRICT_MODE_PRECISION_LOSS)
|
|
77
79
|
end
|
|
78
80
|
|
|
79
|
-
Kernel.raise SolanaError.new(SolanaError::
|
|
81
|
+
Kernel.raise SolanaError.new(SolanaError::LAMPORTS_OUT_OF_RANGE) if raw > SOL_RAW_MAX
|
|
80
82
|
|
|
81
83
|
Sol.new(raw)
|
|
82
84
|
end
|
|
@@ -82,8 +82,8 @@ module Solana::Ruby::Kit
|
|
|
82
82
|
# most recent call's result updates state; superseded threads are ignored.
|
|
83
83
|
sig { params(args: T.untyped).void }
|
|
84
84
|
def dispatch(*args)
|
|
85
|
-
gen = nil
|
|
86
|
-
prev_data = nil
|
|
85
|
+
gen = T.let(nil, T.nilable(Integer))
|
|
86
|
+
prev_data = T.let(nil, T.untyped)
|
|
87
87
|
@mutex.synchronize do
|
|
88
88
|
@current_gen += 1
|
|
89
89
|
gen = @current_gen
|
|
@@ -94,7 +94,7 @@ module Solana::Ruby::Kit
|
|
|
94
94
|
|
|
95
95
|
Thread.new do
|
|
96
96
|
begin
|
|
97
|
-
result = @fn.call(*args)
|
|
97
|
+
result = @fn.call(*T.unsafe(args))
|
|
98
98
|
active = @mutex.synchronize do
|
|
99
99
|
if @current_gen == gen
|
|
100
100
|
@state = ReactiveActionState.new(status: 'success', data: result)
|
|
@@ -125,8 +125,8 @@ module Solana::Ruby::Kit
|
|
|
125
125
|
# by a concurrent dispatch or reset().
|
|
126
126
|
sig { params(args: T.untyped).returns(T.untyped) }
|
|
127
127
|
def dispatch_async(*args)
|
|
128
|
-
gen = nil
|
|
129
|
-
prev_data = nil
|
|
128
|
+
gen = T.let(nil, T.nilable(Integer))
|
|
129
|
+
prev_data = T.let(nil, T.untyped)
|
|
130
130
|
@mutex.synchronize do
|
|
131
131
|
@current_gen += 1
|
|
132
132
|
gen = @current_gen
|
|
@@ -135,7 +135,7 @@ module Solana::Ruby::Kit
|
|
|
135
135
|
end
|
|
136
136
|
_notify
|
|
137
137
|
|
|
138
|
-
result = @fn.call(*args)
|
|
138
|
+
result = @fn.call(*T.unsafe(args))
|
|
139
139
|
|
|
140
140
|
active = @mutex.synchronize do
|
|
141
141
|
if @current_gen == gen
|
|
@@ -108,7 +108,7 @@ module Solana::Ruby::Kit
|
|
|
108
108
|
# Internal: transition state and notify all subscribers.
|
|
109
109
|
sig { params(new_state: ReactiveState).void }
|
|
110
110
|
def _set_state(new_state)
|
|
111
|
-
subs = nil
|
|
111
|
+
subs = T.let(nil, T.nilable(T::Array[T.proc.void]))
|
|
112
112
|
@mutex.synchronize do
|
|
113
113
|
return if @state.equal?(new_state)
|
|
114
114
|
@state = new_state
|
|
@@ -167,7 +167,7 @@ module Solana::Ruby::Kit
|
|
|
167
167
|
return if @mutex.synchronize { @stopped }
|
|
168
168
|
|
|
169
169
|
# Fresh active flag for this connection window
|
|
170
|
-
active = [true]
|
|
170
|
+
active = T.let([true], T::Array[T::Boolean])
|
|
171
171
|
@mutex.synchronize { @conn_active = active }
|
|
172
172
|
|
|
173
173
|
# inner_signal fires (raises) once this connection is superseded or errors out,
|
|
@@ -193,8 +193,8 @@ module Solana::Ruby::Kit
|
|
|
193
193
|
publisher.on(@error_channel, signal: inner_signal) do |err|
|
|
194
194
|
next unless active[0] && get_unified_state.status != 'error'
|
|
195
195
|
active[0] = false
|
|
196
|
-
|
|
197
|
-
_set_state(ReactiveState.new(status: 'error', data:
|
|
196
|
+
last_data = get_unified_state.data
|
|
197
|
+
_set_state(ReactiveState.new(status: 'error', data: last_data, error: err))
|
|
198
198
|
end
|
|
199
199
|
end
|
|
200
200
|
end
|
|
@@ -68,11 +68,11 @@ module Solana::Ruby::Kit
|
|
|
68
68
|
|
|
69
69
|
if existing_idx.nil?
|
|
70
70
|
append_instructions(message, [new_ix])
|
|
71
|
-
elsif compute_unit_limit_from_instruction_data(T.must(message.instructions[existing_idx].data)) == limit
|
|
71
|
+
elsif compute_unit_limit_from_instruction_data(T.must(T.must(message.instructions[existing_idx]).data)) == limit
|
|
72
72
|
message
|
|
73
73
|
else
|
|
74
74
|
new_instructions = message.instructions.dup
|
|
75
|
-
new_instructions[
|
|
75
|
+
new_instructions[existing_idx] = new_ix
|
|
76
76
|
TransactionMessage.new(
|
|
77
77
|
version: message.version,
|
|
78
78
|
instructions: new_instructions,
|
|
@@ -127,11 +127,11 @@ module Solana::Ruby::Kit
|
|
|
127
127
|
|
|
128
128
|
if existing_idx.nil?
|
|
129
129
|
append_instructions(message, [new_ix])
|
|
130
|
-
elsif loaded_accounts_data_size_limit_from_instruction_data(T.must(message.instructions[existing_idx].data)) == limit
|
|
130
|
+
elsif loaded_accounts_data_size_limit_from_instruction_data(T.must(T.must(message.instructions[existing_idx]).data)) == limit
|
|
131
131
|
message
|
|
132
132
|
else
|
|
133
133
|
new_instructions = message.instructions.dup
|
|
134
|
-
new_instructions[
|
|
134
|
+
new_instructions[existing_idx] = new_ix
|
|
135
135
|
TransactionMessage.new(
|
|
136
136
|
version: message.version,
|
|
137
137
|
instructions: new_instructions,
|
|
@@ -115,7 +115,7 @@ module Solana::Ruby::Kit
|
|
|
115
115
|
reason: 'message section is missing'
|
|
116
116
|
)
|
|
117
117
|
end
|
|
118
|
-
message_bytes =
|
|
118
|
+
message_bytes = msg_slice.b
|
|
119
119
|
|
|
120
120
|
# 4. Determine version and locate the message header.
|
|
121
121
|
# Legacy transactions: first byte = num_required_signatures (0..127)
|
|
@@ -139,14 +139,14 @@ module Solana::Ruby::Kit
|
|
|
139
139
|
|
|
140
140
|
account_addrs = T.let([], T::Array[String])
|
|
141
141
|
num_accounts.times do
|
|
142
|
-
account_addrs << Addresses.encode_address(message_bytes[msg_pos, 32].b)
|
|
142
|
+
account_addrs << Addresses.encode_address(T.must(message_bytes[msg_pos, 32]).b)
|
|
143
143
|
msg_pos += 32
|
|
144
144
|
end
|
|
145
145
|
|
|
146
146
|
# 6. Build the signatures map.
|
|
147
147
|
# The first +num_required_sigs+ accounts in the account table are the
|
|
148
148
|
# signers; their raw_sigs slots are positionally aligned.
|
|
149
|
-
signer_addrs = account_addrs[0, num_required_sigs]
|
|
149
|
+
signer_addrs = T.must(account_addrs[0, num_required_sigs])
|
|
150
150
|
signatures = T.let({}, T::Hash[String, T.nilable(String)])
|
|
151
151
|
signer_addrs.each_with_index { |addr, i| signatures[addr] = raw_sigs[i] }
|
|
152
152
|
|
|
@@ -234,7 +234,7 @@ module Solana::Ruby::Kit
|
|
|
234
234
|
def decode_compact_u16(bytes, offset)
|
|
235
235
|
value = 0
|
|
236
236
|
shift = 0
|
|
237
|
-
loop do
|
|
237
|
+
Kernel.loop do
|
|
238
238
|
byte = bytes.getbyte(offset)
|
|
239
239
|
if byte.nil?
|
|
240
240
|
Kernel.raise SolanaError.new(
|