void bitclient_generateTxHash(uint32 nonce1, uint32 userExtraNonceLength, uint8* userExtraNonce, uint32 coinBase1Length, uint8* coinBase1, uint32 coinBase2Length, uint8* coinBase2, uint8* txHash) { stream_t* streamTXData = streamEx_fromDynamicMemoryRange(1024*32); stream_writeData(streamTXData, coinBase1, coinBase1Length); stream_writeData(streamTXData, &nonce1, 4); stream_writeData(streamTXData, userExtraNonce, userExtraNonceLength); stream_writeData(streamTXData, coinBase2, coinBase2Length); sint32 transactionDataLength = 0; uint8* transactionData = (uint8*)streamEx_map(streamTXData, &transactionDataLength); // special case, we can use the hash of the transaction #if 0 int i; printf("Merkle:\n"); for(i=0; i < transactionDataLength; i++){ printf("%2.2x ", transactionData[i]); } printf("\n"); #endif uint8 hashOut[32]; sha256_context sctx; sha256_starts(&sctx); sha256_update(&sctx, transactionData, transactionDataLength); sha256_finish(&sctx, hashOut); sha256_starts(&sctx); sha256_update(&sctx, hashOut, 32); sha256_finish(&sctx, txHash); free(transactionData); stream_destroy(streamTXData); }
void bitclient_generateTxHash(uint32 userExtraNonceLength, uint8* userExtraNonce, uint32 coinBase1Length, uint8* coinBase1, uint32 coinBase2Length, uint8* coinBase2, uint8* txHash) { stream_t* streamTXData = streamEx_fromDynamicMemoryRange(1024*32); stream_writeData(streamTXData, coinBase1, coinBase1Length); stream_writeData(streamTXData, userExtraNonce, userExtraNonceLength); stream_writeData(streamTXData, coinBase2, coinBase2Length); sint32 transactionDataLength = 0; uint8* transactionData = (uint8*)streamEx_map(streamTXData, &transactionDataLength); // special case, we can use the hash of the transaction uint8 hashOut[32]; sha256_ctx sctx; sha256_init(&sctx); sha256_update(&sctx, transactionData, transactionDataLength); sha256_final(&sctx, hashOut); sha256_init(&sctx); sha256_update(&sctx, hashOut, 32); sha256_final(&sctx, txHash); free(transactionData); stream_destroy(streamTXData); }