Get Transaction on the CSCL

Posted by

To retrieve data on a transaction use the script below

<?php

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

function getTx($tx,$daemon) {

$ch = curl_init();

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

       { "method" : "tx", "params" : [ {"transaction": "'.$tx.'"}] }

    ');
    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;
}

$tx = getTx('9206D86D80FC2F80922B38F10F43CD2ACE8C80BE0280E2DE6781707CC9FA073A',$daemon);

var_dump($tx);


?>

This gives the following output

array(1) {
  ["result"]=>
  array(17) {
    ["Account"]=>
    string(34) "cnKwvH78cUTAvZbm8TWZXqdsWhmjcok1Xm"
    ["Amount"]=>
    string(13) "1000000000000"
    ["Destination"]=>
    string(34) "cKyC8KSX1WZH6jTkJb4ntouYvQkuJ1RZVC"
    ["Fee"]=>
    string(8) "25000000"
    ["Flags"]=>
    int(2147483648)
    ["LastLedgerSequence"]=>
    int(191613)
    ["Sequence"]=>
    int(674)
    ["SigningPubKey"]=>
    string(66) "02F845799CAE9AE8421E0AEE0D93526AD21D882A911D93A46AFB17826B923A41C0"
    ["TransactionType"]=>
    string(7) "Payment"
    ["TxnSignature"]=>
    string(140) "3044022039A974644241ED22A4F733CF61B2CD40CED342B926F83704CC6F70CFA3D182B8022047150EA7F903B4CCB1BC085C1D9145DDE13687FDF008EB5DEB344FC79C4495A3"
    ["date"]=>
    int(633433350)
    ["hash"]=>
    string(64) "9206D86D80FC2F80922B38F10F43CD2ACE8C80BE0280E2DE6781707CC9FA073A"
    ["inLedger"]=>
    int(191609)
    ["ledger_index"]=>
    int(191609)
    ["meta"]=>
    array(4) {
      ["AffectedNodes"]=>
      array(2) {
        [0]=>
        array(1) {
          ["ModifiedNode"]=>
          array(6) {
            ["FinalFields"]=>
            array(5) {
              ["Account"]=>
              string(34) "cKyC8KSX1WZH6jTkJb4ntouYvQkuJ1RZVC"
              ["Balance"]=>
              string(13) "2000000000000"
              ["Flags"]=>
              int(0)
              ["OwnerCount"]=>
              int(0)
              ["Sequence"]=>
              int(1)
            }
            ["LedgerEntryType"]=>
            string(11) "AccountRoot"
            ["LedgerIndex"]=>
            string(64) "8DEA01AE8B1765DD9BBC9B0AC3986A1CEB59F3F0843C20052A0060ACE20D1532"
            ["PreviousFields"]=>
            array(1) {
              ["Balance"]=>
              string(13) "1000000000000"
            }
            ["PreviousTxnID"]=>
            string(64) "B04F53E22DBB4723D8C35622A2985FC27A301F9BDFD2F4C9C3D1184E63A156D2"
            ["PreviousTxnLgrSeq"]=>
            int(191606)
          }
        }
        [1]=>
        array(1) {
          ["ModifiedNode"]=>
          array(6) {
            ["FinalFields"]=>
            array(5) {
              ["Account"]=>
              string(34) "cnKwvH78cUTAvZbm8TWZXqdsWhmjcok1Xm"
              ["Balance"]=>
              string(17) "38952191430400000"
              ["Flags"]=>
              int(0)
              ["OwnerCount"]=>
              int(0)
              ["Sequence"]=>
              int(675)
            }
            ["LedgerEntryType"]=>
            string(11) "AccountRoot"
            ["LedgerIndex"]=>
            string(64) "D704E1180AEC7C58F832B9C80AEEF5C8A58BBEBBA56EA70B56327859E97D3C2E"
            ["PreviousFields"]=>
            array(2) {
              ["Balance"]=>
              string(17) "38953191455400000"
              ["Sequence"]=>
              int(674)
            }
            ["PreviousTxnID"]=>
            string(64) "B04F53E22DBB4723D8C35622A2985FC27A301F9BDFD2F4C9C3D1184E63A156D2"
            ["PreviousTxnLgrSeq"]=>
            int(191606)
          }
        }
      }
      ["TransactionIndex"]=>
      int(0)
      ["TransactionResult"]=>
      string(10) "tesSUCCESS"
      ["delivered_amount"]=>
      string(13) "1000000000000"
    }
    ["status"]=>
    string(7) "success"
    ["validated"]=>
    bool(true)
  }
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s