Class: Pochette::Backends::Base
- Inherits:
-
Object
- Object
- Pochette::Backends::Base
- Defined in:
- lib/pochette/backends/base.rb
Overview
All Pochette backends must conform to this interface.
Direct Known Subclasses
Instance Method Summary collapse
-
#balances_for(addresses, confirmations) ⇒ Object
Gets the total received, spent and balance for a list of addresses.
- #block_height ⇒ Object
-
#incoming_for(addresses, min_date) ⇒ Object
Lists all bitcoins received by a list of addresses after a given date.
-
#list_transactions(txids) ⇒ Object
Gets information for the given transactions returns a list of objects, like so: [ { hash: txid, version: 1, lock_time: 0, inputs: [ { prev_hash: txid, prev_index: 0, sequence: 0, script_sig: hex_signature }, … ], bin_outputs: [ { amount: amount (as satoshis), script_pubkey: hex_script }, … ] }.
-
#list_unspent(addresses) ⇒ Object
Get unspent utxos for the given addresses, returns a list of lists like so: [[address, txid, position (vout), amount (in satoshis)], …].
- #propagate(hex) ⇒ Object
- #pushtx(hex, options = { }) ⇒ Object
- #verify_signatures(hex, options = { }) ⇒ Object
Instance Method Details
#balances_for(addresses, confirmations) ⇒ Object
Gets the total received, spent and balance for a list of addresses. Confirmed balances are enforced to have a number of confirmation, appearing in a block is not enough. Returns a hash with: { address: [received, sent, total,
unconfirmed_received, unconfirmed_sent, unconfirmed_total],
...}
26 27 28 |
# File 'lib/pochette/backends/base.rb', line 26 def balances_for(addresses, confirmations) raise NotImplementedError end |
#block_height ⇒ Object
72 73 74 |
# File 'lib/pochette/backends/base.rb', line 72 def block_height raise NotImplementedError end |
#incoming_for(addresses, min_date) ⇒ Object
Lists all bitcoins received by a list of addresses after a given date. Includes both confirmed and unconfirmed transactions, unconfirmed transactions have a nil block height. Returns a list of lists as following:
amount: Amount received (in satoshis)
address: Public address receiving the amount.
txid: The hash for the transaction that received it.
confirmations: Transaction confirmations
output position: To disambiguate in case address received more than once.
sender addresses: Comma separated list of input addresses,
used to identify deposits from trusted parties.
can be used to identify deposits from trusted parties.
15 16 17 |
# File 'lib/pochette/backends/base.rb', line 15 def incoming_for(addresses, min_date) raise NotImplementedError end |
#list_transactions(txids) ⇒ Object
Gets information for the given transactions returns a list of objects, like so: [
{ hash: txid,
version: 1,
lock_time: 0,
inputs: [
{ prev_hash: txid,
prev_index: 0,
sequence: 0,
script_sig: hex_signature
},
...
],
bin_outputs: [
{ amount: amount (as satoshis),
script_pubkey: hex_script
},
...
]
}
58 59 60 |
# File 'lib/pochette/backends/base.rb', line 58 def list_transactions(txids) raise NotImplementedError end |
#list_unspent(addresses) ⇒ Object
Get unspent utxos for the given addresses, returns a list of lists like so:
- [address, txid, position (vout), amount (in satoshis)], …
33 34 35 |
# File 'lib/pochette/backends/base.rb', line 33 def list_unspent(addresses) raise NotImplementedError end |
#propagate(hex) ⇒ Object
68 69 70 |
# File 'lib/pochette/backends/base.rb', line 68 def propagate(hex) raise NotImplementedError end |
#pushtx(hex, options = { }) ⇒ Object
62 63 64 65 66 |
# File 'lib/pochette/backends/base.rb', line 62 def pushtx(hex, = { }) verify_signatures(hex, ) if [:verify_signatures] propagate(hex) Bitcoin::Protocol::Tx.new(hex.htb).hash end |
#verify_signatures(hex, options = { }) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pochette/backends/base.rb', line 76 def verify_signatures(hex, = { }) tx = Bitcoin::P::Tx.new(hex.htb) tx.inputs.each_with_index do |input, idx| prev_tx = list_transactions([ input.previous_output ]).first outputs = prev_tx[:bin_outputs] script_pubkey = outputs[input.prev_out_index][:script_pubkey].htb unless tx.verify_input_signature(idx, script_pubkey, Time.now.to_i, ) raise Pochette::InvalidSignatureError, "Signature for input #{idx} is invalid." end end true end |