Esempio n. 1
0
std::unique_ptr<proto::Bip44Address> Blockchain::AllocateAddress(
    const Identifier& nymID,
    const Identifier& accountID,
    const std::string& label,
    const BIP44Chain chain) const
{
    LOCK_ACCOUNT()

    const std::string sNymID = nymID.str();
    const std::string sAccountID = accountID.str();
    std::unique_ptr<proto::Bip44Address> output{nullptr};
    auto account = load_account(accountLock, sNymID, sAccountID);

    if (false == bool(account)) {
        otErr << OT_METHOD << __FUNCTION__ << ": Account does not exist."
              << std::endl;

        return output;
    }

    const auto& type = account->type();
    const auto index =
        chain ? account->internalindex() : account->externalindex();

    if (MAX_INDEX == index) {
        otErr << OT_METHOD << __FUNCTION__ << ": Account is full." << std::endl;

        return output;
    }

    auto& newAddress = add_address(index, *account, chain);
    newAddress.set_version(BLOCKCHAIN_VERSION);
    newAddress.set_index(index);
    newAddress.set_address(calculate_address(*account, chain, index));

    OT_ASSERT(false == newAddress.address().empty());

    otErr << OT_METHOD << __FUNCTION__ << ": Address " << newAddress.address()
          << " allocated." << std::endl;
    newAddress.set_label(label);
    const auto saved = api_.Storage().Store(sNymID, type, *account);

    if (false == saved) {
        otErr << OT_METHOD << __FUNCTION__ << ": Failed to save account."
              << std::endl;

        return output;
    }

    output.reset(new proto::Bip44Address(newAddress));

    return output;
}
Esempio n. 2
0
int main(int argc, const char *argv[]) {
	uint64_t gdt_table[MAX_NUMBER_OF_RECODRS];
	uint64_t ldt_table[MAX_NUMBER_OF_RECODRS];
	uint64_t page_directory[MAX_NUMBER_OF_RECODRS];
	uint64_t page_table[MAX_NUMBER_OF_RECODRS];
/*
	if (freopen("test2.txt", "r", stdin) == NULL) {
		return EXIT_FAILURE;
	}
*/
	char hex_string[MAX_INPUT];

	if (scanf("%s", hex_string) != 1) {
		return EXIT_FAILURE;
	}
	uint64_t logic_address = strtol(hex_string, NULL, 16);

	if (scanf("%s", hex_string) != 1) {
		return EXIT_FAILURE;
	}
	uint64_t segment_register = strtol(hex_string, NULL, 16);

	uint64_t * tables[4] = { gdt_table, ldt_table, page_directory, page_table };
	size_t table_sizes[4];
	for (int i = 0; i < 4; ++i) {
		int size;
		if (scanf("%d", &size) != 1) {
			return EXIT_FAILURE;
		}

		table_sizes[i] = size;
		for (int j = 0; j < size; j++) {
			if (scanf("%s", hex_string) != 1) {
				return EXIT_FAILURE;
			}
			tables[i][j] = strtol(hex_string, NULL, 16);
		}
	}
	uint64_t address = calculate_address(table_sizes[0], table_sizes[1], table_sizes[2],
			table_sizes[3], logic_address, segment_register, gdt_table, ldt_table, page_directory,
			page_table);
	printf("%lx\n", address);

	return EXIT_SUCCESS;
}