33 lines
986 B
TypeScript
33 lines
986 B
TypeScript
// @ts-ignore
|
|
import * as registry from '@src/assets/js/block-sync/data/Registry.json';
|
|
import {environment} from '@src/environments/environment';
|
|
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);
|
|
return await this.contract.methods.addressOf(id).call();
|
|
}
|
|
}
|