Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 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
Expand Up @@ -113,7 +113,7 @@
"ripemd160": "^2.0.2",
"rxjs": "^6.6.3",
"rxjs-compat": "^6.6.3",
"symbol-openapi-typescript-fetch-client": "0.10.1-SNAPSHOT.202011161425",
"symbol-openapi-typescript-fetch-client": "0.10.1-SNAPSHOT.202011191848",
"tweetnacl": "^1.0.3",
"ws": "^7.3.1"
},
Expand Down
21 changes: 19 additions & 2 deletions src/infrastructure/BlockHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
*/

import { Observable } from 'rxjs';
import { BlockInfoDTO, BlockRoutesApi } from 'symbol-openapi-typescript-fetch-client';
import { BlockInfoDTO, BlockRoutesApi, ImportanceBlockDTO } from 'symbol-openapi-typescript-fetch-client';
import { DtoMapping } from '../core/utils/DtoMapping';
import { Address } from '../model/account/Address';
import { PublicAccount } from '../model/account/PublicAccount';
import { BlockInfo } from '../model/blockchain/BlockInfo';
import { BlockType } from '../model/blockchain/BlockType';
import { MerklePathItem } from '../model/blockchain/MerklePathItem';
import { MerkleProofInfo } from '../model/blockchain/MerkleProofInfo';
import { NemesisImportanceBlockInfo } from '../model/blockchain/NemesisImportanceBlockInfo';
import { NormalBlockInfo } from '../model/blockchain/NomalBlockInfo';
import { UInt64 } from '../model/UInt64';
import { BlockRepository } from './BlockRepository';
import { Http } from './Http';
Expand Down Expand Up @@ -88,7 +91,8 @@ export class BlockHttp extends Http implements BlockRepository {
*/
private toBlockInfo(dto: BlockInfoDTO): BlockInfo {
const networkType = dto.block.network.valueOf();
return new BlockInfo(
const blockType = dto.block.type;
const normalBlock = new NormalBlockInfo(
dto.id ?? '',
dto.block.size,
dto.meta.hash,
Expand Down Expand Up @@ -116,6 +120,19 @@ export class BlockHttp extends Http implements BlockRepository {
dto.meta.transactionsCount,
dto.meta.statementsCount,
);
if (blockType === BlockType.NormalBlock.valueOf()) {
return normalBlock;
} else if ([BlockType.ImportanceBlock.valueOf(), BlockType.NemesisBlock.valueOf()].includes(blockType)) {
const importanceBlockInfoDto = dto.block as ImportanceBlockDTO;
return DtoMapping.assign(normalBlock, {
votingEligibleAccountsCount: importanceBlockInfoDto.votingEligibleAccountsCount,
harvestingEligibleAccountsCount: UInt64.fromNumericString(importanceBlockInfoDto.harvestingEligibleAccountsCount),
totalVotingBalance: UInt64.fromNumericString(importanceBlockInfoDto.totalVotingBalance),
previousImportanceBlockHash: importanceBlockInfoDto.previousImportanceBlockHash,
}) as NemesisImportanceBlockInfo;
} else {
throw new Error(`Block type: ${blockType} invalid.`);
}
}

/**
Expand Down
152 changes: 5 additions & 147 deletions src/model/blockchain/BlockInfo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright 2018 NEM
* Copyright 2020 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License"),
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
Expand All @@ -14,149 +14,7 @@
* limitations under the License.
*/

import { Address } from '../account/Address';
import { PublicAccount } from '../account/PublicAccount';
import { NetworkType } from '../network/NetworkType';
import { UInt64 } from '../UInt64';
import { NemesisImportanceBlockInfo } from './NemesisImportanceBlockInfo';
import { NormalBlockInfo } from './NomalBlockInfo';

/**
* The block info structure describes basic information of a block.
*/
export class BlockInfo {
/**
* @param recordId
* @param size
* @param hash
* @param generationHash
* @param totalFee
* @param stateHashSubCacheMerkleRoots
* @param numTransactions
* @param signature
* @param signer
* @param networkType
* @param version
* @param type
* @param height
* @param timestamp
* @param difficulty
* @param proofGamma
* @param proofScalar
* @param proofVerificationHash
* @param feeMultiplier
* @param previousBlockHash
* @param blockTransactionsHash
* @param blockReceiptsHash
* @param blockStateHash
* @param beneficiaryAddress
* @param numStatements
*/
constructor(
/**
* The database record id.
*/
public readonly recordId: string,
/**
* Entity size in bytes.
*/
public readonly size: number,
/**
* The block hash.
*/
public readonly hash: string,
/**
* The generation hash
*/
public readonly generationHash: string,
/**
* The sum of all transaction fees included in the block.
*/
public readonly totalFee: UInt64,
/**
* State hash sub cache merkle roots
*/
public readonly stateHashSubCacheMerkleRoots: string[],
/**
* The total number of transactions confirmed (including embedded transaction) included.
*/
public readonly totalTransactionsCount: number,
/**
* The block signature.
* The signature was generated by the signer and can be used to validate that the blockchain
* data was not modified by a node.
*/
public readonly signature: string,
/**
* The public account of block harvester.
*/
public readonly signer: PublicAccount,
/**
* The network type.
*/
public readonly networkType: NetworkType,
/**
* The transaction version.
*/
public readonly version: number,
/**
* The block type.
*/
public readonly type: number,
/**
* The height of which the block was confirmed.
* Each block has a unique height. Subsequent blocks differ in height by 1.
*/
public readonly height: UInt64,
/**
* The number of milliseconds elapsed since the creation of the nemesis blockchain.
*/
public readonly timestamp: UInt64,
/**
* The POI difficulty to harvest a block.
*/
public readonly difficulty: UInt64,
/**
* The feeMultiplier defined by the harvester.
*/
public readonly feeMultiplier: number,
/**
* The last block hash.
*/
public readonly previousBlockHash: string,
/**
* The block transaction hash.
*/
public readonly blockTransactionsHash: string,
/**
* The block receipt hash.
*/
public readonly blockReceiptsHash: string,
/**
* The state hash.
*/
public readonly stateHash: string,
/**
* The proof gamma.
*/
public readonly proofGamma: string,
/**
* The proof scalar.
*/
public readonly proofScalar: string,
/**
* The proof verification hash.
*/
public readonly proofVerificationHash: string,
/**
* The beneficiary address.
*/
public readonly beneficiaryAddress: Address,
/**
* The number of statements confiemd (excluding embedded transaction) included.
*/
public readonly transactionsCount: number,
/**
* The number of statements included.
*/
public readonly statementsCount: number,
) {}
}
export type BlockInfo = NormalBlockInfo | NemesisImportanceBlockInfo;
21 changes: 21 additions & 0 deletions src/model/blockchain/BlockType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2020 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export enum BlockType {
NemesisBlock = 0x8043,
NormalBlock = 0x8143,
ImportanceBlock = 0x8243,
}
25 changes: 25 additions & 0 deletions src/model/blockchain/NemesisImportanceBlockInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2020 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { UInt64 } from '../UInt64';
import { NormalBlockInfo } from './NomalBlockInfo';

export type NemesisImportanceBlockInfo = NormalBlockInfo & {
votingEligibleAccountsCount: number;
harvestingEligibleAccountsCount: UInt64;
totalVotingBalance: UInt64;
previousImportanceBlockHash: string;
};
Loading