Skip to content

Commit 3f23bb3

Browse files
sgbettclaude
andcommitted
feat(wallet-postgres): add update_output_basket to PostgresStore (#474)
Implements the new StorageAdapter method added in the UTXO pool work. Updates both the basket column and the JSONB data blob. Follows the same pattern as update_output_state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent dd9d5d4 commit 3f23bb3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

gem/bsv-wallet-postgres/lib/bsv/wallet_postgres/postgres_store.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,26 @@ def update_output_state(outpoint, new_state, pending_reference: nil, no_send: ni
236236
symbolise_keys(row[:data])
237237
end
238238

239+
# Moves an output from one basket to another (metadata-only).
240+
#
241+
# Updates both the +basket+ column and the JSONB +data+ blob.
242+
# Does not affect the output's state or pending metadata.
243+
#
244+
# @param outpoint [String] the outpoint identifier
245+
# @param new_basket [String] the destination basket name
246+
# @raise [BSV::Wallet::WalletError] if the outpoint is not found
247+
# @return [Hash] the updated output hash
248+
def update_output_basket(outpoint, new_basket)
249+
ds = @db[:wallet_outputs].where(outpoint: outpoint)
250+
rows_updated = ds.update(
251+
basket: new_basket,
252+
data: Sequel.lit("data || jsonb_build_object('basket', ?)", new_basket)
253+
)
254+
raise WalletError, "Output not found: #{outpoint}" if rows_updated.zero?
255+
256+
symbolise_keys(ds.first[:data])
257+
end
258+
239259
# Atomically marks a set of outpoints as +:pending+.
240260
#
241261
# Uses +UPDATE ... WHERE state = 'spendable' ... RETURNING outpoint+ so that

0 commit comments

Comments
 (0)