xahau-functionality

This commit is contained in:
Denis Angell
2025-03-14 11:40:44 +01:00
parent aae7e315e8
commit 8b21c9adf6
96 changed files with 3375 additions and 1633 deletions

View File

@@ -14,6 +14,7 @@ import {
} from './enums'
import { STObject } from './types/st-object'
import { JsonObject } from './types/serialized-type'
import { AmountObject } from './types/amount'
/**
* Construct a BinaryParser
@@ -128,7 +129,7 @@ function signingData(
*/
interface ClaimObject extends JsonObject {
channel: string
amount: string | number
amount: AmountObject
}
/**
@@ -139,16 +140,21 @@ interface ClaimObject extends JsonObject {
* @returns the serialized object with appropriate prefix
*/
function signingClaimData(claim: ClaimObject): Uint8Array {
const num = BigInt(String(claim.amount))
const prefix = HashPrefix.paymentChannelClaim
const channel = coreTypes.Hash256.from(claim.channel).toBytes()
const amount = coreTypes.UInt64.from(num).toBytes()
const bytesList = new BytesList()
bytesList.put(prefix)
bytesList.put(channel)
bytesList.put(amount)
if (typeof claim.amount === 'string') {
const num = BigInt(String(claim.amount))
const amount = coreTypes.UInt64.from(num).toBytes()
bytesList.put(amount)
} else {
const amount = coreTypes.Amount.from(claim.amount).toBytes()
bytesList.put(amount)
}
return bytesList.toBytes()
}

File diff suppressed because it is too large Load Diff

View File

@@ -19,6 +19,7 @@ const Field = DEFAULT_DEFINITIONS.field
* @brief: All valid transaction types
*/
const TRANSACTION_TYPES = DEFAULT_DEFINITIONS.transactionNames
const TRANSACTION_TYPE_MAP = DEFAULT_DEFINITIONS.transactionMap
export {
Bytes,
@@ -31,4 +32,5 @@ export {
TransactionResult,
TransactionType,
TRANSACTION_TYPES,
TRANSACTION_TYPE_MAP,
}

View File

@@ -33,6 +33,8 @@ class XrplDefinitionsBase {
transactionType: BytesLookup
// Valid transaction names
transactionNames: string[]
// Valid transaction map
transactionMap: Record<string, number>
// Maps serializable types to their TypeScript class implementation
dataTypes: Record<string, typeof SerializedType>
@@ -72,6 +74,15 @@ class XrplDefinitionsBase {
.filter(([_key, value]) => value >= 0)
.map(([key, _value]) => key)
const ignoreList = ['EnableAmendment', 'SetFee', 'UNLModify', 'EmitFailure']
this.transactionMap = Object.assign(
{},
...Object.entries(enums.TRANSACTION_TYPES)
.filter(([_key, _value]) => _value >= 0 || ignoreList.includes(_key))
.map(([key, value]) => ({ [key]: value })),
)
this.dataTypes = {} // Filled in via associateTypes
this.associateTypes(types)
}

View File

@@ -5,6 +5,7 @@ import { JsonObject } from './types/serialized-type'
import {
XrplDefinitionsBase,
TRANSACTION_TYPES,
TRANSACTION_TYPE_MAP,
DEFAULT_DEFINITIONS,
} from './enums'
import { XrplDefinitions } from './enums/xahau-definitions'
@@ -146,6 +147,7 @@ export {
decodeQuality,
decodeLedgerData,
TRANSACTION_TYPES,
TRANSACTION_TYPE_MAP,
XrplDefinitions,
XrplDefinitionsBase,
DEFAULT_DEFINITIONS,