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.
Constant Summary collapse
- RPC_API =
[ :addmultisigaddress, :addnode, :backupwallet, :bumpfee, :createmultisig, :createrawtransaction, :decoderawtransaction, :decodescript, :dumpprivkey, :dumpwallet, :encryptwallet, :estimatefee, :estimatepriority, :generate, :generatetoaddress, :getaccountaddress, :getaccount, :getaddednodeinfo, :getaddressesbyaccount, :getbalance, :getbestblockhash, :getblock, :getblockchaininfo, :getblockcount, :getblockhash, :getblockheader, :getchaintips, :getconnectioncount, :getdifficulty, :getmempoolancestors, :getmempooldescendants, :getmempoolentry, :clearbanned, :disconnectnode, :getgenerate, :gethashespersec, :getinfo, :getmempoolinfo, :getmininginfo, :getnettotals, :getnetworkhashps, :getnetworkinfo, :getnewaddress, :getpeerinfo, :getrawchangeaddress, :getrawmempool, :getrawtransaction, :getreceivedbyaccount, :getreceivedbyaddress, :gettransaction, :gettxout, :gettxoutproof, :gettxoutsetinfo, :preciousblock, :pruneblockchain, :getunconfirmedbalance, :getwalletinfo, :importmulti, :getwork, :help, :importaddress, :importprivkey, :importwallet, :importpubkey, :keypoolrefill, :listaccounts, :listaddressgroupings, :listlockunspent, :listreceivedbyaccount, :listreceivedbyaddress, :listsinceblock, :listtransactions, :listunspent, :lockunspent, :move, :ping, :prioritisetransaction, :sendfrom, :sendmany, :sendrawtransaction, :sendtoaddress, :setaccount, :setgenerate, :settxfee, :signmessage, :signrawtransaction, :stop, :submitblock, :validateaddress, :verifychain, :verifymessage, :verifytxoutproof, :walletlock, :walletpassphrase, :walletpassphrasechange, :listbanned, :setban, :setnetworkactive, :fundrawtransaction, :estimatesmartfee, :estimatesmartpriority, :signmessagewithprivkey, :abandontransaction, :addwitnessaddress, :importprunedfunds, :importpubkey, :removeprunedfunds ]
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.
-
#import_address(address) ⇒ Object
Adds an address or pubkey script to the wallet without the associated private key, allowing you to watch for transactions affecting that address or pubkey script without being able to spend any of its outputs.
-
#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.
- #method_missing(method, *params) ⇒ Object
-
#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.
29 30 31 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 29 def initialize(config) @config = config end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *params) ⇒ Object
75 76 77 78 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 75 def method_missing(method, *params) super unless RPC_API.include?(method) request(method, *params) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
27 28 29 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 27 def config @config end |
Instance Method Details
#get_transaction(transaction_hash, verbose = 0) ⇒ String
Get raw transaction.
45 46 47 48 49 50 51 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 45 def get_transaction(transaction_hash, verbose = 0) begin request('getrawtransaction', transaction_hash, verbose) rescue OpenAssets::Provider::ApiError => e nil end end |
#import_address(address) ⇒ Object
Adds an address or pubkey script to the wallet without the associated private key, allowing you to watch for transactions affecting that address or pubkey script without being able to spend any of its outputs.
71 72 73 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 71 def import_address(address) request('importaddress', address) end |
#list_unspent(addresses = [], min = 1, max = 9999999) ⇒ Object
Get an array of unspent transaction outputs belonging to this wallet.
37 38 39 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 37 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.
65 66 67 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 65 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.
56 57 58 59 60 |
# File 'lib/openassets/provider/bitcoin_core_provider.rb', line 56 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 |