fixed conflicts with token rs from main

This commit is contained in:
jonesmarvin8 2025-12-12 16:27:27 -05:00
parent fac1dc19e2
commit ae50ff65fa

View File

@ -57,12 +57,15 @@ struct TokenHolding {
} }
impl TokenDefinition { impl TokenDefinition {
fn into_data(self) -> Vec<u8> { fn into_data(self) -> Data {
let mut bytes = [0; TOKEN_DEFINITION_DATA_SIZE]; let mut bytes = [0; TOKEN_DEFINITION_DATA_SIZE];
bytes[0] = self.account_type; bytes[0] = self.account_type;
bytes[1..7].copy_from_slice(&self.name); bytes[1..7].copy_from_slice(&self.name);
bytes[7..].copy_from_slice(&self.total_supply.to_le_bytes()); bytes[7..].copy_from_slice(&self.total_supply.to_le_bytes());
bytes.into() bytes
.to_vec()
.try_into()
.expect("23 bytes should fit into Data")
} }
fn parse(data: &[u8]) -> Option<Self> { fn parse(data: &[u8]) -> Option<Self> {
@ -122,7 +125,10 @@ impl TokenHolding {
bytes[0] = self.account_type; bytes[0] = self.account_type;
bytes[1..33].copy_from_slice(&self.definition_id.to_bytes()); bytes[1..33].copy_from_slice(&self.definition_id.to_bytes());
bytes[33..].copy_from_slice(&self.balance.to_le_bytes()); bytes[33..].copy_from_slice(&self.balance.to_le_bytes());
bytes.into() bytes
.to_vec()
.try_into()
.expect("33 bytes should fit into Data")
} }
} }
@ -376,10 +382,13 @@ fn mint_additional_supply(
type Instruction = [u8; 23]; type Instruction = [u8; 23];
fn main() { fn main() {
let ProgramInput { let (
pre_states, ProgramInput {
instruction, pre_states,
} = read_nssa_inputs::<Instruction>(); instruction,
},
instruction_words,
) = read_nssa_inputs::<Instruction>();
let post_states = match instruction[0] { let post_states = match instruction[0] {
0 => { 0 => {
@ -450,7 +459,7 @@ fn main() {
_ => panic!("Invalid instruction"), _ => panic!("Invalid instruction"),
}; };
write_nssa_outputs(pre_states, post_states); write_nssa_outputs(instruction_words, pre_states, post_states);
} }
#[cfg(test)] #[cfg(test)]
@ -562,15 +571,15 @@ mod tests {
let post_states = new_definition(&pre_states, [0xca, 0xfe, 0xca, 0xfe, 0xca, 0xfe], 10); let post_states = new_definition(&pre_states, [0xca, 0xfe, 0xca, 0xfe, 0xca, 0xfe], 10);
let [definition_account, holding_account] = post_states.try_into().ok().unwrap(); let [definition_account, holding_account] = post_states.try_into().ok().unwrap();
assert_eq!( assert_eq!(
definition_account.account().data, definition_account.account().data.as_ref(),
vec![ &[
0, 0xca, 0xfe, 0xca, 0xfe, 0xca, 0xfe, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xca, 0xfe, 0xca, 0xfe, 0xca, 0xfe, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0 0, 0
] ]
); );
assert_eq!( assert_eq!(
holding_account.account().data, holding_account.account().data.as_ref(),
vec![ &[
1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0 0, 0
@ -620,7 +629,9 @@ mod tests {
AccountWithMetadata { AccountWithMetadata {
account: Account { account: Account {
// First byte should be `TOKEN_HOLDING_TYPE` for token holding accounts // First byte should be `TOKEN_HOLDING_TYPE` for token holding accounts
data: vec![invalid_type; TOKEN_HOLDING_DATA_SIZE], data: vec![invalid_type; TOKEN_HOLDING_DATA_SIZE]
.try_into()
.unwrap(),
..Account::default() ..Account::default()
}, },
is_authorized: true, is_authorized: true,
@ -642,7 +653,7 @@ mod tests {
AccountWithMetadata { AccountWithMetadata {
account: Account { account: Account {
// Data must be of exact length `TOKEN_HOLDING_DATA_SIZE` // Data must be of exact length `TOKEN_HOLDING_DATA_SIZE`
data: vec![1; TOKEN_HOLDING_DATA_SIZE - 1], data: vec![1; TOKEN_HOLDING_DATA_SIZE - 1].try_into().unwrap(),
..Account::default() ..Account::default()
}, },
is_authorized: true, is_authorized: true,
@ -664,7 +675,7 @@ mod tests {
AccountWithMetadata { AccountWithMetadata {
account: Account { account: Account {
// Data must be of exact length `TOKEN_HOLDING_DATA_SIZE` // Data must be of exact length `TOKEN_HOLDING_DATA_SIZE`
data: vec![1; TOKEN_HOLDING_DATA_SIZE + 1], data: vec![1; TOKEN_HOLDING_DATA_SIZE + 1].try_into().unwrap(),
..Account::default() ..Account::default()
}, },
is_authorized: true, is_authorized: true,
@ -685,7 +696,7 @@ mod tests {
let pre_states = vec![ let pre_states = vec![
AccountWithMetadata { AccountWithMetadata {
account: Account { account: Account {
data: vec![1; TOKEN_HOLDING_DATA_SIZE], data: vec![1; TOKEN_HOLDING_DATA_SIZE].try_into().unwrap(),
..Account::default() ..Account::default()
}, },
is_authorized: true, is_authorized: true,
@ -693,10 +704,12 @@ mod tests {
}, },
AccountWithMetadata { AccountWithMetadata {
account: Account { account: Account {
data: vec![1] data: [1]
.into_iter() .into_iter()
.chain(vec![2; TOKEN_HOLDING_DATA_SIZE - 1]) .chain(vec![2; TOKEN_HOLDING_DATA_SIZE - 1])
.collect(), .collect::<Vec<_>>()
.try_into()
.unwrap(),
..Account::default() ..Account::default()
}, },
is_authorized: true, is_authorized: true,
@ -713,10 +726,12 @@ mod tests {
AccountWithMetadata { AccountWithMetadata {
account: Account { account: Account {
// Account with balance 37 // Account with balance 37
data: vec![1; TOKEN_HOLDING_DATA_SIZE - 16] data: [1; TOKEN_HOLDING_DATA_SIZE - 16]
.into_iter() .into_iter()
.chain(u128::to_le_bytes(37)) .chain(u128::to_le_bytes(37))
.collect(), .collect::<Vec<_>>()
.try_into()
.unwrap(),
..Account::default() ..Account::default()
}, },
is_authorized: true, is_authorized: true,
@ -724,7 +739,7 @@ mod tests {
}, },
AccountWithMetadata { AccountWithMetadata {
account: Account { account: Account {
data: vec![1; TOKEN_HOLDING_DATA_SIZE], data: vec![1; TOKEN_HOLDING_DATA_SIZE].try_into().unwrap(),
..Account::default() ..Account::default()
}, },
is_authorized: true, is_authorized: true,
@ -742,10 +757,12 @@ mod tests {
AccountWithMetadata { AccountWithMetadata {
account: Account { account: Account {
// Account with balance 37 // Account with balance 37
data: vec![1; TOKEN_HOLDING_DATA_SIZE - 16] data: [1; TOKEN_HOLDING_DATA_SIZE - 16]
.into_iter() .into_iter()
.chain(u128::to_le_bytes(37)) .chain(u128::to_le_bytes(37))
.collect(), .collect::<Vec<_>>()
.try_into()
.unwrap(),
..Account::default() ..Account::default()
}, },
is_authorized: false, is_authorized: false,
@ -753,7 +770,7 @@ mod tests {
}, },
AccountWithMetadata { AccountWithMetadata {
account: Account { account: Account {
data: vec![1; TOKEN_HOLDING_DATA_SIZE], data: vec![1; TOKEN_HOLDING_DATA_SIZE].try_into().unwrap(),
..Account::default() ..Account::default()
}, },
is_authorized: true, is_authorized: true,
@ -769,10 +786,12 @@ mod tests {
AccountWithMetadata { AccountWithMetadata {
account: Account { account: Account {
// Account with balance 37 // Account with balance 37
data: vec![1; TOKEN_HOLDING_DATA_SIZE - 16] data: [1; TOKEN_HOLDING_DATA_SIZE - 16]
.into_iter() .into_iter()
.chain(u128::to_le_bytes(37)) .chain(u128::to_le_bytes(37))
.collect(), .collect::<Vec<_>>()
.try_into()
.unwrap(),
..Account::default() ..Account::default()
}, },
is_authorized: true, is_authorized: true,
@ -781,10 +800,12 @@ mod tests {
AccountWithMetadata { AccountWithMetadata {
account: Account { account: Account {
// Account with balance 255 // Account with balance 255
data: vec![1; TOKEN_HOLDING_DATA_SIZE - 16] data: [1; TOKEN_HOLDING_DATA_SIZE - 16]
.into_iter() .into_iter()
.chain(u128::to_le_bytes(255)) .chain(u128::to_le_bytes(255))
.collect(), .collect::<Vec<_>>()
.try_into()
.unwrap(),
..Account::default() ..Account::default()
}, },
is_authorized: true, is_authorized: true,
@ -794,15 +815,15 @@ mod tests {
let post_states = transfer(&pre_states, 11); let post_states = transfer(&pre_states, 11);
let [sender_post, recipient_post] = post_states.try_into().ok().unwrap(); let [sender_post, recipient_post] = post_states.try_into().ok().unwrap();
assert_eq!( assert_eq!(
sender_post.account().data, sender_post.account().data.as_ref(),
vec![ [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 1, 1, 1, 1, 1, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
] ]
); );
assert_eq!( assert_eq!(
recipient_post.account().data, recipient_post.account().data.as_ref(),
vec![ [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 10, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 1, 1, 1, 1, 1, 10, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
] ]
@ -818,7 +839,9 @@ mod tests {
data: [0; TOKEN_DEFINITION_DATA_SIZE - 16] data: [0; TOKEN_DEFINITION_DATA_SIZE - 16]
.into_iter() .into_iter()
.chain(u128::to_le_bytes(1000)) .chain(u128::to_le_bytes(1000))
.collect(), .collect::<Vec<_>>()
.try_into()
.unwrap(),
..Account::default() ..Account::default()
}, },
is_authorized: false, is_authorized: false,
@ -832,10 +855,13 @@ mod tests {
]; ];
let post_states = initialize_account(&pre_states); let post_states = initialize_account(&pre_states);
let [definition, holding] = post_states.try_into().ok().unwrap(); let [definition, holding] = post_states.try_into().ok().unwrap();
assert_eq!(definition.account().data, pre_states[0].account.data);
assert_eq!( assert_eq!(
holding.account().data, definition.account().data.as_ref(),
vec![ pre_states[0].account.data.as_ref()
);
assert_eq!(
holding.account().data.as_ref(),
[
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
] ]