Skip to content

Commit

Permalink
add type field and state serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
tammo committed Apr 14, 2020
1 parent c298b56 commit a571708
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export enum BlockType {
}

export class Block {
__type: 'Block';
id: StorageId;
chainId: StorageId;
txId: string;
Expand All @@ -55,6 +56,12 @@ export class Block {
senderAmount: EncryptedNumber;
publicNtruKey: NTRUPublicKey | undefined;

state?: string;

constructor() {
this.__type = 'Block';
}

getDataForSignature(): SignatureData {
const {
type,
Expand Down Expand Up @@ -148,6 +155,7 @@ export function fromBlockObject(obj: any) {
block.senderBalance = obj.senderBalance;
block.senderAmount = obj.senderAmount;
block.publicNtruKey = obj.publicNtruKey;
block.state = obj.state;

return block;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum AssetSymbol {
}

export class Blockchain {
__type: 'Blockchain';
id: StorageId;
leafId: StorageId | undefined;
publicSig: SigPublicKey;
Expand All @@ -16,6 +17,7 @@ export class Blockchain {
blocks: Block[] = [];

constructor(publicSig: SigPublicKey, publicNtru?: NTRUPublicKey, symbol?: AssetSymbol) {
this.__type = 'Blockchain';
this.publicSig = publicSig;
this.publicNtru = publicNtru;
this.assetSymbol = symbol || AssetSymbol.TXL;
Expand Down
4 changes: 3 additions & 1 deletion src/Transaction.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Block, BlockType } from './Block';
import { SigPublicKey, NTRUPublicKey } from './Keys';
import { SigPublicKey } from './Keys';
import { StorageId } from './Storage';
import { AssetSymbol } from './Blockchain';

export class Transaction {
__type: 'Transaction';
id: StorageId;
blocks: Block[] = [];

constructor(symbol?: AssetSymbol) {
this.__type = 'Transaction';
this.assetSymbol = symbol || AssetSymbol.TXL;
}

Expand Down

0 comments on commit a571708

Please sign in to comment.