-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Added bidds decentralized domains support (#19)
* Added bidds decentralized domains support * chore: updated docs and test for bidds domains * chore: bumped version to 1.11.0 and docs update * fix: updated top level domains for bidds --------- Co-authored-by: Henk ter Harmsel <henk@chaink.it> Co-authored-by: dineshnadimpalli <dineshn.consult@gmail.com>
- Loading branch information
1 parent
a0c5780
commit ff00929
Showing
12 changed files
with
247 additions
and
11 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
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,73 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { BDD } from './bdd' | ||
|
||
describe('BDD', () => { | ||
const resolver = new BDD() | ||
|
||
it('should be defined', () => { | ||
expect(resolver).toBeDefined() | ||
}) | ||
|
||
it.concurrent( | ||
'should resolve thisisatest.core', | ||
async () => { | ||
const result = await resolver.resolve('thisisatest.core', 'testnet') | ||
expect(result).toBe('testcore1y7d6cacnu43fhjlclr67tz6n4wqqe8h8mwdgk9') | ||
}, | ||
10000 | ||
) | ||
|
||
it.concurrent( | ||
'should resolve bdd-registrar-test.core', | ||
async () => { | ||
const result = await resolver.resolve( | ||
'bdd-registrar-test.core', | ||
'testnet' | ||
) | ||
expect(result).toBe('testcore10g5cy007hcmzhh4ta9sne0trasfds59lfdtd2g') | ||
}, | ||
10000 | ||
) | ||
|
||
it.concurrent( | ||
'should return bdd-registrar-test.core', | ||
async () => { | ||
const result = await resolver.lookup( | ||
'testcore10g5cy007hcmzhh4ta9sne0trasfds59lfdtd2g', | ||
'testnet' | ||
) | ||
expect(result).toBe('bdd-registrar-test.core') | ||
}, | ||
10000 | ||
) | ||
|
||
it.concurrent( | ||
'should resolve 5534534g.core', | ||
async () => { | ||
const result = await resolver.resolve('5534534g.core', 'mainnet') | ||
expect(result).toBe('core108a6808s9srwz548x58z7cjt08eur54gjtsv92') | ||
}, | ||
10000 | ||
) | ||
|
||
it.concurrent( | ||
'should resolve bdd-registrar.core', | ||
async () => { | ||
const result = await resolver.resolve('bdd-registrar.core', 'mainnet') | ||
expect(result).toBe('core10g5cy007hcmzhh4ta9sne0trasfds59lless97') | ||
}, | ||
10000 | ||
) | ||
|
||
it.concurrent( | ||
'should return bdd-registrar.core', | ||
async () => { | ||
const result = await resolver.lookup( | ||
'core10g5cy007hcmzhh4ta9sne0trasfds59lless97', | ||
'mainnet' | ||
) | ||
expect(result).toBe('bdd-registrar.core') | ||
}, | ||
10000 | ||
) | ||
}) |
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,88 @@ | ||
import { | ||
Addr, | ||
MatchaError, | ||
MatchaErrorType, | ||
NameService, | ||
Network, | ||
RpcURLs | ||
} from './name-service' | ||
import { decode, encode } from 'bech32' | ||
|
||
export const serviceID = 'bdd' | ||
|
||
const rpcUrls = { | ||
mainnet: 'https://full-node.mainnet-1.coreum.dev:26657', | ||
testnet: 'https://full-node.testnet-1.coreum.dev:26657' | ||
} | ||
|
||
export class BDD extends NameService { | ||
serviceID = serviceID | ||
chain = 'coreum' | ||
contractAddress = { | ||
mainnet: 'core1z22n0xy004sxm5w9fms48exwpl3vwqxd890nt8ve0kwjj048tgqstlqf6f', | ||
testnet: 'testcore1uwe9yemth6gr58tm56sx3u37t0c5rhmk963fjt480y4nz3cfxers9fn2kh' | ||
} | ||
|
||
async resolve(name: string, network: Network): Promise<string> { | ||
const client = await this.getCosmWasmClient(rpcUrls[network]) | ||
try { | ||
const result = await client.queryContractSmart( | ||
this.contractAddress[network], | ||
{ | ||
resolve: { | ||
name | ||
} | ||
} | ||
) | ||
if (!result) { | ||
throw new MatchaError('', MatchaErrorType.NOT_FOUND) | ||
} | ||
return result | ||
} catch (err) { | ||
throw new MatchaError('', MatchaErrorType.NOT_FOUND) | ||
} | ||
} | ||
|
||
async lookup( | ||
address: string, | ||
network: Network, | ||
options?: { | ||
rpcUrls?: RpcURLs | ||
} | ||
): Promise<string> { | ||
const client = await this.getCosmWasmClient( | ||
options?.rpcUrls?.[serviceID]?.[network] ?? rpcUrls[network] | ||
) | ||
|
||
const addr: Addr = { | ||
prefix: null, | ||
words: null | ||
} | ||
try { | ||
const { prefix, words } = decode(address) | ||
addr.prefix = prefix | ||
addr.words = words | ||
} catch (e) { | ||
throw new MatchaError('', MatchaErrorType.INVALID_ADDRESS) | ||
} | ||
|
||
const prefix = network === 'mainnet' ? 'core' : 'testcore' | ||
const coreAddress = encode(prefix, addr.words) | ||
try { | ||
const res = await client?.queryContractSmart( | ||
this.contractAddress[network], | ||
{ | ||
primary: { | ||
address: coreAddress | ||
} | ||
} | ||
) | ||
if (!res) { | ||
throw new MatchaError('', MatchaErrorType.NOT_FOUND) | ||
} | ||
return res | ||
} catch (e) { | ||
throw new MatchaError('', MatchaErrorType.NOT_FOUND) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.