mirror of
https://github.com/logos-blockchain/logos-execution-zone-module.git
synced 2026-04-02 20:23:17 +00:00
Prettify
This commit is contained in:
parent
8dddebc7a8
commit
69caefdc54
7
justfile
7
justfile
@ -10,12 +10,15 @@ build: configure
|
||||
cmake --build build --parallel --target liblogos-execution-zone-wallet-module
|
||||
|
||||
clean:
|
||||
rm -rf build target
|
||||
rm -rf build result
|
||||
|
||||
rebuild: clean configure build
|
||||
rebuild: clean build
|
||||
|
||||
nix:
|
||||
nix develop
|
||||
|
||||
prettify:
|
||||
nix shell nixpkgs#clang-tools -c clang-format -i src/**.cpp src/**.h
|
||||
|
||||
unicode-logs file:
|
||||
perl -pe 's/\\u([0-9A-Fa-f]{4})/chr(hex($1))/ge' {{file}} | less -R
|
||||
|
||||
@ -32,22 +32,10 @@ public:
|
||||
bool is_public,
|
||||
QString& output_balance_le16_hex
|
||||
) = 0;
|
||||
virtual WalletFfiError get_account_public(
|
||||
const QString& account_id_hex,
|
||||
QString& output_account_json
|
||||
) = 0;
|
||||
virtual WalletFfiError get_account_private(
|
||||
const QString& account_id_hex,
|
||||
QString& output_account_json
|
||||
) = 0;
|
||||
virtual WalletFfiError get_public_account_key(
|
||||
const QString& account_id_hex,
|
||||
QString& output_public_key_hex
|
||||
) = 0;
|
||||
virtual WalletFfiError get_private_account_keys(
|
||||
const QString& account_id_hex,
|
||||
QString& output_keys_json
|
||||
) = 0;
|
||||
virtual WalletFfiError get_account_public(const QString& account_id_hex, QString& output_account_json) = 0;
|
||||
virtual WalletFfiError get_account_private(const QString& account_id_hex, QString& output_account_json) = 0;
|
||||
virtual WalletFfiError get_public_account_key(const QString& account_id_hex, QString& output_public_key_hex) = 0;
|
||||
virtual WalletFfiError get_private_account_keys(const QString& account_id_hex, QString& output_keys_json) = 0;
|
||||
|
||||
// Account Encoding
|
||||
virtual QString account_id_to_base58(const QString& account_id_hex) = 0;
|
||||
@ -95,14 +83,8 @@ public:
|
||||
const QString& amount_le16_hex,
|
||||
QString& output_result_json
|
||||
) = 0;
|
||||
virtual WalletFfiError register_public_account(
|
||||
const QString& account_id_hex,
|
||||
QString& output_result_json
|
||||
) = 0;
|
||||
virtual WalletFfiError register_private_account(
|
||||
const QString& account_id_hex,
|
||||
QString& output_result_json
|
||||
) = 0;
|
||||
virtual WalletFfiError register_public_account(const QString& account_id_hex, QString& output_result_json) = 0;
|
||||
virtual WalletFfiError register_private_account(const QString& account_id_hex, QString& output_result_json) = 0;
|
||||
|
||||
// Wallet Lifecycle
|
||||
virtual WalletFfiError create_new(
|
||||
|
||||
@ -12,31 +12,35 @@ static QString bytesToHex(const uint8_t* data, const size_t length) {
|
||||
}
|
||||
|
||||
namespace JsonKeys {
|
||||
static constexpr auto TxHash = "tx_hash";
|
||||
static constexpr auto Success = "success";
|
||||
static constexpr auto ProgramOwner = "program_owner";
|
||||
static constexpr auto Balance = "balance";
|
||||
static constexpr auto Nonce = "nonce";
|
||||
static constexpr auto Data = "data";
|
||||
static constexpr auto NullifierPublicKey = "nullifier_public_key";
|
||||
static constexpr auto ViewingPublicKey = "viewing_public_key";
|
||||
static constexpr auto AccountId = "account_id";
|
||||
static constexpr auto IsPublic = "is_public";
|
||||
}
|
||||
static constexpr auto TxHash = "tx_hash";
|
||||
static constexpr auto Success = "success";
|
||||
static constexpr auto ProgramOwner = "program_owner";
|
||||
static constexpr auto Balance = "balance";
|
||||
static constexpr auto Nonce = "nonce";
|
||||
static constexpr auto Data = "data";
|
||||
static constexpr auto NullifierPublicKey = "nullifier_public_key";
|
||||
static constexpr auto ViewingPublicKey = "viewing_public_key";
|
||||
static constexpr auto AccountId = "account_id";
|
||||
static constexpr auto IsPublic = "is_public";
|
||||
} // namespace JsonKeys
|
||||
|
||||
static bool hexToBytes(const QString& hex, QByteArray& output_bytes, int expectedLength = -1) {
|
||||
QString trimmed_hex = hex.trimmed();
|
||||
if (trimmed_hex.startsWith("0x", Qt::CaseInsensitive)) trimmed_hex = trimmed_hex.mid(2);
|
||||
if (trimmed_hex.size() % 2 != 0) return false;
|
||||
if (trimmed_hex.startsWith("0x", Qt::CaseInsensitive))
|
||||
trimmed_hex = trimmed_hex.mid(2);
|
||||
if (trimmed_hex.size() % 2 != 0)
|
||||
return false;
|
||||
const QByteArray decoded = QByteArray::fromHex(trimmed_hex.toLatin1());
|
||||
if (expectedLength != -1 && decoded.size() != expectedLength) return false;
|
||||
if (expectedLength != -1 && decoded.size() != expectedLength)
|
||||
return false;
|
||||
output_bytes = decoded;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool hexToU128(const QString& hex, uint8_t (*output)[16]) {
|
||||
QByteArray buffer;
|
||||
if (!hexToBytes(hex, buffer, 16)) return false;
|
||||
if (!hexToBytes(hex, buffer, 16))
|
||||
return false;
|
||||
memcpy(output, buffer.constData(), 16);
|
||||
return true;
|
||||
}
|
||||
@ -46,9 +50,11 @@ static QString bytes32ToHex(const FfiBytes32& bytes) {
|
||||
}
|
||||
|
||||
static bool hexToBytes32(const QString& hex, FfiBytes32* output_bytes) {
|
||||
if (output_bytes == nullptr) return false;
|
||||
if (output_bytes == nullptr)
|
||||
return false;
|
||||
QByteArray buffer;
|
||||
if (!hexToBytes(hex, buffer, 32)) return false;
|
||||
if (!hexToBytes(hex, buffer, 32))
|
||||
return false;
|
||||
memcpy(output_bytes->data, buffer.constData(), 32);
|
||||
return true;
|
||||
}
|
||||
@ -93,17 +99,20 @@ static QString ffiPrivateAccountKeysToJson(const FfiPrivateAccountKeys& keys) {
|
||||
|
||||
static bool jsonToFfiPrivateAccountKeys(const QString& json, FfiPrivateAccountKeys* output_keys) {
|
||||
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
||||
if (!doc.isObject()) return false;
|
||||
if (!doc.isObject())
|
||||
return false;
|
||||
const QVariantMap map = doc.object().toVariantMap();
|
||||
|
||||
|
||||
if (map.contains(JsonKeys::NullifierPublicKey)) {
|
||||
if (!hexToBytes32(map[JsonKeys::NullifierPublicKey].toString(), &output_keys->nullifier_public_key)) return false;
|
||||
if (!hexToBytes32(map[JsonKeys::NullifierPublicKey].toString(), &output_keys->nullifier_public_key))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (map.contains(JsonKeys::ViewingPublicKey)) {
|
||||
QByteArray buffer;
|
||||
if (!hexToBytes(map[JsonKeys::ViewingPublicKey].toString(), buffer)) return false;
|
||||
|
||||
if (!hexToBytes(map[JsonKeys::ViewingPublicKey].toString(), buffer))
|
||||
return false;
|
||||
|
||||
uint8_t* data = static_cast<uint8_t*>(malloc(buffer.size()));
|
||||
memcpy(data, buffer.constData(), buffer.size());
|
||||
output_keys->viewing_public_key = data;
|
||||
@ -112,7 +121,7 @@ static bool jsonToFfiPrivateAccountKeys(const QString& json, FfiPrivateAccountKe
|
||||
output_keys->viewing_public_key = nullptr;
|
||||
output_keys->viewing_public_key_len = 0;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -362,7 +371,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_shielded(
|
||||
output_result_json = ffiTransferResultToJson(result);
|
||||
wallet_ffi_free_transfer_result(&result);
|
||||
}
|
||||
|
||||
|
||||
free(const_cast<uint8_t*>(toKeys.viewing_public_key));
|
||||
return error;
|
||||
}
|
||||
@ -422,7 +431,7 @@ WalletFfiError LogosExecutionZoneWalletModule::transfer_private(
|
||||
output_result_json = ffiTransferResultToJson(result);
|
||||
wallet_ffi_free_transfer_result(&result);
|
||||
}
|
||||
|
||||
|
||||
free(const_cast<uint8_t*>(toKeys.viewing_public_key));
|
||||
return error;
|
||||
}
|
||||
|
||||
@ -36,27 +36,20 @@ public:
|
||||
Q_INVOKABLE WalletFfiError list_accounts(QJsonArray& output_list) override;
|
||||
|
||||
// Account Queries
|
||||
Q_INVOKABLE WalletFfiError get_balance(
|
||||
const QString& account_id_hex,
|
||||
bool is_public,
|
||||
QString& output_balance_le16_hex
|
||||
) override;
|
||||
Q_INVOKABLE WalletFfiError
|
||||
get_account_public(const QString& account_id_hex, QString& output_account_json) override;
|
||||
get_balance(const QString& account_id_hex, bool is_public, QString& output_balance_le16_hex) override;
|
||||
Q_INVOKABLE WalletFfiError get_account_public(const QString& account_id_hex, QString& output_account_json) override;
|
||||
Q_INVOKABLE WalletFfiError
|
||||
get_account_private(const QString& account_id_hex, QString& output_account_json) override;
|
||||
Q_INVOKABLE WalletFfiError get_public_account_key(
|
||||
const QString& account_id_hex,
|
||||
QString& output_public_key_hex
|
||||
) override;
|
||||
Q_INVOKABLE WalletFfiError get_private_account_keys(
|
||||
const QString& account_id_hex,
|
||||
QString& output_keys_json
|
||||
) override;
|
||||
Q_INVOKABLE WalletFfiError
|
||||
get_public_account_key(const QString& account_id_hex, QString& output_public_key_hex) override;
|
||||
Q_INVOKABLE WalletFfiError
|
||||
get_private_account_keys(const QString& account_id_hex, QString& output_keys_json) override;
|
||||
|
||||
// Account Encoding
|
||||
Q_INVOKABLE QString account_id_to_base58(const QString& account_id_hex) override;
|
||||
Q_INVOKABLE WalletFfiError account_id_from_base58(const QString& base58_str, QString& output_account_id_hex) override;
|
||||
Q_INVOKABLE WalletFfiError
|
||||
account_id_from_base58(const QString& base58_str, QString& output_account_id_hex) override;
|
||||
|
||||
// Blockchain Synchronisation
|
||||
Q_INVOKABLE WalletFfiError sync_to_block(uint64_t block_id) override;
|
||||
@ -106,11 +99,8 @@ public:
|
||||
register_private_account(const QString& account_id_hex, QString& output_result_json) override;
|
||||
|
||||
// Wallet Lifecycle
|
||||
Q_INVOKABLE WalletFfiError create_new(
|
||||
const QString& config_path,
|
||||
const QString& storage_path,
|
||||
const QString& password
|
||||
) override;
|
||||
Q_INVOKABLE WalletFfiError
|
||||
create_new(const QString& config_path, const QString& storage_path, const QString& password) override;
|
||||
Q_INVOKABLE WalletFfiError open(const QString& config_path, const QString& storage_path) override;
|
||||
Q_INVOKABLE WalletFfiError save() override;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user