Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #104 from brianjohnson5972/wallet_start
Browse files Browse the repository at this point in the history
Wallet start
  • Loading branch information
bytemaster authored Jul 30, 2017
2 parents 2632dd5 + 8531b00 commit 87bf4b3
Show file tree
Hide file tree
Showing 6 changed files with 580 additions and 1 deletion.
1 change: 1 addition & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ add_subdirectory( egenesis )
add_subdirectory( utilities )
add_subdirectory( appbase )
add_subdirectory( native_contract )
add_subdirectory( wallet )
19 changes: 19 additions & 0 deletions libraries/wallet/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
file(GLOB HEADERS "include/eos/wallet/*.hpp")

add_library( eos_wallet
wallet.cpp

${HEADERS}
)
target_link_libraries( eos_wallet fc eos_chain )
target_include_directories( eos_wallet
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" )

INSTALL( TARGETS
eos_wallet

RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
INSTALL( FILES ${HEADERS} DESTINATION "include/eos/wallet" )
177 changes: 177 additions & 0 deletions libraries/wallet/include/eos/wallet/wallet.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#pragma once

#include <eos/chain/types.hpp>

#include <fc/real128.hpp>
#include <fc/crypto/base58.hpp>

using namespace std;
using namespace eos::chain;

namespace eos { namespace wallet {

typedef uint16_t transaction_handle_type;

struct wallet_data
{
vector<char> cipher_keys; /** encrypted keys */

string ws_server = "localhost";
uint16_t ws_port = 8090;
string ws_user;
string ws_password;
};

enum authority_type
{
owner,
active,
posting
};

namespace detail {
class wallet_api_impl;
}

/**
* This wallet assumes it is connected to the database server with a high-bandwidth, low-latency connection and
* performs minimal caching. This API could be provided locally to be used by a web interface.
*/
class wallet_api
{
public:
wallet_api( const wallet_data& initial_data );

bool copy_wallet_file( string destination_filename );

/** Returns the current wallet filename.
*
* This is the filename that will be used when automatically saving the wallet.
*
* @see set_wallet_filename()
* @return the wallet filename
*/
string get_wallet_filename() const;

/**
* Get the WIF private key corresponding to a public key. The
* private key must already be in the wallet.
*/
string get_private_key( public_key_type pubkey )const;

/**
* @param role - active | owner | posting | memo
*/
pair<public_key_type,string> get_private_key_from_password( string account, string role, string password )const;

/** Checks whether the wallet has just been created and has not yet had a password set.
*
* Calling \c set_password will transition the wallet to the locked state.
* @return true if the wallet is new
* @ingroup Wallet Management
*/
bool is_new()const;

/** Checks whether the wallet is locked (is unable to use its private keys).
*
* This state can be changed by calling \c lock() or \c unlock().
* @return true if the wallet is locked
* @ingroup Wallet Management
*/
bool is_locked()const;

/** Locks the wallet immediately.
* @ingroup Wallet Management
*/
void lock();

/** Unlocks the wallet.
*
* The wallet remain unlocked until the \c lock is called
* or the program exits.
* @param password the password previously set with \c set_password()
* @ingroup Wallet Management
*/
void unlock(string password);

/** Sets a new password on the wallet.
*
* The wallet must be either 'new' or 'unlocked' to
* execute this command.
* @ingroup Wallet Management
*/
void set_password(string password);

/** Dumps all private keys owned by the wallet.
*
* The keys are printed in WIF format. You can import these keys into another wallet
* using \c import_key()
* @returns a map containing the private keys, indexed by their public key
*/
map<public_key_type, string> list_keys();

/** Loads a specified Graphene wallet.
*
* The current wallet is closed before the new wallet is loaded.
*
* @warning This does not change the filename that will be used for future
* wallet writes, so this may cause you to overwrite your original
* wallet unless you also call \c set_wallet_filename()
*
* @param wallet_filename the filename of the wallet JSON file to load.
* If \c wallet_filename is empty, it reloads the
* existing wallet file
* @returns true if the specified wallet is loaded
*/
bool load_wallet_file(string wallet_filename = "");

/** Saves the current wallet to the given filename.
*
* @warning This does not change the wallet filename that will be used for future
* writes, so think of this function as 'Save a Copy As...' instead of
* 'Save As...'. Use \c set_wallet_filename() to make the filename
* persist.
* @param wallet_filename the filename of the new wallet JSON file to create
* or overwrite. If \c wallet_filename is empty,
* save to the current filename.
*/
void save_wallet_file(string wallet_filename = "");

/** Sets the wallet filename used for future writes.
*
* This does not trigger a save, it only changes the default filename
* that will be used the next time a save is triggered.
*
* @param wallet_filename the new filename to use for future saves
*/
void set_wallet_filename(string wallet_filename);

/** Imports a WIF Private Key into the wallet to be used to sign transactions by an account.
*
* example: import_key 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
*
* @param wif_key the WIF Private Key to import
*/
bool import_key( string wif_key );

std::shared_ptr<detail::wallet_api_impl> my;
void encrypt_keys();
};

struct plain_keys {
fc::sha512 checksum;
map<public_key_type,string> keys;
};

} }

FC_REFLECT( eos::wallet::wallet_data,
(cipher_keys)
(ws_server)
(ws_user)
(ws_password)
)

FC_REFLECT( eos::wallet::plain_keys, (checksum)(keys) )

FC_REFLECT_ENUM( eos::wallet::authority_type, (owner)(active)(posting) )
Loading

0 comments on commit 87bf4b3

Please sign in to comment.