Skip to content

Commit

Permalink
FS
Browse files Browse the repository at this point in the history
  • Loading branch information
dangell7 committed Dec 15, 2023
1 parent 2d24381 commit fff33cf
Show file tree
Hide file tree
Showing 16 changed files with 499 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Builds/CMake/RippledCore.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ target_sources (rippled PRIVATE
src/ripple/app/tx/impl/DepositPreauth.cpp
src/ripple/app/tx/impl/DID.cpp
src/ripple/app/tx/impl/FSPin.cpp
src/ripple/app/tx/impl/FSNSPin.cpp
src/ripple/app/tx/impl/Escrow.cpp
src/ripple/app/tx/impl/InvariantCheck.cpp
src/ripple/app/tx/impl/NFTokenAcceptOffer.cpp
Expand Down Expand Up @@ -796,6 +797,7 @@ if (tests)
src/test/app/Flow_test.cpp
src/test/app/Freeze_test.cpp
src/test/app/FS_test.cpp
src/test/app/FSNS_test.cpp
src/test/app/HashRouter_test.cpp
src/test/app/LedgerHistory_test.cpp
src/test/app/LedgerLoad_test.cpp
Expand Down
132 changes: 132 additions & 0 deletions src/ripple/app/tx/impl/FSNSPin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 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.
*/
//==============================================================================

#include <ripple/app/tx/impl/FSNSPin.h>
#include <ripple/basics/Log.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/TxFlags.h>
#include <ripple/protocol/digest.h>

namespace ripple {

XRPAmount
FSNSPin::calculateBaseFee(ReadView const& view, STTx const& tx)
{
return Transactor::calculateBaseFee(view, tx);
}

NotTEC
FSNSPin::preflight(PreflightContext const& ctx)
{
if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
return ret;

std::uint32_t const txFlags = ctx.tx.getFlags();

if (ctx.tx.isFieldPresent(sfData))
{
auto const data = ctx.tx.getFieldVL(sfData);

if (data.size() < 1 || data.size() > 512)
{
JLOG(ctx.j.warn())
<< "Malformed transaction. Data must be at least 1 "
"character and no more than 512 characters.";
return temMALFORMED;
}
}

return preflight2(ctx);
}

TER
FSNSPin::preclaim(PreclaimContext const& ctx)
{
if (ctx.tx.isFieldPresent(sfData))
{
auto const data = ctx.tx.getFieldVL(sfData);
ripple::uint256 dataHash = ripple::sha512Half_s(
ripple::Slice(data.data(), data.size())
);

if (ctx.view.exists(keylet::fs(dataHash)))
return tecDUPLICATE;
}

return tesSUCCESS;
}

TER
FSNSPin::doApply()
{
auto const sle = view().peek(keylet::account(account_));
if (!sle)
return tefINTERNAL;

auto const nickname = ctx_.tx.getFieldH256(sfNickname);
ripple::uint256 rootIndex;
if (ctx_.tx.isFieldPresent(sfRootIndex))
{
rootIndex = ctx_.tx.getFieldH256(sfRootIndex);
}
else if (ctx_.tx.isFieldPresent(sfData))
{
auto const data = ctx_.tx.getFieldVL(sfData);
auto const dataHash = ripple::sha512Half_s(
ripple::Slice(data.data(), data.size())
);

auto const fsKeylet = keylet::fs(dataHash);
rootIndex = fsKeylet.key;
auto const sleFS = std::make_shared<SLE>(fsKeylet);

sleFS->setFieldVL(sfData, data);
(*sleFS)[sfOwner] = account_;

view().insert(sleFS);
}
else
{
// pass
}

auto const fsnsKeylet = keylet::fsns(nickname);
auto const nsSle = ctx_.view().peek(fsnsKeylet);
if (!nsSle)
{
auto const sleFSNS = std::make_shared<SLE>(fsnsKeylet);
sleFSNS->setFieldH256(sfRootIndex, rootIndex);
(*sleFSNS)[sfOwner] = account_;
view().insert(sleFSNS);
}
else
{
// if (account_ != *nsSle[sfOwner])
// {
// return tefINTERNAL;
// }
(*nsSle)[sfRootIndex] = rootIndex;
view().update(nsSle);
}

return tesSUCCESS;
}

} // namespace ripple
54 changes: 54 additions & 0 deletions src/ripple/app/tx/impl/FSNSPin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 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_TX_FSNS_PIN_H_INCLUDED
#define RIPPLE_TX_FSNS_PIN_H_INCLUDED

#include <ripple/app/tx/impl/Transactor.h>
#include <ripple/basics/Log.h>
#include <ripple/protocol/TxFlags.h>
#include <ripple/protocol/UintTypes.h>

namespace ripple {

class FSNSPin : public Transactor
{
public:
static constexpr ConsequencesFactoryType ConsequencesFactory{Blocker};

explicit FSNSPin(ApplyContext& ctx) : Transactor(ctx)
{
}

static NotTEC
preflight(PreflightContext const& ctx);

static TER
preclaim(PreclaimContext const& ctx);

static XRPAmount
calculateBaseFee(ReadView const& view, STTx const& tx);

TER
doApply() override;
};

} // namespace ripple

#endif
1 change: 1 addition & 0 deletions src/ripple/app/tx/impl/InvariantCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ LedgerEntryTypesMatch::visitEntry(
case ltXCHAIN_OWNED_CREATE_ACCOUNT_CLAIM_ID:
case ltDID:
case ltFS:
case ltFSNS:
break;
default:
invalidTypeAdded_ = true;
Expand Down
3 changes: 3 additions & 0 deletions src/ripple/app/tx/impl/applySteps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <ripple/app/tx/impl/DepositPreauth.h>
#include <ripple/app/tx/impl/Escrow.h>
#include <ripple/app/tx/impl/FSPin.h>
#include <ripple/app/tx/impl/FSNSPin.h>
#include <ripple/app/tx/impl/NFTokenAcceptOffer.h>
#include <ripple/app/tx/impl/NFTokenBurn.h>
#include <ripple/app/tx/impl/NFTokenCancelOffer.h>
Expand Down Expand Up @@ -162,6 +163,8 @@ with_txn_type(TxType txnType, F&& f)
return f.template operator()<DIDDelete>();
case ttFS_PIN:
return f.template operator()<FSPin>();
case ttFSNS_PIN:
return f.template operator()<FSNSPin>();
default:
throw UnknownTxnType(txnType);
}
Expand Down
6 changes: 3 additions & 3 deletions src/ripple/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ foreachFeature(FeatureBitset bs, F&& f)
f(bitsetIndexToFeature(i));
}

// extern uint256 const featureOwnerPaysFee;
// extern uint256 const featureFlow;
// extern uint256 const featureFlowCross;
extern uint256 const featureOwnerPaysFee;
extern uint256 const featureFlow;
extern uint256 const featureFlowCross;
extern uint256 const featureCryptoConditionsSuite;
extern uint256 const fix1513;
extern uint256 const featureDepositAuth;
Expand Down
3 changes: 3 additions & 0 deletions src/ripple/protocol/Indexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ did(AccountID const& account) noexcept;
Keylet
fs(uint256 const& id) noexcept;

Keylet
fsns(uint256 const& ns) noexcept;

} // namespace keylet

// Everything below is deprecated and should be removed in favor of keylets:
Expand Down
6 changes: 6 additions & 0 deletions src/ripple/protocol/LedgerFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ enum LedgerEntryType : std::uint16_t
*/
ltFS = 0x0046,

/** The ledger object which tracks the NS.
\sa keylet::ns
*/
ltFSNS = 0x006E,

//---------------------------------------------------------------------------
/** A special type, matching any ledger entry type.
Expand Down
3 changes: 3 additions & 0 deletions src/ripple/protocol/TxFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ enum TxType : std::uint16_t
/** This transaction type creates an FS */
ttFS_PIN = 66,

/** This transaction type creates an FSNS */
ttFSNS_PIN = 67,


/** This system-generated transaction type is used to update the status of the various amendments.
Expand Down
9 changes: 8 additions & 1 deletion src/ripple/protocol/impl/Indexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ enum class LedgerNameSpace : std::uint16_t {
XCHAIN_CREATE_ACCOUNT_CLAIM_ID = 'K',
DID = 'I',
FS = 'F',
FSNS = 'n',

// No longer used or supported. Left here to reserve the space
// to avoid accidental reuse.
CONTRACT [[deprecated]] = 'c',
GENERATOR [[deprecated]] = 'g',
NICKNAME [[deprecated]] = 'n',
// NICKNAME [[deprecated]] = 'n',
};

template <class... Args>
Expand Down Expand Up @@ -451,6 +452,12 @@ fs(uint256 const& id) noexcept
return {ltFS, indexHash(LedgerNameSpace::FS, id)};
}

Keylet
fsns(uint256 const& ns) noexcept
{
return {ltFSNS, indexHash(LedgerNameSpace::FSNS, ns)};
}

} // namespace keylet

} // namespace ripple
11 changes: 11 additions & 0 deletions src/ripple/protocol/impl/LedgerFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,17 @@ LedgerFormats::LedgerFormats()
// {sfPreviousTxnLgrSeq, soeREQUIRED}
},
commonFields);

add(jss::FSNS,
ltFSNS,
{
{sfOwner, soeREQUIRED},
{sfRootIndex, soeREQUIRED},
// {sfOwnerNode, soeREQUIRED},
// {sfPreviousTxnID, soeREQUIRED},
// {sfPreviousTxnLgrSeq, soeREQUIRED}
},
commonFields);
// clang-format on
}

Expand Down
9 changes: 9 additions & 0 deletions src/ripple/protocol/impl/TxFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ TxFormats::TxFormats()
{sfData, soeREQUIRED},
},
commonFields);

add(jss::FSNSPin,
ttFSNS_PIN,
{
{sfNickname, soeREQUIRED},
{sfRootIndex, soeOPTIONAL},
{sfData, soeOPTIONAL},
},
commonFields);
}

TxFormats const&
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 @@ -87,7 +87,9 @@ JSS(Fee); // in/out: TransactionSign; field.
JSS(FeeSettings); // ledger type.
JSS(Flags); // in/out: TransactionSign; field.
JSS(FS); // ledger type.
JSS(FSNS); // ledger type.
JSS(FSPin); // transaction type.
JSS(FSNSPin); // transaction type.
JSS(incomplete_shards); // out: OverlayImpl, PeerImp
JSS(Invalid); //
JSS(LastLedgerSequence); // in: TransactionSign; field
Expand Down Expand Up @@ -343,6 +345,7 @@ JSS(full); // in: LedgerClearer, handlers/Ledger
JSS(full_reply); // out: PathFind
JSS(fullbelow_size); // out: GetCounts
JSS(fs); // in: LedgerEntry
JSS(fsns); // in: LedgerEntry
JSS(good); // out: RPCVersion
JSS(hash); // out: NetworkOPs, InboundLedger,
// LedgerToJson, STTx; field
Expand Down
12 changes: 12 additions & 0 deletions src/ripple/rpc/handlers/LedgerEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,18 @@ doLedgerEntry(RPC::JsonContext& context)
}
}
}
else if (context.params.isMember(jss::fsns))
{
expectedType = ltFSNS;
if (!context.params[jss::fsns].isObject())
{
if (!uNodeIndex.parseHex(context.params[jss::fsns].asString()))
{
uNodeIndex = beast::zero;
jvResult[jss::error] = "malformedRequest";
}
}
}
else
{
if (context.params.isMember("params") &&
Expand Down
5 changes: 3 additions & 2 deletions src/ripple/rpc/impl/RPCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ chooseLedgerEntryType(Json::Value const& params)
std::pair<RPC::Status, LedgerEntryType> result{RPC::Status::OK, ltANY};
if (params.isMember(jss::type))
{
static constexpr std::array<std::pair<char const*, LedgerEntryType>, 21>
static constexpr std::array<std::pair<char const*, LedgerEntryType>, 22>
types{
{{jss::account, ltACCOUNT_ROOT},
{jss::amendments, ltAMENDMENTS},
Expand All @@ -957,7 +957,8 @@ chooseLedgerEntryType(Json::Value const& params)
{jss::xchain_owned_create_account_claim_id,
ltXCHAIN_OWNED_CREATE_ACCOUNT_CLAIM_ID},
{jss::did, ltDID},
{jss::fs, ltFS}}};
{jss::fs, ltFS},
{jss::fs, ltFSNS}}};

auto const& p = params[jss::type];
if (!p.isString())
Expand Down
Loading

0 comments on commit fff33cf

Please sign in to comment.