-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgetStellarAccountActivationStatus.ts
More file actions
67 lines (60 loc) · 2.1 KB
/
Copy pathgetStellarAccountActivationStatus.ts
File metadata and controls
67 lines (60 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import type {
GetStellarAccountActivationStatusJsonRpcRequest,
GetStellarAccountActivationStatusJsonRpcResponse,
} from './api';
import {
GetStellarAccountActivationStatusJsonRpcRequestStruct,
GetStellarAccountActivationStatusJsonRpcResponseStruct,
} from './api';
import type { AccountService } from '../../services/account';
import type { NetworkService } from '../../services/network';
import type { ILogger } from '../../utils/logger';
import { createPrefixedLogger } from '../../utils/logger';
import { BaseHandler } from '../base';
export class GetStellarAccountActivationStatusHandler extends BaseHandler<
GetStellarAccountActivationStatusJsonRpcRequest,
GetStellarAccountActivationStatusJsonRpcResponse
> {
readonly #accountService: AccountService;
readonly #networkService: NetworkService;
constructor({
logger,
accountService,
networkService,
}: {
logger: ILogger;
accountService: AccountService;
networkService: NetworkService;
}) {
const prefixedLogger = createPrefixedLogger(
logger,
'[GetStellarAccountActivationStatusHandler]',
);
super({
logger: prefixedLogger,
requestStruct: GetStellarAccountActivationStatusJsonRpcRequestStruct,
responseStruct: GetStellarAccountActivationStatusJsonRpcResponseStruct,
});
this.#accountService = accountService;
this.#networkService = networkService;
}
/**
* Returns whether the account exists on Horizon for the requested network scope.
*
* @param request - JSON-RPC request with `accountId` and `scope`.
* @returns `{ activated: true }` when Horizon has the account; `false` when missing / not funded on-ledger.
*/
protected async handleRequest(
request: GetStellarAccountActivationStatusJsonRpcRequest,
): Promise<GetStellarAccountActivationStatusJsonRpcResponse> {
const { accountId, scope } = request.params;
const { account } = await this.#accountService.resolveAccount({
accountId,
});
const onChain = await this.#networkService.getAccountOrNull(
account.address,
scope,
);
return { activated: onChain !== null };
}
}