RecordsKeeperRubyLib 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -1
- data/Gemfile.lock +3 -1
- data/README.md +92 -1
- data/config.yaml +8 -0
- data/docs/address_doc.rb +105 -0
- data/docs/asset_doc.rb +54 -0
- data/docs/block_doc.rb +63 -0
- data/docs/blockchain_doc.rb +77 -0
- data/docs/permissions_doc.rb +54 -0
- data/docs/stream_doc.rb +79 -0
- data/docs/transaction_doc.rb +110 -0
- data/docs/wallet_doc.rb +122 -0
- data/lib/RecordsKeeperRubyLib/address.rb +198 -186
- data/lib/RecordsKeeperRubyLib/assets.rb +99 -92
- data/lib/RecordsKeeperRubyLib/block.rb +94 -88
- data/lib/RecordsKeeperRubyLib/blockchain.rb +148 -138
- data/lib/RecordsKeeperRubyLib/config.yaml +8 -0
- data/lib/RecordsKeeperRubyLib/permissions.rb +77 -71
- data/lib/RecordsKeeperRubyLib/stream.rb +220 -164
- data/lib/RecordsKeeperRubyLib/transaction.rb +213 -183
- data/lib/RecordsKeeperRubyLib/version.rb +1 -1
- data/lib/RecordsKeeperRubyLib/wallet.rb +263 -247
- data/lib/config.yaml +8 -0
- metadata +14 -6
- data/lib/RecordsKeeperRubyLib/sample_config.yaml +0 -29
- data/lib/sample_config.yaml +0 -29
- data/sample_config.yaml +0 -29
@@ -1,183 +1,213 @@
|
|
1
|
-
# Library to work with RecordsKeeper transactions.
|
2
|
-
|
3
|
-
# You can send transaction, create raw transaction, sign raw transaction, send raw transaction, send signed transaction,
|
4
|
-
# retrieve transaction information and calculate transaction's fees by using transaction class. You just have to pass
|
5
|
-
# parameters to invoke the pre-defined functions.
|
6
|
-
|
7
|
-
require 'rubygems'
|
8
|
-
require 'httparty'
|
9
|
-
require 'json'
|
10
|
-
require 'binary_parser'
|
11
|
-
require 'yaml'
|
12
|
-
require 'hex_string'
|
13
|
-
|
14
|
-
module RecordsKeeperRubyLib
|
15
|
-
|
16
|
-
class Transaction
|
17
|
-
|
18
|
-
# Entry point for accessing
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
auth = {:username => @user, :password => @password}
|
87
|
-
options = {
|
88
|
-
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
89
|
-
:basic_auth => auth,
|
90
|
-
:body => [ {"method":"
|
91
|
-
}
|
92
|
-
response = HTTParty.get(@url, options)
|
93
|
-
out = response.parsed_response
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
# Function to
|
165
|
-
def self.
|
166
|
-
auth = {:username => @user, :password => @password}
|
167
|
-
options = {
|
168
|
-
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
169
|
-
:basic_auth => auth,
|
170
|
-
:body => [ {"method":"
|
171
|
-
}
|
172
|
-
response = HTTParty.get(@url, options)
|
173
|
-
out = response.parsed_response
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
1
|
+
# Library to work with RecordsKeeper transactions.
|
2
|
+
|
3
|
+
# You can send transaction, create raw transaction, sign raw transaction, send raw transaction, send signed transaction,
|
4
|
+
# retrieve transaction information and calculate transaction's fees by using transaction class. You just have to pass
|
5
|
+
# parameters to invoke the pre-defined functions.
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'httparty'
|
9
|
+
require 'json'
|
10
|
+
require 'binary_parser'
|
11
|
+
require 'yaml'
|
12
|
+
require 'hex_string'
|
13
|
+
|
14
|
+
module RecordsKeeperRubyLib
|
15
|
+
|
16
|
+
class Transaction
|
17
|
+
|
18
|
+
# # Entry point for accessing Transaction class functions
|
19
|
+
if File.exist?('config.yaml')
|
20
|
+
# Import values from configuration file.
|
21
|
+
cfg = YAML::load(File.open('config.yaml','r'))
|
22
|
+
|
23
|
+
@url = cfg['url']
|
24
|
+
@user = cfg['rkuser']
|
25
|
+
@password = cfg['passwd']
|
26
|
+
@chain = cfg['chain']
|
27
|
+
|
28
|
+
else
|
29
|
+
#Import using ENV variables
|
30
|
+
|
31
|
+
@url = ENV['url']
|
32
|
+
@user = ENV['rkuser']
|
33
|
+
@password = ENV['passwd']
|
34
|
+
@chain = ENV['chain']
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
# Function to send transaction on RecordsKeeper Blockchain
|
39
|
+
def self.sendTransaction sender_address, receiveraddress, data, amount
|
40
|
+
data_hex = data.to_hex_string
|
41
|
+
datahex = data_hex.delete(' ')
|
42
|
+
auth = {:username => @user, :password => @password}
|
43
|
+
options = {
|
44
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
45
|
+
:basic_auth => auth,
|
46
|
+
:body => [ {"method":"createrawsendfrom","params":[sender_address, { receiveraddress => amount }, [datahex], "send"],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
47
|
+
}
|
48
|
+
response = HTTParty.get(@url, options)
|
49
|
+
out = response.parsed_response
|
50
|
+
check = out[0]['result']
|
51
|
+
|
52
|
+
if check.nil?
|
53
|
+
txid = out[0]['error']['message']
|
54
|
+
else
|
55
|
+
txid = out[0]['result']
|
56
|
+
end
|
57
|
+
return txid;
|
58
|
+
end
|
59
|
+
|
60
|
+
# Function to create transaction hex on RecordsKeeper Blockchain
|
61
|
+
def self.createRawTransaction sender_address, receiveraddress, data, amount
|
62
|
+
data_hex = data.to_hex_string
|
63
|
+
datahex = data_hex.delete(' ')
|
64
|
+
auth = {:username => @user, :password => @password}
|
65
|
+
options = {
|
66
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
67
|
+
:basic_auth => auth,
|
68
|
+
:body => [ {"method":"createrawsendfrom","params":[sender_address, {receiveraddress => amount}, [datahex], ''],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
69
|
+
}
|
70
|
+
response = HTTParty.get(@url, options)
|
71
|
+
out = response.parsed_response
|
72
|
+
check = out[0]['result']
|
73
|
+
|
74
|
+
if check.nil?
|
75
|
+
txhex = out[0]['error']['message']
|
76
|
+
else
|
77
|
+
txhex = out[0]['result']
|
78
|
+
end
|
79
|
+
return txhex;
|
80
|
+
end
|
81
|
+
|
82
|
+
# Function to sign transaction on RecordsKeeper Blockchain
|
83
|
+
def self.signRawTransaction txHex, private_key
|
84
|
+
priv_key = []
|
85
|
+
priv_key.push(private_key)
|
86
|
+
auth = {:username => @user, :password => @password}
|
87
|
+
options = {
|
88
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
89
|
+
:basic_auth => auth,
|
90
|
+
:body => [ {"method":"signrawtransaction","params":[txHex, [], priv_key],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
91
|
+
}
|
92
|
+
response = HTTParty.get(@url, options)
|
93
|
+
out = response.parsed_response
|
94
|
+
if out[0]['result']['complete']
|
95
|
+
signedHex = out[0]['result']['hex']
|
96
|
+
else
|
97
|
+
signedHex = "Transaction has not been signed properly."
|
98
|
+
end
|
99
|
+
return signedHex;
|
100
|
+
end
|
101
|
+
|
102
|
+
# Function to send raw transaction on RecordsKeeper Blockchain
|
103
|
+
def self.sendRawTransaction signed_txHex
|
104
|
+
auth = {:username => @user, :password => @password}
|
105
|
+
options = {
|
106
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
107
|
+
:basic_auth => auth,
|
108
|
+
:body => [ {"method":"sendrawtransaction","params":[signed_txHex],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
109
|
+
}
|
110
|
+
response = HTTParty.get(@url, options)
|
111
|
+
out = response.parsed_response
|
112
|
+
txn = out[0]['result']
|
113
|
+
if txn.nil?
|
114
|
+
txid = out[0]['error']['message']
|
115
|
+
else
|
116
|
+
txid = txn
|
117
|
+
end
|
118
|
+
return txid;
|
119
|
+
end
|
120
|
+
|
121
|
+
# Function to send signed transaction on RecordsKeeper Blockchain
|
122
|
+
def self.sendSignedTransaction sender_address, receiveraddress, data, amount, private_key
|
123
|
+
data_hex = data.to_hex_string
|
124
|
+
datahex = data_hex.delete(' ')
|
125
|
+
def self.createRawTransaction sender_address, receiveraddress, amount, datahex
|
126
|
+
auth = {:username => @user, :password => @password}
|
127
|
+
options = {
|
128
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
129
|
+
:basic_auth => auth,
|
130
|
+
:body => [ {"method":"createrawsendfrom","params":[sender_address, {receiveraddress => amount}, [datahex], ""],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
131
|
+
}
|
132
|
+
response = HTTParty.get(@url, options)
|
133
|
+
out = response.parsed_response
|
134
|
+
return out[0]['result']
|
135
|
+
end
|
136
|
+
txHex = createRawTransaction sender_address, receiveraddress, Float(amount), datahex
|
137
|
+
def self.signRawTransaction txHex, private_key
|
138
|
+
auth = {:username => @user, :password => @password}
|
139
|
+
options = {
|
140
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
141
|
+
:basic_auth => auth,
|
142
|
+
:body => [ {"method":"signrawtransaction","params":[txHex, [], [private_key]],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
143
|
+
}
|
144
|
+
response = HTTParty.get(@url, options)
|
145
|
+
out = response.parsed_response
|
146
|
+
return out[0]['result']['hex']
|
147
|
+
end
|
148
|
+
signed_tx_hex = signRawTransaction txHex, private_key
|
149
|
+
def self.sendRawTransaction signed_tx_hex
|
150
|
+
auth = {:username => @user, :password => @password}
|
151
|
+
options = {
|
152
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
153
|
+
:basic_auth => auth,
|
154
|
+
:body => [ {"method":"sendrawtransaction","params":[signed_tx_hex],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
155
|
+
}
|
156
|
+
response = HTTParty.get(@url, options)
|
157
|
+
out = response.parsed_response
|
158
|
+
return out[0]['result']
|
159
|
+
end
|
160
|
+
tx_id = sendRawTransaction signed_tx_hex
|
161
|
+
return tx_id;
|
162
|
+
end
|
163
|
+
|
164
|
+
# Function to retrieve transaction on RecordsKeeper Blockchain
|
165
|
+
def self.retrieveTransaction tx_id
|
166
|
+
auth = {:username => @user, :password => @password}
|
167
|
+
options = {
|
168
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
169
|
+
:basic_auth => auth,
|
170
|
+
:body => [ {"method":"getrawtransaction","params":[tx_id, 1],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
171
|
+
}
|
172
|
+
response = HTTParty.get(@url, options)
|
173
|
+
out = response.parsed_response
|
174
|
+
check = out[0]['result']
|
175
|
+
|
176
|
+
if check.nil?
|
177
|
+
retrievedinfo = out[0]['error']['message']
|
178
|
+
else
|
179
|
+
sent_hex_data = out[0]['result']['data'][0]
|
180
|
+
sent_data = sent_hex_data.to_byte_string
|
181
|
+
sent_amount = out[0]['result']['vout'][0]['value']
|
182
|
+
retrieve = {:sent_data => sent_data,:sent_amount => sent_amount }
|
183
|
+
retrievedinfo = JSON.generate retrieve
|
184
|
+
end
|
185
|
+
return retrievedinfo
|
186
|
+
end
|
187
|
+
|
188
|
+
# Function to calculate transaction's fee on RecordsKeeper Blockchain
|
189
|
+
def self.getFee address, tx_id
|
190
|
+
auth = {:username => @user, :password => @password}
|
191
|
+
options = {
|
192
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
193
|
+
:basic_auth => auth,
|
194
|
+
:body => [ {"method":"getaddresstransaction","params":[address, tx_id, true],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
195
|
+
}
|
196
|
+
response = HTTParty.get(@url, options)
|
197
|
+
out = response.parsed_response
|
198
|
+
check = out[0]['result']
|
199
|
+
|
200
|
+
if check.nil?
|
201
|
+
fees = out[0]['error']['message']
|
202
|
+
else
|
203
|
+
sent_amount = out[0]['result']['vout'][0]['amount']
|
204
|
+
balance_amount = out[0]['result']['balance']['amount']
|
205
|
+
fees = balance_amount.abs - sent_amount
|
206
|
+
end
|
207
|
+
return fees; #returns fees
|
208
|
+
end
|
209
|
+
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
@@ -1,247 +1,263 @@
|
|
1
|
-
# Library to work with RecordsKeeper wallet.
|
2
|
-
|
3
|
-
# You can create wallet, create multisignature wallet, retrieve wallet's information, retrieve private key of a particular
|
4
|
-
# wallet address, sign message verify message, dump wallet file, backup wallet file, import wallet file, encrypt wallet by
|
5
|
-
# using wallet class. You just have to pass parameters to invoke the pre-defined functions.
|
6
|
-
|
7
|
-
require 'rubygems'
|
8
|
-
require 'httparty'
|
9
|
-
require 'json'
|
10
|
-
require 'binary_parser'
|
11
|
-
require 'yaml'
|
12
|
-
require 'hex_string'
|
13
|
-
|
14
|
-
module RecordsKeeperRubyLib
|
15
|
-
class Wallet
|
16
|
-
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
1
|
+
# Library to work with RecordsKeeper wallet.
|
2
|
+
|
3
|
+
# You can create wallet, create multisignature wallet, retrieve wallet's information, retrieve private key of a particular
|
4
|
+
# wallet address, sign message verify message, dump wallet file, backup wallet file, import wallet file, encrypt wallet by
|
5
|
+
# using wallet class. You just have to pass parameters to invoke the pre-defined functions.
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'httparty'
|
9
|
+
require 'json'
|
10
|
+
require 'binary_parser'
|
11
|
+
require 'yaml'
|
12
|
+
require 'hex_string'
|
13
|
+
|
14
|
+
module RecordsKeeperRubyLib
|
15
|
+
class Wallet
|
16
|
+
|
17
|
+
# # Entry point for accessing Wallet class functions
|
18
|
+
if File.exist?('config.yaml')
|
19
|
+
# Import values from configuration file.
|
20
|
+
cfg = YAML::load(File.open('config.yaml','r'))
|
21
|
+
|
22
|
+
@url = cfg['url']
|
23
|
+
@user = cfg['rkuser']
|
24
|
+
@password = cfg['passwd']
|
25
|
+
@chain = cfg['chain']
|
26
|
+
|
27
|
+
else
|
28
|
+
#Import using ENV variables
|
29
|
+
|
30
|
+
@url = ENV['url']
|
31
|
+
@user = ENV['rkuser']
|
32
|
+
@password = ENV['passwd']
|
33
|
+
@chain = ENV['chain']
|
34
|
+
end
|
35
|
+
|
36
|
+
# Function to create wallet on RecordsKeeper Blockchain
|
37
|
+
def self.createWallet
|
38
|
+
auth = {:username => @user, :password => @password}
|
39
|
+
options = {
|
40
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
41
|
+
:basic_auth => auth,
|
42
|
+
:body => [ {"method":"createkeypairs","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
43
|
+
}
|
44
|
+
response = HTTParty.get(@url, options)
|
45
|
+
out = response.parsed_response
|
46
|
+
public_address = out[0]['result'][0]['address'] # returns public address of the wallet
|
47
|
+
private_key = out[0]['result'][0]['privkey'] # returns private key of the wallet
|
48
|
+
public_key = out[0]['result'][0]['pubkey'] # returns public key of the wallet
|
49
|
+
|
50
|
+
def self.importAddress public_address
|
51
|
+
auth = {:username => @user, :password => @password}
|
52
|
+
options = {
|
53
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
54
|
+
:basic_auth => auth,
|
55
|
+
:body => [ {"method":"importaddress","params":[public_address, " ", false],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
56
|
+
}
|
57
|
+
response = HTTParty.get(@url, options)
|
58
|
+
out = response.parsed_response
|
59
|
+
result = out[0]['result']
|
60
|
+
return result;
|
61
|
+
end
|
62
|
+
import_address = importAddress public_address
|
63
|
+
retrieve = {:public_address => public_address,:private_key => private_key,:public_key => public_key}
|
64
|
+
retrievedinfo = JSON.generate retrieve
|
65
|
+
return retrievedinfo
|
66
|
+
end
|
67
|
+
|
68
|
+
# Function to retrieve private key of a wallet address on RecordsKeeper Blockchain
|
69
|
+
def self.getPrivateKey public_address
|
70
|
+
auth = {:username => @user, :password => @password}
|
71
|
+
options = {
|
72
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
73
|
+
:basic_auth => auth,
|
74
|
+
:body => [ {"method":"dumpprivkey","params":[public_address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
75
|
+
}
|
76
|
+
response = HTTParty.get(@url, options)
|
77
|
+
out = response.parsed_response
|
78
|
+
result = out[0]['result']
|
79
|
+
if result.nil?
|
80
|
+
private_key = out[0]['error']['message']
|
81
|
+
else
|
82
|
+
private_key = out[0]['result']
|
83
|
+
end
|
84
|
+
return private_key; #returns private key
|
85
|
+
end
|
86
|
+
|
87
|
+
# Function to retrieve wallet's information on RecordsKeeper Blockchain
|
88
|
+
def self.retrieveWalletinfo
|
89
|
+
auth = {:username => @user, :password => @password}
|
90
|
+
options = {
|
91
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
92
|
+
:basic_auth => auth,
|
93
|
+
:body => [ {"method":"getwalletinfo","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
94
|
+
}
|
95
|
+
response = HTTParty.get(@url, options)
|
96
|
+
out = response.parsed_response
|
97
|
+
balance = out[0]['result']['balance']
|
98
|
+
tx_count = out[0]['result']['txcount']
|
99
|
+
unspent_tx = out[0]['result']['utxocount']
|
100
|
+
retrieve = {:balance => balance,:tx_count => tx_count,:unspent_tx => unspent_tx}
|
101
|
+
retrievedinfo = JSON.generate retrieve
|
102
|
+
return retrievedinfo
|
103
|
+
end
|
104
|
+
|
105
|
+
# Function to create wallet's backup on RecordsKeeper Blockchain
|
106
|
+
def self.backupWallet filename
|
107
|
+
auth = {:username => @user, :password => @password}
|
108
|
+
options = {
|
109
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
110
|
+
:basic_auth => auth,
|
111
|
+
:body => [ {"method":"backupwallet","params":[filename],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
112
|
+
}
|
113
|
+
response = HTTParty.get(@url, options)
|
114
|
+
out = response.parsed_response
|
115
|
+
result = out[0]['result']
|
116
|
+
if result.nil?
|
117
|
+
res = "Backup successful!"
|
118
|
+
else
|
119
|
+
res = out[0]['error']['message']
|
120
|
+
end
|
121
|
+
return res; #returns result
|
122
|
+
end
|
123
|
+
|
124
|
+
# Function to import wallet's backup on RecordsKeeper Blockchain
|
125
|
+
def self.importWallet filename
|
126
|
+
auth = {:username => @user, :password => @password}
|
127
|
+
options = {
|
128
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
129
|
+
:basic_auth => auth,
|
130
|
+
:body => [ {"method":"importwallet","params":[filename],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
131
|
+
}
|
132
|
+
response = HTTParty.get(@url, options)
|
133
|
+
out = response.parsed_response
|
134
|
+
result = out[0]['result']
|
135
|
+
if result.nil?
|
136
|
+
res = "Wallet is successfully imported"
|
137
|
+
else
|
138
|
+
res = out[0]['error']['message']
|
139
|
+
end
|
140
|
+
return res; #returns result
|
141
|
+
end
|
142
|
+
|
143
|
+
# Function to dump wallet on RecordsKeeper Blockchain
|
144
|
+
def self.dumpWallet filename
|
145
|
+
auth = {:username => @user, :password => @password}
|
146
|
+
options = {
|
147
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
148
|
+
:basic_auth => auth,
|
149
|
+
:body => [ {"method":"dumpwallet","params":[filename],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
150
|
+
}
|
151
|
+
response = HTTParty.get(@url, options)
|
152
|
+
out = response.parsed_response
|
153
|
+
result = out[0]['result']
|
154
|
+
if result.nil?
|
155
|
+
res = "Wallet is successfully dumped"
|
156
|
+
else
|
157
|
+
res = out[0]['error']['message']
|
158
|
+
end
|
159
|
+
return res; #returns result
|
160
|
+
end
|
161
|
+
|
162
|
+
# Function to lock wallet on RecordsKeeper Blockchain
|
163
|
+
def self.lockWallet password
|
164
|
+
auth = {:username => @user, :password => @password}
|
165
|
+
options = {
|
166
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
167
|
+
:basic_auth => auth,
|
168
|
+
:body => [ {"method":"encryptwallet","params":[password],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
169
|
+
}
|
170
|
+
response = HTTParty.get(@url, options)
|
171
|
+
out = response.parsed_response
|
172
|
+
result = out[0]['result']
|
173
|
+
if result.nil?
|
174
|
+
res = "Wallet is successfully encrypted."
|
175
|
+
else
|
176
|
+
res = out[0]['error']['message']
|
177
|
+
end
|
178
|
+
return res; #returns result
|
179
|
+
end
|
180
|
+
|
181
|
+
# Function to unlock wallet on RecordsKeeper Blockchain
|
182
|
+
def self.unlockWallet password, unlocktime
|
183
|
+
auth = {:username => @user, :password => @password}
|
184
|
+
options = {
|
185
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
186
|
+
:basic_auth => auth,
|
187
|
+
:body => [ {"method":"walletpassphrase","params":[password, unlocktime],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
188
|
+
}
|
189
|
+
response = HTTParty.get(@url, options)
|
190
|
+
out = response.parsed_response
|
191
|
+
result = out[0]['result']
|
192
|
+
if result.nil?
|
193
|
+
res = "Wallet is successfully unlocked."
|
194
|
+
else
|
195
|
+
res = out[0]['error']['message']
|
196
|
+
end
|
197
|
+
return res; #returns result
|
198
|
+
end
|
199
|
+
|
200
|
+
# Function to change password for wallet on RecordsKeeper Blockchain
|
201
|
+
def self.changeWalletPassword old_password, new_password
|
202
|
+
auth = {:username => @user, :password => @password}
|
203
|
+
options = {
|
204
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
205
|
+
:basic_auth => auth,
|
206
|
+
:body => [ {"method":"walletpassphrasechange","params":[old_password, new_password],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
207
|
+
}
|
208
|
+
response = HTTParty.get(@url, options)
|
209
|
+
out = response.parsed_response
|
210
|
+
result = out[0]['result']
|
211
|
+
if result.nil?
|
212
|
+
res = "Password successfully changed!"
|
213
|
+
else
|
214
|
+
res = out[0]['error']['message']
|
215
|
+
end
|
216
|
+
return res; #returns result
|
217
|
+
end
|
218
|
+
|
219
|
+
# Function to sign message on RecordsKeeper Blockchain
|
220
|
+
def self.signMessage private_key, message
|
221
|
+
auth = {:username => @user, :password => @password}
|
222
|
+
options = {
|
223
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
224
|
+
:basic_auth => auth,
|
225
|
+
:body => [ {"method":"signmessage","params":[private_key, message],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
226
|
+
}
|
227
|
+
response = HTTParty.get(@url, options)
|
228
|
+
out = response.parsed_response
|
229
|
+
check = out[0]['result']
|
230
|
+
|
231
|
+
if check.nil?
|
232
|
+
signedMessage = out[0]['error']['message']
|
233
|
+
else
|
234
|
+
signedMessage = out[0]['result']
|
235
|
+
end
|
236
|
+
return signedMessage; #returns private key
|
237
|
+
end
|
238
|
+
|
239
|
+
# Function to verify message on RecordsKeeper Blockchain
|
240
|
+
def self.verifyMessage address, signedMessage, message
|
241
|
+
auth = {:username => @user, :password => @password}
|
242
|
+
options = {
|
243
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
244
|
+
:basic_auth => auth,
|
245
|
+
:body => [ {"method":"verifymessage","params":[address, signedMessage, message],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
246
|
+
}
|
247
|
+
response = HTTParty.get(@url, options)
|
248
|
+
out = response.parsed_response
|
249
|
+
verifiedMessage = out[0]['result']
|
250
|
+
error = out[0]['error']
|
251
|
+
if verifiedMessage
|
252
|
+
validity = "Yes, message is verified"
|
253
|
+
elsif error.nil?
|
254
|
+
validity = "No, signedMessage is not correct"
|
255
|
+
else
|
256
|
+
validity = error['message']
|
257
|
+
end
|
258
|
+
return validity; #returns validity
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|