RecordsKeeperRubyLib 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,99 +1,87 @@
|
|
1
|
-
# Library to work with assets.
|
2
|
-
|
3
|
-
# You can issue assets
|
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
|
-
class Assets
|
15
|
-
# # Entry point for accessing
|
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
|
-
out = response.parsed_response
|
89
|
-
if out[0]['result'].nil?
|
90
|
-
txid = out[0]['error']['message']
|
91
|
-
else
|
92
|
-
txid = out[0]['result']
|
93
|
-
end
|
94
|
-
return txid; # Variable to store send asset transaction id
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
1
|
+
# Library to work with assets.
|
2
|
+
|
3
|
+
# You can issue assets or retrieve assets information by using asset 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
|
+
class Assets
|
15
|
+
# # Entry point for accessing Block class resources.
|
16
|
+
# # Import values from config file.
|
17
|
+
cfg = YAML::load(File.open('config.yaml','r'))
|
18
|
+
@network = cfg['network']
|
19
|
+
@url = cfg['network']['url']
|
20
|
+
@user = cfg['network']['rkuser']
|
21
|
+
@password = cfg['network']['passwd']
|
22
|
+
@chain = cfg['network']['chain']
|
23
|
+
|
24
|
+
def self.variable
|
25
|
+
net = @network
|
26
|
+
return net
|
27
|
+
end
|
28
|
+
|
29
|
+
# Function to create or issue an asset
|
30
|
+
def self.createAsset address, asset_name, asset_qty
|
31
|
+
auth = {:username => @user, :password => @password}
|
32
|
+
options = {
|
33
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
34
|
+
:basic_auth => auth,
|
35
|
+
:body => [ {"method":"issue","params":[address, asset_name, asset_qty],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
36
|
+
}
|
37
|
+
response = HTTParty.get(@url, options)
|
38
|
+
out = response.parsed_response
|
39
|
+
check = out[0]['result']
|
40
|
+
if check == nil
|
41
|
+
txid = "Asset or stream with this name already exists"
|
42
|
+
else
|
43
|
+
txid = out[0]['result']
|
44
|
+
end
|
45
|
+
return txid; # Variable to store issue transaction id
|
46
|
+
end
|
47
|
+
|
48
|
+
# Function to retrieve assets information
|
49
|
+
def self.retrieveAssets
|
50
|
+
asset_name = []
|
51
|
+
issue_id = []
|
52
|
+
issue_qty = []
|
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":"listassets","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
58
|
+
}
|
59
|
+
response = HTTParty.get(@url, options)
|
60
|
+
out = response.parsed_response
|
61
|
+
asset_count = out[0]['result'].length # Returns assets count
|
62
|
+
for i in 0...asset_count
|
63
|
+
asset_name.push(out[0]['result'][i]['name']) # Returns asset name
|
64
|
+
issue_id.push(out[0]['result'][i]['issuetxid']) # Returns issue id
|
65
|
+
issue_qty.push(out[0]['result'][i]['issueraw']) # Returns issue quantity
|
66
|
+
end
|
67
|
+
retrieve = {:assert_name => assert_name,:issue_id => issue_id,:issue_qty => issue_qty,:asset_count => asset_count}
|
68
|
+
retrievedinfo = JSON.generate retrieve
|
69
|
+
return retrievedinfo
|
70
|
+
end
|
71
|
+
|
72
|
+
# Function to send quantity of assets to an address
|
73
|
+
def self.sendasset address, asset_name, asset_qty
|
74
|
+
auth = {:username => @user, :password => @password}
|
75
|
+
options = {
|
76
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
77
|
+
:basic_auth => auth,
|
78
|
+
:body => [ {"method":"sendasset","params":[address, asset_name, asset_qty],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
79
|
+
}
|
80
|
+
response = HTTParty.get(@url, options)
|
81
|
+
out = response.parsed_response
|
82
|
+
txid = out[0]['result']
|
83
|
+
return txid; # Variable to store send asset transaction id
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
@@ -1,94 +1,88 @@
|
|
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
|
-
|
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
|
-
retrievedinfo = JSON.generate retrieved
|
90
|
-
return retrievedinfo
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|
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
|
+
|
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
|
+
def self.blockinfo block_height
|
32
|
+
height = block_height.to_s
|
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":"getblock","params":[height],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
38
|
+
}
|
39
|
+
response = HTTParty.get(@url, options)
|
40
|
+
out = response.parsed_response
|
41
|
+
tx_count_number = out[0]['result']['tx']
|
42
|
+
tx_count = tx_count_number.length # variable returns block's transaction count
|
43
|
+
miner = out[0]['result']['miner'] # variable returns block's miner
|
44
|
+
size = out[0]['result']['size'] # variable returns block's size
|
45
|
+
nonce = out[0]['result']['nonce'] # variable returns block's nonce
|
46
|
+
blockHash = out[0]['result']['hash'] # variable returns blockhash
|
47
|
+
prevblock = out[0]['result']['previousblockhash'] # variable returns prevblockhash
|
48
|
+
nextblock = out[0]['result']['nextblockhash'] # variable returns nextblockhash
|
49
|
+
merkleroot = out[0]['result']['merkleroot'] # variable returns merkleroot
|
50
|
+
blocktime = out[0]['result']['time'] # variable returns blocktime
|
51
|
+
difficulty = out[0]['result']['difficulty'] # variable returns difficulty
|
52
|
+
tx = [] # list to store transaction ids
|
53
|
+
for i in 0...tx_count
|
54
|
+
tx.push(out[0]['result']['tx'][i]) # pushes transaction ids onto tx list
|
55
|
+
end
|
56
|
+
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}
|
57
|
+
retrievedinfo = JSON.generate retrieved
|
58
|
+
return retrievedinfo
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.retrieveBlocks block_range
|
62
|
+
blockhash = []
|
63
|
+
miner = []
|
64
|
+
blocktime = []
|
65
|
+
tx_count = []
|
66
|
+
auth = {:username => @user, :password => @password}
|
67
|
+
options = {
|
68
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
69
|
+
:basic_auth => auth,
|
70
|
+
:body => [ {"method":"listblocks","params":[block_range],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
71
|
+
}
|
72
|
+
response = HTTParty.get(@url, options)
|
73
|
+
out = response.parsed_response
|
74
|
+
block_count_len = out[0]['result']
|
75
|
+
block_count = block_count_len.length
|
76
|
+
for i in 0...block_count
|
77
|
+
blockhash.push(out[0]['result'][i]['hash'])
|
78
|
+
miner.push(out[0]['result'][i]['miner'])
|
79
|
+
blocktime.push(out[0]['result'][i]['time'])
|
80
|
+
tx_count.push(out[0]['result'][i]['txcount'])
|
81
|
+
end
|
82
|
+
retrieved = { :blockhash => blockhash,:miner => miner,:blocktime => blocktime,:tx_count => tx_count}
|
83
|
+
retrievedinfo = JSON.generate retrieved
|
84
|
+
return retrievedinfo
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
@@ -1,148 +1,138 @@
|
|
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
|
-
|
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
|
-
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
|
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
|
+
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
|
+
# Function to retrieve RecordsKeeper Blockchain parameters
|
29
|
+
def self.getChainInfo
|
30
|
+
auth = {:username => @user, :password => @password}
|
31
|
+
options = {
|
32
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
33
|
+
:basic_auth => auth,
|
34
|
+
:body => [ {"method":"getblockchainparams","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
35
|
+
}
|
36
|
+
response = HTTParty.get(@url, options)
|
37
|
+
out = response.parsed_response
|
38
|
+
result = out[0]['result']
|
39
|
+
chain_protocol = result['chain-protocol']
|
40
|
+
chain_description = result['chain-description']
|
41
|
+
root_stream = result['root-stream-name']
|
42
|
+
max_blocksize = result['maximum-block-size']
|
43
|
+
default_networkport = result['default-network-port']
|
44
|
+
default_rpcport = result['default-rpc-port']
|
45
|
+
mining_diversity = result['mining-diversity']
|
46
|
+
chain_name = result['chain-name']
|
47
|
+
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
|
48
|
+
retrieved = JSON.generate info
|
49
|
+
return retrieved
|
50
|
+
end
|
51
|
+
|
52
|
+
# Function to retrieve node's information on RecordsKeeper Blockchain
|
53
|
+
def self.getNodeInfo
|
54
|
+
auth = {:username => @user, :password => @password}
|
55
|
+
options = {
|
56
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
57
|
+
:basic_auth => auth,
|
58
|
+
:body => [ {"method":"getinfo","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
59
|
+
}
|
60
|
+
response = HTTParty.get(@url, options)
|
61
|
+
out = response.parsed_response
|
62
|
+
node_balance = out[0]['result']['balance']
|
63
|
+
synced_blocks = out[0]['result']['blocks']
|
64
|
+
node_address = out[0]['result']['nodeaddress']
|
65
|
+
difficulty = out[0]['result']['difficulty']
|
66
|
+
info = {:node_balance => node_balance, :synced_blocks => synced_blocks,:node_address => node_address,:difficulty => difficulty} # Returns node's details
|
67
|
+
retrieved = JSON.generate info
|
68
|
+
return retrieved
|
69
|
+
end
|
70
|
+
|
71
|
+
# Function to retrieve node's permissions on RecordsKeeper Blockchain
|
72
|
+
def self.permissions
|
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":"listpermissions","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
78
|
+
}
|
79
|
+
response = HTTParty.get(@url, options)
|
80
|
+
out = response.parsed_response
|
81
|
+
pms_count_len = out[0]['result']
|
82
|
+
pms_count = pms_count_len.length
|
83
|
+
permissions = []
|
84
|
+
for i in 0...pms_count
|
85
|
+
permissions.push(out[0]['result'][i]['type'])
|
86
|
+
end
|
87
|
+
return permissions; # Returns list of permissions
|
88
|
+
end
|
89
|
+
|
90
|
+
# Function to retrieve pending transactions information on RecordsKeeper Blockchain
|
91
|
+
def self.getpendingTransactions
|
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":"getmempoolinfo","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
97
|
+
}
|
98
|
+
response = HTTParty.get(@url, options)
|
99
|
+
out = response.parsed_response
|
100
|
+
tx_count = out[0]['result']['size'] # Stores pending tx count
|
101
|
+
|
102
|
+
if tx_count==0
|
103
|
+
tx = "No pending transactions"
|
104
|
+
else
|
105
|
+
auth = {:username => @user, :password => @password}
|
106
|
+
options = {
|
107
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
108
|
+
:basic_auth => auth,
|
109
|
+
:body => [ {"method":"getrawmempool","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
110
|
+
}
|
111
|
+
response2 = HTTParty.get(@url, options)
|
112
|
+
out2 = response2.parsed_response
|
113
|
+
tx = []
|
114
|
+
for i in 0...tx_count
|
115
|
+
tx.push(out2[0]['result'])
|
116
|
+
end
|
117
|
+
end
|
118
|
+
pending = {:tx_count => tx_count,:tx => tx}
|
119
|
+
pendingtransac = JSON.generate pending # Returns pending tx and tx count
|
120
|
+
return pendingtransac
|
121
|
+
end
|
122
|
+
|
123
|
+
# Function to check node's total balance
|
124
|
+
def self.checkNodeBalance
|
125
|
+
auth = {:username => @user, :password => @password}
|
126
|
+
options = {
|
127
|
+
:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
|
128
|
+
:basic_auth => auth,
|
129
|
+
:body => [ {"method":"getmultibalances","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
|
130
|
+
}
|
131
|
+
response = HTTParty.get(@url, options)
|
132
|
+
out = response.parsed_response
|
133
|
+
balance = out[0]['result']['total'][0]['qty']
|
134
|
+
return balance; # Returns balance of node
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|