Closed netsamir closed 3 years ago
I would assume this pertains to your boost dependency. How did you build libbitcoin? Also, you aren't using any bx code. You can build this directly against libbitcoin.
#include <bitcoin/system.hpp>
BC_USE_LIBBITCOIN_MAIN
int bc::system::main(int argc, char* argv[])
{
const std::string search = "1oana";
data_chunk entropy(ec_secret_size);
while (true)
{
pseudo_random_fill(entropy);
wallet::ec_private private_key(entropy);
// Guard against entropy -> invalid secret (rare but possible).
if (!private_key)
continue;
const auto address = private_key.to_payment_address().encoded();
if (to_lower(address.substr(0, search.length())) == search)
{
cout << "Found vanity address! " << address << std::endl;
cout << "Secret (WIF encoded): " << private_key.encoded()
<< std::endl;
return 0;
}
cout << address << address << std::endl;
}
return 0;
}
The above is equivalent code, and both it and yours compile and run with only the libbitcoin dependency.
I would assume this pertains to your boost dependency. How did you build libbitcoin? Also, you aren't using any bx code. You can build this directly against libbitcoin.
I have build the last version with the following command:
sudo ./install.sh --build-boost --build-zmq --with-icu --disable-shared
#include <bitcoin/system.hpp> BC_USE_LIBBITCOIN_MAIN int bc::system::main(int argc, char* argv[]) { const std::string search = "1oana"; data_chunk entropy(ec_secret_size); while (true) { pseudo_random_fill(entropy); wallet::ec_private private_key(entropy); // Guard against entropy -> invalid secret (rare but possible). if (!private_key) continue; const auto address = private_key.to_payment_address().encoded(); if (to_lower(address.substr(0, search.length())) == search) { cout << "Found vanity address! " << address << std::endl; cout << "Secret (WIF encoded): " << private_key.encoded() << std::endl; return 0; } cout << address << address << std::endl; } return 0; }
Trying to compile your code I get the following trace:
$ g++ -o vanity vanity.cpp $(pkg-config --cflags --libs libbitcoin-explorer) <<<
vanity.cpp:5:9: error: ‘bc::system’ has not been declared
5 | int bc::system::main(int argc, char* argv[])
| ^~~~~~
vanity.cpp:5:5: error: redefinition of ‘int main(int, char**)’
5 | int bc::system::main(int argc, char* argv[])
| ^~
In file included from /usr/local/include/bitcoin/system/unicode/file_lock.hpp:28,
from /usr/local/include/bitcoin/system.hpp:129,
from vanity.cpp:1:
vanity.cpp:3:1: note: ‘int main(int, char**)’ previously defined here
3 | BC_USE_LIBBITCOIN_MAIN
| ^~~~~~~~~~~~~~~~~~~~~~
vanity.cpp: In function ‘int main(int, char**)’:
vanity.cpp:8:5: error: ‘data_chunk’ was not declared in this scope; did you mean ‘libbitcoin::data_chunk’?
8 | data_chunk entropy(ec_secret_size);
| ^~~~~~~~~~
| libbitcoin::data_chunk
In file included from /usr/local/include/bitcoin/system/math/hash.hpp:29,
from /usr/local/include/bitcoin/system/formats/base_16.hpp:24,
from /usr/local/include/bitcoin/system/config/checkpoint.hpp:27,
from /usr/local/include/bitcoin/system/constants.hpp:25,
from /usr/local/include/bitcoin/system.hpp:19,
from vanity.cpp:1:
/usr/local/include/bitcoin/system/utility/data.hpp:48:30: note: ‘libbitcoin::data_chunk’ declared here
48 | typedef std::vector<uint8_t> data_chunk;
| ^~~~~~~~~~
vanity.cpp:12:28: error: ‘entropy’ was not declared in this scope; did you mean ‘getentropy’?
12 | pseudo_random_fill(entropy);
| ^~~~~~~
| getentropy
vanity.cpp:12:9: error: ‘pseudo_random_fill’ was not declared in this scope; did you mean ‘libbitcoin::pseudo_random_fill’?
12 | pseudo_random_fill(entropy);
| ^~~~~~~~~~~~~~~~~~
| libbitcoin::pseudo_random_fill
In file included from /usr/local/include/bitcoin/system.hpp:164,
from vanity.cpp:1:
/usr/local/include/bitcoin/system/utility/pseudo_random.hpp:105:13: note: ‘libbitcoin::pseudo_random_fill’ declared here
105 | BC_API void pseudo_random_fill(data_chunk& out);
| ^~~~~~~~~~~~~~~~~~
vanity.cpp:13:9: error: ‘wallet’ has not been declared
13 | wallet::ec_private private_key(entropy);
| ^~~~~~
vanity.cpp:16:14: error: ‘private_key’ was not declared in this scope
16 | if (!private_key)
| ^~~~~~~~~~~
vanity.cpp:19:30: error: ‘private_key’ was not declared in this scope
19 | const auto address = private_key.to_payment_address().encoded();
| ^~~~~~~~~~~
vanity.cpp:21:13: error: ‘to_lower’ was not declared in this scope; did you mean ‘libbitcoin::to_lower’?
21 | if (to_lower(address.substr(0, search.length())) == search)
| ^~~~~~~~
| libbitcoin::to_lower
In file included from /usr/local/include/bitcoin/system/unicode/file_lock.hpp:28,
from /usr/local/include/bitcoin/system.hpp:129,
from vanity.cpp:1:
/usr/local/include/bitcoin/system/unicode/unicode.hpp:123:20: note: ‘libbitcoin::to_lower’ declared here
123 | BC_API std::string to_lower(const std::string& value);
| ^~~~~~~~
vanity.cpp:23:13: error: ‘cout’ was not declared in this scope
23 | cout << "Found vanity address! " << address << std::endl;
| ^~~~
vanity.cpp:23:13: note: suggested alternatives:
In file included from /usr/local/include/bitcoin/system/config/checkpoint.hpp:23,
from /usr/local/include/bitcoin/system/constants.hpp:25,
from /usr/local/include/bitcoin/system.hpp:19,
from vanity.cpp:1:
61 | extern ostream cout; /// Linked to standard output
| ^~~~
In file included from /usr/local/include/bitcoin/system/unicode/file_lock.hpp:28,
from /usr/local/include/bitcoin/system.hpp:129,
from vanity.cpp:1:
vanity.cpp:3:1: note: ‘libbitcoin::cout’
3 | BC_USE_LIBBITCOIN_MAIN
| ^~~~~~~~~~~~~~~~~~~~~~
vanity.cpp:30:9: error: ‘cout’ was not declared in this scope
30 | cout << address << address << std::endl;
| ^~~~
vanity.cpp:30:9: note: suggested alternatives:
In file included from /usr/local/include/bitcoin/system/config/checkpoint.hpp:23,
from /usr/local/include/bitcoin/system/constants.hpp:25,
from /usr/local/include/bitcoin/system.hpp:19,
from vanity.cpp:1:
/usr/include/c++/9/iostream:61:18: note: ‘std::cout’
61 | extern ostream cout; /// Linked to standard output
| ^~~~
In file included from /usr/local/include/bitcoin/system/unicode/file_lock.hpp:28,
from /usr/local/include/bitcoin/system.hpp:129,
from vanity.cpp:1:
vanity.cpp:3:1: note: ‘libbitcoin::cout’
3 | BC_USE_LIBBITCOIN_MAIN
| ^~~~~~~~~~~~~~~~~~~~~~
I used v4 (master), just remove system::
namespace refs.
Just some background information. I am studying bitcoin and I am testing the code provided by https://github.com/bitcoinbook/bitcoinbook.
The coded provided by the author is out of date. Eventually, I would like to make a pull request with the correct code. Hence my question. Honestly, I am not a CPP developer, I am just trying to follow the book. Thanks in advance.
I used v4 (master), just remove
system::
namespace refs.
yes that compile.
Yes, the book is dated. It’s a couple versions back. But it’s all pretty close.
The code you have provided compile and seems to do what the author intended to do. Have you got any idea why his coded failed ? I am asking because I will try to propose the code you provided. Thanks
It didn’t need to use bx, much simpler to use bc. But otherwise it’s just your build environment that produced the earlier error. Nothing wrong with the code, except being way too complex.
Ok thanks have a nice day. Appreciate. I will create a pull request with your code. Is there something I can comment to make clear that you assist ?
Many thanks for your quick reply
I previously edited the book. Happy to have someone else keep it up. No need for credit.
New pull request for bitcoinbook https://github.com/bitcoinbook/bitcoinbook/pull/908
Hi,
Trying to compile a code (see later) I get the following error message:
Here is the code: