bitbank 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +23 -0
- data/.document +5 -0
- data/.rspec +2 -0
- data/Gemfile +23 -0
- data/Gemfile.lock +59 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +60 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/bitbank.gemspec +112 -0
- data/config.yml +4 -0
- data/lib/bitbank.rb +47 -0
- data/lib/bitbank/account.rb +36 -0
- data/lib/bitbank/client.rb +58 -0
- data/lib/bitbank/transaction.rb +43 -0
- data/spec/account_spec.rb +64 -0
- data/spec/bitbank_spec.rb +37 -0
- data/spec/client_spec.rb +134 -0
- data/spec/fixtures/vcr_cassettes/account/address.yml +30 -0
- data/spec/fixtures/vcr_cassettes/account/balance.yml +30 -0
- data/spec/fixtures/vcr_cassettes/account/new_address.yml +30 -0
- data/spec/fixtures/vcr_cassettes/account/pay.yml +60 -0
- data/spec/fixtures/vcr_cassettes/account/transactions.yml +30 -0
- data/spec/fixtures/vcr_cassettes/client/accounts.yml +30 -0
- data/spec/fixtures/vcr_cassettes/client/balance.yml +30 -0
- data/spec/fixtures/vcr_cassettes/client/balance_account.yml +30 -0
- data/spec/fixtures/vcr_cassettes/client/block_count.yml +30 -0
- data/spec/fixtures/vcr_cassettes/client/difficulty.yml +30 -0
- data/spec/fixtures/vcr_cassettes/client/get_work.yml +30 -0
- data/spec/fixtures/vcr_cassettes/client/info.yml +30 -0
- data/spec/fixtures/vcr_cassettes/client/new_address.yml +30 -0
- data/spec/fixtures/vcr_cassettes/client/transactions.yml +30 -0
- data/spec/fixtures/vcr_cassettes/client/transactions_account.yml +30 -0
- data/spec/fixtures/vcr_cassettes/transaction/details.yml +30 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/focused.rb +7 -0
- data/spec/transaction_spec.rb +73 -0
- metadata +232 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
begin
|
2
|
+
require 'autotest/fsevent'
|
3
|
+
rescue LoadError
|
4
|
+
puts "NOTE: Install autotest-fsevent to prevent filesystem polling"
|
5
|
+
end
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'autotest/growl'
|
9
|
+
rescue LoadError
|
10
|
+
puts "NOTE: Install autotest-growl for growl support"
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'autotest/timestamp'
|
14
|
+
|
15
|
+
Autotest.add_hook :initialize do |at|
|
16
|
+
at.add_exception %r{\/\.bundle}
|
17
|
+
at.add_exception %r{\/\.git}
|
18
|
+
at.add_exception %r{\.gitignore}
|
19
|
+
at.add_exception %r{\.rspec}
|
20
|
+
at.add_exception %r{\.rvmrc}
|
21
|
+
at.add_exception %r{\/config}
|
22
|
+
at.add_exception %r{\/coverage}
|
23
|
+
end
|
data/.document
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem 'activesupport', '>= 2.3.5'
|
5
|
+
|
6
|
+
gem 'rest-client', '~> 1.6.3'
|
7
|
+
gem 'activesupport', '~> 3.0.7'
|
8
|
+
gem 'i18n', '~> 0.6.0'
|
9
|
+
|
10
|
+
# Add dependencies to develop your gem here.
|
11
|
+
# Include everything needed to run rake, tests, features, etc.
|
12
|
+
group :development do
|
13
|
+
gem 'rspec', '~> 2.6.0'
|
14
|
+
gem 'yard', '~> 0.6.0'
|
15
|
+
gem 'bundler', '~> 1.0.0'
|
16
|
+
gem 'jeweler', '~> 1.6.2'
|
17
|
+
gem 'webmock', '~> 1.6.4'
|
18
|
+
gem 'vcr', '~> 1.10.0'
|
19
|
+
gem 'mocha', '~> 0.9.12'
|
20
|
+
gem 'rcov', '>= 0'
|
21
|
+
gem 'fuubar', '>= 0.0.5'
|
22
|
+
gem 'autotest', '>= 4.4.6'
|
23
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ZenTest (4.5.0)
|
5
|
+
activesupport (3.0.8)
|
6
|
+
addressable (2.2.6)
|
7
|
+
autotest (4.4.6)
|
8
|
+
ZenTest (>= 4.4.1)
|
9
|
+
crack (0.1.8)
|
10
|
+
diff-lcs (1.1.2)
|
11
|
+
fuubar (0.0.5)
|
12
|
+
rspec (~> 2.0)
|
13
|
+
rspec-instafail (~> 0.1.4)
|
14
|
+
ruby-progressbar (~> 0.0.10)
|
15
|
+
git (1.2.5)
|
16
|
+
i18n (0.6.0)
|
17
|
+
jeweler (1.6.2)
|
18
|
+
bundler (~> 1.0)
|
19
|
+
git (>= 1.2.5)
|
20
|
+
rake
|
21
|
+
mime-types (1.16)
|
22
|
+
mocha (0.9.12)
|
23
|
+
rake (0.9.2)
|
24
|
+
rcov (0.9.9)
|
25
|
+
rest-client (1.6.3)
|
26
|
+
mime-types (>= 1.16)
|
27
|
+
rspec (2.6.0)
|
28
|
+
rspec-core (~> 2.6.0)
|
29
|
+
rspec-expectations (~> 2.6.0)
|
30
|
+
rspec-mocks (~> 2.6.0)
|
31
|
+
rspec-core (2.6.4)
|
32
|
+
rspec-expectations (2.6.0)
|
33
|
+
diff-lcs (~> 1.1.2)
|
34
|
+
rspec-instafail (0.1.8)
|
35
|
+
rspec-mocks (2.6.0)
|
36
|
+
ruby-progressbar (0.0.10)
|
37
|
+
vcr (1.10.0)
|
38
|
+
webmock (1.6.4)
|
39
|
+
addressable (> 2.2.5, ~> 2.2)
|
40
|
+
crack (>= 0.1.7)
|
41
|
+
yard (0.6.8)
|
42
|
+
|
43
|
+
PLATFORMS
|
44
|
+
ruby
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
activesupport (~> 3.0.7)
|
48
|
+
autotest (>= 4.4.6)
|
49
|
+
bundler (~> 1.0.0)
|
50
|
+
fuubar (>= 0.0.5)
|
51
|
+
i18n (~> 0.6.0)
|
52
|
+
jeweler (~> 1.6.2)
|
53
|
+
mocha (~> 0.9.12)
|
54
|
+
rcov
|
55
|
+
rest-client (~> 1.6.3)
|
56
|
+
rspec (~> 2.6.0)
|
57
|
+
vcr (~> 1.10.0)
|
58
|
+
webmock (~> 1.6.4)
|
59
|
+
yard (~> 0.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Nick Plante
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
= Bitbank
|
2
|
+
|
3
|
+
An easy-to-use Ruby interface for the Bitcoind JSON-RPC API. Work in progress :).
|
4
|
+
|
5
|
+
== Getting Started
|
6
|
+
|
7
|
+
First, you need to be running bitcoind. Download and install the official client from http://bitcoin.org/
|
8
|
+
|
9
|
+
Next, in order for the client to respond to JSON-RPC commands, you need to enable it in the config file. An example of this and a good explanation of the various options can be found at https://en.bitcoin.it/wiki/Running_Bitcoin
|
10
|
+
|
11
|
+
Make sure to set the server, rpcuser, and rpcpassword options.
|
12
|
+
|
13
|
+
== Connecting
|
14
|
+
|
15
|
+
Configure the username and password to match the ones in your bitcoind config. I recommend storing these in a yaml file (see the example config.yml). Once you've done that, you can initialize the client and make requests:
|
16
|
+
|
17
|
+
client = Bitbank.new('/path/to/bitbank/config.yml')
|
18
|
+
|
19
|
+
== Accounts and Account Balances
|
20
|
+
|
21
|
+
You can have a number of different Bitcoin accounts and addresses.
|
22
|
+
|
23
|
+
client.accounts.each do |account|
|
24
|
+
puts "#{account.name}: #{account.balance}"
|
25
|
+
end
|
26
|
+
|
27
|
+
Or you can get the current balance for all your accounts:
|
28
|
+
|
29
|
+
client.balance
|
30
|
+
# => 10.05
|
31
|
+
|
32
|
+
== Transactions
|
33
|
+
|
34
|
+
Each account also has a list of transactions (both sent and received).
|
35
|
+
|
36
|
+
account.transactions.each do |transaction|
|
37
|
+
puts "[#{transaction.category}] #{transaction.address} #{transaction.amount}"
|
38
|
+
end
|
39
|
+
|
40
|
+
And of course you can send payments using the library too:
|
41
|
+
|
42
|
+
account.pay('1DSwyVqyhKKQwrdFw3jpAEqnrXEjTcTKMB', 1.0)
|
43
|
+
|
44
|
+
This would send 1 BTC to me. Which would be really awesome, if you'd like to support the continued development of the gem :).
|
45
|
+
|
46
|
+
== Contributing to Bitbank
|
47
|
+
|
48
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
49
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
50
|
+
* Fork the project
|
51
|
+
* Start a feature/bugfix branch
|
52
|
+
* Commit and push until you are happy with your contribution
|
53
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
54
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
55
|
+
|
56
|
+
== Copyright
|
57
|
+
|
58
|
+
Copyright (c) 2011 Nick Plante. See LICENSE.txt for
|
59
|
+
further details.
|
60
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "bitbank"
|
18
|
+
gem.homepage = "http://github.com/zapnap/bitbank"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Easy to use Ruby interface to the Bitcoind JSON-RPC API}
|
21
|
+
gem.description = %Q{Easy to use Ruby interface to the Bitcoind JSON-RPC API}
|
22
|
+
gem.email = "nap@zerosum.org"
|
23
|
+
gem.authors = ["Nick Plante"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'yard'
|
42
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bitbank.gemspec
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{bitbank}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Nick Plante"]
|
12
|
+
s.date = %q{2011-06-13}
|
13
|
+
s.description = %q{Easy to use Ruby interface to the Bitcoind JSON-RPC API}
|
14
|
+
s.email = %q{nap@zerosum.org}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".autotest",
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bitbank.gemspec",
|
30
|
+
"config.yml",
|
31
|
+
"lib/bitbank.rb",
|
32
|
+
"lib/bitbank/account.rb",
|
33
|
+
"lib/bitbank/client.rb",
|
34
|
+
"lib/bitbank/transaction.rb",
|
35
|
+
"spec/account_spec.rb",
|
36
|
+
"spec/bitbank_spec.rb",
|
37
|
+
"spec/client_spec.rb",
|
38
|
+
"spec/fixtures/vcr_cassettes/account/address.yml",
|
39
|
+
"spec/fixtures/vcr_cassettes/account/balance.yml",
|
40
|
+
"spec/fixtures/vcr_cassettes/account/new_address.yml",
|
41
|
+
"spec/fixtures/vcr_cassettes/account/pay.yml",
|
42
|
+
"spec/fixtures/vcr_cassettes/account/transactions.yml",
|
43
|
+
"spec/fixtures/vcr_cassettes/client/accounts.yml",
|
44
|
+
"spec/fixtures/vcr_cassettes/client/balance.yml",
|
45
|
+
"spec/fixtures/vcr_cassettes/client/balance_account.yml",
|
46
|
+
"spec/fixtures/vcr_cassettes/client/block_count.yml",
|
47
|
+
"spec/fixtures/vcr_cassettes/client/difficulty.yml",
|
48
|
+
"spec/fixtures/vcr_cassettes/client/get_work.yml",
|
49
|
+
"spec/fixtures/vcr_cassettes/client/info.yml",
|
50
|
+
"spec/fixtures/vcr_cassettes/client/new_address.yml",
|
51
|
+
"spec/fixtures/vcr_cassettes/client/transactions.yml",
|
52
|
+
"spec/fixtures/vcr_cassettes/client/transactions_account.yml",
|
53
|
+
"spec/fixtures/vcr_cassettes/transaction/details.yml",
|
54
|
+
"spec/spec_helper.rb",
|
55
|
+
"spec/support/focused.rb",
|
56
|
+
"spec/transaction_spec.rb"
|
57
|
+
]
|
58
|
+
s.homepage = %q{http://github.com/zapnap/bitbank}
|
59
|
+
s.licenses = ["MIT"]
|
60
|
+
s.require_paths = ["lib"]
|
61
|
+
s.rubygems_version = %q{1.6.2}
|
62
|
+
s.summary = %q{Easy to use Ruby interface to the Bitcoind JSON-RPC API}
|
63
|
+
|
64
|
+
if s.respond_to? :specification_version then
|
65
|
+
s.specification_version = 3
|
66
|
+
|
67
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
68
|
+
s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.3"])
|
69
|
+
s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.7"])
|
70
|
+
s.add_runtime_dependency(%q<i18n>, ["~> 0.6.0"])
|
71
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
|
72
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
|
73
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
74
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
75
|
+
s.add_development_dependency(%q<webmock>, ["~> 1.6.4"])
|
76
|
+
s.add_development_dependency(%q<vcr>, ["~> 1.10.0"])
|
77
|
+
s.add_development_dependency(%q<mocha>, ["~> 0.9.12"])
|
78
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
79
|
+
s.add_development_dependency(%q<fuubar>, [">= 0.0.5"])
|
80
|
+
s.add_development_dependency(%q<autotest>, [">= 4.4.6"])
|
81
|
+
else
|
82
|
+
s.add_dependency(%q<rest-client>, ["~> 1.6.3"])
|
83
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.7"])
|
84
|
+
s.add_dependency(%q<i18n>, ["~> 0.6.0"])
|
85
|
+
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
86
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
87
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
88
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
89
|
+
s.add_dependency(%q<webmock>, ["~> 1.6.4"])
|
90
|
+
s.add_dependency(%q<vcr>, ["~> 1.10.0"])
|
91
|
+
s.add_dependency(%q<mocha>, ["~> 0.9.12"])
|
92
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
93
|
+
s.add_dependency(%q<fuubar>, [">= 0.0.5"])
|
94
|
+
s.add_dependency(%q<autotest>, [">= 4.4.6"])
|
95
|
+
end
|
96
|
+
else
|
97
|
+
s.add_dependency(%q<rest-client>, ["~> 1.6.3"])
|
98
|
+
s.add_dependency(%q<activesupport>, ["~> 3.0.7"])
|
99
|
+
s.add_dependency(%q<i18n>, ["~> 0.6.0"])
|
100
|
+
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
101
|
+
s.add_dependency(%q<yard>, ["~> 0.6.0"])
|
102
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
103
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
|
104
|
+
s.add_dependency(%q<webmock>, ["~> 1.6.4"])
|
105
|
+
s.add_dependency(%q<vcr>, ["~> 1.10.0"])
|
106
|
+
s.add_dependency(%q<mocha>, ["~> 0.9.12"])
|
107
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
108
|
+
s.add_dependency(%q<fuubar>, [">= 0.0.5"])
|
109
|
+
s.add_dependency(%q<autotest>, [">= 4.4.6"])
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
data/config.yml
ADDED
data/lib/bitbank.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'json'
|
3
|
+
require 'rest_client'
|
4
|
+
|
5
|
+
require 'active_support/core_ext'
|
6
|
+
|
7
|
+
Dir[File.join(File.dirname(__FILE__), 'bitbank', '*.rb')].each { |f| require f }
|
8
|
+
|
9
|
+
module Bitbank
|
10
|
+
@@defaults = {
|
11
|
+
:host => 'localhost',
|
12
|
+
:port => 8332
|
13
|
+
}
|
14
|
+
|
15
|
+
def self.new(options={})
|
16
|
+
self.config = options
|
17
|
+
Client.new(config)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.config
|
21
|
+
@config
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.config=(filename_or_hash)
|
25
|
+
if filename_or_hash.is_a?(String)
|
26
|
+
options = YAML.load_file(filename_or_hash)
|
27
|
+
else
|
28
|
+
options = filename_or_hash
|
29
|
+
end
|
30
|
+
|
31
|
+
options.symbolize_keys!
|
32
|
+
if options.has_key?(:username) && options.has_key?(:password)
|
33
|
+
@config = @@defaults.merge(options)
|
34
|
+
else
|
35
|
+
raise ArgumentError, 'Please specify a username and password for bitcoind'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.version
|
40
|
+
version_path = File.join(File.dirname(__FILE__), '..', 'VERSION')
|
41
|
+
if File.file?(version_path)
|
42
|
+
File.read(version_path).chomp
|
43
|
+
else
|
44
|
+
'0.0.0'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Bitbank
|
2
|
+
class Account
|
3
|
+
attr_reader :name, :balance
|
4
|
+
|
5
|
+
def initialize(client, name, balance=nil)
|
6
|
+
@client = client
|
7
|
+
@name = name
|
8
|
+
@balance = balance
|
9
|
+
end
|
10
|
+
|
11
|
+
def address
|
12
|
+
@client.request('getaccountaddress', name)
|
13
|
+
end
|
14
|
+
|
15
|
+
def balance
|
16
|
+
@client.balance(name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def new_address
|
20
|
+
@client.new_address(name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def pay(address, amount)
|
24
|
+
txid = @client.request('sendfrom', name, address, amount)
|
25
|
+
Transaction.new(@client, txid)
|
26
|
+
end
|
27
|
+
|
28
|
+
def transactions
|
29
|
+
@client.transactions(name)
|
30
|
+
end
|
31
|
+
|
32
|
+
def ==(other)
|
33
|
+
name == other.name
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|