Class: RecordsKeeperRubyLib::Blockchain

Inherits:
Object
  • Object
show all
Defined in:
lib/RecordsKeeperRubyLib/blockchain.rb

Class Method Summary collapse

Class Method Details

.checkNodeBalanceObject

Function to check node’s total balance



133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/RecordsKeeperRubyLib/blockchain.rb', line 133

def self.checkNodeBalance
	auth = {:username => @user, :password => @password}
	options = {
		:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
		:basic_auth => auth,
		:body => [ {"method":"getmultibalances","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
	}
	response = HTTParty.get(@url, options)
	out = response.parsed_response

	balance = out[0]['result']['total'][-1]['qty']
	return balance;														# Returns balance of  node
end

.getChainInfoObject

Function to retrieve RecordsKeeper Blockchain parameters



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/RecordsKeeperRubyLib/blockchain.rb', line 36

def self.getChainInfo
	auth = {:username => @user, :password => @password}
	options = {
		:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
		:basic_auth => auth,
		:body => [ {"method":"getblockchainparams","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
	}
	response = HTTParty.get(@url, options)
	out = response.parsed_response
	result = out[0]['result']
	chain_protocol = result['chain-protocol']
	chain_description = result['chain-description']
	root_stream = result['root-stream-name']
	max_blocksize = result['maximum-block-size']
	default_networkport = result['default-network-port']
	default_rpcport = result['default-rpc-port']
	mining_diversity = result['mining-diversity']
	chain_name = result['chain-name']
	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
	retrieved = JSON.generate info
	return retrieved
end

.getNodeInfoObject

Function to retrieve node’s information on RecordsKeeper Blockchain



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/RecordsKeeperRubyLib/blockchain.rb', line 60

def self.getNodeInfo
	auth = {:username => @user, :password => @password}
	options = {
		:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
		:basic_auth => auth,
		:body => [ {"method":"getinfo","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
	}
	response = HTTParty.get(@url, options)
	out = response.parsed_response
	node_balance = out[0]['result']['balance']
	synced_blocks = out[0]['result']['blocks']
	node_address = out[0]['result']['nodeaddress']
	difficulty = out[0]['result']['difficulty']
		info = {:node_balance => node_balance, :synced_blocks => synced_blocks,:node_address => node_address,:difficulty => difficulty}						# Returns node's details
	retrieved = JSON.generate info
	return retrieved
end

.getpendingTransactionsObject

Function to retrieve pending transactions information on RecordsKeeper Blockchain



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
# File 'lib/RecordsKeeperRubyLib/blockchain.rb', line 100

def self.getpendingTransactions
	auth = {:username => @user, :password => @password}
	options = {
		:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
		:basic_auth => auth,
		:body => [ {"method":"getmempoolinfo","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
	}
	response = HTTParty.get(@url, options)
	out = response.parsed_response
	tx_count = out[0]['result']['size']											# Stores pending tx count

	if tx_count==0
		tx = "No pending transactions"
	else
		auth = {:username => @user, :password => @password}
		options = {
			:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
			:basic_auth => auth,
			:body => [ {"method":"getrawmempool","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
		}
		response2 = HTTParty.get(@url, options)
		out2 = response2.parsed_response
		tx = []
		for i in 0...tx_count
			tx.push(out2[0]['result'])
		end
	end
	pending = {:tx_count => tx_count,:tx => tx}
	pendingtransaction = JSON.generate pending														# Returns pending tx and tx count
	return pendingtransaction
end

.permissionsObject

Function to retrieve node’s permissions on RecordsKeeper Blockchain



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/RecordsKeeperRubyLib/blockchain.rb', line 79

def self.permissions
	auth = {:username => @user, :password => @password}
	options = {
		:headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
		:basic_auth => auth,
		:body => [ {"method":"listpermissions","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
	}
	response = HTTParty.get(@url, options)
	out = response.parsed_response
	pms_count_len = out[0]['result']
	pms_count = pms_count_len.length
	permissions = []
	for i in 0...pms_count
		permissions.push(out[0]['result'][i]['type'])
	end

	permissions_list = permissions.uniq
	return permissions_list;																# Returns list of permissions
end