Resolve warnings in the NFT bridge

Change-Id: I6d5e5a7d66e8e35418eaf9346c53b3439314c9c5
This commit is contained in:
Hendrik Hofstadt 2021-09-20 12:22:13 +02:00
parent 6cb244ba83
commit 371c9b3dcc
8 changed files with 39 additions and 104 deletions

View File

@ -2,10 +2,6 @@ use crate::types::*;
use bridge::{
accounts::BridgeData,
api::ForeignAddress,
vaa::{
DeserializePayload,
PayloadMessage,
},
};
use primitive_types::U256;
use solana_program::pubkey::Pubkey;
@ -18,28 +14,28 @@ pub type AuthoritySigner<'b> = Derive<Info<'b>, "authority_signer">;
pub type CustodySigner<'b> = Derive<Info<'b>, "custody_signer">;
pub type MintSigner<'b> = Derive<Info<'b>, "mint_signer">;
pub type CoreBridge<'a, const State: AccountState> = Data<'a, BridgeData, { State }>;
pub type CoreBridge<'a, const STATE: AccountState> = Data<'a, BridgeData, { STATE }>;
pub type EmitterAccount<'b> = Derive<Info<'b>, "emitter">;
pub type ConfigAccount<'b, const State: AccountState> =
Derive<Data<'b, Config, { State }>, "config">;
pub type ConfigAccount<'b, const STATE: AccountState> =
Derive<Data<'b, Config, { STATE }>, "config">;
pub type CustodyAccount<'b, const State: AccountState> = Data<'b, SplAccount, { State }>;
pub type CustodyAccount<'b, const STATE: AccountState> = Data<'b, SplAccount, { STATE }>;
pub struct CustodyAccountDerivationData {
pub mint: Pubkey,
}
impl<'b, const State: AccountState> Seeded<&CustodyAccountDerivationData>
for CustodyAccount<'b, { State }>
impl<'b, const STATE: AccountState> Seeded<&CustodyAccountDerivationData>
for CustodyAccount<'b, { STATE }>
{
fn seeds(accs: &CustodyAccountDerivationData) -> Vec<Vec<u8>> {
vec![accs.mint.to_bytes().to_vec()]
}
}
pub type WrappedMint<'b, const State: AccountState> = Data<'b, SplMint, { State }>;
pub type WrappedMint<'b, const STATE: AccountState> = Data<'b, SplMint, { STATE }>;
pub struct WrappedDerivationData {
pub token_chain: ChainID,
@ -47,7 +43,7 @@ pub struct WrappedDerivationData {
pub token_id: U256,
}
impl<'b, const State: AccountState> Seeded<&WrappedDerivationData> for WrappedMint<'b, { State }> {
impl<'b, const STATE: AccountState> Seeded<&WrappedDerivationData> for WrappedMint<'b, { STATE }> {
fn seeds(data: &WrappedDerivationData) -> Vec<Vec<u8>> {
let mut token_id = vec![0u8; 32];
data.token_id.to_big_endian(&mut token_id);
@ -60,14 +56,14 @@ impl<'b, const State: AccountState> Seeded<&WrappedDerivationData> for WrappedMi
}
}
pub type WrappedTokenMeta<'b, const State: AccountState> = Data<'b, WrappedMeta, { State }>;
pub type WrappedTokenMeta<'b, const STATE: AccountState> = Data<'b, WrappedMeta, { STATE }>;
pub struct WrappedMetaDerivationData {
pub mint_key: Pubkey,
}
impl<'b, const State: AccountState> Seeded<&WrappedMetaDerivationData>
for WrappedTokenMeta<'b, { State }>
impl<'b, const STATE: AccountState> Seeded<&WrappedMetaDerivationData>
for WrappedTokenMeta<'b, { STATE }>
{
fn seeds(data: &WrappedMetaDerivationData) -> Vec<Vec<u8>> {
vec![
@ -78,7 +74,7 @@ impl<'b, const State: AccountState> Seeded<&WrappedMetaDerivationData>
}
/// Registered chain endpoint
pub type Endpoint<'b, const State: AccountState> = Data<'b, EndpointRegistration, { State }>;
pub type Endpoint<'b, const STATE: AccountState> = Data<'b, EndpointRegistration, { STATE }>;
pub struct EndpointDerivationData {
pub emitter_chain: u16,
@ -86,7 +82,7 @@ pub struct EndpointDerivationData {
}
/// Seeded implementation based on an incoming VAA
impl<'b, const State: AccountState> Seeded<&EndpointDerivationData> for Endpoint<'b, { State }> {
impl<'b, const STATE: AccountState> Seeded<&EndpointDerivationData> for Endpoint<'b, { STATE }> {
fn seeds(data: &EndpointDerivationData) -> Vec<Vec<u8>> {
vec![
data.emitter_chain.to_be_bytes().to_vec(),

View File

@ -28,8 +28,6 @@ use solana_program::{
invoke,
invoke_signed,
},
program_error::ProgramError,
pubkey::Pubkey,
};
use solitaire::{
processors::seeded::{
@ -39,14 +37,6 @@ use solitaire::{
CreationLamports::Exempt,
*,
};
use spl_token::state::{
Account,
Mint,
};
use std::ops::{
Deref,
DerefMut,
};
#[derive(FromAccounts)]
pub struct CompleteNative<'b> {
@ -81,7 +71,8 @@ impl<'a> From<&CompleteNative<'a>> for CustodyAccountDerivationData {
}
}
impl<'b> InstructionContext<'b> for CompleteNative<'b> {}
impl<'b> InstructionContext<'b> for CompleteNative<'b> {
}
#[derive(BorshDeserialize, BorshSerialize, Default)]
pub struct CompleteNativeData {}
@ -89,7 +80,7 @@ pub struct CompleteNativeData {}
pub fn complete_native(
ctx: &ExecutionContext,
accs: &mut CompleteNative,
data: CompleteNativeData,
_data: CompleteNativeData,
) -> Result<()> {
// Verify the chain registration
let derivation_data: EndpointDerivationData = (&*accs).into();
@ -205,7 +196,8 @@ impl<'a> From<&CompleteWrapped<'a>> for WrappedMetaDerivationData {
}
}
impl<'b> InstructionContext<'b> for CompleteWrapped<'b> {}
impl<'b> InstructionContext<'b> for CompleteWrapped<'b> {
}
#[derive(BorshDeserialize, BorshSerialize, Default)]
pub struct CompleteWrappedData {}
@ -213,7 +205,7 @@ pub struct CompleteWrappedData {}
pub fn complete_wrapped(
ctx: &ExecutionContext,
accs: &mut CompleteWrapped,
data: CompleteWrappedData,
_data: CompleteWrappedData,
) -> Result<()> {
use bstr::ByteSlice;
@ -239,7 +231,7 @@ pub fn complete_wrapped(
if !accs.meta.is_initialized() {
// Create mint account
accs.mint
.create(&((&*accs).into()), ctx, accs.payer.key, Exempt);
.create(&((&*accs).into()), ctx, accs.payer.key, Exempt)?;
// Initialize mint
let init_ix = spl_token::instruction::initialize_mint(
@ -253,7 +245,7 @@ pub fn complete_wrapped(
// Create meta account
accs.meta
.create(&((&*accs).into()), ctx, accs.payer.key, Exempt);
.create(&((&*accs).into()), ctx, accs.payer.key, Exempt)?;
// Initialize spl meta
accs.spl_metadata.verify_derivation(

View File

@ -8,7 +8,6 @@ use crate::{
GovernancePayloadUpgrade,
PayloadGovernanceRegisterChain,
},
types::*,
TokenBridgeError::{
InvalidChain,
InvalidGovernanceKey,
@ -18,14 +17,12 @@ use bridge::{
vaa::{
ClaimableVAA,
DeserializePayload,
PayloadMessage,
},
CHAIN_ID_SOLANA,
};
use solana_program::{
account_info::AccountInfo,
program::invoke_signed,
program_error::ProgramError,
pubkey::Pubkey,
sysvar::{
clock::Clock,
@ -37,10 +34,6 @@ use solitaire::{
CreationLamports::Exempt,
*,
};
use std::ops::{
Deref,
DerefMut,
};
// Confirm that a ClaimableVAA came from the correct chain, signed by the right emitter.
fn verify_governance<'a, T>(vaa: &ClaimableVAA<'a, T>) -> Result<()>
@ -151,7 +144,7 @@ pub struct RegisterChainData {}
pub fn register_chain(
ctx: &ExecutionContext,
accs: &mut RegisterChain,
data: RegisterChainData,
_data: RegisterChainData,
) -> Result<()> {
let derivation_data: EndpointDerivationData = (&*accs).into();
accs.endpoint
@ -168,7 +161,7 @@ pub fn register_chain(
// Create endpoint
accs.endpoint
.create(&((&*accs).into()), ctx, accs.payer.key, Exempt);
.create(&((&*accs).into()), ctx, accs.payer.key, Exempt)?;
accs.endpoint.chain = accs.vaa.chain;
accs.endpoint.contract = accs.vaa.endpoint_address;

View File

@ -1,21 +1,12 @@
use crate::{
accounts::ConfigAccount,
types::*,
};
use crate::accounts::ConfigAccount;
use solana_program::{
account_info::AccountInfo,
msg,
program_error::ProgramError,
pubkey::Pubkey,
};
use solitaire::{
CreationLamports::Exempt,
*,
};
use std::ops::{
Deref,
DerefMut,
};
#[derive(FromAccounts)]
pub struct Initialize<'b> {

View File

@ -10,7 +10,6 @@ use crate::{
MintSigner,
SplTokenMeta,
SplTokenMetaDerivationData,
WrappedDerivationData,
WrappedMetaDerivationData,
WrappedMint,
WrappedTokenMeta,
@ -25,11 +24,7 @@ use crate::{
},
};
use bridge::{
accounts::Bridge,
api::{
PostMessage,
PostMessageData,
},
api::PostMessageData,
types::ConsistencyLevel,
vaa::SerializePayload,
};
@ -44,9 +39,7 @@ use solana_program::{
invoke,
invoke_signed,
},
program_error::ProgramError,
program_option::COption,
pubkey::Pubkey,
sysvar::clock::Clock,
};
use solitaire::{
@ -57,18 +50,7 @@ use solitaire::{
CreationLamports::Exempt,
*,
};
use spl_token::{
error::TokenError::OwnerMismatch,
state::{
Account,
Mint,
},
};
use spl_token_metadata::state::Metadata;
use std::ops::{
Deref,
DerefMut,
};
#[derive(FromAccounts)]
pub struct TransferNative<'b> {

View File

@ -1,6 +1,6 @@
#![feature(const_generics)]
#![allow(warnings)]
#![allow(incomplete_features)]
#![deny(unused_must_use)]
// #![cfg(all(target_arch = "bpf", not(feature = "no-entrypoint")))]
#[cfg(feature = "no-entrypoint")]
@ -44,7 +44,6 @@ pub use api::{
};
use solitaire::*;
use std::error::Error;
pub enum TokenBridgeError {
AlreadyExecuted,

View File

@ -1,13 +1,6 @@
use crate::{
types::{
Address,
ChainID,
},
TokenBridgeError,
};
use borsh::{
BorshDeserialize,
BorshSerialize,
use crate::types::{
Address,
ChainID,
};
use bridge::{
vaa::{
@ -24,23 +17,14 @@ use byteorder::{
};
use primitive_types::U256;
use solana_program::{
native_token::Sol,
program_error::{
ProgramError,
ProgramError::InvalidAccountData,
},
program_error::ProgramError::InvalidAccountData,
pubkey::Pubkey,
};
use solitaire::SolitaireError;
use std::{
error::Error,
io::{
Cursor,
Read,
Write,
},
str::Utf8Error,
string::FromUtf8Error,
use std::io::{
Cursor,
Read,
Write,
};
pub const MODULE: &str = "NFTBridge";
@ -140,13 +124,13 @@ impl SerializePayload for PayloadTransfer {
for i in 0..self.symbol.len() {
symbol[i] = self.symbol.as_bytes()[i];
}
writer.write(&symbol);
writer.write(&symbol)?;
let mut name: [u8; 32] = [0; 32];
for i in 0..self.name.len() {
name[i] = self.name.as_bytes()[i];
}
writer.write(&name);
writer.write(&name)?;
let mut id_data: [u8; 32] = [0; 32];
self.token_id.to_big_endian(&mut id_data);
@ -206,7 +190,7 @@ where
Self: SerializeGovernancePayload,
{
fn serialize<W: Write>(&self, writer: &mut W) -> Result<(), SolitaireError> {
self.write_governance_header(writer);
self.write_governance_header(writer)?;
// Payload ID
writer.write_u16::<BigEndian>(self.chain)?;
writer.write(&self.endpoint_address[..])?;
@ -223,7 +207,7 @@ pub struct GovernancePayloadUpgrade {
impl SerializePayload for GovernancePayloadUpgrade {
fn serialize<W: Write>(&self, v: &mut W) -> std::result::Result<(), SolitaireError> {
self.write_governance_header(v);
self.write_governance_header(v)?;
v.write(&self.new_contract.to_bytes())?;
Ok(())
}

View File

@ -2,7 +2,6 @@ use borsh::{
BorshDeserialize,
BorshSerialize,
};
use primitive_types::U256;
use serde::{
Deserialize,
Serialize,
@ -19,7 +18,6 @@ use spl_token::state::{
Account,
Mint,
};
use spl_token_metadata::state::Metadata;
pub type Address = [u8; 32];
pub type ChainID = u16;