diff --git a/README.md b/README.md index 6a91de2e..7090752d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # ddns-action -DDNS(Distributed Domain Name System) update action. Currently it supports ENS and CNS. +DDNS(Distributed Domain Name System) update action. Currently it supports ENS, CNS and UNS.

ddns action @@ -10,7 +10,7 @@ Parameter |Required |Description --- |--- |--- `mnemonic` |Yes |Mnemonic phrase for wallet recovery. Plain PrivateKey can be used as well. `rpc` |Yes |Url of RPC APIs. -`name` |Yes |Distributed domain name. Currently it supports ENS, CNS (.eth, .crypto) names. (eg `ddns-action.eth`, `ddns-action.crypto`) +`name` |Yes |Distributed domain name. Currently it supports ENS(.eth), CNS(.crypto), UNS(.coin, .wallet, .bitcoin, .x, .888, .nft, .dao, .blockchain) names. (eg `ddns-action.eth`, `ddns-action.crypto`) `contentHash` |Yes |Hash of content.. `contentType` |No |Type of content. Supported types [`ipfs-ns`, `swarm-ns`]. Default `ipfs-ns` `dryRun` |No |Execution emulation without setting new content hash. Default `false` @@ -21,6 +21,7 @@ Provider |ipfs-ns |swarm-ns --- |--- |--- ENS |Yes |Yes CNS |Yes |No +UNS |Yes |No ## Example usage diff --git a/action.yaml b/action.yaml index 5804676e..6a071a49 100644 --- a/action.yaml +++ b/action.yaml @@ -1,5 +1,5 @@ name: 'Update DDNS' -description: 'DDNS(Distributed Domain Name System) update action. Currently it supports ENS and CNS.' +description: 'DDNS(Distributed Domain Name System) update action. Currently it supports ENS, CNS and UNS.' branding: icon: 'edit' color: 'green' @@ -11,7 +11,7 @@ inputs: description: 'Url of RPC APIs.' required: true name: - description: 'Distributed domain name. Currently it supports ENS, CNS (.eth, .crypto) names. (eg `ddns-action.eth`)' + description: 'Distributed domain name. Currently it supports ENS(.eth), CNS(.crypto), UNS(.coin, .wallet, .bitcoin, .x, .888, .nft, .dao, .blockchain) names. (eg `ddns-action.eth`)' required: true contentHash: description: 'Hash of content.' diff --git a/package.json b/package.json index a3f319e9..d6dc5c3c 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ }, "keywords": [ "ENS", + "UNS", "CNS", "DDNS", "GitHub", diff --git a/src/updater/cns/index.js b/src/updater/cns/index.js index dca02e8d..0eb27ae2 100644 --- a/src/updater/cns/index.js +++ b/src/updater/cns/index.js @@ -1,8 +1,8 @@ const { ethers } = require('ethers'); const NetworkConfig = require('uns/uns-config.json'); +const CNSRegistryABI = require('uns/artifacts/abi/CNSRegistry.json'); +const ResolverABI = require('uns/artifacts/abi/Resolver.json'); -const registryABI = require('./registry.json'); -const resolverABI = require('./resolver.json'); const { namehash } = require('../../utils/namehash'); const ipfsKey = 'ipfs.html.value'; @@ -16,7 +16,7 @@ function CNS(options) { const { chainId } = await provider.getNetwork(); const { contracts } = NetworkConfig.networks[chainId]; const { address } = contracts.CNSRegistry; - const registryContract = new ethers.Contract(address, registryABI, provider); + const registryContract = new ethers.Contract(address, CNSRegistryABI, provider); return registryContract.resolverOf(tokenId); } @@ -31,7 +31,7 @@ function CNS(options) { throw new Error('Resolver not found'); } - return new ethers.Contract(resolver, resolverABI, provider); + return new ethers.Contract(resolver, ResolverABI, provider); } this.getContenthash = async () => { diff --git a/src/updater/cns/registry.json b/src/updater/cns/registry.json deleted file mode 100644 index 0853c036..00000000 --- a/src/updater/cns/registry.json +++ /dev/null @@ -1,983 +0,0 @@ -[ - { - "constant": true, - "inputs": [ - { - "internalType": "bytes4", - "name": "interfaceId", - "type": "bytes4" - } - ], - "name": "supportsInterface", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "controlledTransferFrom", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "string", - "name": "label", - "type": "string" - }, - { - "internalType": "bytes", - "name": "_data", - "type": "bytes" - } - ], - "name": "controlledSafeMintChild", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "name", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "getApproved", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "approve", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "resolveTo", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "transferFrom", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "controlledResolveTo", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "safeTransferFrom", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "burn", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "isApprovedOrOwner", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "updateId", - "type": "uint256" - } - ], - "name": "sync", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "_data", - "type": "bytes" - } - ], - "name": "controlledSafeTransferFrom", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "string", - "name": "label", - "type": "string" - } - ], - "name": "burnChild", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "ownerOf", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [], - "name": "renounceController", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - } - ], - "name": "balanceOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "string", - "name": "label", - "type": "string" - } - ], - "name": "safeMintChild", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "string", - "name": "label", - "type": "string" - } - ], - "name": "childOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "pure", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "symbol", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "string", - "name": "label", - "type": "string" - } - ], - "name": "safeTransferFromChild", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "string", - "name": "label", - "type": "string" - } - ], - "name": "transferFromChild", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "bool", - "name": "approved", - "type": "bool" - } - ], - "name": "setApprovalForAll", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "addController", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "resolverOf", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "isController", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "string", - "name": "label", - "type": "string" - } - ], - "name": "controlledMintChild", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "_data", - "type": "bytes" - } - ], - "name": "safeTransferFrom", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "string", - "name": "label", - "type": "string" - }, - { - "internalType": "bytes", - "name": "_data", - "type": "bytes" - } - ], - "name": "safeTransferFromChild", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "tokenURI", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "string", - "name": "label", - "type": "string" - }, - { - "internalType": "bytes", - "name": "_data", - "type": "bytes" - } - ], - "name": "safeMintChild", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "string", - "name": "prefix", - "type": "string" - } - ], - "name": "controlledSetTokenURIPrefix", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "string", - "name": "label", - "type": "string" - } - ], - "name": "mintChild", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "controlledBurn", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "internalType": "address", - "name": "operator", - "type": "address" - } - ], - "name": "isApprovedForAll", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [], - "name": "root", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "string", - "name": "uri", - "type": "string" - } - ], - "name": "NewURI", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "string", - "name": "prefix", - "type": "string" - } - ], - "name": "NewURIPrefix", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - } - ], - "name": "Resolve", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "resolver", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "updateId", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "Sync", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "approved", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "operator", - "type": "address" - }, - { - "indexed": false, - "internalType": "bool", - "name": "approved", - "type": "bool" - } - ], - "name": "ApprovalForAll", - "type": "event" - } -] diff --git a/src/updater/cns/resolver.json b/src/updater/cns/resolver.json deleted file mode 100644 index d6380379..00000000 --- a/src/updater/cns/resolver.json +++ /dev/null @@ -1,348 +0,0 @@ -[ - { - "inputs": [ - { - "internalType": "contract Registry", - "name": "registry", - "type": "address" - } - ], - "payable": false, - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "preset", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "indexed": false, - "internalType": "string", - "name": "value", - "type": "string" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "Set", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "preset", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "SetPreset", - "type": "event" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "get", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "string[]", - "name": "keys", - "type": "string[]" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "getMany", - "outputs": [ - { - "internalType": "string[]", - "name": "", - "type": "string[]" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "address", - "name": "addr", - "type": "address" - } - ], - "name": "nonceOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": true, - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "presetOf", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "payable": false, - "stateMutability": "view", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "reset", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "signature", - "type": "bytes" - } - ], - "name": "resetFor", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "internalType": "string", - "name": "value", - "type": "string" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "set", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "string", - "name": "key", - "type": "string" - }, - { - "internalType": "string", - "name": "value", - "type": "string" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "signature", - "type": "bytes" - } - ], - "name": "setFor", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "string[]", - "name": "keys", - "type": "string[]" - }, - { - "internalType": "string[]", - "name": "values", - "type": "string[]" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "setMany", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "string[]", - "name": "keys", - "type": "string[]" - }, - { - "internalType": "string[]", - "name": "values", - "type": "string[]" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "signature", - "type": "bytes" - } - ], - "name": "setManyFor", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint256", - "name": "presetId", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "setPreset", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - }, - { - "constant": false, - "inputs": [ - { - "internalType": "uint256", - "name": "presetId", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "signature", - "type": "bytes" - } - ], - "name": "setPresetFor", - "outputs": [], - "payable": false, - "stateMutability": "nonpayable", - "type": "function" - } -] diff --git a/src/updater/index.js b/src/updater/index.js index 4a2fdf42..6e1d80f2 100644 --- a/src/updater/index.js +++ b/src/updater/index.js @@ -2,12 +2,21 @@ const core = require('@actions/core'); const ENS = require('./ens'); const CNS = require('./cns'); +const UNS = require('./uns'); const supportedTypes = ['ipfs-ns', 'swarm-ns']; const tldMap = [ { name: '.eth', factory: (options) => { return new ENS(options) } }, - { name: '.crypto', factory: (options) => { return new CNS(options) } } + { name: '.crypto', factory: (options) => { return new CNS(options) } }, + { name: '.coin', factory: (options) => { return new UNS(options) } }, + { name: '.wallet', factory: (options) => { return new UNS(options) } }, + { name: '.bitcoin', factory: (options) => { return new UNS(options) } }, + { name: '.x', factory: (options) => { return new UNS(options) } }, + { name: '.888', factory: (options) => { return new UNS(options) } }, + { name: '.nft', factory: (options) => { return new UNS(options) } }, + { name: '.dao', factory: (options) => { return new UNS(options) } }, + { name: '.blockchain', factory: (options) => { return new UNS(options) } }, ] function validate({ name, contentHash, contentType }) { diff --git a/src/updater/uns/index.js b/src/updater/uns/index.js new file mode 100644 index 00000000..e57edc2c --- /dev/null +++ b/src/updater/uns/index.js @@ -0,0 +1,47 @@ +const { ethers } = require('ethers'); +const NetworkConfig = require('uns/uns-config.json'); +const UNSRegistryABI = require('uns/artifacts/abi/UNSRegistry.json'); + +const { namehash } = require('../../utils/namehash'); + +const ipfsKey = 'ipfs.html.value'; + +function UNS(options) { + const { mnemonic, rpc, name, dryrun, verbose } = options; + + const provider = new ethers.providers.JsonRpcProvider(rpc); + + const getRegistryContract = async () => { + const { chainId } = await provider.getNetwork(); + const { contracts } = NetworkConfig.networks[chainId]; + const { address } = contracts.UNSRegistry; + return new ethers.Contract(address, UNSRegistryABI, provider); + } + + this.getContenthash = async () => { + if (verbose) { + console.log('Getting content...') + } + + const registryContract = await getRegistryContract(); + return registryContract.get(ipfsKey, namehash(name)); + } + + this.setContenthash = async ({ contentHash, contentType }) => { + if (contentType !== 'ipfs-ns') { + throw new Error('ContentType is not supported. UNS supports only ipfs-ns'); + } + + const registryContract = await getRegistryContract(); + const account = new ethers.Wallet(mnemonic, provider); + + if (dryrun) { + return; + } + + return registryContract.connect(account) + .set(ipfsKey, contentHash, namehash(name)); + } +} + +module.exports = UNS; diff --git a/src/updater/uns/index.test.js b/src/updater/uns/index.test.js new file mode 100644 index 00000000..c9bae389 --- /dev/null +++ b/src/updater/uns/index.test.js @@ -0,0 +1,27 @@ +const UNS = require('./'); + +jest.setTimeout(120000); + +describe.skip('UNS: Integration tests', () => { + test('test get content hash', async () => { + const uns = new UNS({ + mnemonic: process.env.DEV_PKEY, + rpc: `https://rinkeby.infura.io/v3/${process.env.INFURA_API_KEY}`, + name: 'udtestdev-ddns-action.x', + verbose: true + }); + const ch = await uns.getContenthash(); + console.log(ch) + }); + + test('test set content hash', async () => { + const uns = new UNS({ + mnemonic: process.env.DEV_PKEY, + rpc: `https://rinkeby.infura.io/v3/${process.env.INFURA_API_KEY}`, + name: 'udtestdev-ddns-action.x', + verbose: true + }); + const ch = await uns.setContenthash({ contentHash: 'QmRJFpRntf1EMgmC5Tm3Rzc438PRrYCMYZPb6nD4DeaNH6', contentType: 'ipfs-ns' }); + console.log(ch) + }); +});