bsv-wallet-postgres 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc93b503d2d084ed5b1221f97803f66b171141f2c8a855b7c247b0a54b434fc3
4
- data.tar.gz: 55b88e4b7a82168df0da8b38ace070fbc50d76249e08e4aa35aaa49bb09a199f
3
+ metadata.gz: d007064fafd9853cdc8696661ef969ddef47c0eeb9a1c0451acc7793a67fd1f1
4
+ data.tar.gz: 21335a50ff36fbaf390ddfe558e5efbb67514ae4da5189f0b6b9c0a2a4b7c2e6
5
5
  SHA512:
6
- metadata.gz: d124ec0511c1ed69ff41a4c9e3a681d794a869a89c1439286b6bac32dc173576e63f22df86f20665a8b5d216fd2057b9245d5b1756581afe4eab6f71deea39e2
7
- data.tar.gz: 62842664bdd3ad2ba4f065f0e081065baec92c30bb7ad53cfed71dd1f91135f7e8cb3a9dbea73abe9895a4ef691da5b32ccaf744b6dcc0d3a52caa4b075aedc1
6
+ metadata.gz: bd2578b3303a8b2a1407c51366aa9a30e78d28e38875fb5f229d5408a76f02a6ecbcaddfa3e1a01d770257e0c3e3f18ea15a257097cd5c5cc5444b4d4501d382
7
+ data.tar.gz: e296a4026b3bddedd41cd572ad627c279ee9aaf16ca4d7ee061c11718a1b81e27cb76e9583dda0012bf55cdfaf7c28a34791c28306951802879c76463efd7157
data/CHANGELOG.md CHANGED
@@ -5,6 +5,18 @@ All notable changes to the `bsv-wallet-postgres` gem are documented here.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
6
6
  and this gem adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 0.3.1 — 2026-04-12
9
+
10
+ ### Fixed
11
+ - `update_action_status` now scopes to a single row by primary key, preventing unintended multi-row updates when duplicate txids exist
12
+ - Added migration 005: unique index on `wallet_actions.txid` enforcing one action per transaction
13
+
14
+ ## 0.3.0 — 2026-04-12
15
+
16
+ ### Added
17
+ - `update_action_status` and `delete_action` implementations for PostgresStore,
18
+ matching the new StorageAdapter contract introduced in bsv-wallet 0.6.0 (#370)
19
+
8
20
  ## 0.2.0 — 2026-04-12
9
21
 
10
22
  ### Added
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add a unique index on wallet_actions.txid.
4
+ #
5
+ # Within a single wallet there should be at most one action per transaction.
6
+ # Without this constraint, concurrent inserts or retries could create duplicate
7
+ # rows sharing the same txid, causing +update_action_status+ to update multiple
8
+ # rows unintentionally.
9
+ #
10
+ # The index also accelerates the +where(txid:)+ lookups performed by
11
+ # +update_action_status+ and +delete_action+.
12
+ #
13
+ # === Backward compatibility
14
+ #
15
+ # The migration will fail if duplicate txids already exist in the table. Clean
16
+ # up any duplicates before running this migration:
17
+ #
18
+ # DELETE FROM wallet_actions a
19
+ # USING wallet_actions b
20
+ # WHERE a.id > b.id AND a.txid = b.txid;
21
+ Sequel.migration do
22
+ change do
23
+ alter_table(:wallet_actions) do
24
+ add_index :txid, unique: true, name: :wallet_actions_txid_unique
25
+ end
26
+ end
27
+ end
@@ -102,6 +102,27 @@ module BSV
102
102
  filter_actions(@db[:wallet_actions], query).count
103
103
  end
104
104
 
105
+ def update_action_status(txid, new_status)
106
+ # Fetch by txid first, then update by primary key so only exactly one
107
+ # row is targeted. The unique index on txid makes this unambiguous, but
108
+ # scoping to the id column makes the intent explicit and is safe even
109
+ # on databases where the migration has not yet been applied.
110
+ row = @db[:wallet_actions].where(txid: txid).first
111
+ raise WalletError, "Action not found: #{txid}" unless row
112
+
113
+ @db[:wallet_actions].where(id: row[:id]).update(
114
+ data: Sequel.lit(
115
+ "data || jsonb_build_object('status', ?)",
116
+ new_status
117
+ )
118
+ )
119
+ symbolise_keys(@db[:wallet_actions].where(id: row[:id]).first[:data])
120
+ end
121
+
122
+ def delete_action(txid)
123
+ @db[:wallet_actions].where(txid: txid).delete.positive?
124
+ end
125
+
105
126
  # --- Outputs ---
106
127
 
107
128
  def store_output(output_data)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module BSV
4
4
  module WalletPostgres
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bsv-wallet-postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Bettison
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-04-11 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bsv-wallet
@@ -15,7 +15,7 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.4.0
18
+ version: 0.6.0
19
19
  - - "<"
20
20
  - !ruby/object:Gem::Version
21
21
  version: '1.0'
@@ -25,7 +25,7 @@ dependencies:
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 0.4.0
28
+ version: 0.6.0
29
29
  - - "<"
30
30
  - !ruby/object:Gem::Version
31
31
  version: '1.0'
@@ -71,6 +71,7 @@ files:
71
71
  - lib/bsv/wallet_postgres/migrations/002_add_output_state.rb
72
72
  - lib/bsv/wallet_postgres/migrations/003_add_wallet_settings.rb
73
73
  - lib/bsv/wallet_postgres/migrations/004_add_pending_metadata.rb
74
+ - lib/bsv/wallet_postgres/migrations/005_add_txid_unique_index.rb
74
75
  - lib/bsv/wallet_postgres/postgres_store.rb
75
76
  - lib/bsv/wallet_postgres/version.rb
76
77
  homepage: https://github.com/sgbett/bsv-ruby-sdk
@@ -95,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
96
  - !ruby/object:Gem::Version
96
97
  version: '0'
97
98
  requirements: []
98
- rubygems_version: 3.6.2
99
+ rubygems_version: 4.0.10
99
100
  specification_version: 4
100
101
  summary: PostgreSQL storage adapter for bsv-wallet
101
102
  test_files: []