Skip to content

Commit 5de2170

Browse files
author
web3blind
committed
Filter archive awards to Viz Magic memos
1 parent c0265aa commit 5de2170

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

tools/archive-node/archive-node.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@ var TEST_BLOCK = {
3939
receiver: 'target-mage',
4040
energy: 1000,
4141
custom_sequence: 1,
42-
memo: 'blessing'
42+
memo: 'viz://vm/bless/target-mage'
43+
}
44+
], [
45+
'award',
46+
{
47+
initiator: 'dice.id',
48+
receiver: 'random-user',
49+
energy: 2,
50+
custom_sequence: 0,
51+
memo: '🎲'
4352
}
4453
]]
4554
}]
@@ -89,6 +98,8 @@ async function run() {
8998
assert.strictEqual(events[0].protocol, 'VM');
9099
assert.strictEqual(events[0].type, 'char.attune');
91100
assert.strictEqual(events[2].protocol, 'award');
101+
assert.strictEqual(events[2].payload.memo, 'viz://vm/bless/target-mage');
102+
assert.ok(events.every(function(ev) { return ev.sender !== 'dice.id'; }), 'non-game awards must not be indexed');
92103

93104
var tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'viz-archive-node-test-'));
94105
var rpc = await startRpcServer();

tools/archive-node/parser.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,17 @@ function normalizeCustom(block, blockNum, txIndex, opIndex, opData) {
5858
};
5959
}
6060

61+
function isGameAward(opData) {
62+
var memo = opData && opData.memo || '';
63+
// VIZ award is global blockchain traffic. Index only awards that Viz Magic
64+
// explicitly marks as in-game social blessings. Economic author rewards
65+
// attached to hunts are already represented by the VM hunt action, so a
66+
// bare award with empty/random memo is intentionally ignored here.
67+
return String(memo).indexOf('viz://vm/') === 0;
68+
}
69+
6170
function normalizeAward(block, blockNum, txIndex, opIndex, opData) {
71+
if (!isGameAward(opData)) return null;
6272
var accounts = [];
6373
uniquePush(accounts, opData && opData.initiator);
6474
uniquePush(accounts, opData && opData.receiver);
@@ -109,5 +119,6 @@ function extractGameEvents(block, blockNum) {
109119
module.exports = {
110120
extractGameEvents: extractGameEvents,
111121
parseJsonMaybe: parseJsonMaybe,
112-
getSender: getSender
122+
getSender: getSender,
123+
isGameAward: isGameAward
113124
};

0 commit comments

Comments
 (0)