mirror of
https://github.com/XRPLF/clio.git
synced 2025-11-20 11:45:53 +00:00
feat: Add Support Credentials for Clio (#1712)
Rippled PR: [here](https://github.com/XRPLF/rippled/pull/5103)
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <xrpl/basics/Blob.h>
|
||||
#include <xrpl/basics/Slice.h>
|
||||
#include <xrpl/basics/StringUtilities.h>
|
||||
#include <xrpl/basics/base_uint.h>
|
||||
#include <xrpl/basics/chrono.h>
|
||||
#include <xrpl/json/json_value.h>
|
||||
@@ -48,6 +49,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -540,7 +542,7 @@ CreateCheckLedgerObject(std::string_view account, std::string_view dest)
|
||||
}
|
||||
|
||||
ripple::STObject
|
||||
CreateDepositPreauthLedgerObject(std::string_view account, std::string_view auth)
|
||||
CreateDepositPreauthLedgerObjectByAuth(std::string_view account, std::string_view auth)
|
||||
{
|
||||
ripple::STObject depositPreauth(ripple::sfLedgerEntry);
|
||||
depositPreauth.setFieldU16(ripple::sfLedgerEntryType, ripple::ltDEPOSIT_PREAUTH);
|
||||
@@ -553,6 +555,27 @@ CreateDepositPreauthLedgerObject(std::string_view account, std::string_view auth
|
||||
return depositPreauth;
|
||||
}
|
||||
|
||||
ripple::STObject
|
||||
CreateDepositPreauthLedgerObjectByAuthCredentials(
|
||||
std::string_view account,
|
||||
std::string_view issuer,
|
||||
std::string_view credType
|
||||
)
|
||||
{
|
||||
ripple::STObject depositPreauth(ripple::sfLedgerEntry);
|
||||
depositPreauth.setFieldU16(ripple::sfLedgerEntryType, ripple::ltDEPOSIT_PREAUTH);
|
||||
depositPreauth.setAccountID(ripple::sfAccount, GetAccountIDWithString(account));
|
||||
depositPreauth.setFieldArray(
|
||||
ripple::sfAuthorizeCredentials,
|
||||
CreateAuthCredentialArray(std::vector<std::string_view>{issuer}, std::vector<std::string_view>{credType})
|
||||
);
|
||||
depositPreauth.setFieldU32(ripple::sfFlags, 0);
|
||||
depositPreauth.setFieldU64(ripple::sfOwnerNode, 0);
|
||||
depositPreauth.setFieldH256(ripple::sfPreviousTxnID, ripple::uint256{});
|
||||
depositPreauth.setFieldU32(ripple::sfPreviousTxnLgrSeq, 0);
|
||||
return depositPreauth;
|
||||
}
|
||||
|
||||
data::NFT
|
||||
CreateNFT(std::string_view tokenID, std::string_view account, ripple::LedgerIndex seq, ripple::Blob uri, bool isBurned)
|
||||
{
|
||||
@@ -1192,3 +1215,47 @@ CreateOracleObject(
|
||||
|
||||
return ledgerObject;
|
||||
}
|
||||
|
||||
// acc2 issue credential for acc1 so acc2 is issuer
|
||||
ripple::STObject
|
||||
CreateCredentialObject(
|
||||
std::string_view acc1,
|
||||
std::string_view acc2,
|
||||
std::string_view credType,
|
||||
bool accept,
|
||||
std::optional<uint32_t> expiration
|
||||
)
|
||||
{
|
||||
ripple::STObject credObj(ripple::sfCredential);
|
||||
credObj.setFieldU16(ripple::sfLedgerEntryType, ripple::ltCREDENTIAL);
|
||||
credObj.setFieldVL(ripple::sfCredentialType, ripple::Blob{credType.begin(), credType.end()});
|
||||
credObj.setAccountID(ripple::sfSubject, GetAccountIDWithString(acc1));
|
||||
credObj.setAccountID(ripple::sfIssuer, GetAccountIDWithString(acc2));
|
||||
if (expiration.has_value())
|
||||
credObj.setFieldU32(ripple::sfExpiration, expiration.value());
|
||||
|
||||
if (accept) {
|
||||
credObj.setFieldU32(ripple::sfFlags, ripple::lsfAccepted);
|
||||
} else {
|
||||
credObj.setFieldU32(ripple::sfFlags, 0);
|
||||
}
|
||||
credObj.setFieldU64(ripple::sfSubjectNode, 0);
|
||||
credObj.setFieldU64(ripple::sfIssuerNode, 0);
|
||||
credObj.setFieldH256(ripple::sfPreviousTxnID, ripple::uint256{});
|
||||
credObj.setFieldU32(ripple::sfPreviousTxnLgrSeq, 0);
|
||||
return credObj;
|
||||
}
|
||||
|
||||
ripple::STArray
|
||||
CreateAuthCredentialArray(std::vector<std::string_view> issuer, std::vector<std::string_view> credType)
|
||||
{
|
||||
ripple::STArray arr;
|
||||
ASSERT(issuer.size() == credType.size(), "issuer and credtype vector must be same length");
|
||||
for (std::size_t i = 0; i < issuer.size(); ++i) {
|
||||
auto credential = ripple::STObject::makeInnerObject(ripple::sfCredential);
|
||||
credential.setAccountID(ripple::sfIssuer, GetAccountIDWithString(issuer[i]));
|
||||
credential.setFieldVL(ripple::sfCredentialType, ripple::strUnHex(std::string(credType[i])).value());
|
||||
arr.push_back(credential);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user