Merge branch 'beta' into hooks

This commit is contained in:
Denis Angell
2023-03-28 20:33:17 +00:00
committed by GitHub
7 changed files with 49 additions and 4 deletions

View File

@@ -39,7 +39,7 @@ jobs:
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v1 uses: github/codeql-action/init@v2
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file. # If you wish to specify custom queries, you can do so here or in a config file.
@@ -50,7 +50,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below) # If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@v1 uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell. # Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl # 📚 https://git.io/JvXDl
@@ -64,4 +64,4 @@ jobs:
# make release # make release
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1 uses: github/codeql-action/analyze@v2

View File

@@ -101,6 +101,7 @@ import {
getXrpBalance, getXrpBalance,
submit, submit,
submitAndWait, submitAndWait,
getNetworkID,
} from '../sugar' } from '../sugar'
import fundWallet from '../Wallet/fundWallet' import fundWallet from '../Wallet/fundWallet'
@@ -200,6 +201,13 @@ class Client extends EventEmitter {
*/ */
public readonly maxFeeXRP: string 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. * 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.feeCushion = options.feeCushion ?? DEFAULT_FEE_CUSHION
this.maxFeeXRP = options.maxFeeXRP ?? DEFAULT_MAX_FEE_XRP this.maxFeeXRP = options.maxFeeXRP ?? DEFAULT_MAX_FEE_XRP
this.networkID = 1
this.connection = new Connection(server, options) this.connection = new Connection(server, options)
@@ -634,6 +643,11 @@ class Client extends EventEmitter {
*/ */
public getLedgerIndex = getLedgerIndex public getLedgerIndex = getLedgerIndex
/**
* @category Abstraction
*/
public getNetworkID = getNetworkID
/** /**
* @category Faucet * @category Faucet
*/ */

View File

@@ -136,6 +136,10 @@ export interface ServerInfoResponse extends BaseResponse {
* overall network's load factor. * overall network's load factor.
*/ */
load_factor?: number load_factor?: number
/**
* The network id of the server.
*/
network_id?: number
/** /**
* Current multiplier to the transaction cost based on * Current multiplier to the transaction cost based on
* load to this server. * load to this server.

View File

@@ -159,6 +159,10 @@ export interface BaseTransaction {
* account it says it is from. * account it says it is from.
*/ */
TxnSignature?: string TxnSignature?: string
/**
* The network id of the transaction.
*/
NetworkID?: number
} }
/** /**
@@ -252,6 +256,9 @@ export function validateBaseTransaction(common: Record<string, unknown>): void {
) { ) {
throw new ValidationError('BaseTransaction: invalid TxnSignature') throw new ValidationError('BaseTransaction: invalid TxnSignature')
} }
if (common.NetworkID !== undefined && typeof common.NetworkID !== 'number') {
throw new ValidationError('BaseTransaction: invalid NetworkID')
}
} }
/** /**

View File

@@ -12,6 +12,7 @@ import { getFeeXrp } from './getFeeXrp'
// Expire unconfirmed transactions after 20 ledger versions, approximately 1 minute, by default // Expire unconfirmed transactions after 20 ledger versions, approximately 1 minute, by default
const LEDGER_OFFSET = 20 const LEDGER_OFFSET = 20
const RESTRICTED_NETWORKS = 1024
interface ClassicAccountAndTag { interface ClassicAccountAndTag {
classicAccount: string classicAccount: string
tag: number | false | undefined tag: number | false | undefined
@@ -39,8 +40,10 @@ async function autofill<T extends Transaction>(
setValidAddresses(tx) setValidAddresses(tx)
setTransactionFlagsToNumber(tx) setTransactionFlagsToNumber(tx)
const promises: Array<Promise<void>> = [] const promises: Array<Promise<void>> = []
if (this.networkID > RESTRICTED_NETWORKS && tx.NetworkID == null) {
tx.NetworkID = this.networkID
}
if (tx.Sequence == null) { if (tx.Sequence == null) {
promises.push(setNextValidSequenceNumber(this, tx)) promises.push(setNextValidSequenceNumber(this, tx))
} }

View File

@@ -0,0 +1,15 @@
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',
})
return response.result.info.network_id ?? 1
}

View File

@@ -7,6 +7,8 @@ export { default as getLedgerIndex } from './getLedgerIndex'
export { default as getOrderbook } from './getOrderbook' export { default as getOrderbook } from './getOrderbook'
export { getFeeXrp, getFeeEstimateXrp } from './getFeeXrp' export { getFeeXrp, getFeeEstimateXrp } from './getFeeXrp'
export { default as getNetworkID } from './getNetworkID'
export * from './submit' export * from './submit'
export * from './utils' export * from './utils'