bitcoiner 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 94caff97e074031bf576ad3b336658154d300058be94938fa7d6704d21977908
4
+ data.tar.gz: 01cf19de5f620b06466304a466cf7463f43bf76b96de07c2b7f88025ef96ea45
5
+ SHA512:
6
+ metadata.gz: ff4daac0d720682cbbf60601e191fb2a5d767ccc25fdecc80bc88b0f292fab575982bf53d6c5d26b7f1867365b29aff91314b8d51c074969275e62d44e998205
7
+ data.tar.gz: f5bf6277414867f71871aed62bc4ce14e0b37d2874caf0e380545f440bcde83aef44f95d9d88cf102549601cdf4156069951b9ba4b190b7ef3e0a6bb4ac7e73e
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in bitcoiner.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2011 Bryce Kerley
2
+ Copyright (c) 2017 Nihad Abbasov
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,93 @@
1
+ # Bitcoiner [![Build Status](https://travis-ci.org/NARKOZ/bitcoiner.svg?branch=master)](https://travis-ci.org/NARKOZ/bitcoiner)
2
+
3
+ Automate your [Bitcoin](https://bitcoin.org/) transactions with this Ruby
4
+ interface to the `bitcoind` JSON-RPC API. This is a fork of
5
+ [bitcoind](https://github.com/bkerley/bitcoind) Ruby gem.
6
+
7
+ ![Super Mario Coin](https://user-images.githubusercontent.com/253398/34371748-45c440f2-eae9-11e7-84ba-fddae754d59a.jpg)
8
+
9
+ ## Installation
10
+
11
+ Install it from rubygems:
12
+
13
+ ```
14
+ gem install bitcoiner
15
+ ```
16
+
17
+ Or add to a Gemfile:
18
+
19
+ ```ruby
20
+ gem 'bitcoiner'
21
+ # gem 'bitcoiner', github: 'NARKOZ/bitcoiner'
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Connecting
27
+
28
+ Before connecting, you will need to configure a username and password for
29
+ `bitcoind`, and start `bitcoind`. Once that's done:
30
+
31
+ ```ruby
32
+ client = Bitcoiner.new 'username', 'password' # REPLACE WITH YOUR bitcoin.conf rpcuser/rpcpassword
33
+ # => #<Bitcoiner::Client "http://username:password@127.0.0.1:8332" >
34
+ ```
35
+
36
+ ### Account Balances
37
+
38
+ You can get the balance of all addresses controlled by the client:
39
+
40
+ ```ruby
41
+ client.balance
42
+ # => 12.34
43
+ ```
44
+
45
+ You can also get a hash of all accounts the client controls:
46
+
47
+ ```ruby
48
+ client.accounts
49
+ # => {"Your Address"=>#<Bitcoiner::Account "Your Address" >, "eve-online ransoms"=>#<Bitcoiner::Account "eve-online ransoms" >}
50
+ ```
51
+
52
+ And of course each account has its own balance too:
53
+
54
+ ```ruby
55
+ ransom = client.accounts['eve-online ransoms']
56
+ # => #<Bitcoiner::Account "eve-online ransoms" >
57
+
58
+ ransom.balance
59
+ # => 2.19
60
+ ```
61
+
62
+ ### Transactions
63
+
64
+ You can get all the transactions in an account:
65
+
66
+ ```ruby
67
+ ransom.transactions
68
+ # => [#<Bitcoiner::Transaction abadbabe123deadbeef 2.19 to eve-online ransoms at 2011-02-19 16:21:09 -0500>]
69
+ ```
70
+
71
+ You can send money from an account too:
72
+
73
+ ```ruby
74
+ ransom.send_to 'destinationaddress', 2
75
+ # => #<Bitcoiner::Account deadbeef888abadbeef UNCONFIRMED>
76
+ ```
77
+
78
+ ### Making Accounts
79
+
80
+ Creating an account with an associated address is done through the accounts
81
+ interface:
82
+
83
+ ```ruby
84
+ tiny_wings = client.accounts.new 'tiny wings ransoms'
85
+ # => #<Bitcoiner::Account "tiny wings ransoms" >
86
+
87
+ tiny_wings.address
88
+ # => "1KV5khnHbbHF2nNQkk7Pe5nPndEj43U27r"
89
+ ```
90
+
91
+ ## License
92
+
93
+ Released under the MIT license. See LICENSE.txt for details.
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'bitcoiner/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'bitcoiner'
7
+ spec.version = Bitcoiner::VERSION
8
+ spec.authors = ['Bryce Kerley', 'Nihad Abbasov']
9
+ spec.email = ['nihad@42na.in']
10
+
11
+ spec.summary = 'Control the bitcoin nework client over JSON-RPC.'
12
+ spec.description = 'Automate your Bitcoin transactions with this Ruby interface to the bitcoind JSON-RPC API.'
13
+ spec.homepage = 'https://github.com/NARKOZ/bitcoiner'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'typhoeus', '~> 1.3.0'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.16'
23
+ spec.add_development_dependency 'minitest', '~> 5.0'
24
+ spec.add_development_dependency 'mocha', '~> 1.1.0'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'shoulda-context', '~> 1.2.2'
27
+ end
@@ -0,0 +1,13 @@
1
+ require 'bitcoiner/version'
2
+ require 'typhoeus'
3
+ require 'json'
4
+
5
+ %w[client account account_hash transaction].each do |f|
6
+ require File.join(File.dirname(__FILE__), 'bitcoiner', f)
7
+ end
8
+
9
+ module Bitcoiner
10
+ def self.new(user, pass)
11
+ Client.new user, pass
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ module Bitcoiner
2
+ class Account
3
+ attr_accessor :name
4
+
5
+ def initialize(client, name)
6
+ @client = client
7
+ @name = name
8
+ end
9
+
10
+ def inspect
11
+ "#<Bitcoiner::Account #{@name.inspect} >"
12
+ end
13
+
14
+ def send_to(destination, amount)
15
+ txn_id = @client.request 'sendfrom', @name, destination, amount
16
+ Transaction.new @clientm, self, txn_id
17
+ end
18
+
19
+ def balance(min_confirmations = 1)
20
+ @balance ||= @client.request 'getbalance', @name, min_confirmations.to_i
21
+ end
22
+
23
+ def address
24
+ @address ||= @client.request 'getaccountaddress', @name
25
+ end
26
+
27
+ def transactions
28
+ txn_array = @client.request 'listtransactions', @name
29
+
30
+ txn_array.map do |h|
31
+ Transaction.new @client, self, h['txid']
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,16 @@
1
+ module Bitcoiner
2
+ class AccountHash < Hash
3
+ def initialize(client, balance_hash)
4
+ @client = client
5
+ balance_hash.each_key do |name|
6
+ self[name] = Account.new client, name
7
+ end
8
+ end
9
+
10
+ def new(name)
11
+ @client.request 'getnewaddress', name
12
+ self[name] = Account.new @client, name
13
+ self[name]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,30 @@
1
+ module Bitcoiner
2
+ class Client
3
+ def initialize(user, pass, host = '127.0.0.1:8332')
4
+ @endpoint = "http://#{user}:#{pass}@#{host}"
5
+ end
6
+
7
+ def balance
8
+ request 'getbalance'
9
+ end
10
+
11
+ def accounts
12
+ balance_hash = request 'listaccounts'
13
+ AccountHash.new self, balance_hash
14
+ end
15
+
16
+ def request(method, *args)
17
+ post_body = { 'method' => method, 'params' => args, 'id' => 'jsonrpc' }.to_json
18
+ response = Typhoeus.post(@endpoint, body: post_body)
19
+ response_hash = JSON.parse response.body
20
+ raise JSONRPCError, response_hash['error'] if response_hash['error']
21
+ response_hash['result']
22
+ end
23
+
24
+ def inspect
25
+ "#<Bitcoiner::Client #{@endpoint.inspect} >"
26
+ end
27
+
28
+ class JSONRPCError < RuntimeError; end
29
+ end
30
+ end
@@ -0,0 +1,37 @@
1
+ module Bitcoiner
2
+ class Transaction
3
+ attr_accessor :id, :account
4
+
5
+ def initialize(client, account, id)
6
+ @client = client
7
+ @account = account
8
+ @id = id
9
+ end
10
+
11
+ def detail_hash
12
+ @detail_hash ||= @client.request 'gettransaction', @id
13
+ end
14
+
15
+ def inspect
16
+ "#<Bitcoiner::Transaction #{id} #{amount} to #{account.name} at #{time}>"
17
+ rescue
18
+ "#<Bitcoiner::Transaction #{id} UNCONFIRMED>"
19
+ end
20
+
21
+ def amount
22
+ detail_hash['amount']
23
+ end
24
+
25
+ def confirmations
26
+ detail_hash['confirmations'] rescue 0
27
+ end
28
+
29
+ def time
30
+ @time ||= Time.at detail_hash['time']
31
+ end
32
+
33
+ def confirmed?(min_confirmations = 6)
34
+ confirmations > min_confirmations
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Bitcoiner
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitcoiner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bryce Kerley
8
+ - Nihad Abbasov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-12-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: typhoeus
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 1.3.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 1.3.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.16'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.16'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '5.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '5.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: mocha
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.1.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.1.0
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '10.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: shoulda-context
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 1.2.2
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 1.2.2
98
+ description: Automate your Bitcoin transactions with this Ruby interface to the bitcoind
99
+ JSON-RPC API.
100
+ email:
101
+ - nihad@42na.in
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bitcoiner.gemspec
113
+ - lib/bitcoiner.rb
114
+ - lib/bitcoiner/account.rb
115
+ - lib/bitcoiner/account_hash.rb
116
+ - lib/bitcoiner/client.rb
117
+ - lib/bitcoiner/transaction.rb
118
+ - lib/bitcoiner/version.rb
119
+ homepage: https://github.com/NARKOZ/bitcoiner
120
+ licenses: []
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.7.3
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Control the bitcoin nework client over JSON-RPC.
142
+ test_files: []