int deserialize_blockheader(struct buff *buf, btc_block_header *hdr) { int res; res = deserialize_uint32(buf, &hdr->version); res |= deserialize_uint256(buf, &hdr->prevBlock); res |= deserialize_uint256(buf, &hdr->merkleRoot); res |= deserialize_uint32(buf, &hdr->timestamp); res |= deserialize_uint32(buf, &hdr->bits); res |= deserialize_uint32(buf, &hdr->nonce); return res; }
int deserialize_tx(struct buff *buf, btc_msg_tx *tx) { uint64 i; int res; res = deserialize_uint32(buf, &tx->version); res |= deserialize_varint(buf, &tx->in_count); tx->tx_in = safe_malloc(tx->in_count * sizeof *tx->tx_in); for (i = 0; i < tx->in_count; i++) { res |= deserialize_uint256(buf, &tx->tx_in[i].prevTxHash); res |= deserialize_uint32(buf, &tx->tx_in[i].prevTxOutIdx); res |= deserialize_varint(buf, &tx->tx_in[i].scriptLength); tx->tx_in[i].scriptSig = safe_malloc(tx->tx_in[i].scriptLength); res |= deserialize_bytes(buf, tx->tx_in[i].scriptSig, tx->tx_in[i].scriptLength); res |= deserialize_uint32(buf, &tx->tx_in[i].sequence); } res |= deserialize_varint(buf, &tx->out_count); tx->tx_out = safe_malloc(tx->out_count * sizeof *tx->tx_out); for (i = 0; i < tx->out_count; i++) { res |= deserialize_uint64(buf, &tx->tx_out[i].value); res |= deserialize_varint(buf, &tx->tx_out[i].scriptLength); tx->tx_out[i].scriptPubKey = safe_malloc(tx->tx_out[i].scriptLength); res |= deserialize_bytes(buf, tx->tx_out[i].scriptPubKey, tx->tx_out[i].scriptLength); } res |= deserialize_uint32(buf, &tx->lock_time); ASSERT_NOT_TESTED(buff_space_left(buf) == 0); return res; }
static struct tx_ser_data * txdb_deserialize_tx_data(const void *val, size_t vlen) { struct tx_ser_data *tx; struct buff buf; ASSERT(val); buff_init(&buf, (void *)val, vlen); tx = safe_malloc(sizeof *tx); deserialize_uint256(&buf, &tx->blkHash); deserialize_uint64(&buf, &tx->timestamp); deserialize_varint(&buf, &tx->len); tx->buf = safe_calloc(1, tx->len + 1); deserialize_bytes(&buf, tx->buf, tx->len); ASSERT(buff_space_left(&buf) == 0); return tx; }