Class: RecordsKeeperRubyLib::Address
- Inherits:
-
Object
- Object
- RecordsKeeperRubyLib::Address
- Defined in:
- lib/RecordsKeeperRubyLib/address.rb
Class Method Summary collapse
-
.checkBalance(address) ⇒ Object
Function to check node address balance on RecordsKeeper Blockchain.
-
.checkifMineAllowed(address) ⇒ Object
Function to check if given address has mining permission or not.
-
.checkifValid(address) ⇒ Object
Function to check if given address is valid or not.
-
.getAddress ⇒ Object
Function to generate new address on the node’s wallet.
-
.getMultisigAddress(nrequired, key) ⇒ Object
Function to generate a new multisignature address.
-
.getMultisigWalletAddress(nrequired, key) ⇒ Object
Function to generate a new multisignature address on the node’s wallet.
-
.importAddress(public_address) ⇒ Object
Function to import address on RecordsKeeper Blockchain.
-
.retrieveAddresses ⇒ Object
Function to list all addresses and no of addresses on the node’s wallet.
Class Method Details
.checkBalance(address) ⇒ Object
Function to check node address balance on RecordsKeeper Blockchain
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/RecordsKeeperRubyLib/address.rb', line 157 def self.checkBalance address auth = {:username => @user, :password => @password} = { :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"}, :basic_auth => auth, :body => [ {"method":"getaddressbalances","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json } response = HTTParty.get(@url, ) out = response.parsed_response check = out[0]['result'] if check balance = out[0]['result'][0]['qty'] else balance = out[0]['error']['message'] end return balance; # Returns balance of a particular node address end |
.checkifMineAllowed(address) ⇒ Object
Function to check if given address has mining permission or not
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/RecordsKeeperRubyLib/address.rb', line 131 def self.checkifMineAllowed address auth = {:username => @user, :password => @password} = { :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"}, :basic_auth => auth, :body => [ {"method":"validateaddress","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json } response = HTTParty.get(@url, ) out = response.parsed_response check = out[0]['result']['isvalid'] if check = out[0]['result']['ismine'] if = "Address has mining permission" # Prints that address has mining permission else = "Address has not given mining permission" # Prints that address hasn't been given mining permission end else = "Invalid address"; end return ; # Returns the permission status end |
.checkifValid(address) ⇒ Object
Function to check if given address is valid or not
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/RecordsKeeperRubyLib/address.rb', line 112 def self.checkifValid address auth = {:username => @user, :password => @password} = { :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"}, :basic_auth => auth, :body => [ {"method":"validateaddress","params":[address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json } response = HTTParty.get(@url, ) out = response.parsed_response validity = out[0]['result']['isvalid'] if validity addressCheck = "Address is valid" # Prints that address is valid else addressCheck= "Address is invalid" # Prints that address is invalid end return addressCheck; # Return the address check status end |
.getAddress ⇒ Object
Function to generate new address on the node’s wallet
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/RecordsKeeperRubyLib/address.rb', line 35 def self.getAddress auth = {:username => @user, :password => @password} = { :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"}, :basic_auth => auth, :body => [ {"method":"getnewaddress","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json } response = HTTParty.get(@url, ) out = response.parsed_response address = out[0]['result'] return address end |
.getMultisigAddress(nrequired, key) ⇒ Object
Function to generate a new multisignature address
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/RecordsKeeperRubyLib/address.rb', line 50 def self.getMultisigAddress nrequired, key #getMultisigAddress() function definition key_list = key.split(",") auth = {:username => @user, :password => @password} = { :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"}, :basic_auth => auth, :body => [ {"method":"createmultisig","params":[nrequired, key_list],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json } response = HTTParty.get(@url, ) out = response.parsed_response address = out[0]['result'] if address.nil? res = out[0]['error']['message'] else res = out[0]['result']['address'] end return res; #returns new multisig address end |
.getMultisigWalletAddress(nrequired, key) ⇒ Object
Function to generate a new multisignature address on the node’s wallet
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/RecordsKeeperRubyLib/address.rb', line 71 def self.getMultisigWalletAddress nrequired, key key_list = key.split(",") auth = {:username => @user, :password => @password} = { :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"}, :basic_auth => auth, :body => [ {"method":"addmultisigaddress","params":[nrequired, key_list],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json } response = HTTParty.get(@url, ) out = response.parsed_response address = out[0]['result'] if address.nil? res = out[0]['error']['message'] else res = out[0]['result'] end return res; # Returns new multisig address end |
.importAddress(public_address) ⇒ Object
Function to import address on RecordsKeeper Blockchain
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/RecordsKeeperRubyLib/address.rb', line 176 def self.importAddress public_address auth = {:username => @user, :password => @password} = { :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"}, :basic_auth => auth, :body => [ {"method":"importaddress","params":[public_address, " ", false],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json } response = HTTParty.get(@url, ) out = response.parsed_response result = out[0]['result'] error = out[0]['error'] if result.nil? && error.nil? resp = "Address successfully imported" # Prints that address has been succesfully imported elsif result.nil? && error!= nil resp = out[0]['error']['message'] else resp = 0 end return resp; end |
.retrieveAddresses ⇒ Object
Function to list all addresses and no of addresses on the node’s wallet
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/RecordsKeeperRubyLib/address.rb', line 91 def self.retrieveAddresses auth = {:username => @user, :password => @password} = { :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"}, :basic_auth => auth, :body => [ {"method":"getaddresses","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json } response = HTTParty.get(@url, ) out = response.parsed_response address = out[0]['result'] address_count = address.length address =[] for i in 0..address_count address.push(out[0]['result'][i]) end retrieved = { :address => address,:address_count => address_count} retrievedinfo = JSON.generate retrieved return retrievedinfo end |