-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* nodejs rename block types * Call inner methods * Update bindings/nodejs/lib/types/block/core/block-body.ts * Add BlockHeader --------- Co-authored-by: Thibault Martinez <[email protected]> Co-authored-by: Thibault Martinez <[email protected]>
- Loading branch information
1 parent
3d0cfd5
commit c32fe8c
Showing
16 changed files
with
309 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { BasicBlockBody } from './basic'; | ||
import { ValidationBlockBody } from './validation'; | ||
|
||
/** | ||
* All of the block body types. | ||
*/ | ||
export enum BlockBodyType { | ||
/// A Basic block body. | ||
Basic = 0, | ||
/// A Validation block body. | ||
Validation = 1, | ||
} | ||
|
||
export abstract class BlockBody { | ||
readonly type: BlockBodyType; | ||
|
||
/** | ||
* @param type The type of BlockBody. | ||
*/ | ||
constructor(type: BlockBodyType) { | ||
this.type = type; | ||
} | ||
|
||
/** | ||
* Checks whether the block body is a `BasicBlockBody`. | ||
* @returns true if it is, otherwise false | ||
*/ | ||
isBasic(): boolean { | ||
return this.type === BlockBodyType.Basic; | ||
} | ||
|
||
/** | ||
* Gets the block body as an actual `BasicBlockBody`. | ||
* NOTE: Will throw an error if the block is not a `BasicBlockBody`. | ||
* @returns The BasicBlockBody | ||
*/ | ||
asBasic(): BasicBlockBody { | ||
if (this.isBasic()) { | ||
return this as unknown as BasicBlockBody; | ||
} else { | ||
throw new Error('invalid downcast of non-BasicBlockBody'); | ||
} | ||
} | ||
|
||
/** | ||
* Checks whether the block body is a `ValidationBlockBody`. | ||
* @returns true if it is, otherwise false | ||
*/ | ||
isValidation(): boolean { | ||
return this.type === BlockBodyType.Validation; | ||
} | ||
|
||
/** | ||
* Gets the block body as an actual `ValidationBlockBody`. | ||
* NOTE: Will throw an error if the block is not a `ValidationBlockBody`. | ||
* @returns The ValidationBlockBody | ||
*/ | ||
asValidation(): ValidationBlockBody { | ||
if (this.isValidation()) { | ||
return this as unknown as ValidationBlockBody; | ||
} else { | ||
throw new Error('invalid downcast of non-ValidationBlockBody'); | ||
} | ||
} | ||
} |
Oops, something went wrong.