shorten transaction
This commit is contained in:
@@ -44,7 +44,6 @@ typedef struct {
|
|||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t txHash[32];
|
|
||||||
uint8_t signature[64]; // Signature of the hash
|
uint8_t signature[64]; // Signature of the hash
|
||||||
} transaction_sig_t;
|
} transaction_sig_t;
|
||||||
|
|
||||||
|
|||||||
@@ -199,7 +199,9 @@ void Block_RemoveTransaction(block_t* block, uint8_t* txHash) {
|
|||||||
|
|
||||||
for (size_t i = 0; i < DynArr_size(block->transactions); i++) {
|
for (size_t i = 0; i < DynArr_size(block->transactions); i++) {
|
||||||
signed_transaction_t* currentTx = (signed_transaction_t*)DynArr_at(block->transactions, i);
|
signed_transaction_t* currentTx = (signed_transaction_t*)DynArr_at(block->transactions, i);
|
||||||
if (memcmp(currentTx->signature.txHash, txHash, 32) == 0) {
|
uint8_t currentTxHash[32];
|
||||||
|
Transaction_CalculateHash(currentTx, currentTxHash);
|
||||||
|
if (memcmp(currentTxHash, txHash, 32) == 0) {
|
||||||
DynArr_remove(block->transactions, i);
|
DynArr_remove(block->transactions, i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,10 @@ void Transaction_Sign(signed_transaction_t* tx, const uint8_t* privateKey) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction_CalculateHash(tx, tx->signature.txHash);
|
uint8_t txHash[32];
|
||||||
|
Transaction_CalculateHash(tx, txHash);
|
||||||
Crypto_SignData(
|
Crypto_SignData(
|
||||||
(const uint8_t*)&tx->transaction,
|
txHash,
|
||||||
sizeof(transaction_t),
|
sizeof(transaction_t),
|
||||||
privateKey,
|
privateKey,
|
||||||
tx->signature.signature
|
tx->signature.signature
|
||||||
@@ -81,13 +82,9 @@ bool Transaction_Verify(const signed_transaction_t* tx) {
|
|||||||
uint8_t txHash[32];
|
uint8_t txHash[32];
|
||||||
Transaction_CalculateHash(tx, txHash);
|
Transaction_CalculateHash(tx, txHash);
|
||||||
|
|
||||||
if (memcmp(txHash, tx->signature.txHash, 32) != 0) {
|
|
||||||
return false; // Hash does not match signature hash
|
|
||||||
}
|
|
||||||
|
|
||||||
// If all checks pass, verify the signature
|
// If all checks pass, verify the signature
|
||||||
return Crypto_VerifySignature(
|
return Crypto_VerifySignature(
|
||||||
(const uint8_t*)&tx->transaction,
|
txHash,
|
||||||
sizeof(transaction_t),
|
sizeof(transaction_t),
|
||||||
tx->signature.signature,
|
tx->signature.signature,
|
||||||
tx->transaction.compressedPublicKey
|
tx->transaction.compressedPublicKey
|
||||||
|
|||||||
Reference in New Issue
Block a user