bit_wallet 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/lib/bit_wallet/account.rb +16 -0
- data/lib/bit_wallet/version.rb +1 -1
- data/lib/bit_wallet.rb +6 -0
- data/spec/bit_wallet/account_spec.rb +12 -0
- data/spec/bit_wallet/errors.rb +4 -0
- metadata +5 -4
data/.gitignore
CHANGED
data/lib/bit_wallet/account.rb
CHANGED
@@ -26,11 +26,27 @@ module BitWallet
|
|
26
26
|
options[:to],
|
27
27
|
amount,
|
28
28
|
BitWallet.config.min_conf)
|
29
|
+
rescue RestClient::InternalServerError => e
|
30
|
+
parse_error e.response
|
29
31
|
end
|
30
32
|
|
31
33
|
def total_received
|
32
34
|
client.getreceivedbyaccount(self.name, BitWallet.config.min_conf)
|
33
35
|
end
|
34
36
|
|
37
|
+
private
|
38
|
+
|
39
|
+
def parse_error(response)
|
40
|
+
json_response = JSON.parse(response)
|
41
|
+
hash = json_response.with_indifferent_access
|
42
|
+
error = if hash[:error]
|
43
|
+
case hash[:error][:code]
|
44
|
+
when -6
|
45
|
+
InsufficientFunds.new("cannot send an amount more than what this account (#{self.name}) has")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
fail error if error
|
49
|
+
end
|
50
|
+
|
35
51
|
end
|
36
52
|
end
|
data/lib/bit_wallet/version.rb
CHANGED
data/lib/bit_wallet.rb
CHANGED
@@ -2,6 +2,7 @@ require "bit_wallet/version"
|
|
2
2
|
require 'ostruct'
|
3
3
|
require 'active_support/core_ext/module/attribute_accessors'
|
4
4
|
require 'active_support/core_ext/module/delegation'
|
5
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
5
6
|
require 'active_support/core_ext/string'
|
6
7
|
require 'bitcoin'
|
7
8
|
|
@@ -10,6 +11,7 @@ require 'bit_wallet/account'
|
|
10
11
|
require 'bit_wallet/accounts'
|
11
12
|
require 'bit_wallet/addresses'
|
12
13
|
require 'bit_wallet/address'
|
14
|
+
require 'bit_wallet/errors'
|
13
15
|
|
14
16
|
module BitWallet
|
15
17
|
|
@@ -20,4 +22,8 @@ module BitWallet
|
|
20
22
|
Wallet.new(*args)
|
21
23
|
end
|
22
24
|
|
25
|
+
def self.initialize(*args)
|
26
|
+
Wallet.new(*args)
|
27
|
+
end
|
28
|
+
|
23
29
|
end
|
@@ -66,6 +66,18 @@ describe BitWallet::Account do
|
|
66
66
|
default_account.send_amount 5.5, to: nona_address_str
|
67
67
|
nona_account.balance.should == expected_balance
|
68
68
|
end
|
69
|
+
|
70
|
+
context 'account does not have enough money' do
|
71
|
+
it 'should fail with the InsufficientFunds error' do
|
72
|
+
default_account = wallet.accounts.new('')
|
73
|
+
nona_account = wallet.accounts.new('nona')
|
74
|
+
nona_address_str = nona_account.addresses.first.address
|
75
|
+
expect {
|
76
|
+
default_account.send_amount(default_account.balance+10,
|
77
|
+
to: nona_address_str)
|
78
|
+
}.to raise_error(BitWallet::InsufficientFunds, "cannot send an amount more than what this account () has")
|
79
|
+
end
|
80
|
+
end
|
69
81
|
end
|
70
82
|
|
71
83
|
describe '#total_received' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bit_wallet
|
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-03-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bitcoin-client
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- spec/bit_wallet/accounts_spec.rb
|
118
118
|
- spec/bit_wallet/address_spec.rb
|
119
119
|
- spec/bit_wallet/addresses_spec.rb
|
120
|
+
- spec/bit_wallet/errors.rb
|
120
121
|
- spec/bit_wallet/wallet_spec.rb
|
121
122
|
- spec/bit_wallet_spec.rb
|
122
123
|
- spec/config.yml
|
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
143
|
version: '0'
|
143
144
|
requirements: []
|
144
145
|
rubyforge_project:
|
145
|
-
rubygems_version: 1.8.
|
146
|
+
rubygems_version: 1.8.24
|
146
147
|
signing_key:
|
147
148
|
specification_version: 3
|
148
149
|
summary: Ruby-esque handling of Bitcoin wallet.
|
@@ -151,9 +152,9 @@ test_files:
|
|
151
152
|
- spec/bit_wallet/accounts_spec.rb
|
152
153
|
- spec/bit_wallet/address_spec.rb
|
153
154
|
- spec/bit_wallet/addresses_spec.rb
|
155
|
+
- spec/bit_wallet/errors.rb
|
154
156
|
- spec/bit_wallet/wallet_spec.rb
|
155
157
|
- spec/bit_wallet_spec.rb
|
156
158
|
- spec/config.yml
|
157
159
|
- spec/factories.rb
|
158
160
|
- spec/spec_helper.rb
|
159
|
-
has_rdoc:
|