Skip to content

Commit

Permalink
Formatting and rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
xbtmatt committed Oct 11, 2023
1 parent 28194ad commit 8ce0ccc
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 81 deletions.
5 changes: 1 addition & 4 deletions src/bcs/serializable/fixed-bytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { Serializable, Serializer } from "../serializer";
import { Deserializer } from "../deserializer";
import { HexInput } from "../../types";
import { Hex } from "../../core";
import {
EntryFunctionArgument,
TransactionArgument,
} from "../../transactions/instances/transactionArgument";
import { EntryFunctionArgument, TransactionArgument } from "../../transactions/instances/transactionArgument";

/**
* This class exists to represent a contiguous sequence of BCS bytes that when serialized
Expand Down
7 changes: 1 addition & 6 deletions src/bcs/serializable/move-primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import {
} from "../consts";
import { AnyNumber, Uint16, Uint32, Uint8 } from "../../types";
import { Deserializer } from "../deserializer";
import {
Serializable,
Serializer,
ensureBoolean,
validateNumberInRange,
} from "../serializer";
import { Serializable, Serializer, ensureBoolean, validateNumberInRange } from "../serializer";
import { TransactionArgument } from "../../transactions/instances/transactionArgument";
import {
ScriptTransactionArgumentBool,
Expand Down
62 changes: 14 additions & 48 deletions src/bcs/serializable/move-structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@ import { Deserializable, Deserializer } from "../deserializer";
import { Bool, U128, U16, U256, U32, U64, U8 } from "./move-primitives";
import { AnyNumber, HexInput } from "../../types";
import { AccountAddress, Hex } from "../../core";
import {
EntryFunctionArgument,
TransactionArgument,
} from "../../transactions/instances/transactionArgument";
import {
ScriptTransactionArgumentAddress,
ScriptTransactionArgumentU8Vector,
} from "../../transactions/instances";
import { EntryFunctionArgument, TransactionArgument } from "../../transactions/instances/transactionArgument";
import { ScriptTransactionArgumentAddress, ScriptTransactionArgumentU8Vector } from "../../transactions/instances";

/**
* This class is the Aptos Typescript SDK representation of a Move `vector<T>`,
Expand Down Expand Up @@ -58,10 +52,7 @@ import {
* values: an Array<T> of values where T is a class that implements Serializable
* @returns a `MoveVector<T>` with the values `values`
*/
export class MoveVector<T extends Serializable>
extends Serializable
implements TransactionArgument
{
export class MoveVector<T extends Serializable> extends Serializable implements TransactionArgument {
public values: Array<T>;

constructor(values: Array<T>) {
Expand Down Expand Up @@ -219,10 +210,7 @@ export class MoveVector<T extends Serializable>
* @returns a MoveVector of the corresponding class T
* *
*/
static deserialize<T extends Serializable>(
deserializer: Deserializer,
cls: Deserializable<T>
): MoveVector<T> {
static deserialize<T extends Serializable>(deserializer: Deserializer, cls: Deserializable<T>): MoveVector<T> {
const length = deserializer.deserializeUleb128AsU32();
const values = new Array<T>();
for (let i = 0; i < length; i += 1) {
Expand Down Expand Up @@ -260,10 +248,7 @@ export class MoveString extends Serializable implements TransactionArgument {
}
}

export class MoveOption<T extends Serializable>
extends Serializable
implements EntryFunctionArgument
{
export class MoveOption<T extends Serializable> extends Serializable implements EntryFunctionArgument {
private vec: MoveVector<T>;

public readonly value?: T;
Expand Down Expand Up @@ -331,9 +316,7 @@ export class MoveOption<T extends Serializable>
* @returns a MoveOption<U8> with an inner value `value`
*/
static U8(value?: number | null): MoveOption<U8> {
return new MoveOption<U8>(
value !== null && value !== undefined ? new U8(value) : undefined
);
return new MoveOption<U8>(value !== null && value !== undefined ? new U8(value) : undefined);
}

/**
Expand All @@ -348,9 +331,7 @@ export class MoveOption<T extends Serializable>
* @returns a MoveOption<U16> with an inner value `value`
*/
static U16(value?: number | null): MoveOption<U16> {
return new MoveOption<U16>(
value !== null && value !== undefined ? new U16(value) : undefined
);
return new MoveOption<U16>(value !== null && value !== undefined ? new U16(value) : undefined);
}

/**
Expand All @@ -365,9 +346,7 @@ export class MoveOption<T extends Serializable>
* @returns a MoveOption<U32> with an inner value `value`
*/
static U32(value?: number | null): MoveOption<U32> {
return new MoveOption<U32>(
value !== null && value !== undefined ? new U32(value) : undefined
);
return new MoveOption<U32>(value !== null && value !== undefined ? new U32(value) : undefined);
}

/**
Expand All @@ -382,9 +361,7 @@ export class MoveOption<T extends Serializable>
* @returns a MoveOption<U64> with an inner value `value`
*/
static U64(value?: AnyNumber | null): MoveOption<U64> {
return new MoveOption<U64>(
value !== null && value !== undefined ? new U64(value) : undefined
);
return new MoveOption<U64>(value !== null && value !== undefined ? new U64(value) : undefined);
}

/**
Expand All @@ -399,9 +376,7 @@ export class MoveOption<T extends Serializable>
* @returns a MoveOption<U128> with an inner value `value`
*/
static U128(value?: AnyNumber | null): MoveOption<U128> {
return new MoveOption<U128>(
value !== null && value !== undefined ? new U128(value) : undefined
);
return new MoveOption<U128>(value !== null && value !== undefined ? new U128(value) : undefined);
}

/**
Expand All @@ -416,9 +391,7 @@ export class MoveOption<T extends Serializable>
* @returns a MoveOption<U256> with an inner value `value`
*/
static U256(value?: AnyNumber | null): MoveOption<U256> {
return new MoveOption<U256>(
value !== null && value !== undefined ? new U256(value) : undefined
);
return new MoveOption<U256>(value !== null && value !== undefined ? new U256(value) : undefined);
}

/**
Expand All @@ -433,9 +406,7 @@ export class MoveOption<T extends Serializable>
* @returns a MoveOption<Bool> with an inner value `value`
*/
static Bool(value?: boolean | null): MoveOption<Bool> {
return new MoveOption<Bool>(
value !== null && value !== undefined ? new Bool(value) : undefined
);
return new MoveOption<Bool>(value !== null && value !== undefined ? new Bool(value) : undefined);
}

/**
Expand All @@ -451,15 +422,10 @@ export class MoveOption<T extends Serializable>
* @returns a MoveOption<MoveString> with an inner value `value`
*/
static MoveString(value?: string | null): MoveOption<MoveString> {
return new MoveOption<MoveString>(
value !== null && value !== undefined ? new MoveString(value) : undefined
);
return new MoveOption<MoveString>(value !== null && value !== undefined ? new MoveString(value) : undefined);
}

static deserialize<U extends Serializable>(
deserializer: Deserializer,
cls: Deserializable<U>
): MoveOption<U> {
static deserialize<U extends Serializable>(deserializer: Deserializer, cls: Deserializable<U>): MoveOption<U> {
const vector = MoveVector.deserialize(deserializer, cls);
return new MoveOption(vector.values[0]);
}
Expand Down
3 changes: 2 additions & 1 deletion src/bcs/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export abstract class Serializable {
* Helper function to get a value's BCS-serialized bytes as a Hex instance.
* @returns a Hex instance with the BCS-serialized bytes loaded into its underlying Uint8Array
*/
bcsToHex() { //: Hex {
bcsToHex() {
//: Hex {
// const bcsBytes = this.bcsToBytes();
// return Hex.fromHexInput({ hexInput: bcsBytes });
}
Expand Down
2 changes: 1 addition & 1 deletion src/transactions/instances/scriptTransactionArguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,4 @@ export class ScriptTransactionArgumentBool extends ScriptTransactionArgument imp
const value = deserializer.deserializeBool();
return new ScriptTransactionArgumentBool(value);
}
}
}
14 changes: 3 additions & 11 deletions src/transactions/instances/transactionArgument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import { Serializer, Deserializer, Serializable } from "../../bcs";
import { HexInput } from "../../types";
import { FixedBytes } from "../../bcs/serializable/fixed-bytes";

export interface TransactionArgument
extends EntryFunctionArgument,
ScriptFunctionArgument {}
export interface TransactionArgument extends EntryFunctionArgument, ScriptFunctionArgument {}

export interface EntryFunctionArgument {
/**
Expand Down Expand Up @@ -41,10 +39,7 @@ export interface ScriptFunctionArgument {
* of the argument beforehand, and use the appropriate class to deserialize the bytes within
* an instance of this class.
*/
export class EntryFunctionBytes
extends Serializable
implements EntryFunctionArgument
{
export class EntryFunctionBytes extends Serializable implements EntryFunctionArgument {
public readonly value: FixedBytes;

private constructor(value: HexInput) {
Expand Down Expand Up @@ -77,10 +72,7 @@ export class EntryFunctionBytes
* @param length the length of the bytes to deserialize
* @returns an instance of this class, which will now only be usable as an EntryFunctionArgument
*/
static deserialize(
deserializer: Deserializer,
length: number
): EntryFunctionBytes {
static deserialize(deserializer: Deserializer, length: number): EntryFunctionBytes {
const fixedBytes = FixedBytes.deserialize(deserializer, length);
return new EntryFunctionBytes(fixedBytes.value);
}
Expand Down
9 changes: 7 additions & 2 deletions src/transactions/instances/transactionPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ export class EntryFunction {
* public entry fun transfer<CoinType>(from: &signer, to: address, amount: u64)
* ```
*/
constructor(module_name: ModuleId, function_name: Identifier, type_args: Array<TypeTag>, args: Array<EntryFunctionArgument>) {
constructor(
module_name: ModuleId,
function_name: Identifier,
type_args: Array<TypeTag>,
args: Array<EntryFunctionArgument>,
) {
this.module_name = module_name;
this.function_name = function_name;
this.type_args = type_args;
Expand Down Expand Up @@ -192,7 +197,7 @@ export class EntryFunction {
* NOTE: When you deserialize an EntryFunction payload with this method, the entry function
* arguments are populated into the deserialized instance as type-agnostic, raw fixed bytes
* in the form of the EntryFunctionBytes class.
*
*
* In order to correctly deserialize these arguments as their actual type representations, you
* must know the types of the arguments beforehand and deserialize them yourself individually.
*
Expand Down
8 changes: 2 additions & 6 deletions src/transactions/typeTag/typeTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,8 @@ export class StructTag extends Serializable {
}
}

export const stringStructTag = () => new StructTag(
AccountAddress.ONE,
new Identifier("string"),
new Identifier("String"),
[],
);
export const stringStructTag = () =>
new StructTag(AccountAddress.ONE, new Identifier("string"), new Identifier("String"), []);

export function optionStructTag(typeArg: TypeTag): StructTag {
return new StructTag(AccountAddress.ONE, new Identifier("option"), new Identifier("Option"), [typeArg]);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/script_transaction_arguments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ describe("Tests for the script transaction argument class", () => {
true,
);
});
});
});
2 changes: 1 addition & 1 deletion tests/unit/type_tag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe("TypeTagParser", () => {
const typeTagError = error as ParsingError<AddressInvalidReason>;
expect(typeTagError.message).toEqual(
`The given hex string ${typeTag} is a special address not in LONG form,
it must be 0x0 to 0xf without padding zeroes.`
it must be 0x0 to 0xf without padding zeroes.`,
);
}

Expand Down

0 comments on commit 8ce0ccc

Please sign in to comment.