Module: Solana::Ruby::Kit::Sysvars
- Extended by:
- T::Sig
- Defined in:
- lib/solana/ruby/kit/sysvars/rent.rb,
lib/solana/ruby/kit/sysvars/clock.rb,
lib/solana/ruby/kit/sysvars/addresses.rb,
lib/solana/ruby/kit/sysvars/epoch_schedule.rb,
lib/solana/ruby/kit/sysvars/last_restart_slot.rb,
lib/solana/ruby/kit/sysvars.rb
Defined Under Namespace
Classes: SysvarClock, SysvarEpochSchedule, SysvarLastRestartSlot, SysvarRent
Constant Summary
collapse
- CLOCK_SIZE =
T.let(40, Integer)
- SYSVAR_CLOCK_ADDRESS =
Well-known on-chain addresses for all Solana sysvar accounts.
T.let('SysvarC1ock11111111111111111111111111111111', String)
- SYSVAR_RENT_ADDRESS =
T.let('SysvarRent111111111111111111111111111111111', String)
- SYSVAR_EPOCH_SCHEDULE_ADDRESS =
T.let('SysvarEpochSchedu1e111111111111111111111111', String)
- SYSVAR_FEES_ADDRESS =
T.let('SysvarFees111111111111111111111111111111111', String)
- SYSVAR_RECENT_BLOCKHASHES_ADDRESS =
T.let('SysvarRecentB1ockHashes11111111111111111111', String)
- SYSVAR_SLOT_HASHES_ADDRESS =
T.let('SysvarS1otHashes111111111111111111111111111', String)
- SYSVAR_SLOT_HISTORY_ADDRESS =
T.let('SysvarS1otHistory11111111111111111111111111', String)
- SYSVAR_STAKE_HISTORY_ADDRESS =
T.let('SysvarStakeHistory1111111111111111111111111', String)
- SYSVAR_INSTRUCTIONS_ADDRESS =
T.let('Sysvar1nstructions1111111111111111111111111', String)
- SYSVAR_LAST_RESTART_SLOT_ADDRESS =
T.let('SysvarLastRestartS1ot1111111111111111111111', String)
- SYSVAR_EPOCH_REWARDS_ADDRESS =
T.let('SysvarEpochRewards1111111111111111111111111', String)
Class Method Summary
collapse
Class Method Details
._decode_account_data(res) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/solana/ruby/kit/sysvars.rb', line 19
def _decode_account_data(res)
info = res.value
Kernel.raise ArgumentError, 'Account not found' if info.nil?
raw = T.cast(info, RpcTypes::AccountInfoWithBase64Data)
Base64.decode64(raw.data.first.to_s).b
end
|
.fetch_sysvar_clock(rpc) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/solana/ruby/kit/sysvars/clock.rb', line 23
def fetch_sysvar_clock(rpc)
res = rpc.get_account_info(SYSVAR_CLOCK_ADDRESS, encoding: 'base64')
data = _decode_account_data(res)
unpacked = T.cast(T.unsafe(data).unpack('Q<q<Q<Q<q<'), T::Array[Integer])
SysvarClock.new(
slot: T.must(unpacked[0]),
epoch_start_timestamp: T.must(unpacked[1]),
epoch: T.must(unpacked[2]),
leader_schedule_epoch: T.must(unpacked[3]),
unix_timestamp: T.must(unpacked[4])
)
end
|
.fetch_sysvar_epoch_schedule(rpc) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/solana/ruby/kit/sysvars/epoch_schedule.rb', line 20
def fetch_sysvar_epoch_schedule(rpc)
res = rpc.get_account_info(SYSVAR_EPOCH_SCHEDULE_ADDRESS, encoding: 'base64')
data = _decode_account_data(res)
unpacked = T.unsafe(data).unpack('Q<Q<CQ<Q<')
SysvarEpochSchedule.new(
slots_per_epoch: unpacked[0],
leader_schedule_slot_offset: unpacked[1],
warmup: unpacked[2] == 1,
first_normal_epoch: unpacked[3],
first_normal_slot: unpacked[4]
)
end
|
.fetch_sysvar_last_restart_slot(rpc) ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/solana/ruby/kit/sysvars/last_restart_slot.rb', line 14
def fetch_sysvar_last_restart_slot(rpc)
res = rpc.get_account_info(SYSVAR_LAST_RESTART_SLOT_ADDRESS, encoding: 'base64')
data = _decode_account_data(res)
slot = data.unpack1('Q<')
SysvarLastRestartSlot.new(last_restart_slot: slot)
end
|
.fetch_sysvar_rent(rpc) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/solana/ruby/kit/sysvars/rent.rb', line 17
def fetch_sysvar_rent(rpc)
res = rpc.get_account_info(SYSVAR_RENT_ADDRESS, encoding: 'base64')
data = _decode_account_data(res)
unpacked = T.unsafe(data).unpack('Q<EC')
SysvarRent.new(
lamports_per_byte_year: unpacked[0],
exemption_threshold: unpacked[1],
burn_percent: unpacked[2]
)
end
|