Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(api): cleanup model TODOs, calculate synced flag #289

Merged
merged 2 commits into from
Oct 31, 2023
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
10 changes: 0 additions & 10 deletions packages/api-database/source/models/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ export class Block {
@Column({
primary: true,
type: "varchar",
// TODO: length depends on hash size...
// length: 64,
})
public readonly id!: string;

Expand All @@ -28,8 +26,6 @@ export class Block {

@Column({
type: "varchar",
// TODO: length depends on hash size...
// length: 64,
})
public readonly previousBlock!: string;

Expand Down Expand Up @@ -72,24 +68,18 @@ export class Block {
@Column({
nullable: false,
type: "varchar",
// TODO: length depends on hash size...
// length: 64,
})
public readonly payloadHash!: string;

@Column({
nullable: false,
type: "varchar",
// TODO: length depends on public key size...
// length: 66,
})
public readonly generatorPublicKey!: string;

@Column({
nullable: false,
type: "varchar",
// TODO: length depends on signature size...
// length: 256,
})
public readonly signature!: string;
}
6 changes: 0 additions & 6 deletions packages/api-database/source/models/mempool-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export class MempoolTransaction {
@Column({
primary: true,
type: "varchar",
// TODO: length depends on hash size...
// length: 64,
})
public id!: string;

Expand Down Expand Up @@ -42,8 +40,6 @@ export class MempoolTransaction {
@Column({
nullable: false,
type: "varchar",
// TODO: length depends on public key size...
// length: 66,
})
public senderPublicKey!: string;

Expand Down Expand Up @@ -85,8 +81,6 @@ export class MempoolTransaction {
@Column({
nullable: false,
type: "varchar",
// TODO: length depends on signature size...
// length: 256,
})
public readonly signature!: string;
}
8 changes: 0 additions & 8 deletions packages/api-database/source/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export class Transaction {
@Column({
primary: true,
type: "varchar",
// TODO: length depends on hash size...
// length: 64,
})
public id!: string;

Expand All @@ -36,8 +34,6 @@ export class Transaction {
@Column({
nullable: false,
type: "varchar",
// TODO: length depends on hash size..., also consider only storing height to save size since hash can be retrieved via join
// length: 64,
})
public blockId!: string;

Expand Down Expand Up @@ -68,8 +64,6 @@ export class Transaction {
@Column({
nullable: false,
type: "varchar",
// TODO: length depends on public key size...
// length: 66,
})
public senderPublicKey!: string;

Expand Down Expand Up @@ -111,8 +105,6 @@ export class Transaction {
@Column({
nullable: false,
type: "varchar",
// TODO: length depends on signature size...
// length: 256,
})
public readonly signature!: string;
}
4 changes: 0 additions & 4 deletions packages/api-database/source/models/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export class Wallet {
@Column({
primary: true,
type: "varchar",
// TODO: length depends on address size...
// length: 64,
})
public address!: string;

Expand All @@ -18,8 +16,6 @@ export class Wallet {
nullable: true,
type: "varchar",
unique: true,
// TODO: length depends on public key size...
// length: 66,
})
public publicKey!: string | undefined;

Expand Down
19 changes: 10 additions & 9 deletions packages/api-http/source/controllers/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,30 @@ export class NodeController extends Controller {

public async status(request: Hapi.Request) {
const state = await this.getState();
const medianPeerHeight = await this.peerRepositoryFactory().getMedianPeerHeight();
const ownHeight = Number(state?.height ?? 0);

return {
data: {
blocksCount: state ? (await this.peerRepositoryFactory().getMedianPeerHeight()) - +state.height : 0,
now: Number(state?.height ?? 0),
// TODO: add flag
synced: false,

blocksCount: state ? medianPeerHeight - ownHeight : 0,
now: ownHeight,
synced: ownHeight >= medianPeerHeight,
timestamp: dayjs().unix(),
},
};
}

public async syncing(request: Hapi.Request) {
const state = await this.getState();
const medianPeerHeight = await this.peerRepositoryFactory().getMedianPeerHeight();
const ownHeight = Number(state?.height ?? 0);

return {
data: {
blocks: state ? (await this.peerRepositoryFactory().getMedianPeerHeight()) - +state.height : 0,
height: Number(state?.height ?? 0),
blocks: state ? medianPeerHeight - ownHeight : 0,
height: ownHeight,
id: state?.id ?? 0,
// TODO: add flag
syncing: false,
syncing: ownHeight < medianPeerHeight,
},
};
}
Expand Down
Loading