40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
// @ts-ignore
|
|
import * as registry from '@src/assets/js/block-sync/data/Registry.json';
|
|
import {environment} from '@src/environments/environment';
|
|
import {LoggingService} from '@app/_services/logging.service';
|
|
const Web3 = require('web3');
|
|
|
|
const web3 = new Web3(environment.web3Provider);
|
|
const abi = registry.default;
|
|
|
|
export class Registry {
|
|
contractAddress: string;
|
|
signerAddress: string;
|
|
contract: any;
|
|
|
|
constructor(contractAddress: string, signerAddress?: string) {
|
|
this.contractAddress = contractAddress;
|
|
this.contract = new web3.eth.Contract(abi, contractAddress);
|
|
if (signerAddress) {
|
|
this.signerAddress = signerAddress;
|
|
} else {
|
|
this.signerAddress = web3.eth.accounts[0];
|
|
}
|
|
}
|
|
|
|
public async owner(): Promise<string> {
|
|
return await this.contract.methods.owner().call();
|
|
}
|
|
|
|
public async addressOf(identifier: string): Promise<string> {
|
|
const id = '0x' + web3.utils.padRight(new Buffer(identifier).toString('hex'), 64);
|
|
try {
|
|
return await this.contract.methods.addressOf(id).call();
|
|
} catch (error) {
|
|
// TODO logger service
|
|
// this.loggingService.sendInfoLevelMessage
|
|
console.log('Unable to fetch addressOf', error)
|
|
}
|
|
}
|
|
}
|