/* Print a human-readable representation of the block to fp. */ void block_print(const struct block *b, FILE *fp) { hash_output h; block_hash(b, h); fprintf(fp, "== BLOCK %s ==\n", byte32_to_hex(h)); fprintf(fp, "prev_block_hash: %s\n", byte32_to_hex(b->prev_block_hash)); fprintf(fp, "height: %lu\n", (unsigned long) b->height); fprintf(fp, "nonce: 0x%016lx\n", (unsigned long) b->nonce); transaction_hash(&b->reward_tx, h); fprintf(fp, " == REWARD TX %s ==\n", byte32_to_hex(h)); fprintf(fp, " prev_transaction_hash: %s\n", byte32_to_hex(b->reward_tx.prev_transaction_hash)); fprintf(fp, " dest_pubkey.x: %s\n", byte32_to_hex(b->reward_tx.dest_pubkey.x)); fprintf(fp, " dest_pubkey.y: %s\n", byte32_to_hex(b->reward_tx.dest_pubkey.y)); fprintf(fp, " src_signature.r: %s\n", byte32_to_hex(b->reward_tx.src_signature.r)); fprintf(fp, " src_signature.s: %s\n", byte32_to_hex(b->reward_tx.src_signature.s)); transaction_hash(&b->normal_tx, h); fprintf(fp, " == NORMAL TX %s ==\n", byte32_to_hex(h)); fprintf(fp, " prev_transaction_hash: %s\n", byte32_to_hex(b->normal_tx.prev_transaction_hash)); fprintf(fp, " dest_pubkey.x: %s\n", byte32_to_hex(b->normal_tx.dest_pubkey.x)); fprintf(fp, " dest_pubkey.y: %s\n", byte32_to_hex(b->normal_tx.dest_pubkey.y)); fprintf(fp, " src_signature.r: %s\n", byte32_to_hex(b->normal_tx.src_signature.r)); fprintf(fp, " src_signature.s: %s\n", byte32_to_hex(b->normal_tx.src_signature.s)); }
int checkAncestorTx(struct blockchain_node *curr) { struct blockchain_node *ancestor = curr->parent; while (ancestor != 0) { hash_output reward_tx_hash; hash_output normal_tx_hash; transaction_hash(&ancestor->block.reward_tx, reward_tx_hash); transaction_hash(&ancestor->block.normal_tx, normal_tx_hash); if (byte32_cmp(curr->block.normal_tx.prev_transaction_hash, reward_tx_hash) == 1 || byte32_cmp(curr->block.normal_tx.prev_transaction_hash, normal_tx_hash) == 1) { return 1; } else { ancestor = ancestor->parent; } } return 0; }
void findPrevTx (struct block* block, struct block* blocks, struct blockchain_node *current, int argc) { int i; for (i=0; i<argc; i++) { struct block b = blocks[i]; hash_output reward_tx_hash; hash_output normal_tx_hash; transaction_hash(&b.reward_tx, reward_tx_hash); transaction_hash(&b.normal_tx, normal_tx_hash); if (byte32_cmp(reward_tx_hash, block->normal_tx.prev_transaction_hash) == 0) { current->prev_transaction = b.reward_tx; //printf("%u/n", current->prev_transaction.height); break; } else if (byte32_cmp(normal_tx_hash, block->normal_tx.prev_transaction_hash) == 0) { current->prev_transaction = b.normal_tx; break; } } }
/* Set the prev_transaction_hash field to the hash of the given prev_tx. The * special value prev_tx==NULL means there is no previous transaction; i.e., * this is either a reward transaction or it is an unused normal transaction. */ void transaction_set_prev_transaction(struct transaction *tx, const struct transaction *prev_tx) { hash_output h; if (prev_tx == NULL) { memset(tx->prev_transaction_hash, 0, sizeof(tx->prev_transaction_hash)); return; } transaction_hash(prev_tx, h); transaction_set_prev_transaction_hash(tx, h); }