mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-07 14:25:49 +00:00
Compare commits
4 Commits
@transia/r
...
beta
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bf6ae0b51 | ||
|
|
925bfef971 | ||
|
|
d5d5350425 | ||
|
|
301c6d6beb |
@@ -4,7 +4,13 @@
|
||||
import { TRANSACTION_TYPES } from '@transia/ripple-binary-codec'
|
||||
|
||||
import { ValidationError } from '../../errors'
|
||||
import { Amount, IssuedCurrencyAmount, Memo, Signer } from '../common'
|
||||
import {
|
||||
Amount,
|
||||
HookParameter,
|
||||
IssuedCurrencyAmount,
|
||||
Memo,
|
||||
Signer,
|
||||
} from '../common'
|
||||
import { onlyHasFields } from '../utils'
|
||||
|
||||
const MEMO_SIZE = 3
|
||||
@@ -163,6 +169,10 @@ export interface BaseTransaction {
|
||||
* The network id of the transaction.
|
||||
*/
|
||||
NetworkID?: number
|
||||
/**
|
||||
* The hook parameters of the transaction
|
||||
*/
|
||||
HookParameters?: HookParameter[]
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,20 @@ export interface DeletedNode {
|
||||
|
||||
export type Node = CreatedNode | ModifiedNode | DeletedNode
|
||||
|
||||
export interface HookExecution {
|
||||
HookExecution: {
|
||||
HookAccount: string
|
||||
HookEmitCount: number
|
||||
HookExecutionIndex: number
|
||||
HookHash: string
|
||||
HookInstructionCount: string
|
||||
HookResult: number
|
||||
HookReturnCode: number
|
||||
HookReturnString: string
|
||||
HookStateChangeCount: number
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A typeguard to check if a node is a CreatedNode.
|
||||
*
|
||||
@@ -63,6 +77,7 @@ export interface TransactionMetadata {
|
||||
AffectedNodes: Node[]
|
||||
DeliveredAmount?: Amount
|
||||
// "unavailable" possible for transactions before 2014-01-20
|
||||
HookExecutions: HookExecution[]
|
||||
delivered_amount?: Amount | 'unavailable'
|
||||
TransactionIndex: number
|
||||
TransactionResult: string
|
||||
|
||||
@@ -13,6 +13,7 @@ import { DepositPreauth, validateDepositPreauth } from './depositPreauth'
|
||||
import { EscrowCancel, validateEscrowCancel } from './escrowCancel'
|
||||
import { EscrowCreate, validateEscrowCreate } from './escrowCreate'
|
||||
import { EscrowFinish, validateEscrowFinish } from './escrowFinish'
|
||||
import { Invoke, validateInvoke } from './invoke'
|
||||
import { TransactionMetadata } from './metadata'
|
||||
import {
|
||||
NFTokenAcceptOffer,
|
||||
@@ -73,6 +74,7 @@ export type Transaction =
|
||||
| EscrowCancel
|
||||
| EscrowCreate
|
||||
| EscrowFinish
|
||||
| Invoke
|
||||
| NFTokenAcceptOffer
|
||||
| NFTokenBurn
|
||||
| NFTokenCancelOffer
|
||||
@@ -158,6 +160,10 @@ export function validate(transaction: Record<string, unknown>): void {
|
||||
validateEscrowFinish(tx)
|
||||
break
|
||||
|
||||
case 'Invoke':
|
||||
validateInvoke(tx)
|
||||
break
|
||||
|
||||
case 'NFTokenAcceptOffer':
|
||||
validateNFTokenAcceptOffer(tx)
|
||||
break
|
||||
|
||||
@@ -95,20 +95,31 @@ export async function hexNamespace(namespace: string): Promise<string> {
|
||||
export function hexHookParameters(data: HookParameter[]): HookParameter[] {
|
||||
const hookParameters: HookParameter[] = []
|
||||
for (const parameter of data) {
|
||||
let nameValue
|
||||
let valueValue
|
||||
// eslint-disable-next-line require-unicode-regexp -- Required
|
||||
if (/^[0-9a-fA-F]{2,}$/.exec(parameter.HookParameter.HookParameterName)) {
|
||||
nameValue = parameter.HookParameter.HookParameterName
|
||||
} else {
|
||||
nameValue = Buffer.from(parameter.HookParameter.HookParameterName, 'utf8')
|
||||
.toString('hex')
|
||||
.toUpperCase()
|
||||
}
|
||||
// eslint-disable-next-line require-unicode-regexp -- Required
|
||||
if (/^[0-9a-fA-F]{2,}$/.exec(parameter.HookParameter.HookParameterValue)) {
|
||||
valueValue = parameter.HookParameter.HookParameterValue
|
||||
} else {
|
||||
valueValue = Buffer.from(
|
||||
parameter.HookParameter.HookParameterValue,
|
||||
'utf8',
|
||||
)
|
||||
.toString('hex')
|
||||
.toUpperCase()
|
||||
}
|
||||
hookParameters.push({
|
||||
HookParameter: {
|
||||
HookParameterName: Buffer.from(
|
||||
parameter.HookParameter.HookParameterName,
|
||||
'utf8',
|
||||
)
|
||||
.toString('hex')
|
||||
.toUpperCase(),
|
||||
HookParameterValue: Buffer.from(
|
||||
parameter.HookParameter.HookParameterValue,
|
||||
'utf8',
|
||||
)
|
||||
.toString('hex')
|
||||
.toUpperCase(),
|
||||
HookParameterName: String(nameValue),
|
||||
HookParameterValue: String(valueValue),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user