Get Ledger and relating transactions on the CSCL

If you are looking to get the that relates to a Ledger (Block) on the CSCL use the following script

<?php

$daemon = 'http://xxxxxxxxxxx:8443';

function getLedger($index, $daemon) {

$ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $daemon);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, '

       { "method" : "ledger", 
			"params" : 
			[ 	{"ledger_index": '.$index.',"transactions": true}
			] }

    ');
    curl_setopt($ch, CURLOPT_POST, 1);

    $headers = array();
    $headers[] = "Content-Type: application/x-www-form-urlencoded";
    curl_setopt($ch, CURLOPT_HEADER, 0);

    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);
    if (empty($result)) {
      throw new Exception("Content is empty.");
    }
    $obj = json_decode($result, 1);
    if (empty($obj)) {
      throw new Exception("JSON decode failed, content: " .$result);
    }
            return $obj;
}

$ledgerArray = getLedger(172234, $daemon);

var_dump($ledgerArray);


?>

This will give the output of

array(1) {
  ["result"]=>
  array(5) {
    ["ledger"]=>
    array(17) {
      ["accepted"]=>
      bool(true)
      ["account_hash"]=>
      string(64) "3609A9D1AC6D6137F8CE7A65E67D4032D0AF6204A85B2ACDB164F37C7CBD6529"
      ["close_flags"]=>
      int(0)
      ["close_time"]=>
      int(633110120)
      ["close_time_human"]=>
      string(20) "2020-Jan-23 15:55:20"
      ["close_time_resolution"]=>
      int(10)
      ["closed"]=>
      bool(true)
      ["hash"]=>
      string(64) "F1F1132376CA09E1FDE281C5B03234F2517C9A7C2E360F292B77F8337F9E4ADA"
      ["ledger_hash"]=>
      string(64) "F1F1132376CA09E1FDE281C5B03234F2517C9A7C2E360F292B77F8337F9E4ADA"
      ["ledger_index"]=>
      string(6) "172234"
      ["parent_close_time"]=>
      int(633110112)
      ["parent_hash"]=>
      string(64) "207C1D118F0F6AAE909302798A7FB7F00FBE1BF372D59F9841FA33524A0DDEDA"
      ["seqNum"]=>
      string(6) "172234"
      ["totalCoins"]=>
      string(19) "3999999992024999979"
      ["total_coins"]=>
      string(19) "3999999992024999979"
      ["transaction_hash"]=>
      string(64) "E5818E0D2DC182E67F894E7D283BCE314024BCD8A8863207ECC9566DC1B8D7D9"
      ["transactions"]=>
      array(1) {
        [0]=>
        string(64) "0E79AD34FB547E9D356A71CD08B6CD960DCAA8CB8B07ED25388D003D86AAB68C"
      }
    }
    ["ledger_hash"]=>
    string(64) "F1F1132376CA09E1FDE281C5B03234F2517C9A7C2E360F292B77F8337F9E4ADA"
    ["ledger_index"]=>
    int(172234)
    ["status"]=>
    string(7) "success"
    ["validated"]=>
    bool(true)
  }
}

Get List of Tokens on CSCL

To retrieve an array of tokens available on the CSCL use the following script

<?php

$daemon = 'http://xxxxxxxxxx:8443';

function tokens($daemon) {

$ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $daemon);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, '

       { "method" : "config_info", 
			"params" : 
			[ 	{
				
				}
			] }

    ');
    curl_setopt($ch, CURLOPT_POST, 1);

    $headers = array();
    $headers[] = "Content-Type: application/x-www-form-urlencoded";
    curl_setopt($ch, CURLOPT_HEADER, 0);

    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);
    if (empty($result)) {
      throw new Exception("Content is empty.");
    }
    $obj = json_decode($result, 1);
    if (empty($obj)) {
      throw new Exception("JSON decode failed, content: " .$result);
    }
            return $obj;
}

$get = tokens($daemon);

var_dump($get);


?>

This will give a response of


array(1) {
  ["result"]=>
  array(4) {
    ["configuration"]=>
    array(5) {
      [0]=>
      array(3) {
        ["ConfigData"]=>
        array(1) {
          [0]=>
          array(1) {
            ["account"]=>
            string(34) "chXKNwZUjRLxdUumHoWji6iAAs2YLPV5eY"
          }
        }
        ["ConfigID"]=>
        int(4)
        ["ConfigType"]=>
        string(16) "Blacklist_Signer"
      }
      [1]=>
      array(3) {
        ["ConfigData"]=>
        array(15) {
          [0]=>
          array(10) {
            ["apiEndpoint"]=>
            string(28) "https://api.100.com/endpoint"
            ["contactEmail"]=>
            string(12) "info@100.com"
            ["extraFeeFactor"]=>
            int(0)
            ["flags"]=>
            int(0)
            ["fullName"]=>
            string(7) "100.com"
            ["iconURL"]=>
            string(94) "https://raw.githubusercontent.com/casinocoin/CasinoCoin-Assets/master/v4/100-coin-icon-512.png"
            ["issuer"]=>
            string(34) "cEWTA66ypmFVzZksJntBetbeQdDqnRLA44"
            ["token"]=>
            string(3) "100"
            ["totalSupply"]=>
            string(12) "250000000000"
            ["website"]=>
            string(19) "https://www.100.com"
          }
          [1]=>
          array(10) {
            ["apiEndpoint"]=>
            string(25) "https://api.pokercoin.com"
            ["contactEmail"]=>
            string(18) "info@pokercoin.com"
            ["extraFeeFactor"]=>
            int(0)
            ["flags"]=>
            int(0)
            ["fullName"]=>
            string(9) "PokerCoin"
            ["iconURL"]=>
            string(96) "https://raw.githubusercontent.com/casinocoin/CasinoCoin-Assets/master/v4/poker-coin-icon-512.png"
            ["issuer"]=>
            string(34) "cfiikpLkuWH2rYK1b7fV7RziYVuqUY6koo"
            ["token"]=>
            string(3) "PCN"
            ["totalSupply"]=>
            string(10) "1000000000"
            ["website"]=>
            string(25) "https://www.pokercoin.com"
          }
        .............

Connecting to a CSCL server

I am using PHP to connect via CURL to the ledger and to test my connection am using the following script

<?php

$daemon = 'http://xxxxxxx:8443'; // default port 5005

function server($daemon) {
/////////// check server info
$ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $daemon);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, '

       { "method" : "server_info", "params" : [ {}] }

    ');
    curl_setopt($ch, CURLOPT_POST, 1);

    $headers = array();
    $headers[] = "Content-Type: application/x-www-form-urlencoded";
    curl_setopt($ch, CURLOPT_HEADER, 0);

    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close ($ch);
    if (empty($result)) {
      throw new Exception("Content is empty.");
    }
    $obj = json_decode($result, 1);
    if (empty($obj)) {
      throw new Exception("JSON decode failed, content: " .$result);
    }
            return $obj;
}

$server = server($daemon);

var_dump($server);


?>

A successful connection will bring a result such as below

array(1) {
  ["result"]=>
  array(2) {
    ["info"]=>
    array(18) {
      ["build_version"]=>
      string(7) "4.0.5-4"
      ["complete_ledgers"]=>
      string(8) "1-191613"
      ["crn_activated"]=>
      bool(true)
      ["crn_domain_name"]=>
      string(10) "xxx.xxxxxxx.xxx"
      ["crn_public_key"]=>
      string(52) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
      ["hostid"]=>
      string(3) "csc"
      ["io_latency_ms"]=>
      int(1)
      ["last_close"]=>
      array(2) {
        ["converge_time_s"]=>
        float(1.998)
        ["proposers"]=>
        int(8)
      }
      ["load"]=>
      array(2) {
        ["job_types"]=>
        array(2) {
          [0]=>
          array(2) {
            ["in_progress"]=>
            int(1)
            ["job_type"]=>
            string(13) "clientCommand"
          }
          [1]=>
          array(2) {
            ["job_type"]=>
            string(11) "peerCommand"
            ["per_second"]=>
            int(15)
          }
        }
        ["threads"]=>
        int(4)
      }
      ["load_factor"]=>
      int(1)
      ["peers"]=>
      int(36)
      ["pubkey_node"]=>
      string(52) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
      ["pubkey_validator"]=>
      string(4) "none"
      ["server_state"]=>
      string(4) "full"
      ["state_accounting"]=>
      array(5) {
        ["connected"]=>
        array(2) {
          ["duration_us"]=>
          string(8) "38004520"
          ["transitions"]=>
          int(1)
        }
        ["disconnected"]=>
        array(2) {
          ["duration_us"]=>
          string(7) "1136881"
          ["transitions"]=>
          int(1)
        }
        ["full"]=>
        array(2) {
          ["duration_us"]=>
          string(12) "222333000321"
          ["transitions"]=>
          int(1)
        }
        ["syncing"]=>
        array(2) {
          ["duration_us"]=>
          string(9) "111007130"
          ["transitions"]=>
          int(1)
        }
        ["tracking"]=>
        array(2) {
          ["duration_us"]=>
          string(2) "83"
          ["transitions"]=>
          int(1)
        }
      }
      ["uptime"]=>
      int(222483)
      ["validated_ledger"]=>
      array(6) {
        ["age"]=>
        int(127)
        ["base_fee_csc"]=>
        float(0.25)
        ["hash"]=>
        string(64) "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        ["reserve_base_csc"]=>
        int(10)
        ["reserve_inc_csc"]=>
        int(1)
        ["seq"]=>
        int(191613)
      }
      ["validation_quorum"]=>
      int(6)
    }
    ["status"]=>
    string(7) "success"
  }
}