RecordsKeeperRubyLib 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,79 @@
1
+ # = Stream Class Usage
2
+ # This is a library to work with streams in RecordsKeeper Blockchain.
3
+ # You can publish address, retrieve data, retrieve with address, retrieve with key, verify data and retrieve items.
4
+ # ---------
5
+ # == Libraries
6
+ # Require these ruby libraries first to get started with the functionality.
7
+ # require 'rubygems'
8
+ # require 'httparty'
9
+ # require 'json'
10
+ # require 'binary_parser'
11
+ # require 'yaml'
12
+ # -----------------
13
+ # == Create Connection
14
+ # Entry point for accessing Address class resources.
15
+ # * URL: Url to connect to the chain ([RPC Host]:[RPC Port])
16
+ # * Chain-name: chain name
17
+ # cfg = YAML::load(File.open('sample_config.yaml','r')) # Loads the configuration file
18
+ # * Set a *network* value.
19
+ # network = cfg['network'] # Network variable to store the network that you want to access
20
+ # * Set url and chain name:
21
+ # @url = cfg['network']['url']
22
+ # @chain = cfg['network']['chain']
23
+ # -------------------
24
+ # == Node Authentication
25
+ # Import values from config file.
26
+ # * User name: The rpc user is used to call the APIs.
27
+ # * Password: The rpc password is used to authenticate the APIs.
28
+ # * Set the rpc username and password:
29
+ # @user = cfg['network']['rkuser']
30
+ # @password = cfg['network']['passwd']
31
+ # Now we have node authentication credentials.
32
+ # ------------
33
+ # = class Stream
34
+ # Stream class is used to call stream related functions to publish address, retrieve data, retrieve with address, retrieve with key, verify data and retrieve items.
35
+ # === 1. publish address, stream, key, data
36
+ # This function retrieves information about the chain.
37
+ # publish address, stream, key, data
38
+ # transacid = publish address, stream, key, data # Function call
39
+ #
40
+ # puts transacid # Prints txid.
41
+ # === 2. retrieve stream, txid
42
+ # This function retrieves information related to your node.
43
+ # retrieve stream, txid
44
+ # data = retrieve stream, txid # Function call
45
+ #
46
+ # puts data # Prints raw_data.
47
+ # === 3. retrieveWithAddress stream, address
48
+ # This function lists all the permissions.
49
+ # retrieveWithAddress stream, address
50
+ # retadd = JSON.parse retrieveWithAddress stream, address # Function call
51
+ #
52
+ # puts retadd['key'] # Prints key, data and txid.
53
+ # puts retadd['raw_data'] # prints raw data
54
+ # puts retadd['txid'] # prints transaction id
55
+ # === 4. retrieveWithKey stream, key
56
+ # This function retrieves information related to your node.
57
+ # retrieveWithKey stream, key
58
+ # retkey = JSON.parse retrieveWithKey stream, key # Function call
59
+ #
60
+ # puts retkey['publisher'] # prints publisher
61
+ # puts retkey['raw_data'] # prints raw data
62
+ # puts retkey['txid'] # prints transaction id
63
+ # === 5. verifyData stream, data, count
64
+ # This function retrieves information related to your node.
65
+ # verifyData stream, data, count
66
+ # verifystat = verifyData stream, data, count # Function call
67
+ #
68
+ # puts verifystat # Prints result.
69
+ # === 6. retrieveItems stream, count
70
+ # This function retrieves information related to your node.
71
+ # retrieveItems stream, count
72
+ # retitem = JSON.parse retrieveItems stream, count # Function call
73
+ #
74
+ # puts retitem['address'] # prints address
75
+ # puts retitem['key_value'] # prints key_value
76
+ # puts retitem['raw_data'] # prints raw_data
77
+ # puts retitem['txid'] # prints transaction id
78
+ class Stream
79
+ end
@@ -0,0 +1,110 @@
1
+ # = Transaction Class Usage
2
+ # This is a library to work with RecordsKeeper transactions.
3
+ # 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.
4
+ # ---------
5
+ # == Libraries
6
+ # Require these ruby libraries first to get started with the functionality.
7
+ # require 'rubygems'
8
+ # require 'httparty'
9
+ # require 'json'
10
+ # require 'binary_parser'
11
+ # require 'yaml'
12
+ # require 'hex_string'
13
+ # -----------------
14
+ # == Create Connection
15
+ # Entry point for accessing Address class resources.
16
+ # * URL: Url to connect to the chain ([RPC Host]:[RPC Port])
17
+ # * Chain-name: chain name
18
+ # cfg = YAML::load(File.open('sample_config.yaml','r')) # Loads the configuration file
19
+ # * Set a *network* value.
20
+ # network = cfg['network'] # Network variable to store the network that you want to access
21
+ # * Set url and chain name:
22
+ # @url = cfg['network']['url']
23
+ # @chain = cfg['network']['chain']
24
+ # -------------------
25
+ # == Node Authentication
26
+ # Import values from config file.
27
+ # * User name: The rpc user is used to call the APIs.
28
+ # * Password: The rpc password is used to authenticate the APIs.
29
+ # * Set the rpc username and password:
30
+ # @user = cfg['network']['rkuser']
31
+ # @password = cfg['network']['passwd']
32
+ # Now we have node authentication credentials.
33
+ # ------------
34
+ # = class Transaction
35
+ # Transaction class is used to call transaction related functions like create raw transaction, sign transaction, send transaction , retrieve transaction and verify transaction functions which are used to create raw transactions, send transactions, sign transactions, retrieve transactions and verify transactions on the RecordsKeeeper Blockchain.
36
+ # === 1. sendTransaction sender_address, reciever_address, amount
37
+ # This function is used to send transaction by passing reciever’s address, sender’s address and amount.
38
+ #
39
+ # You have to pass these three arguments to the sendTransaction function call:
40
+ # * Transaction’s sender address
41
+ # * Transaction’s reciever address
42
+ # * Amount to be sent in transaction
43
+ #
44
+ # txid = sendTransaction sender_address, reciever_address, amount # Function call
45
+ #
46
+ # puts txid # prints transaction id of the sent transaction
47
+ # === 2. sendSignedTransaction
48
+ # This function is used to send transaction by passing reciever’s address, sender’s address, private key of sender and amount. In this function private key is required to sign transaction.
49
+ #
50
+ # You have to pass these four arguments to the sendSignedTransaction function call:
51
+ # * Transaction’s sender address
52
+ # * Transaction’s reciever address
53
+ # * Amount to be sent in transaction
54
+ # * Private key of the sender’s address
55
+ #
56
+ # transaction_id = sendSignedTransaction # Function call
57
+ #
58
+ # puts transaction_id # prints transaction id of the signed transaction
59
+ # === 3. createRawTransaction sender_address, reciever_address, amount
60
+ # This function is used to create raw transaction by passing reciever’s address, sender’s address and amount.
61
+ #
62
+ # You have to pass these three arguments to the sendTransaction function call:
63
+ # * Transaction’s sender address
64
+ # * Transaction’s reciever address
65
+ # * Amount to be sent in transaction
66
+ #
67
+ # tx_hex = createRawTransaction sender_address, reciever_address, amount # Function call
68
+ #
69
+ # puts tx_hex # prints transaction hex of the raw transaction
70
+ # === 4. signRawTransaction tx_hex, private_key
71
+ # This function retrieves is used to sign raw transaction by passing transaction hex of the raw transaction and the private key to sign the raw transaction.
72
+ #
73
+ # You have to pass these three arguments to the signRawTransaction function call:
74
+ # * Transaction hex of the raw transaction
75
+ # * Private key to sign raw transaction
76
+ #
77
+ # signed_hex = signRawTransaction txHex, private_key # Function call
78
+ #
79
+ # puts signed_hex # prints signed transaction hex of the raw transaction
80
+ # === 5. sendRawTransaction signed_txHex
81
+ # This function is used to send raw transaction by passing signed transaction hex of the raw transaction.
82
+ #
83
+ # You have to pass the signed transaction hex of the raw transaction.
84
+ #
85
+ # tx_id = sendRawTransaction signed_txHex # Function call
86
+ #
87
+ # puts tx_id # prints transaction id of the raw transaction
88
+ # === 6. retrieveTransaction tx_id
89
+ # This function is used to retrieve transaction’s information by passing transaction id to the function.
90
+ #
91
+ # You have to pass the transaction id of the transaction you want to retrieve.
92
+ #
93
+ # retrievedinfo = JSON.parse retrieveTransaction tx_id # Function call
94
+ #
95
+ # puts retrievedinfo['sent_data'] #prints sent data
96
+ # puts retrievedinfo['sent_amount'] #prints sent amount
97
+ # puts retrievedinfo['reciever_address'] #prints reciever's address
98
+ # === 7. getFee address, tx_id
99
+ # This function is used to calculate transaction’s fee by passing transaction id and sender’s address to the function.
100
+ #
101
+ # You have to pass these two arguments to the getFee function call:
102
+ # * Transaction id of the transaction you want to calculate fee for
103
+ # * Sender’s address
104
+ #
105
+ # fees = getFee address, tx_id # Function call
106
+ #
107
+ # puts fees #prints fees consumed in the verified transaction
108
+
109
+ class Transaction
110
+ end
@@ -0,0 +1,122 @@
1
+ # = Wallet Class Usage
2
+ # Library to work with RecordsKeeper wallet functionalities.
3
+ # 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.
4
+ # ---------
5
+ # == Libraries
6
+ # Require these ruby libraries first to get started with the functionality.
7
+ # require 'rubygems'
8
+ # require 'httparty'
9
+ # require 'json'
10
+ # require 'binary_parser'
11
+ # require 'yaml'
12
+ # require 'hex_string'
13
+ # -----------------
14
+ # == Create Connection
15
+ # Entry point for accessing Address class resources.
16
+ # * URL: Url to connect to the chain ([RPC Host]:[RPC Port])
17
+ # * Chain-name: chain name
18
+ # cfg = YAML::load(File.open('sample_config.yaml','r')) # Loads the configuration file
19
+ # * Set a *network* value.
20
+ # network = cfg['network'] # Network variable to store the network that you want to access
21
+ # * Set url and chain name:
22
+ # @url = cfg['network']['url']
23
+ # @chain = cfg['network']['chain']
24
+ # -------------------
25
+ # == Node Authentication
26
+ # Import values from config file.
27
+ # * User name: The rpc user is used to call the APIs.
28
+ # * Password: The rpc password is used to authenticate the APIs.
29
+ # * Set the rpc username and password:
30
+ # @user = cfg['network']['rkuser']
31
+ # @password = cfg['network']['passwd']
32
+ # Now we have node authentication credentials.
33
+ # ------------
34
+ # = class Wallet
35
+ # Wallet class is used to call wallet related functions like create wallet, retrieve private key of wallet address, retrieve wallet’s information, dump wallet, lock wallet, unlock wallet, change wallet’s password, create wallet’s backup, import wallet’s backup, sign message and verify message functions on RecordsKeeeper Blockchain.
36
+ # === 1. createWallet
37
+ # This function is used to create wallet on RecordsKeeper blockchain
38
+ # newwallet = JSON.parse createWallet
39
+ #
40
+ # puts newwallet['publicaddress'] # prints public address of the wallet
41
+ # puts newwallet['privatekey'] # prints private key of the wallet
42
+ # puts newwallet['publickey'] # prints public key of the wallet
43
+ # === 2. getPrivateKey
44
+ # This function is used to retrieve private key of the given address.
45
+ # privkey = getPrivateKey
46
+ #
47
+ # puts privkey # prints private key of the given address
48
+ # === 3. retrieveWalletinfo
49
+ # This function is used to retrieve node wallet’s information.
50
+ # walletinfo = JSON.parse retrieveWalletinfo
51
+ #
52
+ # puts walletinfo['balance'] # prints wallet's balance
53
+ # puts walletinfo['tx_count'] # prints wallet transaction count
54
+ # puts walletinfo['unspent_tx'] # prints unspent wallet transactions
55
+ # === 4. backupWallet filename
56
+ # This function is used to create backup of the wallet.dat file.
57
+ #
58
+ # You have to pass filename; wallet’s backup file name
59
+ # result = backupWallet filename
60
+ #
61
+ # puts result # prints result
62
+ # It will return the response of the backup wallet function. The backup of the wallet is created in your chain’s directory and you can simply access your file by using same filename that you have passed with the backupwallet function. Creates a backup of the wallet.dat file in which the node’s private keys and watch-only addresses are stored. The backup is created in file filename. Use with caution – any node with access to this file can perform any action restricted to this node’s addresses.
63
+ # === 5. importWallet filename
64
+ # This function is used to import wallet’s backup file.
65
+ #
66
+ # You have to pass the filename; wallet’s backup file name.
67
+ # result = importWallet filename
68
+ #
69
+ # puts result # prints result
70
+ # It will return the response of the import wallet function. It will import the entire set of private keys which were dumped (using dumpwallet) into file filename.
71
+ # === 6. dumpWallet filename
72
+ # This function is used to retrieve transaction’s information by passing transaction id to the function.
73
+ #
74
+ # You have to pass the filename; file name to dump wallet in.
75
+ # result = dumpWallet filename
76
+ #
77
+ # puts result # prints result
78
+ # === 7. lockWallet password
79
+ # This function is used to verify transaction’s information by passing transaction id and sender’s address to the function.
80
+ #
81
+ # You have to pass password; password to lock the wallet.
82
+ # result = lockWallet password
83
+ #
84
+ # puts result # prints result
85
+ # === 8. unlockWallet password, unlock_time
86
+ # This function is used to verify transaction’s information by passing transaction id and sender’s address to the function.
87
+ #
88
+ # You have to pass these two arguments to the unlockWallet function call:
89
+ # * Password: password to unlock the wallet
90
+ # * unlocktime: seconds for which wallet remains unlock
91
+ # result = unlockWallet password, unlock_time
92
+ #
93
+ # puts result # prints result
94
+ # === 9. changeWalletPassword old_password, new_password
95
+ # This function is used to change wallet’s password and set new password.
96
+ #
97
+ # You have to pass these two arguments to the changeWalletPassword function call:
98
+ # * Old Password: old password of the wallet
99
+ # * New Password: new password of the wallet
100
+ # result = changeWalletPassword password, new_password
101
+ #
102
+ # puts result # prints result
103
+ # === 10. signMessage private_key, message
104
+ # This function is used to change wallet’s password and set new password.
105
+ #
106
+ # You have to pass these two arguments to the signMessage function call:
107
+ # * Message: message to send
108
+ # * Private Key: private key of the sender’s wallet address
109
+ # signedMessage = signMessage private_key, message
110
+ #
111
+ # puts signedMessage # prints signed message
112
+ # === 11. verifyMessage address, signedMessage, message
113
+ # This function is used to change wallet’s password and set new password.
114
+ #
115
+ # You have to pass these three arguments to the verifyMessage function call:
116
+ # * Message: message to send
117
+ # * Private Key: private key of the sender’s wallet address
118
+ # validity = verifyMessage address, signedMessage, message
119
+ #
120
+ # puts validity # prints validity of the message
121
+ class Wallet
122
+ end
@@ -1,186 +1,198 @@
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
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