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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d324ac6751d6dca6221d87cc8ba6def45563226e
4
- data.tar.gz: 9b6277d16371801e4f1be36795b47085d782fdaf
2
+ SHA256:
3
+ metadata.gz: 111feaaa57157ea2426943932aeb13e49488838f9854f041b487482462f73470
4
+ data.tar.gz: 566e3a1fda8d5566c502e881b328e77e0e068ee01090424f85651f44d3ad4d7a
5
5
  SHA512:
6
- metadata.gz: cec03224ca43aec072128a23dce1812a24ea2611ae87c74367f60cca388aa7d80a8bc436b26be0e2e72654aeb9544990e5de32ef260e2d9a019ca1453912186c
7
- data.tar.gz: 3e631c9d26741cb4be3f49e3d0a89f0b2bab081f42827b3bb8ca561017789e18405f56a8886da590ce803ea92eecd248b350369e77fc9d324cb63dbd23666be7
6
+ metadata.gz: bb61b66e17ff9abdedf79d6d0471b01b9c5b07b4f49f8cb15b3c9581d6872b8ee778988cea2f0f080d43ecd20fa935521fb2c62c3616d896931084d2ba24eb6c
7
+ data.tar.gz: 9271bc6cf4291d1664fbaa02f151585121e145589677cb79e7f7787a9f732d919f395f79b34c260dcf6be02ef2d42eb95e413ad79cf8dcfcfa1650b16b8cc485
data/.gitignore CHANGED
@@ -9,4 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
-
12
+ config.yaml
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- RecordsKeeperRubyLib (0.3.0)
4
+ RecordsKeeperRubyLib (0.2.0)
5
5
  binary_parser (~> 1.3.0)
6
6
  hex_string (~> 1.0.1)
7
7
  httparty (~> 0.16.2)
@@ -37,9 +37,7 @@ GEM
37
37
  power_assert
38
38
 
39
39
  PLATFORMS
40
- ruby
41
40
  x64-mingw32
42
- x86_64-linux
43
41
 
44
42
  DEPENDENCIES
45
43
  RecordsKeeperRubyLib!
@@ -53,4 +51,4 @@ DEPENDENCIES
53
51
  test-unit (= 3.2.8)
54
52
 
55
53
  BUNDLED WITH
56
- 1.16.3
54
+ 1.16.2
data/README.md CHANGED
@@ -1,92 +1 @@
1
- RecordsKeeper-Ruby-SDK
2
- =========================
3
-
4
- It is an infrastructure to build RecordsKeeper blockchain-based applications, products and is used to work around applications that are built on top of this blockchain platform.
5
-
6
- **Note:** If you're looking for the RecordsKeeper Ruby Library please see: [RecordsKeeper Ruby Library](https://github.com/RecordsKeeper/recordskeeper-ruby-sdk)
7
-
8
-
9
- ## Getting Started
10
-
11
- Before you begin you need to setup Ruby Development Environment.
12
-
13
-
14
- Import these ruby libraries first to get started with the library classes and functions.
15
-
16
-
17
- ```bash
18
- require 'rubygems'
19
- require 'httparty'
20
- require 'json'
21
- require 'binary_parser'
22
- require 'yaml'
23
- require 'hex_string'
24
- ```
25
-
26
-
27
- Creating Connection
28
- -------------------
29
-
30
- Entry point for accessing Address class resources.
31
-
32
- Make Config file to import config parameters.
33
-
34
- Import chain url and chain name from config file:
35
-
36
- * URL: Url to connect to the chain ([RPC Host]:[RPC Port])
37
- * Chain-name: chain name
38
-
39
- ```bash
40
-
41
- url = network['url']
42
- chain-name = network['chain']
43
-
44
- ```
45
-
46
- Node Authentication
47
- -------------------
48
-
49
- Import user name and password values from config file to authenticate the node:
50
-
51
- * User name: The rpc user is used to call the APIs.
52
- * Password: The rpc password is used to authenticate the APIs.
53
-
54
- ```bash
55
-
56
- user = network['rkuser']
57
- password = network['passwd']
58
-
59
- ```
60
-
61
- ## Libraries
62
-
63
- - [Address](https://github.com/RecordsKeeper/recordskeeper-ruby-sdk/blob/master/lib/RecordsKeeperRubyLib/address.rb) Library to work with RecordsKeeper addresses. 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.
64
-
65
- - [Assets](https://github.com/RecordsKeeper/recordskeeper-ruby-sdk/blob/master/lib/RecordsKeeperRubyLib/assets.rb) Library to work with RecordsKeeper assets. You can create new assets and list all assets by using Assets class. You just have to pass parameters to invoke the pre-defined functions.
66
-
67
- - [Block](https://github.com/RecordsKeeper/recordskeeper-ruby-sdk/blob/master/lib/RecordsKeeperRubyLib/block.rb) Library to work with RecordsKeeper block informaion. You can collect block information by using block class. You just have to pass parameters to invoke the pre-defined functions.
68
-
69
- - [Blockchain](https://github.com/RecordsKeeper/recordskeeper-ruby-sdk/blob/master/lib/RecordsKeeperRubyLib/blockchain.rb) Library to work with RecordsKeeper block informaion. You can collect block information by using block class. You just have to pass parameters to invoke the pre-defined functions.
70
-
71
- - [Permissions](https://github.com/RecordsKeeper/recordskeeper-ruby-sdk/blob/master/lib/RecordsKeeperRubyLib/permissions.rb) Library to work with RecordsKeeper permissions. You can grant and revoke permissions like connect, send, receive, create, issue, mine, activate, admin by using Assets class. You just have to pass parameters to invoke the pre-defined functions.
72
-
73
- - [Stream](https://github.com/RecordsKeeper/recordskeeper-ruby-sdk/blob/master/lib/RecordsKeeperRubyLib/stream.rb) Library to work with RecordsKeeper streams. You can publish, retrieve and verify stream data by using stream class. You just have to pass parameters to invoke the pre-defined functions.
74
-
75
- - [Transaction](https://github.com/RecordsKeeper/recordskeeper-ruby-sdk/blob/master/lib/RecordsKeeperRubyLib/transaction.rb) Library to work with RecordsKeeper transactions. You can send transaction, create raw transaction, sign raw transaction, send raw transaction, send signed transaction, retrieve transaction information and calculate transaction's fees by using transaction class. You just have to pass parameters to invoke the pre-defined functions.
76
-
77
- - [Wallet](https://github.com/RecordsKeeper/recordskeeper-ruby-sdk/blob/master/lib/RecordsKeeperRubyLib/wallet.rb) Library to work with RecordsKeeper wallet functionalities. You can create wallet, dump wallet into a file, backup wallet into a file, import wallet from a file, lock wallet, unlock wallet, change wallet's password, retrieve private key, retrieve wallet's information, sign and verify message by using wallet class. You just have to pass parameters to invoke the pre-defined functions.
78
-
79
-
80
- ## Unit Tests
81
-
82
- Under recordskeeper_ruby_ spec/test using test data from config.yaml file.
83
- - Command to run a all the tests:
84
- [rake spec]
85
- - Command to a specific test file:
86
- [rspec spec/test_name.rb]
87
-
88
-
89
- ## Documentation
90
-
91
- The complete documentation is here: [RecordsKeeper Ruby Library Documentation](https://github.com/RecordsKeeper/recordskeeper-ruby-sdk/tree/master/docs).
92
-
1
+ # RecordsKeeperRubyLib
@@ -1,198 +1,186 @@
1
- # Library to work with RecordsKeeper address class.
2
- # You can generate new address, check all addresses, check address validity, check address permissions, check address balance
3
- # by using Address class. You just have to pass parameters to invoke the pre-defined functions.
4
-
5
- # import rubygems, httparty, json, binary_parser, objspace and yaml
6
- require 'rubygems'
7
- require 'httparty'
8
- require 'json'
9
- require 'binary_parser'
10
- require 'yaml'
11
-
12
- # Address class to access Address related functions
13
- module RecordsKeeperRubyLib
14
- class Address
15
- if File.exist?('config.yaml')
16
- # Import values from configuration file.
17
- cfg = YAML::load(File.open('config.yaml','r'))
18
-
19
- @url = cfg['url']
20
- @user = cfg['rkuser']
21
- @password = cfg['passwd']
22
- @chain = cfg['chain']
23
-
24
- else
25
- #Import using ENV variables
26
-
27
- @url = ENV['url']
28
- @user = ENV['rkuser']
29
- @password = ENV['passwd']
30
- @chain = ENV['chain']
31
- end
32
-
33
-
34
- # Function to generate new address on the node's wallet
35
- def self.getAddress
36
-
37
- auth = {:username => @user, :password => @password}
38
- options = {
39
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
40
- :basic_auth => auth,
41
- :body => [ {"method":"getnewaddress","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
42
- }
43
- response = HTTParty.get(@url, options)
44
- out = response.parsed_response
45
- address = out[0]['result']
46
- return address
47
- end
48
-
49
- # Function to generate a new multisignature address
50
- def self.getMultisigAddress nrequired, key #getMultisigAddress() function definition
51
-
52
- key_list = key.split(",")
53
- auth = {:username => @user, :password => @password}
54
- options = {
55
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
56
- :basic_auth => auth,
57
- :body => [ {"method":"createmultisig","params":[nrequired, key_list],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
58
- }
59
- response = HTTParty.get(@url, options)
60
- out = response.parsed_response
61
- address = out[0]['result']
62
- if address.nil?
63
- res = out[0]['error']['message']
64
- else
65
- res = out[0]['result']['address']
66
- end
67
- return res; #returns new multisig address
68
- end
69
-
70
- # Function to generate a new multisignature address on the node's wallet
71
- def self.getMultisigWalletAddress nrequired, key
72
- key_list = key.split(",")
73
- auth = {:username => @user, :password => @password}
74
- options = {
75
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
76
- :basic_auth => auth,
77
- :body => [ {"method":"addmultisigaddress","params":[nrequired, key_list],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
78
- }
79
- response = HTTParty.get(@url, options)
80
- out = response.parsed_response
81
- address = out[0]['result']
82
- if address.nil?
83
- res = out[0]['error']['message']
84
- else
85
- res = out[0]['result']
86
- end
87
- return res; # Returns new multisig address
88
- end
89
-
90
- # Function to list all addresses and no of addresses on the node's wallet
91
- def self.retrieveAddresses
92
- auth = {:username => @user, :password => @password}
93
- options = {
94
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
95
- :basic_auth => auth,
96
- :body => [ {"method":"getaddresses","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
97
- }
98
- response = HTTParty.get(@url, options)
99
- out = response.parsed_response
100
- address = out[0]['result']
101
- address_count = address.length
102
- address =[]
103
- for i in 0..address_count
104
- address.push(out[0]['result'][i])
105
- end
106
- retrieved = { :address => address,:address_count => address_count}
107
- retrievedinfo = JSON.generate retrieved
108
- return retrievedinfo
109
- end
110
-
111
- # Function to check if given address is valid or not
112
- def self.checkifValid address
113
- auth = {:username => @user, :password => @password}
114
- options = {
115
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
116
- :basic_auth => auth,
117
- :body => [ {"method":"validateaddress","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
118
- }
119
- response = HTTParty.get(@url, options)
120
- out = response.parsed_response
121
- validity = out[0]['result']['isvalid']
122
- if validity
123
- addressCheck = "Address is valid" # Prints that address is valid
124
- else
125
- addressCheck= "Address is invalid" # Prints that address is invalid
126
- end
127
- return addressCheck; # Return the address check status
128
- end
129
-
130
- # Function to check if given address has mining permission or not
131
- def self.checkifMineAllowed address
132
- auth = {:username => @user, :password => @password}
133
- options = {
134
- :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
135
- :basic_auth => auth,
136
- :body => [ {"method":"validateaddress","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
137
- }
138
- response = HTTParty.get(@url, options)
139
- out = response.parsed_response
140
-
141
- check = out[0]['result']['isvalid']
142
-
143
- if check
144
- permission = out[0]['result']['ismine']
145
- if permission
146
- permissionCheck = "Address has mining permission" # Prints that address has mining permission
147
- else
148
- permissionCheck = "Address has not given mining permission" # Prints that address hasn't been given mining permission
149
- end
150
- else
151
- permissionCheck = "Invalid address";
152
- end
153
- return permissionCheck; # Returns the permission status
154
- end
155
-
156
- # Function to check node address balance on RecordsKeeper Blockchain
157
- def self.checkBalance address
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":"getaddressbalances","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
163
- }
164
- response = HTTParty.get(@url, options)
165
- out = response.parsed_response
166
- check = out[0]['result']
167
- if check
168
- balance = out[0]['result'][0]['qty']
169
- else
170
- balance = out[0]['error']['message']
171
- end
172
- return balance; # Returns balance of a particular node address
173
- end
174
-
175
- # Function to import address on RecordsKeeper Blockchain
176
- def self.importAddress public_address
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":"importaddress","params":[public_address, " ", false],"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
- error = out[0]['error']
187
- if result.nil? && error.nil?
188
- resp = "Address successfully imported" # Prints that address has been succesfully imported
189
- elsif result.nil? && error!= nil
190
- resp = out[0]['error']['message']
191
- else
192
- resp = 0
193
- end
194
- return resp;
195
- end
196
-
197
- end
198
- end
1
+ # Library to work with RecordsKeeper address class.
2
+ # You can generate new address, check all addresses, check address validity, check address permissions, check address balance
3
+ # by using Address class. You just have to pass parameters to invoke the pre-defined functions.
4
+
5
+ # import rubygems, httparty, json, binary_parser, objspace and yaml
6
+ require 'rubygems'
7
+ require 'httparty'
8
+ require 'json'
9
+ require 'binary_parser'
10
+ require 'yaml'
11
+
12
+ # Address class to access address related functions
13
+ module RecordsKeeperRubyLib
14
+ class Address
15
+ # Import values from configuration file.
16
+ cfg = YAML::load(File.open('config.yaml','r'))
17
+ @network = cfg['network']
18
+ @url = cfg['network']['url']
19
+ @user = cfg['network']['rkuser']
20
+ @password = cfg['network']['passwd']
21
+ @chain = cfg['network']['chain']
22
+
23
+ def self.variable
24
+ net = @network
25
+ return net
26
+ end
27
+
28
+
29
+ # Function to generate new address on the node's wallet
30
+ def self.getAddress
31
+
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":"getnewaddress","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
37
+ }
38
+ response = HTTParty.get(@url, options)
39
+ out = response.parsed_response
40
+ address = out[0]['result']
41
+ return address
42
+ end
43
+
44
+ # Function to generate a new multisignature address
45
+ def self.getMultisigAddress nrequired, key #getMultisigAddress() function definition
46
+
47
+ key_list = key.split(",")
48
+ auth = {:username => @user, :password => @password}
49
+ options = {
50
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
51
+ :basic_auth => auth,
52
+ :body => [ {"method":"createmultisig","params":[nrequired, key_list],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
53
+ }
54
+ response = HTTParty.get(@url, options)
55
+ out = response.parsed_response
56
+ address = out[0]['result']
57
+ if address.nil?
58
+ res = out[0]['error']['message']
59
+ else
60
+ res = out[0]['result']['address']
61
+ end
62
+ return res; #returns new multisig address
63
+ end
64
+
65
+ # Function to generate a new multisignature address on the node's wallet
66
+ def self.getMultisigWalletAddress nrequired, key
67
+ key_list = key.split(",")
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":"addmultisigaddress","params":[nrequired, key_list],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
73
+ }
74
+ response = HTTParty.get(@url, options)
75
+ out = response.parsed_response
76
+ address = out[0]['result']
77
+ if address.nil?
78
+ res = out[0]['error']['message']
79
+ else
80
+ res = out[0]['result']
81
+ end
82
+ return res; # Returns new multisig address
83
+ end
84
+
85
+ # Function to list all addresses and no of addresses on the node's wallet
86
+ def self.retrieveAddresses
87
+ auth = {:username => @user, :password => @password}
88
+ options = {
89
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
90
+ :basic_auth => auth,
91
+ :body => [ {"method":"getaddresses","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
92
+ }
93
+ response = HTTParty.get(@url, options)
94
+ out = response.parsed_response
95
+ address = out[0]['result']
96
+ address_count = address.length
97
+ address =[]
98
+ for i in 0..address_count
99
+ address.push(out[0]['result'][i])
100
+ end
101
+ retrieved = { :address => address,:address_count => address_count}
102
+ retrievedinfo = JSON.generate retrieved
103
+ return retrievedinfo
104
+ end
105
+
106
+ # Function to check if given address is valid or not
107
+ def self.checkifValid address
108
+ auth = {:username => @user, :password => @password}
109
+ options = {
110
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
111
+ :basic_auth => auth,
112
+ :body => [ {"method":"validateaddress","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
113
+ }
114
+ response = HTTParty.get(@url, options)
115
+ out = response.parsed_response
116
+ validity = out[0]['result']['isvalid']
117
+ if validity
118
+ addressCheck = "Address is valid" # Prints that address is valid
119
+ else
120
+ addressCheck= "Address is invalid" # Prints that address is invalid
121
+ end
122
+ return addressCheck; # Return the address check status
123
+ end
124
+
125
+ # Function to check if given address has mining permission or not
126
+ def self.checkifMineAllowed address
127
+ auth = {:username => @user, :password => @password}
128
+ options = {
129
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
130
+ :basic_auth => auth,
131
+ :body => [ {"method":"validateaddress","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
132
+ }
133
+ response = HTTParty.get(@url, options)
134
+ out = response.parsed_response
135
+ check = out[0]['result']['isvalid']
136
+ if check
137
+ permission = out[0]['result']['ismine']
138
+ if permission
139
+ permissionCheck = "Address has mining permission" # Prints that address has mining permission
140
+ else
141
+ permissionCheck = "Address has not given mining permission" # Prints that address hasn't been given mining permission
142
+ end
143
+ else
144
+ permissionCheck = "Invalid address";
145
+ end
146
+ return permissionCheck; # Returns the permission status
147
+ end
148
+
149
+ # Function to check node address balance on RecordsKeeper Blockchain
150
+ def self.checkBalance address
151
+ auth = {:username => @user, :password => @password}
152
+ options = {
153
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
154
+ :basic_auth => auth,
155
+ :body => [ {"method":"getaddressbalances","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
156
+ }
157
+ response = HTTParty.get(@url, options)
158
+ out = response.parsed_response
159
+ balance = out[0]['result'][0]['qty']
160
+ return balance; # Returns balance of a particular node address
161
+ end
162
+
163
+ # Function to import address on RecordsKeeper Blockchain
164
+ def self.importAddress public_address
165
+ auth = {:username => @user, :password => @password}
166
+ options = {
167
+ :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
168
+ :basic_auth => auth,
169
+ :body => [ {"method":"importaddress","params":[public_address, " ", false],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
170
+ }
171
+ response = HTTParty.get(@url, options)
172
+ out = response.parsed_response
173
+ result = out[0]['result']
174
+ error = out[0]['error']
175
+ if result.nil? && error.nil?
176
+ resp = "Address successfully imported" # Prints that address has been succesfully imported
177
+ elsif result.nil? && error!= nil
178
+ resp = out[0]['error']['message']
179
+ else
180
+ resp = 0
181
+ end
182
+ return resp;
183
+ end
184
+
185
+ end
186
+ end