bool BaseBlock::submitValue(const Parser::name_stack_t& name_stack, Parser& p, bool silent) { if (!deserializeBlock(p, std::make_pair(name_stack.begin(), name_stack.end()))) { if (!silent) { p.parserWarning(llformat("Failed to parse parameter \"%s\"", p.getCurrentElementName().c_str())); } return false; } return true; }
uint32_t deserializeBlockHeaders(BlockHeaders * self){ assert(self != NULL); ByteArray * bytes = getMessage(self)->bytes; if (!bytes) { getMessage(self)->onErrorReceived(ERROR_MESSAGE_DESERIALISATION_NULL_BYTES,"Attempting to deserialize a BlockHeaders with no bytes."); return 0; } if (bytes->length < 82) { getMessage(self)->onErrorReceived(ERROR_MESSAGE_DESERIALISATION_BAD_BYTES,"Attempting to deserialize a BlockHeaders with less bytes than required for one header."); return 0; } VarLenInt numOfHeaders = decodeVarLenInt(bytes, 0); if (numOfHeaders.value > 2000) { getMessage(self)->onErrorReceived(ERROR_MESSAGE_DESERIALISATION_BAD_BYTES,"Attempting to deserialize a BlockHeaders with a var int over 2000."); return 0; } /* Deserialise each header */ self->blockHeaders = malloc(sizeof(*self->blockHeaders) * (size_t)numOfHeaders.value); if (! self->blockHeaders) { getMessage(self)->onErrorReceived(ERROR_OUT_OF_MEMORY,"Cannot allocate %i bytes of memory in deserializeBlockHeaders\n",sizeof(*self->blockHeaders) * (size_t)numOfHeaders.value); return 0; } self->numOfHeaders = numOfHeaders.value; uint16_t cursor = numOfHeaders.storageSize; uint16_t x; for ( x = 0; x < numOfHeaders.value; x++) { /* Make new Block from the rest of the data. */ ByteArray * data = getByteArraySubsectionReference(bytes, cursor, bytes->length-cursor); if (! data) { getMessage(self)->onErrorReceived(ERROR_INIT_FAIL,"Cannot create a new ByteArray in deserializeBlockHeaders for the header number %u.",x); return 0; } self->blockHeaders[x] = createNewBlockFromByteArray(data, getMessage(self)->onErrorReceived); if (! self->blockHeaders[x]){ getMessage(self)->onErrorReceived(ERROR_INIT_FAIL,"Cannot create a new Block in deserializeBlockHeaders for the header number %u.",x); destroyObject(data); return 0; } /* Deserialize */ uint8_t len = deserializeBlock(self->blockHeaders[x],false); /* false for no transactions. Only the header. */ if (! len){ getMessage(self)->onErrorReceived(ERROR_MESSAGE_DESERIALISATION_BAD_BYTES,"BlockHeaders cannot be deserialised because of an error with the Block number %u.",x); destroyObject(data); return 0; } /* Adjust length */ data->length = len; destroyObject(data); cursor += len; } return cursor; }