bitcoin-ruby 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +0 -1
 - data/.travis.yml +4 -0
 - data/README.rdoc +5 -2
 - data/lib/bitcoin.rb +19 -5
 - data/lib/bitcoin/ffi/openssl.rb +5 -1
 - data/lib/bitcoin/protocol/tx.rb +19 -18
 - data/lib/bitcoin/protocol/txin.rb +2 -0
 - data/lib/bitcoin/script.rb +34 -5
 - data/lib/bitcoin/storage/storage.rb +3 -4
 - data/lib/bitcoin/version.rb +1 -1
 - data/spec/bitcoin/bitcoin_spec.rb +10 -0
 - data/spec/bitcoin/fixtures/tx-9fb65b7304aaa77ac9580823c2c06b259cc42591e5cce66d76a81b6f51cc5c28.json +23 -0
 - data/spec/bitcoin/fixtures/tx-a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954.json +30 -0
 - data/spec/bitcoin/protocol/tx_spec.rb +9 -2
 - data/spec/bitcoin/protocol/txin_spec.rb +18 -0
 - metadata +9 -2
 
    
        data/.gitignore
    CHANGED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/README.rdoc
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            = Bitcoin-ruby
         
     | 
| 
      
 1 
     | 
    
         
            +
            = Bitcoin-ruby {<img src="https://api.travis-ci.org/lian/bitcoin-ruby.png?branch=master" />}[http://travis-ci.org/lian/bitcoin-ruby]
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            This is a ruby library for interacting with the bitcoin protocol/network.
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
         @@ -30,7 +30,7 @@ We assume you already have a ruby 1.9 or 2.0 compatible interpreter and rubygems 
     | 
|
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
            if you want to have it available system-wide, just build the gem and install it:
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
             gem build bitcoin-ruby.gemspec && gem install bitcoin-ruby-0.0. 
     | 
| 
      
 33 
     | 
    
         
            +
             gem build bitcoin-ruby.gemspec && gem install bitcoin-ruby-0.0.2.gem
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
            now you can just call +bitcoin_node+ from anywhere.
         
     | 
| 
       36 
36 
     | 
    
         | 
| 
         @@ -45,6 +45,9 @@ intentionally kept to a minimum, so nobody has to install unneeded dependencies. 
     | 
|
| 
       45 
45 
     | 
    
         
             
            * +gir_ffi+ for the gui
         
     | 
| 
       46 
46 
     | 
    
         
             
            * +bacon+ to run the specs
         
     | 
| 
       47 
47 
     | 
    
         | 
| 
      
 48 
     | 
    
         
            +
            If you would like to install using Bundler, put it in your Gemfile and run bundle install
         
     | 
| 
      
 49 
     | 
    
         
            +
             gem 'bitcoin-ruby', git: 'https://github.com/lian/bitcoin-ruby', branch: 'master', require: 'bitcoin'
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
       48 
51 
     | 
    
         
             
            == Client
         
     | 
| 
       49 
52 
     | 
    
         | 
| 
       50 
53 
     | 
    
         
             
            There is a node which connects to the network and downloads
         
     | 
    
        data/lib/bitcoin.rb
    CHANGED
    
    | 
         @@ -112,7 +112,15 @@ module Bitcoin 
     | 
|
| 
       112 
112 
     | 
    
         
             
                end
         
     | 
| 
       113 
113 
     | 
    
         | 
| 
       114 
114 
     | 
    
         
             
                def hash160_to_address(hex)
         
     | 
| 
       115 
     | 
    
         
            -
                  hex  
     | 
| 
      
 115 
     | 
    
         
            +
                  encode_address hex, address_version
         
     | 
| 
      
 116 
     | 
    
         
            +
                end
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
                def hash160_to_p2sh_address(hex)
         
     | 
| 
      
 119 
     | 
    
         
            +
                  encode_address hex, p2sh_version
         
     | 
| 
      
 120 
     | 
    
         
            +
                end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
                def encode_address(hex, version)
         
     | 
| 
      
 123 
     | 
    
         
            +
                  hex = version + hex
         
     | 
| 
       116 
124 
     | 
    
         
             
                  encode_base58(hex + checksum(hex))
         
     | 
| 
       117 
125 
     | 
    
         
             
                end
         
     | 
| 
       118 
126 
     | 
    
         | 
| 
         @@ -448,7 +456,7 @@ module Bitcoin 
     | 
|
| 
       448 
456 
     | 
    
         
             
                  :retarget_interval => 2016,
         
     | 
| 
       449 
457 
     | 
    
         
             
                  :retarget_time => 1209600, # 2 weeks
         
     | 
| 
       450 
458 
     | 
    
         
             
                  :max_money => 21_000_000 * COIN,
         
     | 
| 
       451 
     | 
    
         
            -
                  :min_tx_fee =>  
     | 
| 
      
 459 
     | 
    
         
            +
                  :min_tx_fee => 10_000,
         
     | 
| 
       452 
460 
     | 
    
         
             
                  :min_relay_tx_fee => 10_000,
         
     | 
| 
       453 
461 
     | 
    
         
             
                  :dns_seeds => [
         
     | 
| 
       454 
462 
     | 
    
         
             
                    "seed.bitcoin.sipa.be",
         
     | 
| 
         @@ -492,7 +500,13 @@ module Bitcoin 
     | 
|
| 
       492 
500 
     | 
    
         
             
                  :proof_of_work_limit => 0x1d07fff8,
         
     | 
| 
       493 
501 
     | 
    
         
             
                  :alert_pubkeys => ["04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a"],
         
     | 
| 
       494 
502 
     | 
    
         
             
                  :known_nodes => [],
         
     | 
| 
       495 
     | 
    
         
            -
                  :checkpoints => {}
         
     | 
| 
      
 503 
     | 
    
         
            +
                  :checkpoints => {},
         
     | 
| 
      
 504 
     | 
    
         
            +
                  :coinbase_maturity => 100,
         
     | 
| 
      
 505 
     | 
    
         
            +
                  :retarget_interval => 2016,
         
     | 
| 
      
 506 
     | 
    
         
            +
                  :retarget_time => 1209600, # 2 weeks
         
     | 
| 
      
 507 
     | 
    
         
            +
                  :max_money => 21_000_000 * COIN,
         
     | 
| 
      
 508 
     | 
    
         
            +
                  :min_tx_fee => 10_000,
         
     | 
| 
      
 509 
     | 
    
         
            +
                  :min_relay_tx_fee => 10_000,
         
     | 
| 
       496 
510 
     | 
    
         
             
                },
         
     | 
| 
       497 
511 
     | 
    
         | 
| 
       498 
512 
     | 
    
         
             
                :testnet3 => {
         
     | 
| 
         @@ -507,7 +521,7 @@ module Bitcoin 
     | 
|
| 
       507 
521 
     | 
    
         
             
                  :retarget_interval => 2016,
         
     | 
| 
       508 
522 
     | 
    
         
             
                  :retarget_time => 1209600, # 2 weeks
         
     | 
| 
       509 
523 
     | 
    
         
             
                  :max_money => 21_000_000 * COIN,
         
     | 
| 
       510 
     | 
    
         
            -
                  :min_tx_fee =>  
     | 
| 
      
 524 
     | 
    
         
            +
                  :min_tx_fee => 10_000,
         
     | 
| 
       511 
525 
     | 
    
         
             
                  :min_relay_tx_fee => 10_000,
         
     | 
| 
       512 
526 
     | 
    
         
             
                  :dns_seeds => [
         
     | 
| 
       513 
527 
     | 
    
         
             
                    "testnet-seed.bitcoin.petertodd.org",
         
     | 
| 
         @@ -529,7 +543,7 @@ module Bitcoin 
     | 
|
| 
       529 
543 
     | 
    
         
             
                  :magic_head => "\xfb\xc0\xb6\xdb",
         
     | 
| 
       530 
544 
     | 
    
         
             
                  :address_version => "30",
         
     | 
| 
       531 
545 
     | 
    
         
             
                  :p2sh_version => "05",
         
     | 
| 
       532 
     | 
    
         
            -
                  :privkey_version => " 
     | 
| 
      
 546 
     | 
    
         
            +
                  :privkey_version => "b0",
         
     | 
| 
       533 
547 
     | 
    
         
             
                  :default_port => 9333,
         
     | 
| 
       534 
548 
     | 
    
         
             
                  :protocol_version => 60002,
         
     | 
| 
       535 
549 
     | 
    
         
             
                  :max_money => 84_000_000 * COIN,
         
     | 
    
        data/lib/bitcoin/ffi/openssl.rb
    CHANGED
    
    | 
         @@ -8,7 +8,11 @@ Bitcoin.require_dependency :ffi, exit: false, message: "Skipping FFI needed for 
     | 
|
| 
       8 
8 
     | 
    
         
             
            module Bitcoin
         
     | 
| 
       9 
9 
     | 
    
         
             
            module OpenSSL_EC
         
     | 
| 
       10 
10 
     | 
    
         
             
              extend FFI::Library
         
     | 
| 
       11 
     | 
    
         
            -
               
     | 
| 
      
 11 
     | 
    
         
            +
              if FFI::Platform.windows?
         
     | 
| 
      
 12 
     | 
    
         
            +
                ffi_lib 'libeay32', 'ssleay32'
         
     | 
| 
      
 13 
     | 
    
         
            +
              else
         
     | 
| 
      
 14 
     | 
    
         
            +
                ffi_lib 'ssl'
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
       12 
16 
     | 
    
         | 
| 
       13 
17 
     | 
    
         
             
              NID_secp256k1 = 714
         
     | 
| 
       14 
18 
     | 
    
         
             
              POINT_CONVERSION_COMPRESSED = 2
         
     | 
    
        data/lib/bitcoin/protocol/tx.rb
    CHANGED
    
    | 
         @@ -219,32 +219,33 @@ module Bitcoin 
     | 
|
| 
       219 
219 
     | 
    
         
             
                    @validator ||= Bitcoin::Validation::Tx.new(self, store, block)
         
     | 
| 
       220 
220 
     | 
    
         
             
                  end
         
     | 
| 
       221 
221 
     | 
    
         | 
| 
       222 
     | 
    
         
            -
                   
     | 
| 
       223 
     | 
    
         
            -
                  def minimum_block_fee; calculate_minimum_fee(1_000, true, :block); end
         
     | 
| 
      
 222 
     | 
    
         
            +
                  DEFAULT_BLOCK_PRIORITY_SIZE = 27000
         
     | 
| 
       224 
223 
     | 
    
         | 
| 
       225 
     | 
    
         
            -
                  def calculate_minimum_fee( 
     | 
| 
       226 
     | 
    
         
            -
             
     | 
| 
       227 
     | 
    
         
            -
             
     | 
| 
       228 
     | 
    
         
            -
             
     | 
| 
       229 
     | 
    
         
            -
                     
     | 
| 
      
 224 
     | 
    
         
            +
                  def minimum_relay_fee; calculate_minimum_fee(allow_free=true, :relay); end
         
     | 
| 
      
 225 
     | 
    
         
            +
                  def minimum_block_fee; calculate_minimum_fee(allow_free=true, :block); end
         
     | 
| 
      
 226 
     | 
    
         
            +
             
     | 
| 
      
 227 
     | 
    
         
            +
                  def calculate_minimum_fee(allow_free=true, mode=:block)
         
     | 
| 
      
 228 
     | 
    
         
            +
                    # Base fee is either nMinTxFee or nMinRelayTxFee
         
     | 
| 
      
 229 
     | 
    
         
            +
                    base_fee  = (mode == :relay) ? Bitcoin.network[:min_relay_tx_fee] : Bitcoin.network[:min_tx_fee]
         
     | 
| 
      
 230 
     | 
    
         
            +
                    tx_size   = to_payload.bytesize
         
     | 
| 
      
 231 
     | 
    
         
            +
                    min_fee   = (1 + tx_size / 1_000) * base_fee
         
     | 
| 
       230 
232 
     | 
    
         | 
| 
       231 
233 
     | 
    
         
             
                    if allow_free
         
     | 
| 
       232 
     | 
    
         
            -
                       
     | 
| 
       233 
     | 
    
         
            -
             
     | 
| 
       234 
     | 
    
         
            -
                       
     | 
| 
       235 
     | 
    
         
            -
             
     | 
| 
       236 
     | 
    
         
            -
                       
     | 
| 
      
 234 
     | 
    
         
            +
                      # There is a free transaction area in blocks created by most miners,
         
     | 
| 
      
 235 
     | 
    
         
            +
                      # * If we are relaying we allow transactions up to DEFAULT_BLOCK_PRIORITY_SIZE - 1000
         
     | 
| 
      
 236 
     | 
    
         
            +
                      #   to be considered to fall into this category. We don't want to encourage sending
         
     | 
| 
      
 237 
     | 
    
         
            +
                      #   multiple transactions instead of one big transaction to avoid fees.
         
     | 
| 
      
 238 
     | 
    
         
            +
                      # * If we are creating a transaction we allow transactions up to 1,000 bytes
         
     | 
| 
      
 239 
     | 
    
         
            +
                      #   to be considered safe and assume they can likely make it into this section.
         
     | 
| 
      
 240 
     | 
    
         
            +
                      min_fee = 0 if tx_size < (mode == :block ? 1_000 : DEFAULT_BLOCK_PRIORITY_SIZE - 1_000)
         
     | 
| 
       237 
241 
     | 
    
         
             
                    end
         
     | 
| 
       238 
242 
     | 
    
         | 
| 
       239 
     | 
    
         
            -
                     
     | 
| 
      
 243 
     | 
    
         
            +
                    # This code can be removed after enough miners have upgraded to version 0.9.
         
     | 
| 
      
 244 
     | 
    
         
            +
                    # Until then, be safe when sending and require a fee if any output is less than CENT
         
     | 
| 
      
 245 
     | 
    
         
            +
                    if min_fee < base_fee && mode == :block
         
     | 
| 
       240 
246 
     | 
    
         
             
                      outputs.each{|output| (min_fee = base_fee; break) if output.value < Bitcoin::CENT }
         
     | 
| 
       241 
247 
     | 
    
         
             
                    end
         
     | 
| 
       242 
248 
     | 
    
         | 
| 
       243 
     | 
    
         
            -
                    if block_size != 1 && new_block_size >= (Bitcoin::MAX_BLOCK_SIZE_GEN/2)
         
     | 
| 
       244 
     | 
    
         
            -
                      #return Bitcoin::network[:max_money] if new_block_size >= Bitcoin::MAX_BLOCK_SIZE_GEN
         
     | 
| 
       245 
     | 
    
         
            -
                      min_fee *= Bitcoin::MAX_BLOCK_SIZE_GEN / (Bitcoin::MAX_BLOCK_SIZE_GEN - new_block_size)
         
     | 
| 
       246 
     | 
    
         
            -
                    end
         
     | 
| 
       247 
     | 
    
         
            -
             
     | 
| 
       248 
249 
     | 
    
         
             
                    min_fee = Bitcoin::network[:max_money] unless min_fee.between?(0, Bitcoin::network[:max_money])
         
     | 
| 
       249 
250 
     | 
    
         
             
                    min_fee
         
     | 
| 
       250 
251 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/bitcoin/script.rb
    CHANGED
    
    | 
         @@ -992,8 +992,14 @@ class Bitcoin::Script 
     | 
|
| 
       992 
992 
     | 
    
         
             
              def op_checksig(check_callback)
         
     | 
| 
       993 
993 
     | 
    
         
             
                return invalid if @stack.size < 2
         
     | 
| 
       994 
994 
     | 
    
         
             
                pubkey = @stack.pop
         
     | 
| 
      
 995 
     | 
    
         
            +
                #return (@stack << 0) unless Bitcoin::Script.is_canonical_pubkey?(pubkey) # only for isStandard
         
     | 
| 
       995 
996 
     | 
    
         
             
                drop_sigs      = [ @stack[-1] ]
         
     | 
| 
       996 
     | 
    
         
            -
             
     | 
| 
      
 997 
     | 
    
         
            +
             
     | 
| 
      
 998 
     | 
    
         
            +
                signature = cast_to_string(@stack.pop)
         
     | 
| 
      
 999 
     | 
    
         
            +
                #return (@stack << 0) unless Bitcoin::Script.is_canonical_signature?(signature) # only for isStandard
         
     | 
| 
      
 1000 
     | 
    
         
            +
                return (@stack << 0) if signature == ""
         
     | 
| 
      
 1001 
     | 
    
         
            +
             
     | 
| 
      
 1002 
     | 
    
         
            +
                sig, hash_type = parse_sig(signature)
         
     | 
| 
       997 
1003 
     | 
    
         | 
| 
       998 
1004 
     | 
    
         
             
                if inner_p2sh?
         
     | 
| 
       999 
1005 
     | 
    
         
             
                  script_code = @inner_script_code || to_binary_without_signatures(drop_sigs)
         
     | 
| 
         @@ -1038,9 +1044,9 @@ class Bitcoin::Script 
     | 
|
| 
       1038 
1044 
     | 
    
         
             
                n_sigs = pop_int
         
     | 
| 
       1039 
1045 
     | 
    
         
             
                return invalid  unless (0..n_pubkeys).include?(n_sigs)
         
     | 
| 
       1040 
1046 
     | 
    
         
             
                return invalid  unless @stack.last(n_sigs).all?{|e| e.is_a?(String) && e != '' }
         
     | 
| 
       1041 
     | 
    
         
            -
                sigs =  
     | 
| 
      
 1047 
     | 
    
         
            +
                sigs = drop_sigs = pop_string(n_sigs)
         
     | 
| 
       1042 
1048 
     | 
    
         | 
| 
       1043 
     | 
    
         
            -
                @stack.pop if @stack[-1] ==  
     | 
| 
      
 1049 
     | 
    
         
            +
                @stack.pop if @stack[-1] && cast_to_bignum(@stack[-1]) == 0 # remove OP_0 from stack
         
     | 
| 
       1044 
1050 
     | 
    
         | 
| 
       1045 
1051 
     | 
    
         
             
                if inner_p2sh?
         
     | 
| 
       1046 
1052 
     | 
    
         
             
                  script_code = @inner_script_code || to_binary_without_signatures(drop_sigs)
         
     | 
| 
         @@ -1050,8 +1056,10 @@ class Bitcoin::Script 
     | 
|
| 
       1050 
1056 
     | 
    
         
             
                end
         
     | 
| 
       1051 
1057 
     | 
    
         | 
| 
       1052 
1058 
     | 
    
         
             
                valid_sigs = 0
         
     | 
| 
       1053 
     | 
    
         
            -
                sigs.each{|sig 
     | 
| 
       1054 
     | 
    
         
            -
                     
     | 
| 
      
 1059 
     | 
    
         
            +
                sigs.each{|sig| pubkeys.each{|pubkey|
         
     | 
| 
      
 1060 
     | 
    
         
            +
                    next if sig == ""
         
     | 
| 
      
 1061 
     | 
    
         
            +
                    signature, hash_type = parse_sig(sig)
         
     | 
| 
      
 1062 
     | 
    
         
            +
                    valid_sigs += 1  if check_callback.call(pubkey, signature, hash_type, drop_sigs, script_code)
         
     | 
| 
       1055 
1063 
     | 
    
         
             
                  }}
         
     | 
| 
       1056 
1064 
     | 
    
         | 
| 
       1057 
1065 
     | 
    
         
             
                @stack << ((valid_sigs >= n_sigs) ? 1 : (invalid; 0))
         
     | 
| 
         @@ -1081,6 +1089,27 @@ class Bitcoin::Script 
     | 
|
| 
       1081 
1089 
     | 
    
         
             
                true
         
     | 
| 
       1082 
1090 
     | 
    
         
             
              end
         
     | 
| 
       1083 
1091 
     | 
    
         | 
| 
      
 1092 
     | 
    
         
            +
             
     | 
| 
      
 1093 
     | 
    
         
            +
              SIGHASH_TYPE = { all: 1, none: 2, single: 3, anyonecanpay: 128 }
         
     | 
| 
      
 1094 
     | 
    
         
            +
             
     | 
| 
      
 1095 
     | 
    
         
            +
              def self.is_canonical_signature?(sig)
         
     | 
| 
      
 1096 
     | 
    
         
            +
                return false if sig.bytesize < 9 # Non-canonical signature: too short
         
     | 
| 
      
 1097 
     | 
    
         
            +
                return false if sig.bytesize > 73 # Non-canonical signature: too long
         
     | 
| 
      
 1098 
     | 
    
         
            +
             
     | 
| 
      
 1099 
     | 
    
         
            +
                s = sig.unpack("C*")
         
     | 
| 
      
 1100 
     | 
    
         
            +
             
     | 
| 
      
 1101 
     | 
    
         
            +
                hash_type = s[-1] & (~(SIGHASH_TYPE[:anyonecanpay]))
         
     | 
| 
      
 1102 
     | 
    
         
            +
                return false if hash_type < SIGHASH_TYPE[:all]   ||  hash_type > SIGHASH_TYPE[:single] # Non-canonical signature: unknown hashtype byte
         
     | 
| 
      
 1103 
     | 
    
         
            +
             
     | 
| 
      
 1104 
     | 
    
         
            +
                return false if s[0] != 0x30 # Non-canonical signature: wrong type
         
     | 
| 
      
 1105 
     | 
    
         
            +
                return false if s[1] != s.size-3 # Non-canonical signature: wrong length marker
         
     | 
| 
      
 1106 
     | 
    
         
            +
             
     | 
| 
      
 1107 
     | 
    
         
            +
                # TODO: add/port rest from bitcoind
         
     | 
| 
      
 1108 
     | 
    
         
            +
             
     | 
| 
      
 1109 
     | 
    
         
            +
                true
         
     | 
| 
      
 1110 
     | 
    
         
            +
              end
         
     | 
| 
      
 1111 
     | 
    
         
            +
             
     | 
| 
      
 1112 
     | 
    
         
            +
             
     | 
| 
       1084 
1113 
     | 
    
         
             
              private
         
     | 
| 
       1085 
1114 
     | 
    
         | 
| 
       1086 
1115 
     | 
    
         
             
              def parse_sig(sig)
         
     | 
| 
         @@ -276,14 +276,13 @@ module Bitcoin::Storage 
     | 
|
| 
       276 
276 
     | 
    
         
             
                  def get_locator pointer = get_head
         
     | 
| 
       277 
277 
     | 
    
         
             
                    if @locator
         
     | 
| 
       278 
278 
     | 
    
         
             
                      locator, head = @locator
         
     | 
| 
       279 
     | 
    
         
            -
                      if head ==  
     | 
| 
      
 279 
     | 
    
         
            +
                      if head == pointer
         
     | 
| 
       280 
280 
     | 
    
         
             
                        return locator
         
     | 
| 
       281 
281 
     | 
    
         
             
                      end
         
     | 
| 
       282 
282 
     | 
    
         
             
                    end
         
     | 
| 
       283 
283 
     | 
    
         | 
| 
       284 
284 
     | 
    
         
             
                    return [("\x00"*32).hth]  if get_depth == -1
         
     | 
| 
       285 
     | 
    
         
            -
                    locator = []
         
     | 
| 
       286 
     | 
    
         
            -
                    step = 1
         
     | 
| 
      
 285 
     | 
    
         
            +
                    locator, step, orig_pointer = [], 1, pointer
         
     | 
| 
       287 
286 
     | 
    
         
             
                    while pointer && pointer.hash != Bitcoin::network[:genesis_hash]
         
     | 
| 
       288 
287 
     | 
    
         
             
                      locator << pointer.hash
         
     | 
| 
       289 
288 
     | 
    
         
             
                      depth = pointer.depth - step
         
     | 
| 
         @@ -294,7 +293,7 @@ module Bitcoin::Storage 
     | 
|
| 
       294 
293 
     | 
    
         
             
                      step *= 2  if locator.size > 10
         
     | 
| 
       295 
294 
     | 
    
         
             
                    end
         
     | 
| 
       296 
295 
     | 
    
         
             
                    locator << Bitcoin::network[:genesis_hash]
         
     | 
| 
       297 
     | 
    
         
            -
                    @locator = [locator,  
     | 
| 
      
 296 
     | 
    
         
            +
                    @locator = [locator, orig_pointer]
         
     | 
| 
       298 
297 
     | 
    
         
             
                    locator
         
     | 
| 
       299 
298 
     | 
    
         
             
                  end
         
     | 
| 
       300 
299 
     | 
    
         | 
    
        data/lib/bitcoin/version.rb
    CHANGED
    
    
| 
         @@ -24,6 +24,16 @@ describe 'Bitcoin Address/Hash160/PubKey' do 
     | 
|
| 
       24 
24 
     | 
    
         
             
                  .should == "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa"
         
     | 
| 
       25 
25 
     | 
    
         
             
              end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
      
 27 
     | 
    
         
            +
              it 'bitcoin p2sh address from bitcoin-hash160' do
         
     | 
| 
      
 28 
     | 
    
         
            +
                Bitcoin::network = :testnet
         
     | 
| 
      
 29 
     | 
    
         
            +
                Bitcoin.hash160_to_p2sh_address("d11e2f2f385efeecd30f867f1d55c0bc8a27f29e")
         
     | 
| 
      
 30 
     | 
    
         
            +
                  .should == "2NCJwNct2SVE5VwdrPXmnek59kCfdgCpxeF"
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                Bitcoin::network = :bitcoin
         
     | 
| 
      
 33 
     | 
    
         
            +
                Bitcoin.hash160_to_p2sh_address("d11e2f2f385efeecd30f867f1d55c0bc8a27f29e")
         
     | 
| 
      
 34 
     | 
    
         
            +
                  .should == "3LkjJswzq2ijJA1JiQ9v2o5tXrTTvPtAMe"
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
       27 
37 
     | 
    
         
             
              it 'bitcoin-hash160 from bitcoin-address' do
         
     | 
| 
       28 
38 
     | 
    
         
             
                Bitcoin::network = :testnet
         
     | 
| 
       29 
39 
     | 
    
         
             
                Bitcoin.hash160_from_address("mpXwg4jMtRhuSpVq4xS3HFHmCmWp9NyGKt")
         
     | 
    
        data/spec/bitcoin/fixtures/tx-9fb65b7304aaa77ac9580823c2c06b259cc42591e5cce66d76a81b6f51cc5c28.json
    ADDED
    
    | 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            {
         
     | 
| 
      
 2 
     | 
    
         
            +
              "hash":"9fb65b7304aaa77ac9580823c2c06b259cc42591e5cce66d76a81b6f51cc5c28",
         
     | 
| 
      
 3 
     | 
    
         
            +
              "ver":1,
         
     | 
| 
      
 4 
     | 
    
         
            +
              "vin_sz":1,
         
     | 
| 
      
 5 
     | 
    
         
            +
              "vout_sz":1,
         
     | 
| 
      
 6 
     | 
    
         
            +
              "lock_time":0,
         
     | 
| 
      
 7 
     | 
    
         
            +
              "size":235,
         
     | 
| 
      
 8 
     | 
    
         
            +
              "in":[
         
     | 
| 
      
 9 
     | 
    
         
            +
                {
         
     | 
| 
      
 10 
     | 
    
         
            +
                  "prev_out":{
         
     | 
| 
      
 11 
     | 
    
         
            +
                    "hash":"a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954",
         
     | 
| 
      
 12 
     | 
    
         
            +
                    "n":0
         
     | 
| 
      
 13 
     | 
    
         
            +
                  },
         
     | 
| 
      
 14 
     | 
    
         
            +
                  "scriptSig":"ca42095840735e89283fec298e62ac2ddea9b5f34a8cbb7097ad965b87568100 1b1b01dc829177da4a14551d2fc96a9db00c6501edfa12f22cd9cefd335c227f 3045022100940a7a74d00d590dc6743c8d7416475845611047bed013db2c4f80c96261576a02202b223572a37c2eee65fefabf701b2f39e3df2cba5d136eef0485d9a24f49c0aa01 0"
         
     | 
| 
      
 15 
     | 
    
         
            +
                }
         
     | 
| 
      
 16 
     | 
    
         
            +
              ],
         
     | 
| 
      
 17 
     | 
    
         
            +
              "out":[
         
     | 
| 
      
 18 
     | 
    
         
            +
                {
         
     | 
| 
      
 19 
     | 
    
         
            +
                  "value":"0.00160000",
         
     | 
| 
      
 20 
     | 
    
         
            +
                  "scriptPubKey":"03611f9a45c18f28f06f19076ad571c344c82ce8fcfe34464cf8085217a2d294a6 OP_CHECKSIG"
         
     | 
| 
      
 21 
     | 
    
         
            +
                }
         
     | 
| 
      
 22 
     | 
    
         
            +
              ]
         
     | 
| 
      
 23 
     | 
    
         
            +
            }
         
     | 
    
        data/spec/bitcoin/fixtures/tx-a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954.json
    ADDED
    
    | 
         @@ -0,0 +1,30 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            {
         
     | 
| 
      
 2 
     | 
    
         
            +
              "hash":"a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954",
         
     | 
| 
      
 3 
     | 
    
         
            +
              "ver":1,
         
     | 
| 
      
 4 
     | 
    
         
            +
              "vin_sz":2,
         
     | 
| 
      
 5 
     | 
    
         
            +
              "vout_sz":1,
         
     | 
| 
      
 6 
     | 
    
         
            +
              "lock_time":0,
         
     | 
| 
      
 7 
     | 
    
         
            +
              "size":461,
         
     | 
| 
      
 8 
     | 
    
         
            +
              "in":[
         
     | 
| 
      
 9 
     | 
    
         
            +
                {
         
     | 
| 
      
 10 
     | 
    
         
            +
                  "prev_out":{
         
     | 
| 
      
 11 
     | 
    
         
            +
                    "hash":"4c1497075bfa37eb7a78493b948f9a66b65b81e55ebf8d79d504c5e03857fb8d",
         
     | 
| 
      
 12 
     | 
    
         
            +
                    "n":0
         
     | 
| 
      
 13 
     | 
    
         
            +
                  },
         
     | 
| 
      
 14 
     | 
    
         
            +
                  "scriptSig":"30450221009d124bdcf2aff61d649219ba3b8cc7f637e79f810b7da3ed6df8bdf6c025ddc0022004b7e3d1e4ca92bd8ece38fda3d698bdfa8ab89720fce6df6c014d83e25fe00001"
         
     | 
| 
      
 15 
     | 
    
         
            +
                },
         
     | 
| 
      
 16 
     | 
    
         
            +
                {
         
     | 
| 
      
 17 
     | 
    
         
            +
                  "prev_out":{
         
     | 
| 
      
 18 
     | 
    
         
            +
                    "hash":"2bba9900c0fe67ada751be0e3444be6bb696f473fe84b5b7b0d8f93df6c2b833",
         
     | 
| 
      
 19 
     | 
    
         
            +
                    "n":0
         
     | 
| 
      
 20 
     | 
    
         
            +
                  },
         
     | 
| 
      
 21 
     | 
    
         
            +
                  "scriptSig":"3045022100f665b25b0b14a2aca111dbc52ad1467b9cce69e822f6b7faba2091670b082d1b02202a360069da73a2b3aeb87d7c5645b91fc594e3067f24daefad0596e9ef18d0f801 1b1b01dc829177da4a14551d2fc96a9db00c6501edfa12f22cd9cefd335c227f"
         
     | 
| 
      
 22 
     | 
    
         
            +
                }
         
     | 
| 
      
 23 
     | 
    
         
            +
              ],
         
     | 
| 
      
 24 
     | 
    
         
            +
              "out":[
         
     | 
| 
      
 25 
     | 
    
         
            +
                {
         
     | 
| 
      
 26 
     | 
    
         
            +
                  "value":"0.00170000",
         
     | 
| 
      
 27 
     | 
    
         
            +
                  "scriptPubKey":"02085c6600657566acc2d6382a47bc3f324008d2aa10940dd7705a48aa2a5a5e33 OP_CHECKSIG OP_SWAP 03f5d0fb955f95dd6be6115ce85661db412ec6a08abcbfce7da0ba8297c6cc0ec4 OP_CHECKSIG OP_SWAP 3 OP_PICK OP_SHA256 d68df9e32a147cffa36193c6f7c43a1c8c69cda530e1c6db354bfabdcfefaf3c OP_EQUAL 3 OP_PICK OP_SHA256 f531f3041d3136701ea09067c53e7159c8f9b2746a56c3d82966c54bbc553226 OP_EQUAL OP_BOOLAND 4 OP_PICK OP_SIZE OP_NIP 20 22 OP_WITHIN OP_BOOLAND 3 OP_PICK OP_SIZE OP_NIP 20 22 OP_WITHIN OP_BOOLAND OP_IF 3 OP_PICK OP_SIZE OP_NIP 3 OP_PICK OP_SIZE OP_NIP OP_EQUAL OP_PICK OP_ELSE OP_BOOLAND OP_ENDIF"
         
     | 
| 
      
 28 
     | 
    
         
            +
                }
         
     | 
| 
      
 29 
     | 
    
         
            +
              ]
         
     | 
| 
      
 30 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -176,6 +176,13 @@ describe 'Tx' do 
     | 
|
| 
       176 
176 
     | 
    
         
             
                outpoint_tx = Bitcoin::P::Tx.from_json(fixtures_file('514c46f0b61714092f15c8dfcb576c9f79b3f959989b98de3944b19d98832b58.json'))
         
     | 
| 
       177 
177 
     | 
    
         
             
                outpoint_tx.hash.should == "514c46f0b61714092f15c8dfcb576c9f79b3f959989b98de3944b19d98832b58"
         
     | 
| 
       178 
178 
     | 
    
         
             
                tx.verify_input_signature(0, outpoint_tx).should == true
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
                # OP_CHECKSIG with OP_0 from mainnet a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954 output 0
         
     | 
| 
      
 181 
     | 
    
         
            +
                tx = Bitcoin::P::Tx.from_json(fixtures_file('tx-9fb65b7304aaa77ac9580823c2c06b259cc42591e5cce66d76a81b6f51cc5c28.json'))
         
     | 
| 
      
 182 
     | 
    
         
            +
                tx.hash.should == "9fb65b7304aaa77ac9580823c2c06b259cc42591e5cce66d76a81b6f51cc5c28"
         
     | 
| 
      
 183 
     | 
    
         
            +
                outpoint_tx = Bitcoin::P::Tx.from_json(fixtures_file('tx-a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954.json'))
         
     | 
| 
      
 184 
     | 
    
         
            +
                outpoint_tx.hash.should == "a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954"
         
     | 
| 
      
 185 
     | 
    
         
            +
                tx.verify_input_signature(0, outpoint_tx).should == true
         
     | 
| 
       179 
186 
     | 
    
         
             
              end
         
     | 
| 
       180 
187 
     | 
    
         | 
| 
       181 
188 
     | 
    
         
             
              it '#sign_input_signature' do
         
     | 
| 
         @@ -243,8 +250,8 @@ describe 'Tx' do 
     | 
|
| 
       243 
250 
     | 
    
         
             
                tx.minimum_relay_fee.should == 0
         
     | 
| 
       244 
251 
     | 
    
         
             
                tx.minimum_block_fee.should == 0
         
     | 
| 
       245 
252 
     | 
    
         
             
                tx = Tx.from_json(fixtures_file('bc179baab547b7d7c1d5d8d6f8b0cc6318eaa4b0dd0a093ad6ac7f5a1cb6b3ba.json'))
         
     | 
| 
       246 
     | 
    
         
            -
                tx.minimum_relay_fee.should ==  
     | 
| 
       247 
     | 
    
         
            -
                tx.minimum_block_fee.should ==  
     | 
| 
      
 253 
     | 
    
         
            +
                tx.minimum_relay_fee.should == 0
         
     | 
| 
      
 254 
     | 
    
         
            +
                tx.minimum_block_fee.should == 10_000
         
     | 
| 
       248 
255 
     | 
    
         
             
              end
         
     | 
| 
       249 
256 
     | 
    
         | 
| 
       250 
257 
     | 
    
         
             
              describe "Tx - BIP Scripts" do
         
     | 
| 
         @@ -0,0 +1,18 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # encoding: ascii-8bit
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative '../spec_helper.rb'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            include Bitcoin::Protocol
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            describe 'TxIn' do
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              describe '#initialize without specifying script_sig_length and script_sig' do
         
     | 
| 
      
 10 
     | 
    
         
            +
                it 'still creates a serializable TxIn' do
         
     | 
| 
      
 11 
     | 
    
         
            +
                  prev_tx = Tx.new fixtures_file('rawtx-01.bin')
         
     | 
| 
      
 12 
     | 
    
         
            +
                  tx_in = TxIn.new prev_tx.binary_hash, 0
         
     | 
| 
      
 13 
     | 
    
         
            +
                  lambda { tx_in.to_payload }.should.not.raise
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: bitcoin-ruby
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.3
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2013- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-12-04 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       14 
14 
     | 
    
         
             
            description: This is a ruby library for interacting with the bitcoin protocol/network
         
     | 
| 
       15 
15 
     | 
    
         
             
            email:
         
     | 
| 
         @@ -24,6 +24,7 @@ extensions: [] 
     | 
|
| 
       24 
24 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       25 
25 
     | 
    
         
             
            files:
         
     | 
| 
       26 
26 
     | 
    
         
             
            - .gitignore
         
     | 
| 
      
 27 
     | 
    
         
            +
            - .travis.yml
         
     | 
| 
       27 
28 
     | 
    
         
             
            - COPYING
         
     | 
| 
       28 
29 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       29 
30 
     | 
    
         
             
            - README.rdoc
         
     | 
| 
         @@ -184,6 +185,8 @@ files: 
     | 
|
| 
       184 
185 
     | 
    
         
             
            - spec/bitcoin/fixtures/tx-313897799b1e37e9ecae15010e56156dddde4e683c96b0e713af95272c38aee0.json
         
     | 
| 
       185 
186 
     | 
    
         
             
            - spec/bitcoin/fixtures/tx-3da75972766f0ad13319b0b461fd16823a731e44f6e9de4eb3c52d6a6fb6c8ae.json
         
     | 
| 
       186 
187 
     | 
    
         
             
            - spec/bitcoin/fixtures/tx-44b833074e671120ba33106877b49e86ece510824b9af477a3853972bcd8d06a.json
         
     | 
| 
      
 188 
     | 
    
         
            +
            - spec/bitcoin/fixtures/tx-9fb65b7304aaa77ac9580823c2c06b259cc42591e5cce66d76a81b6f51cc5c28.json
         
     | 
| 
      
 189 
     | 
    
         
            +
            - spec/bitcoin/fixtures/tx-a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954.json
         
     | 
| 
       187 
190 
     | 
    
         
             
            - spec/bitcoin/fixtures/tx-d3d77d63709e47d9ef58f0b557800115a6b676c6a423012fbb96f45d8fcef830.json
         
     | 
| 
       188 
191 
     | 
    
         
             
            - spec/bitcoin/fixtures/txdp-1.txt
         
     | 
| 
       189 
192 
     | 
    
         
             
            - spec/bitcoin/fixtures/txdp-2-signed.txt
         
     | 
| 
         @@ -201,6 +204,7 @@ files: 
     | 
|
| 
       201 
204 
     | 
    
         
             
            - spec/bitcoin/protocol/notfound_spec.rb
         
     | 
| 
       202 
205 
     | 
    
         
             
            - spec/bitcoin/protocol/ping_spec.rb
         
     | 
| 
       203 
206 
     | 
    
         
             
            - spec/bitcoin/protocol/tx_spec.rb
         
     | 
| 
      
 207 
     | 
    
         
            +
            - spec/bitcoin/protocol/txin_spec.rb
         
     | 
| 
       204 
208 
     | 
    
         
             
            - spec/bitcoin/protocol/version_spec.rb
         
     | 
| 
       205 
209 
     | 
    
         
             
            - spec/bitcoin/script/opcodes_spec.rb
         
     | 
| 
       206 
210 
     | 
    
         
             
            - spec/bitcoin/script/script_spec.rb
         
     | 
| 
         @@ -318,6 +322,8 @@ test_files: 
     | 
|
| 
       318 
322 
     | 
    
         
             
            - spec/bitcoin/fixtures/tx-313897799b1e37e9ecae15010e56156dddde4e683c96b0e713af95272c38aee0.json
         
     | 
| 
       319 
323 
     | 
    
         
             
            - spec/bitcoin/fixtures/tx-3da75972766f0ad13319b0b461fd16823a731e44f6e9de4eb3c52d6a6fb6c8ae.json
         
     | 
| 
       320 
324 
     | 
    
         
             
            - spec/bitcoin/fixtures/tx-44b833074e671120ba33106877b49e86ece510824b9af477a3853972bcd8d06a.json
         
     | 
| 
      
 325 
     | 
    
         
            +
            - spec/bitcoin/fixtures/tx-9fb65b7304aaa77ac9580823c2c06b259cc42591e5cce66d76a81b6f51cc5c28.json
         
     | 
| 
      
 326 
     | 
    
         
            +
            - spec/bitcoin/fixtures/tx-a6ce7081addade7676cd2af75c4129eba6bf5e179a19c40c7d4cf6a5fe595954.json
         
     | 
| 
       321 
327 
     | 
    
         
             
            - spec/bitcoin/fixtures/tx-d3d77d63709e47d9ef58f0b557800115a6b676c6a423012fbb96f45d8fcef830.json
         
     | 
| 
       322 
328 
     | 
    
         
             
            - spec/bitcoin/fixtures/txdp-1.txt
         
     | 
| 
       323 
329 
     | 
    
         
             
            - spec/bitcoin/fixtures/txdp-2-signed.txt
         
     | 
| 
         @@ -335,6 +341,7 @@ test_files: 
     | 
|
| 
       335 
341 
     | 
    
         
             
            - spec/bitcoin/protocol/notfound_spec.rb
         
     | 
| 
       336 
342 
     | 
    
         
             
            - spec/bitcoin/protocol/ping_spec.rb
         
     | 
| 
       337 
343 
     | 
    
         
             
            - spec/bitcoin/protocol/tx_spec.rb
         
     | 
| 
      
 344 
     | 
    
         
            +
            - spec/bitcoin/protocol/txin_spec.rb
         
     | 
| 
       338 
345 
     | 
    
         
             
            - spec/bitcoin/protocol/version_spec.rb
         
     | 
| 
       339 
346 
     | 
    
         
             
            - spec/bitcoin/script/opcodes_spec.rb
         
     | 
| 
       340 
347 
     | 
    
         
             
            - spec/bitcoin/script/script_spec.rb
         
     |