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

Fix UI confirmation status #64

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 20 additions & 0 deletions backend/Dockerfile.mac
wanwiset25 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# NodeJS Version 16
FROM node:16.18-alpine

# Copy Dir
COPY . ./app

# Work to Dir
WORKDIR /app

# Install Node Package
RUN apk add g++ make python3
RUN npm install --legacy-peer-deps

# Set Env
ENV NODE_ENV production
EXPOSE 3000
EXPOSE 443

# Cmd script
CMD ["npm", "run", "start"]
38 changes: 36 additions & 2 deletions backend/src/client/extensions.ts
wanwiset25 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,21 @@ export interface NetworkInfo {
export interface Web3WithExtension extends Web3 {
xdcSubnet: {
getV2Block: (type: 'committed') => Promise<FetchedV2BlockInfo>;
getV2BlockByNumber: (bluckNum: string) => Promise<FetchedV2BlockInfo>;
wanwiset25 marked this conversation as resolved.
Show resolved Hide resolved
getV2BlockByNumber: (blockNum: string) => Promise<FetchedV2BlockInfo>;
getV2BlockByHash: (blockHash: string) => Promise<FetchedV2BlockInfo>;
getMasternodesByNumber: (blockStatus: BlockStatus) => Promise<MasternodesInfo>;
getCandidates: (param: 'latest') => Promise<Candidates>;
getNetworkInfo: () => Promise<NetworkInfo>;
};
xdcParentnet: {
getV2Block: (type: 'committed') => Promise<FetchedV2BlockInfo>;
getV2BlockByNumber: (blockNum: string) => Promise<FetchedV2BlockInfo>;
getV2BlockByHash: (blockHash: string) => Promise<FetchedV2BlockInfo>;
getNetworkInfo: () => Promise<NetworkInfo>;
}
}

export const networkExtensions = (extensionName = 'xdcSubnet') => {
export const subnetExtensions = (extensionName = 'xdcSubnet') => {
return {
property: extensionName,
methods: [
Expand Down Expand Up @@ -95,3 +101,31 @@ export const networkExtensions = (extensionName = 'xdcSubnet') => {
],
};
};

export const parentnetExtensions = (extensionName = 'xdcParentnet') => {
return {
property: extensionName,
methods: [
{
name: 'getV2Block',
params: 1,
call: 'XDPoS_getV2BlockByNumber',
},
{
name: 'getV2BlockByNumber',
params: 1,
call: 'XDPoS_getV2BlockByNumber',
},
{
name: 'getV2BlockByHash',
params: 1,
call: 'XDPoS_getV2BlockByHash',
},
{
name: 'getNetworkInfo',
params: 0,
call: 'XDPoS_networkInformation',
},
],
};
};
15 changes: 12 additions & 3 deletions backend/src/client/parentchain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { abi } from './contract';
import { logger } from '../../utils/logger';
import { CHECKPOINT_CONTRACT, PARENTNET_URL } from '../../config';
import { HttpException } from '../../exceptions/httpException';
import { networkExtensions, Web3WithExtension } from '../extensions';
import { parentnetExtensions, Web3WithExtension } from '../extensions';

export interface SmartContractAuditedBlockInfo {
smartContractHash: string;
Expand All @@ -21,7 +21,7 @@ export class ParentChainClient {
constructor() {
const keepaliveAgent = new HttpsAgent();
const provider = new Web3.providers.HttpProvider(PARENTNET_URL, { keepAlive: true, agent: { https: keepaliveAgent } });
this.web3 = new Web3(provider).extend(networkExtensions());
this.web3 = new Web3(provider).extend(parentnetExtensions());
this.smartContractInstance = new this.web3.eth.Contract(abi as any[], CHECKPOINT_CONTRACT);
}

Expand Down Expand Up @@ -94,7 +94,16 @@ export class ParentChainClient {
*/
async confirmBlock(subnetHash: string) {
const { finalized, mainnet_num } = await this.smartContractInstance.methods.getHeader(subnetHash).call();
const { Committed, Hash, Miner, Timestamp } = await this.web3.xdcSubnet.getV2BlockByNumber(Web3.utils.numberToHex(mainnet_num));
if (!finalized){
return{
isCommitted: false,
parentchainHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
parentChainNum: mainnet_num,
proposer: "0x0000000000000000000000000000000000000000000000000000000000000000",
timestamp: 0,
}
}
const { Committed, Hash, Miner, Timestamp } = await this.web3.xdcParentnet.getV2BlockByNumber(Web3.utils.numberToHex(mainnet_num));
return {
isCommitted: Committed && finalized,
parentchainHash: Hash,
Expand Down
4 changes: 2 additions & 2 deletions backend/src/client/subnet/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Web3 from 'web3';
import { HttpsAgent } from 'agentkeepalive';
import { networkExtensions, Web3WithExtension } from '../extensions';
import { subnetExtensions, Web3WithExtension } from '../extensions';
import { logger } from '../../utils/logger';
import { HttpException } from '../../exceptions/httpException';
import { SUBNET_URL } from '../../config';
Expand All @@ -19,7 +19,7 @@ export class SubnetClient {
const keepaliveAgent = new HttpsAgent();
const provider = new Web3.providers.HttpProvider(SUBNET_URL, { keepAlive: true, agent: { https: keepaliveAgent } });

this.web3 = new Web3(provider).extend(networkExtensions());
this.web3 = new Web3(provider).extend(subnetExtensions());
}

async getCandidates() {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/controllers/blocks.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class BlocksController {
blockHash: parentChain.parentchainBlockHash,
blockHeight: parentChain.parentchainBlockHeight,
proposer: parentChain.proposer,
timestamp: subnet.timestamp.toString(),
timestamp: parentChain.timestamp.toString(),
},
};
} else if (parseInt(input)) {
Expand All @@ -145,7 +145,7 @@ export class BlocksController {
blockHash: parentChain.parentchainBlockHash,
blockHeight: parentChain.parentchainBlockHeight,
proposer: parentChain.proposer,
timestamp: subnet.timestamp.toString(),
timestamp: parentChain.timestamp.toString(),
},
};
} else {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/formatter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BigNumber from 'bignumber.js';

export function formatHashFromNonZero(hash: string): string {
return formatHash(hash.replace(/0x[0]*/, 'xdc'));
return formatHash(hash.replace(/0x[0]*/, '0x'));
}

export function formatHash(hash: string): string {
Expand Down