-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
926 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { Command } from '@commander-js/extra-typings'; | ||
import { BigDecimal } from '@lens-protocol/shared-kernel'; | ||
import chalk from 'chalk'; | ||
import { createSpinner } from 'nanospinner'; | ||
|
||
import { ensureParentCommand, initLensClient } from '../lib/commandToEnvironment.js'; | ||
import { LENS_HANDLES_CONTRACT, LENS_PROFILES_CONTRACT } from '../lib/consts.js'; | ||
import { output } from '../lib/output.js'; | ||
import { safeRequest } from '../lib/safeRequest.js'; | ||
|
||
const hexToDecimal = (hex: string) => BigDecimal.from(hex).toFixed(); | ||
|
||
export function investigate() { | ||
const cmd = new Command('investigate') | ||
.description('Investigate a Profile ID, Handle or Wallet Address') | ||
.option('-h, --handle <handle>', 'Handle with prefix (lens/handle)') | ||
.option('-a, --address <address>', 'Wallet address') | ||
.option('-p, --profile <address>', 'Profile ID') | ||
.action(async (options) => { | ||
if (!options.handle && !options.address && !options.profile) { | ||
output.error('At least one of the options is required. See --help for more information.'); | ||
process.exit(1); | ||
} | ||
|
||
const parentCommandName = ensureParentCommand(cmd); | ||
const client = initLensClient(parentCommandName); | ||
|
||
// investigate handle | ||
if (options.handle) { | ||
const fullHandle = options.handle; | ||
|
||
const spinner = createSpinner( | ||
`Investigating handle: ${chalk.green(options.handle)}`, | ||
).start(); | ||
|
||
const address = await safeRequest( | ||
async () => client.handle.resolveAddress({ handle: fullHandle }), | ||
() => spinner.error(), | ||
); | ||
|
||
const profile = await safeRequest( | ||
async () => client.profile.fetch({ forHandle: fullHandle }), | ||
() => spinner.error(), | ||
); | ||
|
||
spinner.success(); | ||
|
||
output.value(`Resolved address:`, address); | ||
output.info( | ||
`Handle details:`, | ||
profile && | ||
profile.handle && { | ||
linkedTo: { | ||
profileId: profile.handle.linkedTo?.nftTokenId, | ||
}, | ||
ownedBy: profile.handle.ownedBy, | ||
}, | ||
); | ||
output.info( | ||
`Linked profile:`, | ||
profile && { | ||
id: profile.id, | ||
ownedBy: profile.ownedBy.address, | ||
createdAt: profile.createdAt, | ||
sponsor: profile.sponsor, | ||
signless: profile.signless, | ||
// guardian: profile.guardian, // can only be read by owner | ||
metadata: profile.metadata && { | ||
displayName: profile.metadata.displayName, | ||
bio: profile.metadata.bio, | ||
}, | ||
stats: profile.stats, | ||
}, | ||
); | ||
|
||
if (parentCommandName === 'production') { | ||
output.value(`URL:`, `https://share.lens.xyz/u/${fullHandle}`); | ||
profile && | ||
profile.handle && | ||
output.value( | ||
`Lens Handles OpenSea:`, | ||
`https://opensea.io/assets/matic/${LENS_HANDLES_CONTRACT}/${hexToDecimal( | ||
profile.handle.id, | ||
)}`, | ||
); | ||
profile && | ||
output.value( | ||
`Lens Profiles OpenSea:`, | ||
`https://opensea.io/assets/matic/${LENS_PROFILES_CONTRACT}/${hexToDecimal( | ||
profile.id, | ||
)}`, | ||
); | ||
} | ||
} | ||
|
||
// investigate address | ||
if (options.address) { | ||
output.value(`Investigating address:`, options.address); | ||
|
||
// validate | ||
// owned/managed profiles | ||
// owned handles | ||
// rate limits | ||
} | ||
|
||
// investigate profile | ||
if (options.profile) { | ||
output.value(`Investigating profile:`, options.profile); | ||
|
||
// owner | ||
// managers | ||
// linked handle | ||
// lens share link | ||
} | ||
}); | ||
|
||
return cmd; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const LENS_HANDLES_CONTRACT = '0xe7e7ead361f3aacd73a61a9bd6c10ca17f38e945'; | ||
export const LENS_PROFILES_CONTRACT = '0xdb46d1dc155634fbc732f92e853b10b288ad5a1d'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import chalk from 'chalk'; | ||
|
||
export const output = { | ||
success: function (...args: Parameters<typeof console.log>) { | ||
console.log(chalk.green(...args)); | ||
}, | ||
error: function (...args: Parameters<typeof console.log>) { | ||
console.log(chalk.red(...args)); | ||
}, | ||
info: function (...args: Parameters<typeof console.log>) { | ||
console.log(...args); | ||
}, | ||
value: function (key: string, ...args: Parameters<typeof console.log>) { | ||
console.log(key, chalk.green(...args)); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { assertError } from '@lens-protocol/shared-kernel'; | ||
|
||
import { output } from './output.js'; | ||
|
||
/* | ||
* Safely execute a request and handle errors | ||
*/ | ||
export async function safeRequest<T>( | ||
callback: () => Promise<T>, | ||
onError?: (error: Error) => void, | ||
): Promise<T> { | ||
try { | ||
return await callback(); | ||
} catch (error) { | ||
assertError(error); | ||
if (onError) { | ||
onError(error); | ||
} | ||
output.error(`Error: ${error.message}`); | ||
process.exit(1); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.