monero 0.0.0.1 → 0.0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +105 -6
- data/lib/monero.rb +1 -0
- data/lib/monero/client.rb +11 -10
- data/lib/monero/config.rb +1 -3
- data/lib/monero/transfer.rb +55 -0
- data/lib/monero/version.rb +1 -1
- data/lib/monero/wallet.rb +56 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b0549acfa68f3efdc2d4a1a141a460ed180a699
|
4
|
+
data.tar.gz: a554fde5c534e43c9e019ae008630f8c792c9b05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c756cdb2a4b451692e704219ad76b768f9ea3e183618fa1de2fe4207d0b111ebcd7e9e448e5fdca044aa3f149ddabb1fca919cdd9c415e80fed53fbc25e1ef12
|
7
|
+
data.tar.gz: dd78a9e2f341d2665ee4e7cb7277bde30e851914f44787723a163c9bc26cd9cc81eb9c8e8ea6c444d2675f50920af4a92ac1057b96fd94ca2c6317a4bc616684
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
monero-*.gem
|
data/README.md
CHANGED
@@ -1,18 +1,117 @@
|
|
1
1
|
# Monero Ruby Client
|
2
2
|
|
3
|
-
Ruby client to connect and use Monero
|
3
|
+
Ruby client to connect and use [Monero Wallet RPC](https://getmonero.org/resources/developer-guides/wallet-rpc.html).
|
4
4
|
|
5
5
|
|
6
|
-
|
6
|
+
___
|
7
|
+
#### Disclaimer - before you start - *important notice!*
|
8
|
+
To try out please make sure that you run your **monerod** and your **monero-wallet-rpc** with the `--testnet` option. Always use the Testchain to play around. Be careful with your wallet, you might lose coins if you try out on the real chain.
|
7
9
|
|
8
|
-
|
10
|
+
- Testnet Faucet: https://dis.gratis/
|
11
|
+
- Testnet Blockexplorer: https://testnet.xmrchain.com
|
12
|
+
---
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
For easy installation add `gem 'monero'` to your Gemfile or run `gem install monero`
|
19
|
+
|
20
|
+
|
21
|
+
## Preparation
|
22
|
+
|
23
|
+
Start your daemon `./monerod --testnet`
|
24
|
+
|
25
|
+
Start your RPC Client `./monero-wallet-rpc --testnet --rpc-bind-port 18081 --rpc-bind-ip 127.0.0.1 --rpc-login username:password --log-level 4 --wallet-dir ./`
|
26
|
+
|
27
|
+
- To open a wallet at start use `--wallet-file filename` and `--password pass`
|
28
|
+
- In case you need to access the client from another machine, you need to set `--confirm-external-bind`.
|
29
|
+
- To be able to create/open other wallets you need to specify `--wallet-file /path/to/wallets/on/your/machine`
|
30
|
+
- if you don't specify `--rpc-login` a file will be created that stores the login data (`cat monero-wallet-rpc.18081.login`)
|
31
|
+
|
32
|
+
## Getting started
|
33
|
+
|
34
|
+
### Configuration
|
35
|
+
Monero.config.host = "127.0.0.1"
|
9
36
|
Monero.config.port = "18081"
|
10
37
|
Monero.config.username = "username"
|
11
38
|
Monero.config.password = "password"
|
12
39
|
|
13
40
|
|
14
|
-
usage:
|
15
41
|
|
16
|
-
|
42
|
+
### Usage
|
43
|
+
|
44
|
+
Monero Ruby Client is very easy to use. Full documentation of RPC Client: https://getmonero.org/resources/developer-guides/wallet-rpc.html#transfer
|
45
|
+
|
46
|
+
___
|
47
|
+
|
48
|
+
|
49
|
+
Get the current address
|
50
|
+
|
51
|
+
Monero::Wallet.address
|
52
|
+
=> "9wm6oNA5nP3LnugTKRSwGJhW4vnYv8RAVdRvYyvbistbHUnojyTHyHcYpbZvbTZHDsi4rF1EK5TiYgnCN6FWM9HjTDpKXAE"
|
53
|
+
___
|
54
|
+
|
55
|
+
Create a new address for a payment (integrated address)
|
56
|
+
|
57
|
+
Monero::Wallet.make_integrated_address
|
58
|
+
=> {"integrated_address"=>"A7TmpAyaPeZLnugTKRSwGJhW4vnYv8RAVdRvYyvbistbHUnojyTHyHcYpbZvbTZHDsi4rF1EK5TiYgnCN6FWM9HjfufSYUchQ8hH2R272H",
|
59
|
+
"payment_id"=>"9d985c985ce58a8e"}
|
60
|
+
___
|
61
|
+
To get the balance of the current wallet (we use the gem 'money')
|
62
|
+
|
63
|
+
Monero::Wallet.balance
|
64
|
+
# returns an ::XMR object which is just a shortcut for ::Money(amount, :xmr)
|
65
|
+
=> #<Money fractional:9980629640000 currency:XMR>
|
66
|
+
|
67
|
+
Monero::Wallet.balance.format
|
68
|
+
=> "9.980629640000 XMR"
|
69
|
+
|
70
|
+
___
|
71
|
+
To get the current block height
|
72
|
+
|
73
|
+
Monero::Wallet.getheight
|
74
|
+
=> 1008032
|
75
|
+
|
76
|
+
|
77
|
+
___
|
78
|
+
|
79
|
+
Send XMR to an address via `Monero::Transfer.create`. If successfull you will get the transaction details. If not succesfull you'll get returned nil.
|
80
|
+
|
81
|
+
amount= 20075 #in atomic units. 1000000000000 == 1.0 XMR
|
82
|
+
Monero::Transfer.create("A7TmpAyaPeZLnugTKRSwGJhW4vnYv8RAVdRvYyvbistbHUnojyTHyHcYpbZvbTZHDsi4rF1EK5TiYgnCN6FWM9HjfwGRvbCHYCZAaKSzDx", amount)
|
83
|
+
=> {"fee"=>19415760000,
|
84
|
+
"tx_blob"=>"020001020005bbcf0896e3.......
|
85
|
+
|
86
|
+
|
87
|
+
To send payments you can also specify the following options:
|
88
|
+
|
89
|
+
options = { fee: fee, mixin: 5, unlock_time: unlock_time, payment_id: "c7e7146b3335aa54", get_tx_key: true, priority: 0, do_not_relay: false, get_tx_hex: true}
|
90
|
+
Please note that `fee` is currently ignored by the chain.
|
91
|
+
|
92
|
+
|
93
|
+
To send payments to multiple recipients simply use an array of `[:recipient, :amount]`. For example:
|
94
|
+
|
95
|
+
recipients = [
|
96
|
+
{address:A7TmpAyaPeZLnugTKRSwGJhW4vnYv8RAVdRvYyvbistbHUnojyTHyHcYpbZvbTZHDsi4rF1EK5TiYgnCN6FWM9HjfwGRvbCHYCZAaKSzDx amount: 1599999},
|
97
|
+
{address:A7TmpAyaPeZLnugTKRSwGJhW4vnYv8RAVdRvYyvbistbHUnojyTHyHcYpbZvbTZHDsi4rF1EK5TiYgnCN6FWM9Hjftr1RgJ6RM4BMMPLUc amount: 130000},
|
98
|
+
{address:A7TmpAyaPeZLnugTKRSwGJhW4vnYv8RAVdRvYyvbistbHUnojyTHyHcYpbZvbTZHDsi4rF1EK5TiYgnCN6FWM9HjfrgPgAEasYGSVhUdwe amount: 442130000}
|
99
|
+
]
|
100
|
+
|
101
|
+
Monero::Transfer.send_bulk(recipients, options)
|
102
|
+
|
103
|
+
___
|
104
|
+
|
105
|
+
|
106
|
+
## Donations
|
107
|
+
If this was useful you might consider a small donation:
|
108
|
+
|
109
|
+
- XMR: 4H19KAdSw1pL2v1iaEx31ngQCQcEGobUpevqtzSzKPTAEAt1Ay7NZrQgU6mnN2mVyWi7yk2ig68KsU8bfXQ45ainLTZFWU7m94yT3D9qUX
|
110
|
+
- BTC:
|
111
|
+
- LTC:
|
112
|
+
|
113
|
+
|
114
|
+
|
17
115
|
|
18
|
-
|
116
|
+
## LICENSE
|
117
|
+
MIT
|
data/lib/monero.rb
CHANGED
data/lib/monero/client.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
module Monero
|
2
2
|
class Client
|
3
3
|
|
4
|
-
def self.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
data = '{"jsonrpc":"2.0","id":"0","method": "'+method+'", "params": { '+params_string+' } }'
|
4
|
+
def self.close!
|
5
|
+
request("stop_wallet")
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.request(method, params="")
|
9
|
+
data = '{"jsonrpc":"2.0","id":"0","method": "'+method+'", "params": '+params.to_json+' }'
|
10
|
+
|
13
11
|
args = " -s"
|
14
12
|
args << " -u #{Monero.config.username}:#{Monero.config.password} --digest"
|
15
13
|
args << " -X POST #{base_uri}/json_rpc"
|
16
14
|
args << " -d '#{data}'"
|
17
15
|
args << " -H 'Content-Type: application/json'"
|
16
|
+
|
17
|
+
p "curl #{args}" if Monero.config.debug
|
18
|
+
|
18
19
|
json = JSON.parse(`curl #{args}`)
|
19
20
|
json["result"]
|
20
21
|
end
|
@@ -26,5 +27,5 @@ module Monero
|
|
26
27
|
end
|
27
28
|
|
28
29
|
end
|
29
|
-
|
30
|
+
|
30
31
|
end
|
data/lib/monero/config.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
# transfer
|
2
|
+
# Send monero to a number of recipients.
|
3
|
+
# Inputs:
|
4
|
+
# destinations - array of destinations to receive XMR:
|
5
|
+
# amount - unsigned int; Amount to send to each destination, in atomic units.
|
6
|
+
# address - string; Destination public address.
|
7
|
+
|
8
|
+
# fee - unsigned int; Ignored, will be automatically calculated.
|
9
|
+
|
10
|
+
# mixin - unsigned int; Number of outpouts from the blockchain to mix with (0 means no mixing).
|
11
|
+
|
12
|
+
# unlock_time - unsigned int; Number of blocks before the monero can be spent (0 to not add a lock).
|
13
|
+
|
14
|
+
# payment_id - string; (Optional) Random 32-byte/64-character hex string to identify a transaction.
|
15
|
+
|
16
|
+
# get_tx_key - boolean; (Optional) Return the transaction key after sending.
|
17
|
+
|
18
|
+
# priority - unsigned int; Set a priority for the transaction. Accepted Values are: 0-3 for: default, unimportant, normal, elevated, priority.
|
19
|
+
|
20
|
+
# do_not_relay - boolean; (Optional) If true, the newly created transaction will not be relayed to the monero network. (Defaults to false)
|
21
|
+
|
22
|
+
# get_tx_hex - boolean; Return the transaction as hex string after sending
|
23
|
+
|
24
|
+
|
25
|
+
module Monero
|
26
|
+
# => {"integrated_address"=>"A7TmpAyaPeZLnugTKRSwGJhW4vnYv8RAVdRvYyvbistbHUnojyTHyHcYpbZvbTZHDsi4rF1EK5TiYgnCN6FWM9HjfwGRvbCHYCZAaKSzDx", "payment_id"=>"c7e7146b3335aa54"}
|
27
|
+
|
28
|
+
class Transfer
|
29
|
+
|
30
|
+
def self.create(address, amount, args={})
|
31
|
+
send_bulk([address: address, amount: amount], args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.send_bulk(destinations, args={})
|
35
|
+
|
36
|
+
mixin = args.fetch(:mixin, 4)
|
37
|
+
fee = args.fetch(:fee, 1) # ignored anyways
|
38
|
+
unlock_time = args.fetch(:unlock_time, 0)
|
39
|
+
payment_id = args.fetch(:payment_id, nil)
|
40
|
+
get_tx_key = args.fetch(:get_tx_key, true)
|
41
|
+
priority = args.fetch(:priority, 0)
|
42
|
+
do_not_relay = args.fetch(:do_not_relay, false)
|
43
|
+
get_tx_hex = args.fetch(:get_tx_hex, false)
|
44
|
+
|
45
|
+
|
46
|
+
options = {
|
47
|
+
destinations: destinations, fee: fee, mixin: mixin, unlock_time: unlock_time,
|
48
|
+
payment_id: payment_id, get_tx_key: get_tx_key, priority: priority, do_not_relay: do_not_relay, get_tx_hex: get_tx_hex
|
49
|
+
}
|
50
|
+
|
51
|
+
Monero::Client.request("transfer", options)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
data/lib/monero/version.rb
CHANGED
data/lib/monero/wallet.rb
CHANGED
@@ -31,6 +31,9 @@ module Monero
|
|
31
31
|
raise ArgumentError unless ["mnemonic", "view_key"].include?(type.to_s)
|
32
32
|
Monero::Client.request("query_key", {key_type: type})["key"]
|
33
33
|
end
|
34
|
+
def self.view_key; query_key(:view_key); end
|
35
|
+
def self.mnemonic_seed; query_key(:mnemonic); end
|
36
|
+
|
34
37
|
|
35
38
|
def self.make_integrated_address(payment_id = "")
|
36
39
|
# TODO
|
@@ -51,10 +54,63 @@ module Monero
|
|
51
54
|
payments.map{|x| Payment.from_raw(x) }
|
52
55
|
end
|
53
56
|
|
57
|
+
|
58
|
+
# in - boolean;
|
59
|
+
# out - boolean;
|
60
|
+
# pending - boolean;
|
61
|
+
# failed - boolean;
|
62
|
+
# pool - boolean;
|
63
|
+
# filter_by_height - boolean;
|
64
|
+
# min_height - unsigned int;
|
65
|
+
# max_height - unsigned int;
|
66
|
+
def self.get_transfers(args={})
|
67
|
+
f_in = args.fetch(:in, true)
|
68
|
+
out = args.fetch(:out, false)
|
69
|
+
pending = args.fetch(:pending, true)
|
70
|
+
failed = args.fetch(:failed, false)
|
71
|
+
pool = args.fetch(:pool, true)
|
72
|
+
filter_by_height = args.fetch(:filter_by_height, false)
|
73
|
+
min_height = args.fetch(:min_height, 0)
|
74
|
+
max_height = args.fetch(:max_height, 0)
|
75
|
+
|
76
|
+
options = {in: f_in, out: out, pending: pending, failed: failed, pool: pool, filter_by_height: filter_by_height, min_height: min_height, max_height: max_height}
|
77
|
+
|
78
|
+
Monero::Client.request("get_transfers", options)
|
79
|
+
end
|
80
|
+
|
54
81
|
def self.get_transfer_by_txid(txid)
|
55
82
|
Monero::Client.request("get_transfer_by_txid", {txid: txid })
|
56
83
|
end
|
57
84
|
|
85
|
+
# creates a wallet and uses it
|
86
|
+
# if wallet exists, will automatically uses it!
|
87
|
+
def self.create_wallet(filename, password, language="English")
|
88
|
+
# TODO
|
89
|
+
# language correct format?
|
90
|
+
options = { filename: filename, password: password, language: language }
|
91
|
+
!! Monero::Client.request("create_wallet", options)
|
92
|
+
end
|
93
|
+
singleton_class.send(:alias_method, :create, :create_wallet)
|
94
|
+
|
95
|
+
# returns current balance if open successfull
|
96
|
+
def self.open_wallet(filename, password)
|
97
|
+
options = { filename: filename, password: password}
|
98
|
+
if Monero::Client.request("open_wallet", options)
|
99
|
+
balance
|
100
|
+
else
|
101
|
+
false
|
102
|
+
end
|
103
|
+
end
|
104
|
+
singleton_class.send(:alias_method, :open, :open_wallet)
|
105
|
+
|
106
|
+
# stops current wallet
|
107
|
+
def self.stop_wallet
|
108
|
+
Monero::Client.close!
|
109
|
+
end
|
110
|
+
singleton_class.send(:alias_method, :close, :stop_wallet)
|
111
|
+
|
112
|
+
|
113
|
+
|
58
114
|
end
|
59
115
|
|
60
116
|
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.0.
|
4
|
+
version: 0.0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Kretschmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,11 +73,13 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- ".gitignore"
|
76
77
|
- README.md
|
77
78
|
- lib/monero.rb
|
78
79
|
- lib/monero/client.rb
|
79
80
|
- lib/monero/config.rb
|
80
81
|
- lib/monero/payment.rb
|
82
|
+
- lib/monero/transfer.rb
|
81
83
|
- lib/monero/version.rb
|
82
84
|
- lib/monero/wallet.rb
|
83
85
|
- lib/xmr.rb
|