This repository was archived by the owner on Jan 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathprocess.ts
More file actions
53 lines (42 loc) · 1.49 KB
/
Copy pathprocess.ts
File metadata and controls
53 lines (42 loc) · 1.49 KB
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
import type { Transaction } from '@gorillapool/js-junglebus';
import bmapjs, { type BmapTx, type BobTx } from 'bmapjs';
import { parse } from 'bpu-ts';
import { saveTx } from './actions.js';
const { allProtocols, TransformTx } = bmapjs;
export const processTransaction = async (data: Partial<Transaction>): Promise<BmapTx | null> => {
try {
console.log('Starting transaction processing...');
console.log('Raw transaction:', data.transaction);
if (!data.transaction) {
console.error('No transaction data provided');
return null;
}
console.log('Parsing transaction with bpu-ts...');
const bob = await parse({
tx: { r: data.transaction },
split: [{ token: { op: 106 }, include: 'l' }, { token: { s: '|' } }],
});
if (!bob) {
console.error('Failed to parse transaction with bpu-ts');
return null;
}
console.log('Parsed BOB:', JSON.stringify(bob, null, 2));
console.log('Transforming transaction with bmapjs...');
const tx = await TransformTx(
bob as BobTx,
allProtocols.map((p) => p.name)
);
if (!tx) {
console.error('Failed to transform transaction with bmapjs');
return null;
}
console.log('Transformed transaction:', JSON.stringify(tx, null, 2));
console.log('Saving transaction...');
await saveTx(tx);
console.log('Transaction processing completed successfully');
return tx;
} catch (error) {
console.error('Error in processTransaction:', error);
throw error;
}
};