Skip to content

Commit

Permalink
Merge pull request #17 from CherryNetwork/ipfs-asset-lifespan
Browse files Browse the repository at this point in the history
Ipfs asset lifespan
  • Loading branch information
charmitro committed Feb 9, 2022
2 parents 8a3a80e + 2638d37 commit 6677d22
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
31 changes: 30 additions & 1 deletion bin/node/pallets/pallet-ipfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod weights;

use codec::{Decode, Encode};
use frame_support::RuntimeDebug;
use frame_system;
use frame_system::offchain::{SendSignedTransaction, Signer};
use scale_info::TypeInfo;
use sp_core::crypto::KeyTypeId;
Expand Down Expand Up @@ -87,6 +88,8 @@ pub mod pallet {
pub size: u64,
pub gateway_url: Vec<u8>,
pub owners: BTreeMap<AccountOf<T>, OwnershipLayer>,
pub created_at: T::BlockNumber,
pub deleting_at: T::BlockNumber,
pub pinned: bool,
}

Expand Down Expand Up @@ -276,6 +279,30 @@ pub mod pallet {
Ok(())
}

// /// Extends the duration of an Ipfs asset
// #[pallet::weight(0)]
// pub fn extend_duration(
// origin: OriginFor<T>,
// ci_address: Vec<u8>,
// fee: BalanceOf<T>,
// ) -> DispatchResult {
// let sender = ensure_signed(origin)?;

// ensure!(
// Self::determine_account_ownership_layer(&ci_address, &sender)? == OwnershipLayer::Owner,
// <Error<T>>::NotIpfsOwner
// );

// let x = TryInto::<u32>::try_into(fee).ok();
// let extra_duration = x.unwrap() / 16; // 16 coins per 1 second
// // let old_duration = <IpfsAsset<T>>::get(&ci_address); //get deleting_at data of cid
// // let new_duration = old_duration + extra_duration.into();

// // update the Ipfs struct with new deleting_at duration.

// Ok(())
// }

/// Pins an IPFS.
#[pallet::weight(0)]
pub fn pin_ipfs_asset(origin: OriginFor<T>, addr: Vec<u8>, cid: Vec<u8>) -> DispatchResult {
Expand Down Expand Up @@ -391,6 +418,7 @@ pub mod pallet {

<DataQueue<T>>::take();

let current_block = <frame_system::Pallet<T>>::block_number();
let mut gateway_url = "http://15.188.14.75:8080/ipfs/".as_bytes().to_vec();
gateway_url.append(&mut cid.clone());

Expand All @@ -399,6 +427,8 @@ pub mod pallet {
size,
gateway_url,
owners: BTreeMap::<AccountOf<T>, OwnershipLayer>::new(),
created_at: current_block,
deleting_at: current_block,
pinned: true, // true by default.
};

Expand Down Expand Up @@ -748,7 +778,6 @@ pub mod pallet {
Err(e) => log::error!("IPFS: add error: {:?}", e),
}
},

DataCommand::AddBytesRaw(m_addr, data, admin, is_recursive) => {
// this should work for different CID's. If you try to
// connect and upload the same CID, you will get a duplicate
Expand Down
1 change: 1 addition & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,7 @@ construct_runtime!(
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>},
TransactionStorage: pallet_transaction_storage::{Pallet, Call, Storage, Inherent, Config<T>, Event<T>},
BagsList: pallet_bags_list::{Pallet, Call, Storage, Event<T>},

Ipfs: pallet_ipfs::{Pallet, Call, Storage, Event<T>},
}
);
Expand Down

0 comments on commit 6677d22

Please sign in to comment.