Skip to content

Commit

Permalink
Merge branch 'main' into security-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
faberto committed Jan 30, 2024
2 parents 3606e11 + fea4083 commit 72ea178
Show file tree
Hide file tree
Showing 13 changed files with 3,774 additions and 2,568 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
uses: docker/build-push-action@94d76d3bc1409736cb5dc1ada9502bec3a72973c
with:
context: ./backend
file: backend/Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-frontend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
uses: docker/build-push-action@94d76d3bc1409736cb5dc1ada9502bec3a72973c
with:
context: .
file: Dockerfile
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# use node 20 alpine image as build image
FROM node:20.11.0-alpine3.19 as build
FROM node:20.11.0-alpine3.19@sha256:2f46fd49c767554c089a5eb219115313b72748d8f62f5eccb58ef52bc36db4ad as build

# create work directory in app folder
WORKDIR /app
Expand All @@ -26,7 +26,7 @@ RUN chmod +x /app/postbuild.sh
RUN npm run build || npm run build

#---------------------------------------------
FROM node:20.11.0-alpine3.19 as run
FROM node:20.11.0-alpine3.19@sha256:2f46fd49c767554c089a5eb219115313b72748d8f62f5eccb58ef52bc36db4ad as run

WORKDIR /app

Expand Down
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# use node 20 alpine image as build image
FROM node:20-alpine
FROM node:20-alpine@sha256:2f46fd49c767554c089a5eb219115313b72748d8f62f5eccb58ef52bc36db4ad

# create work directory in app folder
WORKDIR /app
Expand Down
656 changes: 419 additions & 237 deletions backend/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
"start": "npx node dist/index.js"
},
"dependencies": {
"@kubernetes/client-node": "^0.19.0",
"@kubernetes/client-node": "^0.20.0",
"body-parser": "^1.20.2",
"express": "^4.18.2",
"js-yaml": "^4.1.0",
"morgan": "^1.10.0",
"nimiq-rpc-client-ts": "^0.1.2",
"node-persist": "^3.1.3",
"nimiq-rpc-client-ts": "^0.3.0",
"node-persist": "^4.0.0",
"ofetch": "^1.3.3"
},
"devDependencies": {
"@types/express": "^4.17.19",
"@types/morgan": "^1.9.7",
"@types/node-persist": "^3.1.4",
"typescript": "^5.2.2",
"vite-node": "^0.34.6"
"vite-node": "^1.0.0"
}
}
18 changes: 9 additions & 9 deletions backend/src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import type {
CallResult,
PartialBlock,
Transaction,
Validator,
} from 'nimiq-rpc-client-ts';
import Client from 'nimiq-rpc-client-ts';
import { Client } from 'nimiq-rpc-client-ts';
import { Buffer } from 'node:buffer';
import { getDollarPriceHistory, lunaToNim } from './pricing.js';

Expand Down Expand Up @@ -51,19 +50,19 @@ export function convertAddressForRPC(address: string): Address {
* @param address
* @returns
*/

/*
export async function getValidatorStatus(
address: Address,
): Promise<ValidatorStatus> {
const client = getClient();
const validator: CallResult<Validator> =
await client.validator.byAddress(address);
await client.blockchain.getValidatorByAddress(address);
if (validator.error) return ValidatorStatus.UNKNOWN;
if (validator.data.inactivityFlag) return ValidatorStatus.INACTIVE;
return ValidatorStatus.ACTIVE;
}
} */

/**
* Gets the Block at a specific block number
Expand All @@ -73,7 +72,7 @@ export async function getValidatorStatus(
export async function getBlock(blockNumber: number) {
const client = getClient();
const block: CallResult<PartialBlock> =
await client.block.getByNumber(blockNumber);
await client.blockchain.getBlockByNumber(blockNumber);
return block.data;
}

Expand Down Expand Up @@ -106,7 +105,7 @@ export async function getPaymentStatus(address: Address): Promise<any> {
// Format extra data: Staqe,NQ61 AE12 FJ43 QNP4 SHBJ F7XJ RH4Y FX3T X2N4
const client = getClient();
const payments: CallResult<Transaction[]> =
(await client.transaction.getByAddress(paymentReciver)) as any;
(await client.blockchain.getTransactionsByAddress(paymentReciver)) as any;
const valdatorPayemnts = [];
for (const payment of payments.data) {
// Change of .data to .recipientData not yet implemented by the rpc client
Expand Down Expand Up @@ -146,13 +145,14 @@ export async function getPaymentStatus(address: Address): Promise<any> {

export async function getTotalRewards(validatorAddress: Address) {
const client = getClient();
const validator = await client.validator.byAddress(validatorAddress);
const validator =
await client.blockchain.getValidatorByAddress(validatorAddress);
if (validator.error) {
console.log(`Failed to get Vlaidator ${validatorAddress}`);
return 0;
}
const transactions: CallResult<Transaction[]> =
(await client.transaction.getByAddress(
(await client.blockchain.getTransactionsByAddress(
validator.data.rewardAddress,
)) as CallResult<Transaction[]>;
let total = 0;
Expand Down
4 changes: 2 additions & 2 deletions backend/src/nodecontroller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as k8s from '@kubernetes/client-node';
import * as yaml from 'js-yaml';
import Client from 'nimiq-rpc-client-ts';
import { Client } from 'nimiq-rpc-client-ts';
import * as crypto from 'node:crypto';
import { promises as fs } from 'node:fs';

Expand Down Expand Up @@ -138,7 +138,7 @@ export async function removeValidator(address: string) {
export async function getConsensusStatus(address: string) {
const url = new URL(`http://staqe-node-${kubernetizeAddress(address)}:8648`);
const client = new Client(url);
const response = await client.modules.consensus.isConsensusEstablished();
const response = await client.consensus.isConsensusEstablished();
if (response.data !== undefined) {
return response.data ? 'running' : 'creating';
} else {
Expand Down
6 changes: 3 additions & 3 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"rootDir": "src",
"baseUrl": ".",
"paths": {
"*": ["node_modules/*", "src/types/*"]
}
"*": ["node_modules/*", "src/types/*"],
},
},
"include": ["src/**/*"]
"include": ["src/**/*"],
}
2 changes: 1 addition & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default defineNuxtConfig({
worker: {
// Not needed with vite-plugin-top-level-await >= 1.3.0
// format: "es",
plugins: [wasm(), topLevelAwait()],
plugins: () => [wasm(), topLevelAwait()],
},
optimizeDeps: {
exclude: ['@nimiq/core-web'],
Expand Down
Loading

0 comments on commit 72ea178

Please sign in to comment.