Created
November 25, 2020 05:13
-
-
Save askaaqib/7cb078e1fa813d409994866d82cf9508 to your computer and use it in GitHub Desktop.
List Payments - Stellar PHP API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
require "../vendor/autoload.php"; | |
use ZuluCrypto\StellarSdk\Server; | |
$server = Server::testNet(); | |
//$account = $server->getAccount('GCCZACJX7DHEWGK5WJ2ONRGAJN2RBGGCX3OO4NF66JMJ4MNACKED577A'); | |
$account = $server->getAccount('GBN2Q4QX72P5COMA2EJDRL42BCUXZVPM4FDNCMEMQHL7Z3AWJEL3SETT'); | |
$currentCursor = null; | |
echo "<pre>"; | |
while (true) { | |
$resultsPerPage = 10; | |
$payments = $account->getPayments(null, $resultsPerPage); | |
$seenResults = 0; | |
foreach ($payments as $payment) { | |
/** @var $payment \ZuluCrypto\StellarSdk\Model\Operation|\ZuluCrypto\StellarSdk\Model\AssetTransferInterface */ | |
// If the same cursor shows up twice, we're repeating results and should exit | |
if ($payment->getPagingToken() == $currentCursor) break 2; | |
printf('[%s] Amount: %s From %s in Tx %s' . PHP_EOL, | |
$payment->getAssetTransferType(), | |
$payment->getAssetAmount(), | |
$payment->getFromAccountId(), | |
$payment->getTransactionHash() | |
); | |
$currentCursor = $payment->getPagingToken(); | |
} | |
// Immediate exit if there aren't enough results to fill the page | |
if ($seenResults < $resultsPerPage) break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment