Skip to content

Commit

Permalink
Merge pull request #172 from proximax-storage/next
Browse files Browse the repository at this point in the history
Add new transactions and new node API fetch
  • Loading branch information
sleepyOwl14 authored Apr 22, 2024
2 parents a84d1c3 + 32cb364 commit 2e18cbc
Show file tree
Hide file tree
Showing 100 changed files with 8,103 additions and 224 deletions.
4 changes: 2 additions & 2 deletions e2e/conf/conf.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const conf = require("config");

import { MosaicId, NamespaceId, TransactionType, RegisterNamespaceTransaction, MosaicDefinitionTransaction,
TransferTransaction, TransactionInfo, MosaicNonce, MosaicProperties, UInt64, BlockInfo, ChainConfigTransaction, TransactionBuilderFactory, NetworkType, Account, Transaction } from '../../src/model/model';
TransferTransaction, TransactionInfo, MosaicNonce, MosaicProperties, UInt64, BlockInfo, NetworkConfigTransaction, TransactionBuilderFactory, NetworkType, Account, Transaction } from '../../src/model/model';
import { ConfUtils } from './ConfUtils';
import { AccountHttp, TransactionHttp, NamespaceHttp, MosaicHttp, BlockHttp, TransactionQueryParams } from '../../src/infrastructure/infrastructure';
import { firstValueFrom } from "rxjs"
Expand Down Expand Up @@ -226,7 +226,7 @@ const GetNemesisBlockDataPromise = () => {
const testNamespace = currencyNamespace ? currencyNamespace : regNamespaceTxs[0];
const regMosaicTx = txs.find(tx => tx.type === TransactionType.MOSAIC_DEFINITION) as MosaicDefinitionTransaction;
const transferTx = txs.find(tx => tx.type === TransactionType.TRANSFER) as TransferTransaction;
const config = txs.find(tx => tx.type === TransactionType.CHAIN_CONFIGURE) as ChainConfigTransaction;
const config = txs.find(tx => tx.type === TransactionType.CHAIN_CONFIGURE) as NetworkConfigTransaction;

return {
nemesisBlockInfo,
Expand Down
2 changes: 1 addition & 1 deletion e2e/infrastructure/MetadataHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { APIUrl, TestingAccount, ConfTestingNamespaceId, ConfTestingMosaicId, Co
import { MetadataHttp } from '../../src/infrastructure/MetadataHttp';
import { Address, Transaction, TransactionBuilderFactory, UInt64, Mosaic, NamespaceId } from '../../src/model/model';
import { Convert as convert } from '../../src/core/format';
import { MetadataModification, MetadataModificationType } from '../../src/model/transaction/ModifyMetadataTransaction';
import { MetadataModification, MetadataModificationType } from '../../src/model/transaction/deprecated/ModifyMetadataTransaction';
import { TransactionHttp, Listener } from '../../src/infrastructure/infrastructure';
import { validateTransactionConfirmed, validatePartialTransactionNotPartialAnyMore, validatePartialTransactionAnnouncedCorrectly } from '../utils';
import { fail } from 'assert';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import {expect} from 'chai';
import { APIUrl } from '../conf/conf.spec';
import { ChainConfigHttp } from '../../src/infrastructure/ChainConfigHttp';
describe('ChainConfigHttp', () => {
let chainConfigHttp = new ChainConfigHttp(APIUrl);
import { NetworkConfigHttp } from '../../src/infrastructure/NetworkConfigHttp';
describe('NetworkConfigHttp', () => {
let chainConfigHttp = new NetworkConfigHttp(APIUrl);

describe('getChainConfig', () => {
it('should return blockchain config', (done) => {
chainConfigHttp.getChainConfig(1)
chainConfigHttp.getNetworkConfig(1)
.subscribe((chainConfig) => {
expect(chainConfig.height.compact()).to.be.equal(1);
expect(chainConfig.networkConfig).not.to.be.undefined;
Expand Down
2 changes: 1 addition & 1 deletion e2e/infrastructure/TransactionHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ describe('TransactionHttp', () => {
describe('ChainConfigTransaction', () => {
((NemesisAccount.privateKey !== "0".repeat(64)) ? it : it.skip)('standalone', (done) => {
GetNemesisBlockDataPromise().then(nemesisBlockInfo => {
const chainConfigTransaction = factory.chainConfig()
const chainConfigTransaction = factory.networkConfig()
.applyHeightDelta(UInt64.fromUint(10))
.networkConfig(nemesisBlockInfo.config.networkConfig)
.supportedEntityVersions(nemesisBlockInfo.config.supportedEntityVersions)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tsjs-xpx-chain-sdk",
"version": "0.11.1",
"version": "0.11.2",
"description": "Proximax Blockchain sdk for typescript and javascript",
"scripts": {
"pretest": "npm run build",
Expand Down
63 changes: 58 additions & 5 deletions src/infrastructure/AccountHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import {from as observableFrom, Observable} from 'rxjs';
import {map, mergeMap} from 'rxjs/operators';
import { DtoMapping } from '../core/utils/DtoMapping';
import {AccountInfo} from '../model/account/AccountInfo';
import { AccountInfo } from '../model/account/AccountInfo';
import { SupplementalPublicKeys } from '../model/account/SupplementalPublicKeys';
import { AccountNames } from '../model/account/AccountNames';
import { AccountRestrictionsInfo } from '../model/account/AccountRestrictionsInfo';
import {Address} from '../model/account/Address';
Expand Down Expand Up @@ -91,18 +92,44 @@ export class AccountHttp extends Http implements AccountRepository {
return observableFrom(this.accountRoutesApi.getAccountInfo(address.plain(), requestOptions)).pipe(
map((response: AccountInfoResponse) => {
const accountInfoDTO = response.body;
const accVersion = accountInfoDTO.account.version ?? 1;
const address = Address.createFromEncoded(accountInfoDTO.account.address);
return new AccountInfo(
accountInfoDTO.meta,
Address.createFromEncoded(accountInfoDTO.account.address),
address,
new UInt64(accountInfoDTO.account.addressHeight),
accountInfoDTO.account.publicKey,
new UInt64(accountInfoDTO.account.publicKeyHeight),
accountInfoDTO.account.accountType.valueOf(),
accountInfoDTO.account.linkedAccountKey,
accountInfoDTO.account.mosaics.map((mosaicDTO) => new Mosaic(
new MosaicId(mosaicDTO.id),
new UInt64(mosaicDTO.amount),
)),
accountInfoDTO.account.lockedMosaics ?
accountInfoDTO.account.lockedMosaics.map((mosaicDTO) => new Mosaic(
new MosaicId(mosaicDTO.id),
new UInt64(mosaicDTO.amount),
)): [],
accountInfoDTO.account.linkedAccountKey,
accountInfoDTO.account.supplementalPublicKeys ?
new SupplementalPublicKeys(
accountInfoDTO.account.supplementalPublicKeys.linked ?
PublicAccount.createFromPublicKey(
accountInfoDTO.account.supplementalPublicKeys.linked,
address.networkType
) : undefined,
accountInfoDTO.account.supplementalPublicKeys.node ?
PublicAccount.createFromPublicKey(
accountInfoDTO.account.supplementalPublicKeys.node,
address.networkType
) : undefined,
accountInfoDTO.account.supplementalPublicKeys.vrf ?
PublicAccount.createFromPublicKey(
accountInfoDTO.account.supplementalPublicKeys.vrf,
address.networkType
) : undefined,
) : undefined,
accVersion
);
})
);
Expand Down Expand Up @@ -151,16 +178,42 @@ export class AccountHttp extends Http implements AccountRepository {
this.accountRoutesApi.getAccountsInfo(accountIdsBody, requestOptions))
.pipe(map((response: AccountsInfoResponse) => {
return response.body.map((accountInfoDTO: AccountInfoDTO) => {
const accVersion = accountInfoDTO.account.version ?? 1;
const address = Address.createFromEncoded(accountInfoDTO.account.address);
return new AccountInfo(
accountInfoDTO.meta,
Address.createFromEncoded(accountInfoDTO.account.address),
address,
new UInt64(accountInfoDTO.account.addressHeight),
accountInfoDTO.account.publicKey,
new UInt64(accountInfoDTO.account.publicKeyHeight),
accountInfoDTO.account.accountType.valueOf(),
accountInfoDTO.account.linkedAccountKey,
accountInfoDTO.account.mosaics.map((mosaicDTO: MosaicDTO) =>
new Mosaic(new MosaicId(mosaicDTO.id), new UInt64(mosaicDTO.amount))),
accountInfoDTO.account.lockedMosaics ?
accountInfoDTO.account.lockedMosaics.map((mosaicDTO) => new Mosaic(
new MosaicId(mosaicDTO.id),
new UInt64(mosaicDTO.amount),
)): [],
accountInfoDTO.account.linkedAccountKey,
accountInfoDTO.account.supplementalPublicKeys ?
new SupplementalPublicKeys(
accountInfoDTO.account.supplementalPublicKeys.linked ?
PublicAccount.createFromPublicKey(
accountInfoDTO.account.supplementalPublicKeys.linked,
address.networkType
) : undefined,
accountInfoDTO.account.supplementalPublicKeys.node ?
PublicAccount.createFromPublicKey(
accountInfoDTO.account.supplementalPublicKeys.node,
address.networkType
) : undefined,
accountInfoDTO.account.supplementalPublicKeys.vrf ?
PublicAccount.createFromPublicKey(
accountInfoDTO.account.supplementalPublicKeys.vrf,
address.networkType
) : undefined,
) : undefined,
accVersion
);
});
}));
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/ChainUpgradeHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class ChainUpgradeHttp extends Http implements ChainUpgradeRepository {
/**
* Gets blockchain configuration at given height
* @param height
* @returns Observable<ChainConfig>
* @returns Observable<NetworkConfig>
*/
public getChainUpgrade(height: number, requestOptions?: RequestOptions): Observable<ChainUpgrade> {
return observableFrom(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import {from as observableFrom, Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import { ConfigRoutesApi, NetworkConfigResponse } from './api';
import { ChainConfigRepository } from './ChainConfigRepository';
import { NetworkConfigRepository } from './NetworkConfigRepository';
import {Http} from './Http';
import { ChainConfig } from '../model/model';
import { NetworkConfig } from '../model/model';
import { RequestOptions } from './RequestOptions';

/**
* Chian http repository.
*
* @since 1.0
*/
export class ChainConfigHttp extends Http implements ChainConfigRepository {
export class NetworkConfigHttp extends Http implements NetworkConfigRepository {
/**
* @internal
* xpx chain Library chain config routes api
Expand All @@ -34,14 +34,14 @@ export class ChainConfigHttp extends Http implements ChainConfigRepository {
/**
* Gets blockchain configuration at given height
* @param height
* @returns Observable<ChainConfig>
* @returns Observable<NetworkConfig>
*/
public getChainConfig(height: number, requestOptions?: RequestOptions): Observable<ChainConfig> {
public getNetworkConfig(height: number, requestOptions?: RequestOptions): Observable<NetworkConfig> {
return observableFrom(
this.configRoutesApi.getConfig(height, requestOptions))
.pipe(
map((response: NetworkConfigResponse) => {
return ChainConfig.createFromDTO(response.body.networkConfig);
return NetworkConfig.createFromDTO(response.body.networkConfig);
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
// license that can be found in the LICENSE file

import {Observable} from 'rxjs';
import { ChainConfig } from '../model/model';
import { NetworkConfig } from '../model/model';
import { RequestOptions } from './RequestOptions';

/**
* Chain interface repository.
*
* @since 1.0
*/
export interface ChainConfigRepository {
export interface NetworkConfigRepository {
/**
* Gets config at given height
* @returns Observable<ChainConfig>
* @returns Observable<NetworkConfig>
*/
getChainConfig(height: number, requestOptions?: RequestOptions): Observable<ChainConfig>;
getNetworkConfig(height: number, requestOptions?: RequestOptions): Observable<NetworkConfig>;

}
58 changes: 52 additions & 6 deletions src/infrastructure/NodeHttp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 ProximaX
* Copyright 2024 ProximaX
* Copyright 2019 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,13 +16,18 @@
*/

import {from as observableFrom, Observable} from 'rxjs';
import {map} from 'rxjs/operators';
import {map, mergeMap} from 'rxjs/operators';
import { NodeInfo } from '../model/node/NodeInfo';
import { NodeTime } from '../model/node/NodeTime';
import { NodeInfoResponse, NodeRoutesApi, NodeTimeResponse } from './api';
import { NodeUnlockedAccount } from '../model/node/NodeUnlockedAccount';
import { NodePeers, PeerInfo } from '../model/node/NodePeers';
import { NodeInfoResponse, NodePeersResponse, NodeRoutesApi, NodeTimeResponse, NodeUnlockedAccountResponse } from './api';
import {Http} from './Http';
import {NodeRepository} from './NodeRepository';
import { RequestOptions } from './RequestOptions';
import { PublicAccount } from "../model/account/PublicAccount";
import { NetworkType } from '../model/model';
import {NetworkHttp} from './NetworkHttp';

/**
* Node http repository.
Expand All @@ -39,11 +44,12 @@ export class NodeHttp extends Http implements NodeRepository {
/**
* Constructor
* @param url
* @param networkHttp
*/
constructor(url: string) {
super();
constructor(url: string, networkHttp?: NetworkHttp) {
networkHttp = networkHttp == null ? new NetworkHttp(url) : networkHttp;
super(networkHttp);
this.nodeRoutesApi = new NodeRoutesApi(url);

}

/**
Expand Down Expand Up @@ -79,4 +85,44 @@ export class NodeHttp extends Http implements NodeRepository {
})
);
}

public getNodeUnlockedAccounts(requestOptions?: RequestOptions): Observable<NodeUnlockedAccount> {
return this.getNetworkTypeObservable(requestOptions).pipe(
mergeMap((networkType: NetworkType) =>
observableFrom(this.nodeRoutesApi.getNodeUnlockedAccounts(requestOptions))
.pipe(
map((response: NodeUnlockedAccountResponse) => {
const nodeUnlockedAccountDTOs = response.body;
return new NodeUnlockedAccount(
nodeUnlockedAccountDTOs.map(
x => PublicAccount.createFromPublicKey(x.PublicKey, networkType)
)
);
})
)
)
);
}

public getNodePeers(requestOptions?: RequestOptions): Observable<NodePeers> {
return observableFrom(this.nodeRoutesApi.getNodePeers(requestOptions))
.pipe(
map((response: NodePeersResponse) => {
const nodePeersDTOs = response.body;
return new NodePeers(
nodePeersDTOs.map(
x => new PeerInfo(
x.publicKey,
x.port,
x.networkIdentifier,
x.version,
x.roles,
x.host,
x.friendlyName
)
)
);
})
)
}
}
Loading

0 comments on commit 2e18cbc

Please sign in to comment.