forked from stellar/system-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.ts
executable file
·46 lines (36 loc) · 1.31 KB
/
events.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
#!/usr/bin/env ts-node-script
import { ArgumentParser } from 'argparse';
import { Contract, SorobanRpc } from '@stellar/stellar-sdk';
async function main() {
const parser = new ArgumentParser({ description: 'Get contract events' })
parser.add_argument('--id', { dest: 'contractId', required: true, help: 'Contract ID' });
parser.add_argument('--rpc-url', { dest: 'rpcUrl', required: true, help: 'RPC URL' });
parser.add_argument('--size', { dest: 'size', required: true, help: 'Max Number of events to fetch' });
parser.add_argument('--ledgerFrom', { dest: 'ledgerFrom', help: 'Ledget Start' });
const {
contractId,
rpcUrl,
size,
ledgerFrom,
} = parser.parse_args() as Record<string, string>;
const server = new SorobanRpc.Server(rpcUrl, { allowHttp: true });
let filters: SorobanRpc.Api.EventFilter[] = [];
if (contractId != null) {
filters.push({
contractIds: [ new Contract(contractId).contractId() ]
});
}
let response = await server.getEvents({
startLedger: Number(ledgerFrom),
filters: filters,
limit: Number(size)
});
if (!response.events) {
throw new Error(`No events in response: ${JSON.stringify(response)}`);
}
console.log(JSON.stringify(response.events));
}
main().catch(err => {
console.error(JSON.stringify(err));
throw err;
});