Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
733 changes: 439 additions & 294 deletions Modules/Common/RippleLikeFTModule.php

Large diffs are not rendered by default.

621 changes: 214 additions & 407 deletions Modules/Common/RippleLikeMainModule.php

Large diffs are not rendered by default.

44 changes: 23 additions & 21 deletions Modules/Common/RippleLikeNFTModule.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php declare(strict_types = 1);

/* Copyright (c) 2023 Nikita Zhavoronkov, nikzh@nikzh.com
* Copyright (c) 2023-2024 3xpl developers, 3@3xpl.com
* Distributed under the MIT software license, see the accompanying file LICENSE.md */
/* Idea (c) 2023 Nikita Zhavoronkov, nikzh@nikzh.com
* Copyright (c) 2023-2024 3xpl developers, 3@3xpl.com, see CONTRIBUTORS.md
* Distributed under the MIT software license, see LICENSE.md */

/* This module works with NFT in Ripple. Requires a Ripple node. */

Expand Down Expand Up @@ -142,7 +142,7 @@ final public function pre_process_block($block_id)
if (!isset($tx['meta']))
throw new ModuleException("Transactions haven't been fully processed by the node yet");

$tx_result = $tx['meta']['TransactionResult'] === 'tesSUCCESS' ? false : true;
$tx_result = !($tx['meta']['TransactionResult'] === 'tesSUCCESS');

switch ($tx['TransactionType'])
{
Expand All @@ -151,39 +151,41 @@ final public function pre_process_block($block_id)
$new_owner = null;
$prev_owner = null;
$nft = null;
$broker = isset($tx['NFTokenBrokerFee']);
$broker_op = isset($tx['NFTokenBrokerFee']); // if set this -> we must have 2 offers
if (isset($tx['meta']['AffectedNodes']))
{
$affected_nodes = $tx['meta']['AffectedNodes'];
foreach ($affected_nodes as $id => $affection)
{
if (isset($affection['DeletedNode'])) {
if ($affection['DeletedNode']['LedgerEntryType'] === 'NFTokenOffer')
if (isset($affection['DeletedNode']))
{
if ($affection['DeletedNode']['LedgerEntryType'] === 'NFTokenOffer' && !$broker_op)
{
$prev_owner = $affection['DeletedNode']['FinalFields']['Owner'];
$new_owner = $tx['Account'];
$isSell = $affection['DeletedNode']['FinalFields']['Flags'];
$prev_owner = $isSell ? $affection['DeletedNode']['FinalFields']['Owner'] : $tx['Account']; // seller
$new_owner = $isSell ? $tx['Account'] : $affection['DeletedNode']['FinalFields']['Owner']; // buyer
$nft = $affection['DeletedNode']['FinalFields']['NFTokenID'];
break;
}
if ($affection['DeletedNode']['LedgerEntryType'] === 'NFTokenOffer' && $broker)
if ($affection['DeletedNode']['LedgerEntryType'] === 'NFTokenOffer' && $broker_op)
{
if ($affection['DeletedNode']['FinalFields']['Flags'] == 0) // it means that it's NFT buy offer https://xrpl.org/nftokencreateoffer.html#nftokencreateoffer-flags
switch ($affection['DeletedNode']['FinalFields']['Flags'])
{
$new_owner = $affection['DeletedNode']['FinalFields']['Owner'];
case 0: // flag = 0 -- buying
$new_owner = $affection['DeletedNode']['FinalFields']['Owner']; // buyer
break;
case 1: // flag = 1 -- selling
$prev_owner = $affection['DeletedNode']['FinalFields']['Owner']; // seller
break;
}
if ($affection['DeletedNode']['FinalFields']['Flags'] == 1) // it means that it's NFT sell offer https://xrpl.org/nftokencreateoffer.html#nftokencreateoffer-flags
{
$prev_owner = $affection['DeletedNode']['FinalFields']['Owner'];
}
$nft = $affection['DeletedNode']['FinalFields']['NFTokenID'];
$nft = $affection['DeletedNode']['FinalFields']['NFTokenID'];
}
}
}
}
if(is_null($prev_owner) && is_null($new_owner))
{ // this is for situation when the transaction fallen
// mostly in this situations we don't need to pay
// anything in Token module
{ // this is for a fallen transaction
// in this situations we don't need to pay
break;
}
$events[] = [
Expand Down Expand Up @@ -234,7 +236,7 @@ final public function pre_process_block($block_id)
{
$events[] = [
'transaction' => $tx['hash'],
'address' => $tx['Account'],
'address' => $tx['Owner'] ?? $tx['Account'],
'sort_key' => $sort_key++,
'effect' => '-1',
'failed' => $tx_result,
Expand Down
30 changes: 20 additions & 10 deletions Modules/Common/RippleTraits.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php declare(strict_types = 1);

/* Copyright (c) 2023 Nikita Zhavoronkov, nikzh@nikzh.com
* Copyright (c) 2023 3xpl developers, 3@3xpl.com
* Distributed under the MIT software license, see the accompanying file LICENSE.md */
/* Idea (c) 2023 Nikita Zhavoronkov, nikzh@nikzh.com
* Copyright (c) 2023-2024 3xpl developers, 3@3xpl.com, see CONTRIBUTORS.md
* Distributed under the MIT software license, see LICENSE.md */

/* This module process main Ripple transfers. Requires a Ripple node. */

Expand Down Expand Up @@ -90,26 +90,26 @@ enum RippleSpecialTransactions: string
case NFTokenCancelOffer = 'ntn'; // 83305993

/** This transaction accepts an existing offer to buy or sell an existing NFT. */
case NFTokenAcceptOffer = 'nta'; // 83305991
case NFTokenAcceptOffer = 'nta'; // 83305991 // 86727556 -- token module

// These transactions are not in prod now, will wait for them
/** This transaction claws back issued tokens. */
case Clawback = 'cb';
case Clawback = 'cb'; // 86728685

/** This transaction type creates an AMM instance */
case AMMCreate = 'ac';
case AMMCreate = 'ac'; // 86795329

/** This transaction type deposits into an AMM instance */
case AMMDeposit = 'aa';
case AMMDeposit = 'aa'; // 86795341

/** This transaction type withdraws from an AMM instance */
case AMMWithdraw = 'aw';
case AMMWithdraw = 'aw'; // 86795415

/** This transaction type votes for the trading fee */
case AMMVote = 'av';
case AMMVote = 'av'; // 86795860

/** This transaction type bids for the auction slot */
case AMMBid = 'ab';
case AMMBid = 'ab'; // 86807643

/** This transaction type deletes AMM in the empty state */
case AMMDelete = 'ae';
Expand Down Expand Up @@ -180,6 +180,8 @@ trait RippleTraits
// if amount > y => error
private function to_96($number)
{
if($number === '0')
return $number;
$decimals = 96;
$e = strpos($number, 'e');
$e_num = 0;
Expand Down Expand Up @@ -210,4 +212,12 @@ private function to_96($number)
return $num;
}
}

private function bcabs(string $number)
{
if($number[0] === '-')
return substr($number, 1);
else
return $number;
}
}
Loading