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 0000000000000000000000000000000000000000..eb3b074ccf66011c56d4745b73b35f4464f3d2d7 --- /dev/null +++ b/snippets/queenbee/account-management/on-accounts-full-manabar.ts @@ -0,0 +1,39 @@ +/* eslint-disable no-console */ +/** + * Category: 👤 Account Management + * Demo: onAccountsFullManabar() — notify when accounts reach 98% manabar. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for accounts with full RC manabar..."); + +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) { + 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 new file mode 100644 index 0000000000000000000000000000000000000000..26f36552847d09276d683798381f1c6094c5829f --- /dev/null +++ b/snippets/queenbee/account-management/on-accounts-manabar-percent.ts @@ -0,0 +1,40 @@ +/* eslint-disable no-console */ +/** + * Category: 👤 Account Management + * Demo: onAccountsManabarPercent() — watch for manabar threshold percentage. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for accounts with 90%+ RC manabar..."); + +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) { + 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 new file mode 100644 index 0000000000000000000000000000000000000000..0b11f34ad94b307a4cfecfb33dba1da42994005e --- /dev/null +++ b/snippets/queenbee/account-management/on-accounts-metadata-change.ts @@ -0,0 +1,32 @@ +/* eslint-disable no-console */ +/** + * Category: 👤 Account Management + * Demo: onAccountsMetadataChange() — watch accounts for metadata updates. + * + * 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. + * + * Filter Function Inputs: + * - `...accounts: TAccountName[]` - Account names to monitor for metadata changes + * + * There is no callback data for this observer. + */ +import WorkerBee from "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for account metadata changes..."); + +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"); + }, + 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 0000000000000000000000000000000000000000..18a7ae9507efb00839ea9cd1b353e5dda3e5a10b --- /dev/null +++ b/snippets/queenbee/account-management/on-impacted-accounts.ts @@ -0,0 +1,39 @@ +/* eslint-disable no-console */ +/** + * Category: 👤 Account Management + * Demo: onImpactedAccounts() — monitor all operations affecting accounts. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for account impacts..."); + +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.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 new file mode 100644 index 0000000000000000000000000000000000000000..f31969bfe16f94e264168e19d11838bab2d248bd --- /dev/null +++ b/snippets/queenbee/account-management/on-new-account.ts @@ -0,0 +1,37 @@ +/* eslint-disable no-console */ +/** + * Category: 👤 Account Management + * Demo: onNewAccount() — monitor newly created accounts. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +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}`); + }); + }, + 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 0000000000000000000000000000000000000000..85277851198f5e77a2903b826b8481d4100d747a --- /dev/null +++ b/snippets/queenbee/blockchain-infrastructure/on-block-number.ts @@ -0,0 +1,36 @@ +/* eslint-disable no-console */ +/** + * Category: ⚙️ Blockchain Infrastructure + * Demo: onBlockNumber() — wait for a specific upcoming block number. + * + * 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 "@hiveio/workerbee"; + +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({ + /* + * 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!"); + }, + 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 0000000000000000000000000000000000000000..d04d295ed7d49db642cea8ed156739f9f8e96e89 --- /dev/null +++ b/snippets/queenbee/blockchain-infrastructure/on-block.ts @@ -0,0 +1,34 @@ +/* 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 observer triggers on every new block and provides comprehensive block header data. + * No input parameters required as it monitors all blocks. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Listening for new blocks..."); + +bot.observe.onBlock().subscribe({ + /* + * 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 new file mode 100644 index 0000000000000000000000000000000000000000..d84203858b77104531958d82956da7c055e4ba4a --- /dev/null +++ b/snippets/queenbee/blockchain-infrastructure/on-transaction-ids.ts @@ -0,0 +1,37 @@ +/* eslint-disable no-console */ +/** + * Category: ⚙️ Blockchain Infrastructure + * Demo: onTransactionIds() — monitor specific transaction IDs. + * + * This observer triggers when specific transaction IDs appear on the blockchain. + * Useful for tracking specific transactions and their inclusion in blocks. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for specific transaction IDs..."); + +// 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) { + 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 new file mode 100644 index 0000000000000000000000000000000000000000..120264664cf96efeaa78a91d0bc7ceed8baee53a --- /dev/null +++ b/snippets/queenbee/financial-operations/on-accounts-balance-change.ts @@ -0,0 +1,34 @@ +/* eslint-disable no-console */ +/** + * Category: 🏦 Financial Operations + * Demo: onAccountsBalanceChange() — monitor account balance updates. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for balance changes..."); + +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"); + }, + 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 0000000000000000000000000000000000000000..cf47e64e976aa25973d02b3b6cdc6fdbf2626c40 --- /dev/null +++ b/snippets/queenbee/financial-operations/on-exchange-transfer.ts @@ -0,0 +1,37 @@ +/* eslint-disable no-console */ +/** + * Category: 🏦 Financial Operations + * Demo: onExchangeTransfer() — monitor transfers to/from known exchanges. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +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})`); + }); + }, + 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 0000000000000000000000000000000000000000..f185a7546eeda9ecd6d6d8ac2aaafdce43fe5c3d --- /dev/null +++ b/snippets/queenbee/financial-operations/on-feed-price-change.ts @@ -0,0 +1,31 @@ +/* eslint-disable no-console */ +/** + * Category: 🏦 Financial Operations + * Demo: onFeedPriceChange() — monitor when feed price changes by percentage. + * + * This observer triggers when the Hive price feed changes by a specified percentage + * threshold. Useful for monitoring significant market movements and price volatility. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +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 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 new file mode 100644 index 0000000000000000000000000000000000000000..e0ac178169d1b56b893aef440e877b564d1fe296 --- /dev/null +++ b/snippets/queenbee/financial-operations/on-feed-price-no-change.ts @@ -0,0 +1,31 @@ +/* eslint-disable no-console */ +/** + * Category: 🏦 Financial Operations + * Demo: onFeedPriceNoChange() — monitor when feed price stays stable. + * + * This observer triggers when the Hive price feed remains stable (unchanged) + * for a specified number of hours. Useful for detecting periods of low volatility. + * + * Filter Function Inputs: + * - `hours: number` - Number of hours of required price stability to trigger + * + * Callback Data: + * The callback receives no data. + */ +import WorkerBee from "@hiveio/workerbee"; + +const bot = new WorkerBee(); +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"); + }, + 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 0000000000000000000000000000000000000000..b65363596b09c3f2667fd2ae2b903f414a9b84df --- /dev/null +++ b/snippets/queenbee/financial-operations/on-internal-market-operation.ts @@ -0,0 +1,37 @@ +/* eslint-disable no-console */ +/** + * Category: 🏦 Financial Operations + * Demo: onInternalMarketOperation() — monitor internal market activity. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +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}, 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 new file mode 100644 index 0000000000000000000000000000000000000000..8d88322308daf54d1af87598c284dd82b21bca25 --- /dev/null +++ b/snippets/queenbee/financial-operations/on-whale-alert.ts @@ -0,0 +1,43 @@ +/* eslint-disable no-console */ +/** + * Category: 🏦 Financial Operations + * Demo: onWhaleAlert() — monitor large transfers above a threshold. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +/* + * 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})`); + }); + }, + 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 0000000000000000000000000000000000000000..e68a5df99a54e6a716257cbc3ab8eb3fea544664 --- /dev/null +++ b/snippets/queenbee/security-and-governance/on-alarm.ts @@ -0,0 +1,40 @@ +/* eslint-disable no-console */ +/** + * Category: 🔐 Security & Governance + * Demo: onAlarm() — monitor governance and security alarms. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for governance alarms..."); + +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.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 new file mode 100644 index 0000000000000000000000000000000000000000..a2d8c7407f4dd285d2dc364000d510fc4e303ef2 --- /dev/null +++ b/snippets/queenbee/security-and-governance/on-witnesses-missed-blocks.ts @@ -0,0 +1,34 @@ +/* eslint-disable no-console */ +/** + * Category: 🔐 Security & Governance + * Demo: onWitnessesMissedBlocks() — monitor when witnesses miss blocks. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for witnesses missing blocks..."); + +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("🧭 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 new file mode 100644 index 0000000000000000000000000000000000000000..49476f154aa56f8a38bfb8a884701c841e6cef94 --- /dev/null +++ b/snippets/queenbee/social-and-content/on-comments-incoming-payout.ts @@ -0,0 +1,37 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onCommentsIncomingPayout() — monitor comments near payout window. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for comments near payout..."); + +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 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 new file mode 100644 index 0000000000000000000000000000000000000000..d4a30dd59e6c3fd13ab3b3bf0b90a619c276c3bf --- /dev/null +++ b/snippets/queenbee/social-and-content/on-comments.ts @@ -0,0 +1,37 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onComments() — log new comments by authors. + * + * 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. + * + * Filter Function Inputs: + * - `...authors: TAccountName[]` - Author account names to monitor for new comments + * + * Callback Data: + * The callback receives data of type {@link ICommentProviderData}, + * which is automatically deduced from the set of configured filters. + */ +import WorkerBee from "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for new comments..."); + +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) { + 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 new file mode 100644 index 0000000000000000000000000000000000000000..6456c2cec6089655a4c33e21ace362b5b0855005 --- /dev/null +++ b/snippets/queenbee/social-and-content/on-custom-operation.ts @@ -0,0 +1,44 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onCustomOperation() — monitor custom JSON operations by ID. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +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) { + 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 new file mode 100644 index 0000000000000000000000000000000000000000..3a96c9c14c10865d64a78e749b0e17911d79e2f8 --- /dev/null +++ b/snippets/queenbee/social-and-content/on-follow.ts @@ -0,0 +1,38 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onFollow() — watch follow/mute/blacklist events emitted by accounts. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for follow events..."); + +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) { + 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 new file mode 100644 index 0000000000000000000000000000000000000000..b8f1adeb93ee4548a5d051f857f736a54d89a7af --- /dev/null +++ b/snippets/queenbee/social-and-content/on-mention.ts @@ -0,0 +1,40 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onMention() — detect account mentions in posts/comments. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for mentions..."); + +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.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 new file mode 100644 index 0000000000000000000000000000000000000000..8b832b28b7d7d23ca444d3b07476e1c903187a71 --- /dev/null +++ b/snippets/queenbee/social-and-content/on-posts-incoming-payout.ts @@ -0,0 +1,37 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onPostsIncomingPayout() — monitor posts near payout window. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for posts near payout..."); + +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 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 new file mode 100644 index 0000000000000000000000000000000000000000..da96449ad86fd564b383940264959e6d8f3ae9f4 --- /dev/null +++ b/snippets/queenbee/social-and-content/on-posts.ts @@ -0,0 +1,39 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onPosts() — monitor new posts by specific authors. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for new posts..."); + +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) { + 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 new file mode 100644 index 0000000000000000000000000000000000000000..10c97b6cad48669593ba7f13c0b59b813a6b8f3a --- /dev/null +++ b/snippets/queenbee/social-and-content/on-reblog.ts @@ -0,0 +1,37 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onReblog() — watch reblog actions by accounts. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for reblogs..."); + +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.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 new file mode 100644 index 0000000000000000000000000000000000000000..cb08514e6e32bb58301e628b6ffce0e14cc1b4ae --- /dev/null +++ b/snippets/queenbee/social-and-content/on-votes.ts @@ -0,0 +1,38 @@ +/* eslint-disable no-console */ +/** + * Category: 👥 Social & Content + * Demo: onVotes() — monitor voting activity by specific accounts. + * + * 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. + * + * 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 "@hiveio/workerbee"; + +const bot = new WorkerBee(); +await bot.start(); + +console.log("⏳ Watching for votes..."); + +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) { + if (data.votes.guest4test) + data.votes.guest4test?.forEach(({ operation }) => { + console.log(`👍 @guest4test voted: ${operation.author}/${operation.permlink} (weight: ${operation.weight})`); + }); + }, + error: console.error +});