RecordsKeeperRubyLib 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -1
  3. data/CODE_OF_CONDUCT.md +0 -8
  4. data/Gemfile +0 -1
  5. data/Gemfile.lock +4 -62
  6. data/LICENSE.txt +2 -2
  7. data/README.md +92 -1
  8. data/{RecordsKeeperRuby.gemspec → RecordsKeeperRubyLib.gemspec} +4 -5
  9. data/bin/console +1 -1
  10. data/config.yaml +8 -0
  11. data/docs/{addressdoc.rb → address_doc.rb} +105 -116
  12. data/docs/{assetsdoc.rb → asset_doc.rb} +54 -65
  13. data/docs/block_doc.rb +63 -0
  14. data/docs/blockchain_doc.rb +77 -0
  15. data/docs/{permissionsdoc.rb → permissions_doc.rb} +54 -65
  16. data/docs/{streamdoc.rb → stream_doc.rb} +79 -84
  17. data/docs/{transactiondoc.rb → transaction_doc.rb} +110 -121
  18. data/docs/{walletdoc.rb → wallet_doc.rb} +122 -133
  19. data/lib/RecordsKeeperRubyLib.rb +9 -0
  20. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/address.rb +198 -186
  21. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/assets.rb +99 -87
  22. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/block.rb +94 -89
  23. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/blockchain.rb +148 -135
  24. data/lib/RecordsKeeperRubyLib/config.yaml +8 -0
  25. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/permissions.rb +77 -77
  26. data/lib/RecordsKeeperRubyLib/stream.rb +220 -0
  27. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/transaction.rb +213 -182
  28. data/lib/RecordsKeeperRubyLib/version.rb +3 -0
  29. data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/wallet.rb +263 -252
  30. data/lib/config.yaml +8 -0
  31. metadata +27 -41
  32. data/docs/blockchaindoc.rb +0 -77
  33. data/docs/blockdoc.rb +0 -76
  34. data/lib/RecordsKeeperRuby.rb +0 -9
  35. data/lib/RecordsKeeperRuby/sample_config.yaml +0 -60
  36. data/lib/RecordsKeeperRuby/stream.rb +0 -169
  37. data/lib/RecordsKeeperRuby/version.rb +0 -3
  38. data/lib/sample_config.yaml +0 -60
  39. data/sample_config.yaml +0 -60
data/lib/config.yaml ADDED
@@ -0,0 +1,8 @@
1
+ # config.yaml
2
+
3
+ url: testurl
4
+ rkuser: rkuser
5
+ passwd: rkpwd
6
+ chain: test-chain
7
+ port: testport
8
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: RecordsKeeperRubyLib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusra Qureshi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-20 00:00:00.000000000 Z
11
+ date: 2018-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,21 +122,7 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 3.2.8
125
- - !ruby/object:Gem::Dependency
126
- name: rspec-rails
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: 3.7.2
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: 3.7.2
139
- description: This is a Recordskeeper library in Ruby.
125
+ description: This is ruby library for RecordsKeeper.
140
126
  email:
141
127
  - yusraq10
142
128
  executables: []
@@ -152,30 +138,30 @@ files:
152
138
  - LICENSE.txt
153
139
  - README.md
154
140
  - Rakefile
155
- - RecordsKeeperRuby.gemspec
141
+ - RecordsKeeperRubyLib.gemspec
156
142
  - bin/console
157
143
  - bin/setup
158
- - docs/addressdoc.rb
159
- - docs/assetsdoc.rb
160
- - docs/blockchaindoc.rb
161
- - docs/blockdoc.rb
162
- - docs/permissionsdoc.rb
163
- - docs/streamdoc.rb
164
- - docs/transactiondoc.rb
165
- - docs/walletdoc.rb
166
- - lib/RecordsKeeperRuby.rb
167
- - lib/RecordsKeeperRuby/address.rb
168
- - lib/RecordsKeeperRuby/assets.rb
169
- - lib/RecordsKeeperRuby/block.rb
170
- - lib/RecordsKeeperRuby/blockchain.rb
171
- - lib/RecordsKeeperRuby/permissions.rb
172
- - lib/RecordsKeeperRuby/sample_config.yaml
173
- - lib/RecordsKeeperRuby/stream.rb
174
- - lib/RecordsKeeperRuby/transaction.rb
175
- - lib/RecordsKeeperRuby/version.rb
176
- - lib/RecordsKeeperRuby/wallet.rb
177
- - lib/sample_config.yaml
178
- - sample_config.yaml
144
+ - config.yaml
145
+ - docs/address_doc.rb
146
+ - docs/asset_doc.rb
147
+ - docs/block_doc.rb
148
+ - docs/blockchain_doc.rb
149
+ - docs/permissions_doc.rb
150
+ - docs/stream_doc.rb
151
+ - docs/transaction_doc.rb
152
+ - docs/wallet_doc.rb
153
+ - lib/RecordsKeeperRubyLib.rb
154
+ - lib/RecordsKeeperRubyLib/address.rb
155
+ - lib/RecordsKeeperRubyLib/assets.rb
156
+ - lib/RecordsKeeperRubyLib/block.rb
157
+ - lib/RecordsKeeperRubyLib/blockchain.rb
158
+ - lib/RecordsKeeperRubyLib/config.yaml
159
+ - lib/RecordsKeeperRubyLib/permissions.rb
160
+ - lib/RecordsKeeperRubyLib/stream.rb
161
+ - lib/RecordsKeeperRubyLib/transaction.rb
162
+ - lib/RecordsKeeperRubyLib/version.rb
163
+ - lib/RecordsKeeperRubyLib/wallet.rb
164
+ - lib/config.yaml
179
165
  homepage: https://github.com/RecordsKeeper
180
166
  licenses:
181
167
  - MIT
@@ -196,8 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
182
  version: '0'
197
183
  requirements: []
198
184
  rubyforge_project:
199
- rubygems_version: 2.7.7
185
+ rubygems_version: 2.4.5.2
200
186
  signing_key:
201
187
  specification_version: 4
202
- summary: Recordskeeper-SDK-Ruby
188
+ summary: RecordsKeeper-SDK-Ruby
203
189
  test_files: []
@@ -1,77 +0,0 @@
1
- # = Blockchain Class Usage
2
- # This is a library to work with Blockchain in RecordsKeeper Blockchain.
3
- # You can retrieve information about the chain and node, list all the permissions and the pending transactions and check your node's balance.
4
- # ---------
5
- # == Libraries
6
- # Require these ruby libraries first to get started with the functionality.
7
- # require 'rubygems'
8
- # require 'httparty'
9
- # require 'json'
10
- # require 'binary_parser'
11
- # require 'yaml'
12
- # -----------------
13
- # == Create Connection
14
- # Entry point for accessing Blockchain class resources.
15
- # * URL: Url to connect to the chain ([RPC Host]:[RPC Port])
16
- # * Chain-name: Name of the chain
17
- # cfg = YAML::load(File.open('sample_config.yaml','r')) # Loads the configuration file
18
- # * Set a *network* value to change the network-type
19
- # network = cfg['testnet'] # Network variable to store the network that you want to access
20
- # **NOTE:* Default network is *Test-net* ( i.e., you can set it to either testnet or mainnet).
21
- # Check the network type for url and chain name:
22
- # if @network==cfg['testnet']
23
- # @url = cfg['testnet']['url']
24
- # @chain = cfg['testnet']['chain']
25
- # else
26
- # @url = cfg['mainnet']['url']
27
- # @chain = cfg['mainnet']['chain']
28
- # end
29
- # -------------------
30
- # == Node Authentication
31
- # Import values from config file.
32
- # * User name: The rpc user is used to call the APIs.
33
- # * Password: The rpc password is used to authenticate the APIs.
34
- # * Check the network type for username and password:
35
- # if @network==cfg['testnet']
36
- # @user = cfg['testnet']['rkuser']
37
- # @password = cfg['testnet']['passwd']
38
- # else
39
- # @user = cfg['mainnet']['rkuser']
40
- # @password = cfg['mainnet']['passwd']
41
- # end
42
- # Now we have node authentication credentials.
43
- # ------------
44
- # = class Blockchain
45
- # Blockchain class is used to call blockchain related functions to retrieve information about the chain and node, list all the permissions and the pending transactions and check your node's balance.
46
- # === 1. getChainInfo
47
- # This function retrieves information about the chain.
48
- # getChainInfo
49
- # chainInfo = getChainInfo # Function call
50
- #
51
- # puts chainInfo # Prints chain_protocol, chain_description, root_stream, max_blocksize, default_networkport, default_rpcport, mining_diversity and chain_name.
52
- # === 2. getNodeInfo
53
- # This function retrieves information related to your node.
54
- # getNodeInfo
55
- # nodeInfo = getNodeInfo # Function call
56
- #
57
- # puts nodeInfo # Prints node_balance, synced_blocks, node_address and difficulty.
58
- # === 3. permissions
59
- # This function lists all the permissions.
60
- # permissions
61
- # listpermissions = permissions # Function call
62
- #
63
- # puts listpermissions # Prints the list of permissions.
64
- # === 4. getpendingTransactions
65
- # This function retrieves information related to your node.
66
- # getpendingTransactions
67
- # pentransac = getpendingTransactions # Function call
68
- #
69
- # puts pentransac # Prints transaction_count and the transactions.
70
- # === 5. checkNodeBalance
71
- # This function retrieves information related to your node.
72
- # checkNodeBalance
73
- # nodeBal = checkNodeBalance # Function call
74
- #
75
- # puts nodeBal # Prints node's balance amount.
76
- class Blockchain
77
- end
data/docs/blockdoc.rb DELETED
@@ -1,76 +0,0 @@
1
- # = Block Class Usage
2
- # This is a library to work with RecordsKeeper block information.
3
- # You can generate new address, check all addresses, check address validity, check address permissions, check address balance by using Address class. You just have to pass parameters to invoke the pre-defined functions.
4
- # ---------
5
- # == Libraries
6
- # Require these ruby libraries first to get started with the functionality.
7
- # require 'rubygems'
8
- # require 'httparty'
9
- # require 'json'
10
- # require 'binary_parser'
11
- # require 'yaml'
12
- # -----------------
13
- # == Create Connection
14
- # Entry point for accessing Address class resources.
15
- # * URL: Url to connect to the chain ([RPC Host]:[RPC Port])
16
- # * Chain-name: chain name
17
- # cfg = YAML::load(File.open('sample_config.yaml','r')) # Loads the configuration file
18
- # * Set a *network* value to change the network-type
19
- # network = cfg['testnet'] # Network variable to store the network that you want to access
20
- # **NOTE:* Default network is *Test-net*, you can change it to mainnet or testnet
21
- # Check the network type for url and chain name:
22
- # if @network==cfg['testnet']
23
- # @url = cfg['testnet']['url']
24
- # @chain = cfg['testnet']['chain']
25
- # else
26
- # @url = cfg['mainnet']['url']
27
- # @chain = cfg['mainnet']['chain']
28
- # end
29
- # -------------------
30
- # == Node Authentication
31
- # Import values from config file.
32
- # * User name: The rpc user is used to call the APIs.
33
- # * Password: The rpc password is used to authenticate the APIs.
34
- # * Check the network type for username and password:
35
- # if @network==cfg['testnet']
36
- # @user = cfg['testnet']['rkuser']
37
- # @password = cfg['testnet']['passwd']
38
- # else
39
- # @user = cfg['mainnet']['rkuser']
40
- # @password = cfg['mainnet']['passwd']
41
- # end
42
- # Now we have node authentication credentials.
43
- # ------------
44
- # = class Block
45
- # Block class is used to call block related functions like blockinfo which is used to retrieve block details
46
- # like block's hash value, size, nonce, transaction ids, transaction count, miner address, previous block hash,
47
- # next block hash, merkleroot, blocktime and difficulty of the block for which you have made the query.
48
- # === 1. blockinfo block_height
49
- # * You have to pass the block height as an argument in the blockinfo function call (Block height: Height of the block of which you want to collect information.)
50
- # * It will return transaction ids, transaction count, nonce, size, hash value, previous block's hash value, next block hash value, merkle root, difficulty, blocktime and miner address of the block.
51
- # blockinfo block_height # Function call
52
- # tx_count, tx, miner, size, nonce, blockHash, prevblock, nextblock, merkleroot, blocktime, difficulty = blockinfo block_height
53
- #
54
- # puts tx_count # prints transaction count of the block
55
- # puts tx # prints transaction ids of the block
56
- # puts size # prints size of the block
57
- # puts blockHash # prints hash value of the block
58
- # puts nonce # prints nonce of the block
59
- # puts miner # prints miner's address of the block
60
- # puts nextblock # prints next block's hash
61
- # puts prevblock # prints previous block's hash
62
- # puts merkleroot # prints merkle root of the block
63
- # puts blocktime # prints time at which block is mined
64
- # puts difficulty # prints difficulty of the block
65
- # === 2. retrieveBlocks block_range
66
- # * You have to pass the block's height as the argument to the retrieveBlocks function call (Block range: Range of the block of which you want to collect information)
67
- # * It will return blockhash, miner address, blocktime and transaction count of the blocks.
68
- # retrieveBlocks block_range # Function call
69
- # block_hash, miner_add, block_time, txcount = retrieveBlocks block_range
70
- #
71
- # puts block_hash # prints hash of the blocks
72
- # puts miner_add # prints miner of the blocks
73
- # puts block_time # prints block time of the blocks
74
- # puts txcount # prints transaction count of the blocks
75
- class Block
76
- end
@@ -1,9 +0,0 @@
1
- require "RecordsKeeperRuby/version"
2
- require_relative ('RecordsKeeperRuby/address')
3
- require_relative ('RecordsKeeperRuby/assets')
4
- require_relative ('RecordsKeeperRuby/block')
5
- require_relative ('RecordsKeeperRuby/blockchain')
6
- require_relative ('RecordsKeeperRuby/permissions')
7
- require_relative ('RecordsKeeperRuby/stream')
8
- require_relative ('RecordsKeeperRuby/transaction')
9
- require_relative ('RecordsKeeperRuby/wallet')
@@ -1,60 +0,0 @@
1
- # config.yaml
2
- testnet:
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
30
-
31
-
32
-
33
- mainnet:
34
- url: mainurl
35
- rkuser: rkuser
36
- passwd: rkpwd
37
- chain: main-chain
38
- port: mainport
39
- stream: streamname
40
- testdata: main_data
41
- amount: main_amount
42
- dumptxid: main_txid
43
- privatekey: main_privkey
44
- validaddress: valid_address
45
- invalidaddress: invalid_address
46
- miningaddress: mining_address
47
- nonminingaddress: nonmining_address
48
- multisigaddress: multisig_address
49
- wrongimportaddress: wrongimport_address
50
- mainaddress: main_address
51
- permissionaddress: permission_address
52
- dumptxhex: dump_txhex
53
- dumpsignedtxhex: dump_signedtxhex
54
- samplegetmultisigaddress: sample_multisigaddress
55
- samplemerkleroot: sample_merkleroot
56
- sampleblockhash: sample_blockhash
57
- sampledata: sample_data
58
- sampletransac: sample_transaction_id
59
- transactionid: transaction_id
60
- sampletxid: sample_txid
@@ -1,169 +0,0 @@
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 RecordsKeeperRuby
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['testnet'] # Network variable to store the networrk that you want to access
21
- if @network==cfg['testnet']
22
- @url = cfg['testnet']['url']
23
- @user = cfg['testnet']['rkuser']
24
- @password = cfg['testnet']['passwd']
25
- @chain = cfg['testnet']['chain']
26
- else
27
- @url = cfg['mainnet']['url']
28
- @user = cfg['mainnet']['rkuser']
29
- @password = cfg['mainnet']['passwd']
30
- @chain = cfg['mainnet']['chain']
31
- end
32
-
33
- def self.variable
34
- net = @network
35
- return net
36
- end
37
-
38
- # Function to publish data into the stream
39
- def self.publish address, stream, key, data
40
- datahex1 = data.to_hex_string
41
- datahex = datahex1.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":"publishfrom","params":[address, stream, key, datahex],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
47
- }
48
- response = HTTParty.get(@url, options)
49
- out = response.parsed_response
50
- txid = out[0]['result']
51
- return txid;
52
- end
53
-
54
- # Function to retrieve data against transaction id from the stream
55
- def self.retrieve stream, txid
56
- auth = {:username => @user, :password => @password}
57
- options = {
58
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
59
- :basic_auth => auth,
60
- :body => [ {"method":"getstreamitem","params":[stream, txid],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
61
- }
62
- response = HTTParty.get(@url, options)
63
- out = response.parsed_response
64
- data = out[0]['result']['data']
65
- raw_data = data.to_byte_string
66
- return raw_data;
67
- end
68
-
69
- # Function to retrieve data against a particular publisher address
70
- def self.retrieveWithAddress stream, address, count
71
- auth = {:username => @user, :password => @password}
72
- options = {
73
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
74
- :basic_auth => auth,
75
- :body => [ {"method":"liststreampublisheritems","params":[stream, address, false, count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
76
- }
77
- response = HTTParty.get(@url, options)
78
- out = response.parsed_response
79
- key = []
80
- raw_data = []
81
- txid = []
82
- i = 0
83
- begin
84
- key.push(out[0]['result'][i]['key']) #returns key value of the published data
85
- data = out[0]['result'][i]['data'] #returns hex data
86
- raw_data.push(data.to_byte_string) #returns raw data
87
- txid.push(out[0]['result'][i]['txid']) #returns tx id
88
- end until i <count
89
- return key, raw_data, txid;
90
- end
91
-
92
- # Function to retrieve data against a particular key value
93
- def self.retrieveWithKey stream, key, count
94
- auth = {:username => @user, :password => @password}
95
- options = {
96
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
97
- :basic_auth => auth,
98
- :body => [ {"method":"liststreamkeyitems","params":[stream, key, false, count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
99
- }
100
- response = HTTParty.get(@url, options)
101
- out = response.parsed_response
102
- publisher = []
103
- raw_data = []
104
- txid = []
105
- i = 0
106
- begin
107
- publisher.push(out[0]['result'][i]['publishers'][0]) #returns publisher's address of published data
108
- data = out[0]['result'][i]['data'] #returns published hex data
109
- raw_data.push(data.to_byte_string) #returns data published
110
- txid.push(out[0]['result'][i]['txid']) #returns transaction id of published data
111
- end until i <count
112
- return publisher, raw_data, txid;
113
- end
114
-
115
- # Function to verify data on RecordsKeeper Blockchain
116
- def self.verifyData stream, data, count
117
- auth = {:username => @user, :password => @password}
118
- options = {
119
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
120
- :basic_auth => auth,
121
- :body => [ {"method":"liststreamitems","params":[stream,false ,count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
122
- }
123
- response = HTTParty.get(@url, options)
124
- out = response.parsed_response
125
- raw_data = []
126
- i = 0
127
- begin
128
- result_data = out[0]['result'][i]['data'] # returns hex data
129
- end until i <count
130
- if result_data.unicode_normalized?
131
- raw_data.push(result_data.to_byte_string) # returns raw data
132
- else
133
- raw_data.push("No data found")
134
- end
135
- if raw_data.include?data
136
- result = "Data is successfully verified."
137
- else
138
- result = "Data not found."
139
- end
140
- return result;
141
- end
142
-
143
- # Function to list stream items on RecordsKeeper Blockchain
144
- def self.retrieveItems stream, count
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":"liststreamitems","params":[stream, false ,count],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
150
- }
151
- response = HTTParty.get(@url, options)
152
- out = response.parsed_response
153
- address =[]
154
- key_value = []
155
- raw_data = []
156
- txid = []
157
- i = 0
158
- begin
159
- address.push(out[0]['result'][i]['publishers']) # returns publisher address
160
- key_value.push(out[0]['result'][i]['key']) # returns key value of data
161
- data = out[0]['result'][i]['data'] # returns hex data
162
- raw_data.push(data.to_byte_string) # returns raw data
163
- txid.push(out[0]['result'][i]['txid']) # returns tx id
164
- end until i <count
165
- return address, key_value, raw_data, txid;
166
- end
167
- end
168
-
169
- end