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

0.3.19 #69

Merged
merged 4 commits into from
Oct 14, 2024
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
11 changes: 10 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.17\\\"\"
DEFINES += STELLAR_QT_SDK_CLIENT_VERSION=\"\\\"0.3.19\\\"\"

#DEFINES += STELLAR_QT_AUTOSET_BASE_FEE

Expand All @@ -17,13 +17,21 @@ CONFIG *= c++11

TEMPLATE = app


greaterThan(QT_MAJOR_VERSION, 5) {
DEFINES += QIODeviceEnums=QIODeviceBase
} else {
DEFINES += QIODeviceEnums=QIODevice
}

INCLUDEPATH *= $$PWD
INCLUDEPATH *= $$PWD/src/


SOURCES += \
$$PWD/src/abstracttransaction.cpp \
$$PWD/src/account.cpp \
$$PWD/src/accountconverter.cpp \
$$PWD/src/accountmergeoperation.cpp \
$$PWD/src/beginsponsoringfuturereservesoperation.cpp \
$$PWD/src/claimant.cpp \
Expand Down Expand Up @@ -216,6 +224,7 @@ DEFINES += QT_DEPRECATED_WARNINGS

HEADERS += \
$$PWD/src/abstracttransaction.h \
$$PWD/src/accountconverter.h \
$$PWD/src/beginsponsoringfuturereservesoperation.h \
$$PWD/src/claimant.h \
$$PWD/src/claimclaimablebalanceoperation.h \
Expand Down
2 changes: 2 additions & 0 deletions StellarQtSDK.pro
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#example to add the Stellar Qt SDK to your project. It will not link correctly because it doesn't have a main().

QT += core
QT -= gui

Expand Down
5 changes: 3 additions & 2 deletions StellarQtSDKTest.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ QT -= gui
CONFIG += c++11 testcase

DEFINES += STELLAR_ALLOW_UNSECURE_RANDOM
DEFINES += STELLAR_SKIP_LIVE_TESTS
#DEFINES += STELLAR_SKIP_LIVE_TESTS

DEFINES += STELLAR_ENABLE_TEST_METHODS

#DEFINES += STELLAR_QT_DEBUG_NETWORK_REQUESTS

TARGET = StellarQtSDKTest
CONFIG += console
Expand All @@ -20,6 +20,7 @@ include(StellarQtSDK.pri)


HEADERS += \
test/claimablebalanceidtest.h \
test/fakeserver.h \
test/feebumptransactiontest.h \
test/keypairtest.h \
Expand Down
4 changes: 2 additions & 2 deletions src/abstracttransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "transaction.h"
#include "feebumptransaction.h"

AbstractTransaction::AbstractTransaction(Network *network) : m_network(network)
{
AbstractTransaction::AbstractTransaction(AccountConverter accountConverter, Network *network) : m_accountConverter(accountConverter), m_network(network)
{
checkNotNull(network, "network cannot be null");
}
void AbstractTransaction::sign(KeyPair *signer) {
Expand Down
5 changes: 4 additions & 1 deletion src/abstracttransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
#include "operation.h"
#include "memo.h"
#include "network.h"
#include "accountconverter.h"

class AbstractTransaction : public QObject
{
Q_OBJECT
protected:
AccountConverter m_accountConverter;
Network* m_network;
QVector<stellar::DecoratedSignature> m_signatures;

explicit AbstractTransaction(Network* network);
explicit AbstractTransaction(AccountConverter accountConverter, Network* network);
public:
static const int MIN_BASE_FEE = 100;
/**
Expand Down
15 changes: 14 additions & 1 deletion src/account.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
#include "account.h"
#include "util.h"

#include "accountconverter.h"

Account::Account(KeyPair *keypair, qint64 sequenceNumber) {
m_keyPair = checkNotNull(keypair, "keypair cannot be null");
m_accountId = AccountConverter().encode(keypair->getAccountId());
m_sequenceNumber = sequenceNumber;
}

Account::Account(QString accountId, qint64 sequenceNumber)
{
m_keyPair = KeyPair::fromAccountId(AccountConverter(false).filter(accountId));
m_accountId = AccountConverter().encode(checkNotNull(accountId, "accountId cannot be null"));
m_sequenceNumber = sequenceNumber;
}

Expand All @@ -17,6 +25,11 @@ KeyPair *Account::getKeypair() {
return m_keyPair;
}

QString Account::getAccountId() const
{
return AccountConverter().decode(m_accountId);
}

qint64 Account::getSequenceNumber() {
return m_sequenceNumber;
}
Expand Down
6 changes: 5 additions & 1 deletion src/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
class Account : public TransactionBuilderAccount
{
stellar::MuxedAccount m_accountId;
KeyPair *m_keyPair;
qint64 m_sequenceNumber;
public:
Expand All @@ -18,11 +19,14 @@ class Account : public TransactionBuilderAccount
* @param keypair KeyPair associated with this Account
* @param sequenceNumber Current sequence number of the account (can be obtained using java-stellar-sdk or horizon server)
*/
Account(KeyPair* keypair, qint64 sequenceNumber);
Account(KeyPair* keypair, qint64 sequenceNumber);
Account(QString accountId, qint64 sequenceNumber);
~Account();

KeyPair* getKeypair();

QString getAccountId() const;

qint64 getSequenceNumber();
qint64 getIncrementedSequenceNumber();

Expand Down
61 changes: 61 additions & 0 deletions src/accountconverter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "accountconverter.h"


AccountConverter::AccountConverter(bool enabled) : m_enableMuxed(enabled) {
}

AccountConverter& AccountConverter::enableMuxed() {
m_enableMuxed=true;
return *this;
}

AccountConverter& AccountConverter::disableMuxed() {
m_enableMuxed=false;
return *this;
}

stellar::MuxedAccount AccountConverter::encode(QString account) {
stellar::MuxedAccount muxed = StrKey::encodeToXDRMuxedAccount(account);

if (m_enableMuxed || muxed.type == stellar::CryptoKeyType::KEY_TYPE_ED25519) {
return muxed;
}

stellar::MuxedAccount med25519;

med25519.type = stellar::CryptoKeyType::KEY_TYPE_ED25519;
memcpy(med25519.ed25519,muxed.med25519.ed25519,KeyPair::keyLength);
return med25519;
}

QString AccountConverter::decode(stellar::MuxedAccount account) {
if (m_enableMuxed || account.type == stellar::CryptoKeyType::KEY_TYPE_ED25519) {
return StrKey::encodeStellarMuxedAccount(account);
}


return StrKey::encodeStellarAccountId(StrKey::muxedAccountToAccountId(account));
}

stellar::MuxedAccount AccountConverter::filter(stellar::MuxedAccount account)
{
if (m_enableMuxed || account.type == stellar::CryptoKeyType::KEY_TYPE_ED25519) {
return account;
}

stellar::MuxedAccount med25519;

med25519.type = stellar::CryptoKeyType::KEY_TYPE_ED25519;
memcpy(med25519.ed25519,account.med25519.ed25519,KeyPair::keyLength);
return med25519;
}

QString AccountConverter::filter(QString account)
{
stellar::MuxedAccount muxed = StrKey::encodeToXDRMuxedAccount(account);
if(m_enableMuxed || muxed.type == stellar::CryptoKeyType::KEY_TYPE_ED25519)
{
return account;
}
return StrKey::encodeStellarAccountId(StrKey::muxedAccountToAccountId(muxed));
}
56 changes: 56 additions & 0 deletions src/accountconverter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef ACCOUNTCONVERTER_H
#define ACCOUNTCONVERTER_H
#include "keypair.h"
#include "strkey.h"

class AccountConverter
{
bool m_enableMuxed;
public:

AccountConverter(bool enabled=true);

/**
* Returns an AccountConverter which supports muxed accounts.
**/
AccountConverter& enableMuxed();

/**
* Returns an AccountConverter which does not support muxed accounts. When trying to encode or decode
* a muxed account the AccountConverter will first convert the muxed account into an ED25519 account id.
**/
AccountConverter& disableMuxed();


/**
* Encodes an account string into its XDR MuxedAccount representation.
*
* @param account the string representation of an account
*/
stellar::MuxedAccount encode(QString account);

/**
* Decodes an XDR MuxedAccount into its string representation.
*
* @param account the XDR MuxedAccount representation of an account
*/
QString decode(stellar::MuxedAccount account);

/**
* Filter muxed account
*
* @param account the XDR MuxedAccount representation of an account
*/
stellar::MuxedAccount filter(stellar::MuxedAccount account);


/**
* Filter muxed account
*
* @param account representation of an account M -> G (if muxed is disabled)
*/
QString filter(QString account);

};

#endif // ACCOUNTCONVERTER_H
7 changes: 3 additions & 4 deletions src/accountmergeoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ QString AccountMergeOperation::getDestination() const {
return m_destination;
}

void AccountMergeOperation::fillOperationBody(stellar::Operation &operation) {
void AccountMergeOperation::fillOperationBody(AccountConverter &accountConverter, stellar::Operation &operation) {
operation.type = stellar::OperationType::ACCOUNT_MERGE;
operation.operationAccountMerge = StrKey::encodeToXDRMuxedAccount(m_destination);
operation.operationAccountMerge = accountConverter.encode(m_destination);
}

AccountMergeOperation *AccountMergeOperation::build(stellar::MuxedAccount &operationAccountMerge)
{

return new AccountMergeOperation(StrKey::encodeStellarAccountId(StrKey::muxedAccountToAccountId(operationAccountMerge)));
return new AccountMergeOperation(StrKey::encodeStellarMuxedAccount(operationAccountMerge));
}

AccountMergeOperation *AccountMergeOperation::create(KeyPair* destination)
Expand Down
2 changes: 1 addition & 1 deletion src/accountmergeoperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AccountMergeOperation : public Operation
* The account that receives the remaining XLM balance of the source account.
*/
QString getDestination() const;
void fillOperationBody(stellar::Operation &operation);
void fillOperationBody(AccountConverter& accountConverter, stellar::Operation &operation);

/**
* @brief build an AccountMergeOperation setting destination from an xdr operation
Expand Down
3 changes: 2 additions & 1 deletion src/allowtrustoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ bool AllowTrustOperation::getAuthorizeToMaintainLiabilities() const
return m_op.authorize&static_cast<quint32>(stellar::TrustLineFlags::AUTHORIZED_TO_MAINTAIN_LIABILITIES_FLAG);
}

void AllowTrustOperation::fillOperationBody(stellar::Operation &operation) {
void AllowTrustOperation::fillOperationBody(AccountConverter &accountConverter, stellar::Operation &operation) {
Q_UNUSED(accountConverter)
operation.type = stellar::OperationType::ALLOW_TRUST;
operation.operationAllowTrust = m_op;
}
Expand Down
2 changes: 1 addition & 1 deletion src/allowtrustoperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Q_DECL_DEPRECATED AllowTrustOperation : public Operation
bool getAuthorizeToMaintainLiabilities() const;


void fillOperationBody(stellar::Operation &operation);
void fillOperationBody(AccountConverter& accountConverter, stellar::Operation &operation);


static AllowTrustOperation* build(stellar::AllowTrustOp &op);
Expand Down
3 changes: 2 additions & 1 deletion src/beginsponsoringfuturereservesoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ QString BeginSponsoringFutureReservesOperation::getSponsoredID()
return StrKey::encodeStellarAccountId(m_op.sponsoredID);
}

void BeginSponsoringFutureReservesOperation::fillOperationBody(stellar::Operation &operation)
void BeginSponsoringFutureReservesOperation::fillOperationBody(AccountConverter &accountConverter, stellar::Operation &operation)
{
Q_UNUSED(accountConverter)
operation.type = stellar::OperationType::BEGIN_SPONSORING_FUTURE_RESERVES;
operation.operationBeginSponsoringFutureReserves=m_op;
}
Expand Down
2 changes: 1 addition & 1 deletion src/beginsponsoringfuturereservesoperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BeginSponsoringFutureReservesOperation : public Operation
BeginSponsoringFutureReservesOperation(QString sponsoredId);
BeginSponsoringFutureReservesOperation(stellar::BeginSponsoringFutureReservesOp& op);
QString getSponsoredID();
void fillOperationBody(stellar::Operation &operation);
void fillOperationBody(AccountConverter& accountConverter, stellar::Operation &operation);


static BeginSponsoringFutureReservesOperation* build(stellar::BeginSponsoringFutureReservesOp &op);
Expand Down
3 changes: 2 additions & 1 deletion src/bumpsequenceoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ qint64 BumpSequenceOperation::getBumpTo() const
return m_op.bumpTo;
}

void BumpSequenceOperation::fillOperationBody(stellar::Operation &operation)
void BumpSequenceOperation::fillOperationBody(AccountConverter &accountConverter, stellar::Operation &operation)
{
Q_UNUSED(accountConverter)
operation.type = stellar::OperationType::BUMP_SEQUENCE;
operation.operationBumpSequence=m_op;
}
Expand Down
2 changes: 1 addition & 1 deletion src/bumpsequenceoperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BumpSequenceOperation : public Operation

qint64 getBumpTo() const;

void fillOperationBody(stellar::Operation &operation);
void fillOperationBody(AccountConverter& accountConverter, stellar::Operation &operation);


static BumpSequenceOperation* build(stellar::BumpSequenceOp &op);
Expand Down
3 changes: 2 additions & 1 deletion src/changetrustoperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ QString ChangeTrustOperation::getLimit() {
return Operation::fromXdrAmount(m_op.limit);
}

void ChangeTrustOperation::fillOperationBody(stellar::Operation &operation){
void ChangeTrustOperation::fillOperationBody(AccountConverter &accountConverter, stellar::Operation &operation){
Q_UNUSED(accountConverter)
operation.type = stellar::OperationType::CHANGE_TRUST;
operation.operationChangeTrust=m_op;
}
Expand Down
2 changes: 1 addition & 1 deletion src/changetrustoperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ChangeTrustOperation : public Operation
* The limit of the trustline. For example, if a gateway extends a trustline of up to 200 USD to a user, the limit is 200.
*/
QString getLimit();
void fillOperationBody(stellar::Operation &operation);
void fillOperationBody(AccountConverter& accountConverter, stellar::Operation &operation);
static ChangeTrustOperation* build(stellar::ChangeTrustOp &op);
static ChangeTrustOperation* create(Asset* asset, QString limit);

Expand Down
4 changes: 2 additions & 2 deletions src/claimant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ Claimant Claimant::fromXdr(stellar::Claimant c)
,Predicate::fromXdr(c.v0.predicate));
}

bool Claimant::operator==(const Claimant &other)
bool Claimant::operator==(const Claimant &other) const
{
return m_destination==other.m_destination && m_predicate && other.m_predicate && m_predicate->equals(other.m_predicate);
}

bool Claimant::operator!=(const Claimant &other)
bool Claimant::operator!=(const Claimant &other) const
{
return m_destination!=other.m_destination || !m_predicate || !other.m_predicate || !m_predicate->equals(other.m_predicate);
}
Expand Down
Loading