RecordsKeeperRubyLib 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -1
- data/CODE_OF_CONDUCT.md +0 -8
- data/Gemfile +0 -1
- data/Gemfile.lock +4 -62
- data/LICENSE.txt +2 -2
- data/README.md +92 -1
- data/{RecordsKeeperRuby.gemspec → RecordsKeeperRubyLib.gemspec} +4 -5
- data/bin/console +1 -1
- data/config.yaml +8 -0
- data/docs/{addressdoc.rb → address_doc.rb} +105 -116
- data/docs/{assetsdoc.rb → asset_doc.rb} +54 -65
- data/docs/block_doc.rb +63 -0
- data/docs/blockchain_doc.rb +77 -0
- data/docs/{permissionsdoc.rb → permissions_doc.rb} +54 -65
- data/docs/{streamdoc.rb → stream_doc.rb} +79 -84
- data/docs/{transactiondoc.rb → transaction_doc.rb} +110 -121
- data/docs/{walletdoc.rb → wallet_doc.rb} +122 -133
- data/lib/RecordsKeeperRubyLib.rb +9 -0
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/address.rb +198 -186
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/assets.rb +99 -87
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/block.rb +94 -89
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/blockchain.rb +148 -135
- data/lib/RecordsKeeperRubyLib/config.yaml +8 -0
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/permissions.rb +77 -77
- data/lib/RecordsKeeperRubyLib/stream.rb +220 -0
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/transaction.rb +213 -182
- data/lib/RecordsKeeperRubyLib/version.rb +3 -0
- data/lib/{RecordsKeeperRuby → RecordsKeeperRubyLib}/wallet.rb +263 -252
- data/lib/config.yaml +8 -0
- metadata +27 -41
- data/docs/blockchaindoc.rb +0 -77
- data/docs/blockdoc.rb +0 -76
- data/lib/RecordsKeeperRuby.rb +0 -9
- data/lib/RecordsKeeperRuby/sample_config.yaml +0 -60
- data/lib/RecordsKeeperRuby/stream.rb +0 -169
- data/lib/RecordsKeeperRuby/version.rb +0 -3
- data/lib/sample_config.yaml +0 -60
- data/sample_config.yaml +0 -60
@@ -1,89 +1,94 @@
|
|
1
|
-
# Library to work with RecordsKeeper blocks.
|
2
|
-
|
3
|
-
# You can retrieve complete block information by using block class.
|
4
|
-
# You just have to pass parameters to invoke the pre-defined functions.
|
5
|
-
|
6
|
-
# Import the following libraries
|
7
|
-
|
8
|
-
require 'rubygems'
|
9
|
-
require 'httparty'
|
10
|
-
require 'json'
|
11
|
-
require 'binary_parser'
|
12
|
-
require 'yaml'
|
13
|
-
|
14
|
-
module
|
15
|
-
class Block
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@
|
23
|
-
@
|
24
|
-
@
|
25
|
-
|
26
|
-
else
|
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
|
-
|
1
|
+
# Library to work with RecordsKeeper blocks.
|
2
|
+
|
3
|
+
# You can retrieve complete block information by using block class.
|
4
|
+
# You just have to pass parameters to invoke the pre-defined functions.
|
5
|
+
|
6
|
+
# Import the following libraries
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'httparty'
|
10
|
+
require 'json'
|
11
|
+
require 'binary_parser'
|
12
|
+
require 'yaml'
|
13
|
+
|
14
|
+
module RecordsKeeperRubyLib
|
15
|
+
class Block
|
16
|
+
# # Entry point for accessing Block class functions
|
17
|
+
if File.exist?('config.yaml')
|
18
|
+
# Import values from configuration file.
|
19
|
+
cfg = YAML::load(File.open('config.yaml','r'))
|
20
|
+
|
21
|
+
@url = cfg['url']
|
22
|
+
@user = cfg['rkuser']
|
23
|
+
@password = cfg['passwd']
|
24
|
+
@chain = cfg['chain']
|
25
|
+
|
26
|
+
else
|
27
|
+
#Import using ENV variables
|
28
|
+
|
29
|
+
@url = ENV['url']
|
30
|
+
@user = ENV['rkuser']
|
31
|
+
@password = ENV['passwd']
|
32
|
+
@chain = ENV['chain']
|
33
|
+
end
|
34
|
+
|
35
|
+
# function to retrieve data of a particular block no.
|
36
|
+
def self.blockinfo block_height
|
37
|
+
height = block_height.to_s
|
38
|
+
auth = {:username => @user, :password => @password}
|
39
|
+
options = {
|
40
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
41
|
+
:basic_auth => auth,
|
42
|
+
:body => [ {"method":"getblock","params":[height],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
43
|
+
}
|
44
|
+
response = HTTParty.get(@url, options)
|
45
|
+
out = response.parsed_response
|
46
|
+
tx_count_number = out[0]['result']['tx']
|
47
|
+
tx_count = tx_count_number.length # variable returns block's transaction count
|
48
|
+
miner = out[0]['result']['miner'] # variable returns block's miner
|
49
|
+
size = out[0]['result']['size'] # variable returns block's size
|
50
|
+
nonce = out[0]['result']['nonce'] # variable returns block's nonce
|
51
|
+
blockHash = out[0]['result']['hash'] # variable returns blockhash
|
52
|
+
prevblock = out[0]['result']['previousblockhash'] # variable returns prevblockhash
|
53
|
+
nextblock = out[0]['result']['nextblockhash'] # variable returns nextblockhash
|
54
|
+
merkleroot = out[0]['result']['merkleroot'] # variable returns merkleroot
|
55
|
+
blocktime = out[0]['result']['time'] # variable returns blocktime
|
56
|
+
difficulty = out[0]['result']['difficulty'] # variable returns difficulty
|
57
|
+
tx = [] # list to store transaction ids
|
58
|
+
for i in 0...tx_count
|
59
|
+
tx.push(out[0]['result']['tx'][i]) # pushes transaction ids onto tx list
|
60
|
+
end
|
61
|
+
retrieved = { :tx_count => tx_count,:miner => miner,:size => size,:nonce => nonce,:blockHash => blockHash,:prevblock => prevblock, :nextblock => nextblock,:merkleroot => merkleroot,:blocktime => blocktime,:difficulty => difficulty,:tx => tx}
|
62
|
+
retrievedinfo = JSON.generate retrieved
|
63
|
+
return retrievedinfo
|
64
|
+
end
|
65
|
+
|
66
|
+
# function to retrieve data of blocks in a particular range
|
67
|
+
def self.retrieveBlocks block_range
|
68
|
+
blockhash = []
|
69
|
+
miner = []
|
70
|
+
blocktime = []
|
71
|
+
tx_count = []
|
72
|
+
auth = {:username => @user, :password => @password}
|
73
|
+
options = {
|
74
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
75
|
+
:basic_auth => auth,
|
76
|
+
:body => [ {"method":"listblocks","params":[block_range],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
77
|
+
}
|
78
|
+
response = HTTParty.get(@url, options)
|
79
|
+
out = response.parsed_response
|
80
|
+
block_count_len = out[0]['result']
|
81
|
+
block_count = block_count_len.length
|
82
|
+
for i in 0...block_count
|
83
|
+
blockhash.push(out[0]['result'][i]['hash'])
|
84
|
+
miner.push(out[0]['result'][i]['miner'])
|
85
|
+
blocktime.push(out[0]['result'][i]['time'])
|
86
|
+
tx_count.push(out[0]['result'][i]['txcount'])
|
87
|
+
end
|
88
|
+
retrieved = { :blockhash => blockhash,:miner => miner,:blocktime => blocktime,:tx_count => tx_count}
|
89
|
+
retrievedinfo = JSON.generate retrieved
|
90
|
+
return retrievedinfo
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -1,135 +1,148 @@
|
|
1
|
-
# Library to work with RecordsKeeper Blockchain.
|
2
|
-
|
3
|
-
# You can retrieve blockchain information, node's information, node's balance, node's permissions, pending transaction details
|
4
|
-
# by using Blockchain class.
|
5
|
-
# You just have to pass parameters to invoke the pre-defined functions."""
|
6
|
-
|
7
|
-
require 'rubygems'
|
8
|
-
require 'httparty'
|
9
|
-
require 'json'
|
10
|
-
require 'binary_parser'
|
11
|
-
require 'yaml'
|
12
|
-
|
13
|
-
module
|
14
|
-
class Blockchain
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@
|
22
|
-
@
|
23
|
-
|
24
|
-
@
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
# Function to retrieve RecordsKeeper Blockchain parameters
|
36
|
-
def self.getChainInfo
|
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":"getblockchainparams","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
42
|
-
}
|
43
|
-
response = HTTParty.get(@url, options)
|
44
|
-
out = response.parsed_response
|
45
|
-
result = out[0]['result']
|
46
|
-
chain_protocol = result['chain-protocol']
|
47
|
-
chain_description = result['chain-description']
|
48
|
-
root_stream = result['root-stream-name']
|
49
|
-
max_blocksize = result['maximum-block-size']
|
50
|
-
default_networkport = result['default-network-port']
|
51
|
-
default_rpcport = result['default-rpc-port']
|
52
|
-
mining_diversity = result['mining-diversity']
|
53
|
-
chain_name = result['chain-name']
|
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
|
-
|
1
|
+
# Library to work with RecordsKeeper Blockchain.
|
2
|
+
|
3
|
+
# You can retrieve blockchain information, node's information, node's balance, node's permissions, pending transaction details
|
4
|
+
# by using Blockchain class.
|
5
|
+
# You just have to pass parameters to invoke the pre-defined functions."""
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'httparty'
|
9
|
+
require 'json'
|
10
|
+
require 'binary_parser'
|
11
|
+
require 'yaml'
|
12
|
+
|
13
|
+
module RecordsKeeperRubyLib
|
14
|
+
class Blockchain
|
15
|
+
|
16
|
+
# # Entry point for accessing Blockchain class functions
|
17
|
+
if File.exist?('config.yaml')
|
18
|
+
# Import values from configuration file.
|
19
|
+
cfg = YAML::load(File.open('config.yaml','r'))
|
20
|
+
|
21
|
+
@url = cfg['url']
|
22
|
+
@user = cfg['rkuser']
|
23
|
+
@password = cfg['passwd']
|
24
|
+
@chain = cfg['chain']
|
25
|
+
|
26
|
+
else
|
27
|
+
#Import using ENV variables
|
28
|
+
|
29
|
+
@url = ENV['url']
|
30
|
+
@user = ENV['rkuser']
|
31
|
+
@password = ENV['passwd']
|
32
|
+
@chain = ENV['chain']
|
33
|
+
end
|
34
|
+
|
35
|
+
# Function to retrieve RecordsKeeper Blockchain parameters
|
36
|
+
def self.getChainInfo
|
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":"getblockchainparams","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
42
|
+
}
|
43
|
+
response = HTTParty.get(@url, options)
|
44
|
+
out = response.parsed_response
|
45
|
+
result = out[0]['result']
|
46
|
+
chain_protocol = result['chain-protocol']
|
47
|
+
chain_description = result['chain-description']
|
48
|
+
root_stream = result['root-stream-name']
|
49
|
+
max_blocksize = result['maximum-block-size']
|
50
|
+
default_networkport = result['default-network-port']
|
51
|
+
default_rpcport = result['default-rpc-port']
|
52
|
+
mining_diversity = result['mining-diversity']
|
53
|
+
chain_name = result['chain-name']
|
54
|
+
info = {:chain_protocol => chain_protocol, :chain_description => chain_description, :root_stream => root_stream, :max_blocksize => max_blocksize, :default_networkport => default_networkport, :default_rpcport => default_rpcport, :mining_diversity => mining_diversity, :chain_name => chain_name} #returns chain parameters
|
55
|
+
retrieved = JSON.generate info
|
56
|
+
return retrieved
|
57
|
+
end
|
58
|
+
|
59
|
+
# Function to retrieve node's information on RecordsKeeper Blockchain
|
60
|
+
def self.getNodeInfo
|
61
|
+
auth = {:username => @user, :password => @password}
|
62
|
+
options = {
|
63
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
64
|
+
:basic_auth => auth,
|
65
|
+
:body => [ {"method":"getinfo","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
66
|
+
}
|
67
|
+
response = HTTParty.get(@url, options)
|
68
|
+
out = response.parsed_response
|
69
|
+
node_balance = out[0]['result']['balance']
|
70
|
+
synced_blocks = out[0]['result']['blocks']
|
71
|
+
node_address = out[0]['result']['nodeaddress']
|
72
|
+
difficulty = out[0]['result']['difficulty']
|
73
|
+
info = {:node_balance => node_balance, :synced_blocks => synced_blocks,:node_address => node_address,:difficulty => difficulty} # Returns node's details
|
74
|
+
retrieved = JSON.generate info
|
75
|
+
return retrieved
|
76
|
+
end
|
77
|
+
|
78
|
+
# Function to retrieve node's permissions on RecordsKeeper Blockchain
|
79
|
+
def self.permissions
|
80
|
+
auth = {:username => @user, :password => @password}
|
81
|
+
options = {
|
82
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
83
|
+
:basic_auth => auth,
|
84
|
+
:body => [ {"method":"listpermissions","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
85
|
+
}
|
86
|
+
response = HTTParty.get(@url, options)
|
87
|
+
out = response.parsed_response
|
88
|
+
pms_count_len = out[0]['result']
|
89
|
+
pms_count = pms_count_len.length
|
90
|
+
permissions = []
|
91
|
+
for i in 0...pms_count
|
92
|
+
permissions.push(out[0]['result'][i]['type'])
|
93
|
+
end
|
94
|
+
|
95
|
+
permissions_list = permissions.uniq
|
96
|
+
return permissions_list; # Returns list of permissions
|
97
|
+
end
|
98
|
+
|
99
|
+
# Function to retrieve pending transactions information on RecordsKeeper Blockchain
|
100
|
+
def self.getpendingTransactions
|
101
|
+
auth = {:username => @user, :password => @password}
|
102
|
+
options = {
|
103
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
104
|
+
:basic_auth => auth,
|
105
|
+
:body => [ {"method":"getmempoolinfo","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
106
|
+
}
|
107
|
+
response = HTTParty.get(@url, options)
|
108
|
+
out = response.parsed_response
|
109
|
+
tx_count = out[0]['result']['size'] # Stores pending tx count
|
110
|
+
|
111
|
+
if tx_count==0
|
112
|
+
tx = "No pending transactions"
|
113
|
+
else
|
114
|
+
auth = {:username => @user, :password => @password}
|
115
|
+
options = {
|
116
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
117
|
+
:basic_auth => auth,
|
118
|
+
:body => [ {"method":"getrawmempool","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
119
|
+
}
|
120
|
+
response2 = HTTParty.get(@url, options)
|
121
|
+
out2 = response2.parsed_response
|
122
|
+
tx = []
|
123
|
+
for i in 0...tx_count
|
124
|
+
tx.push(out2[0]['result'])
|
125
|
+
end
|
126
|
+
end
|
127
|
+
pending = {:tx_count => tx_count,:tx => tx}
|
128
|
+
pendingtransaction = JSON.generate pending # Returns pending tx and tx count
|
129
|
+
return pendingtransaction
|
130
|
+
end
|
131
|
+
|
132
|
+
# Function to check node's total balance
|
133
|
+
def self.checkNodeBalance
|
134
|
+
auth = {:username => @user, :password => @password}
|
135
|
+
options = {
|
136
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
137
|
+
:basic_auth => auth,
|
138
|
+
:body => [ {"method":"getmultibalances","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
139
|
+
}
|
140
|
+
response = HTTParty.get(@url, options)
|
141
|
+
out = response.parsed_response
|
142
|
+
|
143
|
+
balance = out[0]['result']['total'][-1]['qty']
|
144
|
+
return balance; # Returns balance of node
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|