mirror of
https://github.com/logos-blockchain/lez-programs.git
synced 2026-07-21 06:19:32 +00:00
119 lines
3.3 KiB
C++
119 lines
3.3 KiB
C++
#pragma once
|
|
|
|
#include <functional>
|
|
#include <QString>
|
|
#include <QStringList>
|
|
#include <QVector>
|
|
|
|
enum class WalletFailure {
|
|
None,
|
|
WalletMissing,
|
|
WalletUnavailable,
|
|
OpenFailed,
|
|
CreateFailed,
|
|
SaveFailed,
|
|
ReadFailed,
|
|
InvalidRequest,
|
|
SubmissionFailed,
|
|
};
|
|
|
|
QString walletFailureCode(WalletFailure failure);
|
|
|
|
struct WalletPaths {
|
|
QString config;
|
|
QString storage;
|
|
};
|
|
|
|
struct WalletAccountRead {
|
|
QString accountId;
|
|
QString status = QStringLiteral("read_failed");
|
|
QString programOwner;
|
|
QString balanceHex;
|
|
QString nonceHex;
|
|
QString dataHex;
|
|
|
|
bool ok() const { return status == QStringLiteral("ok"); }
|
|
};
|
|
|
|
struct WalletAccount {
|
|
QString address;
|
|
QString balance;
|
|
bool isPublic = true;
|
|
};
|
|
|
|
struct WalletSnapshot {
|
|
WalletFailure failure = WalletFailure::None;
|
|
QVector<WalletAccount> accounts;
|
|
QVector<WalletAccountRead> publicAccountReads;
|
|
quint64 lastSyncedBlock = 0;
|
|
quint64 currentBlockHeight = 0;
|
|
QString sequencerAddress;
|
|
|
|
bool ok() const { return failure == WalletFailure::None; }
|
|
};
|
|
|
|
struct WalletSession {
|
|
WalletFailure failure = WalletFailure::None;
|
|
WalletSnapshot snapshot;
|
|
bool adopted = false;
|
|
|
|
bool ok() const { return failure == WalletFailure::None; }
|
|
};
|
|
|
|
struct WalletCreation {
|
|
WalletFailure failure = WalletFailure::None;
|
|
QString mnemonic;
|
|
WalletSnapshot snapshot;
|
|
|
|
bool ok() const { return failure == WalletFailure::None; }
|
|
};
|
|
|
|
struct WalletAccountCreation {
|
|
WalletFailure failure = WalletFailure::None;
|
|
QString accountId;
|
|
WalletAccountRead publicAccount;
|
|
WalletSnapshot snapshot;
|
|
|
|
bool ok() const { return failure == WalletFailure::None; }
|
|
};
|
|
|
|
struct WalletTransaction {
|
|
QString programId;
|
|
QStringList accountIds;
|
|
QVector<bool> signingRequirements;
|
|
QVector<quint32> instruction;
|
|
};
|
|
|
|
struct WalletSubmission {
|
|
WalletFailure failure = WalletFailure::None;
|
|
QString nativeHash;
|
|
|
|
bool accepted() const { return failure == WalletFailure::None && !nativeHash.isEmpty(); }
|
|
};
|
|
|
|
class WalletProvider {
|
|
public:
|
|
using SessionCallback = std::function<void(WalletSession)>;
|
|
using SnapshotCallback = std::function<void(WalletSnapshot)>;
|
|
using AccountCreationCallback = std::function<void(WalletAccountCreation)>;
|
|
using SubmissionCallback = std::function<void(WalletSubmission)>;
|
|
|
|
virtual ~WalletProvider() = default;
|
|
|
|
virtual WalletSession connect(const WalletPaths& paths) = 0;
|
|
virtual void connectAsync(const WalletPaths& paths, SessionCallback callback) = 0;
|
|
virtual WalletCreation createWallet(const WalletPaths& paths,
|
|
const QString& password) = 0;
|
|
virtual WalletSnapshot snapshot(bool forceRefresh = false) = 0;
|
|
virtual void snapshotAsync(bool forceRefresh, SnapshotCallback callback) = 0;
|
|
virtual void clearSnapshot() = 0;
|
|
virtual WalletAccountCreation createAccount(bool isPublic) = 0;
|
|
virtual void createAccountAsync(bool isPublic, AccountCreationCallback callback) = 0;
|
|
virtual WalletAccountRead readPublicAccount(const QString& accountId) const = 0;
|
|
virtual WalletSubmission submitPublicTransaction(
|
|
const WalletTransaction& transaction) = 0;
|
|
virtual void submitPublicTransactionAsync(
|
|
const WalletTransaction& transaction, SubmissionCallback callback) = 0;
|
|
virtual void disconnect() = 0;
|
|
};
|