Skip to content

Commit

Permalink
feat: introduce asset symbol enum
Browse files Browse the repository at this point in the history
  • Loading branch information
tammo committed Feb 28, 2020
1 parent 1baaf9e commit 5365068
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions etc/sqlite/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ CREATE TABLE IF NOT EXISTS blockchains (
id VARCHAR(64) UNIQUE PRIMARY KEY NOT NULL,
public_key TEXT UNIQUE NOT NULL,
public_ntru TEXT UNIQUE,
asset_symbol TEXT,
leaf_id VARCHAR(64) UNIQUE,
FOREIGN KEY (leaf_id) REFERENCES blocks(id)
);
Expand Down
13 changes: 7 additions & 6 deletions etc/sqlite/sqlite.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

### blockchains

| Field | Flags | Description |
| ----------- | ----------------------- | -------------------------------------------- |
| id | PK, unique, not null | **VARCHAR(64)** hash of the public_key field |
| public_key | unique, not null | **TEXT** signature public key |
| leaf_id | FK -> blocks.id, unique | **VARCHAR(64)** block id |
| public_ntru | unique | **TEXT** ntru public key |
| Field | Flags | Description |
| ------------ | ----------------------- | -------------------------------------------- |
| id | PK, unique, not null | **VARCHAR(64)** hash of the public_key field |
| public_key | unique, not null | **TEXT** signature public key |
| leaf_id | FK -> blocks.id, unique | **VARCHAR(64)** block id |
| public_ntru | unique | **TEXT** ntru public key |
| asset_symbol | | **TEXT** asset symbol, e.g. TXL or BTC |

### blocks

Expand Down
11 changes: 9 additions & 2 deletions src/Blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ import { Block, fromBlockObject, BlockType } from './Block';
import { SigPublicKey, NTRUPublicKey } from './Keys';
import { StorageId } from './Storage';

export enum AssetSymbol {
TXL = 'TXL',
BTC = 'BTC',
}

export class Blockchain {
id: StorageId;
leafId: StorageId | undefined;
publicSig: SigPublicKey;
publicNtru: NTRUPublicKey | undefined;
assetSymbol: AssetSymbol;
blocks: Block[] = [];

constructor(publicSig: string, publicNtru?: string) {
constructor(publicSig: string, publicNtru?: string, symbol?: AssetSymbol) {
this.publicSig = publicSig;
this.publicNtru = publicNtru;
this.assetSymbol = symbol || AssetSymbol.TXL;
}

addBlock(block: Block): void {
Expand All @@ -33,7 +40,7 @@ export class Blockchain {
}

export function fromBlockchainObject(obj: any) {
const chain = new Blockchain(obj.publicSig, obj.publicNtru);
const chain = new Blockchain(obj.publicSig, obj.publicNtru, obj.assetSymbol);
chain.blocks = obj.blocks.map(deserializeBlock);

return chain;
Expand Down
6 changes: 6 additions & 0 deletions src/Transaction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Block, BlockType } from './Block';
import { SigPublicKey, NTRUPublicKey } from './Keys';
import { StorageId } from './Storage';
import { AssetSymbol } from './Blockchain';

export class Transaction {
id: StorageId;
Expand All @@ -26,6 +27,11 @@ export class Transaction {
*/
networkApprovalAt?: number;

/**
* Explicitly use this asset.
*/
assetSymbol?: AssetSymbol;

/**
* Return true if transaction wants to write an opening block.
*/
Expand Down

0 comments on commit 5365068

Please sign in to comment.