RecordsKeeperRubyLib 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,77 +1,71 @@
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
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 Block class resources.
18
+ # Import values from config file.
19
+ cfg = YAML::load(File.open('config.yaml','r'))
20
+ @network = cfg['network']
21
+ @url = cfg['network']['url']
22
+ @user = cfg['network']['rkuser']
23
+ @password = cfg['network']['passwd']
24
+ @chain = cfg['network']['chain']
25
+
26
+ def self.variable
27
+ net = @network
28
+ return net
29
+ end
30
+
31
+ # Function to grant permissions on RecordsKeeper Blockchain
32
+ def self.grantPermission address, permissions
33
+ auth = {:username => @user, :password => @password}
34
+ options = {
35
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
36
+ :basic_auth => auth,
37
+ :body => [ {"method":"grant","params":[address, permissions],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
38
+ }
39
+ response = HTTParty.get(@url, options)
40
+ out = response.parsed_response
41
+ result = out[0]['result']
42
+ if result.nil?
43
+ res = out[0]['error']['message']
44
+ else
45
+ res = out[0]['result']
46
+ end
47
+ return res; #returns permissions tx id
48
+ end
49
+
50
+ # Function to revoke permissions on RecordsKeeper Blockchain
51
+ def self.revokePermission address, permissions
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":"revoke","params":[address, permissions],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
57
+ }
58
+ response = HTTParty.get(@url, options)
59
+ out = response.parsed_response
60
+ result = out[0]['result']
61
+ if result.nil?
62
+ res = out[0]['error']['message']
63
+ else
64
+ res = out[0]['result']
65
+ end
66
+ return res; #returns revoke permissions tx id
67
+ end
68
+
69
+ end
70
+
71
+ end
@@ -0,0 +1,29 @@
1
+ # config.yaml
2
+ network:
3
+ url: testurl
4
+ rkuser: rkuser
5
+ passwd: rkpwd
6
+ chain: test-chain
7
+ port: testport
8
+ stream: streamname
9
+ testdata: test_data
10
+ amount: test_amount
11
+ dumptxid: test_txid
12
+ privatekey: test_privkey
13
+ validaddress: valid_address
14
+ invalidaddress: invalid_address
15
+ miningaddress: mining_address
16
+ nonminingaddress: nonmining_address
17
+ multisigaddress: multisig_address
18
+ wrongimportaddress: wrongimport_address
19
+ mainaddress: main_address
20
+ permissionaddress: permission_address
21
+ dumptxhex: dump_txhex
22
+ dumpsignedtxhex: dump_signedtxhex
23
+ samplegetmultisigaddress: sample_multisigaddress
24
+ samplemerkleroot: sample_merkleroot
25
+ sampleblockhash: sample_blockhash
26
+ sampledata: sample_data
27
+ sampletransac: sample_transaction_id
28
+ transactionid: transaction_id
29
+ sampletxid: sample_txid
@@ -1,220 +1,164 @@
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
+ # 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 Block class resources.
18
+ # Import values from config file.
19
+ cfg = YAML::load(File.open('config.yaml','r'))
20
+ @network = cfg['network']
21
+ @url = cfg['network']['url']
22
+ @user = cfg['network']['rkuser']
23
+ @password = cfg['network']['passwd']
24
+ @chain = cfg['network']['chain']
25
+
26
+ def self.variable
27
+ net = @network
28
+ return net
29
+ end
30
+
31
+ # Function to publish data into the stream
32
+ def self.publish address, stream, key, data
33
+ datahex1 = data.to_hex_string
34
+ datahex = datahex1.delete(' ')
35
+ auth = {:username => @user, :password => @password}
36
+ options = {
37
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
38
+ :basic_auth => auth,
39
+ :body => [ {"method":"publishfrom","params":[address, stream, key, datahex],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
40
+ }
41
+ response = HTTParty.get(@url, options)
42
+ out = response.parsed_response
43
+ txid = out[0]['result']
44
+ return txid;
45
+ end
46
+
47
+ # Function to retrieve data against transaction id from the stream
48
+ def self.retrieve stream, txid
49
+ auth = {:username => @user, :password => @password}
50
+ options = {
51
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
52
+ :basic_auth => auth,
53
+ :body => [ {"method":"getstreamitem","params":[stream, txid],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
54
+ }
55
+ response = HTTParty.get(@url, options)
56
+ out = response.parsed_response
57
+ data = out[0]['result']['data']
58
+ raw_data = data.to_byte_string
59
+ return raw_data;
60
+ end
61
+
62
+ # Function to retrieve data against a particular publisher address
63
+ def self.retrieveWithAddress stream, address, count
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":"liststreampublisheritems","params":[stream, address, false, count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
69
+ }
70
+ response = HTTParty.get(@url, options)
71
+ out = response.parsed_response
72
+ key = []
73
+ raw_data = []
74
+ txid = []
75
+ for i in 0...count
76
+ key.push(out[0]['result'][i]['key']) #returns key value of the published data
77
+ data = out[0]['result'][i]['data'] #returns hex data
78
+ raw_data.push(data.to_byte_string) #returns raw data
79
+ txid.push(out[0]['result'][i]['txid']) #returns tx id
80
+ end
81
+ retrieve = {:key => key,:raw_data => raw_data,:txid => txid}
82
+ retrievedinfo = JSON.generate retrieve
83
+ return retrievedinfo
84
+ end
85
+
86
+ # Function to retrieve data against a particular key value
87
+ def self.retrieveWithKey stream, key, count
88
+ auth = {:username => @user, :password => @password}
89
+ options = {
90
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
91
+ :basic_auth => auth,
92
+ :body => [ {"method":"liststreamkeyitems","params":[stream, key, false, count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
93
+ }
94
+ response = HTTParty.get(@url, options)
95
+ out = response.parsed_response
96
+ publisher = []
97
+ raw_data = []
98
+ txid = []
99
+ for i in 0...count
100
+ publisher.push(out[0]['result'][i]['publishers'][0]) #returns publisher's address of published data
101
+ data = out[0]['result'][i]['data'] #returns published hex data
102
+ raw_data.push(data.to_byte_string) #returns data published
103
+ txid.push(out[0]['result'][i]['txid']) #returns transaction id of published data
104
+ end
105
+ retrieve = {:publisher => publisher,:raw_data => raw_data,:txid => txid}
106
+ retrievedinfo = JSON.generate retrieve
107
+ return retrievedinfo
108
+ end
109
+
110
+ # Function to verify data on RecordsKeeper Blockchain
111
+ def self.verifyData stream, data, count
112
+ auth = {:username => @user, :password => @password}
113
+ options = {
114
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
115
+ :basic_auth => auth,
116
+ :body => [ {"method":"liststreamitems","params":[stream,false ,count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
117
+ }
118
+ response = HTTParty.get(@url, options)
119
+ out = response.parsed_response
120
+ raw_data = []
121
+ for i in 0...count
122
+ result_data = out[0]['result'][i]['data'] # returns hex data
123
+ end
124
+ if result_data.unicode_normalized?
125
+ raw_data.push(result_data.to_byte_string) # returns raw data
126
+ else
127
+ raw_data.push("No data found")
128
+ end
129
+ if raw_data.include?data
130
+ result = "Data is successfully verified."
131
+ else
132
+ result = "Data not found."
133
+ end
134
+ return result;
135
+ end
136
+
137
+ # Function to list stream items on RecordsKeeper Blockchain
138
+ def self.retrieveItems stream, count
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":"liststreamitems","params":[stream, false ,count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
144
+ }
145
+ response = HTTParty.get(@url, options)
146
+ out = response.parsed_response
147
+ address =[]
148
+ key_value = []
149
+ raw_data = []
150
+ txid = []
151
+ for i in 0...count
152
+ address.push(out[0]['result'][i]['publishers']) # returns publisher address
153
+ key_value.push(out[0]['result'][i]['key']) # returns key value of data
154
+ data = out[0]['result'][i]['data'] # returns hex data
155
+ raw_data.push(data.to_byte_string) # returns raw data
156
+ txid.push(out[0]['result'][i]['txid']) # returns tx id
157
+ end
158
+ retrieve = {:address => address,:key_value => key_value,:raw_data => raw_data,:txid => txid}
159
+ retrieveditems = JSON.generate retrieve
160
+ return retrieveditems
161
+ end
162
+ end
163
+
164
+ end