Skip to content

Commit 0196437

Browse files
committed
feat(hubble): support bond/unbond - handle create-proxy-account
1 parent c3f88c3 commit 0196437

13 files changed

+318
-9
lines changed

hubble/.sqlx/query-f1e8ab866aee99c240c2583bc6883430b89e063d6c84c33b752d84995aa017bc.json

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

hubble/.sqlx/query-f2c7497b73df281bcf50dcc5d2f32a25c5f58f65f00b56b230404eedd3860ba4.json

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

hubble/src/indexer/consumer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ fn should_trigger_enrich_reset(kind: RecordKind) -> bool {
308308
WalletMutationEntry => false,
309309
CreateWrappedToken => false,
310310
CreateWrappedTokenRelation => false,
311+
CreateProxyAccount => false,
311312
// ignore enriched records
312313
PacketSendDecoded => false,
313314
PacketSendTransfers => false,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use crate::indexer::event::{
4+
header::Header,
5+
types::{ChannelId, Owner, Path, ProxyAccount},
6+
};
7+
8+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
9+
pub struct CreateProxyAccountEvent {
10+
#[serde(flatten)]
11+
pub header: Header,
12+
pub path: Path,
13+
pub channel_id: ChannelId,
14+
pub owner: Owner,
15+
pub proxy_account: ProxyAccount,
16+
}
17+
18+
#[cfg(test)]
19+
mod tests {
20+
use bytes::Bytes;
21+
22+
use super::*;
23+
use crate::indexer::event::{
24+
test_utils::test_helpers::{
25+
create_test_header, test_json_format, test_roundtrip_serialization,
26+
},
27+
types::{ChannelId, Owner, Path, ProxyAccount},
28+
};
29+
30+
/// Creates a test CreateProxyAccountEvent with predictable values
31+
fn create_test_event(suffix: u32) -> CreateProxyAccountEvent {
32+
let header = create_test_header(suffix);
33+
34+
CreateProxyAccountEvent {
35+
header,
36+
channel_id: ChannelId(42),
37+
path: Path(42_u128.try_into().unwrap()),
38+
owner: Owner(Bytes::from("owner")),
39+
proxy_account: ProxyAccount(Bytes::from("proxy_account")),
40+
}
41+
}
42+
43+
#[test]
44+
fn test_json_serialization() {
45+
let event = create_test_event(42);
46+
test_roundtrip_serialization(&event);
47+
}
48+
49+
#[test]
50+
fn test_json_format_stability() {
51+
let event = create_test_event(42);
52+
53+
let expected_json = r#"{
54+
"block_hash": "0x424c4f434b5f484153485f3432",
55+
"channel_id": 42,
56+
"event_index": "42",
57+
"height": "10042",
58+
"message_index": "542",
59+
"owner": "0x6f776e6572",
60+
"path": "0x2a",
61+
"proxy_account": "0x70726f78795f6163636f756e74",
62+
"timestamp": "2020-09-13T12:27:22Z",
63+
"transaction_event_index": "242",
64+
"transaction_hash": "0x54585f484153485f3432",
65+
"transaction_index": "142",
66+
"universal_chain_id": "test-chain-42"
67+
}"#;
68+
69+
test_json_format(&event, expected_json);
70+
}
71+
}

hubble/src/indexer/event/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) mod connection_open_init_event;
88
pub(crate) mod connection_open_try_event;
99
pub(crate) mod create_client_event;
1010
pub(crate) mod create_lens_client_event;
11+
pub(crate) mod create_proxy_account_event;
1112
pub(crate) mod create_wrapped_token;
1213
pub(crate) mod header;
1314
pub(crate) mod hubble;

hubble/src/indexer/event/supported.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ use crate::indexer::event::{
1010
connection_open_confirm_event::ConnectionOpenConfirmEvent,
1111
connection_open_init_event::ConnectionOpenInitEvent,
1212
connection_open_try_event::ConnectionOpenTryEvent, create_client_event::CreateClientEvent,
13-
create_lens_client_event::CreateLensClientEvent, create_wrapped_token::CreateWrappedTokenEvent,
14-
packet_ack_event::PacketAckEvent, packet_recv_event::PacketRecvEvent,
15-
packet_send_event::PacketSendEvent, packet_timeout_event::PacketTimeoutEvent,
16-
token_bucket_update_event::TokenBucketUpdateEvent, types::BlockHeight,
17-
update_client_event::UpdateClientEvent, wallet_mutation_entry_event::WalletMutationEntryEvent,
18-
write_ack_event::WriteAckEvent,
13+
create_lens_client_event::CreateLensClientEvent,
14+
create_proxy_account_event::CreateProxyAccountEvent,
15+
create_wrapped_token::CreateWrappedTokenEvent, packet_ack_event::PacketAckEvent,
16+
packet_recv_event::PacketRecvEvent, packet_send_event::PacketSendEvent,
17+
packet_timeout_event::PacketTimeoutEvent, token_bucket_update_event::TokenBucketUpdateEvent,
18+
types::BlockHeight, update_client_event::UpdateClientEvent,
19+
wallet_mutation_entry_event::WalletMutationEntryEvent, write_ack_event::WriteAckEvent,
1920
};
2021

2122
#[warn(clippy::enum_variant_names)]
@@ -174,6 +175,11 @@ pub enum SupportedBlockEvent {
174175
#[serde(flatten)]
175176
inner: CreateWrappedTokenEvent,
176177
},
178+
#[serde(rename = "create-proxy-account")]
179+
CreateProxyAccount {
180+
#[serde(flatten)]
181+
inner: CreateProxyAccountEvent,
182+
},
177183
}
178184

179185
impl SupportedBlockEvent {
@@ -203,6 +209,7 @@ impl SupportedBlockEvent {
203209
SupportedBlockEvent::TokenBucketUpdate { inner, .. } => inner.header.height,
204210
SupportedBlockEvent::WalletMutationEntry { inner, .. } => inner.header.height,
205211
SupportedBlockEvent::CreateWrappedToken { inner, .. } => inner.header.height,
212+
SupportedBlockEvent::CreateProxyAccount { inner, .. } => inner.header.height,
206213
}
207214
}
208215
}

hubble/src/indexer/event/types.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,24 @@ impl From<bytes::Bytes> for Denom {
530530
}
531531
}
532532

533+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
534+
pub struct Owner(#[serde(with = "bytes_as_hex")] pub bytes::Bytes);
535+
536+
impl From<bytes::Bytes> for Owner {
537+
fn from(value: bytes::Bytes) -> Self {
538+
Self(value)
539+
}
540+
}
541+
542+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
543+
pub struct ProxyAccount(#[serde(with = "bytes_as_hex")] pub bytes::Bytes);
544+
545+
impl From<bytes::Bytes> for ProxyAccount {
546+
fn from(value: bytes::Bytes) -> Self {
547+
Self(value)
548+
}
549+
}
550+
533551
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
534552
pub struct Capacity(pub U256);
535553

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use tracing::trace;
2+
3+
use crate::indexer::{
4+
api::IndexerError,
5+
event::create_proxy_account_event::CreateProxyAccountEvent,
6+
handler::EventContext,
7+
record::{
8+
change_counter::Changes, create_proxy_account_record::CreateProxyAccountRecord,
9+
ChainContext,
10+
},
11+
};
12+
impl<'a> EventContext<'a, ChainContext, CreateProxyAccountEvent> {
13+
pub async fn handle(
14+
&self,
15+
tx: &mut sqlx::Transaction<'_, sqlx::Postgres>,
16+
) -> Result<Changes, IndexerError> {
17+
trace!("handle({self:?})");
18+
19+
CreateProxyAccountRecord::try_from(self)?.insert(tx).await
20+
}
21+
}

hubble/src/indexer/handler/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) mod connection_open_init_event_handler;
1010
pub(crate) mod connection_open_try_event_handler;
1111
pub(crate) mod create_client_handler;
1212
pub(crate) mod create_lens_client_handler;
13+
pub(crate) mod create_proxy_account_handler;
1314
pub(crate) mod create_wrapped_token_handler;
1415
pub(crate) mod packet_ack_event_handler;
1516
pub(crate) mod packet_recv_event_handler;

hubble/src/indexer/record/change_counter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ pub enum RecordKind {
333333
PacketSendUnbond,
334334
CreateWrappedToken,
335335
CreateWrappedTokenRelation,
336+
CreateProxyAccount,
336337
}
337338

338339
/// Trait for types that can be associated with a specific `RecordKind`.

0 commit comments

Comments
 (0)