accountant: export governance modules from sdk to double check in contract

This commit is contained in:
Conor Patrick 2023-03-15 16:55:12 +00:00
parent 6324a239f9
commit 26839604c8
4 changed files with 28 additions and 25 deletions

View File

@ -334,14 +334,21 @@ fn handle_vaa(
let mut evt = if body.emitter_chain == Chain::Solana
&& body.emitter_address == wormhole::GOVERNANCE_EMITTER
{
if let Ok(govpacket) = serde_wormhole::from_slice::<token::GovernancePacket>(body.payload) {
if body.payload.len() < 32 {
bail!("governance module missing");
}
let module = &body.payload[..32];
if module == token::MODULE {
let govpacket = serde_wormhole::from_slice(body.payload)
.context("failed to parse tokenbridge governance packet")?;
handle_token_governance_vaa(deps.branch(), body.with_payload(govpacket))?
} else if let Ok(govpacket) =
serde_wormhole::from_slice::<accountant_module::GovernancePacket>(body.payload)
{
} else if module == accountant_module::MODULE {
let govpacket = serde_wormhole::from_slice(body.payload)
.context("failed to parse accountant governance packet")?;
handle_accountant_governance_vaa(deps.branch(), info, body.with_payload(govpacket))?
} else {
bail!("Unknown governance module")
bail!("unknown governance module")
}
} else {
let msg = serde_wormhole::from_slice(body.payload)

View File

@ -54,7 +54,7 @@ impl<'de> Deserialize<'de> for ModificationKind {
}
}
/// Represents a governance action targeted at the NFT bridge.
/// Represents a governance action targeted at the Accountant.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Action {
// Modify balance for accountant
@ -71,7 +71,7 @@ pub enum Action {
},
}
/// Represents the payload for a governance VAA targeted at the NFT bridge.
/// Represents the payload for a governance VAA targeted at the Accountant.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct GovernancePacket {
/// The chain on which the governance action should be carried out.
@ -81,6 +81,10 @@ pub struct GovernancePacket {
pub action: Action,
}
// MODULE = "GlobalAccountant"
pub const MODULE: [u8; 32] =
*b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00GlobalAccountant";
// The wire format for GovernancePackets is wonky and doesn't lend itself well to auto-deriving
// Serialize / Deserialize so we implement it manually here.
mod governance_packet_impl {
@ -93,14 +97,10 @@ mod governance_packet_impl {
};
use crate::{
accountant::{Action, GovernancePacket},
accountant::{Action, GovernancePacket, MODULE},
Address, Amount,
};
// MODULE = "GlobalAccountant"
const MODULE: [u8; 32] =
*b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00GlobalAccountant";
struct Module;
impl Serialize for Module {
@ -123,7 +123,7 @@ mod governance_packet_impl {
Ok(Module)
} else {
Err(Error::custom(
"invalid governance module, expected \"NFTBridge\"",
"invalid governance module, expected \"GlobalAccountant\"",
))
}
}

View File

@ -78,6 +78,9 @@ pub struct GovernancePacket {
pub action: Action,
}
// MODULE = "NFTBridge"
pub const MODULE: [u8; 32] = *b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00NFTBridge";
// The wire format for GovernancePackets is wonky and doesn't lend itself well to auto-deriving
// Serialize / Deserialize so we implement it manually here.
mod governance_packet_impl {
@ -90,17 +93,10 @@ mod governance_packet_impl {
};
use crate::{
nft::{Action, GovernancePacket},
nft::{Action, GovernancePacket, MODULE},
Address, Chain,
};
// MODULE = "NFTBridge"
const MODULE: [u8; 32] = [
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4e, 0x46, 0x54, 0x42, 0x72, 0x69, 0x64,
0x67, 0x65,
];
struct Module;
impl Serialize for Module {

View File

@ -228,6 +228,9 @@ pub struct GovernancePacket {
pub action: Action,
}
// MODULE = "TokenBridge"
pub const MODULE: [u8; 32] = *b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00TokenBridge";
// The wire format for GovernancePackets is wonky and doesn't lend itself well to auto-deriving
// Serialize / Deserialize so we implement it manually here.
mod governance_packet_impl {
@ -240,13 +243,10 @@ mod governance_packet_impl {
};
use crate::{
token::{Action, GovernancePacket},
token::{Action, GovernancePacket, MODULE},
Address, Chain,
};
// MODULE = "TokenBridge"
const MODULE: [u8; 32] = *b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00TokenBridge";
struct Module;
impl Serialize for Module {