-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from pshenmic/feat/identities
Implement all Identities state transitions
- Loading branch information
Showing
10 changed files
with
279 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE identities ( | ||
id SERIAL PRIMARY KEY, | ||
identifier char(44) NOT NULL, | ||
revision int NOT NULL, | ||
state_transition_hash char(64) NOT NULL references state_transitions(hash) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CREATE TABLE transfers ( | ||
id SERIAL PRIMARY KEY, | ||
amount bigint NOT NULL, | ||
sender char(44), | ||
recipient char(44), | ||
state_transition_hash char(64) NOT NULL references state_transitions(hash) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use dpp::identifier::Identifier; | ||
use dpp::prelude::Revision; | ||
use dpp::state_transition::identity_create_transition::accessors::IdentityCreateTransitionAccessorsV0; | ||
use dpp::state_transition::identity_create_transition::IdentityCreateTransition; | ||
use dpp::state_transition::identity_update_transition::accessors::IdentityUpdateTransitionAccessorsV0; | ||
use dpp::state_transition::identity_update_transition::IdentityUpdateTransition; | ||
|
||
#[derive(Clone)] | ||
pub struct Identity { | ||
pub id: Option<u32>, | ||
pub identifier: Identifier, | ||
pub revision: Revision, | ||
pub balance: Option<u64>, | ||
} | ||
|
||
impl From<IdentityCreateTransition> for Identity { | ||
fn from(state_transition: IdentityCreateTransition) -> Self { | ||
return Identity { | ||
id: None, | ||
identifier: state_transition.identity_id(), | ||
balance: None, | ||
revision: Revision::from(0 as u64), | ||
}; | ||
} | ||
} | ||
|
||
impl From<IdentityUpdateTransition> for Identity { | ||
fn from(state_transition: IdentityUpdateTransition) -> Self { | ||
let identifier = state_transition.identity_id(); | ||
let revision = state_transition.revision(); | ||
|
||
return Identity { | ||
id: None, | ||
identifier, | ||
balance: None, | ||
revision, | ||
}; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ pub mod block_header; | |
pub mod block; | ||
pub mod data_contract; | ||
pub mod document; | ||
pub mod identity; | ||
pub mod transfer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use dpp::identifier::Identifier; | ||
use dpp::state_transition::identity_credit_transfer_transition::accessors::IdentityCreditTransferTransitionAccessorsV0; | ||
use dpp::state_transition::identity_credit_transfer_transition::IdentityCreditTransferTransition; | ||
use dpp::state_transition::identity_credit_withdrawal_transition::accessors::IdentityCreditWithdrawalTransitionAccessorsV0; | ||
use dpp::state_transition::identity_credit_withdrawal_transition::IdentityCreditWithdrawalTransition; | ||
use dpp::state_transition::identity_topup_transition::accessors::IdentityTopUpTransitionAccessorsV0; | ||
use dpp::state_transition::identity_topup_transition::IdentityTopUpTransition; | ||
|
||
#[derive(Clone)] | ||
pub struct Transfer { | ||
pub id: Option<u32>, | ||
pub sender: Option<Identifier>, | ||
pub recipient: Option<Identifier>, | ||
pub amount: u64, | ||
} | ||
|
||
impl From<IdentityTopUpTransition> for Transfer { | ||
fn from(state_transition: IdentityTopUpTransition) -> Self { | ||
let identifier = state_transition.identity_id().clone(); | ||
let asset_lock = state_transition.asset_lock_proof().clone(); | ||
let vout_index = asset_lock.instant_lock_output_index().unwrap(); | ||
let tx_out = asset_lock | ||
.transaction() | ||
.unwrap().clone() | ||
.output.get(vout_index) | ||
.cloned().unwrap(); | ||
let amount = tx_out.value * 1000; | ||
|
||
return Transfer { | ||
id: None, | ||
sender:None, | ||
recipient: Some(identifier), | ||
amount | ||
}; | ||
} | ||
} | ||
|
||
impl From<IdentityCreditWithdrawalTransition> for Transfer { | ||
fn from(state_transition: IdentityCreditWithdrawalTransition) -> Self { | ||
let identifier = state_transition.identity_id().clone(); | ||
let amount = state_transition.amount(); | ||
|
||
return Transfer { | ||
id: None, | ||
sender: Some(identifier), | ||
recipient: None, | ||
amount | ||
}; | ||
} | ||
} | ||
|
||
impl From<IdentityCreditTransferTransition> for Transfer { | ||
fn from(state_transition: IdentityCreditTransferTransition) -> Self { | ||
let sender = state_transition.identity_id().clone(); | ||
let recipient = state_transition.recipient_id().clone(); | ||
let amount = state_transition.amount(); | ||
|
||
return Transfer { | ||
id: None, | ||
sender: Some(sender), | ||
recipient: Some(recipient), | ||
amount | ||
}; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.