user-sidechain-addresses-mapping
User sidechain address mapping is a component containing sidechain addresses belonging to a particular Peerplays user account. User sidechain addresses mapping is used in sidechain handler, a component of a SON plugin, for filtering events reported by listener, to identify the transactions of interest.
Transactions of interest are:
For deposit handling, transfer on a sidechain network where from address is listed in user sidechain addresses mapping and to address is a sidechain address controlled by SON network (Primary wallet).
For withdrawal handling, still to decide… E.g. transfer on a Peerplays network where from address is listed in user sidechain addresses mapping and to address is a address on a Peerplays network controlled by SON network (Primary wallet).
Requirements
In database terms, user sidechain address mapping is one-to-many relation, where one user can have multiple addresses belonging to him on a different blockchain. No duplicates are allowed, so user can register only one address per sidechain.
User sidechain address mapping contains records with Peerplays account as a reference to user, and a string representing the address/account on a target sidechain.
User addresses can be added, deleted and updated. Update and delete may be executed only by user to owning the record.
User sidechain address mapping operations
add_user_sidechain_address - adds user sidechain address
update_user_sidechain_address - updates user sidechain address
delete_user_sidechain_address - deletes user sidechain address
User sidechain address mapping wallet functions
add_user_sidechain_address - adds user sidechain address
update_user_sidechain_address - updates user sidechain address
delete_user_sidechain_address - deletes user sidechain address
get_user_sidechain_address - gets a single user sidechain address (by user account id and network)
list_user_sidechain_address - lists all users sidechain addresses
get_sidechain_addresses - gets a list of all addresses belonging to a given sidechain network
Example of user sidechain addresses mapping
Following table shows user sidechain addresses mapping
User account ID | Network | Addreses |
1.1.1 | network::bitcoin | BitcoinAddress1 |
1.1.1 | network::ethereum | EthereumAddress1 |
1.1.2 | network::bitcoin | BitcoinAddress2 |
1.1.3 | network::bitcoin | BitcoinAddress3 |
1.1.4 | network::ethereum | EthereumAddress4 |
Implementation
Consider the following code as a suggestion, not as a 100% completed ad working implementation. Syntax errors may be present.
Following declaration needs to be moved from SON plugin, to the core:
enum networks {
bitcoin,
eos,
ethereum
};
User sidechain address object:
class user_sidechain_address_object : public graphene::db::abstract_object<user_sidechain_addresses_object> {
uint32_t id; // Primary key
account_id_type user; // User owning the address
network network; // Network to whom address belongs
std::string address; // Sidechain address
}
User sidechain address mapping index:
struct by_network;
struct by_user_network;
using user_sidechain_address_multi_index_type = multi_index_container<
user_sidechain_address_object,
indexed_by<
ordered_unique< tag<by_id>,
member<object, object_id_type, &object::id>
>,
ordered_unique< tag<by_network>,
member<user_sidechain_address_object, network, &user_sidechain_address_object::network>
>,
ordered_unique< tag<by_user_network>,
composite_key<user_sidechain_address_object,
member<user_sidechain_address_object, account_id_type, &user_sidechain_address_object::user>,
member<user_sidechain_address_object, network, &user_sidechain_address_object::network>,
>
>
>
>;
User sidechain address mapping should be indexed at least by:
Primary key index
Network field
User and network fields
User sidechain address create operations:
struct user_sidechain_address_create_operation : public base_operation
{
uint32_t id; // Primary key
account_id_type user; // User owning the address
network network; // Network to whom address belongs
std::string address; // Sidechain address
void validate()const;
};
Validation should check that the item is not duplicated, by checking user and network fields.
User sidechain address update operations:
struct user_sidechain_address_update_operation : public base_operation
{
uint32_t id; // Primary key
account_id_type user; // User owning the address
network network; // Network to whom address belongs
std::string address; // Sidechain address
void validate()const;
};
Validation should check that the item with the given id exists in the list.
User sidechain address delete operation:
struct user_sidechain_address_delete_operation : public base_operation
{
uint32_t id; // Primary key
void validate()const;
};
Validation should check that the item with the given id exists in the list.
Appropriate evaluators must be implemented too.