Class: Counterparty::CounterResource
- Inherits:
-
Object
- Object
- Counterparty::CounterResource
- Defined in:
- lib/counterparty/resource.rb
Overview
A base class for the purpose of extending by api result hashes
Direct Known Subclasses
BTCPay, Balance, Bet, BetExpiration, BetMatch, BetMatchExpiration, Broadcast, Burn, Callback, Cancel, Credit, Debit, Dividend, Execute, Issuance, Message, Order, OrderExpiration, OrderMatch, OrderMatchExpiration, Publish, Send
Class Attribute Summary collapse
-
.connection ⇒ Object
Returns the currently assigned connection object, or if one hasn’t been set, the default specified in the Counterparty module.
Instance Attribute Summary collapse
-
#allow_unconfirmed_inputs ⇒ Object
allow_unconfirmed_inputs (boolean): Set to true to allow this transaction to utilize unconfirmed UTXOs as inputs.
-
#encoding ⇒ Object
encoding (string): The encoding method to use.
-
#fee ⇒ Object
fee (integer): If you’d like to specify a custom miners’ fee, specify it here (in satoshi).
-
#fee_per_kb ⇒ Object
fee_per_kb (integer): The fee per kilobyte of transaction data constant that counterpartyd uses when deciding on the dynamic fee to use (in satoshi).
-
#pubkey ⇒ Object
pubkey (string): The pubkey hex string.
-
#result_attributes ⇒ Object
This is mostly used by the eq operation and indicates the attributes that this resource has.
Class Method Summary collapse
-
.api_name ⇒ Object
Returns the counterparty-api version of this objects class name.
-
.bitcoin ⇒ Object
Returns the currently assigned connection object, or if one hasn’t been set, the default specified in the Counterparty module.
-
.find(params) ⇒ Object
Queries the counterpartyd connection to find matching instances of this resource, given the filters provided in the params.
-
.to_create_request ⇒ Object
Returns the method name of a create_* request for this resource.
-
.to_get_request ⇒ Object
Returns the method name of a get_* request for this resource.
Instance Method Summary collapse
-
#==(b) ⇒ Object
Just a simple compare.
-
#initialize(attrs = {}) ⇒ CounterResource
constructor
A new instance of CounterResource.
-
#save!(private_key) ⇒ Object
Commit this object to the blockchain.
-
#to_raw_tx ⇒ Object
This method returns the unsigned raw create transaction string.
-
#to_signed_tx(private_key) ⇒ Object
Given the provided private key, this method returns a signed transaction suitable for broadcasting on the network.
Constructor Details
#initialize(attrs = {}) ⇒ CounterResource
Returns a new instance of CounterResource.
29 30 31 32 |
# File 'lib/counterparty/resource.rb', line 29 def initialize(attrs={}) @result_attributes = attrs.keys.sort.collect(&:to_sym) attrs.each{|k,v| instance_variable_set '@%s' % k, v} end |
Class Attribute Details
.connection ⇒ Object
Returns the currently assigned connection object, or if one hasn’t been set, the default specified in the Counterparty module
122 123 124 |
# File 'lib/counterparty/resource.rb', line 122 def connection @connection || Counterparty.connection end |
Instance Attribute Details
#allow_unconfirmed_inputs ⇒ Object
allow_unconfirmed_inputs (boolean): Set to true to allow this transaction to utilize unconfirmed UTXOs as inputs.
17 18 19 |
# File 'lib/counterparty/resource.rb', line 17 def allow_unconfirmed_inputs @allow_unconfirmed_inputs end |
#encoding ⇒ Object
encoding (string): The encoding method to use
9 10 11 |
# File 'lib/counterparty/resource.rb', line 9 def encoding @encoding end |
#fee ⇒ Object
fee (integer): If you’d like to specify a custom miners’ fee, specify it here (in satoshi). Leave as default for counterpartyd to automatically choose.
22 23 24 |
# File 'lib/counterparty/resource.rb', line 22 def fee @fee end |
#fee_per_kb ⇒ Object
fee_per_kb (integer): The fee per kilobyte of transaction data constant that counterpartyd uses when deciding on the dynamic fee to use (in satoshi). Leave as default unless you know what you’re doing.
27 28 29 |
# File 'lib/counterparty/resource.rb', line 27 def fee_per_kb @fee_per_kb end |
#pubkey ⇒ Object
pubkey (string): The pubkey hex string. Required if multisig transaction encoding is specified for a key external to counterpartyd’s local wallet.
13 14 15 |
# File 'lib/counterparty/resource.rb', line 13 def pubkey @pubkey end |
#result_attributes ⇒ Object
This is mostly used by the eq operation and indicates the attributes that this resource has
6 7 8 |
# File 'lib/counterparty/resource.rb', line 6 def result_attributes @result_attributes end |
Class Method Details
.api_name ⇒ Object
Returns the counterparty-api version of this objects class name
116 117 118 |
# File 'lib/counterparty/resource.rb', line 116 def api_name to_s.split('::').last.gsub(/[^\A]([A-Z])/, '_\\1').downcase end |
.bitcoin ⇒ Object
Returns the currently assigned connection object, or if one hasn’t been set, the default specified in the Counterparty module
128 129 130 |
# File 'lib/counterparty/resource.rb', line 128 def bitcoin @bitcoin || Counterparty.bitcoin end |
.find(params) ⇒ Object
Queries the counterpartyd connection to find matching instances of this resource, given the filters provided in the params
144 145 146 |
# File 'lib/counterparty/resource.rb', line 144 def find(params) connection.request(to_get_request, params).collect{|r| new r} end |
.to_create_request ⇒ Object
Returns the method name of a create_* request for this resource
133 134 135 |
# File 'lib/counterparty/resource.rb', line 133 def to_create_request 'create_%s' % api_name end |
.to_get_request ⇒ Object
Returns the method name of a get_* request for this resource
138 139 140 |
# File 'lib/counterparty/resource.rb', line 138 def to_get_request 'get_%ss' % api_name end |
Instance Method Details
#==(b) ⇒ Object
Just a simple compare. No need to get crazy
35 36 37 38 39 |
# File 'lib/counterparty/resource.rb', line 35 def ==(b) # :nodoc: ( b.respond_to?(:result_attributes) && result_attributes == b.result_attributes && @result_attributes.all?{ |k| send(k) == b.send(k) } ) end |
#save!(private_key) ⇒ Object
Commit this object to the blockchain. If a private key is passed, the transaction is signed using this key via a create_ call and a subsequent sign_tx call.
57 58 59 |
# File 'lib/counterparty/resource.rb', line 57 def save!(private_key) bitcoin.sendrawtransaction to_signed_tx(private_key) end |
#to_raw_tx ⇒ Object
This method returns the unsigned raw create transaction string. hex encoded (i.e. the same format that bitcoind returns with its raw transaction API calls).
44 45 46 |
# File 'lib/counterparty/resource.rb', line 44 def to_raw_tx connection.request self.class.to_create_request, to_params end |
#to_signed_tx(private_key) ⇒ Object
Given the provided private key, this method returns a signed transaction suitable for broadcasting on the network.
50 51 52 |
# File 'lib/counterparty/resource.rb', line 50 def to_signed_tx(private_key) sign_tx to_raw_tx, private_key end |