Compare commits

...

4 Commits

Author SHA1 Message Date
Denis Angell
3bf6ae0b51 add hook param to tx common 2023-04-23 15:01:49 -04:00
Denis Angell
925bfef971 add hook execution 2023-04-23 15:01:40 -04:00
Denis Angell
d5d5350425 fix invoke error 2023-04-23 15:01:28 -04:00
Denis Angell
301c6d6beb optionally hex hook params 2023-04-23 15:00:25 -04:00
4 changed files with 55 additions and 13 deletions

View File

@@ -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[]
}
/**

View File

@@ -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

View File

@@ -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

View File

@@ -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),
},
})
}