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

View File

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

View File

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

View File

@ -57,7 +57,6 @@ pub fn attest_ix(
payer: String, payer: String,
message: String, message: String,
mint: String, mint: String,
decimals: u8,
nonce: u32, nonce: u32,
) -> JsValue { ) -> JsValue {
let program_id = Pubkey::from_str(program_id.as_str()).unwrap(); 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 message = Pubkey::from_str(message.as_str()).unwrap();
let mint = Pubkey::from_str(mint.as_str()).unwrap(); let mint = Pubkey::from_str(mint.as_str()).unwrap();
let ix = attest( let ix = attest(program_id, bridge_id, payer, message, mint, nonce).unwrap();
program_id,
bridge_id,
payer,
message,
mint,
decimals,
nonce,
)
.unwrap();
JsValue::from_serde(&ix).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. /// 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 let account = client
.get_account_with_commitment(account, CommitmentConfig::processed()) .get_account_with_commitment(account, CommitmentConfig::processed())
.unwrap(); .unwrap();
@ -516,23 +519,21 @@ mod helpers {
client, client,
payer, payer,
&[payer, mint_authority], &[payer, mint_authority],
&[ &[spl_token_metadata::instruction::create_metadata_accounts(
spl_token_metadata::instruction::create_metadata_accounts( spl_token_metadata::id(),
spl_token_metadata::id(), *metadata_account,
*metadata_account, mint.pubkey(),
mint.pubkey(), mint_authority.pubkey(),
mint_authority.pubkey(), payer.pubkey(),
payer.pubkey(), *update_authority,
*update_authority, name,
name, symbol,
symbol, "https://token.org".to_string(),
"https://token.org".to_string(), None,
None, 0,
0, false,
false, false,
false, )],
)
],
CommitmentConfig::processed(), CommitmentConfig::processed(),
) )
} }

View File

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

View File

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

View File

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