RecordsKeeperRubyLib 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +2 -1
- data/CODE_OF_CONDUCT.md +0 -8
- data/Gemfile +0 -1
- data/Gemfile.lock +4 -62
- data/LICENSE.txt +2 -2
- data/README.md +92 -1
- data/{RecordsKeeperRuby.gemspec → RecordsKeeperRubyLib.gemspec} +4 -5
- data/bin/console +1 -1
- data/config.yaml +8 -0
- data/docs/{addressdoc.rb → address_doc.rb} +105 -116
- data/docs/{assetsdoc.rb → asset_doc.rb} +54 -65
- data/docs/block_doc.rb +63 -0
- data/docs/blockchain_doc.rb +77 -0
- data/docs/{permissionsdoc.rb → permissions_doc.rb} +54 -65
- data/docs/{streamdoc.rb → stream_doc.rb} +79 -84
- data/docs/{transactiondoc.rb → transaction_doc.rb} +110 -121
- data/docs/{walletdoc.rb → wallet_doc.rb} +122 -133
- data/lib/RecordsKeeperRubyLib.rb +9 -0
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/address.rb +198 -186
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/assets.rb +99 -87
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/block.rb +94 -89
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/blockchain.rb +148 -135
- data/lib/RecordsKeeperRubyLib/config.yaml +8 -0
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/permissions.rb +77 -77
- data/lib/RecordsKeeperRubyLib/stream.rb +220 -0
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/transaction.rb +213 -182
- data/lib/RecordsKeeperRubyLib/version.rb +3 -0
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/wallet.rb +263 -252
- data/lib/config.yaml +8 -0
- metadata +27 -41
- data/docs/blockchaindoc.rb +0 -77
- data/docs/blockdoc.rb +0 -76
- data/lib/RecordsKeeperRuby.rb +0 -9
- data/lib/RecordsKeeperRuby/sample_config.yaml +0 -60
- data/lib/RecordsKeeperRuby/stream.rb +0 -169
- data/lib/RecordsKeeperRuby/version.rb +0 -3
- data/lib/sample_config.yaml +0 -60
- data/sample_config.yaml +0 -60
@@ -1,77 +1,77 @@
|
|
1
|
-
# Library to work with RecordsKeeper Blockchain permissions.
|
2
|
-
|
3
|
-
# You can grant and revoke permissions to any node on Recordskeeper Blockchain by using permissions class.
|
4
|
-
# You just have to pass parameters to invoke the pre-defined functions.
|
5
|
-
|
6
|
-
require 'rubygems'
|
7
|
-
require 'httparty'
|
8
|
-
require 'json'
|
9
|
-
require 'binary_parser'
|
10
|
-
require 'yaml'
|
11
|
-
require 'hex_string'
|
12
|
-
|
13
|
-
module
|
14
|
-
|
15
|
-
class Permissions
|
16
|
-
|
17
|
-
# Entry point for accessing
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@url = cfg['
|
23
|
-
@user = cfg['
|
24
|
-
@password = cfg['
|
25
|
-
@chain = cfg['
|
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
|
-
end
|
76
|
-
|
77
|
-
end
|
1
|
+
# Library to work with RecordsKeeper Blockchain permissions.
|
2
|
+
|
3
|
+
# You can grant and revoke permissions to any node on Recordskeeper Blockchain by using permissions class.
|
4
|
+
# You just have to pass parameters to invoke the pre-defined functions.
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'httparty'
|
8
|
+
require 'json'
|
9
|
+
require 'binary_parser'
|
10
|
+
require 'yaml'
|
11
|
+
require 'hex_string'
|
12
|
+
|
13
|
+
module RecordsKeeperRubyLib
|
14
|
+
|
15
|
+
class Permissions
|
16
|
+
|
17
|
+
# # Entry point for accessing Permissions 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
|
+
|
37
|
+
# Function to grant permissions on RecordsKeeper Blockchain
|
38
|
+
def self.grantPermission address, permissions
|
39
|
+
auth = {:username => @user, :password => @password}
|
40
|
+
options = {
|
41
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
42
|
+
:basic_auth => auth,
|
43
|
+
:body => [ {"method":"grant","params":[address, permissions],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
44
|
+
}
|
45
|
+
response = HTTParty.get(@url, options)
|
46
|
+
out = response.parsed_response
|
47
|
+
result = out[0]['result']
|
48
|
+
if result.nil?
|
49
|
+
res = out[0]['error']['message']
|
50
|
+
else
|
51
|
+
res = out[0]['result']
|
52
|
+
end
|
53
|
+
return res; #returns permissions tx id
|
54
|
+
end
|
55
|
+
|
56
|
+
# Function to revoke permissions on RecordsKeeper Blockchain
|
57
|
+
def self.revokePermission address, permissions
|
58
|
+
auth = {:username => @user, :password => @password}
|
59
|
+
options = {
|
60
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
61
|
+
:basic_auth => auth,
|
62
|
+
:body => [ {"method":"revoke","params":[address, permissions],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
63
|
+
}
|
64
|
+
response = HTTParty.get(@url, options)
|
65
|
+
out = response.parsed_response
|
66
|
+
result = out[0]['result']
|
67
|
+
if result.nil?
|
68
|
+
res = out[0]['error']['message']
|
69
|
+
else
|
70
|
+
res = out[0]['result']
|
71
|
+
end
|
72
|
+
return res; #returns revoke permissions tx id
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
# Library to work with RecordsKeeper streams.
|
2
|
+
|
3
|
+
# You can publish, retrieve and verify stream data by using stream class.
|
4
|
+
# You just have to pass parameters to invoke the pre-defined functions.
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'httparty'
|
8
|
+
require 'json'
|
9
|
+
require 'binary_parser'
|
10
|
+
require 'yaml'
|
11
|
+
require 'hex_string'
|
12
|
+
|
13
|
+
module RecordsKeeperRubyLib
|
14
|
+
|
15
|
+
class Stream
|
16
|
+
|
17
|
+
# # Entry point for accessing Stream 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 publish data into the stream
|
37
|
+
def self.publish address, stream, key, data
|
38
|
+
datahex1 = data.to_hex_string
|
39
|
+
datahex = datahex1.delete(' ')
|
40
|
+
auth = {:username => @user, :password => @password}
|
41
|
+
options = {
|
42
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
43
|
+
:basic_auth => auth,
|
44
|
+
:body => [ {"method":"publishfrom","params":[address, stream, key, datahex],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
45
|
+
}
|
46
|
+
response = HTTParty.get(@url, options)
|
47
|
+
out = response.parsed_response
|
48
|
+
|
49
|
+
txid = out[0]['result']
|
50
|
+
|
51
|
+
if txid.nil?
|
52
|
+
txid = out[0]['error']['message']
|
53
|
+
end
|
54
|
+
|
55
|
+
return txid;
|
56
|
+
end
|
57
|
+
|
58
|
+
# Function to retrieve data against transaction id from the stream
|
59
|
+
def self.retrieve stream, txid
|
60
|
+
auth = {:username => @user, :password => @password}
|
61
|
+
options = {
|
62
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
63
|
+
:basic_auth => auth,
|
64
|
+
:body => [ {"method":"getstreamitem","params":[stream, txid],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
65
|
+
}
|
66
|
+
response = HTTParty.get(@url, options)
|
67
|
+
out = response.parsed_response
|
68
|
+
check = out[0]['result']
|
69
|
+
|
70
|
+
if check.nil?
|
71
|
+
raw_data = out[0]['error']['message']
|
72
|
+
else
|
73
|
+
data = out[0]['result']['data']
|
74
|
+
raw_data = data.to_byte_string
|
75
|
+
end
|
76
|
+
return raw_data;
|
77
|
+
end
|
78
|
+
|
79
|
+
# Function to retrieve data against a particular publisher address
|
80
|
+
def self.retrieveWithAddress stream, address, count
|
81
|
+
check = []
|
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":"liststreampublisheritems","params":[stream, address, false, count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
87
|
+
}
|
88
|
+
response = HTTParty.get(@url, options)
|
89
|
+
out = response.parsed_response
|
90
|
+
|
91
|
+
|
92
|
+
check = out[0]['result']
|
93
|
+
|
94
|
+
|
95
|
+
if check.empty?
|
96
|
+
retrievedinfo = "No published data found for this address"
|
97
|
+
|
98
|
+
else
|
99
|
+
key = []
|
100
|
+
raw_data = []
|
101
|
+
txid = []
|
102
|
+
for i in 0...check.length
|
103
|
+
key.push(out[0]['result'][i]['key']) #returns key value of the published data
|
104
|
+
data = out[0]['result'][i]['data'] #returns hex data
|
105
|
+
raw_data.push(data.to_byte_string) #returns raw data
|
106
|
+
txid.push(out[0]['result'][i]['txid']) #returns tx id
|
107
|
+
end
|
108
|
+
retrieve = {:key => key,:raw_data => raw_data,:txid => txid}
|
109
|
+
retrievedinfo = JSON.generate retrieve
|
110
|
+
end
|
111
|
+
return retrievedinfo
|
112
|
+
end
|
113
|
+
|
114
|
+
# Function to retrieve data against a particular key value
|
115
|
+
def self.retrieveWithKey stream, key, count
|
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":"liststreamkeyitems","params":[stream, key, false, count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
121
|
+
}
|
122
|
+
response = HTTParty.get(@url, options)
|
123
|
+
out = response.parsed_response
|
124
|
+
|
125
|
+
check = out[0]['result']
|
126
|
+
|
127
|
+
if check.nil?
|
128
|
+
retrievedinfo = out[0]['error']['message']
|
129
|
+
|
130
|
+
else
|
131
|
+
|
132
|
+
publisher = []
|
133
|
+
raw_data = []
|
134
|
+
txid = []
|
135
|
+
|
136
|
+
for i in 0...check.length
|
137
|
+
publisher.push(out[0]['result'][i]['publishers'][0]) #returns publisher's address of published data
|
138
|
+
data = out[0]['result'][i]['data'] #returns published hex data
|
139
|
+
raw_data.push(data.to_byte_string) #returns data published
|
140
|
+
txid.push(out[0]['result'][i]['txid']) #returns transaction id of published data
|
141
|
+
end
|
142
|
+
retrieve = {:publisher => publisher,:raw_data => raw_data,:txid => txid}
|
143
|
+
retrievedinfo = JSON.generate retrieve
|
144
|
+
return retrievedinfo
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# Function to verify data on RecordsKeeper Blockchain
|
149
|
+
def self.verifyData stream, data, count
|
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":"liststreamitems","params":[stream,false ,count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
155
|
+
}
|
156
|
+
response = HTTParty.get(@url, options)
|
157
|
+
out = response.parsed_response
|
158
|
+
|
159
|
+
check = out[0]['result']
|
160
|
+
|
161
|
+
if check.nil?
|
162
|
+
result = out[0]['error']['message']
|
163
|
+
else
|
164
|
+
raw_data = []
|
165
|
+
for i in 0...check.length
|
166
|
+
result_data = out[0]['result'][i]['data'] # returns hex data
|
167
|
+
|
168
|
+
if result_data.unicode_normalized?
|
169
|
+
raw_data.push(result_data.to_byte_string) # returns raw data
|
170
|
+
|
171
|
+
else
|
172
|
+
raw_data.push("No data found")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
if raw_data.include?data
|
177
|
+
result = "Data is successfully verified."
|
178
|
+
else
|
179
|
+
result = "Data not found."
|
180
|
+
end
|
181
|
+
end
|
182
|
+
return result;
|
183
|
+
end
|
184
|
+
|
185
|
+
# Function to list stream items on RecordsKeeper Blockchain
|
186
|
+
def self.retrieveItems stream, count
|
187
|
+
auth = {:username => @user, :password => @password}
|
188
|
+
options = {
|
189
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
190
|
+
:basic_auth => auth,
|
191
|
+
:body => [ {"method":"liststreamitems","params":[stream, false ,count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
192
|
+
}
|
193
|
+
response = HTTParty.get(@url, options)
|
194
|
+
out = response.parsed_response
|
195
|
+
|
196
|
+
check = out[0]['result']
|
197
|
+
|
198
|
+
if check.nil?
|
199
|
+
retrieveditems = out[0]['error']['message']
|
200
|
+
else
|
201
|
+
address =[]
|
202
|
+
key_value = []
|
203
|
+
raw_data = []
|
204
|
+
txid = []
|
205
|
+
|
206
|
+
for i in 0...check.length
|
207
|
+
address.push(out[0]['result'][i]['publishers']) # returns publisher address
|
208
|
+
key_value.push(out[0]['result'][i]['key']) # returns key value of data
|
209
|
+
data = out[0]['result'][i]['data'] # returns hex data
|
210
|
+
raw_data.push(data.to_byte_string) # returns raw data
|
211
|
+
txid.push(out[0]['result'][i]['txid']) # returns tx id
|
212
|
+
end
|
213
|
+
retrieve = {:address => address,:key_value => key_value,:raw_data => raw_data,:txid => txid}
|
214
|
+
retrieveditems = JSON.generate retrieve
|
215
|
+
end
|
216
|
+
return retrieveditems
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
@@ -1,182 +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
|
15
|
-
|
16
|
-
class Transaction
|
17
|
-
|
18
|
-
# Entry point for accessing
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@url = cfg['
|
24
|
-
@user = cfg['
|
25
|
-
@password = cfg['
|
26
|
-
@chain = cfg['
|
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
|
-
|
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
|