Skip to content

Commit

Permalink
Merge pull request #11 from trackback-blockchain/feature/tp-165/did_s…
Browse files Browse the repository at this point in the history
…ave_functionality

Feature/tp 165/did save functionality
  • Loading branch information
Gayan authored Sep 10, 2021
2 parents 4ad206c + 291b5a4 commit 8fe6b0a
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 142 deletions.
45 changes: 37 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
ports:
- "80:80"
default:
image: 533545012068.dkr.ecr.ap-southeast-2.amazonaws.com/tanz-demo-node:latest
image: 533545012068.dkr.ecr.ap-southeast-2.amazonaws.com/trackback-node:latest
ports:
- "9944:9944"
- "30333:30333"
Expand Down
1 change: 1 addition & 0 deletions pallets/dids/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ serde = { version = "1.0.119" }
sp-core = { default-features = false, version = '3.0.0' }
sp-io = { default-features = false, version = '3.0.0' }
sp-runtime = { default-features = false, version = '3.0.0' }
rstest = { version = "0.11.0" }

[features]
default = ['std']
Expand Down
20 changes: 13 additions & 7 deletions pallets/dids/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ pub mod pallet {
/// Value -> DID structure
#[pallet::storage]
#[pallet::getter(fn get_did_document)]
pub(super) type DIDDocument<T: Config> = StorageMap<_, Blake2_128Concat, Vec<u8>, DID<T>>;
pub(super) type DIDDocument<T: Config> = StorageMap<
_,
Blake2_128Concat,
Vec<u8>,
DID<T>
>;

/// Accounts associated with a DID
#[pallet::storage]
Expand Down Expand Up @@ -170,7 +175,6 @@ pub mod pallet {
pub fn create_vc_fingerprint(
origin: OriginFor<T>,
public_key: Vec<u8>,
// mut public_key: Vec<u32>,
vc_hash: Vec<u8>,
active: Option<bool>,
) -> DispatchResultWithPostInfo {
Expand All @@ -189,7 +193,7 @@ pub mod pallet {
VC::<T>::insert(
vc_hash.clone(),
VerifiableCredential {
account_id: None,
account_id: Some(_account),
public_key: public_key.clone(),
block_time_stamp: time,
active,
Expand Down Expand Up @@ -232,6 +236,9 @@ pub mod pallet {
pub fn insert_did_document(
origin: OriginFor<T>,
did_document: Vec<u8>,
did_document_metadata: Option<Vec<u8>>,
did_resolution_metadata: Option<Vec<u8>>,
sender_account_id: <T as frame_system::Config>::AccountId,
did_hash: Vec<u8>,
) -> DispatchResultWithPostInfo {
let origin_account = ensure_signed(origin)?;
Expand All @@ -248,13 +255,12 @@ pub mod pallet {
DIDDocument::<T>::insert(
did_hash.clone(),
DID {
did_uri: None,
did_document,
did_document_metadata,
did_resolution_metadata,
block_number,
block_time_stamp: time,
did_ref: None,
sender_account_id: origin_account.clone(),
active: Some(true),
sender_account_id,
},
);

Expand Down
13 changes: 10 additions & 3 deletions pallets/dids/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ pub struct DIDDetail<T: Config> {
#[derive(Clone, Decode, Encode, Eq, PartialEq)]
pub struct DID<T: Config> {
// DID Document hash: Vec<u8>,
pub did_uri: Option<Vec<u8>>,
// pub did_uri: Option<Vec<u8>>,

// DID Document
pub did_document: Vec<u8>,
// pub did_document: Vec<u8>,

// DID Resolution Metadata
pub did_resolution_metadata: Option<Vec<u8>>,

// DID Document Metadata
pub did_document_metadata: Option<Vec<u8>>,

// Block number
pub block_number: <T as frame_system::Config>::BlockNumber,
// Block time stamp in ISO 8601 format
pub block_time_stamp: u64,
Expand All @@ -33,7 +40,7 @@ pub struct DID<T: Config> {
pub sender_account_id: <T as frame_system::Config>::AccountId,

// Active status
pub active: Option<bool>,
// pub active: Option<bool>,
}

#[derive(Clone, Decode, Encode, Eq, PartialEq)]
Expand Down
Loading

0 comments on commit 8fe6b0a

Please sign in to comment.