Refactor registry service imports.
This commit is contained in:
parent
405199cfe3
commit
8ae6436460
@ -25,8 +25,8 @@ export class BlockSyncService {
|
|||||||
const settings: Settings = new Settings(this.scan);
|
const settings: Settings = new Settings(this.scan);
|
||||||
const readyStateElements: { network: number } = { network: 2 };
|
const readyStateElements: { network: number } = { network: 2 };
|
||||||
settings.w3.provider = environment.web3Provider;
|
settings.w3.provider = environment.web3Provider;
|
||||||
settings.w3.engine = this.registryService.getWeb3();
|
settings.w3.engine = this.registryService.web3;
|
||||||
settings.registry = this.registryService.getRegistry();
|
settings.registry = this.registryService.registry;
|
||||||
settings.txHelper = new TransactionHelper(settings.w3.engine, settings.registry);
|
settings.txHelper = new TransactionHelper(settings.w3.engine, settings.registry);
|
||||||
|
|
||||||
settings.txHelper.ontransfer = async (transaction: any): Promise<void> => {
|
settings.txHelper.ontransfer = async (transaction: any): Promise<void> => {
|
||||||
@ -35,12 +35,10 @@ export class BlockSyncService {
|
|||||||
settings.txHelper.onconversion = async (transaction: any): Promise<any> => {
|
settings.txHelper.onconversion = async (transaction: any): Promise<any> => {
|
||||||
window.dispatchEvent(this.newConversionEvent(transaction));
|
window.dispatchEvent(this.newConversionEvent(transaction));
|
||||||
};
|
};
|
||||||
settings.registry.onload = (addressReturned: number): void => {
|
settings.registry.onload = (addressReturned: string): void => {
|
||||||
this.loggingService.sendInfoLevelMessage(`Loaded network contracts ${addressReturned}`);
|
this.loggingService.sendInfoLevelMessage(`Loaded network contracts ${addressReturned}`);
|
||||||
this.readyStateProcessor(settings, readyStateElements.network, address, offset, limit);
|
this.readyStateProcessor(settings, readyStateElements.network, address, offset, limit);
|
||||||
};
|
};
|
||||||
|
|
||||||
settings.registry.load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
readyStateProcessor(
|
readyStateProcessor(
|
||||||
|
@ -22,12 +22,4 @@ export class RegistryService {
|
|||||||
this.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
|
this.registry.declaratorHelper.addTrust(environment.trustedDeclaratorAddress);
|
||||||
this.registry.load();
|
this.registry.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
getRegistry(): any {
|
|
||||||
return this.registry;
|
|
||||||
}
|
|
||||||
|
|
||||||
getWeb3(): any {
|
|
||||||
return this.web3;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,7 @@ export class TokenService {
|
|||||||
LoadEvent: EventEmitter<number> = new EventEmitter<number>();
|
LoadEvent: EventEmitter<number> = new EventEmitter<number>();
|
||||||
|
|
||||||
constructor(private httpClient: HttpClient, private registryService: RegistryService) {
|
constructor(private httpClient: HttpClient, private registryService: RegistryService) {
|
||||||
this.registry = registryService.getRegistry();
|
this.registry = registryService.registry;
|
||||||
this.registry.load();
|
|
||||||
this.registry.onload = async (address: string): Promise<void> => {
|
this.registry.onload = async (address: string): Promise<void> => {
|
||||||
this.tokenRegistry = new TokenRegistry(
|
this.tokenRegistry = new TokenRegistry(
|
||||||
await this.registry.getContractAddressByName('TokenRegistry')
|
await this.registry.getContractAddressByName('TokenRegistry')
|
||||||
|
@ -37,9 +37,8 @@ export class TransactionService {
|
|||||||
private loggingService: LoggingService,
|
private loggingService: LoggingService,
|
||||||
private registryService: RegistryService
|
private registryService: RegistryService
|
||||||
) {
|
) {
|
||||||
this.web3 = this.registryService.getWeb3();
|
this.web3 = this.registryService.web3;
|
||||||
this.registry = registryService.getRegistry();
|
this.registry = registryService.registry;
|
||||||
this.registry.load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllTransactions(offset: number, limit: number): Observable<any> {
|
getAllTransactions(offset: number, limit: number): Observable<any> {
|
||||||
@ -133,41 +132,43 @@ export class TransactionService {
|
|||||||
recipientAddress: string,
|
recipientAddress: string,
|
||||||
value: number
|
value: number
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const transferAuthAddress = await this.registry.getContractAddressByName(
|
this.registry.onload = async (addressReturned: string): Promise<void> => {
|
||||||
'TransferAuthorization'
|
const transferAuthAddress = await this.registry.getContractAddressByName(
|
||||||
);
|
'TransferAuthorization'
|
||||||
const hashFunction = new Keccak(256);
|
);
|
||||||
hashFunction.update('createRequest(address,address,address,uint256)');
|
const hashFunction = new Keccak(256);
|
||||||
const hash = hashFunction.digest();
|
hashFunction.update('createRequest(address,address,address,uint256)');
|
||||||
const methodSignature = hash.toString('hex').substring(0, 8);
|
const hash = hashFunction.digest();
|
||||||
const abiCoder = new utils.AbiCoder();
|
const methodSignature = hash.toString('hex').substring(0, 8);
|
||||||
const abi = await abiCoder.encode(
|
const abiCoder = new utils.AbiCoder();
|
||||||
['address', 'address', 'address', 'uint256'],
|
const abi = await abiCoder.encode(
|
||||||
[senderAddress, recipientAddress, tokenAddress, value]
|
['address', 'address', 'address', 'uint256'],
|
||||||
);
|
[senderAddress, recipientAddress, tokenAddress, value]
|
||||||
const data = fromHex(methodSignature + strip0x(abi));
|
);
|
||||||
const tx = new Tx(environment.bloxbergChainId);
|
const data = fromHex(methodSignature + strip0x(abi));
|
||||||
tx.nonce = await this.web3.eth.getTransactionCount(senderAddress);
|
const tx = new Tx(environment.bloxbergChainId);
|
||||||
tx.gasPrice = Number(await this.web3.eth.getGasPrice());
|
tx.nonce = await this.web3.eth.getTransactionCount(senderAddress);
|
||||||
tx.gasLimit = 8000000;
|
tx.gasPrice = Number(await this.web3.eth.getGasPrice());
|
||||||
tx.to = fromHex(strip0x(transferAuthAddress));
|
tx.gasLimit = 8000000;
|
||||||
tx.value = toValue(value);
|
tx.to = fromHex(strip0x(transferAuthAddress));
|
||||||
tx.data = data;
|
tx.value = toValue(value);
|
||||||
const txMsg = tx.message();
|
tx.data = data;
|
||||||
const privateKey = this.authService.mutableKeyStore.getPrivateKey();
|
const txMsg = tx.message();
|
||||||
if (!privateKey.isDecrypted()) {
|
const privateKey = this.authService.mutableKeyStore.getPrivateKey();
|
||||||
const password = window.prompt('password');
|
if (!privateKey.isDecrypted()) {
|
||||||
await privateKey.decrypt(password);
|
const password = window.prompt('password');
|
||||||
}
|
await privateKey.decrypt(password);
|
||||||
const signatureObject = secp256k1.ecdsaSign(txMsg, privateKey.keyPacket.privateParams.d);
|
}
|
||||||
const r = signatureObject.signature.slice(0, 32);
|
const signatureObject = secp256k1.ecdsaSign(txMsg, privateKey.keyPacket.privateParams.d);
|
||||||
const s = signatureObject.signature.slice(32);
|
const r = signatureObject.signature.slice(0, 32);
|
||||||
const v = signatureObject.recid;
|
const s = signatureObject.signature.slice(32);
|
||||||
tx.setSignature(r, s, v);
|
const v = signatureObject.recid;
|
||||||
const txWire = add0x(toHex(tx.serializeRLP()));
|
tx.setSignature(r, s, v);
|
||||||
const result = await this.web3.eth.sendSignedTransaction(txWire);
|
const txWire = add0x(toHex(tx.serializeRLP()));
|
||||||
this.loggingService.sendInfoLevelMessage(`Result: ${result}`);
|
const result = await this.web3.eth.sendSignedTransaction(txWire);
|
||||||
const transaction = await this.web3.eth.getTransaction(result.transactionHash);
|
this.loggingService.sendInfoLevelMessage(`Result: ${result}`);
|
||||||
this.loggingService.sendInfoLevelMessage(`Transaction: ${transaction}`);
|
const transaction = await this.web3.eth.getTransaction(result.transactionHash);
|
||||||
|
this.loggingService.sendInfoLevelMessage(`Transaction: ${transaction}`);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,7 @@ export class UserService {
|
|||||||
this.keystore = authService.mutableKeyStore;
|
this.keystore = authService.mutableKeyStore;
|
||||||
this.signer = new PGPSigner(this.keystore);
|
this.signer = new PGPSigner(this.keystore);
|
||||||
});
|
});
|
||||||
this.registry = registryService.getRegistry();
|
this.registry = registryService.registry;
|
||||||
this.registry.load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resetPin(phone: string): Observable<any> {
|
resetPin(phone: string): Observable<any> {
|
||||||
@ -179,17 +178,20 @@ export class UserService {
|
|||||||
|
|
||||||
async loadAccounts(limit: number = 100, offset: number = 0): Promise<void> {
|
async loadAccounts(limit: number = 100, offset: number = 0): Promise<void> {
|
||||||
this.resetAccountsList();
|
this.resetAccountsList();
|
||||||
const accountIndexAddress: string = await this.registry.getContractAddressByName(
|
this.registry.onload = async (addressReturned: string): Promise<void> => {
|
||||||
'AccountRegistry'
|
const accountIndexAddress: string = await this.registry.getContractAddressByName(
|
||||||
);
|
'AccountRegistry'
|
||||||
const accountIndexQuery = new AccountIndex(accountIndexAddress);
|
);
|
||||||
const accountAddresses: Array<string> = await accountIndexQuery.last(
|
const accountIndexQuery = new AccountIndex(accountIndexAddress);
|
||||||
await accountIndexQuery.totalAccounts()
|
const accountAddresses: Array<string> = await accountIndexQuery.last(
|
||||||
);
|
await accountIndexQuery.totalAccounts()
|
||||||
this.loggingService.sendInfoLevelMessage(accountAddresses);
|
);
|
||||||
for (const accountAddress of accountAddresses.slice(offset, offset + limit)) {
|
console.log(accountAddresses);
|
||||||
await this.getAccountByAddress(accountAddress, limit);
|
this.loggingService.sendInfoLevelMessage(accountAddresses);
|
||||||
}
|
for (const accountAddress of accountAddresses.slice(offset, offset + limit)) {
|
||||||
|
await this.getAccountByAddress(accountAddress, limit);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAccountByAddress(
|
async getAccountByAddress(
|
||||||
|
Loading…
Reference in New Issue
Block a user