diff --git a/README.md b/README.md index 657b6af..0aff320 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,10 @@ taking the data (such as `eos`, `telos`, `wax` etc.). balance. Zero is returned if the token is not present or does not exist. -* `http://apihost.domain/api/topholders/CHAIN/CONTRACT/TOKEN/NUM` returns +* `http://apihost.domain/api/topholders/CHAIN/CONTRACT/TOKEN/NUM[/MARKER]` returns top NUM holders of a specified token in a JSON array containing arrays of (account, amount) pairs. NUM must not be less than 10 or more than - 1000. + 1000. MARKER is token integer as pagination offset. * `http://apihost.domain/api/holdercount/CHAIN/CONTRACT/TOKEN` returns the total count of token holders as plain text. The result is "0" if the @@ -50,9 +50,10 @@ taking the data (such as `eos`, `telos`, `wax` etc.). * `http://apihost.domain/api/usercount/CHAIN` returns a plain text with total number of accounts in the network. -* `http://apihost.domain/api/topram/CHAIN/NUM` returns top NUM RAM buyers +* `http://apihost.domain/api/topram/CHAIN/NUM[/MARKER]` returns top NUM RAM buyers in a JSON array containing arrays of (account, bytes) pairs. NUM must - not be less than 10 or more than 1000. + not be less than 10 or more than 1000. MARKER is bytes number as pagination + offset. * `http://apihost.domain/api/topstake/CHAIN/NUM` returns top NUM stake holders by sum of CPU and Net stakes, in a JSON array containing diff --git a/api/lightapi.psgi b/api/lightapi.psgi index 18d97db..9f1d999 100644 --- a/api/lightapi.psgi +++ b/api/lightapi.psgi @@ -929,14 +929,15 @@ $builder->mount my $req = Plack::Request->new($env); my $path_info = $req->path_info; - if ( $path_info !~ /^\/(\w+)\/([a-z1-5.]{1,13})\/([A-Z]{1,7})\/(\d+)$/ ) { - return(error($req, 'Expected network name, contract, token name, count in URL path')); + if ( $path_info !~ /^\/(\w+)\/([a-z1-5.]{1,13})\/([A-Z]{1,7})\/(\d+)(\/(\d+))?$/ ) { + return(error($req, 'Expected network name, contract, token name, count, marker in URL path')); } my $network = $1; my $contract = $2; my $currency = $3; my $count = $4; + my $marker = $6; if( $count < 10 or $count > 1000 ) { @@ -944,12 +945,23 @@ $builder->mount } check_dbserver(); - my $sth_topholders = $dbh->prepare - ('SELECT account_name, CAST(amount AS DECIMAL(48,24)) AS amt, decimals ' . - 'FROM ' . $network . '_CURRENCY_BAL ' . - 'WHERE contract=? AND currency=? ' . - 'ORDER BY amount DESC LIMIT ?'); - $sth_topholders->execute($contract, $currency, $count); + + my $sth_topholders; + if ( $marker ) { + $sth_topholders = $dbh->prepare + ('SELECT account_name, CAST(amount AS DECIMAL(48,24)) AS amt, decimals ' . + 'FROM ' . $network . '_CURRENCY_BAL ' . + 'WHERE contract=? AND currency=? AND amount < ? ' . + 'ORDER BY amount DESC LIMIT ?'); + $sth_topholders->execute($contract, $currency, $marker, $count); + } else { + $sth_topholders = $dbh->prepare + ('SELECT account_name, CAST(amount AS DECIMAL(48,24)) AS amt, decimals ' . + 'FROM ' . $network . '_CURRENCY_BAL ' . + 'WHERE contract=? AND currency=? ' . + 'ORDER BY amount DESC LIMIT ?'); + $sth_topholders->execute($contract, $currency, $count); + } my $all = $sth_topholders->fetchall_arrayref({}); my $result = []; foreach my $r (@{$all}) @@ -1135,12 +1147,13 @@ $builder->mount my $req = Plack::Request->new($env); my $path_info = $req->path_info; - if ( $path_info !~ /^\/(\w+)\/(\d+)$/ ) { - return(error($req, 'Expected a network name and count in URL path')); + if ( $path_info !~ /^\/(\w+)\/(\d+)(\/(\d+))?$/ ) { + return(error($req, 'Expected a network name, count and marker in URL path')); } my $network = $1; my $count = $2; + my $marker = $4; if( $count < 10 or $count > 1000 ) { @@ -1148,11 +1161,21 @@ $builder->mount } check_dbserver(); - my $sth_topram = $dbh->prepare - ('SELECT account_name, ram_bytes FROM ' . $network . '_USERRES ' . - 'ORDER BY ram_bytes DESC LIMIT ?'); - $sth_topram->execute($count); + my $sth_topram; + if ( $marker ) { + $sth_topram = $dbh->prepare + ('SELECT account_name, ram_bytes FROM ' . $network . '_USERRES ' . + 'WHERE ram_bytes < ? ' . + 'ORDER BY ram_bytes DESC LIMIT ?'); + $sth_topram->execute($marker, $count); + } else { + $sth_topram = $dbh->prepare + ('SELECT account_name, ram_bytes FROM ' . $network . '_USERRES ' . + 'ORDER BY ram_bytes DESC LIMIT ?'); + $sth_topram->execute($count); + } + my $all = $sth_topram->fetchall_arrayref({}); my $result = []; foreach my $r (@{$all})