Skip to content

Commit

Permalink
backend
Browse files Browse the repository at this point in the history
  • Loading branch information
faberto committed Jan 30, 2024
1 parent 4b212bd commit c5dbd6b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
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 @@ -49,19 +48,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 @@ -71,7 +70,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 @@ -104,7 +103,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 @@ -144,13 +143,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 @@ -140,7 +140,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/**/*"],
}

0 comments on commit c5dbd6b

Please sign in to comment.