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

112 lines
3.3 KiB
Rust

use lee_core::{
account::{Account, AccountWithMetadata, Data},
program::{AccountPostState, Claim},
};
use token_core::TokenHolding;
#[must_use]
pub fn transfer(
sender: AccountWithMetadata,
recipient: AccountWithMetadata,
balance_to_move: u128,
) -> Vec<AccountPostState> {
assert!(sender.is_authorized, "Sender authorization is missing");
let mut sender_holding =
TokenHolding::try_from(&sender.account.data).expect("Invalid sender data");
let mut recipient_holding = if recipient.account == Account::default() {
TokenHolding::zeroized_clone_from(&sender_holding)
} else {
TokenHolding::try_from(&recipient.account.data).expect("Invalid recipient data")
};
assert_eq!(
sender_holding.definition_id(),
recipient_holding.definition_id(),
"Sender and recipient definition id mismatch"
);
match (&mut sender_holding, &mut recipient_holding) {
(
TokenHolding::Fungible {
definition_id: _,
balance: sender_balance,
},
TokenHolding::Fungible {
definition_id: _,
balance: recipient_balance,
},
) => {
*sender_balance = sender_balance
.checked_sub(balance_to_move)
.expect("Insufficient balance");
*recipient_balance = recipient_balance
.checked_add(balance_to_move)
.expect("Recipient balance overflow");
}
(
TokenHolding::NftMaster {
definition_id: _,
print_balance: sender_print_balance,
},
TokenHolding::NftMaster {
definition_id: _,
print_balance: recipient_print_balance,
},
) => {
assert_eq!(
*recipient_print_balance, 0,
"Invalid balance in recipient account for NFT transfer"
);
assert_eq!(
*sender_print_balance, balance_to_move,
"Invalid balance for NFT Master transfer"
);
std::mem::swap(sender_print_balance, recipient_print_balance);
}
(
TokenHolding::NftPrintedCopy {
definition_id: _,
owned: sender_owned,
},
TokenHolding::NftPrintedCopy {
definition_id: _,
owned: recipient_owned,
},
) => {
assert_eq!(
balance_to_move, 1,
"Invalid balance for NFT Printed Copy transfer"
);
assert!(*sender_owned, "Sender does not own the NFT Printed Copy");
assert!(
!*recipient_owned,
"Recipient already owns the NFT Printed Copy"
);
*sender_owned = false;
*recipient_owned = true;
}
_ => {
panic!("Mismatched token holding types for transfer");
}
}
let mut sender_post = sender.account;
sender_post.data = Data::from(&sender_holding);
let mut recipient_post = recipient.account;
recipient_post.data = Data::from(&recipient_holding);
vec![
AccountPostState::new(sender_post),
AccountPostState::new_claimed_if_default(recipient_post, Claim::Authorized),
]
}