Skip to content

Commit 5a003f1

Browse files
committed
make example plugin use more plugin features
1 parent d9f2619 commit 5a003f1

File tree

5 files changed

+102
-5
lines changed

5 files changed

+102
-5
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
bin
2-
.ergomatic.toml
2+
ergomatic.yaml
33
cov
44
.vscode

deno.jsonc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"imports": {
33
"std/": "https://deno.land/[email protected]/",
4-
"zod": "https://deno.land/x/[email protected]/mod.ts",
4+
"zod/": "https://deno.land/x/[email protected]/",
55
"lodash.merge": "npm:[email protected]",
66
"yargs": "https://deno.land/x/[email protected]/deno.ts",
7+
"dirs/": "https://deno.land/x/[email protected]/",
78
"@fleet-sdk/common": "npm:@fleet-sdk/[email protected]",
89
"axios": "npm:[email protected]"
910
},

deno.lock

+69
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ergomatic.example.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
logLevel: DEBUG
2+
plugins:
3+
- id: example_plugin
4+
enabled: true # defaults to true, can be set to false to disable plugin.
5+
config:
6+
tokenId: c7e22029868ecba3d43c385bb42b8a1c96d0114ad5261ec7e0d27a6f24254f92
7+
exitAtPage: 3

plugins/example_plugin/mod.ts

+23-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { Plugin, PluginDescriptor } from "../../src/plugins/mod.ts";
33
export const EXAMPLE_PLUGIN_ID = "example_plugin";
44

55
interface ExamplePluginConfig {
6-
someValue: number;
6+
tokenId: string;
7+
exitAtPage: number;
78
}
89

910
export class ExamplePlugin extends Plugin<ExamplePluginConfig> {
@@ -16,11 +17,30 @@ export class ExamplePlugin extends Plugin<ExamplePluginConfig> {
1617
};
1718
}
1819

19-
onStart(): Promise<void> {
20+
async onStart(): Promise<void> {
2021
this.logger.info(
2122
`Example plugin started with config: ${JSON.stringify(this.config)}`,
2223
);
2324

24-
return Promise.resolve();
25+
const { tokenId, exitAtPage } = this.config;
26+
let currentPage = 0;
27+
28+
for await (const page of this.blockchainClient.getBoxesByTokenId(tokenId)) {
29+
currentPage++;
30+
31+
this.logger.info(
32+
`Got page ${currentPage} of boxes for token ${tokenId}`,
33+
);
34+
35+
this.logger.info(`there was ${page.length} boxes in this page`);
36+
37+
if (currentPage === exitAtPage) {
38+
this.logger.info(
39+
`Exiting at page ${currentPage} of boxes for token ${tokenId}`,
40+
);
41+
42+
break;
43+
}
44+
}
2545
}
2646
}

0 commit comments

Comments
 (0)