xrplwin/xrpl-ledgertime

此软件包通过提供日期和时间作为输入来提取账本索引。

v1.0.1 2023-05-01 20:49 UTC

This package is auto-updated.

Last update: 2024-09-30 19:11:18 UTC


README

main workflow GitHub license Total Downloads

XRPL 账本时间

此软件包通过提供日期和时间作为输入来提取账本索引。

基本上 2023-04-13 15:00:00 UTC 会给出 79077871

安装

composer require xrplwin/xrpl-ledgertime

为什么?

XRPL API 中没有可用于提取账本确切时间的可用方法。比如说,你想查询2022年1月1日08:00:00到12:00:00之间的账户交易列表。对于这个查询,你需要向 account_tx 方法提供 ledger_index_minledger_index_max

你可以查找本地预同步数据库以获取所需的账本索引并将它们添加到查询中。

你可以同步并存储每日开始的账本、每小时开始的账本等。你将同步的周期取决于你的业务需求。

公平使用声明

始终预同步时间并将它们存储在本地或共享数据库中!

请不要在生产网站上使用此脚本查询 XRPLedger。此脚本通过多次连接到 XRPL Rest API 来提取单个账本时间。请使用后台同步作业来预同步账本时间。

系统时间

Ripple 服务器依赖于维护正确的时间。建议您使用 ntpd 或 chrony 等守护进程,通过网络时间协议 (NTP) 来同步您的系统时间。

用法

选项 1(日期时间到账本索引)

use XRPLWin\XRPLLedgerTime\XRPLLedgerTimeSyncer;
use Carbon\Carbon;

$syncer = new XRPLLedgerTimeSyncer(); //init syncer

$datetime = Carbon::create(2023, 4, 13, 15, 0, 0, 'UTC'); //create Carbon datetime object
$ledgerIndex = $syncer->datetimeToLedgerIndex($datetime); //will return: 79077871

选项 2(账本索引到日期时间)

use XRPLWin\XRPLLedgerTime\XRPLLedgerTimeSyncer;

$syncer = new XRPLLedgerTimeSyncer(); //init syncer
$carbon = $syncer->ledgerIndexToCarbon(79077871);

选项概述

$syncer = new XRPLLedgerTimeSyncer(
  [
    # Following values are defined by default, uncomment to override
    //'ledgerindex_low' => 0
  ],
  [
    # Following values are defined by default, uncomment to override
    # These options will be passed to \XRPLWin\XRPL\Client
    //'endpoint_fullhistory_uri' => 'https://xrplcluster.com'
  ]
); 

运行测试

在 "tests" 目录中运行所有测试。

composer test

或者

./vendor/bin/phpunit --testdox