-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatomicmarket.ts
71 lines (64 loc) · 2.09 KB
/
atomicmarket.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {
EosioReaderAction,
EosioReaderActionFilter,
EosioReaderTableRowFilter,
} from '@blockmatic/eosio-ship-reader';
import { getLogger } from '../src/common/config';
import { ActionData, ActionHandlerResult } from '../src/common/types';
import ShipReaderWrapper from '../src/eosio/ship-reader-wrapper';
const logger = getLogger('atomicmarket_example');
/**
* define tables and actions to listen for
*/
const table_rows_whitelist: () => EosioReaderTableRowFilter[] = () => [
{ code: 'atomicmarket', table: 'auctions' },
{ code: 'atomicmarket', table: 'balances' },
{ code: 'atomicmarket', table: 'buyoffers' },
{ code: 'atomicmarket', table: 'config' },
{ code: 'atomicmarket', table: 'counters' },
{ code: 'atomicmarket', table: 'marketplaces' },
{ code: 'atomicmarket', table: 'sales' },
];
const actions_whitelist: () => EosioReaderActionFilter[] = () => [
{ code: 'atomicmarket', action: '*' },
];
/**
* define the handler which reacts on actions contained in a block
* the message returned by this method will be sent to contract topic
* @param actionData
* @returns
*/
const handleAction = (actionData: ActionData): ActionHandlerResult => {
const action: EosioReaderAction = actionData.eosio_reader_action;
switch (action.name) {
default:
logger.debug(`Ignoring action ${action.name}`);
break;
case 'lognewsale':
if ('atomicmarket' === action.receipt.receiver) {
return {
msg: JSON.stringify({
blocknum: actionData.blocknum,
timestamp: actionData.timestamp,
type: action.name,
transaction_id: action.transaction_id,
data: action.data,
}),
action_type: actionData.eosio_reader_action.name,
};
}
}
};
/**
* configure and start event-processor-node
*/
const run = async () => {
const wrapper: ShipReaderWrapper = new ShipReaderWrapper({
actions_whitelist: actions_whitelist,
message_header_prefix: 'atomicmarket',
table_rows_whitelist: table_rows_whitelist,
action_handler: handleAction,
});
wrapper.startProcessing();
};
run();