Beispiel #1
0
void Cacher::read_header(void){
  if (file.is_open()) file.close();
  file.open(m_cacheFilename.c_str(), ios::in|ios::binary);
  deserialize_uint8(&read_major_version);
  deserialize_uint8(&read_minor_version);
  deserialize_string(&m_baseName);
  deserialize_nl();
  bool b=(read_major_version==CACHER_MAJOR_VERSION) &&
    (read_minor_version==CACHER_MINOR_VERSION);
  assert(b && "Cacher version mismatch");
	 
}
Beispiel #2
0
int deserialize_varint(struct buff *buf, uint64 *val) {
  int res;
  uint8 c;

  res = deserialize_uint8(buf, &c);
  if (res) {
    return res;
  }

  if (c < 253) {
    *val = c;
  } else if (c == 253) {
    uint16 len16 = 0;
    res = deserialize_uint16(buf, &len16);
    *val = len16;
  } else if (c == 254) {
    uint32 len32 = 0;
    res = deserialize_uint32(buf, &len32);
    *val = len32;
  } else {
    uint64 len64 = 0;
    res = deserialize_uint64(buf, &len64);
    *val = len64;
  }
  return res;
}
Beispiel #3
0
int deserialize_version(struct buff *buf, btc_msg_version *v) {
  int res;

  memset(v, 0, sizeof *v);

  res = deserialize_uint32(buf, &v->version);
  res |= deserialize_uint64(buf, &v->services);
  res |= deserialize_uint64(buf, &v->time);
  res |= deserialize_addr(BTC_PROTO_MIN, buf, &v->addrTo);
  res |= deserialize_addr(BTC_PROTO_MIN, buf, &v->addrFrom);
  res |= deserialize_uint64(buf, &v->nonce);
  res |= deserialize_str(buf, v->strVersion, sizeof v->strVersion);
  res |= deserialize_uint32(buf, &v->startingHeight);

  if (v->version >= BTC_PROTO_FILTERING && buff_space_left(buf) > 0) {
    res |= deserialize_uint8(buf, &v->relayTx);
  } else {
    v->relayTx = 1;
  }
  ASSERT(buff_space_left(buf) == 0);

  return res;
}
Beispiel #4
0
static bool script_parse_one_op(struct buff *buf, struct script_inst *inst,
                                bool *error) {
  uint8 opcode;
  size_t len;
  int res;

  ASSERT(buf);
  ASSERT(inst);
  ASSERT(error);

  *error = 0;
  if (buff_space_left(buf) == 0) {
    /* done ! */
    return 0;
  }

  res = deserialize_uint8(buf, &opcode);
  if (res) {
    goto error;
  }
  inst->opcode = opcode;

  if (opcode < OP_PUSHDATA1) {
    len = opcode;
  } else if (opcode == OP_PUSHDATA1) {
    uint8 len8;
    res = deserialize_uint8(buf, &len8);
    if (res) {
      goto error;
    }
    len = len8;
  } else if (opcode == OP_PUSHDATA2) {
    uint16 len16;
    res = deserialize_uint16(buf, &len16);
    if (res) {
      goto error;
    }
    len = len16;
  } else if (opcode == OP_PUSHDATA4) {
    uint32 len32;
    res = deserialize_uint32(buf, &len32);
    if (res) {
      goto error;
    }
    len = len32;
  } else {
    /*
     * opcode with no data.
     */
    inst->data = NULL;
    inst->len = 0;

    return 1;
  }

  inst->data = buff_curptr(buf);
  inst->len = len;

  res = buff_skip(buf, len);
  if (res) {
    goto error;
  }

  return 1;
error:
  *error = 1;
  return 0;
}