class RecordsKeeperRubyLib::Wallet

Public Class Methods

backupWallet(filename) click to toggle source

Function to create wallet's backup on RecordsKeeper Blockchain

# File lib/RecordsKeeperRubyLib/wallet.rb, line 106
      def self.backupWallet filename
  auth = {:username => @user, :password => @password}
  options = {
    :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
    :basic_auth => auth,
    :body => [ {"method":"backupwallet","params":[filename],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
  }
  response = HTTParty.get(@url, options)
  out = response.parsed_response
      result = out[0]['result']
      if result.nil?
              res = "Backup successful!"
      else
              res = out[0]['error']['message']
  end
              return res;                                                          #returns result
end
changeWalletPassword(old_password, new_password) click to toggle source

Function to change password for wallet on RecordsKeeper Blockchain

# File lib/RecordsKeeperRubyLib/wallet.rb, line 201
def self.changeWalletPassword old_password, new_password
  auth = {:username => @user, :password => @password}
  options = {
    :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
    :basic_auth => auth,
    :body => [ {"method":"walletpassphrasechange","params":[old_password, new_password],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
  }
  response = HTTParty.get(@url, options)
  out = response.parsed_response
      result = out[0]['result']
      if result.nil?
              res = "Password successfully changed!"
      else
              res = out[0]['error']['message']
  end
      return res;                                                           #returns result
end
createWallet() click to toggle source

Function to create wallet on RecordsKeeper Blockchain

# File lib/RecordsKeeperRubyLib/wallet.rb, line 37
    def self.createWallet
        auth = {:username => @user, :password => @password}
        options = {
          :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
          :basic_auth => auth,
          :body => [ {"method":"createkeypairs","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
        }
        response = HTTParty.get(@url, options)
        out = response.parsed_response
            public_address = out[0]['result'][0]['address']                      # returns public address of the wallet
            private_key = out[0]['result'][0]['privkey']                         # returns private key of the wallet
            public_key = out[0]['result'][0]['pubkey']                                   # returns public key of the wallet

            def self.importAddress public_address
          auth = {:username => @user, :password => @password}
          options = {
            :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, options)
          out = response.parsed_response
              result = out[0]['result']
              return result;
        end
            import_address = importAddress public_address
            retrieve = {:public_address => public_address,:private_key => private_key,:public_key => public_key}
            retrievedinfo = JSON.generate retrieve
            return retrievedinfo
end
dumpWallet(filename) click to toggle source

Function to dump wallet on RecordsKeeper Blockchain

# File lib/RecordsKeeperRubyLib/wallet.rb, line 144
def self.dumpWallet filename
  auth = {:username => @user, :password => @password}
  options = {
    :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
    :basic_auth => auth,
    :body => [ {"method":"dumpwallet","params":[filename],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
  }
  response = HTTParty.get(@url, options)
  out = response.parsed_response
      result = out[0]['result']
      if result.nil?
              res = "Wallet is successfully dumped"
      else
              res = out[0]['error']['message']
  end
              return res;                                                          #returns result
end
getPrivateKey(public_address) click to toggle source

Function to retrieve private key of a wallet address on RecordsKeeper Blockchain

# File lib/RecordsKeeperRubyLib/wallet.rb, line 69
def self.getPrivateKey public_address
         auth = {:username => @user, :password => @password}
         options = {
           :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
           :basic_auth => auth,
           :body => [ {"method":"dumpprivkey","params":[public_address],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
         }
         response = HTTParty.get(@url, options)
         out = response.parsed_response
             result = out[0]['result']
             if result.nil?
                     private_key = out[0]['error']['message']
             else
                     private_key = out[0]['result']
    end
             return private_key;                                                  #returns private key
end
importAddress(public_address) click to toggle source
# File lib/RecordsKeeperRubyLib/wallet.rb, line 50
    def self.importAddress public_address
  auth = {:username => @user, :password => @password}
  options = {
    :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, options)
  out = response.parsed_response
      result = out[0]['result']
      return result;
end
importWallet(filename) click to toggle source

Function to import wallet's backup on RecordsKeeper Blockchain

# File lib/RecordsKeeperRubyLib/wallet.rb, line 125
def self.importWallet filename
  auth = {:username => @user, :password => @password}
  options = {
    :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
    :basic_auth => auth,
    :body => [ {"method":"importwallet","params":[filename],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
  }
  response = HTTParty.get(@url, options)
  out = response.parsed_response
      result = out[0]['result']
      if result.nil?
              res = "Wallet is successfully imported"
      else
              res = out[0]['error']['message']
  end
              return res;                                                          #returns result
end
lockWallet(password) click to toggle source

Function to lock wallet on RecordsKeeper Blockchain

# File lib/RecordsKeeperRubyLib/wallet.rb, line 163
def self.lockWallet password
  auth = {:username => @user, :password => @password}
  options = {
    :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
    :basic_auth => auth,
    :body => [ {"method":"encryptwallet","params":[password],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
  }
  response = HTTParty.get(@url, options)
  out = response.parsed_response
      result = out[0]['result']
      if result.nil?
              res = "Wallet is successfully encrypted."
      else
              res = out[0]['error']['message']
  end
              return res;                                                          #returns result
end
retrieveWalletinfo() click to toggle source

Function to retrieve wallet's information on RecordsKeeper Blockchain

# File lib/RecordsKeeperRubyLib/wallet.rb, line 88
def self.retrieveWalletinfo
      auth = {:username => @user, :password => @password}
      options = {
        :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
        :basic_auth => auth,
        :body => [ {"method":"getwalletinfo","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
      }
      response = HTTParty.get(@url, options)
      out = response.parsed_response
          balance = out[0]['result']['balance']
          tx_count = out[0]['result']['txcount']
          unspent_tx = out[0]['result']['utxocount']
          retrieve = {:balance => balance,:tx_count => tx_count,:unspent_tx => unspent_tx}
          retrievedinfo = JSON.generate retrieve
          return retrievedinfo
    end
signMessage(private_key, message) click to toggle source

Function to sign message on RecordsKeeper Blockchain

# File lib/RecordsKeeperRubyLib/wallet.rb, line 220
def self.signMessage private_key, message
  auth = {:username => @user, :password => @password}
  options = {
    :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
    :basic_auth => auth,
    :body => [ {"method":"signmessage","params":[private_key, message],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
  }
  response = HTTParty.get(@url, options)
  out = response.parsed_response
  check = out[0]['result']

      if check.nil?
              signedMessage = out[0]['error']['message']
      else 
              signedMessage = out[0]['result']
      end
      return signedMessage;                                                                 #returns private key
end
unlockWallet(password, unlocktime) click to toggle source

Function to unlock wallet on RecordsKeeper Blockchain

# File lib/RecordsKeeperRubyLib/wallet.rb, line 182
      def self.unlockWallet password, unlocktime
  auth = {:username => @user, :password => @password}
  options = {
    :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
    :basic_auth => auth,
    :body => [ {"method":"walletpassphrase","params":[password, unlocktime],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
  }
  response = HTTParty.get(@url, options)
  out = response.parsed_response
      result = out[0]['result']
      if result.nil?
              res = "Wallet is successfully unlocked."
      else
              res = out[0]['error']['message']
  end
              return res;                                                          #returns result
end
verifyMessage(address, signedMessage, message) click to toggle source

Function to verify message on RecordsKeeper Blockchain

# File lib/RecordsKeeperRubyLib/wallet.rb, line 240
  def self.verifyMessage address, signedMessage, message
    auth = {:username => @user, :password => @password}
    options = {
      :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
      :basic_auth => auth,
      :body => [ {"method":"verifymessage","params":[address, signedMessage, message],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
    }
    response = HTTParty.get(@url, options)
    out = response.parsed_response
        verifiedMessage = out[0]['result']
        error = out[0]['error']
        if verifiedMessage
                validity = "Yes, message is verified"
        elsif error.nil?
                validity = "No, signedMessage is not correct"
        else 
                validity = error['message']
end
        return validity;                                                                              #returns validity
  end