dogecoin_ruby 0.0.1
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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/CHANGELOG +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +84 -0
- data/Rakefile +5 -0
- data/dogecoin_ruby.gemspec +24 -0
- data/lib/dogecoin_ruby.rb +8 -0
- data/lib/dogecoin_ruby/client.rb +66 -0
- data/lib/dogecoin_ruby/version.rb +3 -0
- data/spec/dogecoin_spec.rb +57 -0
- data/spec/spec_helper.rb +19 -0
- metadata +115 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 mlapeter
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# DogecoinRuby
|
2
|
+
|
3
|
+
Dogecoin-Ruby is a ruby wrapper for the Dogecoin API located at http://dogechain.info. It's only intended for simple requests like checking a wallet balance, not creating wallets or storing or transacting any dogecoin. DOGECLAIMER: I'm learning this as I go, any help is greatly appreciated, and I make no guarantees!
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dogecoin-ruby'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dogecoin-ruby
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Currently no API key is needed for the dogechain.info API.
|
22
|
+
|
23
|
+
To get started, create the Dogecoin client:
|
24
|
+
|
25
|
+
@doge = DogecoinRuby::Client.new
|
26
|
+
|
27
|
+
The following actions are available:
|
28
|
+
|
29
|
+
@doge.address_balance(address)
|
30
|
+
|
31
|
+
Get the amount ever received minus amount ever sent by a given address.
|
32
|
+
|
33
|
+
@doge.address_to_hash(address)
|
34
|
+
|
35
|
+
Shows the public key hash encoded in an address.
|
36
|
+
|
37
|
+
@doge.check_address(address)
|
38
|
+
|
39
|
+
Checks an address for validity.
|
40
|
+
|
41
|
+
@doge.decode_address(address)
|
42
|
+
|
43
|
+
Shows the version prefix and hash encoded in an address.
|
44
|
+
|
45
|
+
@doge.get_block_count
|
46
|
+
|
47
|
+
Shows the current block number.
|
48
|
+
|
49
|
+
@doge.get_difficulty
|
50
|
+
|
51
|
+
Shows the last solved block's difficulty.
|
52
|
+
|
53
|
+
@doge.get_received_by_address(address)
|
54
|
+
|
55
|
+
Shows the amount ever received by a given address.
|
56
|
+
|
57
|
+
@doge.get_sent_by_address(address)
|
58
|
+
|
59
|
+
Shows the amount ever sent from a given address.
|
60
|
+
|
61
|
+
@doge.hash_to_address(hash)
|
62
|
+
|
63
|
+
Shows the address of the given hash.
|
64
|
+
|
65
|
+
@doge.net_hash
|
66
|
+
|
67
|
+
Shows statistics about difficulty and network power.
|
68
|
+
|
69
|
+
@doge.total_bc
|
70
|
+
|
71
|
+
Shows the amount of currency ever mined.
|
72
|
+
|
73
|
+
@doge.transactions
|
74
|
+
|
75
|
+
Shows the amount transactions of the last blocks.
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
1. Fork it
|
80
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
81
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
82
|
+
4. Please add tests!
|
83
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
84
|
+
6. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dogecoin_ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dogecoin_ruby"
|
8
|
+
spec.version = DogecoinRuby::VERSION
|
9
|
+
spec.authors = ["mlapeter"]
|
10
|
+
spec.email = ["mlapeter@gmail.com"]
|
11
|
+
spec.description = %q{Ruby wrapper for the Dogecoin API located at http://dogechain.info}
|
12
|
+
spec.summary = %q{Ruby wrapper for the Dogecoin API located at http://dogechain.info}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rspec"
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module DogecoinRuby
|
2
|
+
class Client
|
3
|
+
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
end
|
7
|
+
|
8
|
+
def parse_url(path, address=nil)
|
9
|
+
body = open("http://dogechain.info/chain/Dogecoin/q/#{path}/#{address}").read
|
10
|
+
end
|
11
|
+
|
12
|
+
def address_balance(address)
|
13
|
+
parse_url("addressbalance", address).to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
def address_to_hash(address)
|
17
|
+
parse_url("addresstohash", address)
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_address(address)
|
21
|
+
result = parse_url("checkaddress", address)
|
22
|
+
if result == "X5" || result == "SZ" || result == "CK" || result == "BBE"
|
23
|
+
false
|
24
|
+
else
|
25
|
+
true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def decode_address(address)
|
30
|
+
parse_url("decode_address", address)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_block_count
|
34
|
+
parse_url("getblockcount").to_i
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_difficulty
|
38
|
+
parse_url("getdifficulty").to_i
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_received_by_address(address)
|
42
|
+
parse_url("getreceivedbyaddress", address).to_i
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_sent_by_address(address)
|
46
|
+
parse_url("getsentbyaddress", address).to_i
|
47
|
+
end
|
48
|
+
|
49
|
+
def hash_to_address(hash)
|
50
|
+
parse_url("hashtoaddress", hash)
|
51
|
+
end
|
52
|
+
|
53
|
+
def net_hash
|
54
|
+
body = open("http://dogechain.info/chain/Dogecoin/q/nethash?format=json").read
|
55
|
+
JSON.parse(body)
|
56
|
+
end
|
57
|
+
|
58
|
+
def total_bc
|
59
|
+
parse_url("totalbc").to_i
|
60
|
+
end
|
61
|
+
|
62
|
+
def transactions
|
63
|
+
parse_url("transactions")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe DogecoinRuby do
|
4
|
+
before(:all) do
|
5
|
+
@doge = DogecoinRuby::Client.new
|
6
|
+
@address = "DNfFHTUZ4kkXPnoYUvgt6BGVwonEFB1b2i"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns the address balance" do
|
10
|
+
@doge.address_balance(@address).should > 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns the public key hash of the address" do
|
14
|
+
@doge.address_to_hash(@address).should == "C02DEABEEB7EE1B9567CA7FD08D519091589CA6F"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should check the address for validity" do
|
18
|
+
@doge.check_address(@address).should == true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should decode the address" do
|
22
|
+
@doge.decode_address(@address).should == "1e:C02DEABEEB7EE1B9567CA7FD08D519091589CA6F"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return block count" do
|
26
|
+
@doge.get_block_count.should > 136287
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return the current difficulty" do
|
30
|
+
@doge.get_difficulty.should > 876
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return the amount ever received by the address" do
|
34
|
+
@doge.get_received_by_address(@address).should > 16312521
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return the amount ever sent by the address" do
|
38
|
+
@doge.get_sent_by_address(@address).should == 0
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return the address of the hash" do
|
42
|
+
hash = "C02DEABEEB7EE1B9567CA7FD08D519091589CA6F"
|
43
|
+
@doge.hash_to_address(hash).should == "DNfFHTUZ4kkXPnoYUvgt6BGVwonEFB1b2i"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return statistics about difficulty and network power" do
|
47
|
+
@doge.net_hash.length.should > 1
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return the total amount of currency ever mined" do
|
51
|
+
@doge.total_bc.should > 59017694014
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should return all the transaction amounts from the last block" do
|
55
|
+
@doge.transactions.length.should > 1
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'dogecoin_ruby'
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
6
|
+
# loaded once.
|
7
|
+
#
|
8
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dogecoin_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- mlapeter
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-03-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Ruby wrapper for the Dogecoin API located at http://dogechain.info
|
63
|
+
email:
|
64
|
+
- mlapeter@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- CHANGELOG
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- dogecoin_ruby.gemspec
|
77
|
+
- lib/dogecoin_ruby.rb
|
78
|
+
- lib/dogecoin_ruby/client.rb
|
79
|
+
- lib/dogecoin_ruby/version.rb
|
80
|
+
- spec/dogecoin_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
82
|
+
homepage: ''
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
hash: 2701839330415893726
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
hash: 2701839330415893726
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 1.8.25
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: Ruby wrapper for the Dogecoin API located at http://dogechain.info
|
113
|
+
test_files:
|
114
|
+
- spec/dogecoin_spec.rb
|
115
|
+
- spec/spec_helper.rb
|