mastercoin-ruby 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -48,7 +48,7 @@ module Mastercoin
48
48
  return @@storage
49
49
  end
50
50
 
51
- def self.init_logger(level = Logger::INFO)
51
+ def self.init_logger(level = Logger::DEBUG)
52
52
  @@log ||= Logger.new(STDOUT)
53
53
  @@log.level = level
54
54
  @@log
@@ -32,7 +32,8 @@ module Mastercoin
32
32
  end
33
33
 
34
34
  def encode_to_address
35
- 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")
35
+ self.sequence = self.get_sequence(self.receiving_address, true).to_i
36
+ raw = (self.sequence.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")
36
37
  Bitcoin.hash160_to_address(raw)
37
38
  end
38
39
 
@@ -46,13 +47,13 @@ module Mastercoin
46
47
  return simple_send
47
48
  end
48
49
 
49
- def get_sequence(bitcoin_address = nil)
50
+ def get_sequence(bitcoin_address = nil, encoding = false)
50
51
  bitcoin_address ||= self.receiving_address
51
- Mastercoin::Util.get_sequence(bitcoin_address)
52
+ Mastercoin::Util.get_sequence(bitcoin_address, encoding)
52
53
  end
53
54
 
54
55
  def looks_like_mastercoin?
55
- Mastercoin::TRANSACTION_TYPES.keys.include?(self.transaction_type.to_i.to_s) && Mastercoin::CURRENCY_IDS.keys.include?(self.currency_id.to_s)
56
+ Mastercoin::TRANSACTION_TYPES.keys.include?(self.transaction_type.to_i.to_s) && Mastercoin::CURRENCY_IDS.keys.include?(self.currency_id.to_s) && (self.amount / 1e8) < (563061 / 2)
56
57
  end
57
58
 
58
59
  def explain(sending_address = nil, target_address =nil)
@@ -55,26 +55,31 @@ module Mastercoin
55
55
  end
56
56
  end
57
57
  else
58
+ exodus_size_outputs = self.btc_tx.outputs.find_all{|x| x.value == exodus_value}
58
59
  self.btc_tx.outputs.each do |output|
59
60
  if output.get_address == Mastercoin::EXODUS_ADDRESS
60
61
  # Do nothing yet; this is simply the exodus address
61
62
  elsif Mastercoin::SimpleSend.decode_from_address(output.get_address).looks_like_mastercoin? # This looks like a data packet
63
+ Mastercoin.log.debug "Found data for address #{output.get_address}"
62
64
  self.data = Mastercoin::SimpleSend.decode_from_address(output.get_address)
63
65
  end
64
66
  end
65
67
 
66
- self.btc_tx.outputs.each do |output|
68
+ Mastercoin.log.debug "Looking for data sequence #{self.data.sequence} +1 == #{self.data.sequence.to_i + 1}"
69
+
70
+ exodus_size_outputs.each do |output|
67
71
  address = output.get_address
68
72
  sequence = Mastercoin::Util.get_sequence(address)
73
+ Mastercoin.log.debug "Sequence: #{sequence} for #{address}"
69
74
 
70
- if self.data.sequence.to_s == sequence.to_s
75
+ if (self.data.sequence.to_i + 1).to_s == sequence.to_s
71
76
  self.target_address = address
72
77
  end
73
78
  end
74
79
 
75
80
  unless self.target_address
76
81
  # Find data outputs and brute force receiver
77
- found = self.btc_tx.outputs.find_all{|x| x.value == exodus_value}.reject do |output|
82
+ found = exodus_size_outputs.reject do |output|
78
83
  output.get_address == Mastercoin::EXODUS_ADDRESS || Mastercoin::SimpleSend.decode_from_address(output.get_address).looks_like_mastercoin? # This looks like a data packet
79
84
  end
80
85
 
@@ -39,10 +39,14 @@ module Mastercoin
39
39
  return true
40
40
  end
41
41
 
42
- def self.get_sequence(bitcoin_address)
42
+ def self.get_sequence(bitcoin_address, encoding = false)
43
43
  decoded = Bitcoin.decode_base58(bitcoin_address)
44
+ seq = decoded[2..3].to_i(16)
45
+
46
+ if encoding
47
+ seq -= 1
48
+ end
44
49
 
45
- seq = decoded[2..3].to_i(16) - 1
46
50
  if seq < 0
47
51
  seq += 256
48
52
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "mastercoin-ruby"
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Maran"]
@@ -25,8 +25,13 @@ describe Mastercoin::SimpleSend do
25
25
  simple_send.transaction_type.should eq(0)
26
26
  end
27
27
 
28
+ it "Should encode proper sequences" do
29
+ address = @simple_send.encode_to_address
30
+ Mastercoin::Util.get_sequence(@simple_send.receiving_address).should eq(@simple_send.sequence + 1)
31
+ end
32
+
28
33
  it "Should be backwards compatible with sequences" do
29
- Mastercoin::SimpleSend.new.get_sequence("1CcJFxoEW5PUwesMVxGrq6kAPJ1TJsSVqq").should eq(126)
34
+ Mastercoin::SimpleSend.new.get_sequence("1CcJFxoEW5PUwesMVxGrq6kAPJ1TJsSVqq").should eq(127)
30
35
  end
31
36
  end
32
37
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mastercoin-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -194,7 +194,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
194
  version: '0'
195
195
  segments:
196
196
  - 0
197
- hash: -1178827526387473621
197
+ hash: -3636912781632535613
198
198
  required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  none: false
200
200
  requirements: