Skip to content

Commit

Permalink
Merge pull request #1078 from thecodefactory/fixes
Browse files Browse the repository at this point in the history
Initialization order and Electrum mnemonic input fixes
  • Loading branch information
thecodefactory committed Nov 28, 2018
2 parents 82aa2b2 + 02dab97 commit aa1cb8d
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 51 deletions.
2 changes: 1 addition & 1 deletion include/bitcoin/bitcoin/chain/chain_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ class BC_API chain_state

// These are computed on construct from sample and checkpoints.
const activations active_;
const uint32_t median_time_past_;
const uint32_t work_required_;
const uint32_t median_time_past_;
};

} // namespace chain
Expand Down
29 changes: 15 additions & 14 deletions src/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,41 +63,42 @@ using namespace boost::adaptors;
//-----------------------------------------------------------------------------

block::block()
: header_(),
metadata{}
: metadata{},
header_(),
transactions_()
{
}

block::block(const block& other)
: total_inputs_(other.total_inputs_cache()),
non_coinbase_inputs_(other.non_coinbase_inputs_cache()),
: metadata(other.metadata),
header_(other.header_),
transactions_(other.transactions_),
metadata(other.metadata)
total_inputs_(other.total_inputs_cache()),
non_coinbase_inputs_(other.non_coinbase_inputs_cache())
{
}

block::block(block&& other)
: total_inputs_(other.total_inputs_cache()),
non_coinbase_inputs_(other.non_coinbase_inputs_cache()),
: metadata(other.metadata),
header_(std::move(other.header_)),
transactions_(std::move(other.transactions_)),
metadata(other.metadata)
total_inputs_(other.total_inputs_cache()),
non_coinbase_inputs_(other.non_coinbase_inputs_cache())
{
}

block::block(const chain::header& header,
const transaction::list& transactions)
: header_(header),
transactions_(transactions),
metadata{}
: metadata{},
header_(header),
transactions_(transactions)
{
}

block::block(chain::header&& header, transaction::list&& transactions)
: header_(std::move(header)),
transactions_(std::move(transactions)),
metadata{}
: metadata{},
header_(std::move(header)),
transactions_(std::move(transactions))
{
}

Expand Down
30 changes: 15 additions & 15 deletions src/chain/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,39 @@ const uint8_t output::validation::candidate_unspent = 0;
//-----------------------------------------------------------------------------

output::output()
: value_(not_found),
script_{},
metadata{}
: metadata{},
value_(not_found),
script_{}
{
}

output::output(output&& other)
: addresses_(other.addresses_cache()),
: metadata(other.metadata),
addresses_(other.addresses_cache()),
value_(other.value_),
script_(std::move(other.script_)),
metadata(other.metadata)
script_(std::move(other.script_))
{
}

output::output(const output& other)
: addresses_(other.addresses_cache()),
: metadata(other.metadata),
addresses_(other.addresses_cache()),
value_(other.value_),
script_(other.script_),
metadata(other.metadata)
script_(other.script_)
{
}

output::output(uint64_t value, chain::script&& script)
: value_(value),
script_(std::move(script)),
metadata{}
: metadata{},
value_(value),
script_(std::move(script))
{
}

output::output(uint64_t value, const chain::script& script)
: value_(value),
script_(script),
metadata{}
: metadata{},
value_(value),
script_(script)
{
}

Expand Down
20 changes: 15 additions & 5 deletions src/chain/point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,39 @@ const uint32_t point::null_index = no_previous_output;

// A default instance is invalid (until modified).
point::point()
: hash_(null_hash), index_(0), valid_(false)
: hash_(null_hash),
index_(0),
valid_(false)
{
}

point::point(const hash_digest& hash, uint32_t index)
: hash_(hash), index_(index), valid_(true)
: hash_(hash),
index_(index),
valid_(true)
{
}

point::point(hash_digest&& hash, uint32_t index)
: hash_(std::move(hash)), index_(index), valid_(true)
: hash_(std::move(hash)),
index_(index),
valid_(true)
{
}

// protected
point::point(const hash_digest& hash, uint32_t index, bool valid)
: hash_(hash), index_(index), valid_(valid)
: hash_(hash),
index_(index),
valid_(valid)
{
}

// protected
point::point(hash_digest&& hash, uint32_t index, bool valid)
: hash_(std::move(hash)), index_(index), valid_(valid)
: hash_(std::move(hash)),
index_(index),
valid_(valid)
{
}

Expand Down
36 changes: 20 additions & 16 deletions src/chain/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,51 +121,55 @@ inline void write_witnesses(writer& sink, const input::list& inputs)
//-----------------------------------------------------------------------------

transaction::transaction()
: transaction(0, 0, {}, {})
: metadata{},
version_(0),
locktime_(0),
inputs_{},
outputs_{}
{
}

transaction::transaction(transaction&& other)
: hash_(other.hash_cache()),
total_input_value_(other.total_input_value_cache()),
total_output_value_(other.total_output_value_cache()),
: metadata(std::move(other.metadata)),
version_(other.version_),
locktime_(other.locktime_),
inputs_(std::move(other.inputs_)),
outputs_(std::move(other.outputs_)),
metadata(std::move(other.metadata))
hash_(other.hash_cache()),
total_input_value_(other.total_input_value_cache()),
total_output_value_(other.total_output_value_cache())
{
}

transaction::transaction(const transaction& other)
: hash_(other.hash_cache()),
total_input_value_(other.total_input_value_cache()),
total_output_value_(other.total_output_value_cache()),
: metadata(other.metadata),
version_(other.version_),
locktime_(other.locktime_),
inputs_(other.inputs_),
outputs_(other.outputs_),
metadata(other.metadata)
hash_(other.hash_cache()),
total_input_value_(other.total_input_value_cache()),
total_output_value_(other.total_output_value_cache())
{
}

transaction::transaction(uint32_t version, uint32_t locktime,
input::list&& inputs, output::list&& outputs)
: version_(version),
: metadata{},
version_(version),
locktime_(locktime),
inputs_(std::move(inputs)),
outputs_(std::move(outputs)),
metadata{}
outputs_(std::move(outputs))
{
}

transaction::transaction(uint32_t version, uint32_t locktime,
const input::list& inputs, const output::list& outputs)
: version_(version),
: metadata{},
version_(version),
locktime_(locktime),
inputs_(inputs),
outputs_(outputs),
metadata{}
outputs_(outputs)
{
}

Expand Down Expand Up @@ -1140,7 +1144,7 @@ code transaction::accept(bool transaction_pool) const
code transaction::accept(const chain_state& state, bool transaction_pool) const
{
const auto bip16 = state.is_enabled(rule_fork::bip16_rule);
const auto bip30 = state.is_enabled(rule_fork::bip30_rule);
//const auto bip30 = state.is_enabled(rule_fork::bip30_rule);
const auto bip68 = state.is_enabled(rule_fork::bip68_rule);
const auto bip141 = state.is_enabled(rule_fork::bip141_rule);

Expand Down
8 changes: 8 additions & 0 deletions src/wallet/electrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,14 @@ static std::string normalize_text(const std::string& text)
if (!is_combining(ch))
normal += ch;

if (normal.empty())
return {};

if (normal.size() < 3)
return boost::locale::conv::utf_to_utf<char, char32_t>(
reinterpret_cast<const char32_t*>(normal.c_str()),
boost::locale::conv::stop);

// Remove whitespaces between CJK by building an output with them.
std::u32string output{ normal.begin(), normal.begin() + 1 };

Expand Down
14 changes: 14 additions & 0 deletions test/wallet/electrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ BOOST_AUTO_TEST_SUITE(electrum_tests)

#ifdef WITH_ICU

BOOST_AUTO_TEST_CASE(electrum__decode_mnemonic__empty__valid)
{
static const word_list mnemonic{ "" };
const auto seed = electrum::decode_mnemonic(mnemonic);
BOOST_REQUIRE_EQUAL(encode_base16(seed), "2e3749b0a2e6fbbd771b8f0e9227469d0b63d03eeb8c5cddd2a47d7c6f80d0275623ecd50952bef13c0216b52c1272d5bb6e3463e26a696c3d116ae2c4e980f3");
}

BOOST_AUTO_TEST_CASE(electrum__decode_mnemonic__single__valid)
{
static const word_list mnemonic{ "" };
const auto seed = electrum::decode_mnemonic(mnemonic);
BOOST_REQUIRE_EQUAL(encode_base16(seed), "6d0e28a68510d84a46db3daffdef720cb1f796cb68f66b2b5c3294a2805772ebbaa7665a3594addb4440c9024c25b75c80fadb89f1e9ac123dadc65e35e101af");
}

BOOST_AUTO_TEST_CASE(electrum__decode_mnemonic__no_passphrase_1__valid)
{
static const word_list mnemonic{ "foo", "bar", "baz" };
Expand Down

0 comments on commit aa1cb8d

Please sign in to comment.