mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-06-26 00:49:27 +00:00
refactor!(wallet): pass program_id instead of program in send_pub_tx()
This commit is contained in:
parent
d3e507f25d
commit
c74b03582b
@ -31,7 +31,7 @@ use tempfile::tempdir;
|
||||
use wallet::{account::HumanReadableAccount, program_facades::vault::Vault};
|
||||
use wallet_ffi::{
|
||||
FfiAccount, FfiAccountIdentity, FfiAccountList, FfiBytes32, FfiPrivateAccountKeys,
|
||||
FfiPublicAccountKey, FfiTransferResult, FfiU128, WalletHandle, error,
|
||||
FfiProgramId, FfiPublicAccountKey, FfiTransferResult, FfiU128, WalletHandle, error,
|
||||
generic_transaction::{FfiProgramWithDependencies, FfiTransactionResult},
|
||||
wallet::FfiCreateWalletOutput,
|
||||
};
|
||||
@ -234,7 +234,7 @@ unsafe extern "C" {
|
||||
account_identities_size: usize,
|
||||
instruction_words: *const u32,
|
||||
instruction_words_size: usize,
|
||||
program_with_dependencies: *const FfiProgramWithDependencies,
|
||||
program_id: FfiProgramId,
|
||||
out_result: *mut FfiTransactionResult,
|
||||
) -> error::WalletFfiError;
|
||||
|
||||
@ -1595,7 +1595,7 @@ fn test_wallet_ffi_transfer_generic_public() -> Result<()> {
|
||||
account_identities_size,
|
||||
instruction_words,
|
||||
instruction_words_size,
|
||||
&raw const program_with_dependencies,
|
||||
program_id.into(),
|
||||
&raw mut transaction_result,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@ -10,7 +10,7 @@ use crate::{
|
||||
error::{print_error, WalletFfiError},
|
||||
map_execution_error,
|
||||
wallet::get_wallet,
|
||||
FfiAccountIdentity, FfiBytes32, WalletHandle,
|
||||
FfiAccountIdentity, FfiBytes32, FfiProgramId, WalletHandle,
|
||||
};
|
||||
|
||||
#[repr(C)]
|
||||
@ -214,7 +214,7 @@ pub unsafe extern "C" fn wallet_ffi_send_generic_public_transaction(
|
||||
account_identities_size: usize,
|
||||
instruction_words: *const u32,
|
||||
instruction_words_size: usize,
|
||||
program_with_dependencies: *const FfiProgramWithDependencies,
|
||||
program_id: FfiProgramId,
|
||||
out_result: *mut FfiTransactionResult,
|
||||
) -> WalletFfiError {
|
||||
let wrapper = match get_wallet(handle) {
|
||||
@ -260,12 +260,7 @@ pub unsafe extern "C" fn wallet_ffi_send_generic_public_transaction(
|
||||
}
|
||||
}
|
||||
|
||||
let program = match unsafe { &*program_with_dependencies }.try_into() {
|
||||
Ok(v) => v,
|
||||
Err(err) => return err,
|
||||
};
|
||||
|
||||
match block_on(wallet.send_pub_tx(accounts, instruction_data.to_vec(), &program)) {
|
||||
match block_on(wallet.send_pub_tx(accounts, instruction_data.to_vec(), program_id.into())) {
|
||||
Ok(tx_hash) => {
|
||||
let tx_hash = CString::new(tx_hash.to_string())
|
||||
.map_or(std::ptr::null_mut(), std::ffi::CString::into_raw);
|
||||
|
||||
@ -7,7 +7,7 @@ use std::{
|
||||
str::FromStr as _,
|
||||
};
|
||||
|
||||
use lee::{Data, SharedSecretKey};
|
||||
use lee::{Data, ProgramId, SharedSecretKey};
|
||||
use lee_core::{encryption::MlKem768EncapsulationKey, NullifierPublicKey};
|
||||
use wallet::AccountIdentity;
|
||||
|
||||
@ -581,6 +581,18 @@ impl TryFrom<&FfiAccountIdentity> for AccountIdentity {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ProgramId> for FfiProgramId {
|
||||
fn from(value: ProgramId) -> Self {
|
||||
Self { data: value }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FfiProgramId> for ProgramId {
|
||||
fn from(value: FfiProgramId) -> Self {
|
||||
value.data
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use lee::{AccountId, PrivateKey, PublicKey};
|
||||
|
||||
@ -256,23 +256,6 @@ typedef struct FfiAccountIdentity {
|
||||
struct FfiU128 identifier;
|
||||
} FfiAccountIdentity;
|
||||
|
||||
/**
|
||||
* Intended to be created manually.
|
||||
*/
|
||||
typedef struct FfiProgram {
|
||||
const uint8_t *elf_data;
|
||||
uintptr_t elf_size;
|
||||
} FfiProgram;
|
||||
|
||||
/**
|
||||
* Intended to be created manually.
|
||||
*/
|
||||
typedef struct FfiProgramWithDependencies {
|
||||
struct FfiProgram program;
|
||||
const struct FfiProgram *deps;
|
||||
uintptr_t deps_size;
|
||||
} FfiProgramWithDependencies;
|
||||
|
||||
/**
|
||||
* Result of a generic transaction operation.
|
||||
*/
|
||||
@ -292,6 +275,23 @@ typedef struct FfiTransactionResult {
|
||||
uintptr_t secrets_size;
|
||||
} FfiTransactionResult;
|
||||
|
||||
/**
|
||||
* Intended to be created manually.
|
||||
*/
|
||||
typedef struct FfiProgram {
|
||||
const uint8_t *elf_data;
|
||||
uintptr_t elf_size;
|
||||
} FfiProgram;
|
||||
|
||||
/**
|
||||
* Intended to be created manually.
|
||||
*/
|
||||
typedef struct FfiProgramWithDependencies {
|
||||
struct FfiProgram program;
|
||||
const struct FfiProgram *deps;
|
||||
uintptr_t deps_size;
|
||||
} FfiProgramWithDependencies;
|
||||
|
||||
/**
|
||||
* Public key info for a public account.
|
||||
*/
|
||||
@ -613,7 +613,7 @@ enum WalletFfiError wallet_ffi_send_generic_public_transaction(struct WalletHand
|
||||
uintptr_t account_identities_size,
|
||||
const uint32_t *instruction_words,
|
||||
uintptr_t instruction_words_size,
|
||||
const struct FfiProgramWithDependencies *program_with_dependencies,
|
||||
struct FfiProgramId program_id,
|
||||
struct FfiTransactionResult *out_result);
|
||||
|
||||
/**
|
||||
|
||||
@ -16,7 +16,7 @@ use common::{HashType, transaction::LeeTransaction};
|
||||
use config::WalletConfig;
|
||||
use key_protocol::key_management::key_tree::chain_index::ChainIndex;
|
||||
use lee::{
|
||||
Account, AccountId, PrivacyPreservingTransaction,
|
||||
Account, AccountId, PrivacyPreservingTransaction, ProgramId,
|
||||
privacy_preserving_transaction::{
|
||||
circuit::ProgramWithDependencies, message::EncryptedAccountData,
|
||||
},
|
||||
@ -619,9 +619,9 @@ impl WalletCore {
|
||||
&self,
|
||||
accounts: Vec<AccountIdentity>,
|
||||
instruction_data: InstructionData,
|
||||
program: &ProgramWithDependencies,
|
||||
program_id: ProgramId,
|
||||
) -> Result<HashType, ExecutionFailureKind> {
|
||||
self.send_pub_tx_with_pre_check(accounts, instruction_data, program, |_| Ok(()))
|
||||
self.send_pub_tx_with_pre_check(accounts, instruction_data, program_id, |_| Ok(()))
|
||||
.await
|
||||
}
|
||||
|
||||
@ -629,7 +629,7 @@ impl WalletCore {
|
||||
&self,
|
||||
accounts: Vec<AccountIdentity>,
|
||||
instruction_data: InstructionData,
|
||||
program: &ProgramWithDependencies,
|
||||
program_id: ProgramId,
|
||||
tx_pre_check: impl FnOnce(&[&Account]) -> Result<(), ExecutionFailureKind>,
|
||||
) -> Result<HashType, ExecutionFailureKind> {
|
||||
// Public transaction, all accounts must be public
|
||||
@ -652,7 +652,6 @@ impl WalletCore {
|
||||
)?;
|
||||
|
||||
let account_ids = acc_manager.public_account_ids();
|
||||
let program_id = program.program.id();
|
||||
let nonces = acc_manager.public_account_nonces();
|
||||
|
||||
let message = lee::public_transaction::Message::new_preserialized(
|
||||
|
||||
@ -22,7 +22,6 @@ impl Amm<'_> {
|
||||
.public_account_id()
|
||||
.ok_or(ExecutionFailureKind::KeyNotFoundError)?;
|
||||
|
||||
let program = programs::amm();
|
||||
let amm_program_id = programs::amm().id();
|
||||
let user_a_acc = self
|
||||
.0
|
||||
@ -67,7 +66,7 @@ impl Amm<'_> {
|
||||
user_holding_lp,
|
||||
],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
amm_program_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
@ -87,7 +86,6 @@ impl Amm<'_> {
|
||||
.public_account_id()
|
||||
.ok_or(ExecutionFailureKind::KeyNotFoundError)?;
|
||||
|
||||
let program = programs::amm();
|
||||
let amm_program_id = programs::amm().id();
|
||||
let user_a_acc = self
|
||||
.0
|
||||
@ -149,7 +147,7 @@ impl Amm<'_> {
|
||||
user_b_signing_identity,
|
||||
],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
amm_program_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
@ -169,7 +167,6 @@ impl Amm<'_> {
|
||||
.public_account_id()
|
||||
.ok_or(ExecutionFailureKind::KeyNotFoundError)?;
|
||||
|
||||
let program = programs::amm();
|
||||
let amm_program_id = programs::amm().id();
|
||||
let user_a_acc = self
|
||||
.0
|
||||
@ -231,7 +228,7 @@ impl Amm<'_> {
|
||||
user_b_signing_identity,
|
||||
],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
amm_program_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
@ -252,7 +249,6 @@ impl Amm<'_> {
|
||||
.public_account_id()
|
||||
.ok_or(ExecutionFailureKind::KeyNotFoundError)?;
|
||||
|
||||
let program = programs::amm();
|
||||
let amm_program_id = programs::amm().id();
|
||||
let user_a_acc = self
|
||||
.0
|
||||
@ -297,7 +293,7 @@ impl Amm<'_> {
|
||||
user_holding_lp,
|
||||
],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
amm_program_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
@ -311,7 +307,6 @@ impl Amm<'_> {
|
||||
min_amount_to_remove_token_a: u128,
|
||||
min_amount_to_remove_token_b: u128,
|
||||
) -> Result<HashType, ExecutionFailureKind> {
|
||||
let program = programs::amm();
|
||||
let amm_program_id = programs::amm().id();
|
||||
let user_a_acc = self
|
||||
.0
|
||||
@ -356,7 +351,7 @@ impl Amm<'_> {
|
||||
user_holding_lp,
|
||||
],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
amm_program_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@ -21,8 +21,7 @@ impl Ata<'_> {
|
||||
.public_account_id()
|
||||
.ok_or(ExecutionFailureKind::KeyNotFoundError)?;
|
||||
|
||||
let program = programs::ata();
|
||||
let ata_program_id = program.id();
|
||||
let ata_program_id = programs::ata().id();
|
||||
let ata_id = get_associated_token_account_id(
|
||||
&ata_program_id,
|
||||
&compute_ata_seed(owner_id, definition_id),
|
||||
@ -39,7 +38,7 @@ impl Ata<'_> {
|
||||
AccountIdentity::PublicNoSign(ata_id),
|
||||
],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
ata_program_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
@ -55,8 +54,7 @@ impl Ata<'_> {
|
||||
.public_account_id()
|
||||
.ok_or(ExecutionFailureKind::KeyNotFoundError)?;
|
||||
|
||||
let program = programs::ata();
|
||||
let ata_program_id = program.id();
|
||||
let ata_program_id = programs::ata().id();
|
||||
let sender_ata_id = get_associated_token_account_id(
|
||||
&ata_program_id,
|
||||
&compute_ata_seed(owner_id, definition_id),
|
||||
@ -76,7 +74,7 @@ impl Ata<'_> {
|
||||
AccountIdentity::PublicNoSign(recipient_id),
|
||||
],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
ata_program_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
@ -91,8 +89,7 @@ impl Ata<'_> {
|
||||
.public_account_id()
|
||||
.ok_or(ExecutionFailureKind::KeyNotFoundError)?;
|
||||
|
||||
let program = programs::ata();
|
||||
let ata_program_id = program.id();
|
||||
let ata_program_id = programs::ata().id();
|
||||
let holder_ata_id = get_associated_token_account_id(
|
||||
&ata_program_id,
|
||||
&compute_ata_seed(owner_id, definition_id),
|
||||
@ -112,7 +109,7 @@ impl Ata<'_> {
|
||||
AccountIdentity::PublicNoSign(definition_id),
|
||||
],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
ata_program_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@ -12,7 +12,6 @@ impl Bridge<'_> {
|
||||
amount: u64,
|
||||
bedrock_account_pk: [u8; 32],
|
||||
) -> Result<HashType, ExecutionFailureKind> {
|
||||
let program = programs::bridge();
|
||||
let bridge_account_id = system_accounts::bridge_account_id();
|
||||
let instruction = bridge_core::Instruction::Withdraw {
|
||||
amount,
|
||||
@ -28,7 +27,7 @@ impl Bridge<'_> {
|
||||
AccountIdentity::PublicNoSign(bridge_account_id),
|
||||
],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
programs::bridge().id(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@ -26,7 +26,6 @@ fn auth_transfer_preparation(
|
||||
amount: balance_to_move,
|
||||
})
|
||||
.unwrap();
|
||||
let program = programs::authenticated_transfer();
|
||||
|
||||
// TODO: handle large Err-variant properly
|
||||
let tx_pre_check = move |accounts: &[&Account]| {
|
||||
@ -38,5 +37,9 @@ fn auth_transfer_preparation(
|
||||
}
|
||||
};
|
||||
|
||||
(instruction_data, program, tx_pre_check)
|
||||
(
|
||||
instruction_data,
|
||||
programs::authenticated_transfer(),
|
||||
tx_pre_check,
|
||||
)
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ impl NativeTokenTransfer<'_> {
|
||||
.send_pub_tx_with_pre_check(
|
||||
vec![from, to],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
program.id(),
|
||||
tx_pre_check,
|
||||
)
|
||||
.await
|
||||
@ -31,11 +31,14 @@ impl NativeTokenTransfer<'_> {
|
||||
&self,
|
||||
account: AccountIdentity,
|
||||
) -> Result<HashType, ExecutionFailureKind> {
|
||||
let program = programs::authenticated_transfer();
|
||||
let instruction_data = Program::serialize_instruction(AuthTransferInstruction::Initialize)?;
|
||||
|
||||
self.0
|
||||
.send_pub_tx(vec![account], instruction_data, &program.into())
|
||||
.send_pub_tx(
|
||||
vec![account],
|
||||
instruction_data,
|
||||
programs::authenticated_transfer().id(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,6 @@ impl Pinata<'_> {
|
||||
winner_account_id: AccountId,
|
||||
solution: u128,
|
||||
) -> Result<HashType, ExecutionFailureKind> {
|
||||
let program = programs::pinata();
|
||||
let instruction = solution;
|
||||
let instruction_data =
|
||||
Program::serialize_instruction(instruction).expect("Instruction should serialize");
|
||||
@ -25,7 +24,7 @@ impl Pinata<'_> {
|
||||
AccountIdentity::PublicNoSign(winner_account_id),
|
||||
],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
programs::pinata().id(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@ -15,13 +15,16 @@ impl Token<'_> {
|
||||
name: String,
|
||||
total_supply: u128,
|
||||
) -> Result<HashType, ExecutionFailureKind> {
|
||||
let program = programs::token();
|
||||
let instruction = Instruction::NewFungibleDefinition { name, total_supply };
|
||||
let instruction_data =
|
||||
Program::serialize_instruction(instruction).expect("Instruction should serialize");
|
||||
|
||||
self.0
|
||||
.send_pub_tx(vec![definition, supply], instruction_data, &program.into())
|
||||
.send_pub_tx(
|
||||
vec![definition, supply],
|
||||
instruction_data,
|
||||
programs::token().id(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@ -128,7 +131,6 @@ impl Token<'_> {
|
||||
recipient: AccountIdentity,
|
||||
amount: u128,
|
||||
) -> Result<HashType, ExecutionFailureKind> {
|
||||
let program = programs::token();
|
||||
let instruction = Instruction::Transfer {
|
||||
amount_to_transfer: amount,
|
||||
};
|
||||
@ -136,7 +138,11 @@ impl Token<'_> {
|
||||
Program::serialize_instruction(instruction).expect("Instruction should serialize");
|
||||
|
||||
self.0
|
||||
.send_pub_tx(vec![sender, recipient], instruction_data, &program.into())
|
||||
.send_pub_tx(
|
||||
vec![sender, recipient],
|
||||
instruction_data,
|
||||
programs::token().id(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
@ -319,7 +325,6 @@ impl Token<'_> {
|
||||
holder: AccountIdentity,
|
||||
amount: u128,
|
||||
) -> Result<HashType, ExecutionFailureKind> {
|
||||
let program = programs::token();
|
||||
let instruction = Instruction::Burn {
|
||||
amount_to_burn: amount,
|
||||
};
|
||||
@ -330,7 +335,7 @@ impl Token<'_> {
|
||||
.send_pub_tx(
|
||||
vec![AccountIdentity::PublicNoSign(definition_account_id), holder],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
programs::token().id(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
@ -441,7 +446,6 @@ impl Token<'_> {
|
||||
holder: AccountIdentity,
|
||||
amount: u128,
|
||||
) -> Result<HashType, ExecutionFailureKind> {
|
||||
let program = programs::token();
|
||||
let instruction = Instruction::Mint {
|
||||
amount_to_mint: amount,
|
||||
};
|
||||
@ -449,7 +453,11 @@ impl Token<'_> {
|
||||
Program::serialize_instruction(instruction).expect("Instruction should serialize");
|
||||
|
||||
self.0
|
||||
.send_pub_tx(vec![definition, holder], instruction_data, &program.into())
|
||||
.send_pub_tx(
|
||||
vec![definition, holder],
|
||||
instruction_data,
|
||||
programs::token().id(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
|
||||
@ -17,8 +17,7 @@ impl Vault<'_> {
|
||||
recipient_id: AccountId,
|
||||
amount: u128,
|
||||
) -> Result<HashType, ExecutionFailureKind> {
|
||||
let program = programs::vault();
|
||||
let vault_program_id = program.id();
|
||||
let vault_program_id = programs::vault().id();
|
||||
let recipient_vault_id =
|
||||
vault_core::compute_vault_account_id(vault_program_id, recipient_id);
|
||||
|
||||
@ -36,7 +35,7 @@ impl Vault<'_> {
|
||||
AccountIdentity::PublicNoSign(recipient_vault_id),
|
||||
],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
vault_program_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
@ -80,8 +79,7 @@ impl Vault<'_> {
|
||||
owner_id: AccountId,
|
||||
amount: u128,
|
||||
) -> Result<HashType, ExecutionFailureKind> {
|
||||
let program = programs::vault();
|
||||
let vault_program_id = program.id();
|
||||
let vault_program_id = programs::vault().id();
|
||||
let owner_vault_id = vault_core::compute_vault_account_id(vault_program_id, owner_id);
|
||||
|
||||
let instruction = vault_core::Instruction::Claim { amount };
|
||||
@ -95,7 +93,7 @@ impl Vault<'_> {
|
||||
AccountIdentity::PublicNoSign(owner_vault_id),
|
||||
],
|
||||
instruction_data,
|
||||
&program.into(),
|
||||
vault_program_id,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user