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,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
|
-
#
|
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
|
-
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
|
-
#
|
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
|
-
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
|