mirror of
https://github.com/logos-blockchain/logos-execution-zone-module.git
synced 2026-05-21 12:09:26 +00:00
feat: add send_public_transaction for arbitrary program transactions
This commit is contained in:
parent
b94ce296a0
commit
3edadf1e73
@ -88,6 +88,11 @@ public:
|
||||
virtual QString register_public_account(const QString& account_id_hex) = 0;
|
||||
virtual QString register_private_account(const QString& account_id_hex) = 0;
|
||||
|
||||
/// Submit an arbitrary public transaction.
|
||||
/// tx_json: {"program_id":"hex","accounts":["hex",...],"instruction":"hex","signer_account":"hex"}
|
||||
/// Returns tx_hash on success, empty string on failure.
|
||||
virtual QString send_public_transaction(const QString& tx_json) = 0;
|
||||
|
||||
// Wallet Lifecycle
|
||||
virtual int create_new(
|
||||
const QString& config_path,
|
||||
|
||||
@ -785,3 +785,66 @@ QString LogosExecutionZoneWalletModule::get_sequencer_addr() {
|
||||
wallet_ffi_free_string(addr);
|
||||
return result;
|
||||
}
|
||||
|
||||
// === Generic Transaction ===
|
||||
|
||||
QString LogosExecutionZoneWalletModule::send_public_transaction(const QString& tx_json) {
|
||||
const QJsonDocument doc = QJsonDocument::fromJson(tx_json.toUtf8());
|
||||
if (!doc.isObject()) {
|
||||
qWarning() << "send_public_transaction: invalid JSON";
|
||||
return transferResultToJson(nullptr, QStringLiteral("invalid JSON"));
|
||||
}
|
||||
|
||||
const QJsonObject obj = doc.object();
|
||||
|
||||
// Parse program_id (32 bytes hex)
|
||||
FfiBytes32 programId{};
|
||||
if (!hexToBytes32(obj["program_id"].toString(), &programId)) {
|
||||
qWarning() << "send_public_transaction: invalid program_id";
|
||||
return transferResultToJson(nullptr, QStringLiteral("invalid program_id"));
|
||||
}
|
||||
|
||||
// Parse accounts array
|
||||
const QJsonArray accountsArr = obj["accounts"].toArray();
|
||||
std::vector<FfiBytes32> accounts(accountsArr.size());
|
||||
for (int i = 0; i < accountsArr.size(); ++i) {
|
||||
if (!hexToBytes32(accountsArr[i].toString(), &accounts[i])) {
|
||||
qWarning() << "send_public_transaction: invalid account at index" << i;
|
||||
return transferResultToJson(nullptr, QStringLiteral("invalid account hex"));
|
||||
}
|
||||
}
|
||||
|
||||
// Parse instruction (hex-encoded raw bytes)
|
||||
QByteArray instrBytes;
|
||||
if (!hexToBytes(obj["instruction"].toString(), instrBytes)) {
|
||||
qWarning() << "send_public_transaction: invalid instruction hex";
|
||||
return transferResultToJson(nullptr, QStringLiteral("invalid instruction hex"));
|
||||
}
|
||||
|
||||
// Parse signer
|
||||
FfiBytes32 signer{};
|
||||
if (!hexToBytes32(obj["signer_account"].toString(), &signer)) {
|
||||
qWarning() << "send_public_transaction: invalid signer_account";
|
||||
return transferResultToJson(nullptr, QStringLiteral("invalid signer_account"));
|
||||
}
|
||||
|
||||
FfiTransferResult result{};
|
||||
const WalletFfiError error = wallet_ffi_send_public_transaction(
|
||||
walletHandle,
|
||||
&programId,
|
||||
accounts.data(),
|
||||
accounts.size(),
|
||||
reinterpret_cast<const uint8_t*>(instrBytes.constData()),
|
||||
static_cast<size_t>(instrBytes.size()),
|
||||
&signer,
|
||||
&result);
|
||||
|
||||
if (error != SUCCESS) {
|
||||
qWarning() << "send_public_transaction: wallet FFI error" << error;
|
||||
return transferResultToJson(nullptr, QStringLiteral("wallet FFI error ") + QString::number(error));
|
||||
}
|
||||
|
||||
QString resultJson = transferResultToJson(&result, QString());
|
||||
wallet_ffi_free_transfer_result(&result);
|
||||
return resultJson;
|
||||
}
|
||||
|
||||
@ -114,6 +114,7 @@ public:
|
||||
) override;
|
||||
Q_INVOKABLE QString register_public_account(const QString& account_id_hex) override;
|
||||
Q_INVOKABLE QString register_private_account(const QString& account_id_hex) override;
|
||||
Q_INVOKABLE QString send_public_transaction(const QString& tx_json) override;
|
||||
|
||||
// Wallet Lifecycle
|
||||
Q_INVOKABLE int create_new(const QString& config_path, const QString& storage_path, const QString& password) override;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user