mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-12-06 17:27:59 +00:00
initial patch
This commit is contained in:
@@ -66,6 +66,7 @@ function serializeObject(object: JsonObject, opts: OptionObject = {}): Buffer {
|
|||||||
const filter = signingFieldsOnly
|
const filter = signingFieldsOnly
|
||||||
? (f: FieldInstance): boolean => f.isSigningField
|
? (f: FieldInstance): boolean => f.isSigningField
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
coreTypes.STObject.from(object, filter).toBytesSink(bytesList)
|
coreTypes.STObject.from(object, filter).toBytesSink(bytesList)
|
||||||
|
|
||||||
if (suffix) {
|
if (suffix) {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ function fieldHeader(type: number, nth: number): Buffer {
|
|||||||
/*
|
/*
|
||||||
* @brief: Bytes, name, and ordinal representing one type, ledger_type, transaction type, or result
|
* @brief: Bytes, name, and ordinal representing one type, ledger_type, transaction type, or result
|
||||||
*/
|
*/
|
||||||
class Bytes {
|
export class Bytes {
|
||||||
readonly bytes: Uint8Array
|
readonly bytes: Uint8Array
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -126,15 +126,21 @@ class BinarySerializer {
|
|||||||
* @param field field to write to BinarySerializer
|
* @param field field to write to BinarySerializer
|
||||||
* @param value value to write to BinarySerializer
|
* @param value value to write to BinarySerializer
|
||||||
*/
|
*/
|
||||||
writeFieldAndValue(field: FieldInstance, value: SerializedType): void {
|
writeFieldAndValue(
|
||||||
|
field: FieldInstance,
|
||||||
|
value: SerializedType,
|
||||||
|
isUnlModifyWorkaround = false,
|
||||||
|
): void {
|
||||||
const associatedValue = field.associatedType.from(value)
|
const associatedValue = field.associatedType.from(value)
|
||||||
assert.ok(associatedValue.toBytesSink !== undefined)
|
assert.ok(associatedValue.toBytesSink !== undefined)
|
||||||
assert.ok(field.name !== undefined)
|
assert.ok(field.name !== undefined)
|
||||||
|
|
||||||
this.sink.put(field.header)
|
this.sink.put(field.header)
|
||||||
|
|
||||||
|
console.log(field.name, field.isVariableLengthEncoded)
|
||||||
|
|
||||||
if (field.isVariableLengthEncoded) {
|
if (field.isVariableLengthEncoded) {
|
||||||
this.writeLengthEncoded(associatedValue)
|
this.writeLengthEncoded(associatedValue, isUnlModifyWorkaround)
|
||||||
} else {
|
} else {
|
||||||
associatedValue.toBytesSink(this.sink)
|
associatedValue.toBytesSink(this.sink)
|
||||||
}
|
}
|
||||||
@@ -145,9 +151,12 @@ class BinarySerializer {
|
|||||||
*
|
*
|
||||||
* @param value length encoded value to write to BytesList
|
* @param value length encoded value to write to BytesList
|
||||||
*/
|
*/
|
||||||
public writeLengthEncoded(value: SerializedType): void {
|
public writeLengthEncoded(
|
||||||
|
value: SerializedType,
|
||||||
|
isUnlModifyWorkaround = false,
|
||||||
|
): void {
|
||||||
const bytes = new BytesList()
|
const bytes = new BytesList()
|
||||||
value.toBytesSink(bytes)
|
if (!isUnlModifyWorkaround) value.toBytesSink(bytes)
|
||||||
this.put(this.encodeVariableLength(bytes.getLength()))
|
this.put(this.encodeVariableLength(bytes.getLength()))
|
||||||
this.writeBytesList(bytes)
|
this.writeBytesList(bytes)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Field, FieldInstance } from '../enums'
|
import { Field, FieldInstance, Bytes } from '../enums'
|
||||||
import { SerializedType, JsonObject } from './serialized-type'
|
import { SerializedType, JsonObject } from './serialized-type'
|
||||||
import { xAddressToClassicAddress, isValidXAddress } from 'ripple-address-codec'
|
import { xAddressToClassicAddress, isValidXAddress } from 'ripple-address-codec'
|
||||||
import { BinaryParser } from '../serdes/binary-parser'
|
import { BinaryParser } from '../serdes/binary-parser'
|
||||||
@@ -92,10 +92,13 @@ class STObject extends SerializedType {
|
|||||||
if (value instanceof STObject) {
|
if (value instanceof STObject) {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
console.log('HIIIIIIIIIIIIIIII')
|
||||||
|
|
||||||
const list: BytesList = new BytesList()
|
const list: BytesList = new BytesList()
|
||||||
const bytes: BinarySerializer = new BinarySerializer(list)
|
const bytes: BinarySerializer = new BinarySerializer(list)
|
||||||
|
|
||||||
|
let isUnlModify = false
|
||||||
|
|
||||||
const xAddressDecoded = Object.entries(value).reduce((acc, [key, val]) => {
|
const xAddressDecoded = Object.entries(value).reduce((acc, [key, val]) => {
|
||||||
let handled: JsonObject | undefined = undefined
|
let handled: JsonObject | undefined = undefined
|
||||||
if (val && isValidXAddress(val.toString())) {
|
if (val && isValidXAddress(val.toString())) {
|
||||||
@@ -120,13 +123,19 @@ class STObject extends SerializedType {
|
|||||||
if (filter !== undefined) {
|
if (filter !== undefined) {
|
||||||
sorted = sorted.filter(filter)
|
sorted = sorted.filter(filter)
|
||||||
}
|
}
|
||||||
|
// console.log(sorted)
|
||||||
|
|
||||||
sorted.forEach((field) => {
|
sorted.forEach((field) => {
|
||||||
const associatedValue = field.associatedType.from(
|
const associatedValue = field.associatedType.from(
|
||||||
xAddressDecoded[field.name],
|
xAddressDecoded[field.name],
|
||||||
)
|
)
|
||||||
|
// console.log(field, associatedValue)
|
||||||
bytes.writeFieldAndValue(field, associatedValue)
|
if ((associatedValue as unknown as Bytes).name === 'UNLModify') {
|
||||||
|
isUnlModify = true
|
||||||
|
}
|
||||||
|
const isUnlModifyWorkaround = field.name == 'Account' && isUnlModify
|
||||||
|
console.log(isUnlModify, field.name, isUnlModifyWorkaround)
|
||||||
|
bytes.writeFieldAndValue(field, associatedValue, isUnlModifyWorkaround)
|
||||||
if (field.type.name === ST_OBJECT) {
|
if (field.type.name === ST_OBJECT) {
|
||||||
bytes.put(OBJECT_END_MARKER_BYTE)
|
bytes.put(OBJECT_END_MARKER_BYTE)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"binary": "120066240000000026000003006840000000000000007300701321ED9D593004CC501CACD261BD8E31E863F2B3F6CA69505E7FD54DA8F5690BEFB7AE8114000000000000000000000000000000000000000000101101",
|
"binary": "120066240000000026040B52006840000000000000007300701321EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539810000101101",
|
||||||
"tx": {
|
"tx": {
|
||||||
"UNLModifyDisabling": 1,
|
"UNLModifyDisabling": 1,
|
||||||
"LedgerSequence": 768,
|
"LedgerSequence": 67850752,
|
||||||
"UNLModifyValidator": "ED9D593004CC501CACD261BD8E31E863F2B3F6CA69505E7FD54DA8F5690BEFB7AE",
|
"UNLModifyValidator": "EDB6FC8E803EE8EDC2793F1EC917B2EE41D35255618DEB91D3F9B1FC89B75D4539",
|
||||||
"TransactionType": "UNLModify",
|
"TransactionType": "UNLModify",
|
||||||
"Account": "rrrrrrrrrrrrrrrrrrrrrhoLvTp",
|
"Account": "rrrrrrrrrrrrrrrrrrrrrhoLvTp",
|
||||||
"Sequence": 0,
|
"Sequence": 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user