Skip to content

Commit

Permalink
Merge pull request #3 from shawnxie999/cft-direct-pay-apis
Browse files Browse the repository at this point in the history
Meta field and APIs
  • Loading branch information
gregtatcam authored Jan 4, 2024
2 parents d6123da + 17a1bd9 commit bc9b900
Show file tree
Hide file tree
Showing 24 changed files with 679 additions and 20 deletions.
2 changes: 2 additions & 0 deletions Builds/CMake/RippledCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ target_sources (rippled PRIVATE
src/ripple/rpc/handlers/BlackList.cpp
src/ripple/rpc/handlers/BookOffers.cpp
src/ripple/rpc/handlers/CanDelete.cpp
src/ripple/rpc/handlers/CFTHolders.cpp
src/ripple/rpc/handlers/Connect.cpp
src/ripple/rpc/handlers/ConsensusInfo.cpp
src/ripple/rpc/handlers/CrawlShards.cpp
Expand Down Expand Up @@ -737,6 +738,7 @@ target_sources (rippled PRIVATE
src/ripple/rpc/handlers/ValidatorListSites.cpp
src/ripple/rpc/handlers/Validators.cpp
src/ripple/rpc/handlers/WalletPropose.cpp
src/ripple/rpc/impl/CFTokenIssuanceID.cpp
src/ripple/rpc/impl/DeliveredAmount.cpp
src/ripple/rpc/impl/Handler.cpp
src/ripple/rpc/impl/LegacyPathFind.cpp
Expand Down
13 changes: 13 additions & 0 deletions src/ripple/app/ledger/impl/LedgerToJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <ripple/rpc/Context.h>
#include <ripple/rpc/DeliveredAmount.h>
#include <ripple/rpc/impl/RPCHelpers.h>
#include <ripple/rpc/CFTokenIssuanceID.h>

namespace ripple {

Expand Down Expand Up @@ -157,6 +158,12 @@ fillJsonTx(
fill.ledger,
txn,
{txn->getTransactionID(), fill.ledger.seq(), *stMeta});

// If applicable, insert cft issuance id
RPC::insertCFTokenIssuanceID(
txJson[jss::meta],
txn,
{txn->getTransactionID(), fill.ledger.seq(), *stMeta});
}

if (!fill.ledger.open())
Expand Down Expand Up @@ -190,6 +197,12 @@ fillJsonTx(
fill.ledger,
txn,
{txn->getTransactionID(), fill.ledger.seq(), *stMeta});

// If applicable, insert cft issuance id
RPC::insertCFTokenIssuanceID(
txJson[jss::metaData],
txn,
{txn->getTransactionID(), fill.ledger.seq(), *stMeta});
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
#include <ripple/rpc/impl/RPCHelpers.h>
#include <boost/asio/ip/host_name.hpp>
#include <boost/asio/steady_timer.hpp>
#include <ripple/rpc/CFTokenIssuanceID.h>

#include <algorithm>
#include <mutex>
Expand Down Expand Up @@ -3117,6 +3118,8 @@ NetworkOPsImp::transJson(
jvObj[jss::meta] = meta->get().getJson(JsonOptions::none);
RPC::insertDeliveredAmount(
jvObj[jss::meta], *ledger, transaction, meta->get());
RPC::insertCFTokenIssuanceID(
jvObj[jss::meta], transaction, meta->get());
}

if (!ledger->open())
Expand Down
9 changes: 5 additions & 4 deletions src/ripple/app/tx/impl/CFTokenIssuanceCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,26 @@ CFTokenIssuanceCreate::doApply()
if (mPriorBalance < view().fees().accountReserve((*acct)[sfOwnerCount] + 1))
return tecINSUFFICIENT_RESERVE;

auto const cftIssuanceID =
auto const cftIssuanceKeylet =
keylet::cftIssuance(account_, ctx_.tx.getSeqProxy().value());

// create the CFTokenIssuance
{
auto const ownerNode = view().dirInsert(
keylet::ownerDir(account_),
cftIssuanceID,
cftIssuanceKeylet,
describeOwnerDir(account_));

if (!ownerNode)
return tecDIR_FULL;

auto cftIssuance = std::make_shared<SLE>(cftIssuanceID);
auto cftIssuance = std::make_shared<SLE>(cftIssuanceKeylet);
(*cftIssuance)[sfFlags] = ctx_.tx.getFlags() & ~tfUniversal;
(*cftIssuance)[sfIssuer] = account_;
(*cftIssuance)[sfOutstandingAmount] = 0;
(*cftIssuance)[sfOwnerNode] = *ownerNode;

(*cftIssuance)[sfSequence] = ctx_.tx.getSeqProxy().value();

if (auto const max = ctx_.tx[~sfMaximumAmount])
(*cftIssuance)[sfMaximumAmount] = *max;

Expand Down
8 changes: 7 additions & 1 deletion src/ripple/protocol/Indexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,14 @@ cftoken(CFT const& issuanceID, AccountID const& holder) noexcept;
Keylet
cftoken(uint192 const& issuanceID, AccountID const& holder) noexcept;

inline Keylet
cftoken(uint256 const& cftokenKey)
{
return {ltCFTOKEN, cftokenKey};
}

Keylet
cftoken(uint256 const& issuanceID, AccountID const& holder) noexcept;
cftoken(uint256 const& issuanceKey, AccountID const& holder) noexcept;

Keylet
cft_dir(uint192 const& id) noexcept;
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/protocol/impl/Indexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@ cftoken(CFT const& cftID, AccountID const& holder) noexcept
}

Keylet
cftoken(uint256 const& issuanceID, AccountID const& holder) noexcept
cftoken(uint256 const& issuanceKey, AccountID const& holder) noexcept
{
return {ltCFTOKEN, indexHash(LedgerNameSpace::CFTOKEN, issuanceID, holder)};
return {ltCFTOKEN, indexHash(LedgerNameSpace::CFTOKEN, issuanceKey, holder)};
}

Keylet
Expand Down
6 changes: 3 additions & 3 deletions src/ripple/protocol/impl/Issue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ to_json(Issue const& is)
{
Json::Value jv;
if (is.asset().isCFT())
jv[jss::cft_asset_id] = to_string(is.asset());
jv[jss::cft_issuance_id] = to_string(is.asset());
else
jv[jss::currency] = to_string(is.asset());
if (!isXRP(is.asset()) && !is.asset().isCFT())
Expand All @@ -92,10 +92,10 @@ issueFromJson(Json::Value const& v)
"issueFromJson can only be specified with an 'object' Json value");
}

bool const isCFT = v.isMember(jss::cft_asset_id);
bool const isCFT = v.isMember(jss::cft_issuance_id);

Json::Value const assetStr =
isCFT ? v[jss::cft_asset_id] : v[jss::currency];
isCFT ? v[jss::cft_issuance_id] : v[jss::currency];
Json::Value const issStr = v[jss::issuer];

if (!assetStr.isString())
Expand Down
1 change: 1 addition & 0 deletions src/ripple/protocol/impl/LedgerFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ LedgerFormats::LedgerFormats()
ltCFTOKEN_ISSUANCE,
{
{sfIssuer, soeREQUIRED},
{sfSequence, soeREQUIRED},
{sfTransferFee, soeDEFAULT},
{sfOwnerNode, soeREQUIRED},
{sfAssetScale, soeDEFAULT},
Expand Down
6 changes: 3 additions & 3 deletions src/ripple/protocol/impl/STAmount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ STAmount::setJson(Json::Value& elem) const
// json.
elem[jss::value] = getText();
if (mIssue.isCFT())
elem[jss::cft_asset_id] = to_string(mIssue.asset());
elem[jss::cft_issuance_id] = to_string(mIssue.asset());
else
{
elem[jss::currency] = to_string(mIssue.asset());
Expand Down Expand Up @@ -1033,10 +1033,10 @@ amountFromJson(SField const& name, Json::Value const& v)
else if (v.isObject())
{
value = v[jss::value];
if (v.isMember(jss::cft_asset_id))
if (v.isMember(jss::cft_issuance_id))
{
isCFT = true;
asset = v[jss::cft_asset_id];
asset = v[jss::cft_issuance_id];
}
else
{
Expand Down
8 changes: 7 additions & 1 deletion src/ripple/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ JSS(build_path); // in: TransactionSign
JSS(build_version); // out: NetworkOPs
JSS(cancel_after); // out: AccountChannels
JSS(can_delete); // out: CanDelete
JSS(cft_asset_id); // in: Payment
JSS(cft_amount); // out: cft_holders
JSS(cft_issuance); // in: LedgerEntry, AccountObjects
JSS(cft_issuance_id); // in: Payment, cft_holders
JSS(cftoken); // in: LedgerEntry, AccountObjects
JSS(cftoken_index); // out: cft_holders
JSS(changes); // out: BookChanges
JSS(channel_id); // out: AccountChannels
JSS(channels); // out: AccountChannels
Expand Down Expand Up @@ -359,6 +363,7 @@ JSS(high); // out: BookChanges
JSS(highest_sequence); // out: AccountInfo
JSS(highest_ticket); // out: AccountInfo
JSS(historical_perminute); // historical_perminute.
JSS(holders); // out: CFTHolders
JSS(hostid); // out: NetworkOPs
JSS(hotwallet); // in: GatewayBalances
JSS(id); // websocket.
Expand Down Expand Up @@ -446,6 +451,7 @@ JSS(load_fee); // out: LoadFeeTrackImp, NetworkOPs
JSS(local); // out: resource/Logic.h
JSS(local_txs); // out: GetCounts
JSS(local_static_keys); // out: ValidatorList
JSS(locked_amount); // out: CFTHolders
JSS(low); // out: BookChanges
JSS(lowest_sequence); // out: AccountInfo
JSS(lowest_ticket); // out: AccountInfo
Expand Down
53 changes: 53 additions & 0 deletions src/ripple/rpc/CFTokenIssuanceID.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2024 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_CFTOKENISSUANCEID_H_INCLUDED
#define RIPPLE_RPC_CFTOKENISSUANCEID_H_INCLUDED

#include <ripple/basics/base_uint.h>
#include <ripple/json/json_forwards.h>
#include <ripple/protocol/STTx.h>
#include <ripple/protocol/TxMeta.h>

#include <memory>
#include <optional>

namespace ripple {

namespace RPC {

bool
canHaveCFTokenIssuanceID(
std::shared_ptr<STTx const> const& serializedTx,
TxMeta const& transactionMeta);

std::optional<uint192>
getIDFromCreatedIssuance(TxMeta const& transactionMeta);

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

} // namespace RPC
} // namespace ripple

#endif
4 changes: 3 additions & 1 deletion src/ripple/rpc/handlers/AccountObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ doAccountObjects(RPC::JsonContext& context)
{jss::xchain_owned_claim_id, ltXCHAIN_OWNED_CLAIM_ID},
{jss::xchain_owned_create_account_claim_id,
ltXCHAIN_OWNED_CREATE_ACCOUNT_CLAIM_ID},
{jss::bridge, ltBRIDGE}};
{jss::bridge, ltBRIDGE},
{jss::cft_issuance, ltCFTOKEN_ISSUANCE},
{jss::cftoken, ltCFTOKEN}};

typeFilter.emplace();
typeFilter->reserve(std::size(deletionBlockers));
Expand Down
2 changes: 2 additions & 0 deletions src/ripple/rpc/handlers/AccountTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <ripple/rpc/Context.h>
#include <ripple/rpc/DeliveredAmount.h>
#include <ripple/rpc/Role.h>
#include <ripple/rpc/CFTokenIssuanceID.h>

#include <grpcpp/grpcpp.h>

Expand Down Expand Up @@ -361,6 +362,7 @@ populateJsonResponse(
insertDeliveredAmount(
jvObj[jss::meta], context, txn, *txnMeta);
insertNFTSyntheticInJson(jvObj, sttx, *txnMeta);
RPC::insertCFTokenIssuanceID(jvObj[jss::meta], sttx, *txnMeta);
}
else
assert(false && "Missing transaction medatata");
Expand Down
Loading

0 comments on commit bc9b900

Please sign in to comment.