Class: Mastercoin::SellingOffer
- Defined in:
- lib/mastercoin-ruby/selling_offer.rb
Defined Under Namespace
Classes: CannotDecodeSellingOfferException
Instance Attribute Summary collapse
-
#amount ⇒ Object
14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3.
-
#bitcoin_amount ⇒ Object
14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3.
-
#currency_id ⇒ Object
14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3.
-
#time_limit ⇒ Object
14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3.
-
#transaction_fee ⇒ Object
14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3.
-
#transaction_type ⇒ Object
14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3.
Class Method Summary collapse
Instance Method Summary collapse
- #encode_data_to_key ⇒ Object
- #explain(sending_address) ⇒ Object
-
#initialize(options = {}) ⇒ SellingOffer
constructor
A new instance of SellingOffer.
Methods inherited from Message
decode, decode_from_compressed_public_key, #encode_to_compressed_public_key, #mangle_key_until_valid, probe, probe_and_read
Constructor Details
#initialize(options = {}) ⇒ SellingOffer
Returns a new instance of SellingOffer.
8 9 10 11 12 13 14 15 16 |
# File 'lib/mastercoin-ruby/selling_offer.rb', line 8 def initialize( = {}) .reverse_merge!({time_limit: 10, transaction_fee: 20000}) self.transaction_type = Mastercoin::TRANSACTION_SELL_FOR_BITCOIN self.currency_id = [:currency_id] self.amount = [:amount] self.bitcoin_amount = [:bitcoin_amount] self.time_limit = [:time_limit] self.transaction_fee = [:transaction_fee] end |
Instance Attribute Details
#amount ⇒ Object
14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3
6 7 8 |
# File 'lib/mastercoin-ruby/selling_offer.rb', line 6 def amount @amount end |
#bitcoin_amount ⇒ Object
14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3
6 7 8 |
# File 'lib/mastercoin-ruby/selling_offer.rb', line 6 def bitcoin_amount @bitcoin_amount end |
#currency_id ⇒ Object
14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3
6 7 8 |
# File 'lib/mastercoin-ruby/selling_offer.rb', line 6 def currency_id @currency_id end |
#time_limit ⇒ Object
14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3
6 7 8 |
# File 'lib/mastercoin-ruby/selling_offer.rb', line 6 def time_limit @time_limit end |
#transaction_fee ⇒ Object
14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3
6 7 8 |
# File 'lib/mastercoin-ruby/selling_offer.rb', line 6 def transaction_fee @transaction_fee end |
#transaction_type ⇒ Object
14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3
6 7 8 |
# File 'lib/mastercoin-ruby/selling_offer.rb', line 6 def transaction_type @transaction_type end |
Class Method Details
.decode_key_to_data(keys) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mastercoin-ruby/selling_offer.rb', line 18 def self.decode_key_to_data(keys) raise CannotDecodeSellingOfferException.new("Need an array of two public keys in order to decode Selling Offer") unless keys.is_a?(Array) || keys.count != 2 key = Mastercoin::Util.sort_and_strip_keys(keys).join offer = SellingOffer.new offer.transaction_type = key[0..7].to_i(16) offer.currency_id = key[8..15].to_i(16) offer.amount = key[16..31].to_i(16) offer.bitcoin_amount = key[32..47].to_i(16) offer.time_limit = key[48..49].to_i(16) offer.transaction_fee = key[50..65].to_i(16) offer end |
Instance Method Details
#encode_data_to_key ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/mastercoin-ruby/selling_offer.rb', line 33 def encode_data_to_key raw = self.transaction_type.to_i.to_s(16).rjust(8,"0") + self.currency_id.to_i.to_s(16).rjust(8, "0") + self.amount.to_i.to_s(16).rjust(16, "0") + self.bitcoin_amount.to_i.to_s(16).rjust(16, "0") + self.time_limit.to_i.to_s(16).rjust(2,"0") + self.transaction_fee.to_i.to_s(16).rjust(16,"0") raw = raw.ljust(120,"0") keys = raw.chars.each_slice(60).map(&:join) keys.each_with_index.collect do |key, index| "#{(index + 1).to_s(16).rjust(2,"0")}#{key}" end end |
#explain(sending_address) ⇒ Object
42 43 44 |
# File 'lib/mastercoin-ruby/selling_offer.rb', line 42 def explain(sending_address) "Selling Offer from #{sending_address} of #{(self.amount / 1e8).to_f} #{Mastercoin::CURRENCY_IDS[self.currency_id.to_s]} for #{(self.bitcoin_amount / 1e8).to_f} Bitcoins. Time limit #{self.time_limit}. BTC Fee #{self.transaction_fee}" end |