Skip to content

Commit

Permalink
feat: implement addr
Browse files Browse the repository at this point in the history
  • Loading branch information
realnimish committed Sep 4, 2024
1 parent e18f6c0 commit d8727c6
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions packages/gateway/src/azero-id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,27 @@ export class AzeroId implements Database {
);
}

addr(name: string, coinType: number) {
async addr(name: string, coinType: number) {
console.log("addr", name, coinType);
return { addr: ZERO_ADDRESS, ttl: this.ttl };

let value;
if (coinType == 643) {
// AlephZero
value = await this.fetchA0ResolverAddress(name);
} else {
let alias = AzeroId.getAlias(""+coinType);
if (alias !== undefined) {
const serviceKey = "address." + alias;
value = await this.fetchRecord(name, serviceKey);
}
if (value === undefined) {
const serviceKey = "address." + coinType;
value = await this.fetchRecord(name, serviceKey);
}
}

value = value ?? (coinType == 60? ZERO_ADDRESS:'0x');
return { addr: value, ttl: this.ttl };
}

async text(name: string, key: string) {
Expand Down Expand Up @@ -66,6 +84,19 @@ export class AzeroId implements Database {
return resp.output?.toHuman().Ok.Ok;
}

private async fetchA0ResolverAddress(name: string) {
name = this.processName(name);
const resp: any = await this.contract.query.getAddress(
'',
{
gasLimit: this.maxGasLimit
},
name
);

return resp.output?.toHuman().Ok.Ok;
}

private processName(domain: string) {
// TODO: maybe add it as a class variable
const supportedTLDs = ['azero', 'tzero'];
Expand All @@ -81,4 +112,16 @@ export class AzeroId implements Database {

return name || '';
}

static getAlias(coinType: string) {
const alias = new Map<string, string>([
['0', 'btc'],
['60', 'eth'],
['354', 'dot'],
['434', 'ksm'],
['501', 'sol'],
]);

return alias.get(coinType);
}
}

0 comments on commit d8727c6

Please sign in to comment.