Skip to content

Commit

Permalink
Fix env (#105)
Browse files Browse the repository at this point in the history
* fix: env testnet

* fix: testnet init sdk

* fix: derivation

* fix: better check
  • Loading branch information
vladimirvolek committed Oct 21, 2021
1 parent 4c5ee1c commit a2675c2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/server.ts
Expand Up @@ -104,6 +104,13 @@ wss.on('connection', (ws: Server.Ws) => {
return;
}

if (!process.env.NETWORK) {
const message = prepareErrorMessage(-1, `Missing NETWORK env variable see: ${REPOSITORY_URL}`);

ws.send(message);
return;
}

ws.on('error', error => {
const message = prepareErrorMessage(-1, error);
ws.send(message);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/address.ts
Expand Up @@ -16,7 +16,7 @@ export const deriveAddress = (
addressIndex: number,
type: number,
): { address: string; path: string } => {
const networkId = getNetworkId(blockfrostAPI.apiUrl);
const networkId = getNetworkId();
const accountKey = Bip32PublicKey.from_bytes(Buffer.from(publicKey, 'hex'));
const utxoPubKey = accountKey.derive(type).derive(addressIndex);
const stakeKey = accountKey.derive(2).derive(0);
Expand All @@ -34,7 +34,7 @@ export const deriveAddress = (

export const deriveStakeAddress = (publicKey: string): string => {
const accountKey = Bip32PublicKey.from_bytes(Buffer.from(publicKey, 'hex'));
const networkId = getNetworkId(blockfrostAPI.apiUrl);
const networkId = getNetworkId();
const stakeKey = accountKey.derive(2).derive(0);
const rewardAddr = RewardAddress.new(
networkId,
Expand Down
9 changes: 5 additions & 4 deletions src/utils/common.ts
@@ -1,4 +1,5 @@
import { format } from 'date-fns';
import { blockfrostAPI } from '../utils/blockfrostAPI';
import got from 'got';
import { NetworkInfo } from '@emurgo/cardano-serialization-lib-nodejs';

Expand Down Expand Up @@ -38,10 +39,10 @@ export const getRatesForDate = async (date: number): Promise<Record<string, numb
}
};

export const getNetworkId = (apiUrl: string): number => {
const networkId = apiUrl.includes('mainnet')
? NetworkInfo.mainnet().network_id()
: NetworkInfo.testnet().network_id();
export const getNetworkId = (): number => {
const networkId = blockfrostAPI.options.isTestnet
? NetworkInfo.testnet().network_id()
: NetworkInfo.mainnet().network_id();

return networkId;
};

0 comments on commit a2675c2

Please sign in to comment.