class RecordsKeeperRubyLib::Assets

Public Class Methods

createAsset(address, asset_name, asset_qty) click to toggle source

Function to create or issue an asset

# File lib/RecordsKeeperRubyLib/assets.rb, line 36
def self.createAsset address, asset_name, asset_qty

    auth = {:username => @user, :password => @password}
    options = {
      :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
      :basic_auth => auth,
      :body => [ {"method":"issue","params":[address, asset_name, asset_qty],"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
                        txid = out[0]['error']['message']
                else
              txid = out[0]['result']
                end
    return txid;                                                                               # Variable to store issue transaction id
end
retrieveAssets() click to toggle source

Function to retrieve assets information

# File lib/RecordsKeeperRubyLib/assets.rb, line 56
def self.retrieveAssets
    asset_name = []
    issue_id = []
    issue_qty = []
    auth = {:username => @user, :password => @password}
    options = {
      :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
      :basic_auth => auth,
      :body => [ {"method":"listassets","params":[],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
    }
    response = HTTParty.get(@url, options)
    out = response.parsed_response
    asset_count = out[0]['result'].length                                                                                      # Returns assets count
    for i in 0...asset_count
      asset_name.push(out[0]['result'][i]['name'])                                # Returns asset name
      issue_id.push(out[0]['result'][i]['issuetxid'])                           # Returns issue id
      issue_qty.push(out[0]['result'][i]['issueraw'])                                  # Returns issue quantity
    end
                retrieve = {:asset_name => asset_name,:issue_id => issue_id,:issue_qty => issue_qty,:asset_count => asset_count}
                retrievedinfo = JSON.generate retrieve
                return retrievedinfo
end
sendasset(address, asset_name, asset_qty) click to toggle source

Function to send assets to an address

# File lib/RecordsKeeperRubyLib/assets.rb, line 80
def self.sendasset address, asset_name, asset_qty
        auth = {:username => @user, :password => @password}
options = {
        :headers => headers= {"Content-Type"=> "application/json","Cache-Control" => "no-cache"},
        :basic_auth => auth,
        :body => [ {"method":"sendasset","params":[address, asset_name, asset_qty],"jsonrpc":2.0,"id":"curltext","chain_name":@chain}].to_json
        }
response = HTTParty.get(@url, options)
out = response.parsed_response
        if out[0]['result'].nil?
                txid = out[0]['error']['message']
        else 
                txid = out[0]['result']
        end
        return txid;                                                                          # Variable to store send asset transaction id
end