Skip to content

Commit

Permalink
fix: stub response for /new_burn_block (allows sidecar to run with …
Browse files Browse the repository at this point in the history
…latest core node)
  • Loading branch information
zone117x committed Nov 12, 2020
1 parent 0640790 commit 4a48a29
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/event-stream/core-node-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,17 @@ export interface CoreNodeParsedTxMessage {
block_height: number;
burn_block_time: number;
}

export interface CoreNodeNewBurnBlockMessage {
burn_block_hash: string;
/** Amount in BTC satoshis. */
burn_amount: number;
reward_recipients: [
{
/** Bitcoin address (b58 encoded). */
recipient: string;
/** Amount in BTC satoshis. */
amount: number;
}
];
}
27 changes: 23 additions & 4 deletions src/event-stream/event-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import * as bodyParser from 'body-parser';
import { addAsync } from '@awaitjs/express';
import PQueue from 'p-queue';

import { hexToBuffer, logError, logger, digestSha512_256, assertNotNullish } from '../helpers';
import { CoreNodeMessage, CoreNodeEventType, StxLockEvent } from './core-node-message';
import { hexToBuffer, logError, logger, digestSha512_256 } from '../helpers';
import {
CoreNodeMessage,
CoreNodeEventType,
CoreNodeNewBurnBlockMessage,
} from './core-node-message';
import {
DataStore,
createDbTxFromCoreMsg,
Expand Down Expand Up @@ -304,7 +308,22 @@ export async function startEventServer(opts: {
await messageHandler.handleBlockMessage(msg, db);
res.status(200).json({ result: 'ok' });
} catch (error) {
logError(`error processing core-node message: ${error}`, error);
logError(`error processing core-node /new_block: ${error}`, error);
res.status(500).json({ error: error });
}
});

app.postAsync('/new_burn_block', async (req, res) => {
try {
const msg: CoreNodeNewBurnBlockMessage = req.body;
if (msg.reward_recipients.length > 0) {
// TODO: integrate into event handler and db
// console.log(msg);
}
await Promise.resolve();
res.status(200).json({ result: 'ok' });
} catch (error) {
logError(`error processing core-node /new_burn_block: ${error}`, error);
res.status(500).json({ error: error });
}
});
Expand All @@ -316,7 +335,7 @@ export async function startEventServer(opts: {
res.status(200).json({ result: 'ok' });
await Promise.resolve();
} catch (error) {
logError(`error processing core-node mempool tx: ${error}`, error);
logError(`error processing core-node /new_mempool_tx: ${error}`, error);
res.status(500).json({ error: error });
}
});
Expand Down

0 comments on commit 4a48a29

Please sign in to comment.