• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

proximax-storage / tsjs-xpx-chain-sdk / 8778928347

22 Apr 2024 05:20AM UTC coverage: 67.306% (-3.7%) from 71.021%
8778928347

push

github

web-flow
Merge pull request #172 from proximax-storage/next

Add new transactions and new node API fetch

1207 of 2739 branches covered (44.07%)

Branch coverage included in aggregate %.

359 of 1167 new or added lines in 63 files covered. (30.76%)

2 existing lines in 1 file now uncovered.

8977 of 12392 relevant lines covered (72.44%)

140180.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.74
/src/infrastructure/NodeHttp.ts
1
/*
2
 * Copyright 2024 ProximaX
3
 * Copyright 2019 NEM
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17

18
import {from as observableFrom, Observable} from 'rxjs';
1✔
19
import {map, mergeMap} from 'rxjs/operators';
1✔
20
import { NodeInfo } from '../model/node/NodeInfo';
1✔
21
import { NodeTime } from '../model/node/NodeTime';
1✔
22
import { NodeUnlockedAccount } from '../model/node/NodeUnlockedAccount';
1✔
23
import { NodePeers, PeerInfo } from '../model/node/NodePeers';
1✔
24
import { NodeInfoResponse, NodePeersResponse, NodeRoutesApi, NodeTimeResponse, NodeUnlockedAccountResponse } from './api';
1✔
25
import {Http} from './Http';
1✔
26
import {NodeRepository} from './NodeRepository';
27
import { RequestOptions } from './RequestOptions';
28
import { PublicAccount } from "../model/account/PublicAccount";
1✔
29
import { NetworkType } from '../model/model';
30
import {NetworkHttp} from './NetworkHttp';
1✔
31

32
/**
33
 * Node http repository.
34
 *
35
 * @since 1.0
36
 */
37
export class NodeHttp extends Http implements NodeRepository {
1✔
38
    /**
39
     * @internal
40
     * xpx chain Library account routes api
41
     */
42
    private nodeRoutesApi: NodeRoutesApi;
43

44
    /**
45
     * Constructor
46
     * @param url
47
     * @param networkHttp
48
     */
49
    constructor(url: string, networkHttp?: NetworkHttp) {
50
        networkHttp = networkHttp == null ? new NetworkHttp(url) : networkHttp;
1!
51
        super(networkHttp);
1✔
52
        this.nodeRoutesApi = new NodeRoutesApi(url);
1✔
53
    }
54

55
    /**
56
     * Supplies additional information about the application running on a node.
57
     * @summary Get the node information
58
     */
59
    public getNodeInfo(requestOptions?: RequestOptions): Observable<NodeInfo> {
60
        return observableFrom(this.nodeRoutesApi.getNodeInfo(requestOptions)).pipe(
1✔
61
            map((response: NodeInfoResponse) => {
62
                const nodeInfoDTO = response.body;
1✔
63
                return new NodeInfo(
1✔
64
                    nodeInfoDTO.publicKey,
65
                    nodeInfoDTO.port,
66
                    nodeInfoDTO.networkIdentifier,
67
                    nodeInfoDTO.version,
68
                    nodeInfoDTO.roles as number,
69
                    nodeInfoDTO.host,
70
                    nodeInfoDTO.friendlyName,
71
                );
72
            })
73
        );
74
    }
75

76
    /**
77
     * Gets the node time at the moment the reply was sent and received.
78
     * @summary Get the node time
79
     */
80
    public getNodeTime(requestOptions?: RequestOptions): Observable<NodeTime> {
81
        return observableFrom(this.nodeRoutesApi.getNodeTime(requestOptions)).pipe(
1✔
82
            map((response: NodeTimeResponse) => {
83
                const nodeTimeDTO = response.body;
1✔
84
                return new NodeTime(nodeTimeDTO.communicationTimestamps.sendTimestamp, nodeTimeDTO.communicationTimestamps.receiveTimestamp);
1✔
85
            })
86
        );
87
    }
88

89
    public getNodeUnlockedAccounts(requestOptions?: RequestOptions): Observable<NodeUnlockedAccount> {
NEW
90
        return this.getNetworkTypeObservable(requestOptions).pipe(
×
91
            mergeMap((networkType: NetworkType) => 
NEW
92
                observableFrom(this.nodeRoutesApi.getNodeUnlockedAccounts(requestOptions))
×
93
                .pipe(
94
                    map((response: NodeUnlockedAccountResponse) => {
NEW
95
                        const nodeUnlockedAccountDTOs = response.body;
×
NEW
96
                        return new NodeUnlockedAccount(
×
97
                            nodeUnlockedAccountDTOs.map(
NEW
98
                                x => PublicAccount.createFromPublicKey(x.PublicKey, networkType)
×
99
                            )
100
                        );
101
                    })
102
                )
103
            )
104
        );
105
    }
106

107
    public getNodePeers(requestOptions?: RequestOptions): Observable<NodePeers> {
NEW
108
        return observableFrom(this.nodeRoutesApi.getNodePeers(requestOptions))
×
109
                .pipe(
110
                    map((response: NodePeersResponse) => {
NEW
111
                        const nodePeersDTOs = response.body;
×
NEW
112
                        return new NodePeers(
×
113
                            nodePeersDTOs.map(
NEW
114
                                x => new PeerInfo(
×
115
                                    x.publicKey,
116
                                    x.port,
117
                                    x.networkIdentifier,
118
                                    x.version,
119
                                    x.roles,
120
                                    x.host,
121
                                    x.friendlyName
122
                                )
123
                            )
124
                        );
125
                    })
126
                )
127
    }
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc