Make message a signer in CPI, improve attest ix signature

Change-Id: I5136a62d5b0b7617b4dc3e3e2a17614a68908f3f
This commit is contained in:
Hendrik Hofstadt 2021-08-09 19:04:09 +02:00
parent eb457f9e1e
commit fae219e427
8 changed files with 60 additions and 68 deletions

View File

@ -79,7 +79,7 @@ pub struct AttestToken<'b> {
pub bridge: Mut<Info<'b>>,
/// Account to store the posted message
pub message: Mut<Info<'b>>,
pub message: Signer<Mut<Info<'b>>>,
/// Emitter of the VAA
pub emitter: EmitterAccount<'b>,
@ -172,7 +172,7 @@ pub fn attest_token(
params.try_to_vec()?.as_slice(),
vec![
AccountMeta::new(*accs.bridge.key, false),
AccountMeta::new(*accs.message.key, false),
AccountMeta::new(*accs.message.key, true),
AccountMeta::new_readonly(*accs.emitter.key, true),
AccountMeta::new(*accs.sequence.key, false),
AccountMeta::new(*accs.payer.key, true),

View File

@ -83,7 +83,7 @@ pub struct TransferNative<'b> {
pub bridge: Mut<Info<'b>>,
/// Account to store the posted message
pub message: Mut<Info<'b>>,
pub message: Signer<Mut<Info<'b>>>,
/// Emitter of the VAA
pub emitter: EmitterAccount<'b>,
@ -191,7 +191,7 @@ pub fn transfer_native(
params.try_to_vec()?.as_slice(),
vec![
AccountMeta::new(*accs.bridge.key, false),
AccountMeta::new(*accs.message.key, false),
AccountMeta::new(*accs.message.key, true),
AccountMeta::new_readonly(*accs.emitter.key, true),
AccountMeta::new(*accs.sequence.key, false),
AccountMeta::new(*accs.payer.key, true),
@ -222,7 +222,7 @@ pub struct TransferWrapped<'b> {
pub bridge: Mut<Info<'b>>,
/// Account to store the posted message
pub message: Mut<Info<'b>>,
pub message: Signer<Mut<Info<'b>>>,
/// Emitter of the VAA
pub emitter: EmitterAccount<'b>,
@ -324,7 +324,7 @@ pub fn transfer_wrapped(
params.try_to_vec()?.as_slice(),
vec![
AccountMeta::new(*accs.bridge.key, false),
AccountMeta::new(*accs.message.key, false),
AccountMeta::new(*accs.message.key, true),
AccountMeta::new_readonly(*accs.emitter.key, true),
AccountMeta::new(*accs.sequence.key, false),
AccountMeta::new(*accs.payer.key, true),

View File

@ -448,7 +448,6 @@ pub fn attest(
payer: Pubkey,
message_key: Pubkey,
mint: Pubkey,
decimals: u8,
nonce: u32,
) -> solitaire::Result<Instruction> {
let config_key = ConfigAccount::<'_, { AccountState::Uninitialized }>::key(None, &program_id);
@ -462,9 +461,7 @@ pub fn attest(
// Mint Metadata
let mint_meta = WrappedTokenMeta::<'_, { AccountState::Uninitialized }>::key(
&WrappedMetaDerivationData {
mint_key: mint,
},
&WrappedMetaDerivationData { mint_key: mint },
&bridge_id,
);

View File

@ -57,7 +57,6 @@ pub fn attest_ix(
payer: String,
message: String,
mint: String,
decimals: u8,
nonce: u32,
) -> JsValue {
let program_id = Pubkey::from_str(program_id.as_str()).unwrap();
@ -66,16 +65,7 @@ pub fn attest_ix(
let message = Pubkey::from_str(message.as_str()).unwrap();
let mint = Pubkey::from_str(mint.as_str()).unwrap();
let ix = attest(
program_id,
bridge_id,
payer,
message,
mint,
decimals,
nonce,
)
.unwrap();
let ix = attest(program_id, bridge_id, payer, message, mint, nonce).unwrap();
JsValue::from_serde(&ix).unwrap()
}

View File

@ -168,7 +168,10 @@ mod helpers {
}
/// Fetch account data, the loop is there to re-attempt until data is available.
pub fn get_account_data<T: BorshDeserialize>(client: &RpcClient, account: &Pubkey) -> Option<T> {
pub fn get_account_data<T: BorshDeserialize>(
client: &RpcClient,
account: &Pubkey,
) -> Option<T> {
let account = client
.get_account_with_commitment(account, CommitmentConfig::processed())
.unwrap();
@ -516,23 +519,21 @@ mod helpers {
client,
payer,
&[payer, mint_authority],
&[
spl_token_metadata::instruction::create_metadata_accounts(
spl_token_metadata::id(),
*metadata_account,
mint.pubkey(),
mint_authority.pubkey(),
payer.pubkey(),
*update_authority,
name,
symbol,
"https://token.org".to_string(),
None,
0,
false,
false,
)
],
&[spl_token_metadata::instruction::create_metadata_accounts(
spl_token_metadata::id(),
*metadata_account,
mint.pubkey(),
mint_authority.pubkey(),
payer.pubkey(),
*update_authority,
name,
symbol,
"https://token.org".to_string(),
None,
0,
false,
false,
)],
CommitmentConfig::processed(),
)
}

View File

@ -1,13 +1,21 @@
use {
crate::{
state::{Creator, Data, EDITION, EDITION_MARKER_BIT_SIZE, PREFIX},
},
borsh::{BorshDeserialize, BorshSerialize},
solana_program::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
sysvar,
use crate::state::{
Creator,
Data,
EDITION,
EDITION_MARKER_BIT_SIZE,
PREFIX,
};
use borsh::{
BorshDeserialize,
BorshSerialize,
};
use solana_program::{
instruction::{
AccountMeta,
Instruction,
},
pubkey::Pubkey,
sysvar,
};
#[repr(C)]

View File

@ -1,6 +1,4 @@
use crate::{
utils::try_from_slice_checked,
};
use crate::utils::try_from_slice_checked;
use borsh::{
BorshDeserialize,
BorshSerialize,

View File

@ -1,20 +1,18 @@
use crate::{
state::{
Data,
Key,
Metadata,
EDITION,
EDITION_MARKER_BIT_SIZE,
MAX_CREATOR_LIMIT,
MAX_EDITION_LEN,
MAX_EDITION_MARKER_SIZE,
MAX_MASTER_EDITION_LEN,
MAX_METADATA_LEN,
MAX_NAME_LENGTH,
MAX_SYMBOL_LENGTH,
MAX_URI_LENGTH,
PREFIX,
},
use crate::state::{
Data,
Key,
Metadata,
EDITION,
EDITION_MARKER_BIT_SIZE,
MAX_CREATOR_LIMIT,
MAX_EDITION_LEN,
MAX_EDITION_MARKER_SIZE,
MAX_MASTER_EDITION_LEN,
MAX_METADATA_LEN,
MAX_NAME_LENGTH,
MAX_SYMBOL_LENGTH,
MAX_URI_LENGTH,
PREFIX,
};
use borsh::{
BorshDeserialize,