-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version of two examples on how to use the SDK, tutorial explain…
…ing them will be published soon. Includes compiled OpenSSL for windows 64bit Fix an error on the SDK when requesting a stream. Version 0.3.1
- Loading branch information
Showing
122 changed files
with
32,740 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
QT -= gui | ||
|
||
|
||
#add library, we add the code straight with the application, as it uses MPL licence you are allowed to do this. | ||
include($$PWD/../../StellarQtSDK.pri) | ||
|
||
|
||
#add openssl library, for other platforms you will have to link the proper library. | ||
windows { | ||
LIBS += -L$$PWD/../OpenSSL/Win_x64/bin -llibssl-1_1-x64 | ||
LIBS += -L$$PWD/../OpenSSL/Win_x64/bin -llibcrypto-1_1-x64 | ||
#INCLUDEPATH += $PWD/../OpenSSL/Win_x64/include/ | ||
#DEPENDPATH += $PWD/../OpenSSL/Win_x64/include/ | ||
} | ||
|
||
|
||
CONFIG += c++11 console | ||
CONFIG -= app_bundle | ||
|
||
# The following define makes your compiler emit warnings if you use | ||
# any Qt feature that has been marked deprecated (the exact warnings | ||
# depend on your compiler). Please consult the documentation of the | ||
# deprecated API in order to know how to port your code away from it. | ||
DEFINES += QT_DEPRECATED_WARNINGS | ||
|
||
# You can also make your code fail to compile if it uses deprecated APIs. | ||
# In order to do so, uncomment the following line. | ||
# You can also select to disable deprecated APIs only up to a certain version of Qt. | ||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 | ||
|
||
SOURCES += \ | ||
main.cpp | ||
|
||
# Default rules for deployment. | ||
qnx: target.path = /tmp/$${TARGET}/bin | ||
else: unix:!android: target.path = /opt/$${TARGET}/bin | ||
!isEmpty(target.path): INSTALLS += target | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include <QCoreApplication> | ||
#include <QDebug> | ||
#include <QTimer> | ||
|
||
#include "network.h" | ||
#include "server.h" | ||
#include "keypair.h" | ||
#include "responses/operations/paymentoperationresponse.h" | ||
#include "responses/operations/createaccountoperationresponse.h" | ||
|
||
|
||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QCoreApplication a(argc, argv); | ||
|
||
|
||
Network::useTestNetwork();//select the network to use | ||
Server * server = new Server("https://horizon-testnet.stellar.org");//choose a horizon host | ||
//Qt removes child QObjects before removing parent, Server is a QObject, so we can use it to remove it before application ends. | ||
//responses requested to a server object are child of the used server, so they will be removed with the server if you didn't before. | ||
server->setParent(qApp); | ||
|
||
KeyPair * keypair = KeyPair::random(); | ||
|
||
qDebug() << "Created keypair"; | ||
qDebug() << "Public key: "<<keypair->getAccountId(); | ||
qDebug() << "Private key: "<<keypair->getSecretSeed(); | ||
|
||
|
||
//check if the account is already created, if not, we alert the user to create it | ||
AccountResponse * accountCheckResponse = server->accounts().account(keypair); | ||
|
||
//here we connect the signal ready of the response to a lambda function, that will be executed as soon response is ready | ||
QObject::connect(accountCheckResponse,&AccountResponse::ready,[accountCheckResponse,keypair](){ | ||
if(accountCheckResponse->accountID().isEmpty()){ | ||
//account not funded yet | ||
qDebug() << "Account not funded yet, fund it using friendbot loading the next link:"; | ||
qDebug() << QString("https://friendbot.stellar.org?addr=%1").arg(keypair->getAccountId()); | ||
} | ||
//response contains account data | ||
//we remove the response as we don't need anymore | ||
// note that as we are using a lambda, this pointer is now deleted but not set to nullptr | ||
// we could get this pointer by reference, to be able to set it to nullptr | ||
delete accountCheckResponse; //we don't need it anymore. It would be deleted anyway by server destruction, but normally you will have to remove it here | ||
|
||
//we dont need it anymore, note this lambda will not be executed until Qt event loop starts, that is why we can use it the next lines | ||
delete keypair; | ||
}); | ||
|
||
//stream the all the payment for our account | ||
OperationPage* paymentsStream = server->payments().forAccount(keypair).order(RequestBuilder::Order::ASC) | ||
.stream().execute(); | ||
|
||
|
||
|
||
QObject::connect(paymentsStream,&OperationResponse::ready,[paymentsStream](){ | ||
QList<Response*> records = paymentsStream->getRecords(); | ||
for(Response * r : records) | ||
{ | ||
if(PaymentOperationResponse * payment = dynamic_cast<PaymentOperationResponse*>(r)) | ||
{ | ||
qDebug() << "Payment detected! Amount: "<< payment->getAmount()<< " Asset: "<< payment->getAsset()->toString()<< " From: "<< payment->getFrom().getAccountId() << " Created at: "<< payment->getCreatedAt(); | ||
} | ||
else if(CreateAccountOperationResponse * createAccount = dynamic_cast<CreateAccountOperationResponse*>(r)) | ||
{ | ||
qDebug() << "Create account detected! Amount: "<< createAccount->getStartingBalance()<< " From: "<< createAccount->getFunder().getAccountId()<< " Created at: "<<createAccount->getCreatedAt(); | ||
|
||
} | ||
} | ||
//as is a streaming request, objects will be automatically removed with the next update. | ||
//you should take this in consideration, as you can't store them to read values later. | ||
}); | ||
|
||
|
||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
QT += quick | ||
|
||
|
||
CONFIG += c++11 | ||
|
||
|
||
|
||
#add library, we add the code straight with the application, as it uses MPL licence you are allowed to do this. | ||
include($$PWD/../../StellarQtSDK.pri) | ||
|
||
|
||
#add openssl library, for other platforms you will have to link the proper library. | ||
windows { | ||
LIBS += -L$$PWD/../OpenSSL/Win_x64/bin -llibssl-1_1-x64 | ||
LIBS += -L$$PWD/../OpenSSL/Win_x64/bin -llibcrypto-1_1-x64 | ||
#INCLUDEPATH += $PWD/../OpenSSL/Win_x64/include/ | ||
#DEPENDPATH += $PWD/../OpenSSL/Win_x64/include/ | ||
} | ||
|
||
|
||
OTHER_FILES += main.qml | ||
|
||
|
||
# The following define makes your compiler emit warnings if you use | ||
# any Qt feature that has been marked deprecated (the exact warnings | ||
# depend on your compiler). Refer to the documentation for the | ||
# deprecated API to know how to port your code away from it. | ||
DEFINES += QT_DEPRECATED_WARNINGS | ||
|
||
# You can also make your code fail to compile if it uses deprecated APIs. | ||
# In order to do so, uncomment the following line. | ||
# You can also select to disable deprecated APIs only up to a certain version of Qt. | ||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 | ||
|
||
HEADERS += \ | ||
stellargateway.h \ | ||
wallet.h | ||
|
||
|
||
SOURCES += \ | ||
main.cpp \ | ||
stellargateway.cpp \ | ||
wallet.cpp | ||
|
||
RESOURCES += qml.qrc | ||
|
||
# Additional import path used to resolve QML modules in Qt Creator's code model | ||
QML_IMPORT_PATH = | ||
|
||
# Additional import path used to resolve QML modules just for Qt Quick Designer | ||
QML_DESIGNER_IMPORT_PATH = | ||
|
||
# Default rules for deployment. | ||
qnx: target.path = /tmp/$${TARGET}/bin | ||
else: unix:!android: target.path = /opt/$${TARGET}/bin | ||
!isEmpty(target.path): INSTALLS += target | ||
|
||
DISTFILES += \ | ||
PaymentGUI.qml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import QtQuick 2.14 | ||
import QtQuick.Window 2.14 | ||
import QtQuick.Controls 2.12 | ||
import QtQuick.Controls.Material 2.12 | ||
import QtQuick.Layouts 1.12 | ||
|
||
import Example 2.0 | ||
|
||
ColumnLayout{ | ||
id: paymentGui; | ||
property Wallet sourceWallet; | ||
|
||
|
||
readonly property bool fundedTarget : targetWallet.funded; | ||
readonly property bool validTarget : targetWallet.publicAddress!=""; | ||
Wallet{ | ||
id:targetWallet; | ||
gateway : testHorizonGateway;//assign gateway to wallet object, it calls the WRITE method of the property | ||
publicAddress: destinationField.text; | ||
} | ||
Label{ | ||
text:qsTr("Payment"); | ||
|
||
} | ||
RowLayout{ | ||
Label{ | ||
text:qsTr("Destination"); | ||
} | ||
TextField{ | ||
id:destinationField; | ||
Layout.fillWidth: true; | ||
onFocusChanged:{ | ||
if(focus) | ||
selectAll() | ||
} | ||
} | ||
Label{ | ||
color:Qt.rgba(1,0,0,1); | ||
visible: !validTarget; | ||
text:qsTr("Invalid destination wallet"); | ||
} | ||
} | ||
|
||
RowLayout{ | ||
Label{ | ||
text:qsTr("Amount"); | ||
} | ||
TextField{ | ||
id:amountField; | ||
onFocusChanged:{ | ||
if(focus) | ||
selectAll() | ||
} | ||
} | ||
} | ||
RowLayout{ | ||
Label{ | ||
text:qsTr("Memo"); | ||
} | ||
TextField{ | ||
id:memoField; | ||
onFocusChanged:{ | ||
if(focus) | ||
selectAll() | ||
} | ||
} | ||
} | ||
Button{ | ||
text:qsTr("Pay"); | ||
visible: fundedTarget; | ||
onClicked: { | ||
sourceWallet.pay(destinationField.text,amountField.text,memoField.text); | ||
paymentGui.enabled=false; | ||
} | ||
} | ||
Button{ | ||
text:qsTr("Create"); | ||
visible: validTarget && !fundedTarget; | ||
onClicked: { | ||
sourceWallet.create(destinationField.text,amountField.text,memoField.text); | ||
paymentGui.enabled=false; | ||
} | ||
} | ||
//this is a way to connect signals to functions on the GUI | ||
Connections{ | ||
target:sourceWallet; | ||
onSuccess:{ | ||
targetWallet.update(); | ||
paymentGui.enabled=true; | ||
} | ||
onError:{ | ||
paymentGui.enabled=true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <QGuiApplication> | ||
#include <QQmlApplicationEngine> | ||
#include "stellargateway.h" | ||
#include "wallet.h" | ||
int main(int argc, char *argv[]) | ||
{ | ||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | ||
|
||
QGuiApplication app(argc, argv); | ||
|
||
//we register the types so they can be used from QML importing "Example 2.0". From Qt5.15 there will be a new and better way to register types. | ||
qmlRegisterType<StellarGateway>("Example",2,0, "StellarGateway"); | ||
qmlRegisterType<Wallet>("Example",2,0, "Wallet"); | ||
|
||
QQmlApplicationEngine engine; | ||
const QUrl url(QStringLiteral("qrc:/main.qml")); | ||
|
||
//connection that exits application with -1 if there is a problem loading main.qml | ||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, | ||
&app, [url](QObject *obj, const QUrl &objUrl) { | ||
if (!obj && url == objUrl) | ||
QCoreApplication::exit(-1); | ||
}, Qt::QueuedConnection); | ||
|
||
//here the gui is loaded. | ||
engine.load(url); | ||
|
||
//here is when all the signals and slots starts to execute. | ||
return app.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import QtQuick 2.14 | ||
import QtQuick.Window 2.14 | ||
import QtQuick.Controls 2.12 | ||
import QtQuick.Controls.Material 2.12 | ||
import QtQuick.Layouts 1.12 | ||
|
||
import Example 2.0 | ||
Window { | ||
visible: true | ||
width: 640 | ||
height: 480 | ||
title: qsTr("Example 2") | ||
|
||
|
||
|
||
//instance the stellar gateway, it builds the StellarGateway object | ||
StellarGateway{ | ||
id: testHorizonGateway; | ||
} | ||
|
||
Wallet{ | ||
id:localWallet; | ||
gateway : testHorizonGateway;//assign gateway to wallet object, it calls the WRITE method of the property | ||
} | ||
|
||
|
||
ColumnLayout{ | ||
|
||
anchors.fill: parent; | ||
anchors.margins: 5; | ||
RowLayout{ | ||
Label{ | ||
text:qsTr("Our account"); | ||
} | ||
TextField{ | ||
text: localWallet.publicAddress;//it binds publicAddress to text, each time publicAddress signal is emitted, it will be updated | ||
enabled:false; | ||
Layout.fillWidth: true; | ||
} | ||
Button{ | ||
id:createButton; | ||
text:qsTr("Create"); | ||
visible: localWallet.publicAddress==""; | ||
onClicked: { | ||
localWallet.createRandom(); | ||
} | ||
} | ||
Button{ | ||
id:fundButton; | ||
visible: localWallet.publicAddress!="" && !localWallet.funded; | ||
text:qsTr("Fund"); | ||
onClicked: { | ||
localWallet.fund(); | ||
} | ||
} | ||
} | ||
RowLayout{ | ||
Label{ | ||
text:qsTr("Balance"); | ||
} | ||
TextField{ | ||
text:localWallet.balance; | ||
enabled:false; | ||
} | ||
} | ||
PaymentGUI{ | ||
sourceWallet: localWallet; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<RCC> | ||
<qresource prefix="/"> | ||
<file>main.qml</file> | ||
<file>PaymentGUI.qml</file> | ||
</qresource> | ||
</RCC> |
Oops, something went wrong.