Add check for trusted declarator address.

This commit is contained in:
Spencer Ofwiti 2021-06-18 19:43:24 +03:00
parent 665b28a8ba
commit bb6426c252
2 changed files with 61 additions and 37 deletions

View File

@ -129,7 +129,7 @@ const defaultAccount: AccountDetails = {
meta: {
TYP: [],
},
value: '',
value: '+254700000000',
},
],
version: [

View File

@ -62,30 +62,46 @@ export class TransactionService {
transaction.value = Number(transaction.value);
transaction.type = 'transaction';
try {
this.userService
.getAccountDetailsFromMeta(await User.toKey(transaction.from))
.pipe(first())
.subscribe(
(res) => {
transaction.sender = this.getAccountInfo(res, cacheSize);
},
(error) => {
transaction.sender = defaultAccount;
this.userService.addAccount(defaultAccount, cacheSize);
}
);
this.userService
.getAccountDetailsFromMeta(await User.toKey(transaction.to))
.pipe(first())
.subscribe(
(res) => {
transaction.recipient = this.getAccountInfo(res, cacheSize);
},
(error) => {
transaction.recipient = defaultAccount;
this.userService.addAccount(defaultAccount, cacheSize);
}
);
if (transaction.from === environment.trustedDeclaratorAddress) {
transaction.sender = defaultAccount;
this.userService.addAccount(defaultAccount, cacheSize);
} else {
this.userService
.getAccountDetailsFromMeta(await User.toKey(transaction.from))
.pipe(first())
.subscribe(
(res) => {
transaction.sender = this.getAccountInfo(res, cacheSize);
},
(error) => {
this.loggingService.sendErrorLevelMessage(
`Account with address ${transaction.from} not found`,
this,
{ error }
);
}
);
}
if (transaction.to === environment.trustedDeclaratorAddress) {
transaction.recipient = defaultAccount;
this.userService.addAccount(defaultAccount, cacheSize);
} else {
this.userService
.getAccountDetailsFromMeta(await User.toKey(transaction.to))
.pipe(first())
.subscribe(
(res) => {
transaction.recipient = this.getAccountInfo(res, cacheSize);
},
(error) => {
this.loggingService.sendErrorLevelMessage(
`Account with address ${transaction.to} not found`,
this,
{ error }
);
}
);
}
} finally {
this.addTransaction(transaction, cacheSize);
}
@ -99,18 +115,26 @@ export class TransactionService {
conversion.fromValue = Number(conversion.fromValue);
conversion.toValue = Number(conversion.toValue);
try {
this.userService
.getAccountDetailsFromMeta(await User.toKey(conversion.trader))
.pipe(first())
.subscribe(
(res) => {
conversion.sender = conversion.recipient = this.getAccountInfo(res);
},
(error) => {
conversion.sender = conversion.recipient = defaultAccount;
this.userService.addAccount(defaultAccount, cacheSize);
}
);
if (conversion.trader === environment.trustedDeclaratorAddress) {
conversion.sender = conversion.recipient = defaultAccount;
this.userService.addAccount(defaultAccount, cacheSize);
} else {
this.userService
.getAccountDetailsFromMeta(await User.toKey(conversion.trader))
.pipe(first())
.subscribe(
(res) => {
conversion.sender = conversion.recipient = this.getAccountInfo(res);
},
(error) => {
this.loggingService.sendErrorLevelMessage(
`Account with address ${conversion.trader} not found`,
this,
{ error }
);
}
);
}
} finally {
this.addTransaction(conversion, cacheSize);
}