bit_wallet 0.4.0 → 0.5.0
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.
- checksums.yaml +15 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +0 -6
- data/README.md +6 -0
- data/bit_wallet.gemspec +4 -4
- data/lib/bit_wallet/account.rb +4 -12
- data/lib/bit_wallet/errors.rb +1 -0
- data/lib/bit_wallet/handles_error.rb +16 -0
- data/lib/bit_wallet/instantiates_bitcoin_client.rb +10 -0
- data/lib/bit_wallet/version.rb +1 -1
- data/lib/bit_wallet/wallet.rb +1 -3
- data/lib/bit_wallet.rb +3 -0
- data/spec/bit_wallet/account_spec.rb +1 -1
- data/spec/bit_wallet/accounts_spec.rb +1 -5
- data/spec/bit_wallet/handles_error_spec.rb +28 -0
- data/spec/bit_wallet/instantiates_bitcoin_client_spec.rb +27 -0
- data/spec/fixtures/vcr_cassettes/BitWallet_Accounts/_with_balance/should_return_accounts_with_a_balance_0.yml +102 -364
- data/spec/spec_helper.rb +2 -0
- metadata +28 -38
- data/rvmrc.sample +0 -1
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZGFiM2Y3MGRkNjFjYjY2YzIxZWFhNDc0MzNkODE4ZmM2NjhmMTc2MA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTJjZjFhZjVjNjk3MTVkNGQ2MDQ1MjYzYzRiMjRkNWQzNTZkZDFiMw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTIxMjJkNzFiYjllYWVmNDMyYThmYzU5NjVjYWE0NWI0M2IyYWJjZmVmZTgw
|
10
|
+
YTEzMDY2NzQ2ODgwMDRjODRhNTk5YmNiZDM5MjU2ZDY2MzQ3OWQ0YjZkMDQy
|
11
|
+
MWM0MWIzMTAyMDg3MzlkNDdmOWRhYzg4Y2Y0MjYxMzBiZmZmZDA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDE3YTI0YTFhZDM5ZWZjZmE2N2YyMTU3ZGI3N2NkM2RkNTVkZWU3NmE5Yjg1
|
14
|
+
MmIwNDg3ZDA3YmQ0OWY3MDMwNTgxYmU3N2NkNGNjZDNjZjg5YzMzYTRkZDcx
|
15
|
+
YWY5MzUzNzIwMWRjMTM2ZjBiMGVlZGY5ZGE4ZTQ4ODQ2ZmRiMzY=
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-1.9.3-p286
|
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
@@ -2,9 +2,3 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in bit_wallet.gemspec
|
4
4
|
gemspec
|
5
|
-
|
6
|
-
# Override what gem is included until dcd70a686162fad41e5bd4bddc0ee67565227ec6
|
7
|
-
# is released in rubygems
|
8
|
-
gem('bitcoin-client',
|
9
|
-
git: 'git@github.com:sinisterchipmunk/bitcoin-client.git',
|
10
|
-
ref: 'dcd70a686162fad41e5bd4bddc0ee67565227ec6')
|
data/README.md
CHANGED
@@ -19,6 +19,8 @@ Or install it yourself as:
|
|
19
19
|
## Usage
|
20
20
|
|
21
21
|
wallet = BitWallet.new(:username => 'username', :password => 'password')
|
22
|
+
# You can also pass :port and :host
|
23
|
+
|
22
24
|
wallet.accounts.with_balance # returns array of the accounts with balance > 0
|
23
25
|
account = wallet.accounts.new('account name')
|
24
26
|
account.addresses.count # 1, as it already comes with an address
|
@@ -48,6 +50,10 @@ A transaction has the following methods:
|
|
48
50
|
- `occurred_at`: Ruby Time object for the `time` value returned by bitcoind
|
49
51
|
- `received_at`: Ruby Time object for the `timereceived` value returned by bitcoind
|
50
52
|
|
53
|
+
## Tests
|
54
|
+
|
55
|
+
- You must set up bitcoind, and it must be in the executable path. See README.txt in `spec/testnet` as to what version to install.
|
56
|
+
|
51
57
|
## Contributing
|
52
58
|
|
53
59
|
1. Fork it
|
data/bit_wallet.gemspec
CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
20
|
gem.add_dependency 'bitcoin-client'
|
21
|
-
gem.add_dependency 'activesupport'
|
22
|
-
gem.add_development_dependency 'rspec', '2.12
|
21
|
+
gem.add_dependency 'activesupport'
|
22
|
+
gem.add_development_dependency 'rspec', '~> 2.12'
|
23
23
|
gem.add_development_dependency 'pry'
|
24
24
|
gem.add_development_dependency 'factory_girl', '4.2.0'
|
25
|
-
gem.add_development_dependency 'bitcoin_testnet', '0.
|
26
|
-
gem.add_development_dependency 'vcr', '2.4
|
25
|
+
gem.add_development_dependency 'bitcoin_testnet', '0.5.0'
|
26
|
+
gem.add_development_dependency 'vcr', '~> 2.4'
|
27
27
|
gem.add_development_dependency 'webmock', '1.9.0'
|
28
28
|
end
|
data/lib/bit_wallet/account.rb
CHANGED
@@ -29,8 +29,8 @@ module BitWallet
|
|
29
29
|
options[:to],
|
30
30
|
amount,
|
31
31
|
BitWallet.config.min_conf)
|
32
|
-
rescue
|
33
|
-
parse_error e.
|
32
|
+
rescue Bitcoin::Errors::RPCError => e
|
33
|
+
parse_error e.message
|
34
34
|
end
|
35
35
|
|
36
36
|
def total_received
|
@@ -70,16 +70,8 @@ module BitWallet
|
|
70
70
|
|
71
71
|
private
|
72
72
|
|
73
|
-
def parse_error(
|
74
|
-
|
75
|
-
hash = json_response.with_indifferent_access
|
76
|
-
error = if hash[:error]
|
77
|
-
case hash[:error][:code]
|
78
|
-
when -6
|
79
|
-
InsufficientFunds.new("cannot send an amount more than what this account (#{self.name}) has")
|
80
|
-
end
|
81
|
-
end
|
82
|
-
fail error if error
|
73
|
+
def parse_error(message)
|
74
|
+
HandlesError.from(message)
|
83
75
|
end
|
84
76
|
|
85
77
|
end
|
data/lib/bit_wallet/errors.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module BitWallet
|
2
|
+
class HandlesError
|
3
|
+
|
4
|
+
def self.from(message)
|
5
|
+
error = if message.include?("-6")
|
6
|
+
InsufficientFunds.new("cannot send an amount more than what this account has")
|
7
|
+
elsif message.include?("-3")
|
8
|
+
InvalidAmount.new("amount is invalid")
|
9
|
+
else
|
10
|
+
ArgumentError.new("unknown error: #{message}")
|
11
|
+
end
|
12
|
+
fail error if error
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/bit_wallet/version.rb
CHANGED
data/lib/bit_wallet/wallet.rb
CHANGED
data/lib/bit_wallet.rb
CHANGED
@@ -3,6 +3,7 @@ require 'ostruct'
|
|
3
3
|
require 'active_support/core_ext/module/attribute_accessors'
|
4
4
|
require 'active_support/core_ext/module/delegation'
|
5
5
|
require 'active_support/core_ext/hash/indifferent_access'
|
6
|
+
require 'active_support/core_ext/hash/slice'
|
6
7
|
require 'active_support/core_ext/string'
|
7
8
|
require 'bitcoin'
|
8
9
|
|
@@ -13,6 +14,8 @@ require 'bit_wallet/addresses'
|
|
13
14
|
require 'bit_wallet/address'
|
14
15
|
require 'bit_wallet/transaction'
|
15
16
|
require 'bit_wallet/errors'
|
17
|
+
require 'bit_wallet/instantiates_bitcoin_client'
|
18
|
+
require 'bit_wallet/handles_error'
|
16
19
|
|
17
20
|
module BitWallet
|
18
21
|
|
@@ -87,7 +87,7 @@ describe BitWallet::Account, vcr: true do
|
|
87
87
|
expect {
|
88
88
|
default_account.send_amount(default_account.balance+10,
|
89
89
|
to: nona_address_str)
|
90
|
-
}.to raise_error(BitWallet::InsufficientFunds, "cannot send an amount more than what this account
|
90
|
+
}.to raise_error(BitWallet::InsufficientFunds, "cannot send an amount more than what this account has")
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe BitWallet::Accounts, vcr:
|
3
|
+
describe BitWallet::Accounts, vcr: {record: :once} do
|
4
4
|
|
5
5
|
let(:wallet) do
|
6
6
|
build(:wallet)
|
@@ -39,10 +39,6 @@ describe BitWallet::Accounts, vcr: true do
|
|
39
39
|
accounts_with_balance.should include(default_account)
|
40
40
|
accounts_with_balance.should_not include(account_1)
|
41
41
|
accounts_with_balance.should include(account_2)
|
42
|
-
|
43
|
-
account_1.send_amount account_1.balance, to: default_account.addresses.first
|
44
|
-
|
45
|
-
subject.with_balance.should_not include(account_1)
|
46
42
|
end
|
47
43
|
end
|
48
44
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module BitWallet
|
4
|
+
describe HandlesError do
|
5
|
+
describe ".from" do
|
6
|
+
context "error is -3" do
|
7
|
+
it "raises InvalidAmount error" do
|
8
|
+
expect { described_class.from("does not matter -3 meh") }.
|
9
|
+
to raise_error(InvalidAmount, "amount is invalid")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "error is -6" do
|
14
|
+
it "raises InsufficientFunds error" do
|
15
|
+
expect { described_class.from("-6 message") }.
|
16
|
+
to raise_error(InsufficientFunds, "cannot send an amount more than what this account has")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "error is unknown" do
|
21
|
+
it "raises an ArgumentError" do
|
22
|
+
expect { described_class.from("-99 I do not know") }.
|
23
|
+
to raise_error(ArgumentError, "unknown error: -99 I do not know")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module BitWallet
|
4
|
+
describe InstantiatesBitcoinClient, ".execute" do
|
5
|
+
|
6
|
+
context "a hash config with username, password, host, port, ssl" do
|
7
|
+
it "returns a Bitcoin::Client given a hash config" do
|
8
|
+
client = double
|
9
|
+
|
10
|
+
allow(Bitcoin::Client).to receive(:new).
|
11
|
+
with("username", "password", host: "myhost", port: 8288, ssl: false).
|
12
|
+
and_return(client)
|
13
|
+
|
14
|
+
resulting_client = described_class.execute(
|
15
|
+
username: "username",
|
16
|
+
password: "password",
|
17
|
+
host: "myhost",
|
18
|
+
port: 8288,
|
19
|
+
ssl: false
|
20
|
+
)
|
21
|
+
|
22
|
+
expect(resulting_client).to eq(client)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|