bsv-wallet 0.3.4 → 0.5.0
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 +4 -4
- data/CHANGELOG-wallet.md +332 -0
- data/lib/bsv/wallet_interface/chain_provider.rb +14 -0
- data/lib/bsv/wallet_interface/change_generator.rb +192 -0
- data/lib/bsv/wallet_interface/coin_selector.rb +132 -0
- data/lib/bsv/wallet_interface/fee_estimator.rb +124 -0
- data/lib/bsv/wallet_interface/fee_model.rb +21 -0
- data/lib/bsv/wallet_interface/file_store.rb +39 -1
- data/lib/bsv/wallet_interface/memory_store.rb +166 -3
- data/lib/bsv/wallet_interface/null_chain_provider.rb +9 -1
- data/lib/bsv/wallet_interface/proto_wallet.rb +1 -1
- data/lib/bsv/wallet_interface/storage_adapter.rb +79 -0
- data/lib/bsv/wallet_interface/validators.rb +36 -7
- data/lib/bsv/wallet_interface/version.rb +1 -1
- data/lib/bsv/wallet_interface/wallet_client.rb +539 -11
- data/lib/bsv/wallet_interface/whats_on_chain_provider.rb +62 -0
- data/lib/bsv/wallet_interface.rb +8 -2
- metadata +11 -5
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BSV
|
|
4
|
+
module Wallet
|
|
5
|
+
# ChainProvider implementation backed by the WhatsOnChain public API.
|
|
6
|
+
#
|
|
7
|
+
# Delegates to {BSV::Network::WhatsOnChain} for all HTTP communication,
|
|
8
|
+
# adapting its responses to the {ChainProvider} contract.
|
|
9
|
+
#
|
|
10
|
+
# @example Use with WalletClient
|
|
11
|
+
# provider = BSV::Wallet::WhatsOnChainProvider.new(network: :main)
|
|
12
|
+
# wallet = BSV::Wallet::WalletClient.new(key, chain_provider: provider)
|
|
13
|
+
# wallet.sync_utxos
|
|
14
|
+
class WhatsOnChainProvider
|
|
15
|
+
include ChainProvider
|
|
16
|
+
|
|
17
|
+
# @param network [Symbol] :main (default) or :test
|
|
18
|
+
# @param http_client [#request, nil] injectable HTTP client for testing
|
|
19
|
+
def initialize(network: :main, http_client: nil)
|
|
20
|
+
woc_network = network == :main ? :mainnet : :testnet
|
|
21
|
+
@woc = BSV::Network::WhatsOnChain.new(network: woc_network, http_client: http_client)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Returns the current blockchain height.
|
|
25
|
+
# @return [Integer]
|
|
26
|
+
def get_height
|
|
27
|
+
raise NotImplementedError, 'WhatsOnChainProvider#get_height not yet implemented'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Returns the block header at the given height.
|
|
31
|
+
# @param _height [Integer] block height
|
|
32
|
+
# @return [String] 80-byte hex-encoded block header
|
|
33
|
+
def get_header(_height)
|
|
34
|
+
raise NotImplementedError, 'WhatsOnChainProvider#get_header not yet implemented'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Returns unspent transaction outputs for the given address.
|
|
38
|
+
#
|
|
39
|
+
# Delegates to {BSV::Network::WhatsOnChain#fetch_utxos} and normalises
|
|
40
|
+
# the result to plain hashes matching the ChainProvider contract.
|
|
41
|
+
#
|
|
42
|
+
# @param address [String] BSV address
|
|
43
|
+
# @return [Array<Hash>] array of hashes with :tx_hash, :tx_pos, :value keys
|
|
44
|
+
def get_utxos(address)
|
|
45
|
+
@woc.fetch_utxos(address).map do |utxo|
|
|
46
|
+
{ tx_hash: utxo.tx_hash, tx_pos: utxo.tx_pos, value: utxo.satoshis }
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Returns the raw transaction hex for the given txid.
|
|
51
|
+
#
|
|
52
|
+
# Delegates to {BSV::Network::WhatsOnChain#fetch_transaction} and
|
|
53
|
+
# serialises the result back to hex.
|
|
54
|
+
#
|
|
55
|
+
# @param txid [String] transaction ID (hex)
|
|
56
|
+
# @return [String] raw transaction hex string
|
|
57
|
+
def get_transaction(txid)
|
|
58
|
+
@woc.fetch_transaction(txid).to_hex
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
data/lib/bsv/wallet_interface.rb
CHANGED
|
@@ -16,13 +16,19 @@ module BSV
|
|
|
16
16
|
autoload :FileStore, 'bsv/wallet_interface/file_store'
|
|
17
17
|
autoload :ProofStore, 'bsv/wallet_interface/proof_store'
|
|
18
18
|
autoload :LocalProofStore, 'bsv/wallet_interface/local_proof_store'
|
|
19
|
-
autoload :ChainProvider,
|
|
20
|
-
autoload :NullChainProvider,
|
|
19
|
+
autoload :ChainProvider, 'bsv/wallet_interface/chain_provider'
|
|
20
|
+
autoload :NullChainProvider, 'bsv/wallet_interface/null_chain_provider'
|
|
21
|
+
autoload :WhatsOnChainProvider, 'bsv/wallet_interface/whats_on_chain_provider'
|
|
21
22
|
autoload :WalletClient, 'bsv/wallet_interface/wallet_client'
|
|
22
23
|
autoload :Wire, 'bsv/wallet_interface/wire'
|
|
23
24
|
autoload :CertificateSignature, 'bsv/wallet_interface/certificate_signature'
|
|
25
|
+
autoload :FeeModel, 'bsv/wallet_interface/fee_model'
|
|
26
|
+
autoload :FeeEstimator, 'bsv/wallet_interface/fee_estimator'
|
|
27
|
+
autoload :CoinSelector, 'bsv/wallet_interface/coin_selector'
|
|
28
|
+
autoload :ChangeGenerator, 'bsv/wallet_interface/change_generator'
|
|
24
29
|
|
|
25
30
|
# Error classes
|
|
31
|
+
autoload :InsufficientFundsError, 'bsv/wallet/insufficient_funds_error'
|
|
26
32
|
autoload :WalletError, 'bsv/wallet_interface/errors/wallet_error'
|
|
27
33
|
autoload :InvalidParameterError, 'bsv/wallet_interface/errors/invalid_parameter_error'
|
|
28
34
|
autoload :InvalidHmacError, 'bsv/wallet_interface/errors/invalid_hmac_error'
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bsv-wallet
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Simon Bettison
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-04-
|
|
10
|
+
date: 2026-04-11 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: base64
|
|
@@ -29,7 +29,7 @@ dependencies:
|
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 0.
|
|
32
|
+
version: 0.9.0
|
|
33
33
|
- - "<"
|
|
34
34
|
- !ruby/object:Gem::Version
|
|
35
35
|
version: '1.0'
|
|
@@ -39,7 +39,7 @@ dependencies:
|
|
|
39
39
|
requirements:
|
|
40
40
|
- - ">="
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: 0.
|
|
42
|
+
version: 0.9.0
|
|
43
43
|
- - "<"
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
45
|
version: '1.0'
|
|
@@ -49,16 +49,21 @@ executables: []
|
|
|
49
49
|
extensions: []
|
|
50
50
|
extra_rdoc_files: []
|
|
51
51
|
files:
|
|
52
|
+
- CHANGELOG-wallet.md
|
|
52
53
|
- LICENSE
|
|
53
54
|
- lib/bsv-wallet.rb
|
|
54
55
|
- lib/bsv/wallet_interface.rb
|
|
55
56
|
- lib/bsv/wallet_interface/certificate_signature.rb
|
|
56
57
|
- lib/bsv/wallet_interface/chain_provider.rb
|
|
58
|
+
- lib/bsv/wallet_interface/change_generator.rb
|
|
59
|
+
- lib/bsv/wallet_interface/coin_selector.rb
|
|
57
60
|
- lib/bsv/wallet_interface/errors/invalid_hmac_error.rb
|
|
58
61
|
- lib/bsv/wallet_interface/errors/invalid_parameter_error.rb
|
|
59
62
|
- lib/bsv/wallet_interface/errors/invalid_signature_error.rb
|
|
60
63
|
- lib/bsv/wallet_interface/errors/unsupported_action_error.rb
|
|
61
64
|
- lib/bsv/wallet_interface/errors/wallet_error.rb
|
|
65
|
+
- lib/bsv/wallet_interface/fee_estimator.rb
|
|
66
|
+
- lib/bsv/wallet_interface/fee_model.rb
|
|
62
67
|
- lib/bsv/wallet_interface/file_store.rb
|
|
63
68
|
- lib/bsv/wallet_interface/interface.rb
|
|
64
69
|
- lib/bsv/wallet_interface/key_deriver.rb
|
|
@@ -71,6 +76,7 @@ files:
|
|
|
71
76
|
- lib/bsv/wallet_interface/validators.rb
|
|
72
77
|
- lib/bsv/wallet_interface/version.rb
|
|
73
78
|
- lib/bsv/wallet_interface/wallet_client.rb
|
|
79
|
+
- lib/bsv/wallet_interface/whats_on_chain_provider.rb
|
|
74
80
|
- lib/bsv/wallet_interface/wire.rb
|
|
75
81
|
- lib/bsv/wallet_interface/wire/reader.rb
|
|
76
82
|
- lib/bsv/wallet_interface/wire/serializer.rb
|
|
@@ -81,7 +87,7 @@ licenses:
|
|
|
81
87
|
metadata:
|
|
82
88
|
homepage_uri: https://github.com/sgbett/bsv-ruby-sdk
|
|
83
89
|
source_code_uri: https://github.com/sgbett/bsv-ruby-sdk
|
|
84
|
-
changelog_uri: https://github.com/sgbett/bsv-ruby-sdk/blob/master/CHANGELOG.md
|
|
90
|
+
changelog_uri: https://github.com/sgbett/bsv-ruby-sdk/blob/master/CHANGELOG-wallet.md
|
|
85
91
|
rubygems_mfa_required: 'true'
|
|
86
92
|
rdoc_options: []
|
|
87
93
|
require_paths:
|