Skip to content

Commit

Permalink
nft_id and serilization module
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnxie999 committed Mar 6, 2023
1 parent 8687b5c commit 74d149f
Show file tree
Hide file tree
Showing 11 changed files with 742 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Builds/CMake/RippledCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,9 @@ target_sources (rippled PRIVATE
src/ripple/rpc/impl/ShardVerificationScheduler.cpp
src/ripple/rpc/impl/Status.cpp
src/ripple/rpc/impl/TransactionSign.cpp
src/ripple/rpc/impl/NFTokenID.cpp
src/ripple/rpc/impl/NFTokenOfferID.cpp
src/ripple/rpc/impl/TxMetaSerializer.cpp
#[===============================[
main sources:
subdir: perflog
Expand Down
3 changes: 3 additions & 0 deletions src/ripple/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ JSS(nft_offer); // in: LedgerEntry
JSS(nft_offer_index); // out nft_buy_offers, nft_sell_offers
JSS(nft_page); // in: LedgerEntry
JSS(nft_serial); // out: account_nfts
JSS(nftoken_id); // out: insertNFTokenID
JSS(nftoken_ids); // out: insertNFTokenID
JSS(no_ripple); // out: AccountLines
JSS(no_ripple_peer); // out: AccountLines
JSS(node); // out: LedgerEntry
Expand All @@ -432,6 +434,7 @@ JSS(node_writes_delayed); // out::GetCounts
JSS(obligations); // out: GatewayBalances
JSS(offer); // in: LedgerEntry
JSS(offers); // out: NetworkOPs, AccountOffers, Subscribe
JSS(offer_id); // out: insertNFTokenOfferID
JSS(offline); // in: TransactionSign
JSS(offset); // in/out: AccountTxOld
JSS(open); // out: handlers/Ledger
Expand Down
65 changes: 65 additions & 0 deletions src/ripple/rpc/NFTokenID.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2019 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#ifndef RIPPLE_RPC_NFTOKENID_H_INCLUDED
#define RIPPLE_RPC_NFTOKENID_H_INCLUDED

#include <ripple/protocol/Protocol.h>

#include <functional>
#include <memory>

namespace Json {
class Value;
}

namespace ripple {

class TxMeta;
class STTx;

namespace RPC {

/**
Add a `nftoken_ids` field to the `meta` output parameter.
The field is only added to successful NFTokenMint, NFTokenAcceptOffer,
and NFTokenCancelOffer transactions.
@{
*/
bool
canHaveNFTokenID(std::shared_ptr<STTx const> const&, TxMeta const&);

void
getNFTokenIDFromPage(TxMeta const&, std::vector<uint256>&);

void
getNFTokenIDFromDeletedOffer(TxMeta const&, std::vector<uint256>&);

void
insertNFTokenID(
Json::Value&,
std::shared_ptr<STTx const> const&,
TxMeta const&);
/** @} */

} // namespace RPC
} // namespace ripple

#endif
61 changes: 61 additions & 0 deletions src/ripple/rpc/NFTokenOfferID.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2019 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#ifndef RIPPLE_RPC_NFTOKENOFFERID_H_INCLUDED
#define RIPPLE_RPC_NFTOKENOFFERID_H_INCLUDED

#include <ripple/protocol/Protocol.h>

#include <functional>
#include <memory>

namespace Json {
class Value;
}

namespace ripple {

class TxMeta;
class STTx;

namespace RPC {

/**
Add an `offer_id` field to the `meta` output parameter.
The field is only added to successful NFTokenCreateOffer transactions.
@{
*/
bool
canHaveNFTokenOfferID(std::shared_ptr<STTx const> const&, TxMeta const&);

void
getOfferIDFromCreatedOffer(TxMeta const&, std::vector<uint256>&);

void
insertNFTokenOfferID(
Json::Value&,
std::shared_ptr<STTx const> const&,
TxMeta const&);
/** @} */

} // namespace RPC
} // namespace ripple

#endif
59 changes: 59 additions & 0 deletions src/ripple/rpc/TxMetaSerializer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2019 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#ifndef RIPPLE_RPC_TXMETASERIALIZER_H_INCLUDED
#define RIPPLE_RPC_TXMETASERIALIZER_H_INCLUDED

#include <ripple/protocol/Protocol.h>
#include <ripple/protocol/STBase.h>

#include <functional>
#include <memory>

namespace Json {
class Value;
}

namespace ripple {

class TxMeta;
class STTx;

namespace RPC {

struct JsonContext;

/**
Adds common synthetic fields to transaction-related JSON responses
@{
*/
void
serializeTxMetaAsJSON(
Json::Value&,
RPC::JsonContext const&,
std::shared_ptr<STTx const> const&,
TxMeta const&,
JsonOptions);
/** @} */

} // namespace RPC
} // namespace ripple

#endif
12 changes: 7 additions & 5 deletions src/ripple/rpc/handlers/AccountTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#include <ripple/protocol/jss.h>
#include <ripple/resource/Fees.h>
#include <ripple/rpc/Context.h>
#include <ripple/rpc/DeliveredAmount.h>
#include <ripple/rpc/Role.h>
#include <ripple/rpc/TxMetaSerializer.h>
#include <ripple/rpc/impl/RPCHelpers.h>

#include <grpcpp/grpcpp.h>
Expand Down Expand Up @@ -302,11 +302,13 @@ populateJsonResponse(
jvObj[jss::tx] = txn->getJson(JsonOptions::include_date);
if (txnMeta)
{
jvObj[jss::meta] =
txnMeta->getJson(JsonOptions::include_date);
jvObj[jss::validated] = true;
insertDeliveredAmount(
jvObj[jss::meta], context, txn, *txnMeta);
serializeTxMetaAsJSON(
jvObj,
context,
txn->getSTransaction(),
*txnMeta,
JsonOptions::include_date);
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/ripple/rpc/handlers/Tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
#include <ripple/protocol/ErrorCodes.h>
#include <ripple/protocol/jss.h>
#include <ripple/rpc/Context.h>
#include <ripple/rpc/DeliveredAmount.h>
#include <ripple/rpc/GRPCHandlers.h>
#include <ripple/rpc/TxMetaSerializer.h>
#include <ripple/rpc/impl/RPCHelpers.h>

namespace ripple {
Expand Down Expand Up @@ -292,9 +292,12 @@ populateJsonResponse(
auto& meta = *m;
if (meta)
{
response[jss::meta] = meta->getJson(JsonOptions::none);
insertDeliveredAmount(
response[jss::meta], context, result.txn, *meta);
serializeTxMetaAsJSON(
response,
context,
result.txn->getSTransaction(),
*meta,
JsonOptions::none);
}
}
response[jss::validated] = result.validated;
Expand Down
Loading

0 comments on commit 74d149f

Please sign in to comment.