Exemple #1
0
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;
}
Exemple #2
0
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;
}
Exemple #3
0
int deserialize_block(struct buff *buf, btc_msg_block *blk) {
  uint64 i;
  int res;

  res = deserialize_blockheader(buf, &blk->header);
  btcmsg_print_header(&blk->header);
  res |= deserialize_varint(buf, &blk->txCount);
  Warning("numTx=%llu\n", blk->txCount);

  blk->tx = safe_malloc(blk->txCount * sizeof *blk->tx);

  for (i = 0; i < blk->txCount; i++) {
    res |= deserialize_tx(buf, blk->tx + i);
  }

  Warning("sz: %zu vs %zu\n", buff_curlen(buf), buff_maxlen(buf));
  ASSERT(buff_space_left(buf) == 0);

  return res;
}
Exemple #4
0
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;
}
Exemple #5
0
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);
}
Exemple #6
0
	bool
	cql::cql_varint_t::convert_to_boost_multiprecision(boost::multiprecision::cpp_int & output) {
		return deserialize_varint(output, _data);
	}