bc 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data.tar.gz.sig +0 -0
  2. data/lib/bc.rb +34 -1
  3. metadata +4 -4
  4. metadata.gz.sig +0 -0
data.tar.gz.sig CHANGED
Binary file
data/lib/bc.rb CHANGED
@@ -1,6 +1,22 @@
1
1
  # encoding: utf-8
2
+ require 'json/pure'
3
+ require 'net/http'
2
4
  require 'jr'
3
5
 
6
+ # This redefines Float() so that JSON floats will be returned as BigDecimals.
7
+ # This is neccessary because bitcoind returns Floats that are actually decimals
8
+ # with a precision of 8. FUCK YOU, bitcoind.
9
+ class JSON::Pure::Parser
10
+ private
11
+
12
+ def Float(num)
13
+ BigDecimal(num)
14
+ end
15
+ end
16
+
17
+ JSON.send(:remove_const, :Parser)
18
+ JSON::Parser = JSON::Pure::Parser
19
+
4
20
  module Bitcoin
5
21
  # Errors that the bitcoind is expected to raise should derive from this class.
6
22
  class Error < Exception
@@ -649,6 +665,23 @@ module Bitcoin
649
665
  get_block( @jr.getinfo().fetch('blocks') )
650
666
  end
651
667
 
668
+ # This returns the height of the last processed block according to
669
+ # blockexplorer.com. Be cautious—this information is provided by a third
670
+ # party! This method may raise exceptions of numerous different types.
671
+ def latest_remote_block_height
672
+ con = Net::HTTP.new('blockexplorer.com', 443)
673
+ con.use_ssl = true
674
+
675
+ con.get((testnet? ? '/testnet' : '') + '/q/getblockcount').body.to_i
676
+ end
677
+
678
+ # Return the percent of the blockchain we have downloaded according to the
679
+ # number fetched by latest_remote_block_height(). The warnings there apply
680
+ # here, too.
681
+ def percent_complete
682
+ (latest_block.height / latest_remote_block_height) * 100
683
+ end
684
+
652
685
  # Send +amount+ Bitcoin to +dest+. +amount+ should be a positive real
653
686
  # number; +dest+ can either be a String bitcoin address, or an Address
654
687
  # instance. We return a Transaction.
@@ -840,7 +873,7 @@ module Bitcoin
840
873
  # Set the transaction fee to +fee+. (c.f.
841
874
  # https://en.bitcoin.it/wiki/Transaction_fees)
842
875
  def transaction_fee=(fee)
843
- fee = fee.to_f
876
+ fee = fee.to_d
844
877
  @jr.settxfee(fee)
845
878
  fee
846
879
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -50,11 +50,11 @@ cert_chain:
50
50
  -----END CERTIFICATE-----
51
51
 
52
52
  '
53
- date: 2012-03-19 00:00:00.000000000 Z
53
+ date: 2012-04-27 00:00:00.000000000 Z
54
54
  dependencies:
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: jr
57
- requirement: &72538340 !ruby/object:Gem::Requirement
57
+ requirement: &82577590 !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements:
60
60
  - - ! '>='
@@ -62,7 +62,7 @@ dependencies:
62
62
  version: '0'
63
63
  type: :runtime
64
64
  prerelease: false
65
- version_requirements: *72538340
65
+ version_requirements: *82577590
66
66
  description: bc is a Ruby interface to bitcoind.
67
67
  email: the.magical.kat@gmail.com
68
68
  executables: []
metadata.gz.sig CHANGED
Binary file