-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ENS module with
contenthash
helper and renew
command
- Loading branch information
1 parent
cbd9e67
commit 8b4e062
Showing
10 changed files
with
173 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { BindingsManager } from '../../BindingsManager'; | ||
|
||
import { Module } from '../../Module'; | ||
import type { IPFSResolver } from '../../IPFSResolver'; | ||
import { commands } from './commands'; | ||
import { helpers } from './helpers'; | ||
import type { EVMcrispr } from '../../EVMcrispr'; | ||
|
||
export class Ens extends Module { | ||
constructor( | ||
bindingsManager: BindingsManager, | ||
nonces: Record<string, number>, | ||
evmcrispr: EVMcrispr, | ||
ipfsResolver: IPFSResolver, | ||
alias?: string, | ||
) { | ||
super( | ||
'ens', | ||
bindingsManager, | ||
nonces, | ||
commands, | ||
helpers, | ||
evmcrispr, | ||
ipfsResolver, | ||
alias, | ||
); | ||
} | ||
} |
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,8 @@ | ||
import type { Commands } from '../../../types'; | ||
import type { Ens } from '../Ens'; | ||
|
||
import { renew } from './renew'; | ||
|
||
export const commands: Commands<Ens> = { | ||
renew, | ||
}; |
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,49 @@ | ||
import { Contract } from 'ethers'; | ||
|
||
import type { ICommand } from '../../../types'; | ||
|
||
import { ComparisonType, checkArgsLength, encodeAction } from '../../../utils'; | ||
|
||
import type { Ens } from '../Ens'; | ||
|
||
const bulkRenewal = '0xfF252725f6122A92551A5FA9a6b6bf10eb0Be035'; | ||
|
||
export const renew: ICommand<Ens> = { | ||
async run(module, c, { interpretNodes }) { | ||
checkArgsLength(c, { | ||
type: ComparisonType.Equal, | ||
minValue: 2, | ||
}); | ||
|
||
const [domains, duration] = await interpretNodes(c.args); | ||
|
||
if ((await module.getChainId()) !== 1) { | ||
throw Error('This command only works on mainnet'); | ||
} | ||
|
||
const contract = new Contract( | ||
bulkRenewal, | ||
[ | ||
'function rentPrice(string[] calldata names, uint duration) external view returns(uint total)', | ||
], | ||
await module.getProvider(), | ||
); | ||
const value = await contract.rentPrice(domains, duration); | ||
|
||
return [ | ||
{ | ||
...encodeAction(bulkRenewal, 'renewAll(string[],uint256)', [ | ||
domains, | ||
duration, | ||
]), | ||
value, | ||
}, | ||
]; | ||
}, | ||
async runEagerExecution() { | ||
return; | ||
}, | ||
buildCompletionItemsForArg() { | ||
return []; | ||
}, | ||
}; |
13 changes: 13 additions & 0 deletions
13
packages/evmcrispr/src/modules/ens/ensdomains--content-hash.d.ts
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,13 @@ | ||
declare module '@ensdomains/content-hash' { | ||
export function decode(contentHash: string): string; | ||
export function fromIpfs(ipfsHash: string): string; | ||
export function fromSkylink(skylink: string): string; | ||
export function fromSwarm(swarmHash: string): string; | ||
export function encode(codec: string, value: string): string; | ||
export function getCodec(hash: string): string; | ||
|
||
export const helpers: { | ||
cidForWeb(cid: string): string; | ||
cidV0ToV1Base32(cid: string): string; | ||
}; | ||
} |
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,26 @@ | ||
import contentHash from '@ensdomains/content-hash'; | ||
|
||
import type { Ens } from '../Ens'; | ||
import type { HelperFunction } from '../../../types'; | ||
import { ComparisonType, checkArgsLength } from '../../../utils'; | ||
|
||
export const contenthash: HelperFunction<Ens> = async ( | ||
_, | ||
h, | ||
{ interpretNode }, | ||
) => { | ||
checkArgsLength(h, { | ||
type: ComparisonType.Equal, | ||
minValue: 1, | ||
}); | ||
const [codec, hash] = (await interpretNode(h.args[0])).split(':'); | ||
if (!['ipfs', 'ipns', 'skynet'].includes(codec)) { | ||
throw new Error( | ||
'Only ipfs, ipns and skynet are supported. The hash format should be <codec>:<hash>', | ||
); | ||
} | ||
if (!hash) { | ||
throw new Error('The hash format should be <codec>:<hash>'); | ||
} | ||
return '0x' + contentHash.encode(codec + '-ns', hash); | ||
}; |
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,7 @@ | ||
import type { HelperFunctions } from '../../../types'; | ||
import type { Ens } from '../Ens'; | ||
import { contenthash } from './contenthash'; | ||
|
||
export const helpers: HelperFunctions<Ens> = { | ||
contenthash, | ||
}; |
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,5 @@ | ||
import { Ens } from './Ens'; | ||
|
||
export { commands } from './commands'; | ||
export { helpers } from './helpers'; | ||
export const ModuleConstructor = Ens; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.