Graphene Updates and DApp Support #643
7 changed files with 25 additions and 24 deletions
|
|
@ -804,7 +804,7 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx
|
|||
const auto& tapos_block_summary = block_summary_id_type( trx.ref_block_num )(*this);
|
||||
|
||||
//Verify TaPoS block summary has correct ID prefix, and that this block's time is not past the expiration
|
||||
FC_ASSERT( trx.ref_block_prefix == tapos_block_summary.block_id._hash[1] );
|
||||
FC_ASSERT( trx.ref_block_prefix == tapos_block_summary.block_id._hash[1].value() );
|
||||
}
|
||||
|
||||
fc::time_point_sec now = head_block_time();
|
||||
|
|
|
|||
|
|
@ -35,13 +35,13 @@ namespace graphene { namespace chain {
|
|||
|
||||
uint32_t block_header::num_from_id(const block_id_type& id)
|
||||
{
|
||||
return fc::endian_reverse_u32(id._hash[0]);
|
||||
return boost::endian::endian_reverse(id._hash[0].value());
|
||||
}
|
||||
|
||||
block_id_type signed_block_header::id()const
|
||||
{
|
||||
auto tmp = fc::sha224::hash( *this );
|
||||
tmp._hash[0] = fc::endian_reverse_u32(block_num()); // store the block num in the ID, 160 bits is plenty for the hash
|
||||
tmp._hash[0] = boost::endian::endian_reverse(block_num()); // store the block num in the ID, 160 bits is plenty for the hash
|
||||
static_assert( sizeof(tmp._hash[0]) == 4, "should be 4 bytes" );
|
||||
block_id_type result;
|
||||
memcpy(result._hash, tmp._hash, std::min(sizeof(result), sizeof(tmp)));
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
#include <graphene/chain/protocol/memo.hpp>
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <fc/crypto/aes.hpp>
|
||||
#include <fc/io/raw.hpp>
|
||||
|
||||
|
|
@ -36,7 +37,7 @@ void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::pub
|
|||
to = pub;
|
||||
if( custom_nonce == 0 )
|
||||
{
|
||||
uint64_t entropy = fc::sha224::hash(fc::ecc::private_key::generate())._hash[0];
|
||||
uint64_t entropy = fc::sha224::hash(fc::ecc::private_key::generate())._hash[0].value();
|
||||
entropy <<= 32;
|
||||
entropy &= 0xff00000000000000;
|
||||
nonce = (fc::time_point::now().time_since_epoch().count() & 0x00ffffffffffffff) | entropy;
|
||||
|
|
@ -44,7 +45,7 @@ void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::pub
|
|||
nonce = custom_nonce;
|
||||
auto secret = priv.get_shared_secret(pub);
|
||||
auto nonce_plus_secret = fc::sha512::hash(fc::to_string(nonce) + secret.str());
|
||||
string text = memo_message(digest_type::hash(msg)._hash[0], msg).serialize();
|
||||
string text = memo_message(digest_type::hash(msg)._hash[0].value(), msg).serialize();
|
||||
message = fc::aes_encrypt( nonce_plus_secret, vector<char>(text.begin(), text.end()) );
|
||||
}
|
||||
else
|
||||
|
|
@ -63,7 +64,7 @@ string memo_data::get_message(const fc::ecc::private_key& priv,
|
|||
auto nonce_plus_secret = fc::sha512::hash(fc::to_string(nonce) + secret.str());
|
||||
auto plain_text = fc::aes_decrypt( nonce_plus_secret, message );
|
||||
auto result = memo_message::deserialize(string(plain_text.begin(), plain_text.end()));
|
||||
FC_ASSERT( result.checksum == uint32_t(digest_type::hash(result.text)._hash[0]) );
|
||||
FC_ASSERT( result.checksum == (uint32_t)digest_type::hash(result.text)._hash[0].value() );
|
||||
return result.text;
|
||||
}
|
||||
else
|
||||
|
|
@ -75,7 +76,7 @@ string memo_data::get_message(const fc::ecc::private_key& priv,
|
|||
string memo_message::serialize() const
|
||||
{
|
||||
auto serial_checksum = string(sizeof(checksum), ' ');
|
||||
(uint32_t&)(*serial_checksum.data()) = checksum;
|
||||
(uint32_t&)(*serial_checksum.data()) = boost::endian::native_to_little(checksum);
|
||||
return serial_checksum + text;
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +84,7 @@ memo_message memo_message::deserialize(const string& serial)
|
|||
{
|
||||
memo_message result;
|
||||
FC_ASSERT( serial.size() >= sizeof(result.checksum) );
|
||||
result.checksum = ((uint32_t&)(*serial.data()));
|
||||
result.checksum = boost::endian::little_to_native((uint32_t&)(*serial.data()));
|
||||
result.text = serial.substr(sizeof(result.checksum));
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,8 +90,8 @@ void transaction::set_expiration( fc::time_point_sec expiration_time )
|
|||
|
||||
void transaction::set_reference_block( const block_id_type& reference_block )
|
||||
{
|
||||
ref_block_num = fc::endian_reverse_u32(reference_block._hash[0]);
|
||||
ref_block_prefix = reference_block._hash[1];
|
||||
ref_block_num = boost::endian::endian_reverse(reference_block._hash[0].value());
|
||||
ref_block_prefix = reference_block._hash[1].value();
|
||||
}
|
||||
|
||||
void transaction::get_required_authorities( flat_set<account_id_type>& active, flat_set<account_id_type>& owner, vector<authority>& other )const
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ namespace graphene { namespace chain {
|
|||
auto bin = fc::from_base58( base58str.substr( prefix_len ) );
|
||||
auto bin_key = fc::raw::unpack<binary_key>(bin);
|
||||
key_data = bin_key.data;
|
||||
FC_ASSERT( fc::ripemd160::hash( (char*)key_data.data(), key_data.size() )._hash[0] == bin_key.check );
|
||||
FC_ASSERT( fc::ripemd160::hash( (char*)key_data.data(), key_data.size() )._hash[0].value() == bin_key.check );
|
||||
};
|
||||
|
||||
bool public_key_type::is_valid_muse( const std::string& base58str )
|
||||
|
|
@ -83,7 +83,7 @@ namespace graphene { namespace chain {
|
|||
auto bin = fc::from_base58( base58str.substr( prefix_len ) );
|
||||
auto bin_key = fc::raw::unpack<binary_key>(bin);
|
||||
key_data = bin_key.data;
|
||||
FC_ASSERT( fc::ripemd160::hash( (char*)key_data.data(), key_data.size() )._hash[0] == bin_key.check );
|
||||
FC_ASSERT( fc::ripemd160::hash( (char*)key_data.data(), key_data.size() )._hash[0].value() == bin_key.check );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ namespace graphene { namespace chain {
|
|||
auto bin = fc::from_base58( base58str.substr( prefix_len ) );
|
||||
auto bin_key = fc::raw::unpack<binary_key>(bin);
|
||||
fc::ecc::public_key_data key_data = bin_key.data;
|
||||
FC_ASSERT( fc::ripemd160::hash( (char*)key_data.data(), key_data.size() )._hash[0] == bin_key.check );
|
||||
FC_ASSERT( fc::ripemd160::hash( (char*)key_data.data(), key_data.size() )._hash[0].value() == bin_key.check );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +115,7 @@ namespace graphene { namespace chain {
|
|||
{
|
||||
binary_key k;
|
||||
k.data = key_data;
|
||||
k.check = fc::ripemd160::hash( (char*)k.data.data(), k.data.size() )._hash[0];
|
||||
k.check = fc::ripemd160::hash( (char*)k.data.data(), k.data.size() )._hash[0].value();
|
||||
auto data = fc::raw::pack( k );
|
||||
return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() );
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ namespace graphene { namespace chain {
|
|||
FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) );
|
||||
auto bin = fc::from_base58( base58str.substr( prefix_len ) );
|
||||
auto bin_key = fc::raw::unpack<binary_key>(bin);
|
||||
FC_ASSERT( fc::ripemd160::hash( (char*)bin_key.data.data(), bin_key.data.size() )._hash[0] == bin_key.check );
|
||||
FC_ASSERT( fc::ripemd160::hash( (char*)bin_key.data.data(), bin_key.data.size() )._hash[0].value() == bin_key.check );
|
||||
key_data = bin_key.data;
|
||||
}
|
||||
|
||||
|
|
@ -169,7 +169,7 @@ namespace graphene { namespace chain {
|
|||
{
|
||||
binary_key k;
|
||||
k.data = key_data;
|
||||
k.check = fc::ripemd160::hash( (char*)k.data.data(), k.data.size() )._hash[0];
|
||||
k.check = fc::ripemd160::hash( (char*)k.data.data(), k.data.size() )._hash[0].value();
|
||||
auto data = fc::raw::pack( k );
|
||||
return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() );
|
||||
}
|
||||
|
|
@ -210,7 +210,7 @@ namespace graphene { namespace chain {
|
|||
FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) );
|
||||
auto bin = fc::from_base58( base58str.substr( prefix_len ) );
|
||||
auto bin_key = fc::raw::unpack<binary_key>(bin);
|
||||
FC_ASSERT( fc::ripemd160::hash( (char*)bin_key.data.data(), bin_key.data.size() )._hash[0] == bin_key.check );
|
||||
FC_ASSERT( fc::ripemd160::hash( (char*)bin_key.data.data(), bin_key.data.size() )._hash[0].value() == bin_key.check );
|
||||
key_data = bin_key.data;
|
||||
}
|
||||
|
||||
|
|
@ -223,7 +223,7 @@ namespace graphene { namespace chain {
|
|||
{
|
||||
binary_key k;
|
||||
k.data = key_data;
|
||||
k.check = fc::ripemd160::hash( (char*)k.data.data(), k.data.size() )._hash[0];
|
||||
k.check = fc::ripemd160::hash( (char*)k.data.data(), k.data.size() )._hash[0].value();
|
||||
auto data = fc::raw::pack( k );
|
||||
return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,7 +170,7 @@ optional<T> maybe_id( const string& name_or_id )
|
|||
|
||||
string address_to_shorthash( const address& addr )
|
||||
{
|
||||
uint32_t x = addr.addr._hash[0];
|
||||
uint32_t x = addr.addr._hash[0].value();
|
||||
static const char hd[] = "0123456789abcdef";
|
||||
string result;
|
||||
|
||||
|
|
@ -5391,7 +5391,7 @@ blind_confirmation wallet_api::blind_transfer_help( string from_key_or_label,
|
|||
conf_output.decrypted_memo.amount = change;
|
||||
conf_output.decrypted_memo.blinding_factor = change_blind_factor;
|
||||
conf_output.decrypted_memo.commitment = change_out.commitment;
|
||||
conf_output.decrypted_memo.check = from_secret._hash[0];
|
||||
conf_output.decrypted_memo.check = from_secret._hash[0].value();
|
||||
conf_output.confirmation.one_time_key = one_time_key.get_public_key();
|
||||
conf_output.confirmation.to = from_key;
|
||||
conf_output.confirmation.encrypted_memo = fc::aes_encrypt( from_secret, fc::raw::pack( conf_output.decrypted_memo ) );
|
||||
|
|
@ -5409,7 +5409,7 @@ blind_confirmation wallet_api::blind_transfer_help( string from_key_or_label,
|
|||
conf_output.decrypted_memo.amount = amount;
|
||||
conf_output.decrypted_memo.blinding_factor = blind_factor;
|
||||
conf_output.decrypted_memo.commitment = to_out.commitment;
|
||||
conf_output.decrypted_memo.check = secret._hash[0];
|
||||
conf_output.decrypted_memo.check = secret._hash[0].value();
|
||||
conf_output.confirmation.one_time_key = one_time_key.get_public_key();
|
||||
conf_output.confirmation.to = to_key;
|
||||
conf_output.confirmation.encrypted_memo = fc::aes_encrypt( secret, fc::raw::pack( conf_output.decrypted_memo ) );
|
||||
|
|
@ -5497,7 +5497,7 @@ blind_confirmation wallet_api::transfer_to_blind( string from_account_id_or_name
|
|||
conf_output.decrypted_memo.amount = amount;
|
||||
conf_output.decrypted_memo.blinding_factor = blind_factor;
|
||||
conf_output.decrypted_memo.commitment = out.commitment;
|
||||
conf_output.decrypted_memo.check = secret._hash[0];
|
||||
conf_output.decrypted_memo.check = secret._hash[0].value();
|
||||
conf_output.confirmation.one_time_key = one_time_key.get_public_key();
|
||||
conf_output.confirmation.to = to_key;
|
||||
conf_output.confirmation.encrypted_memo = fc::aes_encrypt( secret, fc::raw::pack( conf_output.decrypted_memo ) );
|
||||
|
|
|
|||
|
|
@ -132,14 +132,14 @@ int main( int argc, char** argv )
|
|||
signed_block b = db.generate_block(db.get_slot_time(slot), db.get_scheduled_witness(slot), nathan_priv_key, database::skip_nothing);
|
||||
FC_ASSERT( db.head_block_id() == b.id() );
|
||||
fc::sha256 h = b.digest();
|
||||
uint64_t rand = h._hash[0];
|
||||
uint64_t rand = h._hash[0].value();
|
||||
slot = 1;
|
||||
while(true)
|
||||
{
|
||||
if( (rand % 100) < miss_rate )
|
||||
{
|
||||
slot++;
|
||||
rand = (rand/100) ^ h._hash[slot&3];
|
||||
rand = (rand/100) ^ h._hash[slot&3].value();
|
||||
missed++;
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Reference in a new issue