20 #include <ripple/protocol/XChainAttestations.h>
22 #include <ripple/basics/Expected.h>
23 #include <ripple/basics/Log.h>
24 #include <ripple/basics/StringUtilities.h>
25 #include <ripple/protocol/AccountID.h>
26 #include <ripple/protocol/Indexes.h>
27 #include <ripple/protocol/PublicKey.h>
28 #include <ripple/protocol/SField.h>
29 #include <ripple/protocol/STAccount.h>
30 #include <ripple/protocol/STAmount.h>
31 #include <ripple/protocol/STArray.h>
32 #include <ripple/protocol/STObject.h>
33 #include <ripple/protocol/Serializer.h>
34 #include <ripple/protocol/XChainAttestations.h>
35 #include <ripple/protocol/json_get_or_throw.h>
36 #include <ripple/protocol/jss.h>
42 namespace Attestations {
51 bool wasLockingChainSend_)
52 : attestationSignerAccount{attestationSignerAccount_}
53 , publicKey{publicKey_}
54 , signature{std::move(signature_)}
55 , sendingAccount{sendingAccount_}
56 , sendingAmount{sendingAmount_}
57 , rewardAccount{rewardAccount_}
58 , wasLockingChainSend{wasLockingChainSend_}
117 : attestationSignerAccount{Json::getOrThrow<AccountID>(
120 , publicKey{Json::getOrThrow<PublicKey>(v,
sfPublicKey)}
121 , signature{Json::getOrThrow<Buffer>(v,
sfSignature)}
122 , sendingAccount{Json::getOrThrow<AccountID>(v,
sfAccount)}
123 , sendingAmount{Json::getOrThrow<STAmount>(v,
sfAmount)}
148 bool wasLockingChainSend_,
152 attestationSignerAccount_,
154 std::move(signature_),
158 wasLockingChainSend_)
172 bool wasLockingChainSend_,
176 attestationSignerAccount_,
182 wasLockingChainSend_,
186 auto const toSign = message(bridge);
220 bool wasLockingChainSend,
284 , createCount{Json::getOrThrow<std::uint64_t>(
300 bool wasLockingChainSend_,
304 attestationSignerAccount_,
306 std::move(signature_),
310 wasLockingChainSend_)
311 , createCount{createCount_}
312 , toCreate{toCreate_}
313 , rewardAmount{rewardAmount_}
326 bool wasLockingChainSend_,
330 attestationSignerAccount_,
337 wasLockingChainSend_,
341 auto const toSign = message(bridge);
365 bool wasLockingChainSend,
435 bool wasLockingChainSend_,
437 : keyAccount(keyAccount_)
438 , publicKey(publicKey_)
440 , rewardAccount(rewardAccount_)
441 , wasLockingChainSend(wasLockingChainSend_)
451 bool wasLockingChainSend_,
457 rewardAccount_.
value(),
458 wasLockingChainSend_,
476 Json::getOrThrow<STAmount>(v,
sfAmount),
560 bool wasLockingChainSend_,
588 Json::getOrThrow<STAmount>(v,
sfAmount),
673 template <
class TAttestation>
676 : attestations_{std::move(atts)}
680 template <
class TAttestation>
681 typename XChainAttestationsBase<TAttestation>::AttCollection::const_iterator
684 return attestations_.
begin();
687 template <
class TAttestation>
691 return attestations_.
end();
694 template <
class TAttestation>
698 return attestations_.
begin();
701 template <
class TAttestation>
702 typename XChainAttestationsBase<TAttestation>::AttCollection::iterator
703 XChainAttestationsBase<TAttestation>::end()
705 return attestations_.end();
708 template <
class TAttestation>
714 Throw<std::runtime_error>(
715 "XChainAttestationsBase can only be specified with an 'object' "
719 attestations_ = [&] {
720 auto const jAtts = v[jss::attestations];
722 if (jAtts.size() > maxAttestations)
723 Throw<std::runtime_error>(
724 "XChainAttestationsBase exceeded max number of attestations");
728 for (
auto const& a : jAtts)
734 template <
class TAttestation>
737 if (arr.
size() > maxAttestations)
738 Throw<std::runtime_error>(
739 "XChainAttestationsBase exceeded max number of attestations");
741 attestations_.reserve(arr.
size());
742 for (
auto const& o : arr)
743 attestations_.emplace_back(o);
746 template <
class TAttestation>
750 STArray r{TAttestation::ArrayFieldName, attestations_.
size()};
751 for (
auto const& e : attestations_)
752 r.emplace_back(e.toSTObject());
AttestationBase(AccountID attestationSignerAccount_, PublicKey const &publicKey_, Buffer signature_, AccountID const &sendingAccount_, STAmount const &sendingAmount_, AccountID const &rewardAccount_, bool wasLockingChainSend_)
XChainCreateAccountAttestation(AccountID const &keyAccount_, PublicKey const &publicKey_, STAmount const &amount_, STAmount const &rewardAmount_, AccountID const &rewardAccount_, bool wasLockingChainSend_, AccountID const &dst_)
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
AccountID attestationSignerAccount
const SField sfGeneric(access, 0)
const SF_ACCOUNT sfDestination
std::vector< TAttestation > AttCollection
static std::vector< std::uint8_t > message(STXChainBridge const &bridge, AccountID const &sendingAccount, STAmount const &sendingAmount, AccountID const &rewardAccount, bool wasLockingChainSend, std::uint64_t claimID, std::optional< AccountID > const &dst)
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical) noexcept
Verify a signature on a message.
MatchFields(TSignedAttestation const &att)
AttestationMatch match(MatchFields const &rhs) const
void addHelper(STObject &o) const
const SField sfXChainCreateAccountAttestationCollectionElement
AttestationClaim(AccountID attestationSignerAccount_, PublicKey const &publicKey_, Buffer signature_, AccountID const &sendingAccount_, STAmount const &sendingAmount_, AccountID const &rewardAccount_, bool wasLockingChainSend_, std::uint64_t claimID_, std::optional< AccountID > const &dst_)
static SField const & ArrayFieldName
const SF_ACCOUNT sfOtherChainSource
bool validAmounts() const
AttestationCreateAccount(STObject const &o)
Like std::vector<char> but better.
bool isLegalNet(STAmount const &value)
const SF_UINT8 sfWasLockingChainSend
Json::StaticString const & getJsonName() const
std::optional< AccountID > dst
bool operator==(AttestationClaim const &lhs, AttestationClaim const &rhs)
static bool sameEventHelper(AttestationBase const &lhs, AttestationBase const &rhs)
bool operator==(Manifest const &lhs, Manifest const &rhs)
const SF_UINT64 sfXChainClaimID
AttCollection::const_iterator begin() const
bool sameEvent(AttestationClaim const &rhs) const
bool sameEvent(AttestationCreateAccount const &rhs) const
const SF_AMOUNT sfSignatureReward
const SField sfXChainClaimAttestations
virtual std::vector< std::uint8_t > message(STXChainBridge const &bridge) const =0
XChainAttestationsBase()=default
const SField sfXChainClaimProofSig
const SField sfXChainCreateAccountProofSig
const SF_ACCOUNT sfAttestationSignerAccount
std::optional< AccountID > dst
std::optional< AccountID > dst
static SField const & ArrayFieldName
std::uint64_t createCount
T emplace_back(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool validAmounts() const
AttestationMatch match(MatchFields const &rhs) const
static bool equalHelper(AttestationBase const &lhs, AttestationBase const &rhs)
MatchFields(TSignedAttestation const &att)
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &m)
Generate a signature for a message.
const SField sfXChainClaimAttestationCollectionElement
bool verify(STXChainBridge const &bridge) const
static std::vector< std::uint8_t > message(STXChainBridge const &bridge, AccountID const &sendingAccount, STAmount const &sendingAmount, STAmount const &rewardAmount, AccountID const &rewardAccount, bool wasLockingChainSend, std::uint64_t createCount, AccountID const &dst)
const SF_UINT64 sfXChainAccountCreateCount
XChainClaimAttestation(AccountID const &keyAccount_, PublicKey const &publicKey_, STAmount const &amount_, AccountID const &rewardAccount_, bool wasLockingChainSend_, std::optional< AccountID > const &dst)
friend bool operator==(XChainCreateAccountAttestation const &lhs, XChainCreateAccountAttestation const &rhs)
STObject toSTObject() const
const SField sfXChainCreateAccountAttestations
STObject toSTObject() const
const SF_ACCOUNT sfAccount
const SF_ACCOUNT sfAttestationRewardAccount
AttCollection::const_iterator end() const
AccountID const & value() const noexcept
const SF_XCHAIN_BRIDGE sfXChainBridge
STObject toSTObject() const
STObject toSTObject() const