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: { meta: {
TYP: [], TYP: [],
}, },
value: '', value: '+254700000000',
}, },
], ],
version: [ version: [

View File

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