2021-03-10 10:47:01 +01:00
|
|
|
// @ts-ignore
|
2021-04-21 07:44:32 +02:00
|
|
|
import * as registryClient from '@src/assets/js/block-sync/data/TokenUniqueSymbolIndex.json';
|
2021-03-10 10:47:01 +01:00
|
|
|
import Web3 from 'web3';
|
|
|
|
import {environment} from '@src/environments/environment';
|
|
|
|
|
|
|
|
const web3 = new Web3(environment.web3Provider);
|
|
|
|
const abi = registryClient.default;
|
|
|
|
|
|
|
|
export class TokenRegistry {
|
|
|
|
contractAddress: string;
|
|
|
|
signerAddress: string;
|
|
|
|
contract: any;
|
|
|
|
|
|
|
|
constructor(contractAddress: string, signerAddress?: string) {
|
|
|
|
this.contractAddress = contractAddress;
|
|
|
|
this.contract = new web3.eth.Contract(abi, this.contractAddress);
|
|
|
|
if (signerAddress) {
|
|
|
|
this.signerAddress = signerAddress;
|
|
|
|
} else {
|
|
|
|
this.signerAddress = web3.eth.accounts[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public async totalTokens(): Promise<number> {
|
2021-04-21 07:44:32 +02:00
|
|
|
return await this.contract.methods.entryCount().call();
|
2021-03-10 10:47:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public async entry(serial: number): Promise<string> {
|
|
|
|
return await this.contract.methods.entry(serial).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();
|
|
|
|
}
|
|
|
|
}
|