Skip to content

Commit

Permalink
Merge pull request #2059 from blockstack/feat/event-burn-height
Browse files Browse the repository at this point in the history
feat: add burn_block_height to /new_burn_block event-dispatcher endpoint
  • Loading branch information
kantai authored Nov 13, 2020
2 parents 151e06e + ff241aa commit 6055f41
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/event-dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Example:
```json
{
"burn_block_hash": "0x4eaabcd105865e471f697eff5dd5bd85d47ecb5a26a3379d74fae0ae87c40904",
"burn_block_height": 331,
"reward_recipients": [
{
"recipient": "1C56LYirKa3PFXFsvhSESgDy2acEHVAEt6",
Expand Down
8 changes: 7 additions & 1 deletion src/chainstate/coordinator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pub trait BlockEventDispatcher {
fn announce_burn_block(
&self,
burn_block: &BurnchainHeaderHash,
burn_block_height: u64,
rewards: Vec<(StacksAddress, u64)>,
burns: u64,
);
Expand Down Expand Up @@ -464,7 +465,12 @@ fn dispatcher_announce_burn_ops<T: BlockEventDispatcher>(
}
}
let reward_recipients_vec = reward_recipients.into_iter().collect();
dispatcher.announce_burn_block(&burn_header.block_hash, reward_recipients_vec, burn_amt);
dispatcher.announce_burn_block(
&burn_header.block_hash,
burn_header.block_height,
reward_recipients_vec,
burn_amt,
);
}

impl<'a, T: BlockEventDispatcher, N: CoordinatorNotices, U: RewardSetProvider>
Expand Down
1 change: 1 addition & 0 deletions src/chainstate/coordinator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl BlockEventDispatcher for NullEventDispatcher {
fn announce_burn_block(
&self,
_burn_block: &BurnchainHeaderHash,
_burn_block_height: u64,
_rewards: Vec<(StacksAddress, u64)>,
_burns: u64,
) {
Expand Down
13 changes: 11 additions & 2 deletions testnet/stacks-node/src/event_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl EventObserver {

fn make_new_burn_block_payload(
burn_block: &BurnchainHeaderHash,
burn_block_height: u64,
rewards: Vec<(StacksAddress, u64)>,
burns: u64,
) -> serde_json::Value {
Expand All @@ -132,6 +133,7 @@ impl EventObserver {

json!({
"burn_block_hash": format!("0x{}", burn_block),
"burn_block_height": burn_block_height,
"reward_recipients": serde_json::Value::Array(reward_recipients),
"burn_amount": burns
})
Expand Down Expand Up @@ -291,10 +293,11 @@ impl BlockEventDispatcher for EventDispatcher {
fn announce_burn_block(
&self,
burn_block: &BurnchainHeaderHash,
burn_block_height: u64,
rewards: Vec<(StacksAddress, u64)>,
burns: u64,
) {
self.process_burn_block(burn_block, rewards, burns)
self.process_burn_block(burn_block, burn_block_height, rewards, burns)
}

fn dispatch_boot_receipts(&mut self, receipts: Vec<StacksTransactionReceipt>) {
Expand All @@ -319,6 +322,7 @@ impl EventDispatcher {
pub fn process_burn_block(
&self,
burn_block: &BurnchainHeaderHash,
burn_block_height: u64,
rewards: Vec<(StacksAddress, u64)>,
burns: u64,
) {
Expand All @@ -336,7 +340,12 @@ impl EventDispatcher {
return;
}

let payload = EventObserver::make_new_burn_block_payload(burn_block, rewards, burns);
let payload = EventObserver::make_new_burn_block_payload(
burn_block,
burn_block_height,
rewards,
burns,
);

for (_, observer) in interested_observers.iter() {
observer.send_new_burn_block(&payload);
Expand Down

0 comments on commit 6055f41

Please sign in to comment.