Skip to content

Commit a8042dd

Browse files
authored
Issue 2291 (#281)
* add fa and coin event types * resolve comment from nikita * resolve comment from areg * Revert "resolve comment from areg" This reverts commit 1215adf.
1 parent ffabf2a commit a8042dd

File tree

6 files changed

+96
-0
lines changed

6 files changed

+96
-0
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ debug-ignore = { version = "1.0.3", features = ["serde"] }
545545
derivative = "2.2.0"
546546
derivation-path = "0.2.0"
547547
derive_builder = "0.20.0"
548+
derive-getters = "0.5.0"
548549
determinator = "0.12.0"
549550
derive_more = "0.99.11"
550551
diesel = "2.1"

types/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ arr_macro = { workspace = true }
2828
base64 = { workspace = true }
2929
bcs = { workspace = true }
3030
bytes = { workspace = true }
31+
derive-getters = { workspace = true }
3132
fixed = { workspace = true }
3233
fxhash = { workspace = true }
3334
hashbrown = { workspace = true }
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use move_core_types::{
2+
account_address::AccountAddress, ident_str, identifier::IdentStr, language_storage::TypeTag, move_resource::MoveStructType, parser::parse_type_tag
3+
};
4+
use once_cell::sync::Lazy;
5+
use serde::{Deserialize, Serialize};
6+
use derive_getters::Getters;
7+
pub static COIN_WITHDRAW_EVENT_TYPE_TAG: Lazy<TypeTag> =
8+
Lazy::new(|| TypeTag::Struct(Box::new(CoinWithdraw::struct_tag())));
9+
pub static COIN_DEPOSIT_EVENT_TYPE_TAG: Lazy<TypeTag> =
10+
Lazy::new(|| TypeTag::Struct(Box::new(CoinDeposit::struct_tag())));
11+
12+
pub static COIN_LEGACY_DEPOSIT_EVENT_V1: Lazy<TypeTag> = Lazy::new(|| {
13+
parse_type_tag("0x1::coin::DepositEvent")
14+
.expect("parse type tag for 0x1::coin::DepositEvent should succeed")
15+
});
16+
pub static COIN_LEGACY_WITHDRAW_EVENT_V1: Lazy<TypeTag> = Lazy::new(|| {
17+
parse_type_tag("0x1::coin::WithdrawEvent")
18+
.expect("parse type tag for 0x1::coin::WithdrawEvent should succeed")
19+
});
20+
21+
/// Module event emitted when some amount of a coin is deposited into an account.
22+
#[derive(Debug, Serialize, Deserialize, Getters)]
23+
pub struct CoinDeposit {
24+
coin_type: String,
25+
account: AccountAddress,
26+
amount: u64,
27+
}
28+
29+
/// Module event emitted when some amount of a coin is withdrawn from an account.
30+
#[derive(Debug, Serialize, Deserialize, Getters)]
31+
pub struct CoinWithdraw {
32+
coin_type: String,
33+
account: AccountAddress,
34+
amount: u64,
35+
}
36+
37+
impl MoveStructType for CoinWithdraw {
38+
const MODULE_NAME: &'static IdentStr = ident_str!("coin");
39+
const STRUCT_NAME: &'static IdentStr = ident_str!("CoinWithdraw");
40+
}
41+
42+
impl MoveStructType for CoinDeposit {
43+
const MODULE_NAME: &'static IdentStr = ident_str!("coin");
44+
const STRUCT_NAME: &'static IdentStr = ident_str!("CoinDeposit");
45+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use derive_getters::Getters;
2+
use move_core_types::{account_address::AccountAddress, ident_str, identifier::IdentStr, language_storage::TypeTag, move_resource::MoveStructType};
3+
use once_cell::sync::Lazy;
4+
use serde::{Deserialize, Serialize};
5+
6+
pub static FA_WITHDRAW_EVENT_TYPE_TAG: Lazy<TypeTag> =
7+
Lazy::new(|| TypeTag::Struct(Box::new(FaWithdraw::struct_tag())));
8+
pub static FA_DEPOSIT_EVENT_TYPE_TAG: Lazy<TypeTag> =
9+
Lazy::new(|| TypeTag::Struct(Box::new(FaDeposit::struct_tag())));
10+
11+
/// Represents a Deposit event for a Fungible Asset.
12+
#[derive(Debug, Serialize, Deserialize, Getters)]
13+
pub struct FaDeposit {
14+
store: AccountAddress,
15+
amount: u64,
16+
}
17+
18+
/// Represents a Withdraw event for a Fungible Asset.
19+
#[derive(Debug, Serialize, Deserialize, Getters)]
20+
pub struct FaWithdraw {
21+
store: AccountAddress,
22+
amount: u64,
23+
}
24+
25+
impl MoveStructType for FaDeposit {
26+
const MODULE_NAME: &'static IdentStr = ident_str!("fungible_asset");
27+
const STRUCT_NAME: &'static IdentStr = ident_str!("Deposit");
28+
}
29+
30+
impl MoveStructType for FaWithdraw {
31+
const MODULE_NAME: &'static IdentStr = ident_str!("fungible_asset");
32+
const STRUCT_NAME: &'static IdentStr = ident_str!("Withdraw");
33+
}

types/src/account_config/events/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ pub mod deposit;
66
pub mod new_block;
77
pub mod new_epoch;
88
pub mod withdraw;
9+
pub mod coin;
10+
pub mod fa;
911

1012
pub use deposit::*;
1113
pub use new_block::*;
1214
pub use new_epoch::*;
1315
pub use withdraw::*;
16+
pub use coin::*;
17+
pub use fa::*;

0 commit comments

Comments
 (0)