From bc58b0b5dcf6162b379d7d53636c3b49ca293f55 Mon Sep 17 00:00:00 2001 From: Franziska Mueller <11660876+Franziska-Mueller@users.noreply.github.com> Date: Thu, 30 Jul 2026 15:51:20 +0200 Subject: [PATCH 1/5] use spans to make connection receive and send safe from oob --- CMakeLists.txt | 3 +- asset_utils.cpp | 6 +- connection.cpp | 39 ++++--- connection.h | 45 ++++++-- defines.h | 2 +- escrow.cpp | 70 ++++++------ file_upload.cpp | 4 +- msvault.cpp | 272 +++++++++++++++++++++++------------------------ node_utils.cpp | 79 +++++++------- nostromo.cpp | 44 ++++---- oracle_utils.cpp | 20 ++-- qbond.cpp | 95 ++++++++--------- qearn.cpp | 20 ++-- qpi_adapter.h | 2 +- qswap.cpp | 36 +++---- quottery.cpp | 6 +- qutil.cpp | 24 ++--- qvault.cpp | 26 ++--- qx.cpp | 18 ++-- submodules/core | 2 +- test_utils.cpp | 8 +- utils.h | 7 +- wallet_utils.cpp | 32 +++--- 23 files changed, 445 insertions(+), 415 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 35258372..46b17089 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.12) project(qubic-cli CXX) -set (CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) # keep the lists sorted alphabetically SET(FILES ${CMAKE_SOURCE_DIR}/asset_utils.cpp diff --git a/asset_utils.cpp b/asset_utils.cpp index f050743a..9e63604f 100644 --- a/asset_utils.cpp +++ b/asset_utils.cpp @@ -55,7 +55,7 @@ std::vector getOwnedAsset(const char * nodeIp, const int nod packet.header.randomizeDejavu(); packet.header.setType(REQUEST_OWNED_ASSETS); auto qc = make_qc(nodeIp, nodePort); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); return qc->getLatestVectorPacketAs(); } @@ -74,7 +74,7 @@ std::vector getPossessionAsset(const char * nodeIp, cons packet.header.randomizeDejavu(); packet.header.setType(REQUEST_POSSESSED_ASSETS); auto qc = make_qc(nodeIp, nodePort); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); return qc->getLatestVectorPacketAs(); } @@ -405,7 +405,7 @@ void printAssetRecords(const char* nodeIp, const int nodePort, const char* reque } auto qc = make_qc(nodeIp, nodePort); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); bool receivedResponses = false; if (withSiblings) diff --git a/connection.cpp b/connection.cpp index 30967172..72ae7088 100644 --- a/connection.cpp +++ b/connection.cpp @@ -151,8 +151,11 @@ QubicConnection::~QubicConnection() } // Receive the requested number of bytes (sz) or less if sz bytes have not been received after timeout. Return number of received bytes. -int QubicConnection::receiveData(uint8_t* buffer, int sz) +int QubicConnection::receiveData(std::span buffer, unsigned int sz) { + if (sz > buffer.size()) + throw std::logic_error("Buffer size is smaller than requested size."); + int totalRecvSz = 0; while (sz) { @@ -166,7 +169,7 @@ int QubicConnection::receiveData(uint8_t* buffer, int sz) // "For connection-oriented sockets (type SOCK_STREAM for example), calling recv will // return as much data as is currently available up to the size of the buffer specified. [...] // If no incoming data is available at the socket, the recv call blocks and waits for data to arrive [...]" - int recvSz = recv(mSocket, (char*)buffer + totalRecvSz, sz, 0); + int recvSz = recv(mSocket, (char*)buffer.data() + totalRecvSz, sz, 0); if (recvSz <= 0) { // timeout, closed connection, or other error @@ -178,7 +181,7 @@ int QubicConnection::receiveData(uint8_t* buffer, int sz) return totalRecvSz; } -int QubicConnection::receiveAllDataOrThrowException(uint8_t* buffer, int sz) +int QubicConnection::receiveAllDataOrThrowException(std::span buffer, unsigned int sz) { int recvSz = receiveData(buffer, sz); if (recvSz != sz) @@ -213,7 +216,7 @@ void QubicConnection::receivePacketWithHeaderAs(T& result) int recvByte = -1, packetSize = -1, remainingSize = -1; while (true) { - recvByte = receiveData((uint8_t*)&header, sizeof(RequestResponseHeader)); + recvByte = receiveData(header); if (recvByte != sizeof(RequestResponseHeader)) { throw std::logic_error("No connection."); @@ -239,9 +242,9 @@ void QubicConnection::receivePacketWithHeaderAs(T& result) memset(&result, 0, sizeof(T)); if (remainingSize) { - memset(mBuffer, 0, sizeof(T)); + mBuffer.fill(0); receiveAllDataOrThrowException(mBuffer, remainingSize); - result = *((T*)mBuffer); + result = *((T*)mBuffer.data()); } } @@ -257,7 +260,7 @@ T QubicConnection::receivePacketAs() { throw std::logic_error("Unexpected data size."); } - result = *((T*)mBuffer); + result = *((T*)mBuffer.data()); return result; } @@ -284,28 +287,36 @@ std::vector QubicConnection::getLatestVectorPacketAs() return results; } -int QubicConnection::sendData(uint8_t* buffer, int sz) +int QubicConnection::sendData(std::span buffer, unsigned int sz) { + if (sz > buffer.size()) + { + throw std::logic_error("Buffer size is smaller than requested send size."); + } // also skip printing packets of size 8 (typically used during the preparation step, not the final stage) - if (!std::string(g_printToScreen).empty() && sz != 8) { + if (!std::string(g_printToScreen).empty() && sz != 8) + { std::string printType = g_printToScreen; // Do not print the first 8 bytes (header) - printBytes(buffer + 8, sz - 8, printType); + printBytes(buffer.data() + 8, sz - 8, printType); // this operation may break the normal flow, we need to skip printing error messages to console if (!std::freopen("/dev/null", "w", stdout)) {} if (!std::freopen("/dev/null", "w", stderr)) {} return 0; - } else { + } + else + { int size = sz; int numberOfBytes; - while (size) + int offset = 0; + while (size > 0) { - if ((numberOfBytes = send(mSocket, (char*)buffer, size, 0)) <= 0) + if ((numberOfBytes = send(mSocket, (const char*)buffer.data() + offset, size, 0)) <= 0) { return 0; } - buffer += numberOfBytes; + offset += numberOfBytes; size -= numberOfBytes; } return sz - size; diff --git a/connection.h b/connection.h index 303785a9..2a361539 100644 --- a/connection.h +++ b/connection.h @@ -4,9 +4,21 @@ #include #include #include +#include +#include #define DEFAULT_TIMEOUT_MSEC 1000 +namespace +{ + // Custom concept to detect if something behaves like a pointer (raw or smart) + template + concept IsPointerLike = std::is_pointer_v || requires(T t) + { + t.operator->(); + }; +} + // Not thread safe class QubicConnection { @@ -20,13 +32,32 @@ class QubicConnection // Receive at most sz bytes and write them to buffer. Return the actual number of received bytes. // Should only return less than sz bytes on timeout, closed connection, or error. - int receiveData(uint8_t* buffer, int sz); + // Throws std::logic_error if sz > buffer.size(). + int receiveData(std::span buffer, unsigned int sz); - // Receive sz bytes and write them to buffer. Throws std::logic_error if sz bytes cannot be read. - int receiveAllDataOrThrowException(uint8_t* buffer, int sz); - - // Send sz bytes contained in buffer. - int sendData(uint8_t* buffer, int sz); + // Receive an object of type T. Return the actual number of received bytes. + // Should only return less than sz bytes on timeout, closed connection, or error. + template + int receiveData(T& obj) + { + return receiveData(std::span(reinterpret_cast(&obj), sizeof(T)), sizeof(T)); + } + + // Receive sz bytes and write them to the buffer. Throws std::logic_error if sz bytes cannot be read. + int receiveAllDataOrThrowException(std::span buffer, unsigned int sz); + + // Send sz bytes contained in buffer. Throws std::logic_error if sz > buffer.size(). + int sendData(std::span buffer, unsigned int sz); + + // Send an object of type T. This template only accepts trivially copyable types that are no ranges or pointers. + template + requires std::is_trivially_copyable_v + && (!std::ranges::range) + && (!IsPointerLike) + int sendData(const T& obj) + { + return sendData(std::span(reinterpret_cast(&obj), sizeof(T)), sizeof(T)); + } //void receiveDataAll(std::vector& buffer); void getHandshakeData(std::vector& buffer); @@ -48,7 +79,7 @@ class QubicConnection char mNodeIp[32]; int mNodePort; int mSocket; - uint8_t mBuffer[0xFFFFFF]; + std::array mBuffer; std::vector mHandshakeData; // storing handshake data after open a connection }; diff --git a/defines.h b/defines.h index 1864def5..c6d980df 100644 --- a/defines.h +++ b/defines.h @@ -8,7 +8,7 @@ #define DEFAULT_SCHEDULED_TICK_OFFSET 8 #define DEFAULT_NODE_PORT 21841 #define DEFAULT_NODE_IP "127.0.0.1" -#define NUMBER_OF_TRANSACTIONS_PER_TICK 4096 +#define NUMBER_OF_TRANSACTIONS_PER_TICK 4096ULL #define SIGNATURE_SIZE 64 #define MAX_INPUT_SIZE 1024ULL #define MAX_TRANSACTION_SIZE (MAX_INPUT_SIZE + sizeof(Transaction) + SIGNATURE_SIZE) diff --git a/escrow.cpp b/escrow.cpp index 1c283f3f..3ef06217 100644 --- a/escrow.cpp +++ b/escrow.cpp @@ -88,7 +88,7 @@ void escrowCreateDeal(const char* nodeIp, int nodePort, const char* seed, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -207,17 +207,23 @@ int64_t escrowGetSharesFeesForDeal(const char* nodeIp, int nodePort, const char* EscrowGetDeals_output escrowGetDealsOutput(const char* nodeIp, int nodePort, const char* seed, const int64_t proposedOffset, const int64_t publicOffset) { - EscrowGetDeals_input input; + struct { + RequestResponseHeader header; + RequestContractFunction rcf; + EscrowGetDeals_input input; + } req; + memset(&req, 0, sizeof(req)); + uint8_t subseed[32] = { 0 }; uint8_t privateKey[32] = { 0 }; uint8_t sourcePublicKey[32] = { 0 }; getSubseedFromSeed((uint8_t*) seed, subseed); getPrivateKeyFromSubSeed(subseed, privateKey); getPublicKeyFromPrivateKey(privateKey, sourcePublicKey); - memset(input.owner, 0, 32); - memcpy(input.owner, sourcePublicKey, 32); - input.proposedOffset = proposedOffset; - input.publicOffset = publicOffset; + memset(req.input.owner, 0, 32); + memcpy(req.input.owner, sourcePublicKey, 32); + req.input.proposedOffset = proposedOffset; + req.input.publicOffset = publicOffset; auto qc = make_qc(nodeIp, nodePort); if (!qc) { @@ -225,22 +231,14 @@ EscrowGetDeals_output escrowGetDealsOutput(const char* nodeIp, int nodePort, con return EscrowGetDeals_output{}; } - struct { - RequestResponseHeader header; - RequestContractFunction rcf; - EscrowGetDeals_input in; - } req; - - memset(&req, 0, sizeof(req)); req.rcf.contractIndex = ESCROW_CONTRACT_INDEX; req.rcf.inputType = ESCROW_GET_DEALS; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.rcf.inputSize = sizeof(req.input); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); EscrowGetDeals_output output; memset(&output, 0, sizeof(output)); @@ -332,7 +330,7 @@ void escrowOperateDeal(const char* nodeIp, int nodePort, const char* seed, const packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -402,7 +400,7 @@ void escrowTransferRights(const char* nodeIp, int nodePort, const char* seed, co packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -416,7 +414,13 @@ void escrowTransferRights(const char* nodeIp, int nodePort, const char* seed, co void escrowGetFreeAsset(const char* nodeIp, int nodePort, const char* seed, const char* assetName, const char* issuer) { - EscrowGetFreeAsset_input input; + struct { + RequestResponseHeader header; + RequestContractFunction rcf; + EscrowGetFreeAsset_input input; + } req; + memset(&req, 0, sizeof(req)); + uint8_t subseed[32] = { 0 }; uint8_t privateKey[32] = { 0 }; uint8_t sourcePublicKey[32] = { 0 }; @@ -426,12 +430,12 @@ void escrowGetFreeAsset(const char* nodeIp, int nodePort, const char* seed, cons getPublicKeyFromPrivateKey(privateKey, pk); getPublicKeyFromIdentity(issuer, sourcePublicKey); - memset(input.owner, 0, 32); - memcpy(input.owner, pk, 32); - memset(input.asset.issuer, 0, 32); - memcpy(input.asset.issuer, sourcePublicKey, 32); - memset(&input.asset.assetName, 0, 8); - memcpy(&input.asset.assetName, assetName, std::min(strlen(assetName), (size_t) 7)); + memset(req.input.owner, 0, 32); + memcpy(req.input.owner, pk, 32); + memset(req.input.asset.issuer, 0, 32); + memcpy(req.input.asset.issuer, sourcePublicKey, 32); + memset(&req.input.asset.assetName, 0, 8); + memcpy(&req.input.asset.assetName, assetName, std::min(strlen(assetName), (size_t) 7)); auto qc = make_qc(nodeIp, nodePort); if (!qc) { @@ -439,22 +443,14 @@ void escrowGetFreeAsset(const char* nodeIp, int nodePort, const char* seed, cons return; } - struct { - RequestResponseHeader header; - RequestContractFunction rcf; - EscrowGetFreeAsset_input in; - } req; - - memset(&req, 0, sizeof(req)); req.rcf.contractIndex = ESCROW_CONTRACT_INDEX; req.rcf.inputType = ESCROW_GET_FREE_ASSET; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.rcf.inputSize = sizeof(req.input); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); EscrowGetFreeAsset_output output; memset(&output, 0, sizeof(output)); diff --git a/file_upload.cpp b/file_upload.cpp index d45a76a1..205ef3d2 100644 --- a/file_upload.cpp +++ b/file_upload.cpp @@ -59,7 +59,7 @@ bool uploadHeader(QCPtr& qc, const char* seed, size_t fileSize, int numberOfFrag payload.header.setType(BROADCAST_TRANSACTION); signData(seed, (uint8_t*)&payload.fh, sizeof(payload.fh) - SIGNATURE_SIZE, payload.fh.signature); - qc->sendData((uint8_t *) &payload, payload.header.size()); + qc->sendData(payload); KangarooTwelve((uint8_t*)&payload.fh, sizeof(payload.fh), txHash, 32); LOG("Waiting for tx to be included at tick %d\n", txTick); @@ -125,7 +125,7 @@ bool uploadFragment(QCPtr& qc, const char* seed, const uint64_t fragmentId, payload.header.setType(BROADCAST_TRANSACTION); signData(seed, (uint8_t*)&payload.fftp, sizeof(FileFragmentTransactionPrefix) + fragmentSize, ptr_signature); - qc->sendData((uint8_t *) &payload, payload.header.size()); + qc->sendData(std::span(reinterpret_cast(&payload), payloadSize), static_cast(payloadSize)); KangarooTwelve((uint8_t*)&payload.fftp, uint16_t(sizeof(FileFragmentTransactionPrefix) + fragmentSize + SIGNATURE_SIZE), outTxHash, 32); LOG("Waiting for tx to be included at tick %d\n", txTick); currentTick = getTickNumberFromNode(qc); diff --git a/msvault.cpp b/msvault.cpp index a772f065..7f5a4b5f 100644 --- a/msvault.cpp +++ b/msvault.cpp @@ -56,9 +56,15 @@ static bool queryVaults(const char* nodeIp, int nodePort, const uint8_t publicKe int attempts = 0; while (attempts < maxAttempts) { - MsVaultGetVaults_input input; - memset(&input, 0, sizeof(input)); - memcpy(input.publicKey, publicKey, 32); + struct + { + RequestResponseHeader header; + RequestContractFunction rcf; + MsVaultGetVaults_input input; + } req; + memset(&req, 0, sizeof(req)); + + memcpy(req.input.publicKey, publicKey, 32); auto qc = make_qc(nodeIp, nodePort); if (!qc) @@ -67,23 +73,15 @@ static bool queryVaults(const char* nodeIp, int nodePort, const uint8_t publicKe attempts++; continue; } - - struct - { - RequestResponseHeader header; - RequestContractFunction rcf; - MsVaultGetVaults_input in; - } req; - memset(&req, 0, sizeof(req)); + req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_VAULTS; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.rcf.inputSize = sizeof(req.input); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); memset(&output, 0, sizeof(output)); try @@ -226,7 +224,7 @@ void msvaultRegisterVault(const char* nodeIp, int nodePort, const char* seed, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, 32); getTxHashFromDigest(digest, txHash); @@ -288,7 +286,7 @@ void msvaultDeposit(const char* nodeIp, int nodePort, const char* seed, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -361,7 +359,7 @@ void msvaultReleaseTo(const char* nodeIp, int nodePort, const char* seed, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -425,7 +423,7 @@ void msvaultResetRelease(const char* nodeIp, int nodePort, const char* seed, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -465,8 +463,14 @@ void msvaultGetVaults(const char* nodeIp, int nodePort, const char* identity) void msvaultGetReleaseStatus(const char* nodeIp, int nodePort, uint64_t vaultID) { - MsVaultGetReleaseStatus_input input; - input.vaultID = vaultID; + struct { + RequestResponseHeader header; + RequestContractFunction rcf; + MsVaultGetReleaseStatus_input input; + } req; + memset(&req, 0, sizeof(req)); + + req.input.vaultID = vaultID; auto qc = make_qc(nodeIp, nodePort); if (!qc) { @@ -474,21 +478,14 @@ void msvaultGetReleaseStatus(const char* nodeIp, int nodePort, uint64_t vaultID) return; } - struct { - RequestResponseHeader header; - RequestContractFunction rcf; - MsVaultGetReleaseStatus_input in; - } req; - memset(&req, 0, sizeof(req)); req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_RELEASE_STATUS; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.rcf.inputSize = sizeof(req.input); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultGetReleaseStatus_output output; memset(&output, 0, sizeof(output)); @@ -520,8 +517,14 @@ void msvaultGetReleaseStatus(const char* nodeIp, int nodePort, uint64_t vaultID) void msvaultGetBalanceOf(const char* nodeIp, int nodePort, uint64_t vaultID) { - MsVaultGetBalanceOf_input input; - input.vaultID = vaultID; + struct { + RequestResponseHeader header; + RequestContractFunction rcf; + MsVaultGetBalanceOf_input input; + } req; + memset(&req, 0, sizeof(req)); + + req.input.vaultID = vaultID; auto qc = make_qc(nodeIp, nodePort); if (!qc) { @@ -529,21 +532,14 @@ void msvaultGetBalanceOf(const char* nodeIp, int nodePort, uint64_t vaultID) return; } - struct { - RequestResponseHeader header; - RequestContractFunction rcf; - MsVaultGetBalanceOf_input in; - } req; - memset(&req, 0, sizeof(req)); req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_BALANCE_OF; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.rcf.inputSize = sizeof(req.input); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultGetBalanceOf_output output; memset(&output, 0, sizeof(output)); @@ -566,8 +562,14 @@ void msvaultGetBalanceOf(const char* nodeIp, int nodePort, uint64_t vaultID) void msvaultGetVaultName(const char* nodeIp, int nodePort, uint64_t vaultID) { - MsVaultGetVaultName_input input; - input.vaultID = vaultID; + struct { + RequestResponseHeader header; + RequestContractFunction rcf; + MsVaultGetVaultName_input input; + } req; + memset(&req, 0, sizeof(req)); + + req.input.vaultID = vaultID; auto qc = make_qc(nodeIp, nodePort); if (!qc) { @@ -575,21 +577,14 @@ void msvaultGetVaultName(const char* nodeIp, int nodePort, uint64_t vaultID) return; } - struct { - RequestResponseHeader header; - RequestContractFunction rcf; - MsVaultGetVaultName_input in; - } req; - memset(&req, 0, sizeof(req)); req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_VAULT_NAME; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.rcf.inputSize = sizeof(req.input); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultGetVaultName_output output; memset(&output, 0, sizeof(output)); @@ -626,14 +621,15 @@ void msvaultGetRevenueInfo(const char* nodeIp, int nodePort) RequestContractFunction rcf; } req; memset(&req, 0, sizeof(req)); + req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_REVENUE_INFO; req.rcf.inputSize = 0; - req.header.setSize(sizeof(req.header) + sizeof(req.rcf)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultGetRevenueInfo_output output; memset(&output, 0, sizeof(output)); @@ -652,8 +648,12 @@ void msvaultGetRevenueInfo(const char* nodeIp, int nodePort) void msvaultGetFees(const char* nodeIp, int nodePort) { - MsVaultGetFees_input input; - memset(&input, 0, sizeof(input)); + struct { + RequestResponseHeader header; + RequestContractFunction rcf; + MsVaultGetFees_input input; + } req; + memset(&req, 0, sizeof(req)); auto qc = make_qc(nodeIp, nodePort); if (!qc) { @@ -661,21 +661,14 @@ void msvaultGetFees(const char* nodeIp, int nodePort) return; } - struct { - RequestResponseHeader header; - RequestContractFunction rcf; - MsVaultGetFees_input in; - } req; - memset(&req, 0, sizeof(req)); req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_FEES; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.rcf.inputSize = sizeof(req.input); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - if (qc->sendData((uint8_t*)&req, req.header.size()) != (int)req.header.size()) { + if (qc->sendData(req) != (int)req.header.size()) { LOG("Failed to send msVault getFees request.\n"); return; } @@ -700,9 +693,14 @@ void msvaultGetFees(const char* nodeIp, int nodePort) void msvaultGetVaultOwners(const char* nodeIp, int nodePort, uint64_t vaultID) { - MsVaultGetVaultOwners_input input; - memset(&input, 0, sizeof(input)); - input.vaultID = vaultID; + struct { + RequestResponseHeader header; + RequestContractFunction rcf; + MsVaultGetVaultOwners_input input; + } req; + memset(&req, 0, sizeof(req)); + + req.input.vaultID = vaultID; auto qc = make_qc(nodeIp, nodePort); if (!qc) { @@ -710,22 +708,16 @@ void msvaultGetVaultOwners(const char* nodeIp, int nodePort, uint64_t vaultID) return; } - struct { - RequestResponseHeader header; - RequestContractFunction rcf; - MsVaultGetVaultOwners_input in; - } req; - memset(&req, 0, sizeof(req)); + req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_VAULT_OWNERS; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); + req.rcf.inputSize = sizeof(req.input); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultGetVaultOwners_output output; memset(&output, 0, sizeof(output)); @@ -816,7 +808,7 @@ void msvaultDepositAsset(const char* nodeIp, int nodePort, const char* seed, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -885,7 +877,7 @@ void msvaultReleaseAssetTo(const char* nodeIp, int nodePort, const char* seed, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -948,7 +940,7 @@ void msvaultResetAssetRelease(const char* nodeIp, int nodePort, const char* seed packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, 32); getTxHashFromDigest(digest, txHash); LOG("MsVault resetAssetRelease transaction sent.\n"); @@ -966,27 +958,25 @@ void msvaultGetVaultAssetBalances(const char* nodeIp, int nodePort, uint64_t vau return; } - MsVaultGetVaultAssetBalances_input input; - input.vaultID = vaultID; - struct { RequestResponseHeader header; RequestContractFunction rcf; - MsVaultGetVaultAssetBalances_input in; + MsVaultGetVaultAssetBalances_input input; } req; - memset(&req, 0, sizeof(req)); + + req.input.vaultID = vaultID; + req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_VAULT_ASSET_BALANCES; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); + req.rcf.inputSize = sizeof(req.input); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultGetVaultAssetBalances_output output; memset(&output, 0, sizeof(output)); @@ -1024,28 +1014,27 @@ void msvaultGetAssetReleaseStatus(const char* nodeIp, int nodePort, uint64_t vau { LOG("Failed to connect to node.\n"); return; - } - MsVaultGetAssetReleaseStatus_input input; - input.vaultID = vaultID; + } struct { RequestResponseHeader header; RequestContractFunction rcf; - MsVaultGetAssetReleaseStatus_input in; + MsVaultGetAssetReleaseStatus_input input; } req; - memset(&req, 0, sizeof(req)); + + req.input.vaultID = vaultID; + req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_ASSET_RELEASE_STATUS; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); + req.rcf.inputSize = sizeof(req.input); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultGetAssetReleaseStatus_output output; memset(&output, 0, sizeof(output)); @@ -1101,30 +1090,28 @@ void msvaultGetManagedAssetBalance(const char* nodeIp, int nodePort, const char* LOG("Failed to connect to node.\n"); return; } - MsVaultGetManagedAssetBalance_input input; - memset(&input, 0, sizeof(input)); - getPublicKeyFromIdentity(issuer, input.asset.issuer); - input.asset.assetName = assetNameFromString(assetName); - getPublicKeyFromIdentity(owner, input.owner); - struct { RequestResponseHeader header; RequestContractFunction rcf; - MsVaultGetManagedAssetBalance_input in; + MsVaultGetManagedAssetBalance_input input; } req; - memset(&req, 0, sizeof(req)); + + getPublicKeyFromIdentity(issuer, req.input.asset.issuer); + req.input.asset.assetName = assetNameFromString(assetName); + getPublicKeyFromIdentity(owner, req.input.owner); + + req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_MANAGED_ASSET_BALANCE; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); + req.rcf.inputSize = sizeof(req.input); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultGetManagedAssetBalance_output output; memset(&output, 0, sizeof(output)); @@ -1200,7 +1187,7 @@ void msvaultRevokeAssetManagementRights(const char* nodeIp, int nodePort, const packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, @@ -1216,14 +1203,20 @@ void msvaultRevokeAssetManagementRights(const char* nodeIp, int nodePort, const void msvaultIsShareHolder(const char* nodeIp, int nodePort, const char* identity) { - MsVaultIsShareHolder_input input; - memset(&input, 0, sizeof(input)); + struct + { + RequestResponseHeader header; + RequestContractFunction rcf; + MsVaultIsShareHolder_input input; + } req; + memset(&req, 0, sizeof(req)); + if (!checkSumIdentity(identity)) { LOG("Invalid identity: %s\n", identity); return; } - getPublicKeyFromIdentity(identity, input.candidate); + getPublicKeyFromIdentity(identity, req.input.candidate); auto qc = make_qc(nodeIp, nodePort); if (!qc) @@ -1232,22 +1225,14 @@ void msvaultIsShareHolder(const char* nodeIp, int nodePort, const char* identity return; } - struct - { - RequestResponseHeader header; - RequestContractFunction rcf; - MsVaultIsShareHolder_input in; - } req; - memset(&req, 0, sizeof(req)); req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_IS_SHAREHOLDER; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.rcf.inputSize = sizeof(req.input); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultIsShareHolder_output output; memset(&output, 0, sizeof(output)); @@ -1321,7 +1306,7 @@ void msvaultVoteFeeChange(const char* nodeIp, int nodePort, const char* seed, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -1347,13 +1332,14 @@ void msvaultGetFeeVotes(const char* nodeIp, int nodePort) RequestContractFunction rcf; } req; memset(&req, 0, sizeof(req)); + req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_FEE_VOTES; req.rcf.inputSize = 0; - req.header.setSize(sizeof(req.header) + sizeof(req.rcf)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultGetFeeVotes_output output; memset(&output, 0, sizeof(output)); @@ -1398,13 +1384,14 @@ void msvaultGetFeeVotesOwner(const char* nodeIp, int nodePort) RequestContractFunction rcf; } req; memset(&req, 0, sizeof(req)); + req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_FEE_VOTES_OWNER; req.rcf.inputSize = 0; - req.header.setSize(sizeof(req.header) + sizeof(req.rcf)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultGetFeeVotesOwner_output output; memset(&output, 0, sizeof(output)); @@ -1446,13 +1433,14 @@ void msvaultGetFeeVotesScore(const char* nodeIp, int nodePort) RequestContractFunction rcf; } req; memset(&req, 0, sizeof(req)); + req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_FEE_VOTES_SCORE; req.rcf.inputSize = 0; - req.header.setSize(sizeof(req.header) + sizeof(req.rcf)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultGetFeeVotesScore_output output; memset(&output, 0, sizeof(output)); @@ -1492,13 +1480,14 @@ void msvaultGetUniqueFeeVotes(const char* nodeIp, int nodePort) RequestContractFunction rcf; } req; memset(&req, 0, sizeof(req)); + req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_UNIQUE_FEE_VOTES; req.rcf.inputSize = 0; - req.header.setSize(sizeof(req.header) + sizeof(req.rcf)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultGetUniqueFeeVotes_output output; memset(&output, 0, sizeof(output)); @@ -1543,13 +1532,14 @@ void msvaultGetUniqueFeeVotesRanking(const char* nodeIp, int nodePort) RequestContractFunction rcf; } req; memset(&req, 0, sizeof(req)); + req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_UNIQUE_FEE_VOTES_RANKING; req.rcf.inputSize = 0; - req.header.setSize(sizeof(req.header) + sizeof(req.rcf)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MsVaultGetUniqueFeeVotesRanking_output output; memset(&output, 0, sizeof(output)); diff --git a/node_utils.cpp b/node_utils.cpp index d350c241..56c17984 100644 --- a/node_utils.cpp +++ b/node_utils.cpp @@ -26,7 +26,7 @@ static CurrentTickInfo getTickInfoFromNode(QCPtr qc) packet.header.setSize(sizeof(packet)); packet.header.randomizeDejavu(); packet.header.setType(REQUEST_CURRENT_TICK_INFO); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); try { @@ -79,7 +79,7 @@ CurrentSystemInfo getSystemInfoFromNode(QCPtr qc) packet.header.setSize(sizeof(packet)); packet.header.randomizeDejavu(); packet.header.setType(REQUEST_SYSTEM_INFO); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); try { @@ -242,7 +242,7 @@ void dumpRevenueDataFromNode(const char* nodeIp, int nodePort, const char* outpu packet.header.setSize(sizeof(packet)); packet.header.randomizeDejavu(); packet.header.setType(REQUEST_REVENUE_DATA); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); // RevenueData is ~16 KB; receive into a heap buffer to avoid a large stack frame. auto result = std::make_unique(); @@ -324,19 +324,20 @@ static void getTickTransactions(QCPtr qc, const uint32_t requestedTick, int nTx, packet->txs.tick = requestedTick; for (int i = 0; i < (nTx+7)/8; i++) packet->txs.transactionFlags[i] = 0; for (int i = (nTx+7)/8; i < NUMBER_OF_TRANSACTIONS_PER_TICK/8; i++) packet->txs.transactionFlags[i] = 0xff; - qc->sendData((uint8_t *) packet.get(), packet->header.size()); + qc->sendData(*packet); constexpr unsigned long long bufferSize = sizeof(RequestResponseHeader) + MAX_TRANSACTION_SIZE; - uint8_t buffer[bufferSize]; - int recvByte = qc->receiveData(buffer, sizeof(RequestResponseHeader)); + std::array buffer; + std::span bufferSpan(buffer); + int recvByte = qc->receiveData(bufferSpan, sizeof(RequestResponseHeader)); int recvTx = 0; while (recvByte == sizeof(RequestResponseHeader)) { - auto header = (RequestResponseHeader*)buffer; + auto header = (RequestResponseHeader*)buffer.data(); if (header->type() == BROADCAST_TRANSACTION) { - recvByte = qc->receiveAllDataOrThrowException(buffer + sizeof(RequestResponseHeader), sizeof(Transaction)); - auto tx = (Transaction*)(buffer + sizeof(RequestResponseHeader)); + recvByte = qc->receiveAllDataOrThrowException(bufferSpan.subspan(sizeof(RequestResponseHeader)), sizeof(Transaction)); + auto tx = (Transaction*)(buffer.data() + sizeof(RequestResponseHeader)); txs.push_back(*tx); if (tx->inputSize > MAX_INPUT_SIZE) { @@ -344,7 +345,7 @@ static void getTickTransactions(QCPtr qc, const uint32_t requestedTick, int nTx, exit(1); } ++recvTx; - recvByte = qc->receiveAllDataOrThrowException(buffer + sizeof(RequestResponseHeader) + sizeof(Transaction), tx->inputSize + SIGNATURE_SIZE); + recvByte = qc->receiveAllDataOrThrowException(bufferSpan.subspan(sizeof(RequestResponseHeader) + sizeof(Transaction)), tx->inputSize + SIGNATURE_SIZE); if (hashes != nullptr) { uint8_t digest[32] = { 0 }; @@ -401,7 +402,7 @@ bool getTickData(QCPtr qc, const uint32_t tick, TickData& result) packet.header.randomizeDejavu(); packet.header.setType(REQUEST_TICK_DATA); packet.requestTickData.requestedTickData.tick = tick; - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); try { @@ -431,7 +432,7 @@ int getMoneyFlewStatus(QCPtr qc, const char* txHash, const uint32_t requestedTic packet.header.randomizeDejavu(); packet.header.setType(REQUEST_TX_STATUS); packet.rts.tick = requestedTick; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); RespondTxStatus result; try { @@ -550,19 +551,19 @@ int _GetInputDataFromTxHash(QCPtr& qc, const char* txHash, uint8_t* outData, int packet.header.setType(REQUEST_TRANSACTION_INFO); getPublicKeyFromIdentity(txUpperHash, packet.txs.transactionDigest); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); // Received the respond and print the receipt bool receivedTx = false; constexpr unsigned long long bufferSize = sizeof(RequestResponseHeader) + MAX_TRANSACTION_SIZE; - uint8_t buffer[bufferSize]; + std::array buffer; int recvByte = qc->receiveData(buffer, bufferSize); if (recvByte > 0) { - auto header = (RequestResponseHeader*)buffer; + auto header = (RequestResponseHeader*)buffer.data(); if (header->type() == BROADCAST_TRANSACTION) { - auto tx = (Transaction*)(buffer + sizeof(RequestResponseHeader)); + auto tx = (Transaction*)(buffer.data() + sizeof(RequestResponseHeader)); uint8_t digest[32] = {0}; char respondTxHash[61] = {0}; KangarooTwelve( @@ -618,19 +619,19 @@ int _GetTxInfo(QCPtr& qc, const char* txHash) packet.header.setType(REQUEST_TRANSACTION_INFO); getPublicKeyFromIdentity(txUpperHash, packet.txs.transactionDigest); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); // Received the respond and print the receipt bool receivedTx = false; constexpr unsigned long long bufferSize = sizeof(RequestResponseHeader) + MAX_TRANSACTION_SIZE; - uint8_t buffer[bufferSize]; + std::array buffer; int recvByte = qc->receiveData(buffer, bufferSize); if (recvByte > 0) { - auto header = (RequestResponseHeader*)(buffer); + auto header = (RequestResponseHeader*)(buffer.data()); if (header->type() == BROADCAST_TRANSACTION) { - auto tx = (Transaction*)(buffer + sizeof(RequestResponseHeader)); + auto tx = (Transaction*)(buffer.data() + sizeof(RequestResponseHeader)); uint8_t digest[32] = {0}; char respondTxHash[61] = {0}; KangarooTwelve( @@ -876,13 +877,13 @@ void getQuorumTick(const char* nodeIp, const int nodePort, uint32_t requestedTic packet.header.setType(RequestedQuorumTick::type); // REQUEST_TICK_DATA packet.rqt.tick = requestedTick; memset(packet.rqt.voteFlags, 0, (676 + 7) / 8); - qc->sendData(reinterpret_cast(&packet), sizeof(packet)); + qc->sendData(packet); auto votes = qc->getLatestVectorPacketAs(); LOG("Received %d quorum tick #%u (votes)\n", votes.size(), requestedTick); packet.rqt.tick = requestedTick+1; memset(packet.rqt.voteFlags, 0, (676 + 7) / 8); - qc->sendData(reinterpret_cast(&packet), sizeof(packet)); + qc->sendData(packet); auto votes_next = qc->getLatestVectorPacketAs(); LOG("Received %d quorum tick #%u (votes)\n", votes_next.size(), requestedTick+1); @@ -1312,17 +1313,17 @@ bool checkTxOnFile(const char* txHash, const char* fileName) void sendRawPacket(const char* nodeIp, const int nodePort, int rawPacketSize, uint8_t* rawPacket) { auto qc = make_qc(nodeIp, nodePort); - qc->sendData(rawPacket, rawPacketSize); + qc->sendData(std::span(rawPacket, rawPacketSize), rawPacketSize); LOG("Sent %d bytes\n", rawPacketSize); RequestResponseHeader header; uint8_t* headerPtr = (uint8_t*)&header; - qc->receiveData(headerPtr, sizeof(RequestResponseHeader)); + qc->receiveData(header); std::vector buffer; if (header.size() > sizeof(RequestResponseHeader)) { unsigned long long remainingSize = header.size() - sizeof(RequestResponseHeader); buffer.resize(remainingSize); - qc->receiveData(buffer.data(), int(remainingSize)); + qc->receiveData(buffer, int(remainingSize)); } LOG("Received %d bytes\n", header.size()); for (int i = 0; i < sizeof(RequestResponseHeader); ++i) @@ -1366,7 +1367,7 @@ void sendSpecialCommand(const char* nodeIp, const int nodePort, const char* seed sign(subseed, sourcePublicKey, digest, signature); memcpy(packet.signature, signature, 64); auto qc = make_qc(nodeIp, nodePort); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); SpecialCommand response; try @@ -1435,7 +1436,7 @@ void toggleMainAux(const char* nodeIp, const int nodePort, const char* seed, std sign(subseed, sourcePublicKey, digest, signature); memcpy(packet.signature, signature, 64); auto qc = make_qc(nodeIp, nodePort); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); SpecialCommandToggleMainModeResquestAndResponse response; try @@ -1497,7 +1498,7 @@ void setSolutionThreshold(const char* nodeIp, const int nodePort, const char* se sign(subseed, sourcePublicKey, digest, signature); memcpy(packet.signature, signature, 64); auto qc = make_qc(nodeIp, nodePort); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); SpecialCommandSetSolutionThresholdResquestAndResponse response; try @@ -1612,7 +1613,7 @@ void syncTime(const char* nodeIp, const int nodePort, const char* seed) auto startTime = steady_clock::now(); - qc->sendData((uint8_t*)&queryTimeMsg, queryTimeMsg.header.size()); + qc->sendData(queryTimeMsg); SpecialCommandSendTime response; try @@ -1679,7 +1680,7 @@ void syncTime(const char* nodeIp, const int nodePort, const char* seed) auto startTime = steady_clock::now(); - qc->sendData((uint8_t*)&sendTimeMsg, sendTimeMsg.header.size()); + qc->sendData(sendTimeMsg); SpecialCommandSendTime response; try @@ -1739,7 +1740,7 @@ void setLoggingMode(const char* nodeIp, const int nodePort, const char* seed, ch sign(subseed, sourcePublicKey, digest, signature); memcpy(packet.signature, signature, 64); auto qc = make_qc(nodeIp, nodePort); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); SpecialCommandSetConsoleLoggingModeRequestAndResponse response; try @@ -1799,7 +1800,7 @@ void broadcastCompChat(const char* nodeIp, const int nodePort, const char* seed, 32); sign(subseed, sourcePublicKey, digest, signature_ptr); auto qc = make_qc(nodeIp, nodePort); - qc->sendData(vData.data(), int(vData.size())); + qc->sendData(vData, static_cast(vData.size())); LOG("Broadcasted message to network\n"); } @@ -1843,7 +1844,7 @@ bool getComputorFromNode(const char* nodeIp, const int nodePort, BroadcastComput packet.header.randomizeDejavu(); packet.header.setType(REQUEST_COMPUTORS); auto qc = make_qc(nodeIp, nodePort); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); try { @@ -2141,14 +2142,14 @@ void getMiningScoreRanking(const char* nodeIp, const int nodePort, const char* s sign(subseed, sourcePublicKey, digest, signature); memcpy(packet.signature, signature, 64); auto qc = make_qc(nodeIp, nodePort); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); SpecialCommandGetMiningScoreRanking response; int headerSize = sizeof(RequestResponseHeader) + 8 + 4; // header and everIncreasingNonceAndCommandType and numberOfRankings std::vector buffer; buffer.resize(headerSize); - qc->receiveData(buffer.data(), headerSize); + qc->receiveData(buffer, headerSize); int contentSize = 0; { uint8_t* data = buffer.data() + sizeof(RequestResponseHeader); @@ -2167,7 +2168,7 @@ void getMiningScoreRanking(const char* nodeIp, const int nodePort, const char* s return; } buffer.resize(contentSize); - qc->receiveAllDataOrThrowException(buffer.data(), contentSize); + qc->receiveAllDataOrThrowException(buffer, contentSize); uint8_t* data = buffer.data(); // Get data out unsigned char* ptr = data; @@ -2336,7 +2337,7 @@ void saveSnapshot(const char* nodeIp, const int nodePort, const char* seed) sign(subseed, sourcePublicKey, digest, signature); memcpy(packet.signature, signature, 64); auto qc = make_qc(nodeIp, nodePort); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); SpecialCommandSaveSnapshotRequestAndResponse response; try @@ -2413,7 +2414,7 @@ void setExecutionFeeMultiplier(const char* nodeIp, const int nodePort, const cha sign(subseed, sourcePublicKey, digest, signature); memcpy(packet.signature, signature, 64); auto qc = make_qc(nodeIp, nodePort); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); SpecialCommandExecutionFeeMultiplierRequestAndResponse response; try @@ -2465,7 +2466,7 @@ void getExecutionFeeMultiplier(const char* nodeIp, const int nodePort, const cha sign(subseed, sourcePublicKey, digest, signature); memcpy(packet.signature, signature, 64); auto qc = make_qc(nodeIp, nodePort); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); SpecialCommandExecutionFeeMultiplierRequestAndResponse response; try diff --git a/nostromo.cpp b/nostromo.cpp index 8b148e1c..87c6a912 100644 --- a/nostromo.cpp +++ b/nostromo.cpp @@ -310,7 +310,7 @@ void registerInTier(const char* nodeIp, int nodePort, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(registerInTier_input) + SIGNATURE_SIZE, digest, @@ -371,7 +371,7 @@ void logoutFromTier(const char* nodeIp, int nodePort, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(logoutFromTier_input) + SIGNATURE_SIZE, digest, @@ -456,7 +456,7 @@ void createProject(const char* nodeIp, int nodePort, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(createProject_input) + SIGNATURE_SIZE, digest, @@ -522,7 +522,7 @@ void voteInProject(const char* nodeIp, int nodePort, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(voteInProject_input) + SIGNATURE_SIZE, digest, @@ -682,7 +682,7 @@ void createFundraising(const char* nodeIp, int nodePort, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(createFundraising_input) + SIGNATURE_SIZE, digest, @@ -746,7 +746,7 @@ void investInProject(const char* nodeIp, int nodePort, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(investInProject_input) + SIGNATURE_SIZE, digest, @@ -812,7 +812,7 @@ void claimToken(const char* nodeIp, int nodePort, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(claimToken_input) + SIGNATURE_SIZE, digest, @@ -901,7 +901,7 @@ void upgradeTierLevel(const char* nodeIp, int nodePort, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(upgradeTier_input) + SIGNATURE_SIZE, digest, @@ -977,7 +977,7 @@ void nostromoTransferShareManagementRights(const char* nodeIp, int nodePort, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(nostromoTransferShareManagementRights_input) + SIGNATURE_SIZE, digest, @@ -1007,7 +1007,7 @@ void getStats(const char* nodeIp, int nodePort) packet.rcf.inputType = NOSTROMO_TYPE_GET_STATS; packet.rcf.contractIndex = NOSTROMO_CONTRACT_INDEX; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); NOSTROMOGetStats_output result; try @@ -1048,7 +1048,7 @@ void getTierLevelByUser(const char* nodeIp, int nodePort, memcpy(packet.input.userId, publicKey, 32); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); NOSTROMOGetTierLevelByUser_output result; try @@ -1086,7 +1086,7 @@ void getUserVoteStatus(const char* nodeIp, int nodePort, memcpy(packet.input.userId, publicKey, 32); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); NOSTROMOGetUserVoteStatus_output result; try @@ -1137,7 +1137,7 @@ void checkTokenCreatability(const char* nodeIp, int nodePort, packet.rcf.contractIndex = NOSTROMO_CONTRACT_INDEX; memcpy(&packet.input.tokenName, assetNameS1, 8); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); NOSTROMOCheckTokenCreatability_output result; try @@ -1183,7 +1183,7 @@ void getNumberOfInvestedProjects(const char* nodeIp, int nodePort, memcpy(packet.input.userId, publicKey, 32); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); NOSTROMOGetNumberOfInvestedProjects_output result; try @@ -1220,7 +1220,7 @@ void getProjectByIndex(const char* nodeIp, int nodePort, packet.rcf.contractIndex = NOSTROMO_CONTRACT_INDEX; packet.input.indexOfProject = indexOfProject; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); NOSTROMOGetProjectByIndex_output result; try @@ -1276,7 +1276,7 @@ void getFundarasingByIndex(const char* nodeIp, int nodePort, packet.rcf.contractIndex = NOSTROMO_CONTRACT_INDEX; packet.input.indexOfFundarasing = indexOfFundarasing; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); NOSTROMOGetFundarasingByIndex_output result; try @@ -1330,6 +1330,8 @@ void getProjectIndexListByCreator(const char* nodeIp, int nodePort, NOSTROMOGetProjectIndexListByCreator_input input; } packet; #pragma pack(pop) + memset(&packet, 0, sizeof(packet)); + packet.header.setSize(sizeof(packet)); packet.header.randomizeDejavu(); packet.header.setType(RequestContractFunction::type()); @@ -1339,7 +1341,7 @@ void getProjectIndexListByCreator(const char* nodeIp, int nodePort, memcpy(packet.input.creator, publicKey, 32); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); NOSTROMOGetProjectIndexListByCreator_output result; try @@ -1383,6 +1385,8 @@ void getInfoUserInvested(const char* nodeIp, int nodePort, NOSTROMOGetInfoUserInvested_input input; } packet; #pragma pack(pop) + memset(&packet, 0, sizeof(packet)); + packet.header.setSize(sizeof(packet)); packet.header.randomizeDejavu(); packet.header.setType(RequestContractFunction::type()); @@ -1392,7 +1396,7 @@ void getInfoUserInvested(const char* nodeIp, int nodePort, memcpy(packet.input.investorId, publicKey, 32); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); NOSTROMOGetInfoUserInvested_output result; try @@ -1434,6 +1438,8 @@ void getMaxClaimAmount(const char* nodeIp, int nodePort, NOSTROMOGetMaxClaimAmount_input input; } packet; #pragma pack(pop) + memset(&packet, 0, sizeof(packet)); + packet.header.setSize(sizeof(packet)); packet.header.randomizeDejavu(); packet.header.setType(RequestContractFunction::type()); @@ -1443,7 +1449,7 @@ void getMaxClaimAmount(const char* nodeIp, int nodePort, memcpy(packet.input.investorId, publicKey, 32); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); NOSTROMOGetMaxClaimAmount_output result; try diff --git a/oracle_utils.cpp b/oracle_utils.cpp index 2276aebe..2c245a9f 100644 --- a/oracle_utils.cpp +++ b/oracle_utils.cpp @@ -76,7 +76,7 @@ static std::vector receiveQueryIds(QCPtr qc, unsigned int reqType, long packet.req.reqType = reqType; packet.req.reqTickOrId = reqTickOrId; - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); std::vector queryIds; @@ -99,7 +99,7 @@ static std::vector receiveQueryIds(QCPtr qc, unsigned int reqType, long { payloadBuffer.resize(payloadSize); } - recvByte = qc->receiveAllDataOrThrowException(payloadBuffer.data(), payloadSize); + recvByte = qc->receiveAllDataOrThrowException(payloadBuffer, payloadSize); auto resp = (RespondOracleData*)(payloadBuffer.data()); if (resp->resType == RespondOracleData::respondQueryIds) { @@ -161,7 +161,7 @@ static void receiveQueryInformation(QCPtr qc, int64_t queryId, RespondOracleData memset(&request.req, 0, sizeof(request.req)); request.req.reqType = RequestOracleData::requestQueryAndResponse; request.req.reqTickOrId = queryId; - qc->sendData((uint8_t*)&request, request.header.size()); + qc->sendData(request); // reset output memset(&metadata, 0, sizeof(RespondOracleDataQueryMetadata)); @@ -184,7 +184,7 @@ static void receiveQueryInformation(QCPtr qc, int64_t queryId, RespondOracleData { payloadBuffer.resize(responsePayloadSize); } - qc->receiveAllDataOrThrowException(payloadBuffer.data(), responsePayloadSize); + qc->receiveAllDataOrThrowException(payloadBuffer, responsePayloadSize); // only process if dejavu matches (response is to current request, skip otherwise) if (responseHeader->dejavu() == request.header.dejavu()) @@ -389,7 +389,7 @@ static void receiveQueryStats(QCPtr& qc, RespondOracleDataQueryStatistics& stats packet.header.setType(RequestOracleData::type()); memset(&packet.req, 0, sizeof(packet.req)); packet.req.reqType = RequestOracleData::requestQueryStatistics; - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); constexpr unsigned long long responseSize = sizeof(RequestResponseHeader) + sizeof(RespondOracleData) + sizeof(RespondOracleDataQueryStatistics); uint8_t buffer[responseSize]; @@ -453,7 +453,7 @@ static void receiveOracleRevenuePoints(QCPtr& qc, std::vector& revenue packet.header.setType(RequestOracleData::type()); memset(&packet.req, 0, sizeof(packet.req)); packet.req.reqType = RequestOracleData::requestOracleRevenuePoints; - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); constexpr unsigned long long responseSize = sizeof(RequestResponseHeader) + sizeof(RespondOracleData) + 8 * 676; uint8_t buffer[responseSize]; @@ -713,7 +713,7 @@ static void receiveSubscriptionInformation(QCPtr qc, int64_t subscriptionId, Res memset(&request.req, 0, sizeof(request.req)); request.req.reqType = RequestOracleData::requestSubscription; request.req.reqTickOrId = subscriptionId; - qc->sendData((uint8_t*)&request, request.header.size()); + qc->sendData(request); // reset output memset(&subscription, 0, sizeof(subscription)); @@ -735,7 +735,7 @@ static void receiveSubscriptionInformation(QCPtr qc, int64_t subscriptionId, Res { payloadBuffer.resize(responsePayloadSize); } - qc->receiveAllDataOrThrowException(payloadBuffer.data(), responsePayloadSize); + qc->receiveAllDataOrThrowException(payloadBuffer, responsePayloadSize); // only process if dejavu matches (response is to current request, skip otherwise) if (responseHeader->dejavu() == request.header.dejavu()) @@ -837,7 +837,7 @@ static std::vector receiveSubscriptionIds(QCPtr qc, unsigned int reqTyp packet.req.reqType = reqType; packet.req.reqTickOrId = reqTickOrId; - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); std::vector subscriptionIds; @@ -860,7 +860,7 @@ static std::vector receiveSubscriptionIds(QCPtr qc, unsigned int reqTyp { payloadBuffer.resize(payloadSize); } - recvByte = qc->receiveAllDataOrThrowException(payloadBuffer.data(), payloadSize); + recvByte = qc->receiveAllDataOrThrowException(payloadBuffer, payloadSize); auto resp = (RespondOracleData*)(payloadBuffer.data()); if (resp->resType == RespondOracleData::respondSubscriptionIds) { diff --git a/qbond.cpp b/qbond.cpp index a9b275c5..35ef6522 100644 --- a/qbond.cpp +++ b/qbond.cpp @@ -112,7 +112,7 @@ void qbondStake(const char* nodeIp, int nodePort, const char* seed, const int64_ packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -180,7 +180,7 @@ void qbondTransfer(const char* nodeIp, int nodePort, const char* seed, const cha packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -267,7 +267,7 @@ void qbondOperateOrder(const char* nodeIp, int nodePort, const char* seed, const packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -332,7 +332,7 @@ void qbondBurn(const char* nodeIp, int nodePort, const char* seed, const int64_t packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -399,7 +399,7 @@ void qbondUpdateCFA(const char* nodeIp, int nodePort, const char* seed, const ch packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -424,16 +424,16 @@ void qbondGetFees(const char* nodeIp, int nodePort) RequestContractFunction rcf; GetFees_input in; } req; - memset(&req, 0, sizeof(req)); + req.rcf.contractIndex = QBOND_CONTRACT_INDEX; req.rcf.inputType = QBOND_GET_FEES; req.rcf.inputSize = sizeof(req.in); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(req.in)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); GetFees_output output; memset(&output, 0, sizeof(output)); @@ -463,16 +463,16 @@ void qbondGetEarnedFees(const char* nodeIp, int nodePort) RequestContractFunction rcf; GetFees_input in; } req; - memset(&req, 0, sizeof(req)); + req.rcf.contractIndex = QBOND_CONTRACT_INDEX; req.rcf.inputType = QBOND_GET_EARNED_FEES; req.rcf.inputSize = sizeof(req.in); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(req.in)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); GetEarnedFees_output output; memset(&output, 0, sizeof(output)); @@ -491,9 +491,6 @@ void qbondGetEarnedFees(const char* nodeIp, int nodePort) void qbondGetInfoPerEpoch(const char* nodeIp, int nodePort, const int64_t epoch) { - GetInfoPerEpoch_input input; - input.epoch = epoch; - auto qc = make_qc(nodeIp, nodePort); if (!qc) { LOG("Failed to connect to node.\n"); @@ -503,19 +500,19 @@ void qbondGetInfoPerEpoch(const char* nodeIp, int nodePort, const int64_t epoch) struct { RequestResponseHeader header; RequestContractFunction rcf; - GetInfoPerEpoch_input in; + GetInfoPerEpoch_input input; } req; - memset(&req, 0, sizeof(req)); + + req.input.epoch = epoch; req.rcf.contractIndex = QBOND_CONTRACT_INDEX; req.rcf.inputType = QBOND_GET_INFO_PER_EPOCH; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.rcf.inputSize = sizeof(req.input); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); GetInfoPerEpoch_output output; memset(&output, 0, sizeof(output)); @@ -536,11 +533,6 @@ void qbondGetInfoPerEpoch(const char* nodeIp, int nodePort, const int64_t epoch) void qbondGetOrders(const char* nodeIp, int nodePort, const int64_t epoch, const int64_t asksOffset, const int64_t bidsOffset) { - GetOrders_input input; - input.epoch = epoch; - input.asksOffset = asksOffset; - input.bidsOffset = bidsOffset; - auto qc = make_qc(nodeIp, nodePort); if (!qc) { LOG("Failed to connect to node.\n"); @@ -550,19 +542,22 @@ void qbondGetOrders(const char* nodeIp, int nodePort, const int64_t epoch, const struct { RequestResponseHeader header; RequestContractFunction rcf; - GetOrders_input in; + GetOrders_input input; } req; - memset(&req, 0, sizeof(req)); + + req.input.epoch = epoch; + req.input.asksOffset = asksOffset; + req.input.bidsOffset = bidsOffset; + req.rcf.contractIndex = QBOND_CONTRACT_INDEX; req.rcf.inputType = QBOND_GET_ORDERS; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.rcf.inputSize = sizeof(req.input); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); GetOrders_output output; memset(&output, 0, sizeof(output)); @@ -580,12 +575,6 @@ void qbondGetOrders(const char* nodeIp, int nodePort, const int64_t epoch, const void qbondGetUserOrders(const char* nodeIp, int nodePort, const char* owner, const int64_t asksOffset, const int64_t bidsOffset) { - GetUserOrders_input input; - memset(input.owner, 0, 32); - getPublicKeyFromIdentity(owner, input.owner); - input.asksOffset = asksOffset; - input.bidsOffset = bidsOffset; - auto qc = make_qc(nodeIp, nodePort); if (!qc) { LOG("Failed to connect to node.\n"); @@ -595,19 +584,21 @@ void qbondGetUserOrders(const char* nodeIp, int nodePort, const char* owner, con struct { RequestResponseHeader header; RequestContractFunction rcf; - GetUserOrders_input in; + GetUserOrders_input input; } req; - memset(&req, 0, sizeof(req)); + + getPublicKeyFromIdentity(owner, req.input.owner); + req.input.asksOffset = asksOffset; + req.input.bidsOffset = bidsOffset; req.rcf.contractIndex = QBOND_CONTRACT_INDEX; req.rcf.inputType = QBOND_GET_USER_ORDERS; - req.rcf.inputSize = sizeof(input); - memcpy(&req.in, &input, sizeof(input)); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(input)); + req.rcf.inputSize = sizeof(req.input); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); GetUserOrders_output output; memset(&output, 0, sizeof(output)); @@ -636,16 +627,16 @@ void qbondGetTable(const char* nodeIp, int nodePort) RequestContractFunction rcf; MBondsTable_input in; } req; - memset(&req, 0, sizeof(req)); + req.rcf.contractIndex = QBOND_CONTRACT_INDEX; req.rcf.inputType = QBOND_GET_TABLE; req.rcf.inputSize = sizeof(req.in); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(req.in)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); MBondsTable_output output; memset(&output, 0, sizeof(output)); @@ -684,18 +675,18 @@ void qbondGetUserMBonds(const char* nodeIp, int nodePort, const char* owner) RequestContractFunction rcf; GetUserMBonds_input in; } req; - memset(&req, 0, sizeof(req)); + req.rcf.contractIndex = QBOND_CONTRACT_INDEX; req.rcf.inputType = QBOND_GET_USER_MBONDS; req.rcf.inputSize = sizeof(req.in); memset(req.in.owner, 0, 32); getPublicKeyFromIdentity(owner, req.in.owner); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(req.in)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); GetUserMBonds_output output; memset(&output, 0, sizeof(output)); @@ -733,16 +724,16 @@ void qbondGetCFA(const char* nodeIp, int nodePort) RequestContractFunction rcf; GetCFA_input in; } req; - memset(&req, 0, sizeof(req)); + req.rcf.contractIndex = QBOND_CONTRACT_INDEX; req.rcf.inputType = QBOND_GET_CFA; req.rcf.inputSize = sizeof(req.in); - req.header.setSize(sizeof(req.header) + sizeof(req.rcf) + sizeof(req.in)); + req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); GetCFA_output output; memset(&output, 0, sizeof(output)); diff --git a/qearn.cpp b/qearn.cpp index 8ad6e2cd..8977b829 100644 --- a/qearn.cpp +++ b/qearn.cpp @@ -110,7 +110,7 @@ void qearnLock(const char* nodeIp, int nodePort, const char* seed, long long loc packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + SIGNATURE_SIZE, digest, @@ -168,7 +168,7 @@ void qearnUnlock(const char* nodeIp, int nodePort, const char* seed, long long u packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(Unlock_input) + SIGNATURE_SIZE, digest, @@ -195,7 +195,7 @@ void qearnGetInfoPerEpoch(const char* nodeIp, const int nodePort, uint32_t epoch packet.rcf.inputType = QEARN_GET_LOCK_INFO_PER_EPOCH; packet.rcf.contractIndex = QEARN_CONTRACT_INDEX; packet.input.Epoch = epoch; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); QEarnGetLockInfoPerEpoch_output result; try @@ -246,7 +246,7 @@ void qearnGetUserLockedInfo(const char* nodeIp, const int nodePort, char* Identi packet.input.epoch = epoch; memcpy(packet.input.publicKey, publicKey, 32); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); QEarnGetUserLockedInfo_output result; try @@ -278,7 +278,7 @@ void qearnGetStateOfRound(const char* nodeIp, const int nodePort, uint32_t epoch packet.input.Epoch = epoch; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); QEarnGetStateOfRound_output result; try @@ -313,7 +313,7 @@ void qearnGetStatsPerEpoch(const char* nodeIp, const int nodePort, uint32_t epoc packet.input.epoch = epoch; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); QEarnGetStatsPerEpoch_output result; try @@ -354,7 +354,7 @@ void qearnGetBurnedAndBoostedStats(const char* nodeIp, const int nodePort) packet.input.t = 10; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); QEarnGetBurnedAndBoostedStats_output result; try @@ -400,7 +400,7 @@ void qearnGetBurnedAndBoostedStatsPerEpoch(const char* nodeIp, const int nodePor packet.input.epoch = epoch; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); QEarnGetBurnedAndBoostedStatsPerEpoch_output result; try @@ -450,7 +450,7 @@ void qearnGetUserLockedStatus(const char* nodeIp, const int nodePort, char* Iden memcpy(packet.input.publicKey, publicKey, 32); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); QEarnGetUserLockStatus_output result; try @@ -502,7 +502,7 @@ void qearnGetEndedStatus(const char* nodeIp, const int nodePort, char* Identity) memcpy(packet.input.publicKey, publicKey, 32); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); QEarnGetEndedStatus_output result; try diff --git a/qpi_adapter.h b/qpi_adapter.h index 2edd23e6..9b4ea394 100644 --- a/qpi_adapter.h +++ b/qpi_adapter.h @@ -24,7 +24,7 @@ #endif #include "core/src/contract_core/pre_qpi_def.h" -#include "core/src/contracts/qpi.h" +#include "core/src/qpi/qpi.h" #include "core/src/oracle_core/oracle_interfaces_def.h" #include diff --git a/qswap.cpp b/qswap.cpp index 731ad252..f3d9e417 100644 --- a/qswap.cpp +++ b/qswap.cpp @@ -54,7 +54,7 @@ void getQswapFees(const char* nodeIp, const int nodePort, QswapFees_output& resu packet.rcf.inputSize = 0; packet.rcf.inputType = QSWAP_GET_FEE; packet.rcf.contractIndex = QSWAP_CONTRACT_INDEX; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); try { @@ -139,11 +139,11 @@ void qswapIssueAsset(const char* nodeIp, int nodePort, sign(subSeed, sourcePublicKey, digest, signature); memcpy(packet.sig, signature, SIGNATURE_SIZE); // set header - packet.header.setSize(sizeof(packet.header)+sizeof(Transaction)+sizeof(QswapIssueAsset_input)+ SIGNATURE_SIZE); + packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(Transaction)+sizeof(QswapIssueAsset_input)+ SIGNATURE_SIZE, digest, @@ -216,10 +216,10 @@ void qswapTransferAsset(const char* nodeIp, int nodePort, sign(subSeed, sourcePublicKey, digest, signature); memcpy(packet.sig, signature, SIGNATURE_SIZE); // set header - packet.header.setSize(sizeof(packet.header)+sizeof(Transaction)+sizeof(QswapTransferAssetOwnershipAndPossession_input)+ SIGNATURE_SIZE); + packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(Transaction)+sizeof(QswapTransferAssetOwnershipAndPossession_input)+ SIGNATURE_SIZE, digest, @@ -315,11 +315,11 @@ void qswapCreatePool(const char* nodeIp, int nodePort, sign(subSeed, sourcePublicKey, digest, signature); memcpy(packet.sig, signature, SIGNATURE_SIZE); // set header - packet.header.setSize(sizeof(packet.header)+sizeof(Transaction)+sizeof(CreatePool_input)+ SIGNATURE_SIZE); + packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(Transaction)+sizeof(CreatePool_input)+ SIGNATURE_SIZE, digest, @@ -406,11 +406,11 @@ void qswapAddLiquidity(const char* nodeIp, int nodePort, sign(subSeed, sourcePublicKey, digest, signature); memcpy(packet.sig, signature, SIGNATURE_SIZE); // set header - packet.header.setSize(sizeof(packet.header)+sizeof(Transaction)+sizeof(AddLiquidity_input)+ SIGNATURE_SIZE); + packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(Transaction)+sizeof(AddLiquidity_input)+ SIGNATURE_SIZE, digest, @@ -495,11 +495,11 @@ void qswapRemoveLiquidity(const char* nodeIp, int nodePort, sign(subSeed, sourcePublicKey, digest, signature); memcpy(packet.sig, signature, SIGNATURE_SIZE); // set header - packet.header.setSize(sizeof(packet.header)+sizeof(Transaction)+sizeof(RemoveLiquidity_input)+ SIGNATURE_SIZE); + packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(Transaction)+sizeof(RemoveLiquidity_input)+ SIGNATURE_SIZE, digest, @@ -592,10 +592,10 @@ void qswapSwapQuForAssetAction(const char* nodeIp, int nodePort, sign(subSeed, sourcePublicKey, digest, signature); memcpy(packet.sig, signature, SIGNATURE_SIZE); // set header - packet.header.setSize(sizeof(packet.header)+sizeof(Transaction)+sizeof(SwapQuForAssetAction_input)+ SIGNATURE_SIZE); + packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(Transaction)+sizeof(SwapQuForAssetAction_input)+ SIGNATURE_SIZE, digest, @@ -729,10 +729,10 @@ void qswapSwapAssetForQuAction(const char* nodeIp, int nodePort, sign(subSeed, sourcePublicKey, digest, signature); memcpy(packet.sig, signature, SIGNATURE_SIZE); // set header - packet.header.setSize(sizeof(packet.header)+sizeof(Transaction)+sizeof(SwapAssetForQuAction_input)+ SIGNATURE_SIZE); + packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(Transaction)+sizeof(SwapAssetForQuAction_input)+ SIGNATURE_SIZE, digest, @@ -796,7 +796,7 @@ void qswapGetPoolBasicState(const char* nodeIp, int nodePort, memcpy(packet.gpbs.issuer, issuer, 32); memcpy(&packet.gpbs.assetName, assetNameU1, 8); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); try { @@ -843,7 +843,7 @@ void qswapGetLiquidityOf(const char* nodeIp, int nodePort, memcpy(&packet.glo.assetName, assetNameU1, 8); memcpy(&packet.glo.account, account, 32); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); try { @@ -884,7 +884,7 @@ void qswapQuoteAction(const char* nodeIp, int nodePort, memcpy(packet.q.issuer, issuer, 32); memcpy(&packet.q.assetName, assetNameU1, 8); packet.q.amount = amount; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); try { diff --git a/quottery.cpp b/quottery.cpp index 1ac95219..e26b693a 100644 --- a/quottery.cpp +++ b/quottery.cpp @@ -88,7 +88,7 @@ static int64_t getBalanceNumber(QCPtr& qc, const uint8_t* publicKey) { packet.header.randomizeDejavu(); packet.header.setType(REQUEST_ENTITY); memcpy(packet.req.publicKey, publicKey, 32); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); auto result = qc->receivePacketWithHeaderAs(); return result.entity.incomingAmount - result.entity.outgoingAmount; } @@ -109,7 +109,7 @@ void quotteryGetBasicInfo(QCPtr& qc, qtryBasicInfo_output& result) packet.rcf.inputSize = 0; packet.rcf.inputType = QTRY_GET_BASIC; packet.rcf.contractIndex = QUOTTERY_CONTRACT_ID; - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); try { @@ -281,7 +281,7 @@ void _quotteryGetEventInfo(QCPtr& qc, uint64_t eventId, getEventInfo_output& res packet.rcf.inputType = QTRY_GET_EVENT; packet.rcf.contractIndex = QUOTTERY_CONTRACT_ID; packet.input.eventId = eventId; - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); try { diff --git a/qutil.cpp b/qutil.cpp index 535a3ae6..bf39b748 100644 --- a/qutil.cpp +++ b/qutil.cpp @@ -217,7 +217,7 @@ long long getSendToManyV1Fee(QCPtr qc) packet.rcf.inputSize = 0; packet.rcf.inputType = qutilFunctionId::GetSendToManyV1Fee; packet.rcf.contractIndex = QUTIL_CONTRACT_ID; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); GetSendToManyV1Fee_output fee; memset(&fee, 0, sizeof(GetSendToManyV1Fee_output)); @@ -352,7 +352,7 @@ void qutilSendToManyV1(const char* nodeIp, int nodePort, const char* seed, const packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(SendToManyV1_input) + SIGNATURE_SIZE, digest, @@ -438,7 +438,7 @@ void qutilTransferSharesToManyV1(const char* nodeIp, int nodePort, const char* s packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(TransferSharesToManyV1_input) + SIGNATURE_SIZE, digest, @@ -554,7 +554,7 @@ void qutilBurnQubic(const char* nodeIp, int nodePort, const char* seed, long lon packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(BurnQubic_input) + SIGNATURE_SIZE, digest, @@ -641,7 +641,7 @@ void qutilSendToManyBenchmark(const char* nodeIp, int nodePort, const char* seed packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(SendToManyBenchmark_input) + SIGNATURE_SIZE, digest, @@ -821,7 +821,7 @@ void qutilCreatePoll(const char* nodeIp, int nodePort, const char* seed, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -892,7 +892,7 @@ void qutilVote(const char* nodeIp, int nodePort, const char* seed, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(input) + SIGNATURE_SIZE, digest, @@ -928,7 +928,7 @@ void qutilGetCurrentResult(const char* nodeIp, int nodePort, uint64_t poll_id) req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); GetCurrentResult_output output; try @@ -987,7 +987,7 @@ void qutilGetPollsByCreator(const char* nodeIp, int nodePort, const char* creato req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); - qc->sendData((uint8_t*)&req, req.header.size()); + qc->sendData(req); GetPollsByCreator_output output; try @@ -1030,7 +1030,7 @@ void qutilGetCurrentPollId(const char* nodeIp, int nodePort) { packet.rcf.inputSize = 0; packet.rcf.inputType = qutilFunctionId::GetCurrentPollId; packet.rcf.contractIndex = QUTIL_CONTRACT_ID; - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); GetCurrentPollId_output output; try { @@ -1073,7 +1073,7 @@ void qutilGetPollInfo(const char* nodeIp, int nodePort, uint64_t poll_id) packet.rcf.inputType = qutilFunctionId::GetPollInfo; packet.rcf.contractIndex = QUTIL_CONTRACT_ID; memcpy(&packet.inputData, &input, sizeof(input)); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); try { @@ -1171,7 +1171,7 @@ void qutilCancelPoll(const char* nodeIp, int nodePort, const char* seed, uint64_ packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((uint8_t*)&packet.transaction, sizeof(packet.transaction) + sizeof(CancelPoll_input) + SIGNATURE_SIZE, digest, diff --git a/qvault.cpp b/qvault.cpp index 4bb552dc..3ff0630c 100644 --- a/qvault.cpp +++ b/qvault.cpp @@ -181,7 +181,7 @@ void submitAuthAddress(const char* nodeIp, int nodePort, const char* seed, uint3 packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(submitAuthAddress_input) + SIGNATURE_SIZE, digest, @@ -240,7 +240,7 @@ void changeAuthAddress(const char* nodeIp, int nodePort, const char* seed, uint3 packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(changeAuthAddress_input) + SIGNATURE_SIZE, digest, @@ -301,7 +301,7 @@ void submitFees(const char* nodeIp, int nodePort, const char* seed, uint32_t sch packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(submitFees_input) + SIGNATURE_SIZE, digest, @@ -362,7 +362,7 @@ void changeFees(const char* nodeIp, int nodePort, const char* seed, uint32_t sch packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(changeFees_input) + SIGNATURE_SIZE, digest, @@ -424,7 +424,7 @@ void submitReinvestingAddress(const char* nodeIp, int nodePort, const char* seed packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(submitReinvestingAddress_input) + SIGNATURE_SIZE, digest, @@ -486,7 +486,7 @@ void changeReinvestingAddress(const char* nodeIp, int nodePort, const char* seed packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(changeReinvestingAddress_input) + SIGNATURE_SIZE, digest, @@ -548,7 +548,7 @@ void submitAdminAddress(const char* nodeIp, int nodePort, const char* seed, uin packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(submitAdminAddress_input) + SIGNATURE_SIZE, digest, @@ -610,7 +610,7 @@ void changeAdminAddress(const char* nodeIp, int nodePort, const char* seed, uin packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(changeAdminAddress_input) + SIGNATURE_SIZE, digest, @@ -639,7 +639,7 @@ void getData(const char* nodeIp, int nodePort) packet.rcf.contractIndex = QVAULT_CONTRACT_INDEX; packet.input.t = 10; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); QVaultGetData_output result; try @@ -767,7 +767,7 @@ void submitBannedAddress(const char* nodeIp, int nodePort, const char* seed, ui packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(submitBannedAddress_input) + SIGNATURE_SIZE, digest, @@ -829,7 +829,7 @@ void saveBannedAddress(const char* nodeIp, int nodePort, const char* seed, uint packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(saveBannedAddress_input) + SIGNATURE_SIZE, digest, @@ -891,7 +891,7 @@ void submitUnbannedannedAddress(const char* nodeIp, int nodePort, const char* se packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(submitUnbannedAddress_input) + SIGNATURE_SIZE, digest, @@ -953,7 +953,7 @@ void saveUnbannedAddress(const char* nodeIp, int nodePort, const char* seed, ui packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(unblockBannedAddress_input) + SIGNATURE_SIZE, digest, diff --git a/qx.cpp b/qx.cpp index e716debf..44bc3b43 100644 --- a/qx.cpp +++ b/qx.cpp @@ -47,7 +47,7 @@ void getQxFees(const char* nodeIp, const int nodePort, QxFees_output& result) packet.rcf.inputSize = 0; packet.rcf.inputType = QX_GET_FEE; packet.rcf.contractIndex = QX_CONTRACT_INDEX; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); try { @@ -129,11 +129,11 @@ void qxIssueAsset(const char* nodeIp, int nodePort, sign(subSeed, sourcePublicKey, digest, signature); memcpy(packet.sig, signature, SIGNATURE_SIZE); // set header - packet.header.setSize(sizeof(packet.header)+sizeof(Transaction)+sizeof(IssueAsset_input)+ SIGNATURE_SIZE); + packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(Transaction)+sizeof(IssueAsset_input)+ SIGNATURE_SIZE, digest, @@ -206,10 +206,10 @@ void qxTransferAsset(const char* nodeIp, int nodePort, sign(subSeed, sourcePublicKey, digest, signature); memcpy(packet.sig, signature, SIGNATURE_SIZE); // set header - packet.header.setSize(sizeof(packet.header)+sizeof(Transaction)+sizeof(TransferAssetOwnershipAndPossession_input)+ SIGNATURE_SIZE); + packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(Transaction)+sizeof(TransferAssetOwnershipAndPossession_input)+ SIGNATURE_SIZE, digest, @@ -294,10 +294,10 @@ void qxOrderAction(const char* nodeIp, int nodePort, sign(subSeed, sourcePublicKey, digest, signature); memcpy(packet.sig, signature, SIGNATURE_SIZE); // set header - packet.header.setSize(sizeof(packet.header)+sizeof(Transaction)+sizeof(qxOrderAction_input)+ SIGNATURE_SIZE); + packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(Transaction)+sizeof(qxOrderAction_input)+ SIGNATURE_SIZE, digest, @@ -425,7 +425,7 @@ void qxGetAssetOrder(const char* nodeIp, int nodePort, memcpy(packet.qgao.issuer, issuer, 32); memcpy(&packet.qgao.assetName, assetNameU1, 8); packet.qgao.offset = offset; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); try { @@ -502,7 +502,7 @@ void qxGetEntityOrder(const char* nodeIp, int nodePort, packet.rcf.contractIndex = QX_CONTRACT_INDEX; memcpy(packet.qgeo.entity, entity, 32); packet.qgeo.offset = offset; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); try { diff --git a/submodules/core b/submodules/core index 74b0180f..38d49e4b 160000 --- a/submodules/core +++ b/submodules/core @@ -1 +1 @@ -Subproject commit 74b0180f0fad9e4bb350e7eca0fa383f88c3d0ba +Subproject commit 38d49e4b0dcd4122b9eb49e5d8722a7df50b5020 diff --git a/test_utils.cpp b/test_utils.cpp index a073477e..ef8a19b1 100644 --- a/test_utils.cpp +++ b/test_utils.cpp @@ -163,7 +163,7 @@ std::vector> queryQpiFunctionsOutputToState(QCPtr qc, cons packet.transaction.inputType = TESTEXA_QUERY_QPI_FUNCTIONS_TO_STATE; packet.transaction.inputSize = 0; // set header - packet.header.setSize(sizeof(packet.header) + sizeof(Transaction) + SIGNATURE_SIZE); + packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); @@ -179,7 +179,7 @@ std::vector> queryQpiFunctionsOutputToState(QCPtr qc, cons sign(subSeed, sourcePublicKey, digest, signature); memcpy(packet.sig, signature, SIGNATURE_SIZE); - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(Transaction) + SIGNATURE_SIZE, @@ -206,7 +206,7 @@ QpiFunctionsOutput getQpiFunctionsOutput(QCPtr qc, uint32_t requestedTick, unsig packet.tick = requestedTick; packet.rcf.inputType = inputType; - qc->sendData((uint8_t*)&packet, packet.header.size()); + qc->sendData(packet); try { output = qc->receivePacketWithHeaderAs(); @@ -310,7 +310,7 @@ static void queryAndMatchQpiFunctionsOutput(QCPtr qc, uint32_t firstQueriedTick, packetQT.header.setType(RequestedQuorumTick::type); packetQT.rqt.tick = requestedTick; memset(packetQT.rqt.voteFlags, 0, (676 + 7) / 8); - qc->sendData(reinterpret_cast(&packetQT), sizeof(packetQT)); + qc->sendData(packetQT); auto votes = qc->getLatestVectorPacketAs(); LOG("\tComparing BEGIN_TICK qpi functions output and quorum tick votes\n"); LOG("\t\tReceived %d quorum tick votes for comparison\n", votes.size()); diff --git a/utils.h b/utils.h index 5ab3d5a8..de04fc02 100644 --- a/utils.h +++ b/utils.h @@ -112,7 +112,7 @@ static inline std::string base64_encode(const std::vector &in) { std::string out; int val = 0, valb = -6; - for (uint8_t c : in) { + for (const uint8_t c : in) { val = (val << 8) + c; valb += 8; while (valb >= 0) { @@ -129,7 +129,7 @@ static inline std::string base64_encode(const std::vector &in) { return out; } -static std::string base64_encode(uint8_t *data, size_t length) { +static std::string base64_encode(const uint8_t *data, size_t length) { return base64_encode(std::vector(data, data + length)); } @@ -160,7 +160,8 @@ static std::vector base64_decode(const std::string &in) { return out; } -static void printBytes(uint8_t* data, size_t length, std::string type = "base64") {\ +static void printBytes(const uint8_t* data, size_t length, std::string type = "base64") +{ printf("---------------- %s ----------------\n", type.c_str()); if (type == "base64") { std::string encoded = base64_encode(data, length); diff --git a/wallet_utils.cpp b/wallet_utils.cpp index b07b1bf6..6661201b 100644 --- a/wallet_utils.cpp +++ b/wallet_utils.cpp @@ -46,11 +46,13 @@ RespondedEntity getBalance(const char* nodeIp, const int nodePort, const uint8_t RequestResponseHeader header; RequestedEntity req; } packet; + memset(&packet, 0, sizeof(packet)); + packet.header.setSize(sizeof(packet)); packet.header.randomizeDejavu(); packet.header.setType(REQUEST_ENTITY); memcpy(packet.req.publicKey, publicKey, 32); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); int recvByte = qc->receiveData(tmp, 1024); while (recvByte > 0) { @@ -59,7 +61,7 @@ RespondedEntity getBalance(const char* nodeIp, const int nodePort, const uint8_t recvByte = qc->receiveData(tmp, 1024); } uint8_t* data = buffer.data(); - recvByte = int(buffer.size()); + recvByte = static_cast(buffer.size()); int ptr = 0; while (ptr < recvByte) { @@ -215,10 +217,10 @@ void makeStandardTransactionInTick(const char* nodeIp, int nodePort, const char* 32); sign(subseed, sourcePublicKey, digest, signature); memcpy(packet.signature, signature, 64); - packet.header.setSize(sizeof(packet.header)+sizeof(packet.transaction) + 64); + packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + 64, @@ -312,7 +314,7 @@ void makeCustomTransaction(const char* nodeIp, int nodePort, temp_packet.header.zeroDejavu(); temp_packet.header.setType(BROADCAST_TRANSACTION); memcpy(packet.data(), &temp_packet.header, sizeof(RequestResponseHeader)); - qc->sendData(packet.data(), uint32_t(packet.size())); + qc->sendData(packet, static_cast(packet.size())); KangarooTwelve(packet.data() + sizeof(RequestResponseHeader), sizeof(Transaction) + extraDataSize + 64, @@ -379,7 +381,7 @@ void makeContractTransaction(const char* nodeIp, int nodePort, 32); sign(subseed, sourcePublicKey, digest, packetSignature); - qc->sendData(packet.data(), int(packet.size())); + qc->sendData(packet, static_cast(packet.size())); KangarooTwelve(packet.data() + sizeof(RequestResponseHeader), sizeof(Transaction) + extraDataSize + 64, @@ -418,11 +420,11 @@ bool runContractFunction(const char* nodeIp, int nodePort, packetRcf.contractIndex = contractIndex; if (inputSize) memcpy(packetInputData, inputPtr, inputSize); - qc->sendData(&packet[0], packetHeader.size()); + qc->sendData(packet, static_cast(packet.size())); const size_t fullPacketSize = sizeof(RequestResponseHeader) + outputSize; std::vector buffer(fullPacketSize); - int recvByte = qc->receiveAllDataOrThrowException(buffer.data(), int(buffer.size())); + int recvByte = qc->receiveAllDataOrThrowException(buffer, static_cast(buffer.size())); auto header = (RequestResponseHeader*)buffer.data(); if (header->type() == RespondContractFunction::type() && @@ -436,7 +438,7 @@ bool runContractFunction(const char* nodeIp, int nodePort, LOG("WARNING: Response of runContractFunction() is %llu bytes longer than expected. Dropping unexpected part that cannot be interpreted.\n", (unsigned long long)dropSize); if (dropSize > buffer.size()) buffer.resize(dropSize); - qc->receiveAllDataOrThrowException(buffer.data(), int(dropSize)); + qc->receiveAllDataOrThrowException(buffer, static_cast(dropSize)); } return true; @@ -475,7 +477,7 @@ bool runContractFunction(const char* nodeIp, int nodePort, packetRcf.contractIndex = contractIndex; if (inputSize) memcpy(packetInputData, inputData, inputSize); - qc->sendData(&packet[0], packetHeader.size()); + qc->sendData(packet, static_cast(packet.size())); ContractObject outputContractObject = buildContractObject(formatOutput, true); auto outputSize = outputContractObject.getSize(); @@ -488,7 +490,7 @@ bool runContractFunction(const char* nodeIp, int nodePort, } } std::vector buffer(sizeof(RequestResponseHeader) + outputSize); - int recvByte = qc->receiveAllDataOrThrowException(buffer.data(), int(buffer.size())); + int recvByte = qc->receiveAllDataOrThrowException(buffer, static_cast(buffer.size())); auto header = (RequestResponseHeader*)buffer.data(); if (header->type() == RespondContractFunction::type() && @@ -564,7 +566,7 @@ void invokeContractProcedure(const char* nodeIp, int nodePort, 32); sign(subseed, sourcePublicKey, digest, packetSignature); - qc->sendData(packet.data(), int(packet.size())); + qc->sendData(packet, static_cast(packet.size())); KangarooTwelve(packet.data() + sizeof(RequestResponseHeader), sizeof(Transaction) + extraDataSize + 64, @@ -631,7 +633,7 @@ void makeIPOBid(const char* nodeIp, int nodePort, packet.header.setSize(sizeof(packet)); packet.header.zeroDejavu(); packet.header.setType(BROADCAST_TRANSACTION); - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); KangarooTwelve((unsigned char*)&packet.transaction, sizeof(packet.transaction) + sizeof(packet.ipo) + SIGNATURE_SIZE, digest, @@ -655,7 +657,7 @@ RespondContractIPO _getIPOStatus(const char* nodeIp, int nodePort, uint32_t cont packet.header.randomizeDejavu(); packet.header.setType(REQUEST_CONTRACT_IPO); packet.req.contractIndex = contractIndex; - qc->sendData((uint8_t *) &packet, packet.header.size()); + qc->sendData(packet); try { @@ -676,7 +678,7 @@ std::vector _getActiveIPOs(const char* nodeIp, int nodePort) header.setSize(sizeof(header)); header.randomizeDejavu(); header.setType(RequestActiveIPOs::type()); - qc->sendData((uint8_t*)&header, header.size()); + qc->sendData(header); return qc->getLatestVectorPacketAs(); } From 36babea7a2bcef3c381d82d2710d95779c570e1e Mon Sep 17 00:00:00 2001 From: Franziska Mueller <11660876+Franziska-Mueller@users.noreply.github.com> Date: Thu, 30 Jul 2026 15:58:32 +0200 Subject: [PATCH 2/5] make receive template also only available for trivially copyable types that are no ranges or pointers --- connection.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/connection.h b/connection.h index 2a361539..003d998f 100644 --- a/connection.h +++ b/connection.h @@ -37,7 +37,11 @@ class QubicConnection // Receive an object of type T. Return the actual number of received bytes. // Should only return less than sz bytes on timeout, closed connection, or error. + // This template only accepts trivially copyable types that are no ranges or pointers. template + requires std::is_trivially_copyable_v + && (!std::ranges::range) + && (!IsPointerLike) int receiveData(T& obj) { return receiveData(std::span(reinterpret_cast(&obj), sizeof(T)), sizeof(T)); From 28eeda792be4e9d757d9ab9859db4e15231be359 Mon Sep 17 00:00:00 2001 From: Franziska Mueller <11660876+Franziska-Mueller@users.noreply.github.com> Date: Tue, 4 Aug 2026 16:13:36 +0200 Subject: [PATCH 3/5] remove input struct from contract function request if empty --- msvault.cpp | 3 +-- qbond.cpp | 12 ++++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/msvault.cpp b/msvault.cpp index 7f5a4b5f..2f90b597 100644 --- a/msvault.cpp +++ b/msvault.cpp @@ -651,7 +651,6 @@ void msvaultGetFees(const char* nodeIp, int nodePort) struct { RequestResponseHeader header; RequestContractFunction rcf; - MsVaultGetFees_input input; } req; memset(&req, 0, sizeof(req)); @@ -663,7 +662,7 @@ void msvaultGetFees(const char* nodeIp, int nodePort) req.rcf.contractIndex = MSVAULT_CONTRACT_INDEX; req.rcf.inputType = MSVAULT_GET_FEES; - req.rcf.inputSize = sizeof(req.input); + req.rcf.inputSize = 0; req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); diff --git a/qbond.cpp b/qbond.cpp index 35ef6522..708a3c99 100644 --- a/qbond.cpp +++ b/qbond.cpp @@ -422,13 +422,12 @@ void qbondGetFees(const char* nodeIp, int nodePort) struct { RequestResponseHeader header; RequestContractFunction rcf; - GetFees_input in; } req; memset(&req, 0, sizeof(req)); req.rcf.contractIndex = QBOND_CONTRACT_INDEX; req.rcf.inputType = QBOND_GET_FEES; - req.rcf.inputSize = sizeof(req.in); + req.rcf.inputSize = 0; req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); @@ -461,13 +460,12 @@ void qbondGetEarnedFees(const char* nodeIp, int nodePort) struct { RequestResponseHeader header; RequestContractFunction rcf; - GetFees_input in; } req; memset(&req, 0, sizeof(req)); req.rcf.contractIndex = QBOND_CONTRACT_INDEX; req.rcf.inputType = QBOND_GET_EARNED_FEES; - req.rcf.inputSize = sizeof(req.in); + req.rcf.inputSize = 0; req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); @@ -625,13 +623,12 @@ void qbondGetTable(const char* nodeIp, int nodePort) struct { RequestResponseHeader header; RequestContractFunction rcf; - MBondsTable_input in; } req; memset(&req, 0, sizeof(req)); req.rcf.contractIndex = QBOND_CONTRACT_INDEX; req.rcf.inputType = QBOND_GET_TABLE; - req.rcf.inputSize = sizeof(req.in); + req.rcf.inputSize = 0; req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); @@ -722,13 +719,12 @@ void qbondGetCFA(const char* nodeIp, int nodePort) struct { RequestResponseHeader header; RequestContractFunction rcf; - GetCFA_input in; } req; memset(&req, 0, sizeof(req)); req.rcf.contractIndex = QBOND_CONTRACT_INDEX; req.rcf.inputType = QBOND_GET_CFA; - req.rcf.inputSize = sizeof(req.in); + req.rcf.inputSize = 0; req.header.setSize(sizeof(req)); req.header.randomizeDejavu(); req.header.setType(RequestContractFunction::type()); From d15f76e16434715a23894d40588d20649ccbd36f Mon Sep 17 00:00:00 2001 From: Franziska Mueller <11660876+Franziska-Mueller@users.noreply.github.com> Date: Mon, 10 Aug 2026 18:22:14 +0200 Subject: [PATCH 4/5] fix print asset records --- asset_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asset_utils.cpp b/asset_utils.cpp index 9e63604f..ee64b18a 100644 --- a/asset_utils.cpp +++ b/asset_utils.cpp @@ -405,7 +405,7 @@ void printAssetRecords(const char* nodeIp, const int nodePort, const char* reque } auto qc = make_qc(nodeIp, nodePort); - qc->sendData(packet); + qc->sendData(std::span(reinterpret_cast(&packet), packet.header.size()), packet.header.size()); bool receivedResponses = false; if (withSiblings) From 6ee357404c3df9e0b41aae7dbaed9bf734fa6b49 Mon Sep 17 00:00:00 2001 From: Franziska Mueller <11660876+Franziska-Mueller@users.noreply.github.com> Date: Tue, 11 Aug 2026 17:33:50 +0200 Subject: [PATCH 5/5] address reviewer comments --- connection.cpp | 4 +++- connection.h | 14 ++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/connection.cpp b/connection.cpp index 72ae7088..fa688b94 100644 --- a/connection.cpp +++ b/connection.cpp @@ -9,6 +9,8 @@ #include #include #endif + +#include #include #include #include @@ -242,7 +244,7 @@ void QubicConnection::receivePacketWithHeaderAs(T& result) memset(&result, 0, sizeof(T)); if (remainingSize) { - mBuffer.fill(0); + std::fill_n(mBuffer.begin(), remainingSize, 0); receiveAllDataOrThrowException(mBuffer, remainingSize); result = *((T*)mBuffer.data()); } diff --git a/connection.h b/connection.h index 003d998f..609ae02e 100644 --- a/connection.h +++ b/connection.h @@ -6,18 +6,16 @@ #include #include #include +#include #define DEFAULT_TIMEOUT_MSEC 1000 -namespace +// Custom concept to detect if something behaves like a pointer (raw or smart) +template +concept IsPointerLike = std::is_pointer_v || requires(T t) { - // Custom concept to detect if something behaves like a pointer (raw or smart) - template - concept IsPointerLike = std::is_pointer_v || requires(T t) - { - t.operator->(); - }; -} + t.operator->(); +}; // Not thread safe class QubicConnection