storage { k: User v: Vec<Item> }
If I want to give a unique identifier to the item.
Can I use UnixTime::now()
?
If the user sends a batch tx and it creates two items. Will their identifier be different?
Substrate and Polkadot Stack Exchange is a question and answer site for developers building blockchains with the Substrate SDK. It only takes a minute to sign up.
Sign up to join this communityTimestamp sounds strictly worse than the block number, but this is even not good enough.
We use something called a "timepoint" in the multisig pallet, which is:
https://github.com/paritytech/substrate/blob/master/frame/multisig/src/lib.rs#L94
/// A global extrinsic index, formed as the extrinsic index within a block, together with that
/// block's height. This allows a transaction in which a multisig operation of a particular
/// composite was created to be uniquely identified.
#[derive(
Copy, Clone, Eq, PartialEq, Encode, Decode, Default, RuntimeDebug, TypeInfo, MaxEncodedLen,
)]
pub struct Timepoint<BlockNumber> {
/// The height of the chain at the point in time.
height: BlockNumber,
/// The index of the extrinsic at the point in time.
index: u32,
}
This will not work with a batch call, since all the extrinsics in the batch will have the same height and index. In that case, you should track your own unique id, like a u32 counter, in the pallet you are concerned about.
StorageMap
? Why can you not use an ever-increasing counter?