Closed Z-fly closed 5 months ago
/root/bit/main.cpp: In constructor ‘Bip44Wallet::Bip44Wallet(const string&, int)’:
/root/bit/main.cpp:9:26: error: ‘mnemonic_validate’ is not a member of ‘libbitcoin::wallet’
9 | if (!bc::wallet::mnemonic_validate(mnemonic))
| ^~~~~
/root/bit/main.cpp:12:62: error: invalid initialization of reference of type ‘const word_list&’ {aka ‘const std::vector<std::__cxx11::basic_string~~~
In file included from /root/bit/include/bitcoin/system.hpp:195,
from /root/bit/main.cpp:4:
/root/bit/include/bitcoin/system/wallet/mnemonic.hpp:76:51: note: in passing argument 1 of ‘libbitcoin::long_hash libbitcoin::wallet::decode_mnemonic(const word_list&)’
76 | BC_API long_hash decode_mnemonic(const word_list& mnemonic);
| ~~~^~
/root/bit/main.cpp: In member function ‘std::string Bip44Wallet::get_address(int, int)’:
/root/bit/main.cpp:22:44: error: ‘class libbitcoin::wallet::hd_private’ has no member named ‘to_payment_address’
22 | auto payment_address = address_key.to_payment_address();
| ^~~~~~
ninja: build stopped: subcommand failed.
It seems ChatGPT didn’t specify which version of Libbitcoin to compile with. Did you use /master or /version3?
It appears that the sample was defined using /version3 (the release version). /master/libbitcoin-system/ is production quality, maybe just ask Chat to use that.
I solved the problem.
#include <iostream>
#include <bitcoin/bitcoin.hpp>
std::string generate_bitcoin_address(const std::string& mnemonic, int bip_type, uint32_t account_level, uint32_t chain_type, uint32_t address_index) {
auto mnemonic_words = libbitcoin::split(mnemonic, " ", true);
auto seed = libbitcoin::wallet::decode_mnemonic(mnemonic_words);
libbitcoin::data_chunk seed_chunk(std::begin(seed), std::end(seed));
libbitcoin::wallet::hd_private m_key(seed_chunk, libbitcoin::wallet::hd_private::mainnet);
libbitcoin::wallet::hd_private derived_key = m_key
.derive_private(libbitcoin::wallet::hd_first_hardened_key + bip_type)
.derive_private(libbitcoin::wallet::hd_first_hardened_key)
.derive_private(account_level + libbitcoin::wallet::hd_first_hardened_key)
.derive_private(chain_type)
.derive_private(address_index);
auto pub_key = derived_key.to_public();
auto public_key_hash = libbitcoin::bitcoin_short_hash(pub_key.point());
libbitcoin::wallet::payment_address pay_address(public_key_hash, libbitcoin::wallet::payment_address::mainnet_p2kh);
return pay_address.encoded();
}
int main() {
try {
std::string mnemonic = "interest magic gravity flock border prevent unable ten express notice shaft list";
int bip_type = 44;
uint32_t account_level = 1, chain_type = 0, address_index = 0;
std::string address = generate_bitcoin_address(mnemonic, bip_type, account_level, chain_type, address_index);
std::cout << "Address: " << address << std::endl;
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
return 0;
}
https://chat.openai.com/share/c2e4bb89-648c-4d7b-b825-bf70f2ddbd6e
I asked GPT about this, but the code returned by GPT cannot be compiled. Can someone help me?