Class: Mastercoin::SimpleSend

Inherits:
Message
  • Object
show all
Defined in:
lib/mastercoin-ruby/simple_send.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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 = {}) ⇒ SimpleSend

Supply the amount in ‘dacoinminster’s



6
7
8
9
10
11
# File 'lib/mastercoin-ruby/simple_send.rb', line 6

def initialize(options= {})
  self.transaction_type = Mastercoin::TRANSACTION_SIMPLE_SEND
  self.currency_id = options[:currency_id]
  self.amount = options[:amount]
  self.receiving_address = options[:receiving_address]
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



3
4
5
# File 'lib/mastercoin-ruby/simple_send.rb', line 3

def amount
  @amount
end

#currency_idObject

Returns the value of attribute currency_id.



3
4
5
# File 'lib/mastercoin-ruby/simple_send.rb', line 3

def currency_id
  @currency_id
end

#receiving_addressObject

Returns the value of attribute receiving_address.



3
4
5
# File 'lib/mastercoin-ruby/simple_send.rb', line 3

def receiving_address
  @receiving_address
end

#sequenceObject

Returns the value of attribute sequence.



3
4
5
# File 'lib/mastercoin-ruby/simple_send.rb', line 3

def sequence
  @sequence
end

#transaction_typeObject

Returns the value of attribute transaction_type.



3
4
5
# File 'lib/mastercoin-ruby/simple_send.rb', line 3

def transaction_type
  @transaction_type
end

Class Method Details

.decode_from_address(raw_address) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/mastercoin-ruby/simple_send.rb', line 39

def self.decode_from_address(raw_address)
  simple_send = Mastercoin::SimpleSend.new
  decoded = Bitcoin.decode_base58(raw_address)
  simple_send.sequence = decoded[2..3].to_i(16)
  simple_send.transaction_type = decoded[4..11].to_i(16)
  simple_send.currency_id = decoded[12..19].to_i(16)
  simple_send.amount = decoded[20..35].to_i(16)
  return simple_send
end

.decode_key_to_data(public_key) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/mastercoin-ruby/simple_send.rb', line 19

def self.decode_key_to_data(public_key)
  simple_send = SimpleSend.new
  simple_send.transaction_type = public_key[2..9]#Mastercoin::TRANSACTION_SIMPLE_SEND
  simple_send.currency_id = public_key[10..17].to_i(16)
  simple_send.amount = public_key[18..33].to_i(16)
  simple_send.sequence = public_key[0..1].to_i(16)
  return simple_send
end

Instance Method Details

#currency_id_textObject



62
63
64
# File 'lib/mastercoin-ruby/simple_send.rb', line 62

def currency_id_text
  Mastercoin::CURRENCY_IDS[self.currency_id.to_s]
end

#encode_data_to_keyObject



28
29
30
31
32
# File 'lib/mastercoin-ruby/simple_send.rb', line 28

def encode_data_to_key
  raw = (self.public_key_sequence.to_i.to_s(16).rjust(2, "0") + 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"))
  raw = raw.ljust(62,"0")
  return raw
end

#encode_to_addressObject



34
35
36
37
# File 'lib/mastercoin-ruby/simple_send.rb', line 34

def encode_to_address
  raw = (self.get_sequence.to_i.to_s(16).rjust(2, "0") + 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") + "000000")
  Bitcoin.hash160_to_address(raw)
end

#explain(sending_address = nil, target_address = nil) ⇒ Object



58
59
60
# File 'lib/mastercoin-ruby/simple_send.rb', line 58

def explain(sending_address = nil, target_address =nil)
  "SimpleSend transaction from #{sending_address} for %.8f #{self.currency_id_text} to #{self.receiving_address || target_address}." % (self.amount / 1e8)
end

#get_sequence(bitcoin_address = nil) ⇒ Object



49
50
51
52
# File 'lib/mastercoin-ruby/simple_send.rb', line 49

def get_sequence(bitcoin_address = nil)
  bitcoin_address ||= self.receiving_address
  Mastercoin::Util.get_sequence(bitcoin_address)
end

#looks_like_mastercoin?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/mastercoin-ruby/simple_send.rb', line 54

def looks_like_mastercoin?
  Mastercoin::TRANSACTION_TYPES.keys.include?(self.transaction_type.to_i.to_s) && Mastercoin::CURRENCY_IDS.keys.include?(self.currency_id.to_s)
end

#public_key_sequenceObject

hardcode the sequence for a public key simple send since it’s always fits inside a public key Please note that we start at 01 - 00 will generate unvalid ECDSA points somehow



15
16
17
# File 'lib/mastercoin-ruby/simple_send.rb', line 15

def public_key_sequence
  01
end