Class: Solace::SquadsSmartAccounts::Transaction

Inherits:
Data
  • Object
show all
Defined in:
lib/solace/squads_smart_accounts/types/transaction.rb

Overview

Immutable value object for a deserialized Transaction account — a pending vault transaction stored by ‘createTransaction` and replayed by `executeTransaction`.

Layout follows the deployed (newer) program, which the bundled IDL does not describe: the account holds a ‘Payload` enum after `index`, whose TransactionPayload variant carries account_index, ephemeral_signer_bumps, and the message. The stored message (SmartAccountTransactionMessage) uses standard Borsh Vec (u32 counts) — distinct from the SmallVec format used to submit the message. Only the message header counts and account_keys are decoded (enough to verify a round-trip); compiled instructions and address-table lookups are skipped.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#account_indexObject (readonly)

Returns the value of attribute account_index

Returns:

  • (Object)

    the current value of account_index



17
18
19
# File 'lib/solace/squads_smart_accounts/types/transaction.rb', line 17

def 
  @account_index
end

#account_keysObject (readonly)

Returns the value of attribute account_keys

Returns:

  • (Object)

    the current value of account_keys



17
18
19
# File 'lib/solace/squads_smart_accounts/types/transaction.rb', line 17

def 
  @account_keys
end

#creatorObject (readonly)

Returns the value of attribute creator

Returns:

  • (Object)

    the current value of creator



17
18
19
# File 'lib/solace/squads_smart_accounts/types/transaction.rb', line 17

def creator
  @creator
end

#indexObject (readonly)

Returns the value of attribute index

Returns:

  • (Object)

    the current value of index



17
18
19
# File 'lib/solace/squads_smart_accounts/types/transaction.rb', line 17

def index
  @index
end

#num_signersObject (readonly)

Returns the value of attribute num_signers

Returns:

  • (Object)

    the current value of num_signers



17
18
19
# File 'lib/solace/squads_smart_accounts/types/transaction.rb', line 17

def num_signers
  @num_signers
end

#num_writable_non_signersObject (readonly)

Returns the value of attribute num_writable_non_signers

Returns:

  • (Object)

    the current value of num_writable_non_signers



17
18
19
# File 'lib/solace/squads_smart_accounts/types/transaction.rb', line 17

def num_writable_non_signers
  @num_writable_non_signers
end

#num_writable_signersObject (readonly)

Returns the value of attribute num_writable_signers

Returns:

  • (Object)

    the current value of num_writable_signers



17
18
19
# File 'lib/solace/squads_smart_accounts/types/transaction.rb', line 17

def num_writable_signers
  @num_writable_signers
end

#rent_collectorObject (readonly)

Returns the value of attribute rent_collector

Returns:

  • (Object)

    the current value of rent_collector



17
18
19
# File 'lib/solace/squads_smart_accounts/types/transaction.rb', line 17

def rent_collector
  @rent_collector
end

#settingsObject (readonly)

Returns the value of attribute settings

Returns:

  • (Object)

    the current value of settings



17
18
19
# File 'lib/solace/squads_smart_accounts/types/transaction.rb', line 17

def settings
  @settings
end

Class Method Details

.deserialize(io) ⇒ Transaction

Deserializes a Transaction account from a stream of Borsh-encoded account data.

Parameters:

  • io (IO, StringIO)

    Stream positioned at the start of the account data.

Returns:

Raises:

  • (RuntimeError)

    If the payload is not a TransactionPayload.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/solace/squads_smart_accounts/types/transaction.rb', line 65

def deserialize(io)
  io.read(8) # skip 8-byte Anchor discriminator

  settings       = Solace::Utils::Codecs.decode_pubkey(io)
  creator        = Solace::Utils::Codecs.decode_pubkey(io)
  rent_collector = Solace::Utils::Codecs.decode_pubkey(io)
  index          = Solace::Utils::Codecs.decode_le_u64(io)

  enforce_known_variant!(io)

   = Solace::Utils::Codecs.decode_u8(io)

  # ephemeral_signer_bumps: Borsh Vec<u8> (u32 length + raw bytes). Skipped.
  io.read(Solace::Utils::Codecs.decode_le_u32(io))

  # Embedded SmartAccountTransactionMessage header + account_keys (Vec, u32 count).
  num_signers              = Solace::Utils::Codecs.decode_u8(io)
  num_writable_signers     = Solace::Utils::Codecs.decode_u8(io)
  num_writable_non_signers = Solace::Utils::Codecs.decode_u8(io)
               = Solace::Utils::Codecs.decode_vec_pubkeys(io)

  new(
    settings:,
    creator:,
    rent_collector:,
    index:,
    account_index:,
    num_signers:,
    num_writable_signers:,
    num_writable_non_signers:,
    account_keys:
  )
end

Instance Method Details

#account_metasArray<Hash>

The stored message’s account_keys as ordered account metas — the inverse of how AccountContext#compile lays them out. Each meta carries the same writable: flags vocabulary AccountContext uses, derived from the canonical ordering [writable signers, readonly signers, writable non-signers, readonly non-signers]. This is the input executeTransaction replays as its remaining accounts (the lone signer being the vault PDA).

Returns:

  • (Array<Hash>)

    Each { pubkey: String, signer: Boolean, writable: Boolean }.



36
37
38
39
40
41
42
43
44
# File 'lib/solace/squads_smart_accounts/types/transaction.rb', line 36

def 
  .each_index.map do |index|
    {
      pubkey:   [index],
      signer:   index < num_signers,
      writable: writable_index?(index)
    }
  end
end