-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.0' into feat/wrapper-refactor
- Loading branch information
Showing
20 changed files
with
277 additions
and
71 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 was deleted.
Oops, something went wrong.
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,38 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Payload, PayloadDiscriminator } from '../payload'; | ||
import { Type } from 'class-transformer'; | ||
import { StrongParents, WeakParents, ShallowLikeParents } from '../parents'; | ||
import { Block } from './block'; | ||
import { u64 } from '../../utils'; | ||
|
||
/** | ||
* Basic Block layout. | ||
*/ | ||
export class BasicBlock extends Block { | ||
/** | ||
* Blocks that are strongly directly approved. | ||
*/ | ||
readonly strongParents!: StrongParents; | ||
/** | ||
* Blocks that are weakly directly approved. | ||
*/ | ||
readonly weakParents!: WeakParents; | ||
/** | ||
* Blocks that are directly referenced to adjust opinion. | ||
*/ | ||
readonly shallowLikeParents!: ShallowLikeParents; | ||
/** | ||
* The payload contents. | ||
*/ | ||
@Type(() => Payload, { | ||
discriminator: PayloadDiscriminator, | ||
}) | ||
readonly payload?: Payload; | ||
/** | ||
* The amount of mana the Account identified by IssuerID is at most | ||
* willing to burn for this block. | ||
*/ | ||
readonly burnedMana!: u64; | ||
} |
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,43 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { BasicBlock } from './basic'; | ||
/** | ||
* All of the block types. | ||
*/ | ||
export enum BlockType { | ||
/// A Basic block. | ||
Basic = 0, | ||
} | ||
|
||
export abstract class Block { | ||
readonly type: BlockType; | ||
|
||
/** | ||
* @param type The type of Block. | ||
*/ | ||
constructor(type: BlockType) { | ||
this.type = type; | ||
} | ||
|
||
/** | ||
* Checks whether the block is a `BasicBlock`. | ||
* @returns true if it is, otherwise false | ||
*/ | ||
isBasic(): boolean { | ||
return this.type === BlockType.Basic; | ||
} | ||
|
||
/** | ||
* Gets the block as an actual `BasicBlock`. | ||
* NOTE: Will throw an error if the block is not a `BasicBlock`. | ||
* @returns The block | ||
*/ | ||
asBasic(): BasicBlock { | ||
if (this.isBasic()) { | ||
return this as unknown as BasicBlock; | ||
} else { | ||
throw new Error('invalid downcast of non-BasicBlock'); | ||
} | ||
} | ||
} |
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,15 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { BlockType } from './block'; | ||
import { BasicBlock } from './basic'; | ||
|
||
export * from './block'; | ||
export * from './basic'; | ||
export * from './wrapper'; | ||
|
||
// Here because in block.ts it causes a circular dependency | ||
export const BlockDiscriminator = { | ||
property: 'type', | ||
subTypes: [{ value: BasicBlock, name: BlockType.Basic as any }], | ||
}; |
Oops, something went wrong.