Skip to content

Commit dc171b5

Browse files
committed
align more with original comments
1 parent d6bdb90 commit dc171b5

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

data-streams/getting-started/hardhat/tasks/emitLog.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ export const emitLog = task(
1717
{ logEmitter }: { logEmitter: string },
1818
hre: HardhatRuntimeEnvironment
1919
) => {
20-
// Connect to network and get the contract instance
2120
const { viem } = await hre.network.connect();
2221
const publicClient = await viem.getPublicClient();
23-
const logEmitterContract = await viem.getContractAt(
22+
23+
// Create an instance of the LogEmitter contract at the specified address.
24+
const LogEmitterContract = await viem.getContractAt(
2425
"LogEmitter",
2526
logEmitter as `0x${string}`
2627
);
@@ -29,14 +30,16 @@ export const emitLog = task(
2930
spinner.start("Emitting a log...");
3031

3132
try {
32-
// Call the emitLog function of the LogEmitter contract
33-
const hash = await logEmitterContract.write.emitLog();
33+
// Call the emitLog function of the LogEmitter contract to emit a log event.
34+
const tx = await LogEmitterContract.write.emitLog();
3435

35-
// Wait for the transaction to be mined
36-
await publicClient.waitForTransactionReceipt({ hash });
36+
// Wait for the transaction to be mined to ensure the log has been emitted.
37+
await publicClient.waitForTransactionReceipt({ hash: tx });
3738

38-
spinner.succeed(`Log emitted successfully in transaction: ${hash}`);
39+
// Stop the spinner with a success message, including the transaction hash.
40+
spinner.succeed(`Log emitted successfully in transaction: ${tx}`);
3941
} catch (error) {
42+
// In case of error, stop the spinner with a failure message.
4043
spinner.fail("Failed to emit log.");
4144
throw error;
4245
}

data-streams/getting-started/hardhat/tasks/getLastRetrievedPrice.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@ export const getLastPrice = task(
2525
`Retrieving the last price from StreamsUpkeep at ${streamsUpkeep}...`
2626
);
2727

28-
// Retrieve an instance of the StreamsUpkeep contract
28+
// Retrieve an instance of the StreamsUpkeep contract using the provided address.
29+
// This enables interaction with the contract's functions.
2930
const { viem } = await hre.network.connect();
30-
const contract = await viem.getContractAt(
31+
const StreamsUpkeepContract = await viem.getContractAt(
3132
"StreamsUpkeepRegistrar",
3233
streamsUpkeep as `0x${string}`
3334
);
3435

3536
try {
36-
// Call the automatically generated getter function for the lastDecodedPrice public state variable
37-
const lastDecodedPrice = await contract.read.lastDecodedPrice();
37+
// Call the automatically generated getter function for the lastDecodedPrice public state variable.
38+
const lastDecodedPrice =
39+
await StreamsUpkeepContract.read.lastDecodedPrice();
3840
spinner.succeed(`Last Retrieved Price: ${lastDecodedPrice}`);
3941
} catch (error) {
4042
spinner.fail("Failed to retrieve the last price.");

data-streams/getting-started/hardhat/tasks/registerAndFundLogUpkeep.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,47 @@ export const registerUpkeep = task(
3131
}: { streamsUpkeep: string; logEmitter: string },
3232
hre: HardhatRuntimeEnvironment
3333
) => {
34-
// Connect to network and get wallet client
3534
const { viem } = await hre.network.connect();
3635
const [walletClient] = await viem.getWalletClients();
37-
const account = walletClient.account.address;
3836

39-
// Define registration parameters for the upkeep
40-
const name = "Prog. Streams Upkeep";
41-
const encryptedEmail = "0x" as `0x${string}`;
42-
const gasLimit = 500000;
43-
const triggerType = 1; // Log Trigger
44-
const checkData = "0x" as `0x${string}`;
45-
const offchainConfig = "0x" as `0x${string}`;
46-
const amount = parseEther("1"); // 1 LINK
37+
// Retrieve the deployer's (admin's) signer object to sign transactions.
38+
const admin = walletClient.account.address;
4739

48-
// Event signature hash and placeholder topics for the LogEmitter trigger
40+
// Define registration parameters for the upkeep.
41+
// See more information on https://docs.chain.link/chainlink-automation/guides/register-upkeep-in-contract.
42+
const name = "Prog. Streams Upkeep"; // Name of the upkeep registration.
43+
const encryptedEmail = "0x" as `0x${string}`; // Placeholder for an encrypted email (optional).
44+
const gasLimit = 500000; // Maximum gas allowance for the upkeep execution.
45+
const triggerType = 1; // Type of trigger, where `1` represents a Log Trigger.
46+
const checkData = "0x" as `0x${string}`; // Data passed to checkUpkeep; placeholder in this context.
47+
const offchainConfig = "0x" as `0x${string}`; // Off-chain configuration data; placeholder in this context.
48+
const amount = parseEther("1"); // Funding amount in LINK tokens.
49+
50+
// Event signature hash and placeholder topics for the LogEmitter trigger.
4951
const topic0 =
50-
"0xb8a00d6d8ca1be30bfec34d8f97e55f0f0fd9eeb7fb46e030516363d4cfe1ad6";
52+
"0xb8a00d6d8ca1be30bfec34d8f97e55f0f0fd9eeb7fb46e030516363d4cfe1ad6"; // Event signature hash.
5153
const topic1 =
52-
"0x0000000000000000000000000000000000000000000000000000000000000000";
54+
"0x0000000000000000000000000000000000000000000000000000000000000000"; // Placeholder topics.
5355
const topic2 =
5456
"0x0000000000000000000000000000000000000000000000000000000000000000";
5557
const topic3 =
5658
"0x0000000000000000000000000000000000000000000000000000000000000000";
5759

58-
// ABI-encode the trigger configuration data
60+
// ABI-encode the trigger configuration data.
5961
const triggerConfig = encodeAbiParameters(
6062
parseAbiParameters(
6163
"address, uint8, bytes32, bytes32, bytes32, bytes32"
6264
),
6365
[logEmitter as `0x${string}`, 0, topic0, topic1, topic2, topic3]
6466
);
6567

66-
// Construct the parameters for registration
68+
// Construct the parameters for registration, combining all previously defined values.
6769
const params = {
6870
name,
6971
encryptedEmail,
7072
upkeepContract: streamsUpkeep as `0x${string}`,
7173
gasLimit,
72-
adminAddress: account,
74+
adminAddress: admin,
7375
triggerType,
7476
checkData,
7577
triggerConfig,
@@ -78,18 +80,17 @@ export const registerUpkeep = task(
7880
};
7981

8082
const spinner = spin();
83+
// Interact with the deployed StreamsUpkeep contract to register the upkeep.
8184
spinner.start(
82-
`Registering upkeep with Chainlink Automation using account: ${account}`
85+
`Registering upkeep with Chainlink Automation using account: ${admin}`
8386
);
84-
85-
// Interact with the deployed StreamsUpkeep contract to register the upkeep
86-
const streamsUpkeepContract = await viem.getContractAt(
87+
const StreamsUpkeepContract = await viem.getContractAt(
8788
"StreamsUpkeepRegistrar",
8889
streamsUpkeep as `0x${string}`
8990
);
9091

9192
try {
92-
await streamsUpkeepContract.write.registerAndPredictID([params]);
93+
await StreamsUpkeepContract.write.registerAndPredictID([params]);
9394
spinner.succeed(
9495
"Upkeep registered and funded with 1 LINK successfully."
9596
);

0 commit comments

Comments
 (0)