-
Notifications
You must be signed in to change notification settings - Fork 12
feat: top up identity #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
586a5bf
e26e122
a10481b
bfbff58
2344d98
05f6e0f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ mod load_identity_from_wallet; | |
| mod refresh_identity; | ||
| mod register_dpns_name; | ||
| mod register_identity; | ||
| mod top_up_identity; | ||
| mod transfer; | ||
| mod withdraw_from_identity; | ||
|
|
||
|
|
@@ -19,7 +20,7 @@ use dash_sdk::dashcore_rpc::dashcore::key::Secp256k1; | |
| use dash_sdk::dashcore_rpc::dashcore::{Address, PrivateKey, TxOut}; | ||
| use dash_sdk::dpp::balances::credits::Duffs; | ||
| use dash_sdk::dpp::dashcore::hashes::Hash; | ||
| use dash_sdk::dpp::dashcore::{OutPoint, PublicKey, Transaction}; | ||
| use dash_sdk::dpp::dashcore::{OutPoint, Transaction}; | ||
| use dash_sdk::dpp::fee::Credits; | ||
| use dash_sdk::dpp::identity::accessors::IdentityGettersV0; | ||
| use dash_sdk::dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0; | ||
|
|
@@ -191,30 +192,52 @@ impl IdentityKeys { | |
| } | ||
|
|
||
| pub type IdentityIndex = u32; | ||
| pub type TopUpIndex = u32; | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub enum IdentityRegistrationMethod { | ||
| pub enum RegisterIdentityFundingMethod { | ||
| UseAssetLock(Address, AssetLockProof, Transaction), | ||
| FundWithUtxo(OutPoint, TxOut, Address, IdentityIndex), | ||
| FundWithWallet(Duffs, IdentityIndex), | ||
| } | ||
|
Comment on lines
+197
to
201
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor Suggestion: Reduce Duplication in Funding Method Enums The Here's a possible refactor: #[derive(Debug, Clone, PartialEq, Eq)]
-pub enum RegisterIdentityFundingMethod {
+pub enum IdentityFundingMethod {
UseAssetLock(Address, AssetLockProof, Transaction),
- FundWithUtxo(OutPoint, TxOut, Address, IdentityIndex),
- FundWithWallet(Duffs, IdentityIndex),
+ FundWithUtxo(OutPoint, TxOut, Address, IdentityIndex, Option<TopUpIndex>),
+ FundWithWallet(Duffs, IdentityIndex, Option<TopUpIndex>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
-pub enum TopUpIdentityFundingMethod {
- UseAssetLock(Address, AssetLockProof, Transaction),
- FundWithUtxo(OutPoint, TxOut, Address, IdentityIndex, TopUpIndex),
- FundWithWallet(Duffs, IdentityIndex, TopUpIndex),
-}By adding an optional
|
||
|
|
||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub enum TopUpIdentityFundingMethod { | ||
| UseAssetLock(Address, AssetLockProof, Transaction), | ||
| FundWithUtxo(OutPoint, TxOut, Address, IdentityIndex, TopUpIndex), | ||
| FundWithWallet(Duffs, IdentityIndex, TopUpIndex), | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct IdentityRegistrationInfo { | ||
| pub alias_input: String, | ||
| pub keys: IdentityKeys, | ||
| pub wallet: Arc<RwLock<Wallet>>, | ||
| pub wallet_identity_index: u32, | ||
| pub identity_registration_method: IdentityRegistrationMethod, | ||
| pub identity_funding_method: RegisterIdentityFundingMethod, | ||
| } | ||
|
|
||
| impl PartialEq for IdentityRegistrationInfo { | ||
| fn eq(&self, other: &Self) -> bool { | ||
| self.alias_input == other.alias_input | ||
| && self.identity_registration_method == other.identity_registration_method | ||
| && self.identity_funding_method == other.identity_funding_method | ||
| && self.keys == other.keys | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct IdentityTopUpInfo { | ||
| pub qualified_identity: QualifiedIdentity, | ||
| pub wallet: Arc<RwLock<Wallet>>, | ||
| pub identity_funding_method: TopUpIdentityFundingMethod, | ||
| } | ||
|
|
||
| impl PartialEq for IdentityTopUpInfo { | ||
| fn eq(&self, other: &Self) -> bool { | ||
| self.qualified_identity == other.qualified_identity | ||
| && self.identity_funding_method == other.identity_funding_method | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, PartialEq)] | ||
| pub struct RegisterDpnsNameInput { | ||
| pub qualified_identity: QualifiedIdentity, | ||
|
|
@@ -226,6 +249,7 @@ pub(crate) enum IdentityTask { | |
| LoadIdentity(IdentityInputToLoad), | ||
| SearchIdentityFromWallet(WalletArcRef, IdentityIndex), | ||
| RegisterIdentity(IdentityRegistrationInfo), | ||
| TopUpIdentity(IdentityTopUpInfo), | ||
| AddKeyToIdentity(QualifiedIdentity, QualifiedIdentityPublicKey, [u8; 32]), | ||
| WithdrawFromIdentity(QualifiedIdentity, Option<Address>, Credits, Option<KeyID>), | ||
| Transfer(QualifiedIdentity, Identifier, Credits, Option<KeyID>), | ||
|
|
@@ -440,6 +464,9 @@ impl AppContext { | |
| self.load_user_identity_from_wallet(sdk, wallet, identity_index) | ||
| .await | ||
| } | ||
| IdentityTask::TopUpIdentity(top_up_info) => { | ||
| self.top_up_identity(top_up_info, sender).await | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.