mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
network id
network id add network id to server_info option 2 networkID network id option 3 network ID optional
This commit is contained in:
@@ -101,6 +101,7 @@ import {
|
||||
getXrpBalance,
|
||||
submit,
|
||||
submitAndWait,
|
||||
getNetworkID,
|
||||
} from '../sugar'
|
||||
import fundWallet from '../Wallet/fundWallet'
|
||||
|
||||
@@ -200,6 +201,13 @@ class Client extends EventEmitter {
|
||||
*/
|
||||
public readonly maxFeeXRP: string
|
||||
|
||||
/**
|
||||
* Network ID of the server this sdk is connected to
|
||||
*
|
||||
* @category Fee
|
||||
*/
|
||||
public networkID: number
|
||||
|
||||
/**
|
||||
* Creates a new Client with a websocket connection to a rippled server.
|
||||
*
|
||||
@@ -218,6 +226,7 @@ class Client extends EventEmitter {
|
||||
|
||||
this.feeCushion = options.feeCushion ?? DEFAULT_FEE_CUSHION
|
||||
this.maxFeeXRP = options.maxFeeXRP ?? DEFAULT_MAX_FEE_XRP
|
||||
this.networkID = 1
|
||||
|
||||
this.connection = new Connection(server, options)
|
||||
|
||||
@@ -638,6 +647,11 @@ class Client extends EventEmitter {
|
||||
* @category Faucet
|
||||
*/
|
||||
public fundWallet = fundWallet
|
||||
|
||||
/**
|
||||
* @category Abstraction
|
||||
*/
|
||||
public getNetworkID = getNetworkID
|
||||
}
|
||||
|
||||
export { Client }
|
||||
|
||||
@@ -136,6 +136,10 @@ export interface ServerInfoResponse extends BaseResponse {
|
||||
* overall network's load factor.
|
||||
*/
|
||||
load_factor?: number
|
||||
/**
|
||||
* The network id of this server
|
||||
*/
|
||||
network_id?: number
|
||||
/**
|
||||
* Current multiplier to the transaction cost based on
|
||||
* load to this server.
|
||||
|
||||
@@ -162,7 +162,7 @@ export interface BaseTransaction {
|
||||
/**
|
||||
* The network id of the transaction.
|
||||
*/
|
||||
NetworkID: string
|
||||
NetworkID?: number
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,6 +256,9 @@ export function validateBaseTransaction(common: Record<string, unknown>): void {
|
||||
) {
|
||||
throw new ValidationError('BaseTransaction: invalid TxnSignature')
|
||||
}
|
||||
if (common.NetworkID !== undefined && typeof common.NetworkID !== 'number') {
|
||||
throw new ValidationError('BaseTransaction: invalid NetworkID')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
21
packages/xrpl/src/sugar/getNetworkID.ts
Normal file
21
packages/xrpl/src/sugar/getNetworkID.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import type { Client } from '..'
|
||||
import { XrplError } from '../errors'
|
||||
|
||||
/**
|
||||
* Returns the network ID of the rippled server.
|
||||
*
|
||||
* @param this - The Client used to connect to the ledger.
|
||||
* @returns The network id.
|
||||
*/
|
||||
export default async function getNetworkID(this: Client): Promise<number> {
|
||||
const response = await this.request({
|
||||
command: 'server_info',
|
||||
})
|
||||
const networkID = response.result.info.network_id
|
||||
if (networkID == null) {
|
||||
throw new XrplError(
|
||||
'getNetworkID: Could not get network_id from server_info',
|
||||
)
|
||||
}
|
||||
return networkID
|
||||
}
|
||||
@@ -7,6 +7,8 @@ export { default as getLedgerIndex } from './getLedgerIndex'
|
||||
export { default as getOrderbook } from './getOrderbook'
|
||||
export { getFeeXrp, getFeeEstimateXrp } from './getFeeXrp'
|
||||
|
||||
export { default as getNetworkID } from './getNetworkID'
|
||||
|
||||
export * from './submit'
|
||||
|
||||
export * from './utils'
|
||||
|
||||
Reference in New Issue
Block a user