-
Notifications
You must be signed in to change notification settings - Fork 0
Develop #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Develop #17
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||||||||||||||||
| 'use server'; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import { ERC20Abi } from '@/blockchain/ERC20'; | ||||||||||||||||||||||||||||||||
| import { MNDContractAbi } from '@/blockchain/MNDContract'; | ||||||||||||||||||||||||||||||||
| import { NDContractAbi } from '@/blockchain/NDContract'; | ||||||||||||||||||||||||||||||||
| import { ReaderAbi } from '@/blockchain/Reader'; | ||||||||||||||||||||||||||||||||
| import config, { getCurrentEpoch, getEpochStartTimestamp, getNextEpochTimestamp } from '@/config'; | ||||||||||||||||||||||||||||||||
|
|
@@ -66,10 +67,26 @@ export async function getNodeLicenseDetails(nodeAddress: types.EthAddress): Prom | |||||||||||||||||||||||||||||||
| functionName: 'getNodeLicenseDetails', | ||||||||||||||||||||||||||||||||
| args: [nodeAddress], | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| .then((result) => ({ | ||||||||||||||||||||||||||||||||
| ...result, | ||||||||||||||||||||||||||||||||
| licenseType: [undefined, 'ND', 'MND', 'GND'][result.licenseType] as 'ND' | 'MND' | 'GND' | undefined, | ||||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||||
| .then(async (result) => { | ||||||||||||||||||||||||||||||||
| const licenseType = [undefined, 'ND', 'MND', 'GND'][result.licenseType] as 'ND' | 'MND' | 'GND' | undefined; | ||||||||||||||||||||||||||||||||
| let firstMiningEpoch: bigint | undefined; | ||||||||||||||||||||||||||||||||
| if (licenseType === 'MND') { | ||||||||||||||||||||||||||||||||
| firstMiningEpoch = ( | ||||||||||||||||||||||||||||||||
| await publicClient.readContract({ | ||||||||||||||||||||||||||||||||
| address: config.mndContractAddress, | ||||||||||||||||||||||||||||||||
| abi: MNDContractAbi, | ||||||||||||||||||||||||||||||||
| functionName: 'licenses', | ||||||||||||||||||||||||||||||||
| args: [result.licenseId], | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| )[3]; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||
| ...result, | ||||||||||||||||||||||||||||||||
| licenseType, | ||||||||||||||||||||||||||||||||
| firstMiningEpoch, | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| export async function getLicense(licenseType: 'ND' | 'MND' | 'GND', licenseId: number | string): Promise<types.License> { | ||||||||||||||||||||||||||||||||
|
|
@@ -109,7 +126,7 @@ export async function getLicense(licenseType: 'ND' | 'MND' | 'GND', licenseId: n | |||||||||||||||||||||||||||||||
| functionName: 'getMndLicenseDetails', | ||||||||||||||||||||||||||||||||
| args: [BigInt(licenseId)], | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| .then((license) => { | ||||||||||||||||||||||||||||||||
| .then(async (license) => { | ||||||||||||||||||||||||||||||||
| const isLinked = !isZeroAddress(license.nodeAddress); | ||||||||||||||||||||||||||||||||
| const licenseType = [undefined, 'ND', 'MND', 'GND'][license.licenseType] as 'ND' | 'MND' | 'GND' | undefined; | ||||||||||||||||||||||||||||||||
| if (licenseType === undefined) { | ||||||||||||||||||||||||||||||||
|
|
@@ -118,11 +135,20 @@ export async function getLicense(licenseType: 'ND' | 'MND' | 'GND', licenseId: n | |||||||||||||||||||||||||||||||
| if (licenseType !== 'MND' && licenseType !== 'GND') { | ||||||||||||||||||||||||||||||||
| throw new Error('Invalid license type'); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| const firstMiningEpoch = ( | ||||||||||||||||||||||||||||||||
| await publicClient.readContract({ | ||||||||||||||||||||||||||||||||
| address: config.mndContractAddress, | ||||||||||||||||||||||||||||||||
| abi: MNDContractAbi, | ||||||||||||||||||||||||||||||||
| functionName: 'licenses', | ||||||||||||||||||||||||||||||||
| args: [BigInt(licenseId)], | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| )[3]; | ||||||||||||||||||||||||||||||||
|
Comment on lines
+138
to
+145
|
||||||||||||||||||||||||||||||||
| const firstMiningEpoch = ( | |
| await publicClient.readContract({ | |
| address: config.mndContractAddress, | |
| abi: MNDContractAbi, | |
| functionName: 'licenses', | |
| args: [BigInt(licenseId)], | |
| }) | |
| )[3]; | |
| // The 'licenses' function returns a tuple where the 4th element is firstMiningEpoch. | |
| const [, , , firstMiningEpoch] = await publicClient.readContract({ | |
| address: config.mndContractAddress, | |
| abi: MNDContractAbi, | |
| functionName: 'licenses', | |
| args: [BigInt(licenseId)], | |
| }); |
Copilot
AI
Jan 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comparison logic should use strict equality. The condition should be written as rewards_amount < maxRemainingClaimAmount ? rewards_amount : maxRemainingClaimAmount to match the pattern used in the original calculateLicenseRewards function at line 414. Currently, it uses the reversed order which could be confusing for maintainability.
| return rewards_amount > maxRemainingClaimAmount ? maxRemainingClaimAmount : rewards_amount; | |
| return rewards_amount < maxRemainingClaimAmount ? rewards_amount : maxRemainingClaimAmount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The array indexing used to extract firstMiningEpoch is fragile and unclear. Using a magic index [3] makes the code difficult to understand and maintain. Consider either destructuring the return value with named properties or adding a comment explaining what index 3 represents in the licenses tuple.