-
Notifications
You must be signed in to change notification settings - Fork 3
/
show-messages.js
37 lines (32 loc) · 1.09 KB
/
show-messages.js
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
const {isAttachmentVersion, TransactionType, TransactionArbitrarySubtype} = require('@burstjs/core');
const {convertBurstTimeToDate} = require('@burstjs/util');
const {api, askAccount, handleApiError, getAccountId} = require('./helper');
const getMessageText = transaction =>
isAttachmentVersion(transaction,'EncryptedMessage')
? '<encrypted>'
: transaction.attachment.message;
async function showMessages(account) {
try {
const accountId = getAccountId(account);
const {transactions} = await api.account.getAccountTransactions(accountId,
undefined,
undefined,
undefined,
TransactionType.Arbitrary,
TransactionArbitrarySubtype.Message
);
// now we map the fields we want to print as a table to console then
const mappedTransactions = transactions.map(t => ({
recipient: t.recipientRS,
message: getMessageText(t),
date: convertBurstTimeToDate(t.blockTimestamp)
}));
console.table(mappedTransactions, ['recipient', 'message', 'date'])
} catch (e) {
handleApiError(e)
}
}
(async () => {
const {account} = await askAccount();
await showMessages(account);
})();