From 055847cd585eeff5163c616ec3cdf4ab1e760cad Mon Sep 17 00:00:00 2001 From: bnogalm <18525490+bnogalm@users.noreply.github.com> Date: Mon, 11 Apr 2022 22:56:06 +0200 Subject: [PATCH 1/4] Update XDR definitions for CAP 35 Add CAP 35 Operation and Effect responses --- StellarQtSDK.pri | 10 + ...aimablebalanceclawedbackeffectresponse.cpp | 24 ++ ...claimablebalanceclawedbackeffectresponse.h | 28 +++ .../trustlineflagsupdatedeffectresponse.cpp | 118 ++++++++++ .../trustlineflagsupdatedeffectresponse.h | 81 +++++++ src/responses/effectspage.cpp | 8 + ...wbackclaimablebalanceoperationresponse.cpp | 24 ++ ...lawbackclaimablebalanceoperationresponse.h | 29 +++ .../operations/clawbackoperationresponse.cpp | 89 +++++++ .../operations/clawbackoperationresponse.h | 64 +++++ .../settrustlineflagsoperationresponse.cpp | 136 +++++++++++ .../settrustlineflagsoperationresponse.h | 88 +++++++ src/responses/response.h | 11 +- test/responses/effectdeserializertest.h | 82 ++++++- test/responses/operationdeserializertest.h | 140 ++++++++++- xdr/stellarledgerentries.h | 104 ++++++++- xdr/stellartransaction.h | 218 +++++++++++++++++- 17 files changed, 1243 insertions(+), 11 deletions(-) create mode 100644 src/responses/effects/claimablebalanceclawedbackeffectresponse.cpp create mode 100644 src/responses/effects/claimablebalanceclawedbackeffectresponse.h create mode 100644 src/responses/effects/trustlineflagsupdatedeffectresponse.cpp create mode 100644 src/responses/effects/trustlineflagsupdatedeffectresponse.h create mode 100644 src/responses/operations/clawbackclaimablebalanceoperationresponse.cpp create mode 100644 src/responses/operations/clawbackclaimablebalanceoperationresponse.h create mode 100644 src/responses/operations/clawbackoperationresponse.cpp create mode 100644 src/responses/operations/clawbackoperationresponse.h create mode 100644 src/responses/operations/settrustlineflagsoperationresponse.cpp create mode 100644 src/responses/operations/settrustlineflagsoperationresponse.h diff --git a/StellarQtSDK.pri b/StellarQtSDK.pri index 0f274f3..bd61bec 100644 --- a/StellarQtSDK.pri +++ b/StellarQtSDK.pri @@ -57,6 +57,7 @@ SOURCES += \ $$PWD/src/responses/effects/accountsponsorshipupdatedeffectresponse.cpp \ $$PWD/src/responses/effects/claimablebalanceclaimantcreatedeffectresponse.cpp \ $$PWD/src/responses/effects/claimablebalanceclaimedeffectresponse.cpp \ + $$PWD/src/responses/effects/claimablebalanceclawedbackeffectresponse.cpp \ $$PWD/src/responses/effects/claimablebalancecreatedeffectresponse.cpp \ $$PWD/src/responses/effects/claimablebalancesponsorshipcreatedeffectresponse.cpp \ $$PWD/src/responses/effects/claimablebalancesponsorshipremovedeffectresponse.cpp \ @@ -69,6 +70,7 @@ SOURCES += \ $$PWD/src/responses/effects/signersponsorshipremovedeffectresponse.cpp \ $$PWD/src/responses/effects/signersponsorshipupdatedeffectresponse.cpp \ $$PWD/src/responses/effects/trustlineauthorizedtomaintainliabilitieseffectresponse.cpp \ + $$PWD/src/responses/effects/trustlineflagsupdatedeffectresponse.cpp \ $$PWD/src/responses/effects/trustlinesponsorshipcreatedeffectresponse.cpp \ $$PWD/src/responses/effects/trustlinesponsorshipremovedeffectresponse.cpp \ $$PWD/src/responses/effects/trustlinesponsorshipupdatedeffectresponse.cpp \ @@ -76,6 +78,8 @@ SOURCES += \ $$PWD/src/responses/operations/beginsponsoringfuturereservesoperationresponse.cpp \ $$PWD/src/responses/operations/bumpsequenceoperationresponse.cpp \ $$PWD/src/responses/operations/claimclaimablebalanceoperationresponse.cpp \ + $$PWD/src/responses/operations/clawbackclaimablebalanceoperationresponse.cpp \ + $$PWD/src/responses/operations/clawbackoperationresponse.cpp \ $$PWD/src/responses/operations/createclaimablebalanceoperationresponse.cpp \ $$PWD/src/responses/operations/endsponsoringfuturereservesoperationresponse.cpp \ $$PWD/src/responses/operations/managebuyofferoperationresponse.cpp \ @@ -84,6 +88,7 @@ SOURCES += \ $$PWD/src/responses/operations/pathpaymentstrictreceiveoperationresponse.cpp \ $$PWD/src/responses/operations/pathpaymentstrictsendoperationresponse.cpp \ $$PWD/src/responses/operations/revokesponsorshipoperationresponse.cpp \ + $$PWD/src/responses/operations/settrustlineflagsoperationresponse.cpp \ $$PWD/src/revokeaccountsponsorshipoperation.cpp \ $$PWD/src/revokeclaimablebalancesponsorshipoperation.cpp \ $$PWD/src/revokedatasponsorshipoperation.cpp \ @@ -230,6 +235,7 @@ HEADERS += \ $$PWD/src/responses/effects/accountsponsorshipupdatedeffectresponse.h \ $$PWD/src/responses/effects/claimablebalanceclaimantcreatedeffectresponse.h \ $$PWD/src/responses/effects/claimablebalanceclaimedeffectresponse.h \ + $$PWD/src/responses/effects/claimablebalanceclawedbackeffectresponse.h \ $$PWD/src/responses/effects/claimablebalancecreatedeffectresponse.h \ $$PWD/src/responses/effects/claimablebalancesponsorshipcreatedeffectresponse.h \ $$PWD/src/responses/effects/claimablebalancesponsorshipremovedeffectresponse.h \ @@ -242,6 +248,7 @@ HEADERS += \ $$PWD/src/responses/effects/signersponsorshipremovedeffectresponse.h \ $$PWD/src/responses/effects/signersponsorshipupdatedeffectresponse.h \ $$PWD/src/responses/effects/trustlineauthorizedtomaintainliabilitieseffectresponse.h \ + $$PWD/src/responses/effects/trustlineflagsupdatedeffectresponse.h \ $$PWD/src/responses/effects/trustlinesponsorshipcreatedeffectresponse.h \ $$PWD/src/responses/effects/trustlinesponsorshipremovedeffectresponse.h \ $$PWD/src/responses/effects/trustlinesponsorshipupdatedeffectresponse.h \ @@ -249,6 +256,8 @@ HEADERS += \ $$PWD/src/responses/operations/beginsponsoringfuturereservesoperationresponse.h \ $$PWD/src/responses/operations/bumpsequenceoperationresponse.h \ $$PWD/src/responses/operations/claimclaimablebalanceoperationresponse.h \ + $$PWD/src/responses/operations/clawbackclaimablebalanceoperationresponse.h \ + $$PWD/src/responses/operations/clawbackoperationresponse.h \ $$PWD/src/responses/operations/createclaimablebalanceoperationresponse.h \ $$PWD/src/responses/operations/endsponsoringfuturereservesoperationresponse.h \ $$PWD/src/responses/operations/managebuyofferoperationresponse.h \ @@ -257,6 +266,7 @@ HEADERS += \ $$PWD/src/responses/operations/pathpaymentstrictreceiveoperationresponse.h \ $$PWD/src/responses/operations/pathpaymentstrictsendoperationresponse.h \ $$PWD/src/responses/operations/revokesponsorshipoperationresponse.h \ + $$PWD/src/responses/operations/settrustlineflagsoperationresponse.h \ $$PWD/src/revokeaccountsponsorshipoperation.h \ $$PWD/src/revokeclaimablebalancesponsorshipoperation.h \ $$PWD/src/revokedatasponsorshipoperation.h \ diff --git a/src/responses/effects/claimablebalanceclawedbackeffectresponse.cpp b/src/responses/effects/claimablebalanceclawedbackeffectresponse.cpp new file mode 100644 index 0000000..24f0094 --- /dev/null +++ b/src/responses/effects/claimablebalanceclawedbackeffectresponse.cpp @@ -0,0 +1,24 @@ +#include "claimablebalanceclawedbackeffectresponse.h" + +ClaimableBalanceClawedBackEffectResponse::ClaimableBalanceClawedBackEffectResponse(QNetworkReply *reply):EffectResponse(reply) +{ + +} + +ClaimableBalanceClawedBackEffectResponse::~ClaimableBalanceClawedBackEffectResponse() +{ + +} + +const QString ClaimableBalanceClawedBackEffectResponse::getBalanceID() const +{ + return m_balance_id; +} + +void ClaimableBalanceClawedBackEffectResponse::setBalanceID(const QString newBalance_id) +{ + if (m_balance_id == newBalance_id) + return; + m_balance_id = newBalance_id; + emit balanceIDChanged(); +} diff --git a/src/responses/effects/claimablebalanceclawedbackeffectresponse.h b/src/responses/effects/claimablebalanceclawedbackeffectresponse.h new file mode 100644 index 0000000..10c77fe --- /dev/null +++ b/src/responses/effects/claimablebalanceclawedbackeffectresponse.h @@ -0,0 +1,28 @@ +#ifndef CLAIMABLEBALANCECLAWEDBACKEFFECTRESPONSE_H +#define CLAIMABLEBALANCECLAWEDBACKEFFECTRESPONSE_H + +#include "effectresponse.h" + +/** + * Represents claimable_balance_clawed_back effect response. + * + * @see Effect documentation + * @see org.stellar.sdk.requests.EffectsRequestBuilder + * @see org.stellar.sdk.Server#effects() + */ +class ClaimableBalanceClawedBackEffectResponse : public EffectResponse +{ + Q_OBJECT + Q_PROPERTY(QString balance_id READ getBalanceID WRITE setBalanceID NOTIFY balanceIDChanged) + QString m_balance_id; + +public: + ClaimableBalanceClawedBackEffectResponse(QNetworkReply* reply=nullptr); + virtual ~ClaimableBalanceClawedBackEffectResponse(); + const QString getBalanceID() const; + void setBalanceID(const QString newBalance_id); +signals: + void balanceIDChanged(); +}; + +#endif // CLAIMABLEBALANCECLAWEDBACKEFFECTRESPONSE_H diff --git a/src/responses/effects/trustlineflagsupdatedeffectresponse.cpp b/src/responses/effects/trustlineflagsupdatedeffectresponse.cpp new file mode 100644 index 0000000..e52d0c9 --- /dev/null +++ b/src/responses/effects/trustlineflagsupdatedeffectresponse.cpp @@ -0,0 +1,118 @@ +#include "trustlineflagsupdatedeffectresponse.h" +#include "asset.h" +#include "keypair.h" + + +TrustlineFlagsUpdatedEffectResponse::TrustlineFlagsUpdatedEffectResponse(QNetworkReply *reply):EffectResponse(reply) + ,m_authorizedFlag(false) + ,m_authorizedToMaintainLiabilitiesFlag(false) + ,m_clawbackEnabledFlag(false) + ,m_asset(nullptr) +{ + +} + +TrustlineFlagsUpdatedEffectResponse::~TrustlineFlagsUpdatedEffectResponse() +{ + if(m_asset) + delete m_asset; +} + +Asset *TrustlineFlagsUpdatedEffectResponse::getAsset() { + if(!m_asset){ + KeyPair* issuer = KeyPair::fromAccountId(m_assetIssuer); + m_asset= Asset::createNonNativeAsset(m_assetCode, issuer); + } + return m_asset; +} + +const QString TrustlineFlagsUpdatedEffectResponse::getTrustor() const +{ + return m_trustor; +} + +void TrustlineFlagsUpdatedEffectResponse::setTrustor(const QString newTrustor) +{ + if (m_trustor == newTrustor) + return; + m_trustor = newTrustor; + emit trustorChanged(); +} + +const QString TrustlineFlagsUpdatedEffectResponse::getAssetType() const +{ + return m_assetType; +} + +void TrustlineFlagsUpdatedEffectResponse::setAssetType(const QString newAsset_type) +{ + if (m_assetType == newAsset_type) + return; + m_assetType = newAsset_type; + emit assetTypeChanged(); +} + +const QString TrustlineFlagsUpdatedEffectResponse::getAssetCode() const +{ + return m_assetCode; +} + +void TrustlineFlagsUpdatedEffectResponse::setAssetCode(const QString newAsset_code) +{ + if (m_assetCode == newAsset_code) + return; + m_assetCode = newAsset_code; + emit assetCodeChanged(); +} + +const QString TrustlineFlagsUpdatedEffectResponse::getAssetIssuer() const +{ + return m_assetIssuer; +} + +void TrustlineFlagsUpdatedEffectResponse::setAssetIssuer(const QString newAsset_issuer) +{ + if (m_assetIssuer == newAsset_issuer) + return; + m_assetIssuer = newAsset_issuer; + emit assetIssuerChanged(); +} + +bool TrustlineFlagsUpdatedEffectResponse::getAuthorized() const +{ + return m_authorizedFlag; +} + +void TrustlineFlagsUpdatedEffectResponse::setAuthorized(bool newAuthorized_flag) +{ + if (m_authorizedFlag == newAuthorized_flag) + return; + m_authorizedFlag = newAuthorized_flag; + emit authorizedChanged(); +} + +bool TrustlineFlagsUpdatedEffectResponse::getAuthorizedToMaintainLiabilities() const +{ + return m_authorizedToMaintainLiabilitiesFlag; +} + +void TrustlineFlagsUpdatedEffectResponse::setAuthorizedToMaintainLiabilities(bool newAuthorized_to_maintain_liabilities_flag) +{ + if (m_authorizedToMaintainLiabilitiesFlag == newAuthorized_to_maintain_liabilities_flag) + return; + m_authorizedToMaintainLiabilitiesFlag = newAuthorized_to_maintain_liabilities_flag; + emit authorizedToMaintainLiabilitiesChanged(); +} + +bool TrustlineFlagsUpdatedEffectResponse::getClawbackEnabled() const +{ + return m_clawbackEnabledFlag; +} + +void TrustlineFlagsUpdatedEffectResponse::setClawbackEnabled(bool newClawback_enabled_flag) +{ + if (m_clawbackEnabledFlag == newClawback_enabled_flag) + return; + m_clawbackEnabledFlag = newClawback_enabled_flag; + emit clawbackEnabledChanged(); +} diff --git a/src/responses/effects/trustlineflagsupdatedeffectresponse.h b/src/responses/effects/trustlineflagsupdatedeffectresponse.h new file mode 100644 index 0000000..33af2e5 --- /dev/null +++ b/src/responses/effects/trustlineflagsupdatedeffectresponse.h @@ -0,0 +1,81 @@ +#ifndef TRUSTLINEFLAGSUPDATEDEFFECTRESPONSE_H +#define TRUSTLINEFLAGSUPDATEDEFFECTRESPONSE_H + +#include "effectresponse.h" + + +class Asset; +/** + * Represents trustline_flags_updated effect response. + * + * @see Effect documentation + * @see org.stellar.sdk.requests.EffectsRequestBuilder + * @see org.stellar.sdk.Server#effects() + */ +class TrustlineFlagsUpdatedEffectResponse : public EffectResponse +{ + Q_OBJECT + + Q_PROPERTY(QString trustor READ getTrustor WRITE setTrustor NOTIFY trustorChanged) + Q_PROPERTY(QString asset_type READ getAssetType WRITE setAssetType NOTIFY assetTypeChanged) + Q_PROPERTY(QString asset_code READ getAssetCode WRITE setAssetCode NOTIFY assetCodeChanged) + Q_PROPERTY(QString asset_issuer READ getAssetIssuer WRITE setAssetIssuer NOTIFY assetIssuerChanged) + + Q_PROPERTY(bool authorized_flag READ getAuthorized WRITE setAuthorized NOTIFY authorizedChanged) + Q_PROPERTY(bool authorized_to_maintain_liabilities_flag READ getAuthorizedToMaintainLiabilities WRITE setAuthorizedToMaintainLiabilities NOTIFY authorizedToMaintainLiabilitiesChanged) + Q_PROPERTY(bool clawback_enabled_flag READ getClawbackEnabled WRITE setClawbackEnabled NOTIFY clawbackEnabledChanged) + + + QString m_trustor; + + QString m_assetType; + + QString m_assetCode; + + QString m_assetIssuer; + + bool m_authorizedFlag; + + bool m_authorizedToMaintainLiabilitiesFlag; + + bool m_clawbackEnabledFlag; + + + Asset* m_asset; +public: + TrustlineFlagsUpdatedEffectResponse(QNetworkReply *reply=nullptr); + virtual ~TrustlineFlagsUpdatedEffectResponse(); + + + Asset* getAsset(); + const QString getTrustor() const; + void setTrustor(const QString newTrustor); + const QString getAssetType() const; + void setAssetType(const QString newAsset_type); + + const QString getAssetCode() const; + void setAssetCode(const QString newAsset_code); + + const QString getAssetIssuer() const; + void setAssetIssuer(const QString newAsset_issuer); + + bool getAuthorized() const; + void setAuthorized(bool newAuthorized_flag); + + bool getAuthorizedToMaintainLiabilities() const; + void setAuthorizedToMaintainLiabilities(bool newAuthorized_to_maintain_liabilities_flag); + + bool getClawbackEnabled() const; + void setClawbackEnabled(bool newClawback_enabled_flag); + +signals: + void trustorChanged(); + void assetTypeChanged(); + void assetCodeChanged(); + void assetIssuerChanged(); + void authorizedChanged(); + void authorizedToMaintainLiabilitiesChanged(); + void clawbackEnabledChanged(); +}; + +#endif // TRUSTLINEFLAGSUPDATEDEFFECTRESPONSE_H diff --git a/src/responses/effectspage.cpp b/src/responses/effectspage.cpp index e4cf4cf..d138cf6 100644 --- a/src/responses/effectspage.cpp +++ b/src/responses/effectspage.cpp @@ -48,6 +48,10 @@ #include "effects/signersponsorshipcreatedeffectresponse.h" #include "effects/signersponsorshipremovedeffectresponse.h" #include "effects/signersponsorshipupdatedeffectresponse.h" +#include "effects/trustlineflagsupdatedeffectresponse.h" +#include "effects/claimablebalanceclawedbackeffectresponse.h" + + EffectsPage::EffectsPage(QNetworkReply *reply) :Page(reply) { @@ -99,6 +103,8 @@ void EffectsPage::processRecords(const QJsonArray &records) effect= new TrustlineDeauthorizedEffectResponse();break; case 25: effect= new TrustlineAuthorizedToMaintainLiabilitiesEffectResponse();break; + case 26: + effect= new TrustlineFlagsUpdatedEffectResponse();break; // Trading effects case 30: @@ -156,6 +162,8 @@ void EffectsPage::processRecords(const QJsonArray &records) effect= new SignerSponsorshipUpdatedEffectResponse();break; case 74: effect= new SignerSponsorshipRemovedEffectResponse();break; + case 80: + effect= new ClaimableBalanceClawedBackEffectResponse();break; default: throw std::runtime_error("Invalid effect type"); } diff --git a/src/responses/operations/clawbackclaimablebalanceoperationresponse.cpp b/src/responses/operations/clawbackclaimablebalanceoperationresponse.cpp new file mode 100644 index 0000000..d185e73 --- /dev/null +++ b/src/responses/operations/clawbackclaimablebalanceoperationresponse.cpp @@ -0,0 +1,24 @@ +#include "clawbackclaimablebalanceoperationresponse.h" + +ClawbackClaimableBalanceOperationResponse::ClawbackClaimableBalanceOperationResponse(QNetworkReply *reply):OperationResponse(reply) +{ + +} + +ClawbackClaimableBalanceOperationResponse::~ClawbackClaimableBalanceOperationResponse() +{ + +} + +const QString ClawbackClaimableBalanceOperationResponse::getBalanceID() const +{ + return m_balanceId; +} + +void ClawbackClaimableBalanceOperationResponse::setBalanceID(const QString newBalance_id) +{ + if (m_balanceId == newBalance_id) + return; + m_balanceId = newBalance_id; + emit balanceIDChanged(); +} diff --git a/src/responses/operations/clawbackclaimablebalanceoperationresponse.h b/src/responses/operations/clawbackclaimablebalanceoperationresponse.h new file mode 100644 index 0000000..2280d1e --- /dev/null +++ b/src/responses/operations/clawbackclaimablebalanceoperationresponse.h @@ -0,0 +1,29 @@ +#ifndef CLAWBACKCLAIMABLEBALANCEOPERATIONRESPONSE_H +#define CLAWBACKCLAIMABLEBALANCEOPERATIONRESPONSE_H + +#include "operationresponse.h" + + +/** + * Represents a Clawback Claimable Balance operation response. + * + * @see org.stellar.sdk.requests.OperationsRequestBuilder + * @see org.stellar.sdk.Server#operations() + */ +class ClawbackClaimableBalanceOperationResponse : public OperationResponse +{ + Q_OBJECT + + Q_PROPERTY(QString balance_id READ getBalanceID WRITE setBalanceID NOTIFY balanceIDChanged) + QString m_balanceId; + +public: + ClawbackClaimableBalanceOperationResponse(QNetworkReply* reply=nullptr); + virtual ~ClawbackClaimableBalanceOperationResponse(); + const QString getBalanceID() const; + void setBalanceID(const QString newBalance_id); +signals: + void balanceIDChanged(); +}; + +#endif // CLAWBACKCLAIMABLEBALANCEOPERATIONRESPONSE_H diff --git a/src/responses/operations/clawbackoperationresponse.cpp b/src/responses/operations/clawbackoperationresponse.cpp new file mode 100644 index 0000000..8ef7cf0 --- /dev/null +++ b/src/responses/operations/clawbackoperationresponse.cpp @@ -0,0 +1,89 @@ +#include "clawbackoperationresponse.h" +#include "keypair.h" +#include "asset.h" + +ClawbackOperationResponse::ClawbackOperationResponse(QNetworkReply *reply):OperationResponse(reply), m_asset(nullptr) +{ + +} + +ClawbackOperationResponse::~ClawbackOperationResponse() +{ + + if(m_asset) + delete m_asset; +} + +const QString ClawbackOperationResponse::getAssetType() const +{ + return m_assetType; +} + +void ClawbackOperationResponse::setAssetType(const QString newAsset_type) +{ + if (m_assetType == newAsset_type) + return; + m_assetType = newAsset_type; + emit assetTypeChanged(); +} + +const QString ClawbackOperationResponse::getAssetCode() const +{ + return m_assetCode; +} + +void ClawbackOperationResponse::setAssetCode(const QString newAsset_code) +{ + if (m_assetCode == newAsset_code) + return; + m_assetCode = newAsset_code; + emit assetCodeChanged(); +} + +const QString ClawbackOperationResponse::getAssetIssuer() const +{ + return m_assetIssuer; +} + +void ClawbackOperationResponse::setAssetIssuer(const QString newAsset_issuer) +{ + if (m_assetIssuer == newAsset_issuer) + return; + m_assetIssuer = newAsset_issuer; + emit assetIssuerChanged(); +} + +const QString ClawbackOperationResponse::getAmount() const +{ + return m_amount; +} + +void ClawbackOperationResponse::setAmount(const QString newAmount) +{ + if (m_amount == newAmount) + return; + m_amount = newAmount; + emit amountChanged(); +} + +const QString ClawbackOperationResponse::getFrom() const +{ + return m_from; +} + +void ClawbackOperationResponse::setFrom(const QString newFrom) +{ + if (m_from == newFrom) + return; + m_from = newFrom; + emit fromChanged(); +} + +Asset *ClawbackOperationResponse::getAsset() +{ + if(!m_asset){ + KeyPair* issuer = KeyPair::fromAccountId(m_assetIssuer); + m_asset= Asset::createNonNativeAsset(m_assetCode, issuer); + } + return m_asset; +} diff --git a/src/responses/operations/clawbackoperationresponse.h b/src/responses/operations/clawbackoperationresponse.h new file mode 100644 index 0000000..22878e7 --- /dev/null +++ b/src/responses/operations/clawbackoperationresponse.h @@ -0,0 +1,64 @@ +#ifndef CLAWBACKOPERATIONRESPONSE_H +#define CLAWBACKOPERATIONRESPONSE_H + +#include "operationresponse.h" + + +class Asset; + +/** + * Represents a Clawback operation response. + * + * @see org.stellar.sdk.requests.OperationsRequestBuilder + * @see org.stellar.sdk.Server#operations() + */ +class ClawbackOperationResponse : public OperationResponse +{ + Q_OBJECT + + Q_PROPERTY(QString asset_type READ getAssetType WRITE setAssetType NOTIFY assetTypeChanged) + Q_PROPERTY(QString asset_code READ getAssetCode WRITE setAssetCode NOTIFY assetCodeChanged) + Q_PROPERTY(QString asset_issuer READ getAssetIssuer WRITE setAssetIssuer NOTIFY assetIssuerChanged) + Q_PROPERTY(QString amount READ getAmount WRITE setAmount NOTIFY amountChanged) + Q_PROPERTY(QString from READ getFrom WRITE setFrom NOTIFY fromChanged) + + + QString m_assetType; + + QString m_assetCode; + + QString m_assetIssuer; + + QString m_amount; + + QString m_from; + + Asset* m_asset; + +public: + ClawbackOperationResponse(QNetworkReply* reply=nullptr); + virtual ~ClawbackOperationResponse(); + const QString getAssetType() const; + void setAssetType(const QString newAsset_type); + const QString getAssetCode() const; + void setAssetCode(const QString newAsset_code); + + const QString getAssetIssuer() const; + void setAssetIssuer(const QString newAsset_issuer); + + const QString getAmount() const; + void setAmount(const QString newAmount); + + const QString getFrom() const; + void setFrom(const QString newFrom); + + Asset* getAsset(); +signals: + void assetTypeChanged(); + void assetCodeChanged(); + void assetIssuerChanged(); + void amountChanged(); + void fromChanged(); +}; + +#endif // CLAWBACKOPERATIONRESPONSE_H diff --git a/src/responses/operations/settrustlineflagsoperationresponse.cpp b/src/responses/operations/settrustlineflagsoperationresponse.cpp new file mode 100644 index 0000000..4cb8640 --- /dev/null +++ b/src/responses/operations/settrustlineflagsoperationresponse.cpp @@ -0,0 +1,136 @@ +#include "settrustlineflagsoperationresponse.h" +#include "keypair.h" +#include "asset.h" +#include + +static void registerTypes() +{ + qRegisterMetaType >(); + QMetaType::registerConverter >(&ResponseConverters::convertPlain); +} + +Q_COREAPP_STARTUP_FUNCTION(registerTypes) + +SetTrustLineFlagsOperationResponse::SetTrustLineFlagsOperationResponse(QNetworkReply *reply):OperationResponse(reply), m_asset(nullptr) +{ + +} + +SetTrustLineFlagsOperationResponse::~SetTrustLineFlagsOperationResponse() +{ + if(m_asset) + delete m_asset; +} + +const QString SetTrustLineFlagsOperationResponse::getAssetType() const +{ + return m_assetType; +} + +void SetTrustLineFlagsOperationResponse::setAssetType(const QString newAsset_type) +{ + if (m_assetType == newAsset_type) + return; + m_assetType = newAsset_type; + emit assetTypeChanged(); +} + +const QString SetTrustLineFlagsOperationResponse::getAssetCode() const +{ + return m_assetCode; +} + +void SetTrustLineFlagsOperationResponse::setAssetCode(const QString newAsset_code) +{ + if (m_assetCode == newAsset_code) + return; + m_assetCode = newAsset_code; + emit assetCodeChanged(); +} + +const QString SetTrustLineFlagsOperationResponse::getAssetIssuer() const +{ + return m_assetIssuer; +} + +void SetTrustLineFlagsOperationResponse::setAssetIssuer(const QString newAsset_issuer) +{ + if (m_assetIssuer == newAsset_issuer) + return; + m_assetIssuer = newAsset_issuer; + emit assetIssuerChanged(); +} + +const QList SetTrustLineFlagsOperationResponse::getClearFlags() const +{ + return m_clearFlags; +} + +void SetTrustLineFlagsOperationResponse::setClearFlags(const QList newClear_flags) +{ + if (m_clearFlags == newClear_flags) + return; + m_clearFlags = newClear_flags; + emit clearFlagsChanged(); +} + +const QStringList SetTrustLineFlagsOperationResponse::getClearFlagStrings() const +{ + return m_clearFlagsS; +} + +void SetTrustLineFlagsOperationResponse::setClearFlagStrings(const QStringList newClear_flags_s) +{ + if (m_clearFlagsS == newClear_flags_s) + return; + m_clearFlagsS = newClear_flags_s; + emit clearFlagStringsChanged(); +} + +const QList SetTrustLineFlagsOperationResponse::getSetFlags() const +{ + return m_setFlags; +} + +void SetTrustLineFlagsOperationResponse::setSetFlags(const QList newSet_flags) +{ + if (m_setFlags == newSet_flags) + return; + m_setFlags = newSet_flags; + emit setFlagsChanged(); +} + +const QStringList SetTrustLineFlagsOperationResponse::getSetFlagStrings() const +{ + return m_setFlagsS; +} + +void SetTrustLineFlagsOperationResponse::setSetFlagStrings(const QStringList newSet_flags_s) +{ + if (m_setFlagsS == newSet_flags_s) + return; + m_setFlagsS = newSet_flags_s; + emit setFlagStringsChanged(); +} + +const QString SetTrustLineFlagsOperationResponse::getTrustor() const +{ + return m_trustor; +} + +void SetTrustLineFlagsOperationResponse::setTrustor(const QString newTrustor) +{ + if (m_trustor == newTrustor) + return; + m_trustor = newTrustor; + emit trustorChanged(); +} + +Asset *SetTrustLineFlagsOperationResponse::getAsset() +{ + if(!m_asset){ + KeyPair* issuer = KeyPair::fromAccountId(m_assetIssuer); + m_asset= Asset::createNonNativeAsset(m_assetCode, issuer); + } + return m_asset; +} diff --git a/src/responses/operations/settrustlineflagsoperationresponse.h b/src/responses/operations/settrustlineflagsoperationresponse.h new file mode 100644 index 0000000..7752af2 --- /dev/null +++ b/src/responses/operations/settrustlineflagsoperationresponse.h @@ -0,0 +1,88 @@ +#ifndef SETTRUSTLINEFLAGSOPERATIONRESPONSE_H +#define SETTRUSTLINEFLAGSOPERATIONRESPONSE_H + +#include "operationresponse.h" + + +class Asset; +/** + * Represents a Set Trustine Flags operation response. + * + * @see org.stellar.sdk.requests.OperationsRequestBuilder + * @see org.stellar.sdk.Server#operations() + */ +class SetTrustLineFlagsOperationResponse : public OperationResponse +{ + Q_OBJECT + + Q_PROPERTY(QString asset_type READ getAssetType WRITE setAssetType NOTIFY assetTypeChanged) + Q_PROPERTY(QString asset_code READ getAssetCode WRITE setAssetCode NOTIFY assetCodeChanged) + Q_PROPERTY(QString asset_issuer READ getAssetIssuer WRITE setAssetIssuer NOTIFY assetIssuerChanged) + + + Q_PROPERTY(QList clear_flags READ getClearFlags WRITE setClearFlags NOTIFY clearFlagsChanged) + Q_PROPERTY(QStringList clear_flags_s READ getClearFlagStrings WRITE setClearFlagStrings NOTIFY clearFlagStringsChanged) + Q_PROPERTY(QList set_flags READ getSetFlags WRITE setSetFlags NOTIFY setFlagsChanged) + Q_PROPERTY(QStringList set_flags_s READ getSetFlagStrings WRITE setSetFlagStrings NOTIFY setFlagStringsChanged) + + Q_PROPERTY(QString trustor READ getTrustor WRITE setTrustor NOTIFY trustorChanged) + + + QString m_assetType; + + QString m_assetCode; + + QString m_assetIssuer; + + QList m_clearFlags; + + QList m_clearFlagsS; + + QList m_setFlags; + + QList m_setFlagsS; + + QString m_trustor; + + Asset* m_asset; +public: + SetTrustLineFlagsOperationResponse(QNetworkReply* reply=nullptr); + virtual ~SetTrustLineFlagsOperationResponse(); + + const QString getAssetType() const; + void setAssetType(const QString newAsset_type); + + const QString getAssetCode() const; + void setAssetCode(const QString newAsset_code); + + const QString getAssetIssuer() const; + void setAssetIssuer(const QString newAsset_issuer); + + const QList getClearFlags() const; + void setClearFlags(const QList newClear_flags); + + const QStringList getClearFlagStrings() const; + void setClearFlagStrings(const QStringList newClear_flags_s); + + const QList getSetFlags() const; + void setSetFlags(const QList newSet_flags); + + const QStringList getSetFlagStrings() const; + void setSetFlagStrings(const QStringList newSet_flags_s); + + const QString getTrustor() const; + void setTrustor(const QString newTrustor); + + Asset* getAsset(); +signals: + void assetTypeChanged(); + void assetCodeChanged(); + void assetIssuerChanged(); + void clearFlagsChanged(); + void clearFlagStringsChanged(); + void setFlagsChanged(); + void setFlagStringsChanged(); + void trustorChanged(); +}; + +#endif // SETTRUSTLINEFLAGSOPERATIONRESPONSE_H diff --git a/src/responses/response.h b/src/responses/response.h index 072709b..a28ae43 100644 --- a/src/responses/response.h +++ b/src/responses/response.h @@ -12,7 +12,7 @@ inline QList convert(QVariantList source) for(int n = 0;n=T::staticMetaObject.propertyOffset()){ @@ -25,6 +25,15 @@ inline QList convert(QVariantList source) } return res; } +template +inline QList convertPlain(QVariantList source) +{ + QList res; + for(int n = 0;n()); + } + return res; +} } diff --git a/test/responses/effectdeserializertest.h b/test/responses/effectdeserializertest.h index dea3c05..3d0c91b 100644 --- a/test/responses/effectdeserializertest.h +++ b/test/responses/effectdeserializertest.h @@ -34,11 +34,12 @@ #include "../../src/responses/effects/dataupdatedeffectresponse.h" #include "../../src/responses/effects/tradeeffectresponse.h" #include "../../src/responses/effects/sequencebumpedeffectresponse.h" +#include "../../src/responses/effects/claimablebalanceclawedbackeffectresponse.h" +#include "../../src/responses/effects/trustlineflagsupdatedeffectresponse.h" #include "../../src/asset.h" #include "../../src/assettypenative.h" - - #include "../../src/keypair.h" + class EffectDeserializerTest: public QObject { Q_OBJECT @@ -852,6 +853,83 @@ private slots: QCOMPARE(effect.getCreatedAt(), "2018-06-06T10:23:57Z"); QCOMPARE(effect.getNewSequence(), 79473726952833048L); } + + + void testDeserializeClaimableBalanceClawedbackEffect() { + QByteArray json = "{\n" + " \"_links\": {\n" + " \"operation\": {\n" + " \"href\": \"https://horizon-testnet.stellar.org/operations/40181480638386177\"\n" + " },\n" + " \"succeeds\": {\n" + " \"href\": \"https://horizon-testnet.stellar.org/effects?order=desc&cursor=40181480638386177-1\"\n" + " },\n" + " \"precedes\": {\n" + " \"href\": \"https://horizon-testnet.stellar.org/effects?order=asc&cursor=40181480638386177-1\"\n" + " }\n" + " },\n" + " \"id\": \"0040181480638386177-0000000001\",\n" + " \"paging_token\": \"40181480638386177-1\",\n" + " \"account\": \"GDPFGP4IPE5DXG6XRXC4ZBUI43PAGRQ5VVNJ3LJTBXDBZ4ITO6HBHNSF\",\n" + " \"type\": \"claimable_balance_clawed_back\",\n" + " \"type_i\": 80,\n" + " \"balance_id\": \"00000000178826fbfe339e1f5c53417c6fedfe2c05e8bec14303143ec46b38981b09c3f9\",\n" + " \"created_at\": \"2018-06-06T10:23:57Z\"\n" + " }"; + + ClaimableBalanceClawedBackEffectResponse effect; + effect.loadFromJson(json); + + QCOMPARE(effect.getAccount(), QString("GDPFGP4IPE5DXG6XRXC4ZBUI43PAGRQ5VVNJ3LJTBXDBZ4ITO6HBHNSF")); + QCOMPARE(effect.getCreatedAt(), QString("2018-06-06T10:23:57Z")); + QCOMPARE(effect.getBalanceID(), QString("00000000178826fbfe339e1f5c53417c6fedfe2c05e8bec14303143ec46b38981b09c3f9")); + QCOMPARE(effect.getType(), QString("claimable_balance_clawed_back")); + } + + void testDeserializeTrustlineFlagsUpdatedEffect() { + QByteArray json = "{\n" + " \"_links\": {\n" + " \"operation\": {\n" + " \"href\": \"https://horizon-testnet.stellar.org/operations/40181480638386177\"\n" + " },\n" + " \"succeeds\": {\n" + " \"href\": \"https://horizon-testnet.stellar.org/effects?order=desc&cursor=40181480638386177-1\"\n" + " },\n" + " \"precedes\": {\n" + " \"href\": \"https://horizon-testnet.stellar.org/effects?order=asc&cursor=40181480638386177-1\"\n" + " }\n" + " },\n" + " \"id\": \"0040181480638386177-0000000001\",\n" + " \"paging_token\": \"40181480638386177-1\",\n" + " \"account\": \"GDPFGP4IPE5DXG6XRXC4ZBUI43PAGRQ5VVNJ3LJTBXDBZ4ITO6HBHNSF\",\n" + " \"type\": \"trustline_flags_updated\",\n" + " \"type_i\": 26,\n" + " \"trustor\": \"GCVHDLN6EHZBYW2M3BQIY32C23E4GPIRZZDBNF2Q73DAZ5VJDRGSMYRB\",\n" + " \"asset_type\": \"credit_alphanum4\",\n" + " \"asset_code\": \"EUR\",\n" + " \"asset_issuer\": \"GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS\",\n" + " \"authorized_flag\": true,\n" + " \"clawback_enabled_flag\": true,\n" + " \"created_at\": \"2018-06-06T10:23:57Z\"\n" + " }"; + + TrustlineFlagsUpdatedEffectResponse effect; + effect.loadFromJson(json); + + QCOMPARE(effect.getType(), "trustline_flags_updated"); + + QCOMPARE(effect.getAccount(), QString("GDPFGP4IPE5DXG6XRXC4ZBUI43PAGRQ5VVNJ3LJTBXDBZ4ITO6HBHNSF")); + QCOMPARE(effect.getCreatedAt(), QString("2018-06-06T10:23:57Z")); + QCOMPARE(effect.getTrustor(), QString("GCVHDLN6EHZBYW2M3BQIY32C23E4GPIRZZDBNF2Q73DAZ5VJDRGSMYRB")); + QVERIFY(effect.getAuthorized()); + QVERIFY(effect.getClawbackEnabled()); + QVERIFY(!effect.getAuthorizedToMaintainLiabilities()); + + QVERIFY(effect.getAsset()->equals(Asset::createNonNativeAsset("EUR", QString("GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS")))); + QCOMPARE(effect.getAssetIssuer(), QString("GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS")); + QCOMPARE(effect.getAssetCode(), QString("EUR")); + QCOMPARE(effect.getAssetType(), QString("credit_alphanum4")); + } }; ADD_TEST(EffectDeserializerTest) diff --git a/test/responses/operationdeserializertest.h b/test/responses/operationdeserializertest.h index 95d9287..cca5efc 100644 --- a/test/responses/operationdeserializertest.h +++ b/test/responses/operationdeserializertest.h @@ -22,8 +22,12 @@ #include "../../src/responses/operations/managesellofferoperationresponse.h" #include "../../src/responses/operations/managebuyofferoperationresponse.h" #include "../../src/responses/operations/bumpsequenceoperationresponse.h" -#include "../../src/responses/genericoperation.h" +#include "../../src/responses/operations/clawbackclaimablebalanceoperationresponse.h" +#include "../../src/responses/operations/clawbackoperationresponse.h" +#include "../../src/responses/operations/settrustlineflagsoperationresponse.h" + +#include "../../src/responses/genericoperation.h" #include "../../src/asset.h" #include "../../src/assettypenative.h" @@ -985,6 +989,140 @@ private slots: QCOMPARE(operation.getBumpTo(), 79473726952833048L); } + void testDeserializeClawbackClaimableBalanceOperation() { + QByteArray json = "{\n" + " \"_links\": {\n" + " \"effects\": {\n" + " \"href\": \"/operations/12884914177/effects/{?cursor,limit,order}\",\n" + " \"templated\": true\n" + " },\n" + " \"precedes\": {\n" + " \"href\": \"/operations?cursor=12884914177\\u0026order=asc\"\n" + " },\n" + " \"self\": {\n" + " \"href\": \"/operations/12884914177\"\n" + " },\n" + " \"succeeds\": {\n" + " \"href\": \"/operations?cursor=12884914177\\u0026order=desc\"\n" + " },\n" + " \"transaction\": {\n" + " \"href\": \"/transactions/12884914176\"\n" + " }\n" + " },\n" + " \"id\": 12884914177,\n" + " \"paging_token\": \"12884914177\",\n" + " \"type_i\": 20,\n" + " \"type\": \"clawback_claimable_balance\",\n" + " \"balance_id\": \"00000000178826fbfe339e1f5c53417c6fedfe2c05e8bec14303143ec46b38981b09c3f9\"\n" + "}"; + + ClawbackClaimableBalanceOperationResponse operation; + operation.loadFromJson(json); + + QCOMPARE(operation.getId(), 12884914177L); + QCOMPARE(operation.getBalanceID(), "00000000178826fbfe339e1f5c53417c6fedfe2c05e8bec14303143ec46b38981b09c3f9"); + QCOMPARE(operation.getType(), "clawback_claimable_balance"); + } + + void testDeserializeClawbackOperation() { + QByteArray json = "{\n" + " \"_links\": {\n" + " \"effects\": {\n" + " \"href\": \"/operations/12884914177/effects/{?cursor,limit,order}\",\n" + " \"templated\": true\n" + " },\n" + " \"precedes\": {\n" + " \"href\": \"/operations?cursor=12884914177\\u0026order=asc\"\n" + " },\n" + " \"self\": {\n" + " \"href\": \"/operations/12884914177\"\n" + " },\n" + " \"succeeds\": {\n" + " \"href\": \"/operations?cursor=12884914177\\u0026order=desc\"\n" + " },\n" + " \"transaction\": {\n" + " \"href\": \"/transactions/12884914176\"\n" + " }\n" + " },\n" + " \"id\": 12884914177,\n" + " \"paging_token\": \"12884914177\",\n" + " \"type_i\": 19,\n" + " \"type\": \"clawback\",\n" + " \"asset_type\": \"credit_alphanum4\",\n" + " \"asset_code\": \"EUR\",\n" + " \"asset_issuer\": \"GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS\",\n" + " \"from\": \"GDPFGP4IPE5DXG6XRXC4ZBUI43PAGRQ5VVNJ3LJTBXDBZ4ITO6HBHNSF\"\n" + "}"; + + ClawbackOperationResponse operation; + operation.loadFromJson(json); + + QCOMPARE(operation.getId(), 12884914177L); + QCOMPARE(operation.getFrom(), "GDPFGP4IPE5DXG6XRXC4ZBUI43PAGRQ5VVNJ3LJTBXDBZ4ITO6HBHNSF"); + QCOMPARE(operation.getType(), "clawback"); + QVERIFY(operation.getAsset()->equals(Asset::createNonNativeAsset("EUR", "GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS"))); + QCOMPARE(operation.getAssetIssuer(), "GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS"); + QCOMPARE(operation.getAssetCode(), "EUR"); + QCOMPARE(operation.getAssetType(), "credit_alphanum4"); + } + + void testDeserializeSetTrustlineFlagsOperation() { + QByteArray json = "{\n" + " \"_links\": {\n" + " \"effects\": {\n" + " \"href\": \"/operations/12884914177/effects/{?cursor,limit,order}\",\n" + " \"templated\": true\n" + " },\n" + " \"precedes\": {\n" + " \"href\": \"/operations?cursor=12884914177\\u0026order=asc\"\n" + " },\n" + " \"self\": {\n" + " \"href\": \"/operations/12884914177\"\n" + " },\n" + " \"succeeds\": {\n" + " \"href\": \"/operations?cursor=12884914177\\u0026order=desc\"\n" + " },\n" + " \"transaction\": {\n" + " \"href\": \"/transactions/12884914176\"\n" + " }\n" + " },\n" + " \"id\": 12884914177,\n" + " \"paging_token\": \"12884914177\",\n" + " \"type_i\": 21,\n" + " \"type\": \"set_trust_line_flags\",\n" + " \"asset_type\": \"credit_alphanum4\",\n" + " \"asset_code\": \"EUR\",\n" + " \"asset_issuer\": \"GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS\",\n" + " \"set_flags\": [\n" + " 4\n" + " ]," + " \"clear_flags\": [\n" + " 2\n" + " ]," + " \"set_flags_s\": [\n" + " \"clawback_enabled\"\n" + " ]," + " \"clear_flags_s\": [\n" + " \"authorized_to_maintain_liabilites\"\n" + " ]," + " \"trustor\": \"GDPFGP4IPE5DXG6XRXC4ZBUI43PAGRQ5VVNJ3LJTBXDBZ4ITO6HBHNSF\"\n" + "}"; + + SetTrustLineFlagsOperationResponse operation; + operation.loadFromJson(json); + + QCOMPARE(operation.getId(), 12884914177L); + QCOMPARE(operation.getTrustor(), "GDPFGP4IPE5DXG6XRXC4ZBUI43PAGRQ5VVNJ3LJTBXDBZ4ITO6HBHNSF"); + QCOMPARE(operation.getType(), "set_trust_line_flags"); + QVERIFY(operation.getAsset()->equals(Asset::createNonNativeAsset("EUR", "GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS"))); + QCOMPARE(operation.getAssetIssuer(), "GCWVFBJ24754I5GXG4JOEB72GJCL3MKWC7VAEYWKGQHPVH3ENPNBSKWS"); + QCOMPARE(operation.getAssetCode(), "EUR"); + QCOMPARE(operation.getAssetType(), "credit_alphanum4"); + QCOMPARE(operation.getSetFlags(), QList() << 4); + QCOMPARE(operation.getClearFlags(), QList() << 2); + QCOMPARE(operation.getSetFlagStrings(), QStringList() << "clawback_enabled"); + QCOMPARE(operation.getClearFlagStrings(), QStringList()<< "authorized_to_maintain_liabilites"); + } }; ADD_TEST(OperationDeserializerTest) #endif // OPERATIONDESERIALIZERTEST_H diff --git a/xdr/stellarledgerentries.h b/xdr/stellarledgerentries.h index c79507d..aa250fd 100644 --- a/xdr/stellarledgerentries.h +++ b/xdr/stellarledgerentries.h @@ -93,6 +93,45 @@ namespace stellar return in; } + struct AssetCode{ + AssetType type; + union{ + struct{ + AssetCode4 assetCode;// 1 to 4 characters + AccountID issuer; + }alphaNum4; + struct{ + AssetCode12 assetCode;// 5 to 12 characters + AccountID issuer; + }alphaNum12; + }; + }; + inline QDataStream &operator<<(QDataStream &out, const AssetCode &obj) { + out << obj.type; + switch(obj.type){ + case AssetType::ASSET_TYPE_CREDIT_ALPHANUM4: + out << obj.alphaNum4.assetCode << obj.alphaNum4.issuer; break; + case AssetType::ASSET_TYPE_CREDIT_ALPHANUM12: + out << obj.alphaNum12.assetCode << obj.alphaNum12.issuer; break; + default: throw std::runtime_error("invalid assed code"); break; + } + + return out; + } + + inline QDataStream &operator>>(QDataStream &in, AssetCode &obj) { + in >> obj.type; + switch(obj.type){ + case AssetType::ASSET_TYPE_CREDIT_ALPHANUM4: + in >> obj.alphaNum4.assetCode >> obj.alphaNum4.issuer; break; + case AssetType::ASSET_TYPE_CREDIT_ALPHANUM12: + in >> obj.alphaNum12.assetCode >> obj.alphaNum12.issuer; break; + default: throw std::runtime_error("invalid assed code"); break;//default: break; + } + + return in; + } + // price in fractional representation struct alignas(4) Price @@ -174,10 +213,16 @@ namespace stellar // otherwise, authorization cannot be revoked AUTH_REVOCABLE_FLAG = 0x2, // Once set, causes all AUTH_* flags to be read-only - AUTH_IMMUTABLE_FLAG = 0x4 + AUTH_IMMUTABLE_FLAG = 0x4, + + // Trustlines are created with clawback enabled set to "true", + // and claimable balances created from those trustlines are created + // with clawback enabled set to "true" + AUTH_CLAWBACK_ENABLED_FLAG = 0x8 }; //mask for all valid flags const qint32 MASK_ACCOUNT_FLAGS = 0x7; + const qint32 MASK_ACCOUNT_FLAGS_V16 = 0xF; // maximum number of signers const qint32 MAX_SIGNERS = 20; @@ -574,6 +619,33 @@ namespace stellar return in; } + enum class ClaimableBalanceFlags : qint32 + { + // If set, the issuer account of the asset held by the claimable balance may + // clawback the claimable balance + CLAIMABLE_BALANCE_CLAWBACK_ENABLED_FLAG = 0x1 + }; + + const qint32 MASK_CLAIMABLE_BALANCE_FLAGS = 0x1; + + struct ClaimableBalanceEntryExtensionV1 + { + // reserved for future use + Reserved ext; + + quint32 flags; // see ClaimableBalanceFlags + }; + + inline QDataStream &operator<<(QDataStream &out, const ClaimableBalanceEntryExtensionV1 &obj) { + out << obj.ext<< obj.flags; + return out; + } + + inline QDataStream &operator>>(QDataStream &in, ClaimableBalanceEntryExtensionV1 &obj) { + in >> obj.ext>> obj.flags; + return in; + } + struct ClaimableBalanceEntry { // Unique identifier for this ClaimableBalanceEntry @@ -590,15 +662,39 @@ namespace stellar // reserved for future use Reserved ext; + union{ + ClaimableBalanceEntryExtensionV1 v1; + }; }; inline QDataStream &operator<<(QDataStream &out, const ClaimableBalanceEntry &obj) { out << obj.balanceID<< obj.claimants<< obj.asset<< obj.amount<< obj.ext; + switch(obj.ext.reserved) + { + case 1: + { + out << obj.v1; + break; + } + default: + break; + } + return out; } inline QDataStream &operator>>(QDataStream &in, ClaimableBalanceEntry &obj) { in >> obj.balanceID>> obj.claimants>> obj.asset>> obj.amount>> obj.ext; + switch(obj.ext.reserved) + { + case 1: + { + in >> obj.v1; + break; + } + default: + break; + } return in; } @@ -628,11 +724,15 @@ namespace stellar AUTHORIZED_FLAG = 1, // issuer has authorized account to maintain and reduce liabilities for its // credit - AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG = 2 + AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG = 2, + // issuer has specified that it may clawback its credit, and that claimable + // balances created with its credit may also be clawed back + TRUSTLINE_CLAWBACK_ENABLED_FLAG = 4 }; //mask for all trustline flags const qint32 MASK_TRUSTLINE_FLAGS = 1; const qint32 MASK_TRUSTLINE_FLAGS_V13 = 3; + const qint32 MASK_TRUSTLINE_FLAGS_V16 = 7; struct TrustLineEntry { diff --git a/xdr/stellartransaction.h b/xdr/stellartransaction.h index b18e7d6..66fb8c4 100644 --- a/xdr/stellartransaction.h +++ b/xdr/stellartransaction.h @@ -90,7 +90,10 @@ namespace stellar CLAIM_CLAIMABLE_BALANCE = 15, BEGIN_SPONSORING_FUTURE_RESERVES = 16, END_SPONSORING_FUTURE_RESERVES = 17, - REVOKE_SPONSORSHIP = 18 + REVOKE_SPONSORSHIP = 18, + CLAWBACK = 19, + CLAWBACK_CLAIMABLE_BALANCE = 20, + SET_TRUST_LINE_FLAGS = 21 }; /* CreateAccount @@ -347,8 +350,8 @@ namespace stellar struct AllowTrustOp { AccountID trustor; - Asset asset; - quint32 authorize;//bool, 4 bytes + AssetCode asset; + quint32 authorize;// 0, or any bitwise combination of the AUTHORIZED_* flags of TrustLineFlags }; // ASSET_TYPE_NATIVE is not allowed inline QDataStream &operator<<(QDataStream &out, const AllowTrustOp &obj) { @@ -655,6 +658,75 @@ namespace stellar return in; } + /* Claws back an amount of an asset from an account + Threshold: med + Result: ClawbackResult + */ + struct ClawbackOp + { + Asset asset; + MuxedAccount from; + qint64 amount; + }; + + inline QDataStream &operator<<(QDataStream &out, const ClawbackOp &obj) { + out << obj.asset << obj.from << obj.amount; + return out; + } + + inline QDataStream &operator>>(QDataStream &in, ClawbackOp &obj) { + + in >> obj.asset >> obj.from >> obj.amount; + return in; + } + + /* Claws back a claimable balance + Threshold: med + Result: ClawbackClaimableBalanceResult + */ + struct ClawbackClaimableBalanceOp + { + ClaimableBalanceID balanceID; + }; + + + inline QDataStream &operator<<(QDataStream &out, const ClawbackClaimableBalanceOp &obj) { + out << obj.balanceID; + return out; + } + + inline QDataStream &operator>>(QDataStream &in, ClawbackClaimableBalanceOp &obj) { + + in >> obj.balanceID; + return in; + } + + /* SetTrustLineFlagsOp + Updates the flags of an existing trust line. + This is called by the issuer of the related asset. + Threshold: low + Result: SetTrustLineFlagsResult + */ + struct SetTrustLineFlagsOp + { + AccountID trustor; + Asset asset; + + quint32 clearFlags; // which flags to clear + quint32 setFlags; // which flags to set + }; + + inline QDataStream &operator<<(QDataStream &out, const SetTrustLineFlagsOp &obj) { + out << obj.trustor << obj.asset << obj.clearFlags << obj.setFlags; + return out; + } + + inline QDataStream &operator>>(QDataStream &in, SetTrustLineFlagsOp &obj) { + + in >> obj.trustor >> obj.asset >> obj.clearFlags >> obj.setFlags; + return in; + } + /* An operation is the lowest unit of work that a transaction does */ struct Operation { @@ -673,7 +745,10 @@ namespace stellar MuxedAccount operationAccountMerge; MuxedAccount operationInflation; BumpSequenceOp operationBumpSequence; - ManageBuyOfferOp operationManageBuyOffer; + ManageBuyOfferOp operationManageBuyOffer; + ClawbackOp operationClawback; + ClawbackClaimableBalanceOp operationClawbackClaimableBalance; + SetTrustLineFlagsOp operationSetTrustLineFlags; //non trivials, you MUST call contructor explicity to use them PathPaymentStrictReceiveOp operationPathPaymentStrictReceive; @@ -750,6 +825,12 @@ namespace stellar break; case OperationType::REVOKE_SPONSORSHIP: out <>obj.operationRevokeSponsorship; break; + case OperationType::CLAWBACK: + in >> obj.operationClawback; break; + case OperationType::CLAWBACK_CLAIMABLE_BALANCE: + in >> obj.operationClawbackClaimableBalance; break; + case OperationType::SET_TRUST_LINE_FLAGS: + in >> obj.operationSetTrustLineFlags; break; //default: break; } return in; @@ -1641,7 +1728,8 @@ namespace stellar SET_OPTIONS_UNKNOWN_FLAG = -6, // can't set an unknown flag SET_OPTIONS_THRESHOLD_OUT_OF_RANGE = -7, // bad value for weight/threshold SET_OPTIONS_BAD_SIGNER = -8, // signer cannot be masterkey - SET_OPTIONS_INVALID_HOME_DOMAIN = -9 // malformed home domain + SET_OPTIONS_INVALID_HOME_DOMAIN = -9, // malformed home domain + SET_OPTIONS_AUTH_REVOCABLE_REQUIRED = -10 // auth revocable is required for clawback }; XDR_SERIALIZER(SetOptionsResultCode) @@ -1992,6 +2080,111 @@ namespace stellar in >> obj.code; return in; } + + /******* Clawback Result ********/ + + enum class ClawbackResultCode : qint32 + { + // codes considered as "success" for the operation + CLAWBACK_SUCCESS = 0, + + // codes considered as "failure" for the operation + CLAWBACK_MALFORMED = -1, + CLAWBACK_NOT_CLAWBACK_ENABLED = -2, + CLAWBACK_NO_TRUST = -3, + CLAWBACK_UNDERFUNDED = -4 + }; + XDR_SERIALIZER(ClawbackResultCode) + + struct ClawbackResult + { + ClawbackResultCode code; +// union{ +// case : CLAWBACK_SUCCESS void; +// default: void +// }; + }; + inline QDataStream &operator<<(QDataStream &out, const ClawbackResult &obj) { + out << obj.code; + return out; + } + + inline QDataStream &operator>>(QDataStream &in, ClawbackResult &obj) { + in >> obj.code; + return in; + } + + /******* ClawbackClaimableBalance Result ********/ + + enum class ClawbackClaimableBalanceResultCode : qint32 + { + // codes considered as "success" for the operation + CLAWBACK_CLAIMABLE_BALANCE_SUCCESS = 0, + + // codes considered as "failure" for the operation + CLAWBACK_CLAIMABLE_BALANCE_DOES_NOT_EXIST = -1, + CLAWBACK_CLAIMABLE_BALANCE_NOT_ISSUER = -2, + CLAWBACK_CLAIMABLE_BALANCE_NOT_CLAWBACK_ENABLED = -3 + }; + XDR_SERIALIZER(ClawbackClaimableBalanceResultCode) + + struct ClawbackClaimableBalanceResult + { + ClawbackClaimableBalanceResultCode code; +// union{ +// case CLAWBACK_CLAIMABLE_BALANCE_SUCCESS: +// void; +// default: +// void; +// }; + + }; + inline QDataStream &operator<<(QDataStream &out, const ClawbackClaimableBalanceResult &obj) { + out << obj.code; + return out; + } + + inline QDataStream &operator>>(QDataStream &in, ClawbackClaimableBalanceResult &obj) { + in >> obj.code; + return in; + } + + /******* SetTrustLineFlags Result ********/ + + enum class SetTrustLineFlagsResultCode : qint32 + { + // codes considered as "success" for the operation + SET_TRUST_LINE_FLAGS_SUCCESS = 0, + + // codes considered as "failure" for the operation + SET_TRUST_LINE_FLAGS_MALFORMED = -1, + SET_TRUST_LINE_FLAGS_NO_TRUST_LINE = -2, + SET_TRUST_LINE_FLAGS_CANT_REVOKE = -3, + SET_TRUST_LINE_FLAGS_INVALID_STATE = -4 + }; + XDR_SERIALIZER(SetTrustLineFlagsResultCode) + + union SetTrustLineFlagsResult + { + SetTrustLineFlagsResultCode code; +// union{ +// case SET_TRUST_LINE_FLAGS_SUCCESS: +// void; +// default: +// void; +// }; + }; + inline QDataStream &operator<<(QDataStream &out, const SetTrustLineFlagsResult &obj) { + out << obj.code; + return out; + } + + inline QDataStream &operator>>(QDataStream &in, SetTrustLineFlagsResult &obj) { + in >> obj.code; + return in; + } + + /* High level Operation Result */ enum class OperationResultCode : qint32 @@ -2019,6 +2212,9 @@ namespace stellar ManageDataResult manageDataResult; BumpSequenceResult bumpSequenceResult; CreateClaimableBalanceResult createClaimableBalanceResult; + ClawbackResult clawbackResult; + ClawbackClaimableBalanceResult clawbackClaimableBalanceResult; + SetTrustLineFlagsResult setTrustLineFlagsResult; //no trivial ManageBuyOfferResult manageBuyOfferResult; PaymentResult paymentResult; @@ -2081,6 +2277,12 @@ namespace stellar out << obj.pathPaymentStrictSendResult; break; case OperationType::CREATE_CLAIMABLE_BALANCE: out << obj.createClaimableBalanceResult; break; + case OperationType::CLAWBACK: + out << obj.clawbackResult; break; + case OperationType::CLAWBACK_CLAIMABLE_BALANCE: + out << obj.clawbackClaimableBalanceResult; break; + case OperationType::SET_TRUST_LINE_FLAGS: + out << obj.setTrustLineFlagsResult; break; default:break; } break; @@ -2136,6 +2338,12 @@ namespace stellar in >> obj.pathPaymentStrictSendResult; break; case OperationType::CREATE_CLAIMABLE_BALANCE: in >> obj.createClaimableBalanceResult; break; + case OperationType::CLAWBACK: + in >> obj.clawbackResult; break; + case OperationType::CLAWBACK_CLAIMABLE_BALANCE: + in >> obj.clawbackClaimableBalanceResult; break; + case OperationType::SET_TRUST_LINE_FLAGS: + in >> obj.setTrustLineFlagsResult; break; default: break; } break; From 3ca0ae167664b3f7c9d89df03dce9be9fa21d613 Mon Sep 17 00:00:00 2001 From: bnogalm <18525490+bnogalm@users.noreply.github.com> Date: Wed, 13 Apr 2022 20:44:18 +0200 Subject: [PATCH 2/4] Add some const to parameters are actually const Remove unnecessary object creation --- src/keypair.cpp | 14 +++++++------- src/keypair.h | 8 ++++---- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/keypair.cpp b/src/keypair.cpp index 55fdf09..e80cef4 100644 --- a/src/keypair.cpp +++ b/src/keypair.cpp @@ -44,7 +44,7 @@ KeyPair::~KeyPair() } -KeyPair::KeyPair(quint8 *publicKey, quint8 *privateKey) +KeyPair::KeyPair(const quint8 *publicKey,const quint8 *privateKey) { m_publicKey = new quint8[keyLength]; memcpy(m_publicKey,publicKey,keyLength); @@ -164,7 +164,7 @@ stellar::SignatureHint KeyPair::getSignatureHint() { stellar::PublicKey KeyPair::getXdrPublicKey() { stellar::PublicKey publicKey; publicKey.type = stellar::PublicKeyType::PUBLIC_KEY_TYPE_ED25519; - memcpy(publicKey.ed25519,this->getPublicKey().data(),keyLength); + memcpy(publicKey.ed25519,m_publicKey,keyLength); return publicKey; } @@ -172,27 +172,27 @@ stellar::MuxedAccount KeyPair::getXdrMutexPublicKey() { stellar::MuxedAccount mutexPublicKey; mutexPublicKey.type = stellar::CryptoKeyType::KEY_TYPE_ED25519; - memcpy(mutexPublicKey.ed25519,this->getPublicKey().data(),keyLength); + memcpy(mutexPublicKey.ed25519,m_publicKey,keyLength); return mutexPublicKey; } stellar::SignerKey KeyPair::getXdrSignerKey() { stellar::SignerKey signerKey; signerKey.type = stellar::SignerKeyType::SIGNER_KEY_TYPE_ED25519; - memcpy(signerKey.ed25519,this->getPublicKey().data(),keyLength); + memcpy(signerKey.ed25519,m_publicKey,keyLength); return signerKey; } -KeyPair *KeyPair::fromXdrPublicKey(stellar::PublicKey& key) { +KeyPair *KeyPair::fromXdrPublicKey(const stellar::PublicKey &key) { return new KeyPair(key.ed25519); } -KeyPair *KeyPair::fromXdrMutexPublicKey(stellar::MuxedAccount &key) +KeyPair *KeyPair::fromXdrMutexPublicKey(const stellar::MuxedAccount &key) { return new KeyPair(key.ed25519); } -KeyPair *KeyPair::fromXdrSignerKey(stellar::SignerKey key) { +KeyPair *KeyPair::fromXdrSignerKey(const stellar::SignerKey key) { return new KeyPair(key.ed25519); } diff --git a/src/keypair.h b/src/keypair.h index 08f73d5..08bc08b 100644 --- a/src/keypair.h +++ b/src/keypair.h @@ -32,7 +32,7 @@ class KeyPair * @param publicKey * @param privateKey */ - KeyPair(quint8* publicKey,quint8* privateKey=nullptr); + KeyPair(const quint8* publicKey, const quint8 *privateKey=nullptr); /** Creates a new KeyPair from the given strkey encoded Stellar account ID. * Some requesters and API classes requires KeyPair class, if KeyPair is not going to be used any longer, this constructor allow to build a keypair on the stack @@ -122,11 +122,11 @@ class KeyPair stellar::SignerKey getXdrSignerKey(); - static KeyPair* fromXdrPublicKey(stellar::PublicKey& key); + static KeyPair* fromXdrPublicKey(const stellar::PublicKey& key); - static KeyPair* fromXdrMutexPublicKey(stellar::MuxedAccount& key); + static KeyPair* fromXdrMutexPublicKey(const stellar::MuxedAccount &key); - static KeyPair* fromXdrSignerKey(stellar::SignerKey key); + static KeyPair* fromXdrSignerKey(const stellar::SignerKey key); /** * Sign the provided data with the keypair's private key. From 715b23c62602b7b039bd135697ff35c60a4c29eb Mon Sep 17 00:00:00 2001 From: bnogalm <18525490+bnogalm@users.noreply.github.com> Date: Wed, 13 Apr 2022 20:48:06 +0200 Subject: [PATCH 3/4] Add support for CAP 35 operations when building transactions Fix claimclaimablebalanceoperation --- StellarQtSDK.pri | 6 + src/allowtrustoperation.h | 5 +- src/asset.cpp | 2 +- src/asset.h | 2 +- src/assettypecreditalphanum.cpp | 8 + src/assettypecreditalphanum.h | 2 +- src/claimclaimablebalanceoperation.cpp | 10 +- src/clawbackclaimablebalanceoperation.cpp | 40 + src/clawbackclaimablebalanceoperation.h | 33 + src/clawbackoperation.cpp | 69 + src/clawbackoperation.h | 44 + src/operation.cpp | 14 + .../trustlineauthorizedeffectresponse.h | 5 +- ...rizedtomaintainliabilitieseffectresponse.h | 4 +- .../trustlinedeauthorizedeffectresponse.h | 4 +- .../operations/allowtrustoperationresponse.h | 4 +- src/settrustlineflagsoperation.cpp | 64 + src/settrustlineflagsoperation.h | 55 + src/util.cpp | 26 + src/util.h | 10 + test/operationtest.h | 1540 +++++++++-------- 21 files changed, 1232 insertions(+), 715 deletions(-) create mode 100644 src/clawbackclaimablebalanceoperation.cpp create mode 100644 src/clawbackclaimablebalanceoperation.h create mode 100644 src/clawbackoperation.cpp create mode 100644 src/clawbackoperation.h create mode 100644 src/settrustlineflagsoperation.cpp create mode 100644 src/settrustlineflagsoperation.h diff --git a/StellarQtSDK.pri b/StellarQtSDK.pri index bd61bec..2a1ca28 100644 --- a/StellarQtSDK.pri +++ b/StellarQtSDK.pri @@ -28,6 +28,8 @@ SOURCES += \ $$PWD/src/beginsponsoringfuturereservesoperation.cpp \ $$PWD/src/claimant.cpp \ $$PWD/src/claimclaimablebalanceoperation.cpp \ + $$PWD/src/clawbackclaimablebalanceoperation.cpp \ + $$PWD/src/clawbackoperation.cpp \ $$PWD/src/createclaimablebalanceoperation.cpp \ $$PWD/src/createpassivesellofferoperation.cpp \ $$PWD/src/endsponsoringfuturereservesoperation.cpp \ @@ -96,6 +98,7 @@ SOURCES += \ $$PWD/src/revokesignersponsorshipoperation.cpp \ $$PWD/src/revoketrustlinesponsorshipoperation.cpp \ $$PWD/src/sep10challenge.cpp \ + $$PWD/src/settrustlineflagsoperation.cpp \ $$PWD/src/strkey.cpp \ $$PWD/src/inflationoperation.cpp \ $$PWD/src/util.cpp \ @@ -216,6 +219,8 @@ HEADERS += \ $$PWD/src/beginsponsoringfuturereservesoperation.h \ $$PWD/src/claimant.h \ $$PWD/src/claimclaimablebalanceoperation.h \ + $$PWD/src/clawbackclaimablebalanceoperation.h \ + $$PWD/src/clawbackoperation.h \ $$PWD/src/createclaimablebalanceoperation.h \ $$PWD/src/createpassivesellofferoperation.h \ $$PWD/src/endsponsoringfuturereservesoperation.h \ @@ -274,6 +279,7 @@ HEADERS += \ $$PWD/src/revokesignersponsorshipoperation.h \ $$PWD/src/revoketrustlinesponsorshipoperation.h \ $$PWD/src/sep10challenge.h \ + $$PWD/src/settrustlineflagsoperation.h \ $$PWD/xdr/stellartypes.h \ $$PWD/src/account.h \ $$PWD/src/transactionbuilderaccount.h \ diff --git a/src/allowtrustoperation.h b/src/allowtrustoperation.h index ae2a591..81794b2 100644 --- a/src/allowtrustoperation.h +++ b/src/allowtrustoperation.h @@ -2,12 +2,13 @@ #define ALLOWTRUSTOPERATION_H #include "operation.h" - /** + * @deprecated As of release 0.24.0, replaced by {@link SetTrustlineFlagsOperation} + * * Represents AllowTrust operation. * @see List of Operations */ -class AllowTrustOperation : public Operation +class Q_DECL_DEPRECATED AllowTrustOperation : public Operation { KeyPair* m_trustor; diff --git a/src/asset.cpp b/src/asset.cpp index 8f77f38..58e5e8c 100644 --- a/src/asset.cpp +++ b/src/asset.cpp @@ -62,7 +62,7 @@ Asset *Asset::create(QString canonicalForm) return Asset::createNonNativeAsset(parts[0], parts[1]); } -Asset *Asset::fromXdr(stellar::Asset &xdr) { +Asset *Asset::fromXdr(const stellar::Asset &xdr) { switch (xdr.type) { case stellar::AssetType::ASSET_TYPE_NATIVE: return new AssetTypeNative(); diff --git a/src/asset.h b/src/asset.h index e5dd311..d180121 100644 --- a/src/asset.h +++ b/src/asset.h @@ -47,7 +47,7 @@ class Asset * Generates Asset object from a given XDR object * @param xdr XDR object */ - static Asset* fromXdr(stellar::Asset& xdr); + static Asset* fromXdr(const stellar::Asset &xdr); /** * Returns asset type. Possible types: diff --git a/src/assettypecreditalphanum.cpp b/src/assettypecreditalphanum.cpp index 8c8d0f2..6337bb8 100644 --- a/src/assettypecreditalphanum.cpp +++ b/src/assettypecreditalphanum.cpp @@ -42,3 +42,11 @@ QString AssetTypeCreditAlphaNum::toString() const { return getCode()+":"+this->getIssuer().getAccountId(); } + +AssetTypeCreditAlphaNum *checkNotNull(AssetTypeCreditAlphaNum *asset, const char *error) +{ + if(!asset){ + throw std::runtime_error(error); + } + return asset; +} diff --git a/src/assettypecreditalphanum.h b/src/assettypecreditalphanum.h index d72708d..1924b03 100644 --- a/src/assettypecreditalphanum.h +++ b/src/assettypecreditalphanum.h @@ -43,5 +43,5 @@ class AssetTypeCreditAlphaNum : public Asset virtual QString toString() const; }; - +AssetTypeCreditAlphaNum* checkNotNull(AssetTypeCreditAlphaNum* asset, const char *error); #endif // ASSETTYPECREDITALPHANUM_H diff --git a/src/claimclaimablebalanceoperation.cpp b/src/claimclaimablebalanceoperation.cpp index 71f7ec6..c90ae56 100644 --- a/src/claimclaimablebalanceoperation.cpp +++ b/src/claimclaimablebalanceoperation.cpp @@ -7,12 +7,8 @@ ClaimClaimableBalanceOperation::ClaimClaimableBalanceOperation(stellar::ClaimCla ClaimClaimableBalanceOperation::ClaimClaimableBalanceOperation(QString balanceID) { - checkNotNull(balanceID, "balanceID cannot be null"); - m_op.balanceID.type = stellar::ClaimableBalanceIDType::CLAIMABLE_BALANCE_ID_TYPE_V0; - QByteArray balanceIDDecoded = QByteArray::fromHex(balanceID.toLower().toLatin1()); - if(balanceIDDecoded.length()!=sizeof(m_op.balanceID.v0)) - throw std::runtime_error("invalid balance id length"); - memcpy(balanceIDDecoded.data(),m_op.balanceID.v0,sizeof(m_op.balanceID.v0)); + checkNotNull(balanceID, "balanceID cannot be null"); + Util::claimableBalanceIdToXDR(balanceID,m_op.balanceID); } void ClaimClaimableBalanceOperation::fillOperationBody(stellar::Operation &operation) @@ -22,7 +18,7 @@ void ClaimClaimableBalanceOperation::fillOperationBody(stellar::Operation &opera } QString ClaimClaimableBalanceOperation::getBalanceId() { - return QString(QByteArray::fromRawData((char*)m_op.balanceID.v0,sizeof(m_op.balanceID.v0)).toHex()); + return Util::xdrToClaimableBalanceId(m_op.balanceID); } ClaimClaimableBalanceOperation *ClaimClaimableBalanceOperation::build(stellar::ClaimClaimableBalanceOp &op) diff --git a/src/clawbackclaimablebalanceoperation.cpp b/src/clawbackclaimablebalanceoperation.cpp new file mode 100644 index 0000000..df87e19 --- /dev/null +++ b/src/clawbackclaimablebalanceoperation.cpp @@ -0,0 +1,40 @@ +#include "clawbackclaimablebalanceoperation.h" + +ClawbackClaimableBalanceOperation::ClawbackClaimableBalanceOperation(stellar::ClawbackClaimableBalanceOp &op):m_op(op) +{ + +} + +ClawbackClaimableBalanceOperation::ClawbackClaimableBalanceOperation(QString balanceID) +{ + checkNotNull(balanceID, "balanceID cannot be null"); + Util::claimableBalanceIdToXDR(balanceID,m_op.balanceID); +} + +void ClawbackClaimableBalanceOperation::fillOperationBody(stellar::Operation &operation) +{ + operation.type = stellar::OperationType::CLAWBACK_CLAIMABLE_BALANCE; + operation.operationClawbackClaimableBalance = m_op; +} + +QString ClawbackClaimableBalanceOperation::getBalanceId() +{ + return Util::xdrToClaimableBalanceId(m_op.balanceID); +} + +ClawbackClaimableBalanceOperation *ClawbackClaimableBalanceOperation::build(stellar::ClawbackClaimableBalanceOp &op) +{ + return new ClawbackClaimableBalanceOperation(op); +} + +ClawbackClaimableBalanceOperation *ClawbackClaimableBalanceOperation::create(QString balanceId) +{ + return new ClawbackClaimableBalanceOperation(balanceId); +} + +ClawbackClaimableBalanceOperation *ClawbackClaimableBalanceOperation::setSourceAccount(QString sourceAccount) +{ + Operation::setSourceAccount(sourceAccount); + return this; +} + diff --git a/src/clawbackclaimablebalanceoperation.h b/src/clawbackclaimablebalanceoperation.h new file mode 100644 index 0000000..b4175dd --- /dev/null +++ b/src/clawbackclaimablebalanceoperation.h @@ -0,0 +1,33 @@ +#ifndef CLAWBACKCLAIMABLEBALANCEOPERATION_H +#define CLAWBACKCLAIMABLEBALANCEOPERATION_H + +#include "operation.h" +/** + * + * Represents a Clawback Claimable Balance operation. + * @see List of Operations + */ +class ClawbackClaimableBalanceOperation : public Operation +{ + + stellar::ClawbackClaimableBalanceOp m_op; +public: + ClawbackClaimableBalanceOperation(stellar::ClawbackClaimableBalanceOp &op); + ClawbackClaimableBalanceOperation(QString balanceID); + void fillOperationBody(stellar::Operation &operation); + /** + * The id of the claimable balance which will be clawed back. + */ + QString getBalanceId(); + + static ClawbackClaimableBalanceOperation* build(stellar::ClawbackClaimableBalanceOp &op); + static ClawbackClaimableBalanceOperation* create(QString balanceId); + /** + * Sets the source account for this operation. + * @param sourceAccount The operation's source account. + * @return ClawbackClaimableBalanceOp object so you can chain methods. + */ + ClawbackClaimableBalanceOperation* setSourceAccount(QString sourceAccount); +}; + +#endif // CLAWBACKCLAIMABLEBALANCEOPERATION_H diff --git a/src/clawbackoperation.cpp b/src/clawbackoperation.cpp new file mode 100644 index 0000000..912bf5c --- /dev/null +++ b/src/clawbackoperation.cpp @@ -0,0 +1,69 @@ +#include "clawbackoperation.h" +#include "assettypecreditalphanum.h" + + +ClawbackOperation::ClawbackOperation(QString from, Asset *asset, QString amount):m_asset(nullptr) +{ + checkNotNull(from, "from cannot be null"); + checkNotNull(asset, "asset cannot be null"); + AssetTypeCreditAlphaNum* assetAlphaNum = Util::assertNonNativeAsset(asset); + checkNotNull(amount, "amount cannot be null"); + + + m_op.from = StrKey::encodeToXDRMuxedAccount(from); + m_op.asset = assetAlphaNum->toXdr(); + m_op.amount = Operation::toXdrAmount(amount); +} + +ClawbackOperation::ClawbackOperation(stellar::ClawbackOp &op) + :m_op(op) + ,m_asset(nullptr) +{ + +} + +ClawbackOperation::~ClawbackOperation() +{ + if(m_asset) + delete m_asset; +} + +void ClawbackOperation::fillOperationBody(stellar::Operation &operation) +{ + operation.type = stellar::OperationType::CLAWBACK; + operation.operationClawback = m_op; +} + +QString ClawbackOperation::getFrom() const +{ + + return StrKey::encodeStellarAccountId(StrKey::muxedAccountToAccountId(m_op.from)); +} + +QString ClawbackOperation::getAmount() const +{ + return Operation::fromXdrAmount(m_op.amount); +} + +Asset *ClawbackOperation::getAsset() +{ + if(!m_asset) + m_asset = Asset::fromXdr(m_op.asset); + return m_asset; +} + +ClawbackOperation *ClawbackOperation::build(stellar::ClawbackOp &op) +{ + return new ClawbackOperation(op); +} + +ClawbackOperation *ClawbackOperation::create(QString from, Asset *asset, QString amount) +{ + return new ClawbackOperation(from,asset,amount); +} + +ClawbackOperation *ClawbackOperation::setSourceAccount(QString sourceAccount) +{ + Operation::setSourceAccount(sourceAccount); + return this; +} diff --git a/src/clawbackoperation.h b/src/clawbackoperation.h new file mode 100644 index 0000000..57ffb12 --- /dev/null +++ b/src/clawbackoperation.h @@ -0,0 +1,44 @@ +#ifndef CLAWBACKOPERATION_H +#define CLAWBACKOPERATION_H + +#include "operation.h" +/** + * + * Represents a Clawback operation. + * @see List of Operations + */ +class ClawbackOperation : public Operation +{ + stellar::ClawbackOp m_op; + Asset* m_asset; +public: + ClawbackOperation(QString from, Asset* asset, QString amount); + ClawbackOperation(stellar::ClawbackOp& op); + ~ClawbackOperation(); + void fillOperationBody(stellar::Operation &operation); + /** + * The account owning of the trustline. + */ + QString getFrom() const; + + /** + * The amount to be clawed back. + */ + QString getAmount() const; + + /** + * The asset to be clawed back. + */ + Asset* getAsset(); + + static ClawbackOperation* build(stellar::ClawbackOp &op); + static ClawbackOperation* create(QString from, Asset* asset, QString amount); + /** + * Sets the source account for this operation. + * @param sourceAccount The operation's source account. + * @return ClawbackOperation object so you can chain methods. + */ + ClawbackOperation* setSourceAccount(QString sourceAccount); +}; + +#endif // CLAWBACKOPERATION_H diff --git a/src/operation.cpp b/src/operation.cpp index 065ddb9..fee85c5 100644 --- a/src/operation.cpp +++ b/src/operation.cpp @@ -27,6 +27,10 @@ #include "revokesignersponsorshipoperation.h" #include "revoketrustlinesponsorshipoperation.h" +#include "clawbackoperation.h" +#include "clawbackclaimablebalanceoperation.h" +#include "settrustlineflagsoperation.h" + Operation::Operation() { @@ -169,6 +173,16 @@ Operation *Operation::fromXdr(stellar::Operation &xdr) { break; } break; + + case stellar::OperationType::CLAWBACK: + operation = ClawbackOperation::build(xdr.operationClawback); + break; + case stellar::OperationType::CLAWBACK_CLAIMABLE_BALANCE: + operation = ClawbackClaimableBalanceOperation::build(xdr.operationClawbackClaimableBalance); + break; + case stellar::OperationType::SET_TRUST_LINE_FLAGS: + operation = SetTrustlineFlagsOperation::build(xdr.operationSetTrustLineFlags); + break; default: throw std::runtime_error("Unknown operation body"); } diff --git a/src/responses/effects/trustlineauthorizedeffectresponse.h b/src/responses/effects/trustlineauthorizedeffectresponse.h index e087e1a..6f2a8bf 100644 --- a/src/responses/effects/trustlineauthorizedeffectresponse.h +++ b/src/responses/effects/trustlineauthorizedeffectresponse.h @@ -5,12 +5,15 @@ /** + * @deprecated As of release 0.24.0, replaced by {@link TrustlineFlagsUpdatedEffectResponse} + * * Represents trustline_authorized effect response. * @see Effect documentation * @see org.stellar.sdk.requests.EffectsRequestBuilder * @see org.stellar.sdk.Server#effects() */ -class TrustlineAuthorizedEffectResponse : public TrustlineAuthorizationResponse + +class Q_DECL_DEPRECATED TrustlineAuthorizedEffectResponse : public TrustlineAuthorizationResponse { Q_OBJECT public: diff --git a/src/responses/effects/trustlineauthorizedtomaintainliabilitieseffectresponse.h b/src/responses/effects/trustlineauthorizedtomaintainliabilitieseffectresponse.h index bf955b9..2c462b9 100644 --- a/src/responses/effects/trustlineauthorizedtomaintainliabilitieseffectresponse.h +++ b/src/responses/effects/trustlineauthorizedtomaintainliabilitieseffectresponse.h @@ -2,10 +2,12 @@ #define TRUSTLINEAUTHORIZEDTOMAINTAINLIABILITIESEFFECTRESPONSE_H #include "trustlineauthorizationresponse.h" /** + * @deprecated As of release 0.24.0, replaced by {@link TrustlineFlagsUpdatedEffectResponse} + * * Represents trustline_authorized_to_maintain_liabilities effect response. * @see Effect documentation */ -class TrustlineAuthorizedToMaintainLiabilitiesEffectResponse : public TrustlineAuthorizationResponse +class Q_DECL_DEPRECATED TrustlineAuthorizedToMaintainLiabilitiesEffectResponse : public TrustlineAuthorizationResponse { public: TrustlineAuthorizedToMaintainLiabilitiesEffectResponse(); diff --git a/src/responses/effects/trustlinedeauthorizedeffectresponse.h b/src/responses/effects/trustlinedeauthorizedeffectresponse.h index f2a9502..dcac18a 100644 --- a/src/responses/effects/trustlinedeauthorizedeffectresponse.h +++ b/src/responses/effects/trustlinedeauthorizedeffectresponse.h @@ -4,13 +4,15 @@ #include "trustlineauthorizationresponse.h" /** + * @deprecated As of release 0.24.0, replaced by {@link TrustlineFlagsUpdatedEffectResponse} + * * Represents trustline_deauthorized effect response. * @see Effect documentation * @see org.stellar.sdk.requests.EffectsRequestBuilder * @see org.stellar.sdk.Server#effects() */ -class TrustlineDeauthorizedEffectResponse : public TrustlineAuthorizationResponse +class Q_DECL_DEPRECATED TrustlineDeauthorizedEffectResponse : public TrustlineAuthorizationResponse { Q_OBJECT public: diff --git a/src/responses/operations/allowtrustoperationresponse.h b/src/responses/operations/allowtrustoperationresponse.h index 99f5db7..92dfe63 100644 --- a/src/responses/operations/allowtrustoperationresponse.h +++ b/src/responses/operations/allowtrustoperationresponse.h @@ -6,12 +6,14 @@ class Asset; /** + * @deprecated As of release 0.24.0, replaced by {@link SetTrustLineFlagsOperationResponse} + * * Represents AllowTrust operation response. * @see Operation documentation * @see org.stellar.sdk.requests.OperationsRequestBuilder * @see org.stellar.sdk.Server#operations() */ -class AllowTrustOperationResponse : public OperationResponse +class Q_DECL_DEPRECATED AllowTrustOperationResponse : public OperationResponse { Q_OBJECT Q_PROPERTY(QString trustor READ trustor WRITE setTrustor) diff --git a/src/settrustlineflagsoperation.cpp b/src/settrustlineflagsoperation.cpp new file mode 100644 index 0000000..0d14c2a --- /dev/null +++ b/src/settrustlineflagsoperation.cpp @@ -0,0 +1,64 @@ +#include "settrustlineflagsoperation.h" +#include "assettypecreditalphanum.h" +SetTrustlineFlagsOperation::SetTrustlineFlagsOperation(stellar::SetTrustLineFlagsOp& op):m_op(op),m_asset(nullptr) +{ + +} + +SetTrustlineFlagsOperation::SetTrustlineFlagsOperation(QString trustor, Asset *asset, QFlags clearFlags, QFlags setFlags) + :m_asset(nullptr) +{ + checkNotNull(trustor, "from cannot be null"); + checkNotNull(asset, "asset cannot be null"); + AssetTypeCreditAlphaNum* assetAlphaNum= Util::assertNonNativeAsset(asset); + m_op.trustor = StrKey::encodeToXDRAccountId(trustor); + m_op.asset = assetAlphaNum->toXdr(); + m_op.clearFlags = clearFlags; + m_op.setFlags = setFlags; +} + +SetTrustlineFlagsOperation::~SetTrustlineFlagsOperation() +{ + if(m_asset) + delete m_asset; +} + +void SetTrustlineFlagsOperation::fillOperationBody(stellar::Operation &operation) +{ + operation.type = stellar::OperationType::SET_TRUST_LINE_FLAGS; + operation.operationSetTrustLineFlags = m_op; +} + +Asset *SetTrustlineFlagsOperation::getAsset() { + if(!m_asset) + { + m_asset = AssetTypeCreditAlphaNum::fromXdr(m_op.asset); + } + return m_asset; +} + +QFlags SetTrustlineFlagsOperation::getSetFlags() +{ + return QFlags(m_op.setFlags); +} + +QFlags SetTrustlineFlagsOperation::getClearFlags() +{ + return QFlags(m_op.clearFlags); +} + +SetTrustlineFlagsOperation *SetTrustlineFlagsOperation::build(stellar::SetTrustLineFlagsOp &op) +{ + return new SetTrustlineFlagsOperation(op); +} + +SetTrustlineFlagsOperation *SetTrustlineFlagsOperation::create(QString trustor, Asset *asset, QFlags clearFlags, QFlags setFlags) +{ + return new SetTrustlineFlagsOperation(trustor,asset,clearFlags,setFlags); +} + +SetTrustlineFlagsOperation *SetTrustlineFlagsOperation::setSourceAccount(QString sourceAccount) +{ + Operation::setSourceAccount(sourceAccount); + return this; +} diff --git a/src/settrustlineflagsoperation.h b/src/settrustlineflagsoperation.h new file mode 100644 index 0000000..23dcf24 --- /dev/null +++ b/src/settrustlineflagsoperation.h @@ -0,0 +1,55 @@ +#ifndef SETTRUSTLINEFLAGSOPERATION_H +#define SETTRUSTLINEFLAGSOPERATION_H + +#include "operation.h" +/** + * + * Represents a Set Trustline Flags operation. + * @see List of Operations + */ +class SetTrustlineFlagsOperation : public Operation +{ + stellar::SetTrustLineFlagsOp m_op; + Asset* m_asset; +public: + SetTrustlineFlagsOperation(stellar::SetTrustLineFlagsOp& op); + SetTrustlineFlagsOperation(QString trustor, Asset* asset, QFlags clearFlags, QFlags setFlags); + + ~SetTrustlineFlagsOperation(); + + void fillOperationBody(stellar::Operation &operation); + /** + * The account owning of the trustline. + */ + QString getTrustor() { + return StrKey::encodeStellarAccountId(m_op.trustor); + } + + /** + * The asset of the trustline. + */ + Asset* getAsset(); + + /** + * The flags to be set. + */ + QFlags getSetFlags(); + + /** + * The flags to be cleared. + */ + QFlags getClearFlags(); + + + + static SetTrustlineFlagsOperation* build(stellar::SetTrustLineFlagsOp &op); + static SetTrustlineFlagsOperation* create(QString trustor, Asset* asset, QFlags clearFlags, QFlags setFlags); + /** + * Sets the source account for this operation. + * @param sourceAccount The operation's source account. + * @return SetTrustlineFlagsOperation object so you can chain methods. + */ + SetTrustlineFlagsOperation* setSourceAccount(QString sourceAccount); +}; + +#endif // SETTRUSTLINEFLAGSOPERATION_H diff --git a/src/util.cpp b/src/util.cpp index a79b3d4..c9bf0b1 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -5,7 +5,10 @@ #include #include "account.h" #include "transaction.h" +#include "asset.h" +#include "assettypecreditalphanum.h" #include "managedataoperation.h" + #include Util::Util() @@ -86,6 +89,29 @@ QByteArray Util::mnemonicToBIP39Seed(QString words, QString passphrase) ,2048,64); } +void Util::claimableBalanceIdToXDR(QString balanceID, stellar::ClaimableBalanceID &balanceIdToFill) { + QByteArray balanceIDDecoded = QByteArray::fromHex(balanceID.toLower().toLatin1()); + if(balanceIDDecoded.length()!=sizeof(stellar::ClaimableBalanceID)) + throw std::runtime_error("invalid balance id length"); + balanceIdToFill.type = *((stellar::ClaimableBalanceIDType*)(balanceIDDecoded.data())); + memcpy(balanceIdToFill.v0,balanceIDDecoded.data()+sizeof(stellar::ClaimableBalanceIDType),sizeof(balanceIdToFill.v0)); + +} + +QString Util::xdrToClaimableBalanceId(stellar::ClaimableBalanceID &balanceId) { + //byteorder??, verify when v1 exists + QString res = QString("%1").arg((int)balanceId.type, 8, 16, QLatin1Char('0')); + res.append(QByteArray::fromRawData((char*)balanceId.v0,sizeof(balanceId.v0)).toHex()); + return res; +} + +AssetTypeCreditAlphaNum *Util::assertNonNativeAsset(Asset *asset) { + if (AssetTypeCreditAlphaNum* res = dynamic_cast(asset)) { + return res; + } + throw std::runtime_error("native assets are not supported"); +} + QString checkNotNull(QString p, const char *error) { if(p.isNull()){ diff --git a/src/util.h b/src/util.h index 30fb400..27454d2 100644 --- a/src/util.h +++ b/src/util.h @@ -5,6 +5,9 @@ #include #include #include "xdr/stellartransaction.h" + +class Asset; +class AssetTypeCreditAlphaNum; QString checkNotNull(QString p, const char* error); QByteArray checkNotNull(QByteArray p, const char* error); @@ -85,6 +88,13 @@ class Util static QList mnemonicWords(SupportedMnemonicLanguages language = SupportedMnemonicLanguages::EN); static QByteArray mnemonicToBIP39Seed(QString words, QString passphrase=QString("")); + + static void claimableBalanceIdToXDR(QString balanceID, stellar::ClaimableBalanceID& balanceIdToFill); + + static QString xdrToClaimableBalanceId(stellar::ClaimableBalanceID& balanceId); + + static AssetTypeCreditAlphaNum* assertNonNativeAsset(Asset* asset); + }; diff --git a/test/operationtest.h b/test/operationtest.h index f8c7755..75ef126 100644 --- a/test/operationtest.h +++ b/test/operationtest.h @@ -44,6 +44,10 @@ #include "src/beginsponsoringfuturereservesoperation.h" #include "src/endsponsoringfuturereservesoperation.h" +#include "src/claimclaimablebalanceoperation.h" +#include "src/clawbackoperation.h" +#include "src/clawbackclaimablebalanceoperation.h" +#include "src/settrustlineflagsoperation.h" class OperationTest: public QObject { @@ -64,519 +68,519 @@ private slots: QCOMPARE(Operation::fromXdrAmount(1234500001),QString("123.4500001")); QVERIFY(Operation::toXdrAmount("123.4500001")==1234500001UL); QVERIFY(Operation::toXdrAmount("123.45")==1234500000UL); - QVERIFY(Operation::toXdrAmount("123")==1230000000UL); + QVERIFY(Operation::toXdrAmount("123")==1230000000UL); } - void testCreateAccountOperation(){ - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair *source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - KeyPair *destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); + void testCreateAccountOperation(){ + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair *source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + KeyPair *destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); - QString startingAmount("1000"); - CreateAccountOperation* operation = new CreateAccountOperation(destination, startingAmount); - operation->setSourceAccount(source->getAccountId()); + QString startingAmount("1000"); + CreateAccountOperation* operation = new CreateAccountOperation(destination, startingAmount); + operation->setSourceAccount(source->getAccountId()); - stellar::Operation xdr = operation->toXdr(); - CreateAccountOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); + stellar::Operation xdr = operation->toXdr(); + CreateAccountOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); - QVERIFY(10000000000L==xdr.operationCreateAccount.startingBalance); + QVERIFY(10000000000L==xdr.operationCreateAccount.startingBalance); - QVERIFY(source->getAccountId()==parsedOperation->getSourceAccount()); + QVERIFY(source->getAccountId()==parsedOperation->getSourceAccount()); - QVERIFY(destination->getAccountId()==parsedOperation->getDestination()->getAccountId()); - QVERIFY(startingAmount==parsedOperation->getStartingBalance()); - QString expected("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAAAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAACVAvkAA=="); + QVERIFY(destination->getAccountId()==parsedOperation->getDestination()->getAccountId()); + QVERIFY(startingAmount==parsedOperation->getStartingBalance()); + QString expected("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAAAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAACVAvkAA=="); - QVERIFY(expected == operation->toXdrBase64()); + QVERIFY(expected == operation->toXdrBase64()); - } + } + + + void testPaymentOperation() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + KeyPair* destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); + + Asset* asset = new AssetTypeNative(); + QString amount = "1000"; + + Operation* operation = PaymentOperation::create(destination, asset, amount)->setSourceAccount(source->getAccountId()); + + stellar::Operation xdr = operation->toXdr(); + + + PaymentOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); + + QVERIFY(10000000000L==xdr.operationPayment.amount); + QVERIFY(source->getAccountId()==parsedOperation->getSourceAccount()); + //QVERIFY(destination->getAccountId()== parsedOperation->getDestination()); + QCOMPARE(parsedOperation->getDestination(),destination->getAccountId()); + QVERIFY(dynamic_cast(parsedOperation->getAsset())); + QVERIFY(amount == parsedOperation->getAmount()); + QString expected("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAEAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAAAAAAAAlQL5AA="); + //qDebug() << QByteArray::fromBase64(expected.toLatin1()).toHex(); + //qDebug() << QByteArray::fromBase64(operation->toXdrBase64().toLatin1()).toHex(); + + QVERIFY(expected == operation->toXdrBase64()); + } + + void testPathPaymentOperation(){ + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + KeyPair* destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); + // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 + KeyPair* issuer = KeyPair::fromSecretSeed(QString("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG")); + + // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV + KeyPair* pathIssuer1 = KeyPair::fromSecretSeed(QString("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5")); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + KeyPair* pathIssuer2 = KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); + + Asset* sendAsset = new AssetTypeNative(); + QString sendMax = "0.0001"; + Asset* destAsset = new AssetTypeCreditAlphaNum4("USD", issuer); + QString destAmount = "0.0001"; + QList path; + path.append(new AssetTypeCreditAlphaNum4("USD", pathIssuer1)); + path.append( new AssetTypeCreditAlphaNum12("TESTTEST", pathIssuer2)); + + + PathPaymentOperation* operation = new PathPaymentOperation( + sendAsset, sendMax, destination->getAccountId(), destAsset, destAmount, path); + operation->setSourceAccount(source->getAccountId()); + + + + auto xdr = operation->toXdr(); + PathPaymentOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); + + QVERIFY(1000L== xdr.operationPathPaymentStrictReceive.sendMax); + QVERIFY(1000L== xdr.operationPathPaymentStrictReceive.destAmount); + QVERIFY(dynamic_cast(parsedOperation->getSendAsset())); + QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); + QCOMPARE(destination->getAccountId(), parsedOperation->getDestination()); + QCOMPARE(sendMax, parsedOperation->getSendMax()); + QVERIFY(dynamic_cast(parsedOperation->getDestAsset())); + QCOMPARE(destAmount, parsedOperation->getDestAmount()); + QCOMPARE(path.length(), parsedOperation->getPath().length()); + + QString expected = QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAIAAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAgAAAAFVU0QAAAAAACoIKnpnw8rtrfxa276dFZo1C19mDqWXtG4ufhWrLUd1AAAAAlRFU1RURVNUAAAAAAAAAABE/ttVl8BLV0csW/xgXtbXOVf1lMyDluMiafl0IDVFIg=="); + + QVERIFY(expected==operation->toXdrBase64()); + } + + void testPathPaymentEmptyPathOperation() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + KeyPair* destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); + // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 + KeyPair* issuer = KeyPair::fromSecretSeed(QString("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG")); + + Asset* sendAsset = new AssetTypeNative(); + QString sendMax = "0.0001"; + Asset* destAsset = new AssetTypeCreditAlphaNum4("USD", issuer); + QString destAmount = "0.0001"; - void testPaymentOperation() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - KeyPair* destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); + PathPaymentOperation* operation = new PathPaymentOperation( + sendAsset, sendMax, destination->getAccountId(), destAsset, destAmount); + operation->setSourceAccount(source->getAccountId()); - Asset* asset = new AssetTypeNative(); - QString amount = "1000"; + auto xdr = operation->toXdr(); + PathPaymentOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); - Operation* operation = PaymentOperation::create(destination, asset, amount)->setSourceAccount(source->getAccountId()); + QVERIFY(1000L== xdr.operationPathPaymentStrictReceive.sendMax); - stellar::Operation xdr = operation->toXdr(); + QVERIFY(1000L== xdr.operationPathPaymentStrictReceive.destAmount); + QVERIFY(dynamic_cast(parsedOperation->getSendAsset())); + QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); + QCOMPARE(destination->getAccountId(), parsedOperation->getDestination()); + QCOMPARE(sendMax, parsedOperation->getSendMax()); + QVERIFY(dynamic_cast(parsedOperation->getDestAsset())); + QCOMPARE(destAmount, parsedOperation->getDestAmount()); + QCOMPARE(0, parsedOperation->getPath().size()); + QCOMPARE(operation->toXdrBase64(), + QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAIAAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAA==")); + } - PaymentOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); + void testPathPaymentStrictSendOperation() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + KeyPair* destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); + // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 + KeyPair* issuer = KeyPair::fromSecretSeed(QString("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG")); + + // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV + KeyPair* pathIssuer1 = KeyPair::fromSecretSeed(QString("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5")); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + KeyPair* pathIssuer2 = KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); + + Asset* sendAsset = new AssetTypeNative(); + QString sendAmount = "0.0001"; + Asset* destAsset = new AssetTypeCreditAlphaNum4("USD", issuer); + QString destMin = "0.0009"; + QList path = {new AssetTypeCreditAlphaNum4("USD", pathIssuer1), new AssetTypeCreditAlphaNum12("TESTTEST", pathIssuer2)}; + + PathPaymentStrictSendOperation* operation = PathPaymentStrictSendOperation::create( + sendAsset, sendAmount, destination, destAsset, destMin) + ->setPath(path) + ->setSourceAccount(source->getAccountId()); - QVERIFY(10000000000L==xdr.operationPayment.amount); - QVERIFY(source->getAccountId()==parsedOperation->getSourceAccount()); - //QVERIFY(destination->getAccountId()== parsedOperation->getDestination()); - QCOMPARE(parsedOperation->getDestination(),destination->getAccountId()); - QVERIFY(dynamic_cast(parsedOperation->getAsset())); - QVERIFY(amount == parsedOperation->getAmount()); - QString expected("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAEAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAAAAAAAAlQL5AA="); - //qDebug() << QByteArray::fromBase64(expected.toLatin1()).toHex(); - //qDebug() << QByteArray::fromBase64(operation->toXdrBase64().toLatin1()).toHex(); + auto xdr = operation->toXdr(); + PathPaymentStrictSendOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); + + QCOMPARE(xdr.operationPathPaymentStrictSend.sendAmount,1000L); + QCOMPARE(xdr.operationPathPaymentStrictSend.destMin,9000L); + QVERIFY(dynamic_cast(parsedOperation->getSendAsset())); + QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); + QCOMPARE(destination->getAccountId(), parsedOperation->getDestination()); + QCOMPARE(sendAmount, parsedOperation->getSendAmount()); + QVERIFY(dynamic_cast(parsedOperation->getDestAsset())); + QCOMPARE(destMin, parsedOperation->getDestMin()); + QVERIFY((path.size() == parsedOperation->getPath().size()) && std::equal(path.begin(),path.end(),parsedOperation->getPath().begin(),[](Asset* a, Asset* b){return a->equals(b);})); + + QCOMPARE(operation->toXdrBase64(),QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAA0AAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAACMoAAAAAgAAAAFVU0QAAAAAACoIKnpnw8rtrfxa276dFZo1C19mDqWXtG4ufhWrLUd1AAAAAlRFU1RURVNUAAAAAAAAAABE/ttVl8BLV0csW/xgXtbXOVf1lMyDluMiafl0IDVFIg==")); + } - QVERIFY(expected == operation->toXdrBase64()); - } + void testPathPaymentStrictSendEmptyPathOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + KeyPair* destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); + // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 + KeyPair* issuer = KeyPair::fromSecretSeed(QString("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG")); + + // // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV + // KeyPair* pathIssuer1 = KeyPair::fromSecretSeed(QString("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5")); + // // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + // KeyPair* pathIssuer2 = KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); + + Asset* sendAsset = new AssetTypeNative(); + QString sendAmount = "0.0001"; + Asset* destAsset = new AssetTypeCreditAlphaNum4("USD", issuer); + QString destMin = "0.0009"; + + PathPaymentStrictSendOperation* operation = PathPaymentStrictSendOperation::create( + sendAsset, sendAmount, destination, destAsset, destMin)->setSourceAccount(source->getAccountId()); - void testPathPaymentOperation(){ - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - KeyPair* destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); - // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 - KeyPair* issuer = KeyPair::fromSecretSeed(QString("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG")); + auto xdr = operation->toXdr(); + PathPaymentStrictSendOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); + + QCOMPARE(xdr.operationPathPaymentStrictSend.sendAmount,1000L); + QCOMPARE(xdr.operationPathPaymentStrictSend.destMin,9000L); + QVERIFY(dynamic_cast(parsedOperation->getSendAsset())); + QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); + QCOMPARE(destination->getAccountId(), parsedOperation->getDestination()); + QCOMPARE(sendAmount, parsedOperation->getSendAmount()); + QVERIFY(dynamic_cast(parsedOperation->getDestAsset())); + QCOMPARE(destMin, parsedOperation->getDestMin()); + QCOMPARE(parsedOperation->getPath().length(), 0); + + QCOMPARE(operation->toXdrBase64(),QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAA0AAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAACMoAAAAAA==")); + } - // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV - KeyPair* pathIssuer1 = KeyPair::fromSecretSeed(QString("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5")); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - KeyPair* pathIssuer2 = KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); + void testChangeTrustOperation() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - Asset* sendAsset = new AssetTypeNative(); - QString sendMax = "0.0001"; - Asset* destAsset = new AssetTypeCreditAlphaNum4("USD", issuer); - QString destAmount = "0.0001"; - QList path; - path.append(new AssetTypeCreditAlphaNum4("USD", pathIssuer1)); - path.append( new AssetTypeCreditAlphaNum12("TESTTEST", pathIssuer2)); + Asset* asset = new AssetTypeNative(); + QString limit = "922337203685.4775807"; + ChangeTrustOperation* operation = new ChangeTrustOperation(asset, limit); + operation->setSourceAccount(source->getAccountId()); - PathPaymentOperation* operation = new PathPaymentOperation( - sendAsset, sendMax, destination->getAccountId(), destAsset, destAmount, path); - operation->setSourceAccount(source->getAccountId()); + auto xdr = operation->toXdr(); + ChangeTrustOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); + QCOMPARE(9223372036854775807L, xdr.operationChangeTrust.limit); + QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); + QVERIFY(dynamic_cast(parsedOperation->getAsset())); + QCOMPARE(limit, parsedOperation->getLimit()); + QCOMPARE(operation->toXdrBase64(), + QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAYAAAAAf/////////8=")); + } - auto xdr = operation->toXdr(); - PathPaymentOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); - QVERIFY(1000L== xdr.operationPathPaymentStrictReceive.sendMax); - QVERIFY(1000L== xdr.operationPathPaymentStrictReceive.destAmount); - QVERIFY(dynamic_cast(parsedOperation->getSendAsset())); - QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); - QCOMPARE(destination->getAccountId(), parsedOperation->getDestination()); - QCOMPARE(sendMax, parsedOperation->getSendMax()); - QVERIFY(dynamic_cast(parsedOperation->getDestAsset())); - QCOMPARE(destAmount, parsedOperation->getDestAmount()); - QCOMPARE(path.length(), parsedOperation->getPath().length()); + void testAllowTrustOperation(){ + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + KeyPair* trustor = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); - QString expected = QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAIAAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAgAAAAFVU0QAAAAAACoIKnpnw8rtrfxa276dFZo1C19mDqWXtG4ufhWrLUd1AAAAAlRFU1RURVNUAAAAAAAAAABE/ttVl8BLV0csW/xgXtbXOVf1lMyDluMiafl0IDVFIg=="); - - QVERIFY(expected==operation->toXdrBase64()); - } + QString assetCode = "USDA"; + bool authorize = true; - void testPathPaymentEmptyPathOperation() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - KeyPair* destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); - // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 - KeyPair* issuer = KeyPair::fromSecretSeed(QString("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG")); - - - Asset* sendAsset = new AssetTypeNative(); - QString sendMax = "0.0001"; - Asset* destAsset = new AssetTypeCreditAlphaNum4("USD", issuer); - QString destAmount = "0.0001"; - - PathPaymentOperation* operation = new PathPaymentOperation( - sendAsset, sendMax, destination->getAccountId(), destAsset, destAmount); - operation->setSourceAccount(source->getAccountId()); - - auto xdr = operation->toXdr(); - PathPaymentOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); - - QVERIFY(1000L== xdr.operationPathPaymentStrictReceive.sendMax); - - QVERIFY(1000L== xdr.operationPathPaymentStrictReceive.destAmount); - QVERIFY(dynamic_cast(parsedOperation->getSendAsset())); - QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); - QCOMPARE(destination->getAccountId(), parsedOperation->getDestination()); - QCOMPARE(sendMax, parsedOperation->getSendMax()); - QVERIFY(dynamic_cast(parsedOperation->getDestAsset())); - QCOMPARE(destAmount, parsedOperation->getDestAmount()); - QCOMPARE(0, parsedOperation->getPath().size()); - - QCOMPARE(operation->toXdrBase64(), - QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAIAAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAA==")); - } - - void testPathPaymentStrictSendOperation() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - KeyPair* destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); - // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 - KeyPair* issuer = KeyPair::fromSecretSeed(QString("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG")); - - // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV - KeyPair* pathIssuer1 = KeyPair::fromSecretSeed(QString("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5")); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - KeyPair* pathIssuer2 = KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); - - Asset* sendAsset = new AssetTypeNative(); - QString sendAmount = "0.0001"; - Asset* destAsset = new AssetTypeCreditAlphaNum4("USD", issuer); - QString destMin = "0.0009"; - QList path = {new AssetTypeCreditAlphaNum4("USD", pathIssuer1), new AssetTypeCreditAlphaNum12("TESTTEST", pathIssuer2)}; - - PathPaymentStrictSendOperation* operation = PathPaymentStrictSendOperation::create( - sendAsset, sendAmount, destination, destAsset, destMin) - ->setPath(path) - ->setSourceAccount(source->getAccountId()); - - auto xdr = operation->toXdr(); - PathPaymentStrictSendOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); - - QCOMPARE(xdr.operationPathPaymentStrictSend.sendAmount,1000L); - QCOMPARE(xdr.operationPathPaymentStrictSend.destMin,9000L); - QVERIFY(dynamic_cast(parsedOperation->getSendAsset())); - QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); - QCOMPARE(destination->getAccountId(), parsedOperation->getDestination()); - QCOMPARE(sendAmount, parsedOperation->getSendAmount()); - QVERIFY(dynamic_cast(parsedOperation->getDestAsset())); - QCOMPARE(destMin, parsedOperation->getDestMin()); - QVERIFY((path.size() == parsedOperation->getPath().size()) && std::equal(path.begin(),path.end(),parsedOperation->getPath().begin(),[](Asset* a, Asset* b){return a->equals(b);})); - - QCOMPARE(operation->toXdrBase64(),QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAA0AAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAACMoAAAAAgAAAAFVU0QAAAAAACoIKnpnw8rtrfxa276dFZo1C19mDqWXtG4ufhWrLUd1AAAAAlRFU1RURVNUAAAAAAAAAABE/ttVl8BLV0csW/xgXtbXOVf1lMyDluMiafl0IDVFIg==")); - } - - void testPathPaymentStrictSendEmptyPathOperation() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - KeyPair* destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); - // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 - KeyPair* issuer = KeyPair::fromSecretSeed(QString("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG")); - -// // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV -// KeyPair* pathIssuer1 = KeyPair::fromSecretSeed(QString("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5")); -// // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR -// KeyPair* pathIssuer2 = KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); - - Asset* sendAsset = new AssetTypeNative(); - QString sendAmount = "0.0001"; - Asset* destAsset = new AssetTypeCreditAlphaNum4("USD", issuer); - QString destMin = "0.0009"; - - PathPaymentStrictSendOperation* operation = PathPaymentStrictSendOperation::create( - sendAsset, sendAmount, destination, destAsset, destMin)->setSourceAccount(source->getAccountId()); - - auto xdr = operation->toXdr(); - PathPaymentStrictSendOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); - - QCOMPARE(xdr.operationPathPaymentStrictSend.sendAmount,1000L); - QCOMPARE(xdr.operationPathPaymentStrictSend.destMin,9000L); - QVERIFY(dynamic_cast(parsedOperation->getSendAsset())); - QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); - QCOMPARE(destination->getAccountId(), parsedOperation->getDestination()); - QCOMPARE(sendAmount, parsedOperation->getSendAmount()); - QVERIFY(dynamic_cast(parsedOperation->getDestAsset())); - QCOMPARE(destMin, parsedOperation->getDestMin()); - QCOMPARE(parsedOperation->getPath().length(), 0); - - QCOMPARE(operation->toXdrBase64(),QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAA0AAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAACMoAAAAAA==")); - } - - void testChangeTrustOperation() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - - Asset* asset = new AssetTypeNative(); - QString limit = "922337203685.4775807"; - - ChangeTrustOperation* operation = new ChangeTrustOperation(asset, limit); - operation->setSourceAccount(source->getAccountId()); - - auto xdr = operation->toXdr(); - ChangeTrustOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); - - QCOMPARE(9223372036854775807L, xdr.operationChangeTrust.limit); - QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); - QVERIFY(dynamic_cast(parsedOperation->getAsset())); - QCOMPARE(limit, parsedOperation->getLimit()); - - QCOMPARE(operation->toXdrBase64(), - QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAYAAAAAf/////////8=")); - } - - - void testAllowTrustOperation(){ - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - KeyPair* trustor = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); - - QString assetCode = "USDA"; - bool authorize = true; - - AllowTrustOperation operation(trustor, assetCode, authorize, false); - operation.setSourceAccount(source->getAccountId()); - - - auto xdr = operation.toXdr(); - AllowTrustOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); - - QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); - QCOMPARE(trustor->getAccountId(), parsedOperation->getTrustor()->getAccountId()); - QCOMPARE(assetCode, parsedOperation->getAssetCode()); - QCOMPARE(authorize, parsedOperation->getAuthorize()); - QCOMPARE(operation.toXdrBase64(), - QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAcAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEQQAAAAE=") - ); - } - - void testAllowTrustOperationAssetCodeBuffer() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - KeyPair* trustor = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); - - QString assetCode = "USDABC"; - bool authorize = true; - - AllowTrustOperation* operation = AllowTrustOperation::create(trustor, assetCode, authorize) - ->setSourceAccount(source->getAccountId()); - - auto xdr = operation->toXdr(); - AllowTrustOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); - - QCOMPARE(assetCode, parsedOperation->getAssetCode()); - } - - void testSetOptionsOperation(){ - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - KeyPair* inflationDestination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - auto signer = Signer::ed25519PublicKey(KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"))); - - Integer clearFlags = 1; - Integer setFlags = 1; - Integer masterKeyWeight = 1; - Integer lowThreshold = 2; - Integer mediumThreshold = 3; - Integer highThreshold = 4; - QString homeDomain = "stellar.org"; - Integer signerWeight = 1; - - SetOptionsOperation* operation = SetOptionsOperation::create() - ->setInflationDestination(inflationDestination) - ->setClearFlags(clearFlags) - ->setSetFlags(setFlags) - ->setMasterKeyWeight(masterKeyWeight) - ->setLowThreshold(lowThreshold) - ->setMediumThreshold(mediumThreshold) - ->setHighThreshold(highThreshold) - ->setHomeDomain(homeDomain) - ->setSigner(signer, signerWeight) - ->setSourceAccount(source->getAccountId()); - - auto xdr = operation->toXdr(); - SetOptionsOperation* parsedOperation = static_cast(SetOptionsOperation::fromXdr(xdr)); - - QCOMPARE(inflationDestination->getAccountId(), parsedOperation->getInflationDestination()->getAccountId()); - QCOMPARE(clearFlags, parsedOperation->getClearFlags()); - QCOMPARE(setFlags, parsedOperation->getSetFlags()); - QCOMPARE(masterKeyWeight, parsedOperation->getMasterKeyWeight()); - QCOMPARE(lowThreshold, parsedOperation->getLowThreshold()); - QCOMPARE(mediumThreshold, parsedOperation->getMediumThreshold()); - QCOMPARE(highThreshold, parsedOperation->getHighThreshold()); - QCOMPARE(homeDomain, parsedOperation->getHomeDomain()); - QCOMPARE(signer.type, parsedOperation->getSigner()->type); - QVERIFY(memcmp(signer.ed25519, parsedOperation->getSigner()->ed25519,sizeof(signer.ed25519))==0); - QCOMPARE(signerWeight, parsedOperation->getSignerWeight()); - QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); - - QCOMPARE(operation->toXdrBase64() - ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAUAAAABAAAAAO3gUmG83C+VCqO6FztuMtXJF/l7grZA7MjRzqdZ9W8QAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAIAAAABAAAAAwAAAAEAAAAEAAAAAQAAAAtzdGVsbGFyLm9yZwAAAAABAAAAAET+21WXwEtXRyxb/GBe1tc5V/WUzIOW4yJp+XQgNUUiAAAAAQ==")); - } - - - void testSetOptionsOperationSingleField() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - - QString homeDomain = "stellar.org"; - - SetOptionsOperation* operation = SetOptionsOperation::create() - ->setHomeDomain(homeDomain) - ->setSourceAccount(source->getAccountId()); - - auto xdr = operation->toXdr(); - SetOptionsOperation* parsedOperation = static_cast(SetOptionsOperation::fromXdr(xdr)); - - QVERIFY(parsedOperation->getInflationDestination()==nullptr); - QVERIFY(parsedOperation->getClearFlags().isNull()); - QVERIFY(parsedOperation->getSetFlags().isNull()); - QVERIFY(parsedOperation->getMasterKeyWeight().isNull()); - QVERIFY(parsedOperation->getLowThreshold().isNull()); - QVERIFY(parsedOperation->getMediumThreshold().isNull()); - QVERIFY(parsedOperation->getHighThreshold().isNull()); - QCOMPARE(homeDomain, parsedOperation->getHomeDomain()); - QVERIFY(parsedOperation->getSigner()==nullptr); - QVERIFY(parsedOperation->getSignerWeight().isNull()); - QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); - - QCOMPARE(operation->toXdrBase64() - ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAtzdGVsbGFyLm9yZwAAAAAA")); - } - - - void testSetOptionsOperationSignerSha256() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - - QByteArray preimage = "stellar.org"; - QByteArray hash = Util::hash(preimage); - - SetOptionsOperation* operation = SetOptionsOperation::create() - ->setSigner(Signer::sha256Hash(hash), 10) - ->setSourceAccount(source->getAccountId()); - - auto xdr = operation->toXdr(); - - SetOptionsOperation* parsedOperation = static_cast(SetOptionsOperation::fromXdr(xdr)); - - QVERIFY(!parsedOperation->getInflationDestination()); - - QVERIFY(parsedOperation->getClearFlags().isNull()); - - QVERIFY(parsedOperation->getSetFlags().isNull()); - QVERIFY(parsedOperation->getMasterKeyWeight().isNull()); - QVERIFY(parsedOperation->getLowThreshold().isNull()); - QVERIFY(parsedOperation->getMediumThreshold().isNull()); - QVERIFY(parsedOperation->getHighThreshold().isNull()); - QVERIFY(parsedOperation->getHomeDomain().isNull()); - QVERIFY(memcmp(hash.data(), parsedOperation->getSigner()->hashX,static_cast(hash.size()))==0); - QCOMPARE(10, static_cast(parsedOperation->getSignerWeight())); - QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); - - QCOMPARE(operation->toXdrBase64() - ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAACbpRqMkaQAfCYSk/n3xIl4fCoHfKqxF34ht2iuvSYEJQAAAAK")); - } - - void testSetOptionsOperationPreAuthTxSigner() { + AllowTrustOperation operation(trustor, assetCode, authorize, false); + operation.setSourceAccount(source->getAccountId()); + + + auto xdr = operation.toXdr(); + AllowTrustOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); + + QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); + QCOMPARE(trustor->getAccountId(), parsedOperation->getTrustor()->getAccountId()); + QCOMPARE(assetCode, parsedOperation->getAssetCode()); + QCOMPARE(authorize, parsedOperation->getAuthorize()); + QCOMPARE(operation.toXdrBase64(), + QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAcAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEQQAAAAE=") + ); + } + + void testAllowTrustOperationAssetCodeBuffer() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + KeyPair* trustor = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); + + QString assetCode = "USDABC"; + bool authorize = true; + + AllowTrustOperation* operation = AllowTrustOperation::create(trustor, assetCode, authorize) + ->setSourceAccount(source->getAccountId()); + + auto xdr = operation->toXdr(); + AllowTrustOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); + + QCOMPARE(assetCode, parsedOperation->getAssetCode()); + } + + void testSetOptionsOperation(){ + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + KeyPair* inflationDestination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + auto signer = Signer::ed25519PublicKey(KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"))); + + Integer clearFlags = 1; + Integer setFlags = 1; + Integer masterKeyWeight = 1; + Integer lowThreshold = 2; + Integer mediumThreshold = 3; + Integer highThreshold = 4; + QString homeDomain = "stellar.org"; + Integer signerWeight = 1; + + SetOptionsOperation* operation = SetOptionsOperation::create() + ->setInflationDestination(inflationDestination) + ->setClearFlags(clearFlags) + ->setSetFlags(setFlags) + ->setMasterKeyWeight(masterKeyWeight) + ->setLowThreshold(lowThreshold) + ->setMediumThreshold(mediumThreshold) + ->setHighThreshold(highThreshold) + ->setHomeDomain(homeDomain) + ->setSigner(signer, signerWeight) + ->setSourceAccount(source->getAccountId()); + + auto xdr = operation->toXdr(); + SetOptionsOperation* parsedOperation = static_cast(SetOptionsOperation::fromXdr(xdr)); + + QCOMPARE(inflationDestination->getAccountId(), parsedOperation->getInflationDestination()->getAccountId()); + QCOMPARE(clearFlags, parsedOperation->getClearFlags()); + QCOMPARE(setFlags, parsedOperation->getSetFlags()); + QCOMPARE(masterKeyWeight, parsedOperation->getMasterKeyWeight()); + QCOMPARE(lowThreshold, parsedOperation->getLowThreshold()); + QCOMPARE(mediumThreshold, parsedOperation->getMediumThreshold()); + QCOMPARE(highThreshold, parsedOperation->getHighThreshold()); + QCOMPARE(homeDomain, parsedOperation->getHomeDomain()); + QCOMPARE(signer.type, parsedOperation->getSigner()->type); + QVERIFY(memcmp(signer.ed25519, parsedOperation->getSigner()->ed25519,sizeof(signer.ed25519))==0); + QCOMPARE(signerWeight, parsedOperation->getSignerWeight()); + QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); + + QCOMPARE(operation->toXdrBase64() + ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAUAAAABAAAAAO3gUmG83C+VCqO6FztuMtXJF/l7grZA7MjRzqdZ9W8QAAAAAQAAAAEAAAABAAAAAQAAAAEAAAABAAAAAQAAAAIAAAABAAAAAwAAAAEAAAAEAAAAAQAAAAtzdGVsbGFyLm9yZwAAAAABAAAAAET+21WXwEtXRyxb/GBe1tc5V/WUzIOW4yJp+XQgNUUiAAAAAQ==")); + } + + + void testSetOptionsOperationSingleField() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + + QString homeDomain = "stellar.org"; + + SetOptionsOperation* operation = SetOptionsOperation::create() + ->setHomeDomain(homeDomain) + ->setSourceAccount(source->getAccountId()); + + auto xdr = operation->toXdr(); + SetOptionsOperation* parsedOperation = static_cast(SetOptionsOperation::fromXdr(xdr)); + + QVERIFY(parsedOperation->getInflationDestination()==nullptr); + QVERIFY(parsedOperation->getClearFlags().isNull()); + QVERIFY(parsedOperation->getSetFlags().isNull()); + QVERIFY(parsedOperation->getMasterKeyWeight().isNull()); + QVERIFY(parsedOperation->getLowThreshold().isNull()); + QVERIFY(parsedOperation->getMediumThreshold().isNull()); + QVERIFY(parsedOperation->getHighThreshold().isNull()); + QCOMPARE(homeDomain, parsedOperation->getHomeDomain()); + QVERIFY(parsedOperation->getSigner()==nullptr); + QVERIFY(parsedOperation->getSignerWeight().isNull()); + QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); + + QCOMPARE(operation->toXdrBase64() + ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAtzdGVsbGFyLm9yZwAAAAAA")); + } + + + void testSetOptionsOperationSignerSha256() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + + QByteArray preimage = "stellar.org"; + QByteArray hash = Util::hash(preimage); + + SetOptionsOperation* operation = SetOptionsOperation::create() + ->setSigner(Signer::sha256Hash(hash), 10) + ->setSourceAccount(source->getAccountId()); + + auto xdr = operation->toXdr(); + + SetOptionsOperation* parsedOperation = static_cast(SetOptionsOperation::fromXdr(xdr)); + + QVERIFY(!parsedOperation->getInflationDestination()); + + QVERIFY(parsedOperation->getClearFlags().isNull()); + + QVERIFY(parsedOperation->getSetFlags().isNull()); + QVERIFY(parsedOperation->getMasterKeyWeight().isNull()); + QVERIFY(parsedOperation->getLowThreshold().isNull()); + QVERIFY(parsedOperation->getMediumThreshold().isNull()); + QVERIFY(parsedOperation->getHighThreshold().isNull()); + QVERIFY(parsedOperation->getHomeDomain().isNull()); + QVERIFY(memcmp(hash.data(), parsedOperation->getSigner()->hashX,static_cast(hash.size()))==0); + QCOMPARE(10, static_cast(parsedOperation->getSignerWeight())); + QCOMPARE(source->getAccountId(), parsedOperation->getSourceAccount()); + + QCOMPARE(operation->toXdrBase64() + ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAACbpRqMkaQAfCYSk/n3xIl4fCoHfKqxF34ht2iuvSYEJQAAAAK")); + } + + void testSetOptionsOperationPreAuthTxSigner() { Network::useTestNetwork(); - // GBPMKIRA2OQW2XZZQUCQILI5TMVZ6JNRKM423BSAISDM7ZFWQ6KWEBC4 - KeyPair* source = KeyPair::fromSecretSeed(QString("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS")); - KeyPair* destination = KeyPair::fromAccountId(QString("GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR")); - - qint64 sequenceNumber = 2908908335136768L; - Account* account = new Account(source, sequenceNumber); - - - Transaction* transaction = Transaction::Builder(account).addOperation(new CreateAccountOperation(destination,"2000")) - .setTimeout(Transaction::Builder::TIMEOUT_INFINITE) - .setBaseFee(Transaction::Builder::BASE_FEE) - .build(); - - - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* opSource = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - - SetOptionsOperation* operation = SetOptionsOperation::create() - ->setSigner(Signer::preAuthTx(transaction), 10) - ->setSourceAccount(opSource->getAccountId()); - - auto xdr = operation->toXdr(); - SetOptionsOperation* parsedOperation = static_cast(SetOptionsOperation::fromXdr(xdr)); - - QVERIFY(!parsedOperation->getInflationDestination()); - QVERIFY(parsedOperation->getClearFlags().isNull()); - QVERIFY(parsedOperation->getSetFlags().isNull()); - QVERIFY(parsedOperation->getMasterKeyWeight().isNull()); - QVERIFY(parsedOperation->getLowThreshold().isNull()); - QVERIFY(parsedOperation->getMediumThreshold().isNull()); - QVERIFY(parsedOperation->getHighThreshold().isNull()); - QVERIFY(parsedOperation->getHomeDomain().isNull()); - QVERIFY(memcmp(transaction->hash().data(), parsedOperation->getSigner()->preAuthTx,sizeof(parsedOperation->getSigner()->preAuthTx))==0); - QCOMPARE(Integer(10), parsedOperation->getSignerWeight()); - QCOMPARE(opSource->getAccountId(), parsedOperation->getSourceAccount()); - - QCOMPARE(operation->toXdrBase64() - ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAB1vRBIRC3w7ZH5rQa17hIBKUwZTvBP4kNmSP7jVyw1fQAAAAK")); - } - - - void testManageSellOfferOperation() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - KeyPair* issuer = KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); - - Asset* selling = new AssetTypeNative(); - Asset* buying = Asset::createNonNativeAsset("USD", issuer); - QString amount = "0.00001"; - QString price = "0.85334384"; // n=5333399 d=6250000 - Price* priceObj = Price::fromString(price); - qint64 offerId = 1; - - ManageSellOfferOperation* operation = ManageSellOfferOperation::create(selling, buying, amount, price) - ->setOfferId(offerId) - ->setSourceAccount(source->getAccountId()); - - auto xdr = operation->toXdr(); - ManageSellOfferOperation* parsedOperation = (ManageSellOfferOperation*) ManageSellOfferOperation::fromXdr(xdr); - - - QCOMPARE(xdr.operationManageSellOffer.amount,(qint64)100L); - QVERIFY(dynamic_cast(parsedOperation->getSelling())); - QVERIFY(dynamic_cast(parsedOperation->getBuying())); - QVERIFY(parsedOperation->getBuying()->equals(buying)); - QCOMPARE(parsedOperation->getAmount(),amount); - QCOMPARE(parsedOperation->getPrice(),price); - QCOMPARE(priceObj->getNumerator(), 5333399); - QCOMPARE(priceObj->getDenominator(), 6250000); - QCOMPARE(parsedOperation->getOfferId(),offerId); - - QCOMPARE(operation->toXdrBase64() - ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAMAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZABRYZcAX14QAAAAAAAAAAE=")); - } - - void testManageBuyOfferOperation() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - KeyPair* issuer = KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); - - Asset* selling = new AssetTypeNative(); - Asset* buying = Asset::createNonNativeAsset("USD", issuer); - QString amount = "0.00001"; - QString price = "0.85334384"; // n=5333399 d=6250000 - Price* priceObj = Price::fromString(price); - qint64 offerId = 1; - - ManageBuyOfferOperation* operation = ManageBuyOfferOperation::create(selling, buying, amount, price) - ->setOfferId(offerId) - ->setSourceAccount(source->getAccountId()); - - auto xdr = operation->toXdr(); - ManageBuyOfferOperation* parsedOperation = (ManageBuyOfferOperation*) ManageBuyOfferOperation::fromXdr(xdr); - - - QCOMPARE(xdr.operationManageBuyOffer.buyAmount,(qint64)100L); - QVERIFY(dynamic_cast(parsedOperation->getSelling())); - QVERIFY(dynamic_cast(parsedOperation->getBuying())); - QVERIFY(parsedOperation->getBuying()->equals(buying)); - QCOMPARE(parsedOperation->getAmount(),amount); - QCOMPARE(parsedOperation->getPrice(),price); - QCOMPARE(priceObj->getNumerator(), 5333399); - QCOMPARE(priceObj->getDenominator(), 6250000); - QCOMPARE(parsedOperation->getOfferId(),offerId); - - QCOMPARE(operation->toXdrBase64() - ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAwAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZABRYZcAX14QAAAAAAAAAAE=")); - } - - void testManageSellOfferOperation_BadArithmeticRegression(){ + // GBPMKIRA2OQW2XZZQUCQILI5TMVZ6JNRKM423BSAISDM7ZFWQ6KWEBC4 + KeyPair* source = KeyPair::fromSecretSeed(QString("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS")); + KeyPair* destination = KeyPair::fromAccountId(QString("GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR")); + + qint64 sequenceNumber = 2908908335136768L; + Account* account = new Account(source, sequenceNumber); + + + Transaction* transaction = Transaction::Builder(account).addOperation(new CreateAccountOperation(destination,"2000")) + .setTimeout(Transaction::Builder::TIMEOUT_INFINITE) + .setBaseFee(Transaction::Builder::BASE_FEE) + .build(); + + + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* opSource = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + + SetOptionsOperation* operation = SetOptionsOperation::create() + ->setSigner(Signer::preAuthTx(transaction), 10) + ->setSourceAccount(opSource->getAccountId()); + + auto xdr = operation->toXdr(); + SetOptionsOperation* parsedOperation = static_cast(SetOptionsOperation::fromXdr(xdr)); + + QVERIFY(!parsedOperation->getInflationDestination()); + QVERIFY(parsedOperation->getClearFlags().isNull()); + QVERIFY(parsedOperation->getSetFlags().isNull()); + QVERIFY(parsedOperation->getMasterKeyWeight().isNull()); + QVERIFY(parsedOperation->getLowThreshold().isNull()); + QVERIFY(parsedOperation->getMediumThreshold().isNull()); + QVERIFY(parsedOperation->getHighThreshold().isNull()); + QVERIFY(parsedOperation->getHomeDomain().isNull()); + QVERIFY(memcmp(transaction->hash().data(), parsedOperation->getSigner()->preAuthTx,sizeof(parsedOperation->getSigner()->preAuthTx))==0); + QCOMPARE(Integer(10), parsedOperation->getSignerWeight()); + QCOMPARE(opSource->getAccountId(), parsedOperation->getSourceAccount()); + + QCOMPARE(operation->toXdrBase64() + ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAB1vRBIRC3w7ZH5rQa17hIBKUwZTvBP4kNmSP7jVyw1fQAAAAK")); + } + + + void testManageSellOfferOperation() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + KeyPair* issuer = KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); + + Asset* selling = new AssetTypeNative(); + Asset* buying = Asset::createNonNativeAsset("USD", issuer); + QString amount = "0.00001"; + QString price = "0.85334384"; // n=5333399 d=6250000 + Price* priceObj = Price::fromString(price); + qint64 offerId = 1; + + ManageSellOfferOperation* operation = ManageSellOfferOperation::create(selling, buying, amount, price) + ->setOfferId(offerId) + ->setSourceAccount(source->getAccountId()); + + auto xdr = operation->toXdr(); + ManageSellOfferOperation* parsedOperation = (ManageSellOfferOperation*) ManageSellOfferOperation::fromXdr(xdr); + + + QCOMPARE(xdr.operationManageSellOffer.amount,(qint64)100L); + QVERIFY(dynamic_cast(parsedOperation->getSelling())); + QVERIFY(dynamic_cast(parsedOperation->getBuying())); + QVERIFY(parsedOperation->getBuying()->equals(buying)); + QCOMPARE(parsedOperation->getAmount(),amount); + QCOMPARE(parsedOperation->getPrice(),price); + QCOMPARE(priceObj->getNumerator(), 5333399); + QCOMPARE(priceObj->getDenominator(), 6250000); + QCOMPARE(parsedOperation->getOfferId(),offerId); + + QCOMPARE(operation->toXdrBase64() + ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAMAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZABRYZcAX14QAAAAAAAAAAE=")); + } + + void testManageBuyOfferOperation() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + KeyPair* issuer = KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); + + Asset* selling = new AssetTypeNative(); + Asset* buying = Asset::createNonNativeAsset("USD", issuer); + QString amount = "0.00001"; + QString price = "0.85334384"; // n=5333399 d=6250000 + Price* priceObj = Price::fromString(price); + qint64 offerId = 1; + + ManageBuyOfferOperation* operation = ManageBuyOfferOperation::create(selling, buying, amount, price) + ->setOfferId(offerId) + ->setSourceAccount(source->getAccountId()); + + auto xdr = operation->toXdr(); + ManageBuyOfferOperation* parsedOperation = (ManageBuyOfferOperation*) ManageBuyOfferOperation::fromXdr(xdr); + + + QCOMPARE(xdr.operationManageBuyOffer.buyAmount,(qint64)100L); + QVERIFY(dynamic_cast(parsedOperation->getSelling())); + QVERIFY(dynamic_cast(parsedOperation->getBuying())); + QVERIFY(parsedOperation->getBuying()->equals(buying)); + QCOMPARE(parsedOperation->getAmount(),amount); + QCOMPARE(parsedOperation->getPrice(),price); + QCOMPARE(priceObj->getNumerator(), 5333399); + QCOMPARE(priceObj->getDenominator(), 6250000); + QCOMPARE(parsedOperation->getOfferId(),offerId); + + QCOMPARE(operation->toXdrBase64() + ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAwAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZABRYZcAX14QAAAAAAAAAAE=")); + } + + void testManageSellOfferOperation_BadArithmeticRegression(){ // from https://github.com/stellar/java-stellar-sdk/issues/183 QByteArray transactionEnvelopeToDecode = QByteArray::fromBase64("AAAAAButy5zasS3DLZ5uFpZHL25aiHUfKRwdv1+3Wp12Ce7XAAAAZAEyGwYAAAAOAAAAAAAAAAAAAAABAAAAAQAAAAAbrcuc2rEtwy2ebhaWRy9uWoh1HykcHb9ft1qddgnu1wAAAAMAAAAAAAAAAUtJTgAAAAAARkrT28ebM6YQyhVZi1ttlwq/dk6ijTpyTNuHIMgUp+EAAAAAAAARPSfDKZ0AAv7oAAAAAAAAAAAAAAAAAAAAAXYJ7tcAAABAbE8rEoFt0Hcv41iwVCl74C1Hyr+Lj8ZyaYn7zTJhezClbc+pTW1KgYFIZOJiGVth2xFnBT1pMXuQkVdTlB3FCw=="); @@ -589,9 +593,9 @@ private slots: ManageSellOfferOperation* op = (ManageSellOfferOperation*)Operation::fromXdr(opXdr); QCOMPARE(op->getPrice(),"3397.893306099996"); - } + } - void testManageBuyOfferOperation_BadArithmeticRegression(){ + void testManageBuyOfferOperation_BadArithmeticRegression(){ // from https://github.com/stellar/java-stellar-sdk/issues/183 QByteArray transactionEnvelopeToDecode = QByteArray::fromBase64("AAAAAButy5zasS3DLZ5uFpZHL25aiHUfKRwdv1+3Wp12Ce7XAAAAZAEyGwYAAAAxAAAAAAAAAAAAAAABAAAAAQAAAAAbrcuc2rEtwy2ebhaWRy9uWoh1HykcHb9ft1qddgnu1wAAAAwAAAABS0lOAAAAAABGStPbx5szphDKFVmLW22XCr92TqKNOnJM24cgyBSn4QAAAAAAAAAAACNyOCfDKZ0AAv7oAAAAAAABv1IAAAAAAAAAAA=="); @@ -607,252 +611,390 @@ private slots: ManageBuyOfferOperation* op = (ManageBuyOfferOperation*)t->getOperations().first();//Operation::fromXdr(transactionEnvelope.tx.operations.value[0]); QCOMPARE(op->getPrice(),"3397.893306099996");//3397.893306099995925186 - } - - void testCreatePassiveSellOfferOperation() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - KeyPair* issuer = KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); - - Asset* selling = new AssetTypeNative(); - Asset* buying = Asset::createNonNativeAsset("USD", issuer); - QString amount = "0.00001"; - QString price = "2.93850088"; // n=36731261 d=12500000 - Price* priceObj = Price::fromString(price); + } - CreatePassiveSellOfferOperation* operation = new CreatePassiveSellOfferOperation(selling, buying, amount, price); - operation->setSourceAccount(source->getAccountId()); + void testCreatePassiveSellOfferOperation() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + KeyPair* issuer = KeyPair::fromSecretSeed(QString("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); - auto xdr = operation->toXdr(); - CreatePassiveSellOfferOperation* parsedOperation = static_cast(CreatePassiveSellOfferOperation::fromXdr(xdr)); + Asset* selling = new AssetTypeNative(); + Asset* buying = Asset::createNonNativeAsset("USD", issuer); + QString amount = "0.00001"; + QString price = "2.93850088"; // n=36731261 d=12500000 + Price* priceObj = Price::fromString(price); - QVERIFY(100L == xdr.operationCreatePassiveSellOffer.amount); - QVERIFY(dynamic_cast(parsedOperation->getSelling())); - QVERIFY(dynamic_cast(parsedOperation->getBuying())); - QVERIFY(parsedOperation->getBuying()->equals(buying)); - QCOMPARE(amount, parsedOperation->getAmount()); - QCOMPARE(price, parsedOperation->getPrice()); - QCOMPARE(priceObj->getNumerator(), 36731261); - QCOMPARE(priceObj->getDenominator(), 12500000); + CreatePassiveSellOfferOperation* operation = new CreatePassiveSellOfferOperation(selling, buying, amount, price); + operation->setSourceAccount(source->getAccountId()); - QCOMPARE(operation->toXdrBase64(), - QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAQAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZAIweX0Avrwg")); - } + auto xdr = operation->toXdr(); + CreatePassiveSellOfferOperation* parsedOperation = static_cast(CreatePassiveSellOfferOperation::fromXdr(xdr)); + + QVERIFY(100L == xdr.operationCreatePassiveSellOffer.amount); + QVERIFY(dynamic_cast(parsedOperation->getSelling())); + QVERIFY(dynamic_cast(parsedOperation->getBuying())); + QVERIFY(parsedOperation->getBuying()->equals(buying)); + QCOMPARE(amount, parsedOperation->getAmount()); + QCOMPARE(price, parsedOperation->getPrice()); + QCOMPARE(priceObj->getNumerator(), 36731261); + QCOMPARE(priceObj->getDenominator(), 12500000); + + QCOMPARE(operation->toXdrBase64(), + QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAQAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZAIweX0Avrwg")); + } - void testAccountMergeOperation() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - KeyPair* destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); + void testAccountMergeOperation() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + KeyPair* destination = KeyPair::fromSecretSeed(QString("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII")); - AccountMergeOperation* operation = new AccountMergeOperation(destination->getAccountId()); - operation->setSourceAccount(source->getAccountId()); + AccountMergeOperation* operation = new AccountMergeOperation(destination->getAccountId()); + operation->setSourceAccount(source->getAccountId()); - stellar::Operation xdr = operation->toXdr(); + stellar::Operation xdr = operation->toXdr(); - AccountMergeOperation* parsedOperation = (AccountMergeOperation*) Operation::fromXdr(xdr); + AccountMergeOperation* parsedOperation = (AccountMergeOperation*) Operation::fromXdr(xdr); - QCOMPARE(destination->getAccountId(), parsedOperation->getDestination()); + QCOMPARE(destination->getAccountId(), parsedOperation->getDestination()); - QCOMPARE(QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAgAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxA="), - operation->toXdrBase64()); - } + QCOMPARE(QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAgAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxA="), + operation->toXdrBase64()); + } - void testManageDataOperation() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + void testManageDataOperation() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - QByteArray data = QByteArray::fromHex("0001020304"); + QByteArray data = QByteArray::fromHex("0001020304"); - ManageDataOperation* operation = new ManageDataOperation("test", data); - operation->setSourceAccount(source->getAccountId()); + ManageDataOperation* operation = new ManageDataOperation("test", data); + operation->setSourceAccount(source->getAccountId()); - auto xdr = operation->toXdr(); + auto xdr = operation->toXdr(); - ManageDataOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); + ManageDataOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); - QCOMPARE(parsedOperation->getName(),QString("test")); - QCOMPARE(parsedOperation->getValue(),data); + QCOMPARE(parsedOperation->getName(),QString("test")); + QCOMPARE(parsedOperation->getValue(),data); - QCOMPARE(operation->toXdrBase64(), - QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAoAAAAEdGVzdAAAAAEAAAAFAAECAwQAAAA=")); - } + QCOMPARE(operation->toXdrBase64(), + QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAoAAAAEdGVzdAAAAAEAAAAFAAECAwQAAAA=")); + } - void testManageDataOperationEmptyValue() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + void testManageDataOperationEmptyValue() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - ManageDataOperation* operation = new ManageDataOperation("test"); - operation->setSourceAccount(source->getAccountId()); + ManageDataOperation* operation = new ManageDataOperation("test"); + operation->setSourceAccount(source->getAccountId()); - auto xdr = operation->toXdr(); + auto xdr = operation->toXdr(); - ManageDataOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); + ManageDataOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); - QCOMPARE(parsedOperation->getName(),QString("test")); - QCOMPARE(parsedOperation->getValue(),QByteArray()); + QCOMPARE(parsedOperation->getName(),QString("test")); + QCOMPARE(parsedOperation->getValue(),QByteArray()); - QCOMPARE(operation->toXdrBase64() - ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAoAAAAEdGVzdAAAAAA=")); - } + QCOMPARE(operation->toXdrBase64() + ,QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAoAAAAEdGVzdAAAAAA=")); + } - void testBumpSequence() { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); - BumpSequenceOperation* operation = BumpSequenceOperation::create(156L) - ->setSourceAccount(source->getAccountId()); + void testBumpSequence() { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + KeyPair* source = KeyPair::fromSecretSeed(QString("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK")); + BumpSequenceOperation* operation = BumpSequenceOperation::create(156L) + ->setSourceAccount(source->getAccountId()); auto xdr = operation->toXdr(); BumpSequenceOperation* parsedOperation = static_cast(Operation::fromXdr(xdr)); QCOMPARE(parsedOperation->getBumpTo(),156L); QCOMPARE(operation->toXdrBase64(),QString("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAsAAAAAAAAAnA==")); - } - - void testToXdrAmount() { - QVERIFY(0L== Operation::toXdrAmount("0")); - QVERIFY(1L== Operation::toXdrAmount("0.0000001")); - QVERIFY(10000000L== Operation::toXdrAmount("1")); - QVERIFY(11234567L== Operation::toXdrAmount("1.1234567")); - QVERIFY(729912843007381L== Operation::toXdrAmount("72991284.3007381")); - QVERIFY(729912843007381L== Operation::toXdrAmount("72991284.30073810")); - QVERIFY(1014016711446800155L== Operation::toXdrAmount("101401671144.6800155")); - qDebug() << Operation::toXdrAmount("922337203685.4775807"); - QVERIFY(9223372036854775807UL== Operation::toXdrAmount("922337203685.4775807")); - try { - Operation::toXdrAmount("0.00000001"); - QFAIL("expected exception"); - } - catch (std::exception e) { - } - try { - Operation::toXdrAmount("72991284.30073811"); - QFAIL("expected exception"); - } - catch(std::exception e){ - } - } - - - void testFromXdrAmount() { - QCOMPARE(QString("0"), Operation::fromXdrAmount(0L)); - QCOMPARE(QString("0.0000001"), Operation::fromXdrAmount(1L)); - QCOMPARE(QString("1"), Operation::fromXdrAmount(10000000L)); - QCOMPARE(QString("1.1234567"), Operation::fromXdrAmount(11234567L)); - QCOMPARE(QString("72991284.3007381"), Operation::fromXdrAmount(729912843007381L)); - QCOMPARE(QString("101401671144.6800155"), Operation::fromXdrAmount(1014016711446800155L)); - QCOMPARE(QString("922337203685.4775807"), Operation::fromXdrAmount(9223372036854775807L)); - } - - - void testRevokeAccountSponsorshipOperation() { - QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; - QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; - RevokeAccountSponsorshipOperation* operation = RevokeAccountSponsorshipOperation::create(accountId)->setSourceAccount(source); - QCOMPARE(operation->toXdrBase64(),"AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABIAAAAAAAAAAAAAAAAND42wpWEfOthyO+2vpGJJ5QgHfCRRZKvHXjjhkRA7Sw=="); - - stellar::Operation xdr = operation->toXdr(); - RevokeAccountSponsorshipOperation* parsedOperation = (RevokeAccountSponsorshipOperation*) Operation::fromXdr(xdr); - QCOMPARE(accountId, parsedOperation->getAccountId()); - QCOMPARE(source, parsedOperation->getSourceAccount()); - } - - - void testRevokeDataSponsorshipOperation() { - QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; - QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; - QString dataName = "data_name"; - RevokeDataSponsorshipOperation* operation = RevokeDataSponsorshipOperation::create(accountId, dataName)->setSourceAccount(source); - QCOMPARE(operation->toXdrBase64(), "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABIAAAAAAAAAAwAAAAAND42wpWEfOthyO+2vpGJJ5QgHfCRRZKvHXjjhkRA7SwAAAAlkYXRhX25hbWUAAAA="); - - stellar::Operation xdr = operation->toXdr(); - RevokeDataSponsorshipOperation* parsedOperation = (RevokeDataSponsorshipOperation*) Operation::fromXdr(xdr); - QCOMPARE(accountId, parsedOperation->getAccountId()); - QCOMPARE(source, parsedOperation->getSourceAccount()); - QCOMPARE(dataName, parsedOperation->getDataName()); - } - - void testRevokeClaimableBalanceSponsorshipOperation() { - QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; - QString balanceId = "00000000550e14acbdafcd3089289363b3b0c8bec9b4edd87298c690655b4b2456d68ba0"; - RevokeClaimableBalanceSponsorshipOperation* operation = RevokeClaimableBalanceSponsorshipOperation::create(balanceId)->setSourceAccount(source); - QCOMPARE(operation->toXdrBase64(), "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABIAAAAAAAAABAAAAABVDhSsva/NMIkok2OzsMi+ybTt2HKYxpBlW0skVtaLoA=="); - - stellar::Operation xdr = operation->toXdr(); - RevokeClaimableBalanceSponsorshipOperation* parsedOperation = (RevokeClaimableBalanceSponsorshipOperation*) Operation::fromXdr(xdr); - QCOMPARE(balanceId, parsedOperation->getBalanceId()); - QCOMPARE(source, parsedOperation->getSourceAccount()); - } - - void testRevokeOfferSponsorshipOperation() { - QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; - QString seller = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; - qint64 offerId = 123456L; - RevokeOfferSponsorshipOperation* operation = RevokeOfferSponsorshipOperation::create(seller, offerId)->setSourceAccount(source); - QCOMPARE(operation->toXdrBase64(), "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABIAAAAAAAAAAgAAAAAND42wpWEfOthyO+2vpGJJ5QgHfCRRZKvHXjjhkRA7SwAAAAAAAeJA"); - - stellar::Operation xdr = operation->toXdr(); - RevokeOfferSponsorshipOperation* parsedOperation = (RevokeOfferSponsorshipOperation*) Operation::fromXdr(xdr); - QCOMPARE(offerId, parsedOperation->getOfferId()); - QCOMPARE(seller, parsedOperation->getSeller()); - QCOMPARE(source, parsedOperation->getSourceAccount()); - } - - void testRevokeSignerSponsorshipOperation() { - QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; - QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; - stellar::SignerKey signerKey = KeyPair::fromAccountId("GBOSQJIV4VJMWMPVPB7EFVIRJT7A7SAAAB4FA23ZDJRUMXMYHBYWY57L")->getXdrSignerKey(); - RevokeSignerSponsorshipOperation* operation = RevokeSignerSponsorshipOperation::create(accountId, signerKey)->setSourceAccount(source); - QCOMPARE(operation->toXdrBase64(), "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABIAAAABAAAAAA0PjbClYR862HI77a+kYknlCAd8JFFkq8deOOGREDtLAAAAAF0oJRXlUssx9Xh+QtURTP4PyAAAeFBreRpjRl2YOHFs"); - - stellar::Operation xdr = operation->toXdr(); - RevokeSignerSponsorshipOperation* parsedOperation = (RevokeSignerSponsorshipOperation*) Operation::fromXdr(xdr); - QCOMPARE(accountId, parsedOperation->getAccountId()); - QCOMPARE(source, parsedOperation->getSourceAccount()); - QCOMPARE(signerKey, parsedOperation->getSigner()); - } - - - void testRevokeTrustlineSponsorshipOperation() { - QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; - QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; - Asset* asset = Asset::create("DEMO", "GCWPICV6IV35FQ2MVZSEDLORHEMMIAODRQPVDEIKZOW2GC2JGGDCXVVV"); - RevokeTrustlineSponsorshipOperation* operation = RevokeTrustlineSponsorshipOperation::create(accountId, asset)->setSourceAccount(source); - QCOMPARE(operation->toXdrBase64() , "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABIAAAAAAAAAAQAAAAAND42wpWEfOthyO+2vpGJJ5QgHfCRRZKvHXjjhkRA7SwAAAAFERU1PAAAAAKz0Cr5Fd9LDTK5kQa3RORjEAcOMH1GRCsutowtJMYYr"); - - stellar::Operation xdr = operation->toXdr(); - RevokeTrustlineSponsorshipOperation* parsedOperation = (RevokeTrustlineSponsorshipOperation*) Operation::fromXdr(xdr); - QCOMPARE(accountId, parsedOperation->getAccountId()); - QCOMPARE(source, parsedOperation->getSourceAccount()); - QVERIFY(asset->equals(parsedOperation->getAsset())); - } - - void testBeginSponsoringFutureReserves() { - QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; - QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; - - BeginSponsoringFutureReservesOperation* operation = BeginSponsoringFutureReservesOperation::create(accountId)->setSourceAccount(source); - QCOMPARE(operation->toXdrBase64() , "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABAAAAAADQ+NsKVhHzrYcjvtr6RiSeUIB3wkUWSrx1444ZEQO0s="); - - stellar::Operation xdr = operation->toXdr(); - BeginSponsoringFutureReservesOperation* parsedOperation = (BeginSponsoringFutureReservesOperation*) Operation::fromXdr(xdr); - QCOMPARE(accountId, parsedOperation->getSponsoredID()); - QCOMPARE(source, parsedOperation->getSourceAccount()); - - } - void testEndSponsoringFutureReserves() { - QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; - - EndSponsoringFutureReservesOperation* operation = EndSponsoringFutureReservesOperation::create()->setSourceAccount(source); - QCOMPARE(operation->toXdrBase64() , "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABE="); - - stellar::Operation xdr = operation->toXdr(); - EndSponsoringFutureReservesOperation* parsedOperation = (EndSponsoringFutureReservesOperation*) Operation::fromXdr(xdr); - QCOMPARE(source, parsedOperation->getSourceAccount()); - - - } + } + + void testToXdrAmount() { + QVERIFY(0L== Operation::toXdrAmount("0")); + QVERIFY(1L== Operation::toXdrAmount("0.0000001")); + QVERIFY(10000000L== Operation::toXdrAmount("1")); + QVERIFY(11234567L== Operation::toXdrAmount("1.1234567")); + QVERIFY(729912843007381L== Operation::toXdrAmount("72991284.3007381")); + QVERIFY(729912843007381L== Operation::toXdrAmount("72991284.30073810")); + QVERIFY(1014016711446800155L== Operation::toXdrAmount("101401671144.6800155")); + qDebug() << Operation::toXdrAmount("922337203685.4775807"); + QVERIFY(9223372036854775807UL== Operation::toXdrAmount("922337203685.4775807")); + try { + Operation::toXdrAmount("0.00000001"); + QFAIL("expected exception"); + } + catch (std::exception e) { + } + try { + Operation::toXdrAmount("72991284.30073811"); + QFAIL("expected exception"); + } + catch(std::exception e){ + } + } + + + void testFromXdrAmount() { + QCOMPARE(QString("0"), Operation::fromXdrAmount(0L)); + QCOMPARE(QString("0.0000001"), Operation::fromXdrAmount(1L)); + QCOMPARE(QString("1"), Operation::fromXdrAmount(10000000L)); + QCOMPARE(QString("1.1234567"), Operation::fromXdrAmount(11234567L)); + QCOMPARE(QString("72991284.3007381"), Operation::fromXdrAmount(729912843007381L)); + QCOMPARE(QString("101401671144.6800155"), Operation::fromXdrAmount(1014016711446800155L)); + QCOMPARE(QString("922337203685.4775807"), Operation::fromXdrAmount(9223372036854775807L)); + } + + + void testClaimClaimableBalanceOperationValid() + { + QString balanceId = "000000006d6a0c142516a9cc7885a85c5aba3a1f4af5181cf9e7a809ac7ae5e4a58c825f"; + QString accountId = "GABTTS6N4CT7AUN4LD7IFIUMRD5PSMCW6QTLIQNEFZDEI6ZQVUCQMCLN"; + ClaimClaimableBalanceOperation* operation = ClaimClaimableBalanceOperation::create(balanceId)->setSourceAccount(accountId); + + stellar::Operation xdr = operation->toXdr(); + ClaimClaimableBalanceOperation* parsedOperation = (ClaimClaimableBalanceOperation*) Operation::fromXdr(xdr); + QCOMPARE(accountId, parsedOperation->getSourceAccount()); + QCOMPARE(balanceId, parsedOperation->getBalanceId()); + // Generated by js-stellar-base. + QCOMPARE(operation->toXdrBase64() + ,"AAAAAQAAAAADOcvN4KfwUbxY/oKijIj6+TBW9Ca0QaQuRkR7MK0FBgAAAA8AAAAAbWoMFCUWqcx4hahcWro6H0r1GBz556gJrHrl5KWMgl8="); + } + + void testClaimClaimableBalanceOperationInvalidEmptyBalanceId() + { + QString balanceId = ""; + QString accountId = "GABTTS6N4CT7AUN4LD7IFIUMRD5PSMCW6QTLIQNEFZDEI6ZQVUCQMCLN"; + try { + ClaimClaimableBalanceOperation* operation = ClaimClaimableBalanceOperation::create(balanceId)->setSourceAccount(accountId); + operation->toXdr(); + QFAIL("missing excepcion"); + } catch (std::runtime_error e) { + //"invalid balanceId" + } + } + + void testClaimClaimableBalanceOperationInvalidClaimableBalanceIDTypeMissing() + { + QString balanceId = "6d6a0c142516a9cc7885a85c5aba3a1f4af5181cf9e7a809ac7ae5e4a58c825f"; + QString accountId = "GABTTS6N4CT7AUN4LD7IFIUMRD5PSMCW6QTLIQNEFZDEI6ZQVUCQMCLN"; + try { + ClaimClaimableBalanceOperation* operation = ClaimClaimableBalanceOperation::create(balanceId)->setSourceAccount(accountId); + operation->toXdr(); + QFAIL("missing excepcion"); + } catch (std::runtime_error ignored) { + } + } + + void testClaimClaimableBalanceOperationInvalidClaimableBalanceIDBodyMissing() + { + QString balanceId = "00000000"; + QString accountId = "GABTTS6N4CT7AUN4LD7IFIUMRD5PSMCW6QTLIQNEFZDEI6ZQVUCQMCLN"; + try { + ClaimClaimableBalanceOperation* operation = ClaimClaimableBalanceOperation::create(balanceId)->setSourceAccount(accountId); + operation->toXdr(); + QFAIL("missing excepcion"); + } catch (std::runtime_error e) { + //"invalid balanceId" + } + } + + void testRevokeAccountSponsorshipOperation() { + QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; + QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; + RevokeAccountSponsorshipOperation* operation = RevokeAccountSponsorshipOperation::create(accountId)->setSourceAccount(source); + QCOMPARE(operation->toXdrBase64(),"AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABIAAAAAAAAAAAAAAAAND42wpWEfOthyO+2vpGJJ5QgHfCRRZKvHXjjhkRA7Sw=="); + + stellar::Operation xdr = operation->toXdr(); + RevokeAccountSponsorshipOperation* parsedOperation = (RevokeAccountSponsorshipOperation*) Operation::fromXdr(xdr); + QCOMPARE(accountId, parsedOperation->getAccountId()); + QCOMPARE(source, parsedOperation->getSourceAccount()); + } + + + void testRevokeDataSponsorshipOperation() { + QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; + QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; + QString dataName = "data_name"; + RevokeDataSponsorshipOperation* operation = RevokeDataSponsorshipOperation::create(accountId, dataName)->setSourceAccount(source); + QCOMPARE(operation->toXdrBase64(), "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABIAAAAAAAAAAwAAAAAND42wpWEfOthyO+2vpGJJ5QgHfCRRZKvHXjjhkRA7SwAAAAlkYXRhX25hbWUAAAA="); + + stellar::Operation xdr = operation->toXdr(); + RevokeDataSponsorshipOperation* parsedOperation = (RevokeDataSponsorshipOperation*) Operation::fromXdr(xdr); + QCOMPARE(accountId, parsedOperation->getAccountId()); + QCOMPARE(source, parsedOperation->getSourceAccount()); + QCOMPARE(dataName, parsedOperation->getDataName()); + } + + void testRevokeClaimableBalanceSponsorshipOperation() { + QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; + QString balanceId = "00000000550e14acbdafcd3089289363b3b0c8bec9b4edd87298c690655b4b2456d68ba0"; + RevokeClaimableBalanceSponsorshipOperation* operation = RevokeClaimableBalanceSponsorshipOperation::create(balanceId)->setSourceAccount(source); + QCOMPARE(operation->toXdrBase64(), "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABIAAAAAAAAABAAAAABVDhSsva/NMIkok2OzsMi+ybTt2HKYxpBlW0skVtaLoA=="); + + stellar::Operation xdr = operation->toXdr(); + RevokeClaimableBalanceSponsorshipOperation* parsedOperation = (RevokeClaimableBalanceSponsorshipOperation*) Operation::fromXdr(xdr); + QCOMPARE(balanceId, parsedOperation->getBalanceId()); + QCOMPARE(source, parsedOperation->getSourceAccount()); + } + + void testRevokeOfferSponsorshipOperation() { + QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; + QString seller = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; + qint64 offerId = 123456L; + RevokeOfferSponsorshipOperation* operation = RevokeOfferSponsorshipOperation::create(seller, offerId)->setSourceAccount(source); + QCOMPARE(operation->toXdrBase64(), "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABIAAAAAAAAAAgAAAAAND42wpWEfOthyO+2vpGJJ5QgHfCRRZKvHXjjhkRA7SwAAAAAAAeJA"); + + stellar::Operation xdr = operation->toXdr(); + RevokeOfferSponsorshipOperation* parsedOperation = (RevokeOfferSponsorshipOperation*) Operation::fromXdr(xdr); + QCOMPARE(offerId, parsedOperation->getOfferId()); + QCOMPARE(seller, parsedOperation->getSeller()); + QCOMPARE(source, parsedOperation->getSourceAccount()); + } + + void testRevokeSignerSponsorshipOperation() { + QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; + QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; + stellar::SignerKey signerKey = KeyPair::fromAccountId("GBOSQJIV4VJMWMPVPB7EFVIRJT7A7SAAAB4FA23ZDJRUMXMYHBYWY57L")->getXdrSignerKey(); + RevokeSignerSponsorshipOperation* operation = RevokeSignerSponsorshipOperation::create(accountId, signerKey)->setSourceAccount(source); + QCOMPARE(operation->toXdrBase64(), "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABIAAAABAAAAAA0PjbClYR862HI77a+kYknlCAd8JFFkq8deOOGREDtLAAAAAF0oJRXlUssx9Xh+QtURTP4PyAAAeFBreRpjRl2YOHFs"); + + stellar::Operation xdr = operation->toXdr(); + RevokeSignerSponsorshipOperation* parsedOperation = (RevokeSignerSponsorshipOperation*) Operation::fromXdr(xdr); + QCOMPARE(accountId, parsedOperation->getAccountId()); + QCOMPARE(source, parsedOperation->getSourceAccount()); + QCOMPARE(signerKey, parsedOperation->getSigner()); + } + + + void testRevokeTrustlineSponsorshipOperation() { + QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; + QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; + Asset* asset = Asset::create("DEMO", "GCWPICV6IV35FQ2MVZSEDLORHEMMIAODRQPVDEIKZOW2GC2JGGDCXVVV"); + RevokeTrustlineSponsorshipOperation* operation = RevokeTrustlineSponsorshipOperation::create(accountId, asset)->setSourceAccount(source); + QCOMPARE(operation->toXdrBase64() , "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABIAAAAAAAAAAQAAAAAND42wpWEfOthyO+2vpGJJ5QgHfCRRZKvHXjjhkRA7SwAAAAFERU1PAAAAAKz0Cr5Fd9LDTK5kQa3RORjEAcOMH1GRCsutowtJMYYr"); + + stellar::Operation xdr = operation->toXdr(); + RevokeTrustlineSponsorshipOperation* parsedOperation = (RevokeTrustlineSponsorshipOperation*) Operation::fromXdr(xdr); + QCOMPARE(accountId, parsedOperation->getAccountId()); + QCOMPARE(source, parsedOperation->getSourceAccount()); + QVERIFY(asset->equals(parsedOperation->getAsset())); + } + + void testBeginSponsoringFutureReserves() { + QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; + QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; + + BeginSponsoringFutureReservesOperation* operation = BeginSponsoringFutureReservesOperation::create(accountId)->setSourceAccount(source); + QCOMPARE(operation->toXdrBase64() , "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABAAAAAADQ+NsKVhHzrYcjvtr6RiSeUIB3wkUWSrx1444ZEQO0s="); + + stellar::Operation xdr = operation->toXdr(); + BeginSponsoringFutureReservesOperation* parsedOperation = (BeginSponsoringFutureReservesOperation*) Operation::fromXdr(xdr); + QCOMPARE(accountId, parsedOperation->getSponsoredID()); + QCOMPARE(source, parsedOperation->getSourceAccount()); + + } + void testEndSponsoringFutureReserves() { + QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; + + EndSponsoringFutureReservesOperation* operation = EndSponsoringFutureReservesOperation::create()->setSourceAccount(source); + QCOMPARE(operation->toXdrBase64() , "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABE="); + + stellar::Operation xdr = operation->toXdr(); + EndSponsoringFutureReservesOperation* parsedOperation = (EndSponsoringFutureReservesOperation*) Operation::fromXdr(xdr); + QCOMPARE(source, parsedOperation->getSourceAccount()); + + + } + + void testClawbackClaimableBalanceOperation() + { + QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; + QString balanceId = "00000000929b20b72e5890ab51c24f1cc46fa01c4f318d8d33367d24dd614cfdf5491072"; + ClawbackClaimableBalanceOperation* operation = ClawbackClaimableBalanceOperation::create(balanceId)->setSourceAccount(source); + QCOMPARE(operation->toXdrBase64(), "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABQAAAAAkpsgty5YkKtRwk8cxG+gHE8xjY0zNn0k3WFM/fVJEHI="); + + stellar::Operation xdr = operation->toXdr(); + ClawbackClaimableBalanceOperation* parsedOperation = (ClawbackClaimableBalanceOperation*) Operation::fromXdr(xdr); + QCOMPARE(balanceId, parsedOperation->getBalanceId()); + QCOMPARE(source, parsedOperation->getSourceAccount()); + } + + void testClawbackOperation() + { + QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; + QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; + + Asset* asset = Asset::create("DEMO", "GCWPICV6IV35FQ2MVZSEDLORHEMMIAODRQPVDEIKZOW2GC2JGGDCXVVV"); + QString amt = "100"; + + ClawbackOperation* operation = ClawbackOperation::create(accountId, asset, amt)->setSourceAccount(source); + QCOMPARE(operation->toXdrBase64(), "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABMAAAABREVNTwAAAACs9Aq+RXfSw0yuZEGt0TkYxAHDjB9RkQrLraMLSTGGKwAAAAAND42wpWEfOthyO+2vpGJJ5QgHfCRRZKvHXjjhkRA7SwAAAAA7msoA"); + + stellar::Operation xdr = operation->toXdr(); + ClawbackOperation* parsedOperation = (ClawbackOperation*) Operation::fromXdr(xdr); + QCOMPARE(accountId, parsedOperation->getFrom()); + QVERIFY(asset->equals(parsedOperation->getAsset())); + QCOMPARE(amt, parsedOperation->getAmount()); + + QCOMPARE(source, parsedOperation->getSourceAccount()); + } + + void testCantClawbackNativeAsset() + { + try { + QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; + QString amt = "100"; + ClawbackOperation::create(accountId, Asset::create("native"), amt); + QFAIL("missing excepcion"); + } catch (std::runtime_error e) { + //"native assets are not supported" + } + } + + void testSetTrustlineFlagsOperation() + { + QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; + QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; + Asset* asset = Asset::create("DEMO", "GCWPICV6IV35FQ2MVZSEDLORHEMMIAODRQPVDEIKZOW2GC2JGGDCXVVV"); + QFlags toClear = QFlags(stellar::TrustLineFlags::AUTHORIZED_FLAG); + + QFlags toSet = QFlags({ stellar::TrustLineFlags::AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG, stellar::TrustLineFlags::TRUSTLINE_CLAWBACK_ENABLED_FLAG}); + + SetTrustlineFlagsOperation* operation = SetTrustlineFlagsOperation::create(accountId, asset, toClear, toSet)->setSourceAccount(source); + QCOMPARE(operation->toXdrBase64(), "AAAAAQAAAAA037UdsRiULYrlHjmXWb6CiMKM2fNCa/ONGxK3rOkvTwAAABUAAAAADQ+NsKVhHzrYcjvtr6RiSeUIB3wkUWSrx1444ZEQO0sAAAABREVNTwAAAACs9Aq+RXfSw0yuZEGt0TkYxAHDjB9RkQrLraMLSTGGKwAAAAEAAAAG"); + + stellar::Operation xdr = operation->toXdr(); + QCOMPARE( (int)xdr.operationSetTrustLineFlags.clearFlags, (int)stellar::TrustLineFlags::AUTHORIZED_FLAG); + QCOMPARE( (int)xdr.operationSetTrustLineFlags.setFlags, ((int)stellar::TrustLineFlags::AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG | (int)stellar::TrustLineFlags::TRUSTLINE_CLAWBACK_ENABLED_FLAG)); + SetTrustlineFlagsOperation* parsedOperation = (SetTrustlineFlagsOperation*) Operation::fromXdr(xdr); + QCOMPARE(accountId, parsedOperation->getTrustor()); + QVERIFY(asset->equals(parsedOperation->getAsset())); + QCOMPARE(toClear, parsedOperation->getClearFlags()); + QCOMPARE(toSet, parsedOperation->getSetFlags()); + + QCOMPARE(source, parsedOperation->getSourceAccount()); + + } + + + void testCantSetNativeTrustlineFlags() { + try { + QString source = "GA2N7NI5WEMJILMK4UPDTF2ZX2BIRQUM3HZUE27TRUNRFN5M5EXU6RQV"; + QString accountId = "GAGQ7DNQUVQR6OWYOI563L5EMJE6KCAHPQSFCZFLY5PDRYMRCA5UWCMP"; + QFlags toClear = QFlags(stellar::TrustLineFlags::AUTHORIZED_FLAG); + QFlags toSet = QFlags(stellar::TrustLineFlags::AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG); + + SetTrustlineFlagsOperation::create(accountId, Asset::create("native"), toClear, toSet)->setSourceAccount(source); + QFAIL("missing excepcion"); + } catch (std::runtime_error e) { + //"native assets are not supported" + } + } }; ADD_TEST(OperationTest) From d708b8cec117acea76c7176f7630e4cb15ca8c77 Mon Sep 17 00:00:00 2001 From: bnogalm <18525490+bnogalm@users.noreply.github.com> Date: Wed, 13 Apr 2022 20:52:34 +0200 Subject: [PATCH 4/4] push version number --- StellarQtSDK.pri | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StellarQtSDK.pri b/StellarQtSDK.pri index 2a1ca28..f9afa97 100644 --- a/StellarQtSDK.pri +++ b/StellarQtSDK.pri @@ -5,7 +5,7 @@ DEFINES += STELLAR_QT_REPLY_TIMEOUT=30000 DEFINES *= ED25519_NO_SEED DEFINES += STELLAR_QT_SDK_CLIENT_NAME=\"\\\"qtcpp-stellar-sdk\\\"\" -DEFINES += STELLAR_QT_SDK_CLIENT_VERSION=\"\\\"0.3.9\\\"\" +DEFINES += STELLAR_QT_SDK_CLIENT_VERSION=\"\\\"0.3.17\\\"\" #DEFINES += STELLAR_QT_AUTOSET_BASE_FEE