class Mastercoin::SellingOffer

Attributes

amount[RW]

14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3

bitcoin_amount[RW]

14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3

currency_id[RW]

14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3

time_limit[RW]

14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3

transaction_fee[RW]

14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3

transaction_type[RW]

14015bd586c0c7a28979ca294b114441f23bfc97be17cd6077b9e12e2709fec3

Public Class Methods

decode_key_to_data(keys) click to toggle source
# 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
new(options = {}) click to toggle source
# File lib/mastercoin-ruby/selling_offer.rb, line 8
def initialize(options = {})
  options.reverse_merge!({time_limit: 10, transaction_fee: 20000})
  self.transaction_type = Mastercoin::TRANSACTION_SELL_FOR_BITCOIN
  self.currency_id = options[:currency_id]
  self.amount = options[:amount]
  self.bitcoin_amount = options[:bitcoin_amount]
  self.time_limit = options[:time_limit]
  self.transaction_fee = options[:transaction_fee]
end

Public Instance Methods

encode_data_to_key() click to toggle source
# 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, address=nil) click to toggle source
# File lib/mastercoin-ruby/selling_offer.rb, line 42
def explain(sending_address, address=nil)
  "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