sdk/rust: shared accountant ModificationKind
This commit is contained in:
parent
7539c1d1d8
commit
dbc1bf6955
|
@ -18,7 +18,9 @@ use serde_wormhole::RawMessage;
|
||||||
use tinyvec::{Array, TinyVec};
|
use tinyvec::{Array, TinyVec};
|
||||||
use wormhole_bindings::WormholeQuery;
|
use wormhole_bindings::WormholeQuery;
|
||||||
use wormhole_sdk::{
|
use wormhole_sdk::{
|
||||||
accountant as accountant_module, token,
|
accountant as accountant_module,
|
||||||
|
accountant_modification::ModificationKind,
|
||||||
|
token,
|
||||||
vaa::{self, Body, Header, Signature},
|
vaa::{self, Body, Header, Signature},
|
||||||
Chain,
|
Chain,
|
||||||
};
|
};
|
||||||
|
@ -416,9 +418,9 @@ fn handle_accountant_governance_vaa(
|
||||||
} => {
|
} => {
|
||||||
let token_address = TokenAddress::new(token_address.0);
|
let token_address = TokenAddress::new(token_address.0);
|
||||||
let kind = match kind {
|
let kind = match kind {
|
||||||
accountant_module::ModificationKind::Add => Kind::Add,
|
ModificationKind::Add => Kind::Add,
|
||||||
accountant_module::ModificationKind::Subtract => Kind::Sub,
|
ModificationKind::Subtract => Kind::Sub,
|
||||||
accountant_module::ModificationKind::Unknown => {
|
ModificationKind::Unknown => {
|
||||||
bail!("unsupported governance action")
|
bail!("unsupported governance action")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,7 +20,8 @@ use global_accountant::{
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use wormhole_bindings::{fake, WormholeQuery};
|
use wormhole_bindings::{fake, WormholeQuery};
|
||||||
use wormhole_sdk::{
|
use wormhole_sdk::{
|
||||||
accountant::{self as accountant_module, ModificationKind},
|
accountant as accountant_module,
|
||||||
|
accountant_modification::ModificationKind,
|
||||||
token,
|
token,
|
||||||
vaa::{Body, Header, Signature},
|
vaa::{Body, Header, Signature},
|
||||||
Address, Amount, Chain, Vaa,
|
Address, Amount, Chain, Vaa,
|
||||||
|
|
|
@ -28,6 +28,7 @@ use tinyvec::{Array, TinyVec};
|
||||||
use wormhole_bindings::WormholeQuery;
|
use wormhole_bindings::WormholeQuery;
|
||||||
use wormhole_io::TypePrefixedPayload;
|
use wormhole_io::TypePrefixedPayload;
|
||||||
use wormhole_sdk::{
|
use wormhole_sdk::{
|
||||||
|
accountant_modification::ModificationKind,
|
||||||
ntt_accountant as ntt_accountant_module, relayer,
|
ntt_accountant as ntt_accountant_module, relayer,
|
||||||
vaa::{self, Body, Header, Signature},
|
vaa::{self, Body, Header, Signature},
|
||||||
Chain,
|
Chain,
|
||||||
|
@ -465,9 +466,9 @@ fn handle_accountant_governance_vaa(
|
||||||
} => {
|
} => {
|
||||||
let token_address = TokenAddress::new(token_address.0);
|
let token_address = TokenAddress::new(token_address.0);
|
||||||
let kind = match kind {
|
let kind = match kind {
|
||||||
ntt_accountant_module::ModificationKind::Add => Kind::Add,
|
ModificationKind::Add => Kind::Add,
|
||||||
ntt_accountant_module::ModificationKind::Subtract => Kind::Sub,
|
ModificationKind::Subtract => Kind::Sub,
|
||||||
ntt_accountant_module::ModificationKind::Unknown => {
|
ModificationKind::Unknown => {
|
||||||
bail!("unsupported governance action")
|
bail!("unsupported governance action")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,8 +20,8 @@ use ntt_global_accountant::{
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use wormhole_bindings::{fake, WormholeQuery};
|
use wormhole_bindings::{fake, WormholeQuery};
|
||||||
use wormhole_sdk::{
|
use wormhole_sdk::{
|
||||||
ntt_accountant::{self as ntt_accountant_module, ModificationKind},
|
accountant_modification::ModificationKind,
|
||||||
relayer,
|
ntt_accountant as ntt_accountant_module, relayer,
|
||||||
vaa::{Body, Header, Signature},
|
vaa::{Body, Header, Signature},
|
||||||
Address, Amount, Chain, Vaa,
|
Address, Amount, Chain, Vaa,
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,55 +4,9 @@
|
||||||
//! It needs a modify_balance message to be able to correct for unforeseen events.
|
//! It needs a modify_balance message to be able to correct for unforeseen events.
|
||||||
|
|
||||||
use bstr::BString;
|
use bstr::BString;
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{Address, Amount, Chain};
|
use crate::{accountant_modification::ModificationKind, Address, Amount, Chain};
|
||||||
|
|
||||||
#[repr(u8)]
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
|
|
||||||
pub enum ModificationKind {
|
|
||||||
Unknown = 0,
|
|
||||||
Add = 1,
|
|
||||||
Subtract = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<u8> for ModificationKind {
|
|
||||||
fn from(other: u8) -> ModificationKind {
|
|
||||||
match other {
|
|
||||||
1 => ModificationKind::Add,
|
|
||||||
2 => ModificationKind::Subtract,
|
|
||||||
_ => ModificationKind::Unknown,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ModificationKind> for u8 {
|
|
||||||
fn from(other: ModificationKind) -> u8 {
|
|
||||||
match other {
|
|
||||||
ModificationKind::Unknown => 0,
|
|
||||||
ModificationKind::Add => 1,
|
|
||||||
ModificationKind::Subtract => 2,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Serialize for ModificationKind {
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
serializer.serialize_u8((*self).into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for ModificationKind {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
<u8 as Deserialize>::deserialize(deserializer).map(Self::from)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Represents a governance action targeted at the Accountant.
|
/// Represents a governance action targeted at the Accountant.
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
|
#[repr(u8)]
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
|
||||||
|
pub enum ModificationKind {
|
||||||
|
Unknown = 0,
|
||||||
|
Add = 1,
|
||||||
|
Subtract = 2,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<u8> for ModificationKind {
|
||||||
|
fn from(other: u8) -> ModificationKind {
|
||||||
|
match other {
|
||||||
|
1 => ModificationKind::Add,
|
||||||
|
2 => ModificationKind::Subtract,
|
||||||
|
_ => ModificationKind::Unknown,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ModificationKind> for u8 {
|
||||||
|
fn from(other: ModificationKind) -> u8 {
|
||||||
|
match other {
|
||||||
|
ModificationKind::Unknown => 0,
|
||||||
|
ModificationKind::Add => 1,
|
||||||
|
ModificationKind::Subtract => 2,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Serialize for ModificationKind {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: Serializer,
|
||||||
|
{
|
||||||
|
serializer.serialize_u8((*self).into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for ModificationKind {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
<u8 as Deserialize>::deserialize(deserializer).map(Self::from)
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ use std::fmt;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub mod accountant;
|
pub mod accountant;
|
||||||
|
pub mod accountant_modification;
|
||||||
mod arraystring;
|
mod arraystring;
|
||||||
mod chain;
|
mod chain;
|
||||||
pub mod core;
|
pub mod core;
|
||||||
|
|
|
@ -4,55 +4,9 @@
|
||||||
//! It needs a modify_balance message to be able to correct for unforeseen events.
|
//! It needs a modify_balance message to be able to correct for unforeseen events.
|
||||||
|
|
||||||
use bstr::BString;
|
use bstr::BString;
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{Address, Amount, Chain};
|
use crate::{accountant_modification::ModificationKind, Address, Amount, Chain};
|
||||||
|
|
||||||
#[repr(u8)]
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy)]
|
|
||||||
pub enum ModificationKind {
|
|
||||||
Unknown = 0,
|
|
||||||
Add = 1,
|
|
||||||
Subtract = 2,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<u8> for ModificationKind {
|
|
||||||
fn from(other: u8) -> ModificationKind {
|
|
||||||
match other {
|
|
||||||
1 => ModificationKind::Add,
|
|
||||||
2 => ModificationKind::Subtract,
|
|
||||||
_ => ModificationKind::Unknown,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ModificationKind> for u8 {
|
|
||||||
fn from(other: ModificationKind) -> u8 {
|
|
||||||
match other {
|
|
||||||
ModificationKind::Unknown => 0,
|
|
||||||
ModificationKind::Add => 1,
|
|
||||||
ModificationKind::Subtract => 2,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Serialize for ModificationKind {
|
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
serializer.serialize_u8((*self).into())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'de> Deserialize<'de> for ModificationKind {
|
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
||||||
where
|
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
<u8 as Deserialize>::deserialize(deserializer).map(Self::from)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Represents a governance action targeted at the Accountant.
|
/// Represents a governance action targeted at the Accountant.
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
|
Loading…
Reference in New Issue