-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #182 from ElrondNetwork/network-obj
Breaking change: unifying provider interfaces, preparing network providers for extraction - step 3
- Loading branch information
Showing
7 changed files
with
301 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import BigNumber from "bignumber.js"; | ||
import { IChainID, IGasLimit, IGasPrice, IGasPriceModifier, ITransactionVersion } from "./interface"; | ||
|
||
/** | ||
* An object holding Network configuration parameters. | ||
*/ | ||
export class NetworkConfig { | ||
/** | ||
* The chain ID. E.g. "1" for the Mainnet. | ||
*/ | ||
public ChainID: IChainID; | ||
|
||
/** | ||
* The gas required by the Network to process a byte of the {@link TransactionPayload}. | ||
*/ | ||
public GasPerDataByte: number; | ||
/** | ||
* The round duration. | ||
*/ | ||
public RoundDuration: number; | ||
/** | ||
* The number of rounds per epoch. | ||
*/ | ||
public RoundsPerEpoch: number; | ||
|
||
/** | ||
* The Top Up Factor for APR calculation | ||
*/ | ||
public TopUpFactor: number; | ||
|
||
/** | ||
* The Top Up Factor for APR calculation | ||
*/ | ||
public TopUpRewardsGradientPoint: BigNumber; | ||
|
||
/** | ||
* | ||
*/ | ||
public GasPriceModifier: IGasPriceModifier; | ||
|
||
/** | ||
* The minimum gas limit required to be set when broadcasting a {@link Transaction}. | ||
*/ | ||
public MinGasLimit: IGasLimit; | ||
|
||
/** | ||
* The minimum gas price required to be set when broadcasting a {@link Transaction}. | ||
*/ | ||
public MinGasPrice: IGasPrice; | ||
|
||
/** | ||
* The oldest transaction version accepted by the Network. | ||
*/ | ||
public MinTransactionVersion: ITransactionVersion; | ||
|
||
constructor() { | ||
this.ChainID = "T"; | ||
this.GasPerDataByte = 1500; | ||
this.TopUpFactor = 0; | ||
this.RoundDuration = 0; | ||
this.RoundsPerEpoch = 0; | ||
this.TopUpRewardsGradientPoint = new BigNumber(0); | ||
this.MinGasLimit = 50000; | ||
this.MinGasPrice = 1000000000; | ||
this.GasPriceModifier = 1; | ||
this.MinTransactionVersion = 1; | ||
} | ||
|
||
/** | ||
* Constructs a configuration object from a HTTP response (as returned by the provider). | ||
*/ | ||
static fromHttpResponse(payload: any): NetworkConfig { | ||
let networkConfig = new NetworkConfig(); | ||
|
||
networkConfig.ChainID = String(payload["erd_chain_id"]); | ||
networkConfig.GasPerDataByte = Number(payload["erd_gas_per_data_byte"]); | ||
networkConfig.TopUpFactor = Number(payload["erd_top_up_factor"]); | ||
networkConfig.RoundDuration = Number(payload["erd_round_duration"]); | ||
networkConfig.RoundsPerEpoch = Number(payload["erd_rounds_per_epoch"]); | ||
networkConfig.TopUpRewardsGradientPoint = new BigNumber(payload["erd_rewards_top_up_gradient_point"]); | ||
networkConfig.MinGasLimit = Number(payload["erd_min_gas_limit"]); | ||
networkConfig.MinGasPrice = Number(payload["erd_min_gas_price"]); | ||
networkConfig.MinTransactionVersion = Number(payload["erd_min_transaction_version"]); | ||
networkConfig.GasPriceModifier = Number(payload["erd_gas_price_modifier"]); | ||
|
||
return networkConfig; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import BigNumber from "bignumber.js"; | ||
|
||
/** | ||
* An object holding Network stake parameters. | ||
*/ | ||
export class NetworkStake { | ||
private static default: NetworkStake; | ||
|
||
/** | ||
* The Total Validators Number. | ||
*/ | ||
public TotalValidators: number; | ||
|
||
/** | ||
* The Active Validators Number. | ||
*/ | ||
public ActiveValidators: number; | ||
/** | ||
* The Queue Size. | ||
*/ | ||
public QueueSize: number; | ||
/** | ||
* The Total Validators Number. | ||
*/ | ||
public TotalStaked: BigNumber; | ||
|
||
constructor() { | ||
this.TotalValidators = 0; | ||
this.ActiveValidators = 0; | ||
this.QueueSize = 0; | ||
this.TotalStaked = new BigNumber(0); | ||
} | ||
|
||
/** | ||
* Constructs a configuration object from a HTTP response (as returned by the provider). | ||
*/ | ||
static fromHttpResponse(payload: any): NetworkStake { | ||
let networkStake = new NetworkStake(); | ||
|
||
networkStake.TotalValidators = Number(payload["totalValidators"]); | ||
networkStake.ActiveValidators = Number(payload["activeValidators"]); | ||
networkStake.QueueSize = Number(payload["queueSize"]); | ||
networkStake.TotalStaked = new BigNumber(payload["totalStaked"]); | ||
|
||
return networkStake; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* An object holding network status configuration parameters. | ||
*/ | ||
export class NetworkStatus { | ||
private static default: NetworkStatus; | ||
|
||
/** | ||
* The current round. | ||
*/ | ||
public CurrentRound: number; | ||
|
||
/** | ||
* The epoch number. | ||
*/ | ||
public EpochNumber: number; | ||
|
||
/** | ||
* The Highest final nonce. | ||
*/ | ||
public HighestFinalNonce: number; | ||
|
||
/** | ||
* The erd nonce. | ||
*/ | ||
public Nonce: number; | ||
|
||
/** | ||
* The nonce at epoch start. | ||
*/ | ||
public NonceAtEpochStart: number; | ||
|
||
/** | ||
* The nonces passed in current epoch. | ||
*/ | ||
public NoncesPassedInCurrentEpoch: number; | ||
|
||
/** | ||
* The round at epoch start | ||
*/ | ||
public RoundAtEpochStart: number; | ||
|
||
/** | ||
* The rounds passed in current epoch | ||
*/ | ||
public RoundsPassedInCurrentEpoch: number; | ||
|
||
/** | ||
* The rounds per epoch | ||
*/ | ||
public RoundsPerEpoch: number; | ||
|
||
constructor() { | ||
this.CurrentRound = 0; | ||
this.EpochNumber = 0; | ||
this.HighestFinalNonce = 0; | ||
this.Nonce = 0; | ||
this.NonceAtEpochStart = 0; | ||
this.NoncesPassedInCurrentEpoch = 0; | ||
this.RoundAtEpochStart = 0; | ||
this.RoundsPassedInCurrentEpoch = 0; | ||
this.RoundsPerEpoch = 0; | ||
} | ||
|
||
/** | ||
* Constructs a configuration object from a HTTP response (as returned by the provider). | ||
*/ | ||
static fromHttpResponse(payload: any): NetworkStatus { | ||
let networkStatus = new NetworkStatus(); | ||
|
||
networkStatus.CurrentRound = Number(payload["erd_current_round"]); | ||
networkStatus.EpochNumber = Number(payload["erd_epoch_number"]); | ||
networkStatus.HighestFinalNonce = Number(payload["erd_highest_final_nonce"]); | ||
networkStatus.Nonce = Number(payload["erd_nonce"]); | ||
networkStatus.NonceAtEpochStart = Number(payload["erd_nonce_at_epoch_start"]); | ||
networkStatus.NoncesPassedInCurrentEpoch = Number(payload["erd_nonces_passed_in_current_epoch"]); | ||
networkStatus.RoundAtEpochStart = Number(payload["erd_round_at_epoch_start"]); | ||
networkStatus.RoundsPassedInCurrentEpoch = Number(payload["erd_rounds_passed_in_current_epoch"]); | ||
networkStatus.RoundsPerEpoch = Number(payload["erd_rounds_per_epoch"]); | ||
|
||
return networkStatus; | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
src-network-providers/networkProvider/proxyNetworkProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* An object holding Network stats parameters. | ||
*/ | ||
export class Stats { | ||
private static default: Stats; | ||
|
||
/** | ||
* The number of Shards. | ||
*/ | ||
public Shards: number; | ||
|
||
/** | ||
* The Number of Blocks. | ||
*/ | ||
public Blocks: number; | ||
/** | ||
* The Number of Accounts. | ||
*/ | ||
public Accounts: number; | ||
/** | ||
* The Number of transactions. | ||
*/ | ||
public Transactions: number; | ||
/** | ||
* The Refresh rate. | ||
*/ | ||
public RefreshRate: number; | ||
/** | ||
* The Number of the current Epoch. | ||
*/ | ||
public Epoch: number; | ||
/** | ||
* The Number of rounds passed. | ||
*/ | ||
public RoundsPassed: number; | ||
/** | ||
* The Number of Rounds per epoch. | ||
*/ | ||
public RoundsPerEpoch: number; | ||
|
||
constructor() { | ||
this.Shards = 0; | ||
this.Blocks = 0; | ||
this.Accounts = 0; | ||
this.Transactions = 0; | ||
this.RefreshRate = 0; | ||
this.Epoch = 0; | ||
this.RoundsPassed = 0; | ||
this.RoundsPerEpoch = 0; | ||
} | ||
|
||
/** | ||
* Constructs a stats object from a HTTP response (as returned by the provider). | ||
*/ | ||
static fromHttpResponse(payload: any): Stats { | ||
let stats = new Stats(); | ||
|
||
stats.Shards = Number(payload["shards"]); | ||
stats.Blocks = Number(payload["blocks"]); | ||
stats.Accounts = Number(payload["accounts"]); | ||
stats.Transactions = Number(payload["transactions"]); | ||
stats.RefreshRate = Number(payload["refreshRate"]); | ||
stats.Epoch = Number(payload["epoch"]); | ||
stats.RoundsPassed = Number(payload["roundsPassed"]); | ||
stats.RoundsPerEpoch = Number(payload["roundsPerEpoch"]); | ||
|
||
return stats; | ||
} | ||
} |