utxoracle 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 966c4c18a2b785a539acbfd09a9b491b24d5e83b6b606e5db05f4f3997c3f13c
4
- data.tar.gz: 6089c1e572294e3b0a2a0c5f1e842f5b52449d78001522fe1f5c6c3db1c3382e
3
+ metadata.gz: 2ac6ef650a940eb64d180a28f6d556acca9310a42d199fa4bceb59e909cb6b2e
4
+ data.tar.gz: '0792d9c0e1867d62fcc507a0574c9338577b8468399d26b34124092525dddd8d'
5
5
  SHA512:
6
- metadata.gz: 9cbde112559f59680e49d3fbef85dee93660b2ca03f3c8c73c45d07565ec6f90871e00de939ff530ce0a63f53e8fad3ef0c0b8e338e60d05aae9628fb72af971
7
- data.tar.gz: 592eaf022a3bdfd81856cb9dfe1a6ee822daaf71d43bd824f7dd39e88d6b192cf17bb6d7d42f1a27368de5417ff8bbbbaa33c0a1e908e5b492427ae94a91a709
6
+ metadata.gz: 528c646c4201da999ca64ef7ea2ddd723a27e4663d7a253a0bc58472af5efc44d17ae28c4482b0bb271c7d87ed4269c165aa7355c6f0364b49cbdf1672b7e4e6
7
+ data.tar.gz: a34764d738c7fc67d09d57a9bf142642c2087233fe0fbb9110327ad2153b8d5c737924fab4cb120386f798b4ad4f819102d19f809a41b59b213797f7396c414d
data/.gitignore CHANGED
@@ -57,3 +57,4 @@ build-iPhoneSimulator/
57
57
 
58
58
  /Gemfile.lock
59
59
  .rspec_status
60
+ .DS_Store
data/README.md CHANGED
@@ -44,29 +44,58 @@ All examples below assume that the gem has been required.
44
44
  require 'utxoracle'
45
45
  ```
46
46
 
47
-
48
47
  ### Fetching price
49
48
 
50
49
  #### Using a specific bitcoin node
50
+
51
+ `bitcoin.conf` would look like:
52
+ ```txt
53
+ server=1
54
+ rpcuser=aUser
55
+ rpcpassword=aPassword
56
+ ```
51
57
  ```ruby
52
58
  provider = Utxoracle::Node.new("aUser", "aPassword", "127.0.0.1", 8332)
59
+ oracle = Utxoracle::Oracle.new(provider, log = false)
60
+ oracle.price("2023-10-30")
61
+ 34840
53
62
  ```
54
63
 
55
64
  #### Using mempool.space node
56
- ```ruby
57
- provider = Utxoracle::Mempool.new
58
- ```
59
65
 
60
- ####
61
66
  ```ruby
62
- oracle = Utxoracle::Oracle.new(provider)
67
+ # Mempool will throttle you without an enterprise license
68
+ provider = Utxoracle::Mempool.new
69
+ oracle = Utxoracle::Oracle.new(provider, log = false)
63
70
  oracle.price("2023-10-30")
64
71
  34840
65
72
  ```
66
73
 
74
+ ### Command line usage
75
+ ```bash
76
+ $ ./bin/run aUser aPassword 127.0.0.1 8332 2023-10-10
77
+ Reading all blocks on 2023-10-12 00:00:00 -0400...
78
+ This will take a few minutes (~144 blocks)...
79
+ Height Time(utc) Completion %
80
+ 811769 00:18:31 1.25
81
+ 811770 00:22:48 1.53
82
+ 811771 00:24:24 1.67
83
+ 811772 00:33:32 2.29
84
+ 811773 00:38:14 2.64
85
+ 811774 01:06:40 4.58
86
+ 811775 01:09:07 4.79
87
+ ...
88
+ 811931 23:41:09 98.68
89
+ 811932 23:44:01 98.89
90
+ 811933 23:48:40 99.17
91
+ blocks_on_this_day: 165
92
+ Price Estimate: $27,045
93
+ ```
94
+
95
+
67
96
  ## Development
68
97
 
69
- After checking out the repo, run `bundle i` to install dependencies.
98
+ After checking out the repo, run `bundle install` to install dependencies.
70
99
 
71
100
  To install this gem onto your local machine, run `bundle exec rake install`.
72
101
 
data/bin/run CHANGED
@@ -9,7 +9,19 @@ password = ARGV[1]
9
9
  ip = ARGV[2]
10
10
  port = ARGV[3]
11
11
  date = ARGV[4]
12
+ profile = ARGV[5]
12
13
 
13
- provider = Utxoracle::Node.new(user, password, ip, port)
14
- oracle = Utxoracle::Oracle.new(provider, true)
15
- oracle.price(date)
14
+
15
+ if profile
16
+ require 'stackprof'
17
+ # See https://github.com/tmm1/stackprof#sampling: for :cpu, :wall, :object
18
+ StackProf.run(mode: :wall, out: 'tmp/stackprof-wall.dump', raw: true) do
19
+ provider = Utxoracle::Node.new(user, password, ip, port)
20
+ oracle = Utxoracle::Oracle.new(provider, log = true)
21
+ oracle.price(date)
22
+ end
23
+ else
24
+ provider = Utxoracle::Node.new(user, password, ip, port)
25
+ oracle = Utxoracle::Oracle.new(provider, log = true)
26
+ oracle.price(date)
27
+ end
@@ -1,5 +1,4 @@
1
1
  require 'time'
2
- require_relative 'rpc'
3
2
 
4
3
  module Utxoracle
5
4
  class Oracle
@@ -25,7 +24,7 @@ module Utxoracle
25
24
  end
26
25
 
27
26
  if price_estimate = @cache[requested_date]
28
- puts "price_estimate is #{price_estimate}" if @log
27
+ puts "Price Estimate: $#{price_estimate.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse}" if @log
29
28
  return price_estimate
30
29
  end
31
30
 
@@ -261,7 +260,7 @@ module Utxoracle
261
260
  w2 = a2 / (a1 + a2)
262
261
  price_estimate = (w1 * btc_in_usd_best + w2 * btc_in_usd_2nd).to_i
263
262
 
264
- puts "price_estimate is #{price_estimate}" if @log
263
+ puts "Price Estimate: $#{price_estimate.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse}" if @log
265
264
 
266
265
  price_estimate
267
266
  end
@@ -1,10 +1,10 @@
1
1
  require_relative '../provider'
2
- require_relative '../rpc'
2
+ require 'cleanrpc'
3
3
 
4
4
  module Utxoracle
5
5
  class Node < Provider
6
6
  def initialize(rpcuser, rpcpassword, ip, port)
7
- @rpc = Rpc.new("http://#{rpcuser}:#{rpcpassword}@#{ip}:#{port}")
7
+ @rpc = Cleanrpc::Rpc.new("http://#{rpcuser}:#{rpcpassword}@#{ip}:#{port}")
8
8
  end
9
9
 
10
10
  def getblockcount
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Utxoracle
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
data/lib/utxoracle.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'utxoracle/rpc'
4
3
  require_relative 'utxoracle/version'
5
4
  require_relative 'utxoracle/oracle'
6
5
  require_relative 'utxoracle/providers/mempool'
data/utxoracle.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.require_path = 'lib'
23
23
 
24
24
  spec.add_dependency 'typhoeus', '~> 1.4.0'
25
+ spec.add_dependency 'cleanrpc', '~> 0.0.2'
25
26
 
26
27
  spec.add_development_dependency 'pry'
27
28
  spec.add_development_dependency 'rake'
@@ -30,4 +31,5 @@ Gem::Specification.new do |spec|
30
31
  spec.add_development_dependency 'rubocop-rspec'
31
32
  spec.add_development_dependency 'simplecov'
32
33
  spec.add_development_dependency 'simplecov-console'
34
+ spec.add_development_dependency 'stackprof'
33
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utxoracle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Gardner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-03 00:00:00.000000000 Z
11
+ date: 2023-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: cleanrpc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.0.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.0.2
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: pry
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,20 @@ dependencies:
122
136
  - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: stackprof
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
125
153
  description: Offline price oracle for Bitcoin. Offers programmable data providers
126
154
  (Bitcoin node, mempool, etc). Can be used from commandline, or integrated into existing
127
155
  ruby stacks.
@@ -144,11 +172,9 @@ files:
144
172
  - lib/utxoracle/providers/mempool.rb
145
173
  - lib/utxoracle/providers/node.rb
146
174
  - lib/utxoracle/request.rb
147
- - lib/utxoracle/rpc.rb
148
175
  - lib/utxoracle/version.rb
149
176
  - spec/spec_helper.rb
150
177
  - spec/utxoracle/oracle_spec.rb
151
- - spec/utxoracle/rpc_spec.rb
152
178
  - spec/utxoracle_spec.rb
153
179
  - utxoracle.gemspec
154
180
  homepage: https://github.com/Carolina-Bitcoin-Project/UTXOracle
@@ -170,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
196
  - !ruby/object:Gem::Version
171
197
  version: '0'
172
198
  requirements: []
173
- rubygems_version: 3.4.10
199
+ rubygems_version: 3.4.21
174
200
  signing_key:
175
201
  specification_version: 4
176
202
  summary: Offline price oracle for Bitcoin.
data/lib/utxoracle/rpc.rb DELETED
@@ -1,30 +0,0 @@
1
- require 'net/http'
2
- require 'uri'
3
- require 'json'
4
-
5
- module Utxoracle
6
- class Rpc
7
- def initialize(service_url)
8
- @uri = URI.parse(service_url)
9
- end
10
-
11
- def method_missing(name, *args)
12
- post_body = { 'method' => name, 'params' => args, 'id' => 'jsonrpc' }.to_json
13
- resp = JSON.parse(http_post_request(post_body))
14
- raise JSONRPCError, resp['error'] if resp['error']
15
-
16
- resp['result']
17
- end
18
-
19
- def http_post_request(post_body)
20
- http = Net::HTTP.new(@uri.host, @uri.port)
21
- request = Net::HTTP::Post.new(@uri.request_uri)
22
- request.basic_auth @uri.user, @uri.password
23
- request.content_type = 'application/json'
24
- request.body = post_body
25
- http.request(request).body
26
- end
27
-
28
- class JSONRPCError < RuntimeError; end
29
- end
30
- end
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Utxoracle::Rpc do
6
- let(:rpc) do
7
- described_class.new('http://foo:bar@127.0.0.1:8332')
8
- end
9
-
10
- describe '.new' do
11
- it 'creates an instance of Rpc with given uri' do
12
- expect(rpc.class).to eq(Utxoracle::Rpc)
13
- end
14
- end
15
-
16
- it 'exposes http request interface' do
17
- allow(rpc).to receive(:http_post_request).and_return(true)
18
- expect(rpc.http_post_request('')).to eq true
19
- end
20
-
21
- it 'forwards methods over http' do
22
- allow(rpc).to receive(:http_post_request).and_return(
23
- "{\"result\":814521,\"error\":null,\"id\":\"jsonrpc\"}\n"
24
- )
25
- expect(rpc.getblockcount).to eq 814_521
26
- end
27
-
28
- it 'returns error from http endpoint when indicated' do
29
- expect(rpc).to receive(:http_post_request).and_return(
30
- "{\"result\":814521,\"error\":\"test error\",\"id\":\"jsonrpc\"}\n"
31
- )
32
- expect { rpc.test_rpc_call }.to raise_error(Utxoracle::Rpc::JSONRPCError)
33
- end
34
- end