int deserialize_str_alloc(struct buff *buf, char **str, size_t *len) { uint64 length; int res; *str = NULL; if (len) { *len = 0; } res = deserialize_varint(buf, &length); if (res) { return res; } if (length == 0) { return 0; } *str = safe_calloc(1, length + 1); if (len) { *len = length; } if (deserialize_bytes(buf, *str, length)) { free(*str); *str = NULL; if (len) { *len = 0; } return 1; } return 0; }
int deserialize_inv(struct buff *buf, btc_msg_inv *inv) { int res; res = deserialize_uint32(buf, &inv->type); if (res) { return res; } return deserialize_bytes(buf, &inv->hash, sizeof inv->hash); }
int deserialize_addr(uint32 protversion, struct buff *buf, btc_msg_address *addr) { int res = 0; addr->time = 0; if (protversion >= BTC_PROTO_ADDR_W_TIME) { res = deserialize_uint32(buf, &addr->time); } res |= deserialize_uint64(buf, &addr->services); res |= deserialize_bytes(buf, addr->ip, ARRAYSIZE(addr->ip)); res |= deserialize_uint16(buf, &addr->port); 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; }
int deserialize_str(struct buff *buf, char *str, size_t size) { uint64 len; int res; memset(str, 0, size); res = deserialize_varint(buf, &len); if (res) { return res; } if (len == 0) { return 0; } if (len >= size) { NOT_TESTED(); return 1; } str[size - 1] = '\0'; if (len < size) { str[len] = '\0'; } return deserialize_bytes(buf, str, len); }
bool deserialize_uint32(const char *p_stream, uint32_t p_stream_size, uint32_t &r_offset, uint32_t &r_val) { return deserialize_bytes(p_stream, p_stream_size, r_offset, &r_val, sizeof(uint32_t)); }
int deserialize_uint256(struct buff *buf, uint256 *val) { return deserialize_bytes(buf, val, sizeof *val); }