From c5a25261998d20f75cc81e6cea2537dcfdba80b3 Mon Sep 17 00:00:00 2001 From: fwaszkiewicz Date: Tue, 12 Aug 2025 12:32:35 +0200 Subject: [PATCH 1/2] Add code snippets --- .../on-accounts-full-manabar.ts | 29 ++++++++++++++ .../on-accounts-manabar-percent.ts | 28 +++++++++++++ .../on-accounts-metadata-change.ts | 26 ++++++++++++ .../on-impacted-accounts.ts | 28 +++++++++++++ .../account-management/on-new-account.ts | 28 +++++++++++++ .../on-block-number.ts | 24 +++++++++++ .../blockchain-infrastructure/on-block.ts | 27 +++++++++++++ .../on-transaction-ids.ts | 27 +++++++++++++ .../on-accounts-balance-change.ts | 26 ++++++++++++ .../on-exchange-transfer.ts | 28 +++++++++++++ .../on-feed-price-change.ts | 26 ++++++++++++ .../on-feed-price-no-change.ts | 26 ++++++++++++ .../on-internal-market-operation.ts | 28 +++++++++++++ .../financial-operations/on-whale-alert.ts | 31 ++++++++++++++ .../security-and-governance/on-alarm.ts | 28 +++++++++++++ .../on-witnesses-missed-blocks.ts | 26 ++++++++++++ .../on-comments-incoming-payout.ts | 30 ++++++++++++++ .../social-and-content/on-comments.ts | 40 +++++++++++++++++++ .../social-and-content/on-custom-operation.ts | 26 ++++++++++++ .../queenbee/social-and-content/on-follow.ts | 25 ++++++++++++ .../queenbee/social-and-content/on-mention.ts | 25 ++++++++++++ .../on-posts-incoming-payout.ts | 29 ++++++++++++++ .../queenbee/social-and-content/on-posts.ts | 30 ++++++++++++++ .../queenbee/social-and-content/on-reblog.ts | 25 ++++++++++++ .../queenbee/social-and-content/on-votes.ts | 29 ++++++++++++++ 25 files changed, 695 insertions(+) create mode 100644 snippets/queenbee/account-management/on-accounts-full-manabar.ts create mode 100644 snippets/queenbee/account-management/on-accounts-manabar-percent.ts create mode 100644 snippets/queenbee/account-management/on-accounts-metadata-change.ts create mode 100644 snippets/queenbee/account-management/on-impacted-accounts.ts create mode 100644 snippets/queenbee/account-management/on-new-account.ts create mode 100644 snippets/queenbee/blockchain-infrastructure/on-block-number.ts create mode 100644 snippets/queenbee/blockchain-infrastructure/on-block.ts create mode 100644 snippets/queenbee/blockchain-infrastructure/on-transaction-ids.ts create mode 100644 snippets/queenbee/financial-operations/on-accounts-balance-change.ts create mode 100644 snippets/queenbee/financial-operations/on-exchange-transfer.ts create mode 100644 snippets/queenbee/financial-operations/on-feed-price-change.ts create mode 100644 snippets/queenbee/financial-operations/on-feed-price-no-change.ts create mode 100644 snippets/queenbee/financial-operations/on-internal-market-operation.ts create mode 100644 snippets/queenbee/financial-operations/on-whale-alert.ts create mode 100644 snippets/queenbee/security-and-governance/on-alarm.ts create mode 100644 snippets/queenbee/security-and-governance/on-witnesses-missed-blocks.ts create mode 100644 snippets/queenbee/social-and-content/on-comments-incoming-payout.ts create mode 100644 snippets/queenbee/social-and-content/on-comments.ts create mode 100644 snippets/queenbee/social-and-content/on-custom-operation.ts create mode 100644 snippets/queenbee/social-and-content/on-follow.ts create mode 100644 snippets/queenbee/social-and-content/on-mention.ts create mode 100644 snippets/queenbee/social-and-content/on-posts-incoming-payout.ts create mode 100644 snippets/queenbee/social-and-content/on-posts.ts create mode 100644 snippets/queenbee/social-and-content/on-reblog.ts create mode 100644 snippets/queenbee/social-and-content/on-votes.ts diff --git a/snippets/queenbee/account-management/on-accounts-full-manabar.ts b/snippets/queenbee/account-management/on-accounts-full-manabar.ts new file mode 100644 index 0000000..5457d71 --- /dev/null +++ b/snippets/queenbee/account-management/on-accounts-full-manabar.ts @@ -0,0 +1,29 @@ +/* eslint-disable no-console */ +/** + * Category: 👤 Account Management + * Demo: onAccountsFullManabar() — notify when accounts reach 98% manabar. + * + * The onAccountsFullManabar observer monitors manabar levels and triggers + * when any specified account reaches 98% (full) manabar capacity. + * + * Data Types & IDE IntelliSense: + * - `EManabarType.RC`: Resource Credits for transactions + * - `EManabarType.VOTING`: Voting power + * - `EManabarType.DOWNVOTING`: Downvoting power + * - `data.account`: Account name that reached full manabar + * - `data.percentage`: Current manabar percentage + */ +import { EManabarType } from "@hiveio/wax"; +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for accounts with full RC manabar..."); + +bot.observe.onAccountsFullManabar(EManabarType.RC, "gtg").subscribe({ + next(data) { + console.log(`⚡ Account gtg has ${data.manabarData.gtg?.[EManabarType.RC]?.percent}% RC manabar!`); + }, + error: console.error +}); diff --git a/snippets/queenbee/account-management/on-accounts-manabar-percent.ts b/snippets/queenbee/account-management/on-accounts-manabar-percent.ts new file mode 100644 index 0000000..56b384a --- /dev/null +++ b/snippets/queenbee/account-management/on-accounts-manabar-percent.ts @@ -0,0 +1,28 @@ +/* eslint-disable no-console */ +/** + * Category: 👤 Account Management + * Demo: onAccountsManabarPercent() — watch for manabar threshold percentage. + * + * The onAccountsManabarPercent observer triggers when accounts reach a specific + * manabar percentage threshold. Simple monitoring without complex logic. + * + * Data Types & IDE IntelliSense: + * - `EManabarType.RC`: Resource Credits for transactions + * - `EManabarType.VOTING`: Voting power + * - `data.manabarData`: Account manabar information + * - IDE shows all available manabar properties via IntelliSense + */ +import { EManabarType } from "@hiveio/wax"; +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for accounts with 90%+ RC manabar..."); + +bot.observe.onAccountsManabarPercent(EManabarType.RC, 90, "gtg").subscribe({ + next(data) { + console.log(`🔋 Manabar threshold reached: ${data.manabarData.gtg?.[EManabarType.RC]?.percent}`); + }, + error: console.error +}); diff --git a/snippets/queenbee/account-management/on-accounts-metadata-change.ts b/snippets/queenbee/account-management/on-accounts-metadata-change.ts new file mode 100644 index 0000000..5e6f8af --- /dev/null +++ b/snippets/queenbee/account-management/on-accounts-metadata-change.ts @@ -0,0 +1,26 @@ +/* eslint-disable no-console */ +/** + * Category: 👤 Account Management + * Demo: onAccountsMetadataChange() — watch accounts for metadata updates. + * + * The onAccountsMetadataChange observer triggers when accounts update their + * profile data, posting keys, recovery accounts, or other metadata. + * + * Data Types & IDE IntelliSense: + * - Monitors account_update operations + * - `data`: Account update operation data + * - IDE shows all available account update properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for account metadata changes..."); + +bot.observe.onAccountsMetadataChange("gtg").subscribe({ + next() { + console.log("👤 Account metadata changed"); + }, + error: console.error +}); diff --git a/snippets/queenbee/account-management/on-impacted-accounts.ts b/snippets/queenbee/account-management/on-impacted-accounts.ts new file mode 100644 index 0000000..f097872 --- /dev/null +++ b/snippets/queenbee/account-management/on-impacted-accounts.ts @@ -0,0 +1,28 @@ +/* eslint-disable no-console */ +/** + * Category: 👤 Account Management + * Demo: onImpactedAccounts() — monitor all operations affecting accounts. + * + * The onImpactedAccounts observer triggers when ANY operation affects the + * specified accounts (transfers, votes received, mentions, follows, etc.). + * + * Data Types & IDE IntelliSense: + * - Comprehensive account activity monitoring + * - `data`: Impact data showing which operations affected the accounts + * - IDE shows all available impact properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for account impacts..."); + +bot.observe.onImpactedAccounts("gtg").subscribe({ + next(data) { + data.impactedAccounts.gtg?.forEach(({ operation }) => { + console.log(`💥 Account impacted in operation: ${operation}`); + }); + }, + error: console.error +}); diff --git a/snippets/queenbee/account-management/on-new-account.ts b/snippets/queenbee/account-management/on-new-account.ts new file mode 100644 index 0000000..3b7f87b --- /dev/null +++ b/snippets/queenbee/account-management/on-new-account.ts @@ -0,0 +1,28 @@ +/* eslint-disable no-console */ +/** + * Category: 👤 Account Management + * Demo: onNewAccount() — monitor newly created accounts. + * + * The onNewAccount observer triggers when new accounts are created on the + * blockchain via account_create or account_create_with_delegation operations. + * + * Data Types & IDE IntelliSense: + * - Monitors all new account creations without filtering + * - `data.newAccounts`: Array of newly created account data + * - IDE shows all available account creation properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for new accounts..."); + +bot.observe.onNewAccount().subscribe({ + next(data) { + data.newAccounts.forEach(account => { + console.log(`👶 New account created: - ${account.accountName} by ${account.creator}`); + }); + }, + error: console.error +}); diff --git a/snippets/queenbee/blockchain-infrastructure/on-block-number.ts b/snippets/queenbee/blockchain-infrastructure/on-block-number.ts new file mode 100644 index 0000000..75f7b71 --- /dev/null +++ b/snippets/queenbee/blockchain-infrastructure/on-block-number.ts @@ -0,0 +1,24 @@ +/* eslint-disable no-console */ +/** + * Category: ⚙️ Blockchain Infrastructure + * Demo: onBlockNumber() — wait for a specific upcoming block number. + * + * The onBlockNumber observer triggers when a specific block number is reached. + * Useful for scheduled operations, testing, or waiting for governance proposals. + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +// Wait for a future block (adjust this number as needed) +const targetBlock = 99999999; + +console.log(`⏳ Waiting for block #${targetBlock}...`); + +bot.observe.onBlockNumber(targetBlock).subscribe({ + next() { + console.log("🎯 Target block reached!"); + }, + error: console.error +}); diff --git a/snippets/queenbee/blockchain-infrastructure/on-block.ts b/snippets/queenbee/blockchain-infrastructure/on-block.ts new file mode 100644 index 0000000..d8f0d10 --- /dev/null +++ b/snippets/queenbee/blockchain-infrastructure/on-block.ts @@ -0,0 +1,27 @@ +/* eslint-disable no-console */ +/** + * Category: ⚙️ Blockchain Infrastructure + * Demo: onBlock() — logs new block headers for a short duration. + * + * This is the foundational snippet that demonstrates WorkerBee's core concepts. + * The onBlock observer triggers on every new block and provides block header data. + * + * Data Types & IDE IntelliSense: + * - `data.block.number` (number): Block height + * - `data.block.id` (string): Block hash identifier + * - `data.block.timestamp` (Date): When the block was produced + * - IDE shows all available block properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Listening for new blocks..."); + +bot.observe.onBlock().subscribe({ + next({ block }) { + console.log(`📦 Block #${block.number} id=${block.id} time=${block.timestamp}`); + }, + error: console.error +}); diff --git a/snippets/queenbee/blockchain-infrastructure/on-transaction-ids.ts b/snippets/queenbee/blockchain-infrastructure/on-transaction-ids.ts new file mode 100644 index 0000000..0105666 --- /dev/null +++ b/snippets/queenbee/blockchain-infrastructure/on-transaction-ids.ts @@ -0,0 +1,27 @@ +/* eslint-disable no-console */ +/** + * Category: ⚙️ Blockchain Infrastructure + * Demo: onTransactionIds() — monitor specific transaction IDs. + * + * The onTransactionIds observer triggers when specific transaction IDs + * appear on the blockchain. Useful for tracking specific transactions. + * + * Data Types & IDE IntelliSense: + * - `transactionIds` (string[]): Transaction IDs to monitor + * - `data.transactions`: Transaction data when IDs are found + * - IDE shows all available transaction properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for specific transaction IDs..."); + +// Example transaction ID (replace with actual ones) +bot.observe.onTransactionIds("example-tx-id-1").subscribe({ + next(data) { + console.log(`🔍 Transaction found: ${data.transactions["example-tx-id-1"]}`); + }, + error: console.error +}); diff --git a/snippets/queenbee/financial-operations/on-accounts-balance-change.ts b/snippets/queenbee/financial-operations/on-accounts-balance-change.ts new file mode 100644 index 0000000..9ffb4c7 --- /dev/null +++ b/snippets/queenbee/financial-operations/on-accounts-balance-change.ts @@ -0,0 +1,26 @@ +/* eslint-disable no-console */ +/** + * Category: 🏦 Financial Operations + * Demo: onAccountsBalanceChange() — monitor account balance updates. + * + * The onAccountsBalanceChange observer triggers when account balances change + * due to transfers, rewards, or other financial operations. + * + * Data Types & IDE IntelliSense: + * - `includeInternal` (boolean): Whether to include internal balance changes + * - `data`: Balance change data for the affected accounts + * - IDE shows all available balance change properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for balance changes..."); + +bot.observe.onAccountsBalanceChange(true, "gtg").subscribe({ + next() { + console.log("💰 Balance changed"); + }, + error: console.error +}); diff --git a/snippets/queenbee/financial-operations/on-exchange-transfer.ts b/snippets/queenbee/financial-operations/on-exchange-transfer.ts new file mode 100644 index 0000000..b594b1d --- /dev/null +++ b/snippets/queenbee/financial-operations/on-exchange-transfer.ts @@ -0,0 +1,28 @@ +/* eslint-disable no-console */ +/** + * Category: 🏦 Financial Operations + * Demo: onExchangeTransfer() — monitor transfers to/from known exchanges. + * + * The onExchangeTransfer observer triggers when transfers involve known exchange + * accounts. WorkerBee maintains a list of known exchanges automatically. + * + * Data Types & IDE IntelliSense: + * - Monitors both deposits to and withdrawals from exchanges + * - `data.exchangeTransferOperations`: Array of exchange transfer operations + * - IDE shows all available exchange transfer properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for exchange transfers..."); + +bot.observe.onExchangeTransfer().subscribe({ + next(data) { + data.exchangeTransferOperations.forEach(({ operation }) => { + console.log(`🏦 Exchange transfer: ${operation.from} -> ${operation.to} (${operation.amount})`); + }); + }, + error: console.error +}); diff --git a/snippets/queenbee/financial-operations/on-feed-price-change.ts b/snippets/queenbee/financial-operations/on-feed-price-change.ts new file mode 100644 index 0000000..3ff47a5 --- /dev/null +++ b/snippets/queenbee/financial-operations/on-feed-price-change.ts @@ -0,0 +1,26 @@ +/* eslint-disable no-console */ +/** + * Category: 🏦 Financial Operations + * Demo: onFeedPriceChange() — monitor when feed price changes by percentage. + * + * The onFeedPriceChange observer triggers when the Hive price feed changes + * by a specified percentage threshold. + * + * Data Types & IDE IntelliSense: + * - `percentThreshold` (number): Minimum percentage change to trigger + * - `data`: Price change information with old/new values + * - IDE shows all available price data properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for price changes (5%+)..."); + +bot.observe.onFeedPriceChange(5).subscribe({ + next() { + console.log("📈 Price changed"); + }, + error: console.error +}); diff --git a/snippets/queenbee/financial-operations/on-feed-price-no-change.ts b/snippets/queenbee/financial-operations/on-feed-price-no-change.ts new file mode 100644 index 0000000..8696e05 --- /dev/null +++ b/snippets/queenbee/financial-operations/on-feed-price-no-change.ts @@ -0,0 +1,26 @@ +/* eslint-disable no-console */ +/** + * Category: 🏦 Financial Operations + * Demo: onFeedPriceNoChange() — monitor when feed price stays stable. + * + * The onFeedPriceNoChange observer triggers when the Hive price feed + * remains stable (unchanged) for a specified number of hours. + * + * Data Types & IDE IntelliSense: + * - `hours` (number): Number of hours of price stability to monitor + * - `data`: Price stability information + * - IDE shows all available stability data properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for price stability (24h+)..."); + +bot.observe.onFeedPriceNoChange(24).subscribe({ + next() { + console.log("🧊 Price stable for 24h"); + }, + error: console.error +}); diff --git a/snippets/queenbee/financial-operations/on-internal-market-operation.ts b/snippets/queenbee/financial-operations/on-internal-market-operation.ts new file mode 100644 index 0000000..7efb2b6 --- /dev/null +++ b/snippets/queenbee/financial-operations/on-internal-market-operation.ts @@ -0,0 +1,28 @@ +/* eslint-disable no-console */ +/** + * Category: 🏦 Financial Operations + * Demo: onInternalMarketOperation() — monitor internal market activity. + * + * The onInternalMarketOperation observer monitors the Hive internal market + * for limit order creation, cancellation, and order fills. + * + * Data Types & IDE IntelliSense: + * - Monitors HIVE ↔ HBD trading activity + * - `data`: Internal market operation data + * - IDE shows all available market operation properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for internal market operations..."); + +bot.observe.onInternalMarketOperation().subscribe({ + next(data) { + data.internalMarketOperations.forEach(({ operation }) => { + console.log(`🏪 Market operation: ${operation.owner}, ${operation.orderId}, ${operation.cancel}`); + }); + }, + error: console.error +}); diff --git a/snippets/queenbee/financial-operations/on-whale-alert.ts b/snippets/queenbee/financial-operations/on-whale-alert.ts new file mode 100644 index 0000000..ee244c1 --- /dev/null +++ b/snippets/queenbee/financial-operations/on-whale-alert.ts @@ -0,0 +1,31 @@ +/* eslint-disable no-console */ +/** + * Category: 🏦 Financial Operations + * Demo: onWhaleAlert() — monitor large transfers above a threshold. + * + * The onWhaleAlert observer triggers when transfers exceed a specified amount + * threshold, useful for monitoring large financial movements. + * + * Data Types & IDE IntelliSense: + * - Uses asset objects created by `bot.chain.hiveCoins(amount)` + * - `data.whaleOperations`: Array of large transfer operations + * - IDE shows all available whale operation properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +// Monitor transfers of 1000 HIVE or more +const threshold = bot.chain!.hiveCoins(1000); + +console.log("⏳ Watching for whale transfers (1000+ HIVE)..."); + +bot.observe.onWhaleAlert(threshold).subscribe({ + next(data) { + data.whaleOperations.forEach(({ operation }) => { + console.log(`🐋 Whale alert: ${operation.from} -> ${operation.to} (${operation.amount})`); + }); + }, + error: console.error +}); diff --git a/snippets/queenbee/security-and-governance/on-alarm.ts b/snippets/queenbee/security-and-governance/on-alarm.ts new file mode 100644 index 0000000..95dc13e --- /dev/null +++ b/snippets/queenbee/security-and-governance/on-alarm.ts @@ -0,0 +1,28 @@ +/* eslint-disable no-console */ +/** + * Category: 🔐 Security & Governance + * Demo: onAlarm() — monitor governance and security alarms. + * + * The onAlarm observer triggers on various governance and security events + * like recovery account changes, governance votes, and witness actions. + * + * Data Types & IDE IntelliSense: + * - Monitors governance and security events for specified accounts + * - `data.alarmsPerAccount`: Account-specific alarm information + * - IDE shows all available alarm properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for governance alarms..."); + +bot.observe.onAlarm("gtg").subscribe({ + next(data) { + data.alarmsPerAccount.gtg?.forEach(alarm => { + console.log(`🚨 Governance alarm: ${alarm}`); + }) + }, + error: console.error +}); diff --git a/snippets/queenbee/security-and-governance/on-witnesses-missed-blocks.ts b/snippets/queenbee/security-and-governance/on-witnesses-missed-blocks.ts new file mode 100644 index 0000000..4212f26 --- /dev/null +++ b/snippets/queenbee/security-and-governance/on-witnesses-missed-blocks.ts @@ -0,0 +1,26 @@ +/* eslint-disable no-console */ +/** + * Category: 🔐 Security & Governance + * Demo: onWitnessesMissedBlocks() — monitor when witnesses miss blocks. + * + * The onWitnessesMissedBlocks observer triggers when specified witnesses + * miss a certain number of blocks, useful for monitoring network health. + * + * Data Types & IDE IntelliSense: + * - `missedCount` (number): Number of missed blocks to trigger on + * - `data`: Witness missed block information + * - IDE shows all available witness data properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for witnesses missing blocks..."); + +bot.observe.onWitnessesMissedBlocks(1, "gtg").subscribe({ + next() { + console.log("🧭 Witness missed blocks"); + }, + error: console.error +}); diff --git a/snippets/queenbee/social-and-content/on-comments-incoming-payout.ts b/snippets/queenbee/social-and-content/on-comments-incoming-payout.ts new file mode 100644 index 0000000..55cddd8 --- /dev/null +++ b/snippets/queenbee/social-and-content/on-comments-incoming-payout.ts @@ -0,0 +1,30 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onCommentsIncomingPayout() — monitor comments near payout window. + * + * The onCommentsIncomingPayout observer triggers when comments by specified + * authors are approaching their payout window (7 days after creation). + * + * Data Types & IDE IntelliSense: + * - `relative` (string): Time window like "-30m" for last 30 minutes + * - `data.commentsMetadata`: Comment payout information by author + * - IDE shows all available payout properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for comments near payout..."); + +bot.observe.onCommentsIncomingPayout("-30m", "gtg").subscribe({ + next(data) { + for(const account in data.commentsMetadata) + if(data.commentsMetadata[account] !== undefined) + for(const permlink of data.commentsMetadata[account]) + console.log("Comment about to payout:", data.commentsMetadata[account][permlink]); + + }, + error: console.error +}); diff --git a/snippets/queenbee/social-and-content/on-comments.ts b/snippets/queenbee/social-and-content/on-comments.ts new file mode 100644 index 0000000..4f15254 --- /dev/null +++ b/snippets/queenbee/social-and-content/on-comments.ts @@ -0,0 +1,40 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onComments() — log new comments by authors. + * + * The onComments observer monitors new comment creation on the Hive blockchain: + * - Filters by specific author account names + * - Captures replies to posts and nested comment threads + * - Real-time conversation and engagement tracking + * + * This snippet demonstrates: + * - Author-specific comment monitoring using account filters + * - Automatic provision of comment data by WorkerBee (content, parent info, etc.) + * - Comment thread analysis and engagement metrics + * + * Data Types & IDE IntelliSense: + * - `author` (string): The account that created the comment + * - `permlink` (string): Unique identifier for the comment + * - `body`: Comment content text + * - `parent_author` and `parent_permlink`: The post or comment being replied to + * - `json_metadata`: Additional metadata and app information + * - IDE will show all available comment properties via IntelliSense + * + * Cross-reference: See on-posts.ts for original post monitoring + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for new comments..."); + +bot.observe.onComments("gtg").subscribe({ + next(data) { + data.comments.gtg?.forEach(({ operation }) => { + console.log(`💬 New comment detected: ${operation.author}/${operation.permlink}`); + }); + }, + error: console.error +}); diff --git a/snippets/queenbee/social-and-content/on-custom-operation.ts b/snippets/queenbee/social-and-content/on-custom-operation.ts new file mode 100644 index 0000000..a8d029b --- /dev/null +++ b/snippets/queenbee/social-and-content/on-custom-operation.ts @@ -0,0 +1,26 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onCustomOperation() — monitor custom JSON operations by ID. + * + * The onCustomOperation observer triggers when custom_json operations with + * specified IDs occur. Used by dApps and games like Splinterlands, PeakD, etc. + * + * Data Types & IDE IntelliSense: + * - `ids` (string[]): Custom operation IDs to monitor (e.g., "follow", "reblog") + * - `data.customOperations`: Custom operations grouped by ID + * - IDE shows all available custom operation properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for custom operations..."); + +bot.observe.onCustomOperation("follow", "reblog", "sm_claim_reward").subscribe({ + next(data) { + console.log("🔧 Custom operation detected:", data); + }, + error: console.error +}); diff --git a/snippets/queenbee/social-and-content/on-follow.ts b/snippets/queenbee/social-and-content/on-follow.ts new file mode 100644 index 0000000..4e1657d --- /dev/null +++ b/snippets/queenbee/social-and-content/on-follow.ts @@ -0,0 +1,25 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onFollow() — watch follow/mute/blacklist events emitted by accounts. + * + * The onFollow observer monitors social graph changes on the Hive blockchain: + * - Follow actions (adding someone to your following list) + * - Mute actions (blocking content from specific accounts) + * - Blacklist actions (more severe blocking) + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for follow events..."); + +bot.observe.onFollow("gtg").subscribe({ + next(data) { + data.follows.gtg?.forEach(({ operation }) => { + console.log(`🧭 Follow event: @${operation.follower} followed @${operation.following}`); + }); + }, + error: console.error +}); diff --git a/snippets/queenbee/social-and-content/on-mention.ts b/snippets/queenbee/social-and-content/on-mention.ts new file mode 100644 index 0000000..71d11d6 --- /dev/null +++ b/snippets/queenbee/social-and-content/on-mention.ts @@ -0,0 +1,25 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onMention() — detect account mentions in posts/comments. + * + * The onMention observer monitors when specific accounts are mentioned: + * - Detects @username mentions in post and comment content + * - Tracks social interactions and notifications + * - Essential for social engagement applications + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for mentions..."); + +bot.observe.onMention("gtg").subscribe({ + next(data) { + data.mentioned.gtg?.forEach(comment => { + console.log(`📣 Mention detected: @${comment.author} mentioned @gtg`); + }); + }, + error: console.error +}); diff --git a/snippets/queenbee/social-and-content/on-posts-incoming-payout.ts b/snippets/queenbee/social-and-content/on-posts-incoming-payout.ts new file mode 100644 index 0000000..e497ab3 --- /dev/null +++ b/snippets/queenbee/social-and-content/on-posts-incoming-payout.ts @@ -0,0 +1,29 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onPostsIncomingPayout() — monitor posts near payout window. + * + * The onPostsIncomingPayout observer triggers when posts by specified + * authors are approaching their payout window (7 days after creation). + * + * Data Types & IDE IntelliSense: + * - `relative` (string): Time window like "-1h" for last hour + * - `data.postsMetadata`: Post payout information by author + * - IDE shows all available payout properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for posts near payout..."); + +bot.observe.onPostsIncomingPayout("-1h", "gtg").subscribe({ + next(data) { + for(const account in data.postsMetadata) + if(data.postsMetadata[account] !== undefined) + for(const permlink of data.postsMetadata[account]) + console.log("Post about to payout:", data.postsMetadata[account][permlink]); + }, + error: console.error +}); diff --git a/snippets/queenbee/social-and-content/on-posts.ts b/snippets/queenbee/social-and-content/on-posts.ts new file mode 100644 index 0000000..fe5d324 --- /dev/null +++ b/snippets/queenbee/social-and-content/on-posts.ts @@ -0,0 +1,30 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onPosts() — monitor new posts by specific authors. + * + * The onPosts observer monitors new post creation on the Hive blockchain. + * Filters by specific author account names and captures complete post data. + * + * Data Types & IDE IntelliSense: + * - `operation.author` (string): The account that created the post + * - `operation.permlink` (string): Unique identifier for the post + * - `operation.title` and `operation.body`: Post content and title text + * - `operation.json_metadata`: Additional metadata (tags, app info, etc.) + * - IDE shows all available post properties via IntelliSense + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for new posts..."); + +bot.observe.onPosts("gtg").subscribe({ + next(data) { + data.posts.gtg?.forEach(({ operation }) => { + console.log(`📝 New post detected: ${operation.author}/${operation.permlink}`); + }); + }, + error: console.error +}); diff --git a/snippets/queenbee/social-and-content/on-reblog.ts b/snippets/queenbee/social-and-content/on-reblog.ts new file mode 100644 index 0000000..89e5892 --- /dev/null +++ b/snippets/queenbee/social-and-content/on-reblog.ts @@ -0,0 +1,25 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onReblog() — watch reblog actions by accounts. + * + * The onReblog observer monitors when accounts reblog (share/repost) content: + * - Detects when specified accounts reblog posts + * - Captures both the reblogger and original author information + * - Real-time reblog activity tracking for content distribution analysis + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for reblogs..."); + +bot.observe.onReblog("gtg").subscribe({ + next(data) { + data.reblogs.gtg?.forEach(({ operation }) => { + console.log(`🔁 Reblog detected: @${operation.account} reblogged @${operation.author}/${operation.permlink}`); + }); + }, + error: console.error +}); diff --git a/snippets/queenbee/social-and-content/on-votes.ts b/snippets/queenbee/social-and-content/on-votes.ts new file mode 100644 index 0000000..caec5b9 --- /dev/null +++ b/snippets/queenbee/social-and-content/on-votes.ts @@ -0,0 +1,29 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onVotes() — monitor voting activity by specific accounts. + * + * The onVotes observer monitors voting activity on the Hive blockchain. + * Tracks upvotes and downvotes by specific accounts with voting details. + * + * Data Types & IDE IntelliSense: + * - `operation.voter` (string): The account that cast the vote + * - `operation.author` and `operation.permlink`: The post/comment being voted on + * - `operation.weight` (number): Vote strength (-10000 to +10000) + * - Positive weight = upvote, negative weight = downvote + */ +import WorkerBee from "../../../src"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for votes..."); + +bot.observe.onVotes("gtg").subscribe({ + next(data) { + data.votes.gtg?.forEach(({ operation }) => { + console.log(`👍 @${operation.voter} voted: ${operation.author}/${operation.permlink} (weight: ${operation.weight})`); + }); + }, + error: console.error +}); -- GitLab From 24dfe7e78b0f13b5199d0599485efa4dae2fa1fe Mon Sep 17 00:00:00 2001 From: fwaszkiewicz Date: Wed, 20 Aug 2025 14:48:19 +0200 Subject: [PATCH 2/2] fixup! Add code snippets --- .../on-accounts-full-manabar.ts | 32 ++++++++++----- .../on-accounts-manabar-percent.ts | 32 ++++++++++----- .../on-accounts-metadata-change.ts | 22 ++++++---- .../on-impacted-accounts.ts | 31 +++++++++----- .../account-management/on-new-account.ts | 23 +++++++---- .../on-block-number.ts | 16 +++++++- .../blockchain-infrastructure/on-block.ts | 25 +++++++---- .../on-transaction-ids.ts | 30 +++++++++----- .../on-accounts-balance-change.ts | 24 +++++++---- .../on-exchange-transfer.ts | 23 +++++++---- .../on-feed-price-change.ts | 21 ++++++---- .../on-feed-price-no-change.ts | 19 +++++---- .../on-internal-market-operation.ts | 25 +++++++---- .../financial-operations/on-whale-alert.ts | 28 +++++++++---- .../security-and-governance/on-alarm.ts | 34 ++++++++++----- .../on-witnesses-missed-blocks.ts | 26 ++++++++---- .../on-comments-incoming-payout.ts | 29 ++++++++----- .../social-and-content/on-comments.ts | 41 +++++++++---------- .../social-and-content/on-custom-operation.ts | 34 +++++++++++---- .../queenbee/social-and-content/on-follow.ts | 31 ++++++++++---- .../queenbee/social-and-content/on-mention.ts | 31 ++++++++++---- .../on-posts-incoming-payout.ts | 28 ++++++++----- .../queenbee/social-and-content/on-posts.ts | 35 ++++++++++------ .../queenbee/social-and-content/on-reblog.ts | 28 +++++++++---- .../queenbee/social-and-content/on-votes.ts | 33 +++++++++------ 25 files changed, 467 insertions(+), 234 deletions(-) diff --git a/snippets/queenbee/account-management/on-accounts-full-manabar.ts b/snippets/queenbee/account-management/on-accounts-full-manabar.ts index 5457d71..eb3b074 100644 --- a/snippets/queenbee/account-management/on-accounts-full-manabar.ts +++ b/snippets/queenbee/account-management/on-accounts-full-manabar.ts @@ -3,27 +3,37 @@ * Category: 👤 Account Management * Demo: onAccountsFullManabar() — notify when accounts reach 98% manabar. * - * The onAccountsFullManabar observer monitors manabar levels and triggers - * when any specified account reaches 98% (full) manabar capacity. + * This observer monitors manabar levels and triggers when any specified account reaches 98% manabar capacity. + * You can specify a manabar kind to be monitored (expressed by values of {@link EManabarType}). + * Multiple account names can be observed at single observer call. * - * Data Types & IDE IntelliSense: - * - `EManabarType.RC`: Resource Credits for transactions - * - `EManabarType.VOTING`: Voting power - * - `EManabarType.DOWNVOTING`: Downvoting power - * - `data.account`: Account name that reached full manabar - * - `data.percentage`: Current manabar percentage + * Filter Function Inputs: + * - `manabarType: EManabarType` - The type of manabar to monitor (RC, UPVOTE, or DOWNVOTE) + * - `...accounts: TAccountName[]` - Account names to monitor for full manabar + * + * Callback Data: + * The callback receives data of type {@link IManabarProviderData}, + * which is automatically deduced from the set of configured filters. */ import { EManabarType } from "@hiveio/wax"; -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for accounts with full RC manabar..."); -bot.observe.onAccountsFullManabar(EManabarType.RC, "gtg").subscribe({ +bot.observe.onAccountsFullManabar(EManabarType.RC, "guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when either guest4test or guest4test1 reaches 98% RC manabar. + * The callback receives data of type {@link IManabarProviderData}, which includes: + * - `data.manabarData` - Contains manabar information for each monitored account + * The callback receives data for all monitored account even if only one reaches 98% manabar. + * The rest of the accounts will point to undefined so you should check for their existence before accessing their properties. + */ next(data) { - console.log(`⚡ Account gtg has ${data.manabarData.gtg?.[EManabarType.RC]?.percent}% RC manabar!`); + if (data.manabarData.guest4test) + console.log(`⚡ Account guest4test has ${data.manabarData.guest4test?.[EManabarType.RC]?.percent}% RC manabar!`); }, error: console.error }); diff --git a/snippets/queenbee/account-management/on-accounts-manabar-percent.ts b/snippets/queenbee/account-management/on-accounts-manabar-percent.ts index 56b384a..26f3655 100644 --- a/snippets/queenbee/account-management/on-accounts-manabar-percent.ts +++ b/snippets/queenbee/account-management/on-accounts-manabar-percent.ts @@ -3,26 +3,38 @@ * Category: 👤 Account Management * Demo: onAccountsManabarPercent() — watch for manabar threshold percentage. * - * The onAccountsManabarPercent observer triggers when accounts reach a specific - * manabar percentage threshold. Simple monitoring without complex logic. + * This observer triggers when accounts reach a specific manabar percentage threshold. + * You can specify a manabar kind to be monitored (expressed by values of {@link EManabarType}). + * Multiple account names can be observed at single observer call. * - * Data Types & IDE IntelliSense: - * - `EManabarType.RC`: Resource Credits for transactions - * - `EManabarType.VOTING`: Voting power - * - `data.manabarData`: Account manabar information - * - IDE shows all available manabar properties via IntelliSense + * Filter Function Inputs: + * - `manabarType: EManabarType` - The type of manabar to monitor (RC, UPVOTE, or DOWNVOTE) + * - `percent: number` - The percentage threshold to trigger on (0-100) + * - `...accounts: TAccountName[]` - Account names to monitor for threshold + * + * Callback Data: + * The callback receives data of type {@link IManabarProviderData}, + * which is automatically deduced from the set of configured filters. */ import { EManabarType } from "@hiveio/wax"; -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for accounts with 90%+ RC manabar..."); -bot.observe.onAccountsManabarPercent(EManabarType.RC, 90, "gtg").subscribe({ +bot.observe.onAccountsManabarPercent(EManabarType.RC, 90, "guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when either guest4test or guest4test1 reaches 90% RC manabar. + * The callback receives data of type {@link IManabarProviderData}, which includes: + * - `data.manabarData` - Contains manabar information for each monitored account + * The callback receives data for all monitored accounts even if only one reaches the threshold. + * The rest of the accounts will point to undefined so you should check for their existence before accessing their properties. + */ next(data) { - console.log(`🔋 Manabar threshold reached: ${data.manabarData.gtg?.[EManabarType.RC]?.percent}`); + if (data.manabarData.guest4test) + console.log(`🔋 Account guest4test has ${data.manabarData.guest4test?.[EManabarType.RC]?.percent}% RC manabar!`); }, error: console.error }); diff --git a/snippets/queenbee/account-management/on-accounts-metadata-change.ts b/snippets/queenbee/account-management/on-accounts-metadata-change.ts index 5e6f8af..0b11f34 100644 --- a/snippets/queenbee/account-management/on-accounts-metadata-change.ts +++ b/snippets/queenbee/account-management/on-accounts-metadata-change.ts @@ -3,22 +3,28 @@ * Category: 👤 Account Management * Demo: onAccountsMetadataChange() — watch accounts for metadata updates. * - * The onAccountsMetadataChange observer triggers when accounts update their - * profile data, posting keys, recovery accounts, or other metadata. + * This observer triggers when accounts update their profile data, posting keys, + * recovery accounts, or other metadata via account_update operations. + * Multiple account names can be observed at single observer call. * - * Data Types & IDE IntelliSense: - * - Monitors account_update operations - * - `data`: Account update operation data - * - IDE shows all available account update properties via IntelliSense + * Filter Function Inputs: + * - `...accounts: TAccountName[]` - Account names to monitor for metadata changes + * + * There is no callback data for this observer. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for account metadata changes..."); -bot.observe.onAccountsMetadataChange("gtg").subscribe({ +bot.observe.onAccountsMetadataChange("guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when guest4test or guest4test1 updates their account metadata. + * Account metadata changes include profile updates, posting key changes, recovery account changes, etc. + * There is no callback data for this observer - it simply notifies when any of monitored accounts change the metadata. + */ next() { console.log("👤 Account metadata changed"); }, diff --git a/snippets/queenbee/account-management/on-impacted-accounts.ts b/snippets/queenbee/account-management/on-impacted-accounts.ts index f097872..18a7ae9 100644 --- a/snippets/queenbee/account-management/on-impacted-accounts.ts +++ b/snippets/queenbee/account-management/on-impacted-accounts.ts @@ -3,25 +3,36 @@ * Category: 👤 Account Management * Demo: onImpactedAccounts() — monitor all operations affecting accounts. * - * The onImpactedAccounts observer triggers when ANY operation affects the - * specified accounts (transfers, votes received, mentions, follows, etc.). + * This observer triggers when ANY operation affects the specified accounts + * (transfers, votes received, mentions, follows, etc.). This provides comprehensive + * account activity monitoring across all operation types. * - * Data Types & IDE IntelliSense: - * - Comprehensive account activity monitoring - * - `data`: Impact data showing which operations affected the accounts - * - IDE shows all available impact properties via IntelliSense + * Filter Function Inputs: + * - `...accounts: TAccountName[]` - Account names to monitor for any activity + * + * Callback Data: + * The callback receives data of type {@link IImpactedAccountProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for account impacts..."); -bot.observe.onImpactedAccounts("gtg").subscribe({ +bot.observe.onImpactedAccounts("guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when guest4test or guest4test1 is affected by any blockchain operation. + * The callback receives data of type {@link IImpactedAccountProviderData}, which includes: + * - `data.impactedAccounts` - Contains operations that impacted each monitored account + * Each account's data contains arrays of operation-transaction pairs affecting that account. + * The callback receives data for all monitored accounts even if only one is impacted, + * but the content for account that is not impacted will be undefined. + */ next(data) { - data.impactedAccounts.gtg?.forEach(({ operation }) => { - console.log(`💥 Account impacted in operation: ${operation}`); + data.impactedAccounts.guest4test?.forEach(({ operation }) => { + console.log(`💥 Account guest4test impacted in operation: ${operation}`); }); }, error: console.error diff --git a/snippets/queenbee/account-management/on-new-account.ts b/snippets/queenbee/account-management/on-new-account.ts index 3b7f87b..f31969b 100644 --- a/snippets/queenbee/account-management/on-new-account.ts +++ b/snippets/queenbee/account-management/on-new-account.ts @@ -3,15 +3,18 @@ * Category: 👤 Account Management * Demo: onNewAccount() — monitor newly created accounts. * - * The onNewAccount observer triggers when new accounts are created on the - * blockchain via account_create or account_create_with_delegation operations. + * This observer triggers when new accounts are created on the blockchain via + * account_create or account_create_with_delegation operations. No input parameters + * required as it monitors all new account creations. * - * Data Types & IDE IntelliSense: - * - Monitors all new account creations without filtering - * - `data.newAccounts`: Array of newly created account data - * - IDE shows all available account creation properties via IntelliSense + * Filter Function Inputs: + * - No parameters required (monitors all new account creations) + * + * Callback Data: + * The callback receives data of type {@link INewAccountProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); @@ -19,6 +22,12 @@ await bot.start(); console.log("⏳ Watching for new accounts..."); bot.observe.onNewAccount().subscribe({ + /* + * This observer will trigger when any new account is created on the blockchain. + * The callback receives data of type {@link INewAccountProviderData}, which includes: + * - `data.newAccounts` - Array of newly created account data with account details + * Each new account object contains information like accountName, creator, and creation details. + */ next(data) { data.newAccounts.forEach(account => { console.log(`👶 New account created: - ${account.accountName} by ${account.creator}`); diff --git a/snippets/queenbee/blockchain-infrastructure/on-block-number.ts b/snippets/queenbee/blockchain-infrastructure/on-block-number.ts index 75f7b71..8527785 100644 --- a/snippets/queenbee/blockchain-infrastructure/on-block-number.ts +++ b/snippets/queenbee/blockchain-infrastructure/on-block-number.ts @@ -3,10 +3,15 @@ * Category: ⚙️ Blockchain Infrastructure * Demo: onBlockNumber() — wait for a specific upcoming block number. * - * The onBlockNumber observer triggers when a specific block number is reached. + * This observer triggers when a specific block number is reached. * Useful for scheduled operations, testing, or waiting for governance proposals. + * + * Filter Function Inputs: + * - `blockNumber: number` - The specific block number to wait for + * + * There is no callback data for this observer. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); @@ -17,6 +22,13 @@ const targetBlock = 99999999; console.log(`⏳ Waiting for block #${targetBlock}...`); bot.observe.onBlockNumber(targetBlock).subscribe({ + /* + * This observer will trigger when the blockchain reaches the specified block number. + * Useful for scheduled operations, testing, or waiting for governance proposals. + * There is no callback data for this observer - it simply notifies when the target block is reached. + * The main concept of this observer is to observe for specific block without a need of calling get_block API + * This is why the block header data is also not available in the callback. + */ next() { console.log("🎯 Target block reached!"); }, diff --git a/snippets/queenbee/blockchain-infrastructure/on-block.ts b/snippets/queenbee/blockchain-infrastructure/on-block.ts index d8f0d10..d04d295 100644 --- a/snippets/queenbee/blockchain-infrastructure/on-block.ts +++ b/snippets/queenbee/blockchain-infrastructure/on-block.ts @@ -4,15 +4,17 @@ * Demo: onBlock() — logs new block headers for a short duration. * * This is the foundational snippet that demonstrates WorkerBee's core concepts. - * The onBlock observer triggers on every new block and provides block header data. + * The observer triggers on every new block and provides comprehensive block header data. + * No input parameters required as it monitors all blocks. * - * Data Types & IDE IntelliSense: - * - `data.block.number` (number): Block height - * - `data.block.id` (string): Block hash identifier - * - `data.block.timestamp` (Date): When the block was produced - * - IDE shows all available block properties via IntelliSense + * Filter Function Inputs: + * - No parameters required (monitors all new blocks) + * + * Callback Data: + * The callback receives data of type {@link IBlockHeaderProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); @@ -20,8 +22,13 @@ await bot.start(); console.log("⏳ Listening for new blocks..."); bot.observe.onBlock().subscribe({ - next({ block }) { - console.log(`📦 Block #${block.number} id=${block.id} time=${block.timestamp}`); + /* + * This observer will trigger on every new block produced on the blockchain. + * The callback receives data of type {@link IBlockHeaderProviderData}, which includes: + * - `data.block` - Contains complete block header information like id, number and timestamp + */ + next(data) { + console.log(`📦 Block #${data.block.number} id=${data.block.id} time=${data.block.timestamp}`); }, error: console.error }); diff --git a/snippets/queenbee/blockchain-infrastructure/on-transaction-ids.ts b/snippets/queenbee/blockchain-infrastructure/on-transaction-ids.ts index 0105666..d842038 100644 --- a/snippets/queenbee/blockchain-infrastructure/on-transaction-ids.ts +++ b/snippets/queenbee/blockchain-infrastructure/on-transaction-ids.ts @@ -3,25 +3,35 @@ * Category: ⚙️ Blockchain Infrastructure * Demo: onTransactionIds() — monitor specific transaction IDs. * - * The onTransactionIds observer triggers when specific transaction IDs - * appear on the blockchain. Useful for tracking specific transactions. + * This observer triggers when specific transaction IDs appear on the blockchain. + * Useful for tracking specific transactions and their inclusion in blocks. * - * Data Types & IDE IntelliSense: - * - `transactionIds` (string[]): Transaction IDs to monitor - * - `data.transactions`: Transaction data when IDs are found - * - IDE shows all available transaction properties via IntelliSense + * Filter Function Inputs: + * - `...transactionIds: string[]` - Transaction IDs to monitor + * + * Callback Data: + * The callback receives data of type {@link ITransactionProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for specific transaction IDs..."); -// Example transaction ID (replace with actual ones) -bot.observe.onTransactionIds("example-tx-id-1").subscribe({ +// Example transaction IDs (replace with actual ones) +bot.observe.onTransactionIds("example-tx-id-1", "example-tx-id-2").subscribe({ + /* + * This observer will trigger when any of the specified transaction IDs appear on the blockchain. + * The callback receives data of type {@link ITransactionProviderData}, which includes: + * - `data.transactions` - Contains transaction data for each found transaction ID + * All transaction IDs will be present in the data object, but those not found will have undefined values. + * You should check for the existence of each transaction before accessing its properties when observing multiple IDs. + */ next(data) { - console.log(`🔍 Transaction found: ${data.transactions["example-tx-id-1"]}`); + if (data.transactions["example-tx-id-1"]) + console.log("🔍 Transaction found: example-tx-id-1"); }, error: console.error }); diff --git a/snippets/queenbee/financial-operations/on-accounts-balance-change.ts b/snippets/queenbee/financial-operations/on-accounts-balance-change.ts index 9ffb4c7..1202646 100644 --- a/snippets/queenbee/financial-operations/on-accounts-balance-change.ts +++ b/snippets/queenbee/financial-operations/on-accounts-balance-change.ts @@ -3,22 +3,30 @@ * Category: 🏦 Financial Operations * Demo: onAccountsBalanceChange() — monitor account balance updates. * - * The onAccountsBalanceChange observer triggers when account balances change - * due to transfers, rewards, or other financial operations. + * This observer triggers when account balances change due to transfers, rewards, + * or other financial operations. You can specify whether to include internal + * balance changes and monitor multiple accounts. * - * Data Types & IDE IntelliSense: - * - `includeInternal` (boolean): Whether to include internal balance changes - * - `data`: Balance change data for the affected accounts - * - IDE shows all available balance change properties via IntelliSense + * Filter Function Inputs: + * - `includeInternal: boolean` - Whether to include internal balance changes + * - `...accounts: TAccountName[]` - Account names to monitor for balance changes + * + * Callback Data: + * There is no callback data for this observer. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for balance changes..."); -bot.observe.onAccountsBalanceChange(true, "gtg").subscribe({ +bot.observe.onAccountsBalanceChange(true, "guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when guest4test or guest4test1 has a balance change. + * Balance changes include transfers, rewards, power ups/downs, and savings operations. + * There is no callback data for this observer - it simply notifies when the change in any of monitored accounts occurs. + */ next() { console.log("💰 Balance changed"); }, diff --git a/snippets/queenbee/financial-operations/on-exchange-transfer.ts b/snippets/queenbee/financial-operations/on-exchange-transfer.ts index b594b1d..cf47e64 100644 --- a/snippets/queenbee/financial-operations/on-exchange-transfer.ts +++ b/snippets/queenbee/financial-operations/on-exchange-transfer.ts @@ -3,15 +3,18 @@ * Category: 🏦 Financial Operations * Demo: onExchangeTransfer() — monitor transfers to/from known exchanges. * - * The onExchangeTransfer observer triggers when transfers involve known exchange - * accounts. WorkerBee maintains a list of known exchanges automatically. + * This observer triggers when transfers involve known exchange accounts. + * WorkerBee maintains a list of known exchanges automatically, monitoring + * both deposits to and withdrawals from these exchange accounts. * - * Data Types & IDE IntelliSense: - * - Monitors both deposits to and withdrawals from exchanges - * - `data.exchangeTransferOperations`: Array of exchange transfer operations - * - IDE shows all available exchange transfer properties via IntelliSense + * Filter Function Inputs: + * - No parameters required (monitors all transfers involving known exchanges) + * + * Callback Data: + * The callback receives data of type {@link IExchangeTransferProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); @@ -19,6 +22,12 @@ await bot.start(); console.log("⏳ Watching for exchange transfers..."); bot.observe.onExchangeTransfer().subscribe({ + /* + * This observer will trigger when transfers involve known exchange accounts. + * The callback receives data of type {@link IExchangeTransferProviderData}, which includes: + * - `data.exchangeTransferOperations` - Array of transfer-operation pairs involving exchanges + * Each transaction/operation contains transfer details with standard hive transfer properties. + */ next(data) { data.exchangeTransferOperations.forEach(({ operation }) => { console.log(`🏦 Exchange transfer: ${operation.from} -> ${operation.to} (${operation.amount})`); diff --git a/snippets/queenbee/financial-operations/on-feed-price-change.ts b/snippets/queenbee/financial-operations/on-feed-price-change.ts index 3ff47a5..f185a75 100644 --- a/snippets/queenbee/financial-operations/on-feed-price-change.ts +++ b/snippets/queenbee/financial-operations/on-feed-price-change.ts @@ -3,15 +3,16 @@ * Category: 🏦 Financial Operations * Demo: onFeedPriceChange() — monitor when feed price changes by percentage. * - * The onFeedPriceChange observer triggers when the Hive price feed changes - * by a specified percentage threshold. + * This observer triggers when the Hive price feed changes by a specified percentage + * threshold. Useful for monitoring significant market movements and price volatility. * - * Data Types & IDE IntelliSense: - * - `percentThreshold` (number): Minimum percentage change to trigger - * - `data`: Price change information with old/new values - * - IDE shows all available price data properties via IntelliSense + * Filter Function Inputs: + * - `percentThreshold: number` - Minimum percentage change required to trigger (e.g., 5 for 5%) + * + * Callback Data: + * The callback receives no data. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); @@ -19,8 +20,12 @@ await bot.start(); console.log("⏳ Watching for price changes (5%+)..."); bot.observe.onFeedPriceChange(5).subscribe({ + /* + * This observer will trigger when the Hive price feed changes by 5% or more. + * The callback receives no data. + */ next() { - console.log("📈 Price changed"); + console.log("📈 Price changed by 5%+"); }, error: console.error }); diff --git a/snippets/queenbee/financial-operations/on-feed-price-no-change.ts b/snippets/queenbee/financial-operations/on-feed-price-no-change.ts index 8696e05..e0ac178 100644 --- a/snippets/queenbee/financial-operations/on-feed-price-no-change.ts +++ b/snippets/queenbee/financial-operations/on-feed-price-no-change.ts @@ -3,15 +3,16 @@ * Category: 🏦 Financial Operations * Demo: onFeedPriceNoChange() — monitor when feed price stays stable. * - * The onFeedPriceNoChange observer triggers when the Hive price feed - * remains stable (unchanged) for a specified number of hours. + * This observer triggers when the Hive price feed remains stable (unchanged) + * for a specified number of hours. Useful for detecting periods of low volatility. * - * Data Types & IDE IntelliSense: - * - `hours` (number): Number of hours of price stability to monitor - * - `data`: Price stability information - * - IDE shows all available stability data properties via IntelliSense + * Filter Function Inputs: + * - `hours: number` - Number of hours of required price stability to trigger + * + * Callback Data: + * The callback receives no data. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); @@ -19,6 +20,10 @@ await bot.start(); console.log("⏳ Watching for price stability (24h+)..."); bot.observe.onFeedPriceNoChange(24).subscribe({ + /* + * This observer will trigger when the Hive price feed remains stable for 24 hours. + * The callback receives no data. + */ next() { console.log("🧊 Price stable for 24h"); }, diff --git a/snippets/queenbee/financial-operations/on-internal-market-operation.ts b/snippets/queenbee/financial-operations/on-internal-market-operation.ts index 7efb2b6..b653635 100644 --- a/snippets/queenbee/financial-operations/on-internal-market-operation.ts +++ b/snippets/queenbee/financial-operations/on-internal-market-operation.ts @@ -3,15 +3,18 @@ * Category: 🏦 Financial Operations * Demo: onInternalMarketOperation() — monitor internal market activity. * - * The onInternalMarketOperation observer monitors the Hive internal market - * for limit order creation, cancellation, and order fills. + * This observer monitors the Hive internal market for limit order creation, + * cancellation, and order fills. Tracks HIVE ↔ HBD trading activity on the + * built-in decentralized exchange. * - * Data Types & IDE IntelliSense: - * - Monitors HIVE ↔ HBD trading activity - * - `data`: Internal market operation data - * - IDE shows all available market operation properties via IntelliSense + * Filter Function Inputs: + * - No parameters required (monitors all internal market operations) + * + * Callback Data: + * The callback receives data of type {@link IInternalMarketProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); @@ -19,9 +22,15 @@ await bot.start(); console.log("⏳ Watching for internal market operations..."); bot.observe.onInternalMarketOperation().subscribe({ + /* + * This observer will trigger when internal market operations occur (order create/cancel/fill). + * The callback receives data of type {@link IInternalMarketProviderData}, which includes: + * - `data.internalMarketOperations` - Array of market transaction/operation pairs (create/cancel/fill) + * Each transaction/operation follows either {@link IInternalMarketCreateOperation}. + */ next(data) { data.internalMarketOperations.forEach(({ operation }) => { - console.log(`🏪 Market operation: ${operation.owner}, ${operation.orderId}, ${operation.cancel}`); + console.log(`🏪 Market operation: ${operation.owner}, order ${operation.orderId}`); }); }, error: console.error diff --git a/snippets/queenbee/financial-operations/on-whale-alert.ts b/snippets/queenbee/financial-operations/on-whale-alert.ts index ee244c1..8d88322 100644 --- a/snippets/queenbee/financial-operations/on-whale-alert.ts +++ b/snippets/queenbee/financial-operations/on-whale-alert.ts @@ -3,25 +3,37 @@ * Category: 🏦 Financial Operations * Demo: onWhaleAlert() — monitor large transfers above a threshold. * - * The onWhaleAlert observer triggers when transfers exceed a specified amount - * threshold, useful for monitoring large financial movements. + * This observer triggers when transfers exceed a specified amount threshold, + * useful for monitoring large financial movements on the blockchain. + * The threshold can be specified for any supported asset type. * - * Data Types & IDE IntelliSense: - * - Uses asset objects created by `bot.chain.hiveCoins(amount)` - * - `data.whaleOperations`: Array of large transfer operations - * - IDE shows all available whale operation properties via IntelliSense + * Filter Function Inputs: + * - `threshold: asset` - Minimum transfer amount to trigger alert (use bot.chain.hiveCoins() or similar) + * + * Callback Data: + * The callback receives data of type {@link IWhaleAlertProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); -// Monitor transfers of 1000 HIVE or more +/* + * Monitor transfers of 1000 HIVE or more + * Remember that chain is available only after calling `start` method. + */ const threshold = bot.chain!.hiveCoins(1000); console.log("⏳ Watching for whale transfers (1000+ HIVE)..."); bot.observe.onWhaleAlert(threshold).subscribe({ + /* + * This observer will trigger when any transfer exceeds the specified threshold amount. + * The callback receives data of type {@link IWhaleAlertProviderData}, which includes: + * - `data.whaleOperations` - Array of large transfer transaction-operation pairs exceeding the threshold + * You can access each transaction/operation that contains details like from, to, amount, and memo. + */ next(data) { data.whaleOperations.forEach(({ operation }) => { console.log(`🐋 Whale alert: ${operation.from} -> ${operation.to} (${operation.amount})`); diff --git a/snippets/queenbee/security-and-governance/on-alarm.ts b/snippets/queenbee/security-and-governance/on-alarm.ts index 95dc13e..e68a5df 100644 --- a/snippets/queenbee/security-and-governance/on-alarm.ts +++ b/snippets/queenbee/security-and-governance/on-alarm.ts @@ -3,26 +3,38 @@ * Category: 🔐 Security & Governance * Demo: onAlarm() — monitor governance and security alarms. * - * The onAlarm observer triggers on various governance and security events - * like recovery account changes, governance votes, and witness actions. + * This observer triggers on various governance and security events like recovery + * account changes, governance votes, witness actions, and other security-related + * operations. Multiple accounts can be monitored simultaneously. * - * Data Types & IDE IntelliSense: - * - Monitors governance and security events for specified accounts - * - `data.alarmsPerAccount`: Account-specific alarm information - * - IDE shows all available alarm properties via IntelliSense + * Filter Function Inputs: + * - `...accounts: TAccountName[]` - Account names to monitor for security and governance events + * + * Callback Data: + * The callback receives data of type {@link IAlarmAccountsData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for governance alarms..."); -bot.observe.onAlarm("gtg").subscribe({ +bot.observe.onAlarm("guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when security or governance events occur for guest4test or guest4test1. + * The callback receives data of type {@link IAlarmAccountsData}, which includes: + * - `data.alarmsPerAccount` - Contains alarm information grouped by account + * Each account's alarms follow the {@link TAlarmAccounts} structure with {@link EAlarmType} categorization. + */ next(data) { - data.alarmsPerAccount.gtg?.forEach(alarm => { - console.log(`🚨 Governance alarm: ${alarm}`); - }) + data.alarmsPerAccount.guest4test?.forEach(alarm => { + console.log(`🚨 Governance alarm for guest4test: ${alarm}`); + }); + data.alarmsPerAccount.guest4test1?.forEach(alarm => { + console.log(`🚨 Governance alarm for guest4test1: ${alarm}`); + }); }, error: console.error }); diff --git a/snippets/queenbee/security-and-governance/on-witnesses-missed-blocks.ts b/snippets/queenbee/security-and-governance/on-witnesses-missed-blocks.ts index 4212f26..a2d8c74 100644 --- a/snippets/queenbee/security-and-governance/on-witnesses-missed-blocks.ts +++ b/snippets/queenbee/security-and-governance/on-witnesses-missed-blocks.ts @@ -3,24 +3,32 @@ * Category: 🔐 Security & Governance * Demo: onWitnessesMissedBlocks() — monitor when witnesses miss blocks. * - * The onWitnessesMissedBlocks observer triggers when specified witnesses - * miss a certain number of blocks, useful for monitoring network health. + * This observer triggers when specified witnesses miss a certain number of blocks. + * Essential for monitoring network health and witness performance. Can track + * multiple witnesses simultaneously. * - * Data Types & IDE IntelliSense: - * - `missedCount` (number): Number of missed blocks to trigger on - * - `data`: Witness missed block information - * - IDE shows all available witness data properties via IntelliSense + * Filter Function Inputs: + * - `missedCount: number` - Number of missed blocks required to trigger + * - `...witnesses: TAccountName[]` - Witness account names to monitor for missed blocks + * + * Callback Data: + * There is no callback data for this observer. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for witnesses missing blocks..."); -bot.observe.onWitnessesMissedBlocks(1, "gtg").subscribe({ +bot.observe.onWitnessesMissedBlocks(1, "guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when guest4test or guest4test1 (as witnesses) miss 1 or more blocks. + * This filter monitors witness performance and network health by tracking missed block production. + * There is no callback data for this observer - it simply notifies when the threshold is reached. + */ next() { - console.log("🧭 Witness missed blocks"); + console.log("🧭 A witness has missed blocks"); }, error: console.error }); diff --git a/snippets/queenbee/social-and-content/on-comments-incoming-payout.ts b/snippets/queenbee/social-and-content/on-comments-incoming-payout.ts index 55cddd8..49476f1 100644 --- a/snippets/queenbee/social-and-content/on-comments-incoming-payout.ts +++ b/snippets/queenbee/social-and-content/on-comments-incoming-payout.ts @@ -3,28 +3,35 @@ * Category: 👥 Social & Content * Demo: onCommentsIncomingPayout() — monitor comments near payout window. * - * The onCommentsIncomingPayout observer triggers when comments by specified - * authors are approaching their payout window (7 days after creation). + * This observer triggers when comments by specified authors are approaching their + * payout window (7 days after creation). Useful for monitoring comment earnings + * and engagement performance before final payout. Multiple authors can be monitored simultaneously. * - * Data Types & IDE IntelliSense: - * - `relative` (string): Time window like "-30m" for last 30 minutes - * - `data.commentsMetadata`: Comment payout information by author - * - IDE shows all available payout properties via IntelliSense + * Filter Function Inputs: + * - `relative: string` - Time window specification (e.g., "-30m" for last 30 minutes before payout) + * - `...authors: TAccountName[]` - Author account names to monitor for upcoming comment payouts + * + * Callback Data: + * The callback receives data of type {@link ICommentMetadataProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for comments near payout..."); -bot.observe.onCommentsIncomingPayout("-30m", "gtg").subscribe({ +bot.observe.onCommentsIncomingPayout("-30m", "guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when comments by guest4test or guest4test1 are 30 minutes away from payout. + * The callback receives data of type {@link ICommentMetadataProviderData}, similar to the structure used in other comment-related events. + */ next(data) { for(const account in data.commentsMetadata) if(data.commentsMetadata[account] !== undefined) - for(const permlink of data.commentsMetadata[account]) - console.log("Comment about to payout:", data.commentsMetadata[account][permlink]); - + for(const permlink in data.commentsMetadata[account]) + console.log(`⏰ Comment about to payout: @${account}/${permlink}`); }, error: console.error }); diff --git a/snippets/queenbee/social-and-content/on-comments.ts b/snippets/queenbee/social-and-content/on-comments.ts index 4f15254..d4a30dd 100644 --- a/snippets/queenbee/social-and-content/on-comments.ts +++ b/snippets/queenbee/social-and-content/on-comments.ts @@ -3,38 +3,35 @@ * Category: 👥 Social & Content * Demo: onComments() — log new comments by authors. * - * The onComments observer monitors new comment creation on the Hive blockchain: - * - Filters by specific author account names - * - Captures replies to posts and nested comment threads - * - Real-time conversation and engagement tracking + * This observer monitors new comment creation on the Hive blockchain. Filters by + * specific author account names and captures replies to posts and nested comment + * threads. Multiple authors can be monitored at single observer call. * - * This snippet demonstrates: - * - Author-specific comment monitoring using account filters - * - Automatic provision of comment data by WorkerBee (content, parent info, etc.) - * - Comment thread analysis and engagement metrics + * Filter Function Inputs: + * - `...authors: TAccountName[]` - Author account names to monitor for new comments * - * Data Types & IDE IntelliSense: - * - `author` (string): The account that created the comment - * - `permlink` (string): Unique identifier for the comment - * - `body`: Comment content text - * - `parent_author` and `parent_permlink`: The post or comment being replied to - * - `json_metadata`: Additional metadata and app information - * - IDE will show all available comment properties via IntelliSense - * - * Cross-reference: See on-posts.ts for original post monitoring + * Callback Data: + * The callback receives data of type {@link ICommentProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for new comments..."); -bot.observe.onComments("gtg").subscribe({ +bot.observe.onComments("guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when guest4test or guest4test1 creates a new comment. + * See on-posts.ts for more details on how observing comment_operation works. + * In this case, the callback will occur for comment_operation with not empty parent_author property. + */ next(data) { - data.comments.gtg?.forEach(({ operation }) => { - console.log(`💬 New comment detected: ${operation.author}/${operation.permlink}`); - }); + if (data.comments.guest4test) + data.comments.guest4test?.forEach(({ operation }) => { + console.log(`💬 New comment by guest4test: ${operation.author}/${operation.permlink}`); + }); }, error: console.error }); diff --git a/snippets/queenbee/social-and-content/on-custom-operation.ts b/snippets/queenbee/social-and-content/on-custom-operation.ts index a8d029b..6456c2c 100644 --- a/snippets/queenbee/social-and-content/on-custom-operation.ts +++ b/snippets/queenbee/social-and-content/on-custom-operation.ts @@ -3,15 +3,18 @@ * Category: 👥 Social & Content * Demo: onCustomOperation() — monitor custom JSON operations by ID. * - * The onCustomOperation observer triggers when custom_json operations with - * specified IDs occur. Used by dApps and games like Splinterlands, PeakD, etc. + * This observer triggers when custom_json operations with specified IDs occur. + * Used extensively by dApps and games like Splinterlands, PeakD, and other + * applications building on Hive. Multiple operation IDs can be monitored simultaneously. * - * Data Types & IDE IntelliSense: - * - `ids` (string[]): Custom operation IDs to monitor (e.g., "follow", "reblog") - * - `data.customOperations`: Custom operations grouped by ID - * - IDE shows all available custom operation properties via IntelliSense + * Filter Function Inputs: + * - `...ids: Array` - Custom operation IDs to monitor (e.g., "follow", "reblog", "sm_claim_reward") + * + * Callback Data: + * The callback receives data of type {@link ICustomOperationProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); @@ -19,8 +22,23 @@ await bot.start(); console.log("⏳ Watching for custom operations..."); bot.observe.onCustomOperation("follow", "reblog", "sm_claim_reward").subscribe({ + /* + * This observer will trigger when custom operations with the specified IDs occur. + * The callback receives data of type {@link ICustomOperationProviderData}, which includes: + * - `data.customOperations` - Contains custom operations grouped by operation name + * Each operation contains an array with transaction/operation pairs. + */ next(data) { - console.log("🔧 Custom operation detected:", data); + if (data.customOperations.follow) + data.customOperations.follow.forEach(({ operation }) => { + console.log(`🔧 Follow operation detected: ${operation}`); + }); + + if (data.customOperations.reblog) + console.log(`🔧 Reblog operations detected: ${data.customOperations.reblog.length}`); + + if (data.customOperations.sm_claim_reward) + console.log(`🔧 Splinterlands reward claims detected: ${data.customOperations.sm_claim_reward.length}`); }, error: console.error }); diff --git a/snippets/queenbee/social-and-content/on-follow.ts b/snippets/queenbee/social-and-content/on-follow.ts index 4e1657d..3a96c9c 100644 --- a/snippets/queenbee/social-and-content/on-follow.ts +++ b/snippets/queenbee/social-and-content/on-follow.ts @@ -3,23 +3,36 @@ * Category: 👥 Social & Content * Demo: onFollow() — watch follow/mute/blacklist events emitted by accounts. * - * The onFollow observer monitors social graph changes on the Hive blockchain: - * - Follow actions (adding someone to your following list) - * - Mute actions (blocking content from specific accounts) - * - Blacklist actions (more severe blocking) + * This observer monitors social graph changes on the Hive blockchain including + * follow actions, mute actions, and blacklist actions. Tracks relationship changes + * between accounts. Multiple accounts can be monitored simultaneously. + * + * Filter Function Inputs: + * - `...accounts: TAccountName[]` - Account names to monitor for follow/mute/blacklist activity + * + * Callback Data: + * The callback receives data of type {@link IFollowProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for follow events..."); -bot.observe.onFollow("gtg").subscribe({ +bot.observe.onFollow("guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when guest4test or guest4test1 performs follow/mute/blacklist actions. + * The callback receives data of type {@link IFollowProviderData}, which includes: + * - `data.follows` - Contains follow transaction/operation pairs grouped by account + * Remember to check if follows for specific account actually exist when observing multiple accounts. + */ next(data) { - data.follows.gtg?.forEach(({ operation }) => { - console.log(`🧭 Follow event: @${operation.follower} followed @${operation.following}`); - }); + if (data.follows.guest4test) + data.follows.guest4test?.forEach(({ operation }) => { + console.log(`🧭 Follow event by guest4test: @${operation.follower} -> @${operation.following} (${operation.what})`); + }); }, error: console.error }); diff --git a/snippets/queenbee/social-and-content/on-mention.ts b/snippets/queenbee/social-and-content/on-mention.ts index 71d11d6..b8f1ade 100644 --- a/snippets/queenbee/social-and-content/on-mention.ts +++ b/snippets/queenbee/social-and-content/on-mention.ts @@ -3,22 +3,37 @@ * Category: 👥 Social & Content * Demo: onMention() — detect account mentions in posts/comments. * - * The onMention observer monitors when specific accounts are mentioned: - * - Detects @username mentions in post and comment content - * - Tracks social interactions and notifications - * - Essential for social engagement applications + * This observer monitors when specific accounts are mentioned in post and comment + * content using @username syntax. Essential for social engagement applications + * and notification systems. Multiple accounts can be monitored simultaneously. + * + * Filter Function Inputs: + * - `...accounts: TAccountName[]` - Account names to monitor for mentions + * + * Callback Data: + * The callback receives data of type {@link IMentionedAccountProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for mentions..."); -bot.observe.onMention("gtg").subscribe({ +bot.observe.onMention("guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when guest4test or guest4test1 is mentioned in content. + * The callback receives data of type {@link IMentionedAccountProviderData}, which includes: + * - `data.mentioned` - Contains mention instances (comment_operation) grouped by mentioned account + * Remember to check if mentions for specific account actually exist when observing multiple accounts. + */ next(data) { - data.mentioned.gtg?.forEach(comment => { - console.log(`📣 Mention detected: @${comment.author} mentioned @gtg`); + data.mentioned.guest4test?.forEach(comment => { + console.log(`📣 @guest4test mentioned by @${comment.author}`); + }); + data.mentioned.guest4test1?.forEach(comment => { + console.log(`📣 @guest4test1 mentioned by @${comment.author}`); }); }, error: console.error diff --git a/snippets/queenbee/social-and-content/on-posts-incoming-payout.ts b/snippets/queenbee/social-and-content/on-posts-incoming-payout.ts index e497ab3..8b832b2 100644 --- a/snippets/queenbee/social-and-content/on-posts-incoming-payout.ts +++ b/snippets/queenbee/social-and-content/on-posts-incoming-payout.ts @@ -3,27 +3,35 @@ * Category: 👥 Social & Content * Demo: onPostsIncomingPayout() — monitor posts near payout window. * - * The onPostsIncomingPayout observer triggers when posts by specified - * authors are approaching their payout window (7 days after creation). + * This observer triggers when posts by specified authors are approaching their + * payout window (7 days after creation). Useful for monitoring earnings and + * content performance before final payout. Multiple authors can be monitored simultaneously. * - * Data Types & IDE IntelliSense: - * - `relative` (string): Time window like "-1h" for last hour - * - `data.postsMetadata`: Post payout information by author - * - IDE shows all available payout properties via IntelliSense + * Filter Function Inputs: + * - `relative: string` - Time window specification (e.g., "-1h" for last hour before payout) + * - `...authors: TAccountName[]` - Author account names to monitor for upcoming payouts + * + * Callback Data: + * The callback receives data of type {@link IPostMetadataProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for posts near payout..."); -bot.observe.onPostsIncomingPayout("-1h", "gtg").subscribe({ +bot.observe.onPostsIncomingPayout("-1h", "guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when posts by guest4test or guest4test1 are 1 hour away from payout. + * The callback receives data of type {@link IPostMetadataProviderData}, similar to the structure used in other post-related events. + */ next(data) { for(const account in data.postsMetadata) if(data.postsMetadata[account] !== undefined) - for(const permlink of data.postsMetadata[account]) - console.log("Post about to payout:", data.postsMetadata[account][permlink]); + for(const permlink in data.postsMetadata[account]) + console.log(`⏰ Post about to payout: @${account}/${permlink}`); }, error: console.error }); diff --git a/snippets/queenbee/social-and-content/on-posts.ts b/snippets/queenbee/social-and-content/on-posts.ts index fe5d324..da96449 100644 --- a/snippets/queenbee/social-and-content/on-posts.ts +++ b/snippets/queenbee/social-and-content/on-posts.ts @@ -3,28 +3,37 @@ * Category: 👥 Social & Content * Demo: onPosts() — monitor new posts by specific authors. * - * The onPosts observer monitors new post creation on the Hive blockchain. - * Filters by specific author account names and captures complete post data. + * This observer monitors new post creation on the Hive blockchain. Filters by + * specific author account names and captures complete operations/transactions. + * Multiple authors can be monitored at single observer call. * - * Data Types & IDE IntelliSense: - * - `operation.author` (string): The account that created the post - * - `operation.permlink` (string): Unique identifier for the post - * - `operation.title` and `operation.body`: Post content and title text - * - `operation.json_metadata`: Additional metadata (tags, app info, etc.) - * - IDE shows all available post properties via IntelliSense + * Filter Function Inputs: + * - `...authors: TAccountName[]` - Author account names to monitor for new posts + * + * Callback Data: + * The callback receives data of type {@link IPostProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for new posts..."); -bot.observe.onPosts("gtg").subscribe({ +bot.observe.onPosts("guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when guest4test or guest4test1 creates a new post. + * The callback receives data of type {@link IPostProviderData}, which includes: + * - `data.posts` - Contains post operations/transactions (hive comment_operation with empty parent_author property) + * Remember to check if content for specific author actually exists when observing multiple authors. + */ next(data) { - data.posts.gtg?.forEach(({ operation }) => { - console.log(`📝 New post detected: ${operation.author}/${operation.permlink}`); - }); + if (data.posts.guest4test) + data.posts.guest4test.forEach(({ operation }) => { + console.log(`📝 New post by guest4test: ${operation.author}/${operation.permlink}`); + }); + }, error: console.error }); diff --git a/snippets/queenbee/social-and-content/on-reblog.ts b/snippets/queenbee/social-and-content/on-reblog.ts index 89e5892..10c97b6 100644 --- a/snippets/queenbee/social-and-content/on-reblog.ts +++ b/snippets/queenbee/social-and-content/on-reblog.ts @@ -3,22 +3,34 @@ * Category: 👥 Social & Content * Demo: onReblog() — watch reblog actions by accounts. * - * The onReblog observer monitors when accounts reblog (share/repost) content: - * - Detects when specified accounts reblog posts - * - Captures both the reblogger and original author information - * - Real-time reblog activity tracking for content distribution analysis + * This observer monitors when accounts reblog (share/repost) content. Captures + * both the reblogger and original author information for content distribution + * analysis. Multiple accounts can be monitored simultaneously. + * + * Filter Function Inputs: + * - `...accounts: TAccountName[]` - Account names to monitor for reblog activity + * + * Callback Data: + * The callback receives data of type {@link IReblogProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for reblogs..."); -bot.observe.onReblog("gtg").subscribe({ +bot.observe.onReblog("guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when guest4test or guest4test1 reblogs content. + * The callback receives data of type {@link IReblogProviderData}, which includes: + * - `data.reblogs` - Contains reblog (comment_operation) transaction/operation pairs grouped by reblogger account + * Remember to check if reblogs for specific account actually exist when observing multiple accounts. + */ next(data) { - data.reblogs.gtg?.forEach(({ operation }) => { - console.log(`🔁 Reblog detected: @${operation.account} reblogged @${operation.author}/${operation.permlink}`); + data.reblogs.guest4test?.forEach(({ operation }) => { + console.log(`🔁 guest4test reblogged: @${operation.author}/${operation.permlink}`); }); }, error: console.error diff --git a/snippets/queenbee/social-and-content/on-votes.ts b/snippets/queenbee/social-and-content/on-votes.ts index caec5b9..cb08514 100644 --- a/snippets/queenbee/social-and-content/on-votes.ts +++ b/snippets/queenbee/social-and-content/on-votes.ts @@ -3,27 +3,36 @@ * Category: 👥 Social & Content * Demo: onVotes() — monitor voting activity by specific accounts. * - * The onVotes observer monitors voting activity on the Hive blockchain. - * Tracks upvotes and downvotes by specific accounts with voting details. + * This observer monitors voting activity on the Hive blockchain. Tracks upvotes + * and downvotes by specific accounts with detailed voting information including + * vote weight and target content. Multiple voters can be monitored simultaneously. * - * Data Types & IDE IntelliSense: - * - `operation.voter` (string): The account that cast the vote - * - `operation.author` and `operation.permlink`: The post/comment being voted on - * - `operation.weight` (number): Vote strength (-10000 to +10000) - * - Positive weight = upvote, negative weight = downvote + * Filter Function Inputs: + * - `...voters: TAccountName[]` - Voter account names to monitor for voting activity + * + * Callback Data: + * The callback receives data of type {@link IVoteProviderData}, + * which is automatically deduced from the set of configured filters. */ -import WorkerBee from "../../../src"; +import WorkerBee from "@hiveio/workerbee"; const bot = new WorkerBee(); await bot.start(); console.log("⏳ Watching for votes..."); -bot.observe.onVotes("gtg").subscribe({ +bot.observe.onVotes("guest4test", "guest4test1").subscribe({ + /* + * This observer will trigger when guest4test or guest4test1 casts a vote. + * The callback receives data of type {@link IVoteProviderData}, which includes: + * - `data.votes` - Contains vote transaction/operation pairs grouped by voter + * Remember to check if votes for specific voter actually exist when observing multiple voters. + */ next(data) { - data.votes.gtg?.forEach(({ operation }) => { - console.log(`👍 @${operation.voter} voted: ${operation.author}/${operation.permlink} (weight: ${operation.weight})`); - }); + if (data.votes.guest4test) + data.votes.guest4test?.forEach(({ operation }) => { + console.log(`👍 @guest4test voted: ${operation.author}/${operation.permlink} (weight: ${operation.weight})`); + }); }, error: console.error }); -- GitLab