Class: OpenAssets::Provider::BitcoinCoreProvider
- Inherits:
-
BlockChainProviderBase
- Object
- BlockChainProviderBase
- OpenAssets::Provider::BitcoinCoreProvider
- Defined in:
- lib/openassets/provider/bitcoin_core_provider.rb
Overview
The implementation of BlockChain provider using Bitcoin Core.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#get_transaction(transaction_hash, verbose = 0) ⇒ String
Get raw transaction.
-
#initialize(config) ⇒ BitcoinCoreProvider
constructor
A new instance of BitcoinCoreProvider.
-
#list_unspent(addresses = [], min = 1, max = 9999999) ⇒ Object
Get an array of unspent transaction outputs belonging to this wallet.
-
#send_transaction(tx) ⇒ String
Validates a transaction and broadcasts it to the peer-to-peer network.
-
#sign_transaction(tx) ⇒ Bitcoin::Protocol::Tx
Signs a transaction in the serialized transaction format using private keys.
Constructor Details
#initialize(config) ⇒ BitcoinCoreProvider
Returns a new instance of BitcoinCoreProvider.
11 12 13 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 11 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 9 def config @config end |
Instance Method Details
#get_transaction(transaction_hash, verbose = 0) ⇒ String
Get raw transaction.
27 28 29 30 31 32 33 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 27 def get_transaction(transaction_hash, verbose = 0) begin request('getrawtransaction', transaction_hash, verbose) rescue OpenAssets::Provider::ApiError => e nil end end |
#list_unspent(addresses = [], min = 1, max = 9999999) ⇒ Object
Get an array of unspent transaction outputs belonging to this wallet.
19 20 21 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 19 def list_unspent(addresses = [], min = 1 , max = 9999999) request('listunspent', min, max, addresses) end |
#send_transaction(tx) ⇒ String
Validates a transaction and broadcasts it to the peer-to-peer network.
47 48 49 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 47 def send_transaction(tx) request('sendrawtransaction', tx) end |
#sign_transaction(tx) ⇒ Bitcoin::Protocol::Tx
Signs a transaction in the serialized transaction format using private keys.
38 39 40 41 42 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 38 def sign_transaction(tx) signed_tx = request('signrawtransaction', tx) raise OpenAssets::Error, 'Could not sign the transaction.' unless signed_tx['complete'] Bitcoin::Protocol::Tx.new(signed_tx['hex'].htb) end |