Module: BSV::Wallet::StorageAdapter
- Included in:
- MemoryStore
- Defined in:
- lib/bsv/wallet_interface/storage_adapter.rb
Overview
Duck-typed storage interface for wallet persistence.
Include this module in storage adapters and override all methods. The default implementations raise NotImplementedError.
Instance Method Summary collapse
- #count_actions(_query) ⇒ Object
- #count_certificates(_query) ⇒ Object
- #count_outputs(_query) ⇒ Object
-
#delete_action(_txid) ⇒ Boolean
Removes a stored action by txid.
- #delete_certificate(type:, serial_number:, certifier:) ⇒ Object
- #delete_output(_outpoint) ⇒ Object
- #find_actions(_query) ⇒ Object
- #find_certificates(_query) ⇒ Object
- #find_outputs(_query) ⇒ Object
- #find_proof(_txid) ⇒ Object
-
#find_setting(_key) ⇒ Object?
Retrieves a named wallet setting.
-
#find_spendable_outputs(basket: nil, min_satoshis: nil, sort_order: :desc) ⇒ Array<Hash>
Returns only outputs whose effective state is
:spendable. - #find_transaction(_txid) ⇒ Object
-
#lock_utxos(outpoints, reference:, no_send: false) ⇒ Array<String>
Atomically finds outputs by outpoint and marks them as
:pending. -
#release_stale_pending!(timeout: 300) ⇒ Integer
Releases pending locks that have been held longer than
timeoutseconds. - #store_action(_action_data) ⇒ Object
- #store_certificate(_cert_data) ⇒ Object
- #store_output(_output_data) ⇒ Object
- #store_proof(_txid, _bump_hex) ⇒ Object
-
#store_setting(_key, _value) ⇒ Object
Persists a named wallet setting.
- #store_transaction(_txid, _tx_hex) ⇒ Object
-
#update_action_status(_txid, _new_status) ⇒ Hash
Updates the status field of a stored action identified by txid.
-
#update_output_state(_outpoint, _new_state, pending_reference: nil, no_send: nil) ⇒ Object
Transitions the state of an existing output.
Instance Method Details
#count_actions(_query) ⇒ Object
42 43 44 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 42 def count_actions(_query) raise NotImplementedError, "#{self.class}#count_actions not implemented" end |
#count_certificates(_query) ⇒ Object
50 51 52 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 50 def count_certificates(_query) raise NotImplementedError, "#{self.class}#count_certificates not implemented" end |
#count_outputs(_query) ⇒ Object
46 47 48 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 46 def count_outputs(_query) raise NotImplementedError, "#{self.class}#count_outputs not implemented" end |
#delete_action(_txid) ⇒ Boolean
Removes a stored action by txid.
86 87 88 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 86 def delete_action(_txid) raise NotImplementedError, "#{self.class}#delete_action not implemented" end |
#delete_certificate(type:, serial_number:, certifier:) ⇒ Object
38 39 40 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 38 def delete_certificate(type:, serial_number:, certifier:) raise NotImplementedError, "#{self.class}#delete_certificate not implemented" end |
#delete_output(_outpoint) ⇒ Object
26 27 28 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 26 def delete_output(_outpoint) raise NotImplementedError, "#{self.class}#delete_output not implemented" end |
#find_actions(_query) ⇒ Object
14 15 16 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 14 def find_actions(_query) raise NotImplementedError, "#{self.class}#find_actions not implemented" end |
#find_certificates(_query) ⇒ Object
34 35 36 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 34 def find_certificates(_query) raise NotImplementedError, "#{self.class}#find_certificates not implemented" end |
#find_outputs(_query) ⇒ Object
22 23 24 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 22 def find_outputs(_query) raise NotImplementedError, "#{self.class}#find_outputs not implemented" end |
#find_proof(_txid) ⇒ Object
58 59 60 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 58 def find_proof(_txid) raise NotImplementedError, "#{self.class}#find_proof not implemented" end |
#find_setting(_key) ⇒ Object?
Retrieves a named wallet setting.
165 166 167 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 165 def find_setting(_key) raise NotImplementedError, "#{self.class}#find_setting not implemented" end |
#find_spendable_outputs(basket: nil, min_satoshis: nil, sort_order: :desc) ⇒ Array<Hash>
Returns only outputs whose effective state is :spendable.
132 133 134 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 132 def find_spendable_outputs(basket: nil, min_satoshis: nil, sort_order: :desc) raise NotImplementedError, "#{self.class}#find_spendable_outputs not implemented" end |
#find_transaction(_txid) ⇒ Object
66 67 68 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 66 def find_transaction(_txid) raise NotImplementedError, "#{self.class}#find_transaction not implemented" end |
#lock_utxos(outpoints, reference:, no_send: false) ⇒ Array<String>
Atomically finds outputs by outpoint and marks them as :pending.
This prevents TOCTOU races where two threads select the same UTXO between find_spendable_outputs and update_output_state. Only outputs still in :spendable state are locked; any that have already transitioned are skipped.
121 122 123 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 121 def lock_utxos(outpoints, reference:, no_send: false) raise NotImplementedError, "#{self.class}#lock_utxos not implemented" end |
#release_stale_pending!(timeout: 300) ⇒ Integer
Releases pending locks that have been held longer than timeout seconds.
Each output in :pending state whose :pending_since timestamp is older than timeout seconds is reverted to :spendable and its pending metadata is cleared.
This is a no-op for adapters that do not support pending metadata.
147 148 149 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 147 def release_stale_pending!(timeout: 300) raise NotImplementedError, "#{self.class}#release_stale_pending! not implemented" end |
#store_action(_action_data) ⇒ Object
10 11 12 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 10 def store_action(_action_data) raise NotImplementedError, "#{self.class}#store_action not implemented" end |
#store_certificate(_cert_data) ⇒ Object
30 31 32 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 30 def store_certificate(_cert_data) raise NotImplementedError, "#{self.class}#store_certificate not implemented" end |
#store_output(_output_data) ⇒ Object
18 19 20 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 18 def store_output(_output_data) raise NotImplementedError, "#{self.class}#store_output not implemented" end |
#store_proof(_txid, _bump_hex) ⇒ Object
54 55 56 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 54 def store_proof(_txid, _bump_hex) raise NotImplementedError, "#{self.class}#store_proof not implemented" end |
#store_setting(_key, _value) ⇒ Object
Persists a named wallet setting.
156 157 158 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 156 def store_setting(_key, _value) raise NotImplementedError, "#{self.class}#store_setting not implemented" end |
#store_transaction(_txid, _tx_hex) ⇒ Object
62 63 64 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 62 def store_transaction(_txid, _tx_hex) raise NotImplementedError, "#{self.class}#store_transaction not implemented" end |
#update_action_status(_txid, _new_status) ⇒ Hash
Updates the status field of a stored action identified by txid.
77 78 79 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 77 def update_action_status(_txid, _new_status) raise NotImplementedError, "#{self.class}#update_action_status not implemented" end |
#update_output_state(_outpoint, _new_state, pending_reference: nil, no_send: nil) ⇒ Object
Transitions the state of an existing output.
When new_state is :pending, pass a pending_reference: string to associate the lock with a specific action. The adapter should record a timestamp (ISO 8601 UTC) alongside the reference so stale locks can be detected and released by #release_stale_pending!.
When transitioning away from :pending, the adapter must clear any stored :pending_since and :pending_reference metadata.
106 107 108 |
# File 'lib/bsv/wallet_interface/storage_adapter.rb', line 106 def update_output_state(_outpoint, _new_state, pending_reference: nil, no_send: nil) raise NotImplementedError, "#{self.class}#update_output_state not implemented" end |