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