Module: Solana::Ruby::Kit::Instructions::AccountRole

Extended by:
T::Sig
Defined in:
lib/solana/ruby/kit/instructions/roles.rb

Overview

Bitflag-based account roles for Solana instructions. Mirrors TypeScript’s AccountRole enum from @solana/instructions.

Bit layout:

bit 1 (0b10) 

Constant Summary collapse

READONLY =

read-only, no signing required

T.let(0b00, Integer)
WRITABLE =

writable, no signing required

T.let(0b01, Integer)
READONLY_SIGNER =

must sign, read-only

T.let(0b10, Integer)
WRITABLE_SIGNER =

must sign AND writable

T.let(0b11, Integer)
ALL =
T.let([READONLY, WRITABLE, READONLY_SIGNER, WRITABLE_SIGNER].freeze, T::Array[Integer])

Class Method Summary collapse

Class Method Details

.downgrade_to_non_signer(role) ⇒ Object



46
47
48
# File 'lib/solana/ruby/kit/instructions/roles.rb', line 46

def downgrade_to_non_signer(role)
  role & 0b01
end

.downgrade_to_readonly(role) ⇒ Object



53
54
55
# File 'lib/solana/ruby/kit/instructions/roles.rb', line 53

def downgrade_to_readonly(role)
  role & 0b10
end

.merge(a, b) ⇒ Object



39
40
41
# File 'lib/solana/ruby/kit/instructions/roles.rb', line 39

def merge(a, b)
  a | b
end

.name(role) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/solana/ruby/kit/instructions/roles.rb', line 73

def name(role)
  case role
  when READONLY        then 'READONLY'
  when WRITABLE        then 'WRITABLE'
  when READONLY_SIGNER then 'READONLY_SIGNER'
  when WRITABLE_SIGNER then 'WRITABLE_SIGNER'
  else "UNKNOWN(#{role})"
  end
end

.signer_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/solana/ruby/kit/instructions/roles.rb', line 26

def signer_role?(role)
  (role & 0b10) != 0
end

.upgrade_to_signer(role) ⇒ Object



60
61
62
# File 'lib/solana/ruby/kit/instructions/roles.rb', line 60

def upgrade_to_signer(role)
  role | 0b10
end

.upgrade_to_writable(role) ⇒ Object



67
68
69
# File 'lib/solana/ruby/kit/instructions/roles.rb', line 67

def upgrade_to_writable(role)
  role | 0b01
end

.writable_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/solana/ruby/kit/instructions/roles.rb', line 32

def writable_role?(role)
  (role & 0b01) != 0
end