Skip to content

Commit 0b96be3

Browse files
author
Aaron Blankstein
authored
Merge pull request #2050 from blockstack/feat/locked-addr-event
Minor event dispatcher updates
2 parents 2c55318 + aeb0639 commit 0b96be3

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

docs/event-dispatcher.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Example:
3636
"burn_block_time": 1591301733,
3737
"events": [
3838
{
39+
"event_index": 1,
3940
"committed": true,
4041
"stx_transfer_event": {
4142
"amount": "1000",

src/chainstate/stacks/events.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,58 +44,72 @@ pub enum StacksTransactionEvent {
4444
}
4545

4646
impl StacksTransactionEvent {
47-
pub fn json_serialize(&self, txid: &Txid, committed: bool) -> serde_json::Value {
47+
pub fn json_serialize(
48+
&self,
49+
event_index: usize,
50+
txid: &Txid,
51+
committed: bool,
52+
) -> serde_json::Value {
4853
match self {
4954
StacksTransactionEvent::SmartContractEvent(event_data) => json!({
5055
"txid": format!("0x{:?}", txid),
56+
"event_index": event_index,
5157
"committed": committed,
5258
"type": "contract_event",
5359
"contract_event": event_data.json_serialize()
5460
}),
5561
StacksTransactionEvent::STXEvent(STXEventType::STXTransferEvent(event_data)) => json!({
5662
"txid": format!("0x{:?}", txid),
63+
"event_index": event_index,
5764
"committed": committed,
5865
"type": "stx_transfer_event",
5966
"stx_transfer_event": event_data.json_serialize()
6067
}),
6168
StacksTransactionEvent::STXEvent(STXEventType::STXMintEvent(event_data)) => json!({
6269
"txid": format!("0x{:?}", txid),
70+
"event_index": event_index,
6371
"committed": committed,
6472
"type": "stx_mint_event",
6573
"stx_mint_event": event_data.json_serialize()
6674
}),
6775
StacksTransactionEvent::STXEvent(STXEventType::STXBurnEvent(event_data)) => json!({
6876
"txid": format!("0x{:?}", txid),
77+
"event_index": event_index,
6978
"committed": committed,
7079
"type": "stx_burn_event",
7180
"stx_burn_event": event_data.json_serialize()
7281
}),
7382
StacksTransactionEvent::STXEvent(STXEventType::STXLockEvent(event_data)) => json!({
7483
"txid": format!("0x{:?}", txid),
84+
"event_index": event_index,
7585
"committed": committed,
7686
"type": "stx_lock_event",
7787
"stx_lock_event": event_data.json_serialize()
7888
}),
7989
StacksTransactionEvent::NFTEvent(NFTEventType::NFTTransferEvent(event_data)) => json!({
8090
"txid": format!("0x{:?}", txid),
91+
"event_index": event_index,
8192
"committed": committed,
8293
"type": "nft_transfer_event",
8394
"nft_transfer_event": event_data.json_serialize()
8495
}),
8596
StacksTransactionEvent::NFTEvent(NFTEventType::NFTMintEvent(event_data)) => json!({
8697
"txid": format!("0x{:?}", txid),
98+
"event_index": event_index,
8799
"committed": committed,
88100
"type": "nft_mint_event",
89101
"nft_mint_event": event_data.json_serialize()
90102
}),
91103
StacksTransactionEvent::FTEvent(FTEventType::FTTransferEvent(event_data)) => json!({
92104
"txid": format!("0x{:?}", txid),
105+
"event_index": event_index,
93106
"committed": committed,
94107
"type": "ft_transfer_event",
95108
"ft_transfer_event": event_data.json_serialize()
96109
}),
97110
StacksTransactionEvent::FTEvent(FTEventType::FTMintEvent(event_data)) => json!({
98111
"txid": format!("0x{:?}", txid),
112+
"event_index": event_index,
99113
"committed": committed,
100114
"type": "ft_mint_event",
101115
"ft_mint_event": event_data.json_serialize()
@@ -160,13 +174,15 @@ impl STXMintEventData {
160174
pub struct STXLockEventData {
161175
pub locked_amount: u128,
162176
pub unlock_height: u64,
177+
pub locked_address: PrincipalData,
163178
}
164179

165180
impl STXLockEventData {
166181
pub fn json_serialize(&self) -> serde_json::Value {
167182
json!({
168183
"locked_amount": format!("{}",self.locked_amount),
169184
"unlock_height": format!("{}", self.unlock_height),
185+
"locked_address": format!("{}", self.locked_address),
170186
})
171187
}
172188
}
@@ -180,7 +196,7 @@ pub struct STXBurnEventData {
180196
impl STXBurnEventData {
181197
pub fn json_serialize(&self) -> serde_json::Value {
182198
json!({
183-
"sender": format!("{}",self.sender),
199+
"sender": format!("{}", self.sender),
184200
"amount": format!("{}", self.amount),
185201
})
186202
}

src/vm/functions/special.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ fn handle_pox_api_contract_call(
9292
STXEventType::STXLockEvent(STXLockEventData {
9393
locked_amount,
9494
unlock_height,
95+
locked_address: stacker,
9596
}),
9697
));
9798
}

testnet/stacks-node/src/event_dispatcher.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl EventObserver {
197197

198198
fn send(
199199
&self,
200-
filtered_events: Vec<&(bool, Txid, &StacksTransactionEvent)>,
200+
filtered_events: Vec<(usize, &(bool, Txid, &StacksTransactionEvent))>,
201201
chain_tip: &ChainTip,
202202
parent_index_hash: &StacksBlockId,
203203
boot_receipts: Option<&Vec<StacksTransactionReceipt>>,
@@ -207,7 +207,9 @@ impl EventObserver {
207207
// Serialize events to JSON
208208
let serialized_events: Vec<serde_json::Value> = filtered_events
209209
.iter()
210-
.map(|(committed, txid, event)| event.json_serialize(txid, *committed))
210+
.map(|(event_index, (committed, txid, event))| {
211+
event.json_serialize(*event_index, txid, *committed)
212+
})
211213
.collect();
212214

213215
let mut tx_index: u32 = 0;
@@ -449,7 +451,7 @@ impl EventDispatcher {
449451
for (observer_id, filtered_events_ids) in dispatch_matrix.iter().enumerate() {
450452
let filtered_events: Vec<_> = filtered_events_ids
451453
.iter()
452-
.map(|event_id| &events[*event_id])
454+
.map(|event_id| (*event_id, &events[*event_id]))
453455
.collect();
454456

455457
self.registered_observers[observer_id].send(

0 commit comments

Comments
 (0)