Merge 76b02d78771eb6be429fe52eb1557304baec8637 into 23f41c893a2d59b77f1e56764114ccc481d4e196

This commit is contained in:
Pravdyvy 2026-06-22 12:24:01 +03:00 committed by GitHub
commit 09db9007fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18762 additions and 4124 deletions

22817
flake.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
inputs = {
logos-module-builder.url = "github:logos-co/logos-module-builder";
nix-bundle-lgx.url = "github:logos-co/nix-bundle-lgx";
logos_execution_zone.url = "github:logos-blockchain/logos-execution-zone-module";
logos_execution_zone.url = "github:logos-blockchain/logos-execution-zone-module?rev=024b63f2d5e263870c5e1d76cafba211bdceebe3";
};
outputs = inputs@{ logos-module-builder, ... }:

View File

@ -14,6 +14,8 @@
#include <QSettings>
#include <QTimer>
#include <QUrl>
#include <QList>
#include <QString>
#include "logos_api.h"
#include "logos_api_client.h"
@ -56,6 +58,23 @@ namespace {
}
}
static bool hexToU128(const QString& hex, uint8_t (*output)[16])
{
if (hex.isEmpty() || hex.length() != 32)
return false;
for (int i = 0; i < 16; i++)
{
bool ok = false;
uint8_t byte = static_cast<uint8_t>(hex.mid(i * 2, 2).toUInt(&ok, 16));
if (!ok)
return false;
(*output)[i] = byte;
}
return true;
}
LEZWalletBackend::LEZWalletBackend(LogosAPI* logosAPI, QObject* parent)
: LEZWalletBackendSimpleSource(parent),
m_accountModel(new LEZWalletAccountModel(this)),
@ -262,9 +281,55 @@ bool LEZWalletBackend::syncToBlock(quint64 blockId)
QString LEZWalletBackend::transferPublic(QString fromHex, QString toHex, QString amountStr)
{
QStringList account_ids = { fromHex, toHex };
QStringList signing_requirements = { "true", "false" };
QStringList elf_json = m_logos->logos_execution_zone.authenticated_transfer_elf();
// No dependencies
QStringList program_dependencies;
// Instruction encoding, the hardest part
// RISC0 consumes not bytes, but uint32_t words
// construction of which is dependant on Rust serialization
// In this exact case instruction is:
//
// Instruction::Transfer {
// amount: u128
// }
//
// which encodes to [0, word_1, word_2, word_3, word_4]
// where 0 - is Transfer enum identifier and words is from le representation of u128.
const QString amountHex = amountToLe16Hex(amountStr);
if (amountHex.isEmpty()) return QStringLiteral("Error: Invalid amount.");
return m_logos->logos_execution_zone.transfer_public(fromHex, toHex, amountHex);
uint8_t amount[16];
if (!hexToU128(amountHex, &amount)) {
return QStringLiteral("Error: Invalid amount.");
}
QList<uint32_t> amount_words;
amount_words.reserve(5);
amount_words.append(0);
for (int i = 0; i < 4; ++i) {
uint32_t word = static_cast<uint32_t>(amount[i * 4])
| static_cast<uint32_t>(amount[i * 4 + 1]) << 8
| static_cast<uint32_t>(amount[i * 4 + 2]) << 16
| static_cast<uint32_t>(amount[i * 4 + 3]) << 24;
amount_words.append(word);
}
QStringList amount_list;
amount_list.reserve(amount_words.size());
for (const uint32_t word : amount_words) {
amount_list.append(QString::number(word));
}
const QStringList& account_ids_ref = account_ids;
const QStringList& signing_requirements_ref = signing_requirements;
const QStringList& input_data_ref = amount_list;
const QStringList& elf_json_ref = elf_json;
const QStringList& program_dependencies_ref = program_dependencies;
return m_logos->logos_execution_zone.send_generic_public_transaction(account_ids_ref, signing_requirements_ref, input_data_ref, elf_json_ref, program_dependencies_ref);
}
QString LEZWalletBackend::transferPrivate(QString fromHex, QString toHex, QString amountStr)