Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Cap35 #62

Merged
merged 4 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion StellarQtSDK.pri
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 \
Expand Down Expand Up @@ -57,6 +59,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 \
Expand All @@ -69,13 +72,16 @@ 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 \
$$PWD/src/responses/feestatsresponse.cpp \
$$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 \
Expand All @@ -84,13 +90,15 @@ 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 \
$$PWD/src/revokeoffersponsorshipoperation.cpp \
$$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 \
Expand Down Expand Up @@ -211,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 \
Expand All @@ -230,6 +240,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 \
Expand All @@ -242,13 +253,16 @@ 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 \
$$PWD/src/responses/feestatsresponse.h \
$$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 \
Expand All @@ -257,13 +271,15 @@ 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 \
$$PWD/src/revokeoffersponsorshipoperation.h \
$$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 \
Expand Down
5 changes: 3 additions & 2 deletions src/allowtrustoperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#define ALLOWTRUSTOPERATION_H
#include "operation.h"


/**
* @deprecated As of release 0.24.0, replaced by {@link SetTrustlineFlagsOperation}
*
* Represents <a href="https://www.stellar.org/developers/learn/concepts/list-of-operations.html#allow-trust" target="_blank">AllowTrust</a> operation.
* @see <a href="https://www.stellar.org/developers/learn/concepts/list-of-operations.html" target="_blank">List of Operations</a>
*/
class AllowTrustOperation : public Operation
class Q_DECL_DEPRECATED AllowTrustOperation : public Operation
{
KeyPair* m_trustor;

Expand Down
2 changes: 1 addition & 1 deletion src/asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/asset.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions src/assettypecreditalphanum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/assettypecreditalphanum.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ class AssetTypeCreditAlphaNum : public Asset

virtual QString toString() const;
};

AssetTypeCreditAlphaNum* checkNotNull(AssetTypeCreditAlphaNum* asset, const char *error);
#endif // ASSETTYPECREDITALPHANUM_H
10 changes: 3 additions & 7 deletions src/claimclaimablebalanceoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions src/clawbackclaimablebalanceoperation.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

33 changes: 33 additions & 0 deletions src/clawbackclaimablebalanceoperation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef CLAWBACKCLAIMABLEBALANCEOPERATION_H
#define CLAWBACKCLAIMABLEBALANCEOPERATION_H

#include "operation.h"
/**
*
* Represents a Clawback Claimable Balance operation.
* @see <a href="https://www.stellar.org/developers/learn/concepts/list-of-operations.html" target="_blank">List of Operations</a>
*/
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
69 changes: 69 additions & 0 deletions src/clawbackoperation.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
44 changes: 44 additions & 0 deletions src/clawbackoperation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#ifndef CLAWBACKOPERATION_H
#define CLAWBACKOPERATION_H

#include "operation.h"
/**
*
* Represents a Clawback operation.
* @see <a href="https://www.stellar.org/developers/learn/concepts/list-of-operations.html" target="_blank">List of Operations</a>
*/
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
Loading