Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cft apis latest #14

Draft
wants to merge 4 commits into
base: cft-feature
Choose a base branch
from
Draft
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
1 change: 1 addition & 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
10 changes: 6 additions & 4 deletions src/ripple/app/tx/impl/CFTokenIssuanceCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/TxFlags.h>
#include <ripple/protocol/st.h>
#include <ripple/protocol/cft.h>

namespace ripple {

Expand Down Expand Up @@ -68,24 +69,25 @@ CFTokenIssuanceCreate::doApply()
if (mPriorBalance < view().fees().accountReserve((*acct)[sfOwnerCount] + 1))
return tecINSUFFICIENT_RESERVE;

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

// 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
1 change: 1 addition & 0 deletions src/ripple/basics/base_uint.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ class base_uint

using uint128 = base_uint<128>;
using uint160 = base_uint<160>;
using uint192 = base_uint<192>;
using uint256 = base_uint<256>;

template <std::size_t Bits, class Tag>
Expand Down
14 changes: 7 additions & 7 deletions src/ripple/protocol/Indexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,19 @@ Keylet
did(AccountID const& account) noexcept;

Keylet
cftIssuance(AccountID const& issuer, std::uint32_t seq) noexcept;
cftIssuance(uint192 const& issuanceID) noexcept;

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

inline Keylet
cftIssuance(uint256 const& issuance)
cftoken(uint256 const& cftokenKey)
{
return {ltCFTOKEN_ISSUANCE, issuance};
return {ltNFTOKEN_OFFER, cftokenKey};
}

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

Keylet
cft_dir(uint256 const& id) noexcept;
cft_dir(uint192 const& issuanceID) noexcept;
} // namespace keylet

// Everything below is deprecated and should be removed in favor of keylets:
Expand Down
4 changes: 3 additions & 1 deletion src/ripple/protocol/SField.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ extern SF_UINT160 const sfTakerPaysIssuer;
extern SF_UINT160 const sfTakerGetsCurrency;
extern SF_UINT160 const sfTakerGetsIssuer;

// 192-bit (common)
extern SF_UINT192 const sfCFTokenIssuanceID;

// 256-bit (common)
extern SF_UINT256 const sfLedgerHash;
extern SF_UINT256 const sfParentHash;
Expand All @@ -490,7 +493,6 @@ extern SF_UINT256 const sfEmitParentTxnID;
extern SF_UINT256 const sfEmitNonce;
extern SF_UINT256 const sfEmitHookHash;
extern SF_UINT256 const sfAMMID;
extern SF_UINT256 const sfCFTokenIssuanceID;

// 256-bit (uncommon)
extern SF_UINT256 const sfBookDirectory;
Expand Down
8 changes: 8 additions & 0 deletions src/ripple/protocol/STBitString.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class STBitString final : public STBase

using STUInt128 = STBitString<128>;
using STUInt160 = STBitString<160>;
using STUInt192 = STBitString<192>;
using STUInt256 = STBitString<256>;

template <int Bits>
Expand Down Expand Up @@ -135,6 +136,13 @@ STUInt160::getSType() const
return STI_UINT160;
}

template <>
inline SerializedTypeID
STUInt192::getSType() const
{
return STI_UINT192;
}

template <>
inline SerializedTypeID
STUInt256::getSType() const
Expand Down
4 changes: 4 additions & 0 deletions src/ripple/protocol/STObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ class STObject : public STBase, public CountedObject<STObject>

uint160
getFieldH160(SField const& field) const;
uint192
getFieldH192(SField const& field) const;
uint256
getFieldH256(SField const& field) const;
AccountID
Expand Down Expand Up @@ -352,6 +354,8 @@ class STObject : public STBase, public CountedObject<STObject>
void
setFieldH128(SField const& field, uint128 const&);
void
setFieldH192(SField const& field, uint192 const&);
void
setFieldH256(SField const& field, uint256 const&);
void
setFieldVL(SField const& field, Blob const&);
Expand Down
68 changes: 68 additions & 0 deletions src/ripple/protocol/cft.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2023 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_PROTOCOL_CFT_H_INCLUDED
#define RIPPLE_PROTOCOL_CFT_H_INCLUDED

#include <ripple/basics/base_uint.h>
#include <string_view>

namespace ripple {
namespace cft {

inline std::uint32_t
getSequence(uint192 const& issuanceID)
{
std::uint32_t seq;
memcpy(&seq, issuanceID.begin(), 4);
return boost::endian::big_to_native(seq);
}

inline AccountID
getIssuer(uint192 const& issuanceID)
{
return AccountID::fromVoid(issuanceID.data() + 4);
}


inline uint192
createCFTokenIssuanceID(
std::uint32_t sequence,
AccountID const& issuer)
{
sequence = boost::endian::native_to_big(sequence);

std::array<std::uint8_t, 24> buf{};

auto ptr = buf.data();

std::memcpy(ptr, &sequence, sizeof(sequence));
ptr += sizeof(sequence);

std::memcpy(ptr, issuer.data(), issuer.size());
ptr += issuer.size();
assert(std::distance(buf.data(), ptr) == buf.size());

return uint192::fromVoid(buf.data());
}

} // namespace cft
} // namespace ripple

#endif
13 changes: 8 additions & 5 deletions src/ripple/protocol/impl/Indexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <ripple/protocol/SeqProxy.h>
#include <ripple/protocol/digest.h>
#include <ripple/protocol/nftPageMask.h>
#include <ripple/protocol/cft.h>

#include <algorithm>
#include <cassert>
Expand Down Expand Up @@ -448,23 +449,25 @@ did(AccountID const& account) noexcept
}

Keylet
cftIssuance(AccountID const& issuer, std::uint32_t seq) noexcept
cftIssuance(uint192 const& issuanceID) noexcept
{
uint32_t const sequence = cft::getSequence(issuanceID);
AccountID const issuer = cft::getIssuer(issuanceID);
return {
ltCFTOKEN_ISSUANCE,
indexHash(LedgerNameSpace::CFTOKEN_ISSUANCE, issuer, seq)};
indexHash(LedgerNameSpace::CFTOKEN_ISSUANCE, sequence, issuer)};
}

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

Keylet
cft_dir(uint256 const& id) noexcept
cft_dir(uint192 const& issuanceID) noexcept
{
return {ltDIR_NODE, indexHash(LedgerNameSpace::CFT_DIR, id)};
return {ltDIR_NODE, indexHash(LedgerNameSpace::CFT_DIR, issuanceID)};
}
} // namespace keylet

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
4 changes: 3 additions & 1 deletion src/ripple/protocol/impl/SField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ CONSTRUCT_TYPED_SFIELD(sfTakerPaysIssuer, "TakerPaysIssuer", UINT160,
CONSTRUCT_TYPED_SFIELD(sfTakerGetsCurrency, "TakerGetsCurrency", UINT160, 3);
CONSTRUCT_TYPED_SFIELD(sfTakerGetsIssuer, "TakerGetsIssuer", UINT160, 4);

// 192-bit (common)
CONSTRUCT_TYPED_SFIELD(sfCFTokenIssuanceID, "CFTokenIssuanceID", UINT192, 1);

// 256-bit (common)
CONSTRUCT_TYPED_SFIELD(sfLedgerHash, "LedgerHash", UINT256, 1);
CONSTRUCT_TYPED_SFIELD(sfParentHash, "ParentHash", UINT256, 2);
Expand All @@ -219,7 +222,6 @@ CONSTRUCT_TYPED_SFIELD(sfEmitParentTxnID, "EmitParentTxnID", UINT256,
CONSTRUCT_TYPED_SFIELD(sfEmitNonce, "EmitNonce", UINT256, 12);
CONSTRUCT_TYPED_SFIELD(sfEmitHookHash, "EmitHookHash", UINT256, 13);
CONSTRUCT_TYPED_SFIELD(sfAMMID, "AMMID", UINT256, 14);
CONSTRUCT_TYPED_SFIELD(sfCFTokenIssuanceID, "CFTokenIssuanceID", UINT256, 15);

// 256-bit (uncommon)
CONSTRUCT_TYPED_SFIELD(sfBookDirectory, "BookDirectory", UINT256, 16);
Expand Down
12 changes: 12 additions & 0 deletions src/ripple/protocol/impl/STObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,12 @@ STObject::getFieldH160(SField const& field) const
return getFieldByValue<STUInt160>(field);
}

uint192
STObject::getFieldH192(SField const& field) const
{
return getFieldByValue<STUInt192>(field);
}

uint256
STObject::getFieldH256(SField const& field) const
{
Expand Down Expand Up @@ -673,6 +679,12 @@ STObject::setFieldH128(SField const& field, uint128 const& v)
setFieldUsingSetValue<STUInt128>(field, v);
}

void
STObject::setFieldH192(SField const& field, uint192 const& v)
{
setFieldUsingSetValue<STUInt192>(field, v);
}

void
STObject::setFieldH256(SField const& field, uint256 const& v)
{
Expand Down
24 changes: 24 additions & 0 deletions src/ripple/protocol/impl/STParsedJSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,30 @@ parseLeaf(
break;
}

case STI_UINT192: {
if (!value.isString())
{
error = bad_type(json_name, fieldName);
return ret;
}

uint192 num;

if (auto const s = value.asString(); !num.parseHex(s))
{
if (!s.empty())
{
error = invalid_data(json_name, fieldName);
return ret;
}

num.zero();
}

ret = detail::make_stvar<STUInt192>(field, num);
break;
}

case STI_UINT256: {
if (!value.isString())
{
Expand Down
6 changes: 6 additions & 0 deletions src/ripple/protocol/impl/STVar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ STVar::STVar(SerialIter& sit, SField const& name, int depth)
case STI_UINT160:
construct<STUInt160>(sit, name);
return;
case STI_UINT192:
construct<STUInt192>(sit, name);
return;
case STI_UINT256:
construct<STUInt256>(sit, name);
return;
Expand Down Expand Up @@ -201,6 +204,9 @@ STVar::STVar(SerializedTypeID id, SField const& name)
case STI_UINT160:
construct<STUInt160>(name);
return;
case STI_UINT192:
construct<STUInt192>(name);
return;
case STI_UINT256:
construct<STUInt256>(name);
return;
Expand Down
7 changes: 7 additions & 0 deletions src/ripple/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ JSS(build_path); // in: TransactionSign
JSS(build_version); // out: NetworkOPs
JSS(cancel_after); // out: AccountChannels
JSS(can_delete); // out: CanDelete
JSS(cft_amount); // out: cft_holders
JSS(cft_issuance); // in: LedgerEntry, AccountObjects
JSS(cft_issuance_id); // in: 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 @@ -358,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 @@ -445,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
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
Loading
Loading