monero 0.0.0.8 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +13 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +41 -0
- data/LICENSE.txt +21 -0
- data/README.md +127 -100
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/monero.rb +37 -13
- data/lib/monero_rpc/client.rb +49 -0
- data/lib/monero_rpc/config.rb +13 -0
- data/lib/{rpc → monero_rpc}/payment.rb +1 -3
- data/lib/{rpc → monero_rpc}/transfer.rb +19 -24
- data/lib/monero_rpc/transfer_class.rb +30 -0
- data/lib/monero_rpc/version.rb +3 -0
- data/lib/monero_rpc/wallet.rb +157 -0
- data/monero.gemspec +3 -3
- data/spec/monero_spec.rb +109 -0
- data/spec/spec_helper.rb +20 -0
- metadata +29 -18
- data/lib/rpc/client.rb +0 -40
- data/lib/rpc/config.rb +0 -8
- data/lib/rpc/incoming_transfer.rb +0 -26
- data/lib/rpc/version.rb +0 -3
- data/lib/rpc/wallet.rb +0 -148
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "monero"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
|
15
|
+
# configure the RPC singleton
|
16
|
+
MoneroRPC.config.host = "change to your ip address"
|
17
|
+
MoneroRPC.config.port = "28081"
|
18
|
+
MoneroRPC.config.username = "username"
|
19
|
+
MoneroRPC.config.password = "password"
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Kretschmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: money
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -69,21 +69,31 @@ dependencies:
|
|
69
69
|
description: A Monero-Wallet-RPC ruby client
|
70
70
|
email:
|
71
71
|
- tim@krtschmr.de
|
72
|
-
executables:
|
72
|
+
executables:
|
73
|
+
- console
|
74
|
+
- setup
|
73
75
|
extensions: []
|
74
76
|
extra_rdoc_files: []
|
75
77
|
files:
|
76
78
|
- ".gitignore"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
77
82
|
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
78
86
|
- lib/monero.rb
|
79
|
-
- lib/
|
80
|
-
- lib/
|
81
|
-
- lib/
|
82
|
-
- lib/
|
83
|
-
- lib/
|
84
|
-
- lib/
|
85
|
-
- lib/
|
87
|
+
- lib/monero_rpc/client.rb
|
88
|
+
- lib/monero_rpc/config.rb
|
89
|
+
- lib/monero_rpc/payment.rb
|
90
|
+
- lib/monero_rpc/transfer.rb
|
91
|
+
- lib/monero_rpc/transfer_class.rb
|
92
|
+
- lib/monero_rpc/version.rb
|
93
|
+
- lib/monero_rpc/wallet.rb
|
86
94
|
- monero.gemspec
|
95
|
+
- spec/monero_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
87
97
|
homepage: ''
|
88
98
|
licenses:
|
89
99
|
- MIT
|
@@ -103,9 +113,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
113
|
- !ruby/object:Gem::Version
|
104
114
|
version: 1.3.6
|
105
115
|
requirements: []
|
106
|
-
|
107
|
-
rubygems_version: 2.6.11
|
116
|
+
rubygems_version: 3.0.3
|
108
117
|
signing_key:
|
109
118
|
specification_version: 4
|
110
119
|
summary: A Monero-Wallet-RPC ruby client
|
111
|
-
test_files:
|
120
|
+
test_files:
|
121
|
+
- spec/monero_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
data/lib/rpc/client.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module RPC
|
2
|
-
class Client
|
3
|
-
#class RequestError < StandardError; end
|
4
|
-
|
5
|
-
|
6
|
-
def self.close!
|
7
|
-
request("stop_wallet")
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.request(method, params="")
|
11
|
-
data = '{"jsonrpc":"2.0","id":"0","method": "'+method+'", "params": '+params.to_json+' }'
|
12
|
-
|
13
|
-
args = ""
|
14
|
-
args << " -s"
|
15
|
-
args << " -u #{RPC.config.username}:#{RPC.config.password} --digest"
|
16
|
-
args << " -X POST #{base_uri}/json_rpc"
|
17
|
-
args << " -d '#{data}'"
|
18
|
-
args << " -H 'Content-Type: application/json'"
|
19
|
-
|
20
|
-
p "curl #{args}" if RPC.config.debug
|
21
|
-
|
22
|
-
json = JSON.parse(`curl #{args}`)
|
23
|
-
|
24
|
-
# Error handling
|
25
|
-
if json["error"]
|
26
|
-
raise "#{json["error"]["message"]} | code: #{json["error"]["code"]}"
|
27
|
-
end
|
28
|
-
|
29
|
-
json["result"]
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def self.base_uri
|
35
|
-
"http://#{RPC.config.host}:#{RPC.config.port}"
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
data/lib/rpc/config.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module RPC
|
2
|
-
class IncomingTransfer
|
3
|
-
|
4
|
-
attr_accessor :address, :amount, :double_spend_seen, :fee, :height, :note, :payment_id, :subaddr_index, :timestamp, :txid, :type, :unlock_time, :destinations
|
5
|
-
|
6
|
-
def initialize(args={})
|
7
|
-
args.each do |k,v|
|
8
|
-
self.send("#{k}=", v)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def confirmations
|
13
|
-
pending? ? 0 : RPC::Wallet.getheight - height
|
14
|
-
end
|
15
|
-
|
16
|
-
def confirmed?
|
17
|
-
confirmations >= 10
|
18
|
-
end
|
19
|
-
|
20
|
-
def pending?
|
21
|
-
height == 0
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
data/lib/rpc/version.rb
DELETED
data/lib/rpc/wallet.rb
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
module RPC
|
2
|
-
|
3
|
-
class Wallet
|
4
|
-
|
5
|
-
def self.create_address(label="")
|
6
|
-
RPC::Client.request("create_address", label: label)
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.get_address
|
10
|
-
RPC::Client.request("get_address")["address"]
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.address; getaddress; end
|
14
|
-
|
15
|
-
def self.get_addresses
|
16
|
-
RPC::Client.request("get_address")["addresses"]
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.getbalance
|
20
|
-
RPC::Client.request("getbalance")
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.balance
|
24
|
-
XMR.new(getbalance["balance"])
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.unlocked_balance
|
28
|
-
XMR.new(getbalance["unlocked_balance"])
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.getaddress
|
32
|
-
RPC::Client.request("getaddress")["address"]
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.getheight
|
36
|
-
RPC::Client.request("getheight")["height"]
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.query_key(type)
|
40
|
-
raise ArgumentError unless ["mnemonic", "view_key"].include?(type.to_s)
|
41
|
-
RPC::Client.request("query_key", {key_type: type})["key"]
|
42
|
-
end
|
43
|
-
def self.view_key; query_key(:view_key); end
|
44
|
-
def self.mnemonic_seed; query_key(:mnemonic); end
|
45
|
-
|
46
|
-
|
47
|
-
def self.make_integrated_address(payment_id = "")
|
48
|
-
# TODO
|
49
|
-
# Check if payment_id is correct format
|
50
|
-
RPC::Client.request("make_integrated_address", {payment_id: payment_id})
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.split_integrated_address(address)
|
54
|
-
RPC::Client.request("split_integrated_address", {integrated_address: address})
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.incoming_transfers(type)
|
58
|
-
raise ArgumentError unless ["all", "available", "unavailable"].include?(type.to_s)
|
59
|
-
json = RPC::Client.request("incoming_transfers", {transfer_type: type})
|
60
|
-
json["transfers"] || []
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.get_payments(payment_id)
|
64
|
-
payments = RPC::Client.request("get_payments", {payment_id: payment_id})["payments"] || []
|
65
|
-
# TODO
|
66
|
-
# make it a RPC::Payment that hase a amount as XMR and confirmations (getheight - tx.block_height)
|
67
|
-
payments.map{|x| Payment.from_raw(x) }
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.get_bulk_payments(payment_ids, min_block_height)
|
71
|
-
payments = RPC::Client.request("get_bulk_payments", {"payment_ids": payment_ids, "min_block_height": min_block_height})
|
72
|
-
return payments
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
# in - boolean;
|
77
|
-
# out - boolean;
|
78
|
-
# pending - boolean;
|
79
|
-
# failed - boolean;
|
80
|
-
# pool - boolean;
|
81
|
-
# filter_by_height - boolean;
|
82
|
-
# min_height - unsigned int;
|
83
|
-
# max_height - unsigned int;
|
84
|
-
def self.get_transfers(args={})
|
85
|
-
f_in = args.fetch(:in, true)
|
86
|
-
out = args.fetch(:out, false)
|
87
|
-
pending = args.fetch(:pending, true)
|
88
|
-
failed = args.fetch(:failed, false)
|
89
|
-
pool = args.fetch(:pool, true)
|
90
|
-
filter_by_height = args.fetch(:filter_by_height, false)
|
91
|
-
min_height = args.fetch(:min_height, 0)
|
92
|
-
max_height = args.fetch(:max_height, 0)
|
93
|
-
|
94
|
-
options = {in: f_in, out: out, pending: pending, failed: failed, pool: pool, filter_by_height: filter_by_height, min_height: min_height}
|
95
|
-
options[:max_height] = max_height if max_height > min_height
|
96
|
-
|
97
|
-
h = Hash.new
|
98
|
-
json = RPC::Client.request("get_transfers", options)
|
99
|
-
json.map{|k, v|
|
100
|
-
h[k] = v.collect{|transfer| Module.const_get((RPC.config.transfer_clazz || "RPC::IncomingTransfer")).new(transfer) }
|
101
|
-
}
|
102
|
-
return h
|
103
|
-
end
|
104
|
-
|
105
|
-
def self.get_all_incoming_transfers(args={})
|
106
|
-
min_height = args.fetch(:min_height, 0)
|
107
|
-
max_height = args.fetch(:max_height, 0)
|
108
|
-
|
109
|
-
all = get_transfers(filter_by_height: true, min_height: min_height, max_height: max_height, in: true, out: false, pending: true, pool: true)
|
110
|
-
[ all["in"], all["pending"], all["pool"]].flatten.compact
|
111
|
-
end
|
112
|
-
|
113
|
-
def self.get_transfer_by_txid(txid)
|
114
|
-
RPC::Client.request("get_transfer_by_txid", {txid: txid })
|
115
|
-
end
|
116
|
-
|
117
|
-
# creates a wallet and uses it
|
118
|
-
# if wallet exists, will automatically uses it!
|
119
|
-
def self.create_wallet(filename, password, language="English")
|
120
|
-
# TODO
|
121
|
-
# language correct format?
|
122
|
-
options = { filename: filename, password: password, language: language }
|
123
|
-
!! RPC::Client.request("create_wallet", options)
|
124
|
-
end
|
125
|
-
singleton_class.send(:alias_method, :create, :create_wallet)
|
126
|
-
|
127
|
-
# returns current balance if open successfull
|
128
|
-
def self.open_wallet(filename, password="")
|
129
|
-
options = { filename: filename, password: password}
|
130
|
-
if RPC::Client.request("open_wallet", options)
|
131
|
-
balance
|
132
|
-
else
|
133
|
-
false
|
134
|
-
end
|
135
|
-
end
|
136
|
-
singleton_class.send(:alias_method, :open, :open_wallet)
|
137
|
-
|
138
|
-
# stops current RPC process!
|
139
|
-
def self.stop_wallet
|
140
|
-
RPC::Client.close!
|
141
|
-
end
|
142
|
-
singleton_class.send(:alias_method, :close, :stop_wallet)
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
end
|
147
|
-
|
148
|
-
end
|