diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-06-11 09:44:13 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-06-12 16:48:41 +0100 |
commit | 63741d82644944f236c93e9f44cb988a38df1993 (patch) | |
tree | 067e2c60d2205ef97f7732ba9ebe0b586b456af2 /src/cryptonote_core | |
parent | Merge pull request #312 (diff) | |
download | monero-63741d82644944f236c93e9f44cb988a38df1993.tar.xz |
Integrated addresses (standard address plus payment id)
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r-- | src/cryptonote_core/account.cpp | 6 | ||||
-rw-r--r-- | src/cryptonote_core/account.h | 1 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_basic_impl.cpp | 75 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_basic_impl.h | 22 |
4 files changed, 100 insertions, 4 deletions
diff --git a/src/cryptonote_core/account.cpp b/src/cryptonote_core/account.cpp index 55e368836..b68103dda 100644 --- a/src/cryptonote_core/account.cpp +++ b/src/cryptonote_core/account.cpp @@ -104,4 +104,10 @@ DISABLE_VS_WARNINGS(4244 4345) return get_account_address_as_str(testnet, m_keys.m_account_address); } //----------------------------------------------------------------- + std::string account_base::get_public_integrated_address_str(const crypto::hash &payment_id, bool testnet) + { + //TODO: change this code into base 58 + return get_account_integrated_address_as_str(testnet, m_keys.m_account_address, payment_id); + } + //----------------------------------------------------------------- } diff --git a/src/cryptonote_core/account.h b/src/cryptonote_core/account.h index dcfd9e8d9..0f36029b5 100644 --- a/src/cryptonote_core/account.h +++ b/src/cryptonote_core/account.h @@ -60,6 +60,7 @@ namespace cryptonote crypto::secret_key generate(const crypto::secret_key& recovery_key = crypto::secret_key(), bool recover = false, bool two_random = false); const account_keys& get_keys() const; std::string get_public_address_str(bool testnet); + std::string get_public_integrated_address_str(const crypto::hash &payment_id, bool testnet); uint64_t get_createtime() const { return m_creation_timestamp; } void set_createtime(uint64_t val) { m_creation_timestamp = val; } diff --git a/src/cryptonote_core/cryptonote_basic_impl.cpp b/src/cryptonote_core/cryptonote_basic_impl.cpp index f2d862e57..839c6ad1e 100644 --- a/src/cryptonote_core/cryptonote_basic_impl.cpp +++ b/src/cryptonote_core/cryptonote_basic_impl.cpp @@ -44,6 +44,21 @@ using namespace epee; namespace cryptonote { + struct integrated_address { + account_public_address adr; + crypto::hash payment_id; + + BEGIN_SERIALIZE_OBJECT() + FIELD(adr) + FIELD(payment_id) + END_SERIALIZE() + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(adr) + KV_SERIALIZE(payment_id) + END_KV_SERIALIZE_MAP() + }; + /************************************************************************/ /* Cryptonote helper functions */ /************************************************************************/ @@ -106,6 +121,16 @@ namespace cryptonote { return summ; } + //------------------------------------------------------------------------------------ + uint8_t get_account_integrated_address_checksum(const public_integrated_address_outer_blob& bl) + { + const unsigned char* pbuf = reinterpret_cast<const unsigned char*>(&bl); + uint8_t summ = 0; + for(size_t i = 0; i!= sizeof(public_integrated_address_outer_blob)-1; i++) + summ += pbuf[i]; + + return summ; + } //----------------------------------------------------------------------- std::string get_account_address_as_str( bool testnet @@ -118,6 +143,21 @@ namespace cryptonote { return tools::base58::encode_addr(address_prefix, t_serializable_object_to_blob(adr)); } //----------------------------------------------------------------------- + std::string get_account_integrated_address_as_str( + bool testnet + , account_public_address const & adr + , crypto::hash const & payment_id + ) + { + uint64_t integrated_address_prefix = testnet ? + config::testnet::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX; + + integrated_address iadr = { + adr, payment_id + }; + return tools::base58::encode_addr(integrated_address_prefix, t_serializable_object_to_blob(iadr)); + } + //----------------------------------------------------------------------- bool is_coinbase(const transaction& tx) { if(tx.vin.size() != 1) @@ -129,14 +169,18 @@ namespace cryptonote { return true; } //----------------------------------------------------------------------- - bool get_account_address_from_str( + bool get_account_integrated_address_from_str( account_public_address& adr + , bool& has_payment_id + , crypto::hash& payment_id , bool testnet , std::string const & str ) { uint64_t address_prefix = testnet ? config::testnet::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX; + uint64_t integrated_address_prefix = testnet ? + config::testnet::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX : config::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX; if (2 * sizeof(public_address_outer_blob) != str.size()) { @@ -148,18 +192,29 @@ namespace cryptonote { return false; } - if (address_prefix != prefix) + if (integrated_address_prefix == prefix) + { + has_payment_id = true; + } + else if (address_prefix == prefix) { - LOG_PRINT_L1("Wrong address prefix: " << prefix << ", expected " << address_prefix); + has_payment_id = false; + } + else { + LOG_PRINT_L1("Wrong address prefix: " << prefix << ", expected " << address_prefix << " or " << integrated_address_prefix); return false; } - if (!::serialization::parse_binary(data, adr)) + integrated_address iadr; + if (!::serialization::parse_binary(data, iadr)) { LOG_PRINT_L1("Account public address keys can't be parsed"); return false; } + adr = iadr.adr; + payment_id = iadr.payment_id; + if (!crypto::check_key(adr.m_spend_public_key) || !crypto::check_key(adr.m_view_public_key)) { LOG_PRINT_L1("Failed to validate address keys"); @@ -196,10 +251,22 @@ namespace cryptonote { //we success adr = blob.m_address; + has_payment_id = false; } return true; } + //----------------------------------------------------------------------- + bool get_account_address_from_str( + account_public_address& adr + , bool testnet + , std::string const & str + ) + { + bool has_payment_id; + crypto::hash payment_id; + return get_account_integrated_address_from_str(adr, has_payment_id, payment_id, testnet, str); + } bool operator ==(const cryptonote::transaction& a, const cryptonote::transaction& b) { return cryptonote::get_transaction_hash(a) == cryptonote::get_transaction_hash(b); diff --git a/src/cryptonote_core/cryptonote_basic_impl.h b/src/cryptonote_core/cryptonote_basic_impl.h index 5c773c4e1..87d6f1024 100644 --- a/src/cryptonote_core/cryptonote_basic_impl.h +++ b/src/cryptonote_core/cryptonote_basic_impl.h @@ -56,6 +56,13 @@ namespace cryptonote { account_public_address m_address; uint8_t check_sum; }; + struct public_integrated_address_outer_blob + { + uint8_t m_ver; + account_public_address m_address; + crypto::hash payment_id; + uint8_t check_sum; + }; #pragma pack (pop) @@ -66,12 +73,27 @@ namespace cryptonote { size_t get_max_tx_size(); bool get_block_reward(size_t median_size, size_t current_block_size, uint64_t already_generated_coins, uint64_t &reward); uint8_t get_account_address_checksum(const public_address_outer_blob& bl); + uint8_t get_account_integrated_address_checksum(const public_integrated_address_outer_blob& bl); std::string get_account_address_as_str( bool testnet , const account_public_address& adr ); + std::string get_account_integrated_address_as_str( + bool testnet + , const account_public_address& adr + , const crypto::hash& payment_id + ); + + bool get_account_integrated_address_from_str( + account_public_address& adr + , bool& has_payment_id + , crypto::hash& payment_id + , bool testnet + , const std::string& str + ); + bool get_account_address_from_str( account_public_address& adr , bool testnet |