-
Notifications
You must be signed in to change notification settings - Fork 84
fix: make serializeForEntryFunction backward-compatible with older Serializers (DVR-143) #861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
16f0dd1
e4606fa
b8edbdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { Bool, U128, U16, U256, U32, U64, U8, I8, I16, I32, I64, I128, I256 } from "./movePrimitives"; | ||
| import { Serializable, Serializer } from "../serializer"; | ||
| import { Serializable, Serializer, serializeEntryFunctionBytesCompat } from "../serializer"; | ||
| import { Deserializable, Deserializer } from "../deserializer"; | ||
| import { AnyNumber, HexInput, ScriptTransactionArgumentVariants } from "../../types"; | ||
| import { Hex } from "../../core/hex"; | ||
|
|
@@ -69,14 +69,14 @@ export class MoveVector<T extends Serializable & EntryFunctionArgument> | |
| /** | ||
| * Serializes the current instance into a byte sequence suitable for entry functions. | ||
| * This allows the data to be properly formatted for transmission or storage. | ||
| * Uses the optimized serializeAsBytes method to reduce allocations. | ||
| * Uses serializeAsBytes when available, with a fallback for older Serializer versions. | ||
| * | ||
| * @param serializer - The serializer instance used to serialize the byte sequence. | ||
| * @group Implementation | ||
| * @category BCS | ||
| */ | ||
| serializeForEntryFunction(serializer: Serializer): void { | ||
| serializer.serializeAsBytes(this); | ||
| serializeEntryFunctionBytesCompat(serializer, this); | ||
| } | ||
|
Comment on lines
76
to
80
|
||
|
|
||
| /** | ||
|
|
@@ -493,7 +493,7 @@ export class MoveString extends Serializable implements TransactionArgument { | |
| } | ||
|
|
||
| serializeForEntryFunction(serializer: Serializer): void { | ||
| serializer.serializeAsBytes(this); | ||
| serializeEntryFunctionBytesCompat(serializer, this); | ||
| } | ||
|
|
||
| serializeForScriptFunction(serializer: Serializer): void { | ||
|
|
@@ -530,7 +530,7 @@ export class MoveOption<T extends Serializable & EntryFunctionArgument> | |
| } | ||
|
|
||
| serializeForEntryFunction(serializer: Serializer): void { | ||
| serializer.serializeAsBytes(this); | ||
| serializeEntryFunctionBytesCompat(serializer, this); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { bytesToHex, hexToBytes } from "@noble/hashes/utils"; | ||
| import { Serializable, Serializer } from "../bcs/serializer"; | ||
| import { Serializable, Serializer, serializeEntryFunctionBytesCompat } from "../bcs/serializer"; | ||
| import { Deserializer } from "../bcs/deserializer"; | ||
| import { ParsingError, ParsingResult } from "./common"; | ||
| import { TransactionArgument } from "../transactions/instances/transactionArgument"; | ||
|
|
@@ -240,14 +240,14 @@ export class AccountAddress extends Serializable implements TransactionArgument | |
| /** | ||
| * Serializes the current instance into a byte sequence suitable for entry functions. | ||
| * This allows for the proper encoding of data when interacting with entry functions in the blockchain. | ||
| * Uses the optimized serializeAsBytes method to reduce allocations. | ||
| * Uses serializeAsBytes when available, with a fallback for older Serializer versions. | ||
| * | ||
| * @param serializer - The serializer instance used to convert the data into bytes. | ||
| * @group Implementation | ||
| * @category Serialization | ||
| */ | ||
| serializeForEntryFunction(serializer: Serializer): void { | ||
| serializer.serializeAsBytes(this); | ||
| serializeEntryFunctionBytesCompat(serializer, this); | ||
|
Comment on lines
248
to
+250
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSDoc above this method still claims it “Uses the optimized serializeAsBytes method”, but the implementation now uses
serializeEntryFunctionBytesCompat()which may fall back tobcsToBytes() + serializeBytes()for older Serializer implementations. Please update the comment to match the new behavior (prefer optimized path when available, otherwise fallback for compatibility).