lssa/programs/token/src/new_definition.rs
Sergio Chouhy 4bcffafe27 refactor!: rename nssa crate to lee
BREAKING CHANGE:
- Crate `nssa` renamed to `lee`; update `Cargo.toml` dependencies from `nssa = { workspace = true }` to `lee = { workspace = true }`.
- Crate `nssa_core` renamed to `lee_core`; update similarly.
- Crate `key_protocol` moved under `lee`; update `Cargo.toml` dependencies from `key_protocol = { workspace = true }` to `lee_key_protocol = { workspace = true }`.
- Type `NSSATransaction` (in `common`) renamed to `LeeTransaction`.
- Error type `nssa::error::NssaError` renamed to `lee::error::LeeError`.
- Error type `nssa_core::error::NssaCoreError` renamed to `lee_core::error::LeeCoreError`.
- All `use nssa::` and `use nssa_core::` import paths must be updated to `use lee::` and `use lee_core::` respectively.
- Guest programs must replace `write_nssa_outputs` with `write_lee_outputs`.
- The sequencer RocksDB column family for the chain state was renamed. Existing databases are incompatible and must be wiped before running the new version.
- Domain separators updated: `"NSSA_seed"` → `"LEE_seed"` (key derivation), `"NSSA/v0.2/KDF-SHA256/"` → `"LEE/v0.2/KDF-SHA256/"` (encryption KDF), `"/NSSA/v0.2/AccountId/PDA/"` →
  `"/LEE/v0.2/AccountId/PDA/"` (public PDA address derivation). All previously derived keys, encrypted outputs, and public PDA addresses are invalidated.
2026-06-01 17:11:42 -03:00

127 lines
4.1 KiB
Rust

use lee_core::{
account::{Account, AccountWithMetadata, Data},
program::{AccountPostState, Claim},
};
use token_core::{
NewTokenDefinition, NewTokenMetadata, TokenDefinition, TokenHolding, TokenMetadata,
};
#[must_use]
pub fn new_fungible_definition(
definition_target_account: AccountWithMetadata,
holding_target_account: AccountWithMetadata,
name: String,
total_supply: u128,
) -> Vec<AccountPostState> {
assert_eq!(
definition_target_account.account,
Account::default(),
"Definition target account must have default values"
);
assert_eq!(
holding_target_account.account,
Account::default(),
"Holding target account must have default values"
);
let token_definition = TokenDefinition::Fungible {
name,
total_supply,
metadata_id: None,
};
let token_holding = TokenHolding::Fungible {
definition_id: definition_target_account.account_id,
balance: total_supply,
};
let mut definition_target_account_post = definition_target_account.account;
definition_target_account_post.data = Data::from(&token_definition);
let mut holding_target_account_post = holding_target_account.account;
holding_target_account_post.data = Data::from(&token_holding);
vec![
AccountPostState::new_claimed(definition_target_account_post, Claim::Authorized),
AccountPostState::new_claimed(holding_target_account_post, Claim::Authorized),
]
}
#[must_use]
pub fn new_definition_with_metadata(
definition_target_account: AccountWithMetadata,
holding_target_account: AccountWithMetadata,
metadata_target_account: AccountWithMetadata,
new_definition: NewTokenDefinition,
metadata: NewTokenMetadata,
) -> Vec<AccountPostState> {
assert_eq!(
definition_target_account.account,
Account::default(),
"Definition target account must have default values"
);
assert_eq!(
holding_target_account.account,
Account::default(),
"Holding target account must have default values"
);
assert_eq!(
metadata_target_account.account,
Account::default(),
"Metadata target account must have default values"
);
let (token_definition, token_holding) = match new_definition {
NewTokenDefinition::Fungible { name, total_supply } => (
TokenDefinition::Fungible {
name,
total_supply,
metadata_id: Some(metadata_target_account.account_id),
},
TokenHolding::Fungible {
definition_id: definition_target_account.account_id,
balance: total_supply,
},
),
NewTokenDefinition::NonFungible {
name,
printable_supply,
} => (
TokenDefinition::NonFungible {
name,
printable_supply,
metadata_id: metadata_target_account.account_id,
},
TokenHolding::NftMaster {
definition_id: definition_target_account.account_id,
print_balance: printable_supply,
},
),
};
let token_metadata = TokenMetadata {
definition_id: definition_target_account.account_id,
standard: metadata.standard,
uri: metadata.uri,
creators: metadata.creators,
primary_sale_date: 0_u64, // TODO #261: future works to implement this
};
let mut definition_target_account_post = definition_target_account.account;
definition_target_account_post.data = Data::from(&token_definition);
let mut holding_target_account_post = holding_target_account.account;
holding_target_account_post.data = Data::from(&token_holding);
let mut metadata_target_account_post = metadata_target_account.account;
metadata_target_account_post.data = Data::from(&token_metadata);
vec![
AccountPostState::new_claimed(definition_target_account_post, Claim::Authorized),
AccountPostState::new_claimed(holding_target_account_post, Claim::Authorized),
AccountPostState::new_claimed(metadata_target_account_post, Claim::Authorized),
]
}