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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 111feaaa57157ea2426943932aeb13e49488838f9854f041b487482462f73470
|
4
|
+
data.tar.gz: 566e3a1fda8d5566c502e881b328e77e0e068ee01090424f85651f44d3ad4d7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb61b66e17ff9abdedf79d6d0471b01b9c5b07b4f49f8cb15b3c9581d6872b8ee778988cea2f0f080d43ecd20fa935521fb2c62c3616d896931084d2ba24eb6c
|
7
|
+
data.tar.gz: 9271bc6cf4291d1664fbaa02f151585121e145589677cb79e7f7787a9f732d919f395f79b34c260dcf6be02ef2d42eb95e413ad79cf8dcfcfa1650b16b8cc485
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
RecordsKeeperRubyLib (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.
|
54
|
+
1.16.2
|
data/README.md
CHANGED
@@ -1,92 +1 @@
|
|
1
|
-
|
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
|
13
|
-
module RecordsKeeperRubyLib
|
14
|
-
class Address
|
15
|
-
|
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
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
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
|