forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename enum variants and transaction arguments (aptos-labs#10384)
- Loading branch information
Showing
8 changed files
with
263 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export * from "./chainId"; | ||
export * from "./rawTransaction"; | ||
export * from "./transactionArguments"; | ||
export * from "./scriptTransactionArguments"; | ||
export * from "./transactionPayload"; | ||
export * from "./moduleId"; | ||
export * from "./identifier"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
214 changes: 214 additions & 0 deletions
214
ecosystem/typescript/sdk_v2/src/transactions/types/scriptTransactionArguments.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
import { Serializer, Deserializer, Serializable } from "../../bcs"; | ||
import { AccountAddress } from "../../core"; | ||
import { ScriptTransactionArgumentVariants } from "../../types"; | ||
|
||
/** | ||
* Representation of a Script Transaction Argument that can be serialized and deserialized | ||
*/ | ||
export abstract class ScriptTransactionArgument extends Serializable { | ||
/** | ||
* Serialize a Script Transaction Argument | ||
*/ | ||
abstract serialize(serializer: Serializer): void; | ||
|
||
/** | ||
* Deserialize a Script Transaction Argument | ||
*/ | ||
static deserialize(deserializer: Deserializer): ScriptTransactionArgument { | ||
// index enum variant | ||
const index = deserializer.deserializeUleb128AsU32(); | ||
switch (index) { | ||
case ScriptTransactionArgumentVariants.ScriptTransactionArgumentU8: | ||
return ScriptTransactionArgumentU8.load(deserializer); | ||
case ScriptTransactionArgumentVariants.ScriptTransactionArgumentU64: | ||
return ScriptTransactionArgumentU64.load(deserializer); | ||
case ScriptTransactionArgumentVariants.ScriptTransactionArgumentU128: | ||
return ScriptTransactionArgumentU128.load(deserializer); | ||
case ScriptTransactionArgumentVariants.ScriptTransactionArgumentAddress: | ||
return ScriptTransactionArgumentAddress.load(deserializer); | ||
case ScriptTransactionArgumentVariants.ScriptTransactionArgumentU8Vector: | ||
return ScriptTransactionArgumentU8Vector.load(deserializer); | ||
case ScriptTransactionArgumentVariants.ScriptTransactionArgumentBool: | ||
return ScriptTransactionArgumentBool.load(deserializer); | ||
case ScriptTransactionArgumentVariants.ScriptTransactionArgumentU16: | ||
return ScriptTransactionArgumentU16.load(deserializer); | ||
case ScriptTransactionArgumentVariants.ScriptTransactionArgumentU32: | ||
return ScriptTransactionArgumentU32.load(deserializer); | ||
case ScriptTransactionArgumentVariants.ScriptTransactionArgumentU256: | ||
return ScriptTransactionArgumentU256.load(deserializer); | ||
default: | ||
throw new Error(`Unknown variant index for ScriptTransactionArgument: ${index}`); | ||
} | ||
} | ||
} | ||
|
||
export class ScriptTransactionArgumentU8 extends ScriptTransactionArgument { | ||
public readonly value: number; | ||
|
||
constructor(value: number) { | ||
super(); | ||
this.value = value; | ||
} | ||
|
||
serialize(serializer: Serializer): void { | ||
serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.ScriptTransactionArgumentU8); | ||
serializer.serializeU8(this.value); | ||
} | ||
|
||
static load(deserializer: Deserializer): ScriptTransactionArgumentU8 { | ||
const value = deserializer.deserializeU8(); | ||
return new ScriptTransactionArgumentU8(value); | ||
} | ||
} | ||
|
||
export class ScriptTransactionArgumentU16 extends ScriptTransactionArgument { | ||
public readonly value: number; | ||
|
||
constructor(value: number) { | ||
super(); | ||
this.value = value; | ||
} | ||
|
||
serialize(serializer: Serializer): void { | ||
serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.ScriptTransactionArgumentU16); | ||
serializer.serializeU16(this.value); | ||
} | ||
|
||
static load(deserializer: Deserializer): ScriptTransactionArgumentU16 { | ||
const value = deserializer.deserializeU16(); | ||
return new ScriptTransactionArgumentU16(value); | ||
} | ||
} | ||
|
||
export class ScriptTransactionArgumentU32 extends ScriptTransactionArgument { | ||
public readonly value: number; | ||
|
||
constructor(value: number) { | ||
super(); | ||
this.value = value; | ||
} | ||
|
||
serialize(serializer: Serializer): void { | ||
serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.ScriptTransactionArgumentU32); | ||
serializer.serializeU32(this.value); | ||
} | ||
|
||
static load(deserializer: Deserializer): ScriptTransactionArgumentU32 { | ||
const value = deserializer.deserializeU32(); | ||
return new ScriptTransactionArgumentU32(value); | ||
} | ||
} | ||
|
||
export class ScriptTransactionArgumentU64 extends ScriptTransactionArgument { | ||
public readonly value: bigint; | ||
|
||
constructor(value: bigint) { | ||
super(); | ||
this.value = value; | ||
} | ||
|
||
serialize(serializer: Serializer): void { | ||
serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.ScriptTransactionArgumentU64); | ||
serializer.serializeU64(this.value); | ||
} | ||
|
||
static load(deserializer: Deserializer): ScriptTransactionArgumentU64 { | ||
const value = deserializer.deserializeU64(); | ||
return new ScriptTransactionArgumentU64(value); | ||
} | ||
} | ||
|
||
export class ScriptTransactionArgumentU128 extends ScriptTransactionArgument { | ||
public readonly value: bigint; | ||
|
||
constructor(value: bigint) { | ||
super(); | ||
this.value = value; | ||
} | ||
|
||
serialize(serializer: Serializer): void { | ||
serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.ScriptTransactionArgumentU128); | ||
serializer.serializeU128(this.value); | ||
} | ||
|
||
static load(deserializer: Deserializer): ScriptTransactionArgumentU128 { | ||
const value = deserializer.deserializeU128(); | ||
return new ScriptTransactionArgumentU128(value); | ||
} | ||
} | ||
|
||
export class ScriptTransactionArgumentU256 extends ScriptTransactionArgument { | ||
public readonly value: bigint; | ||
|
||
constructor(value: bigint) { | ||
super(); | ||
this.value = value; | ||
} | ||
|
||
serialize(serializer: Serializer): void { | ||
serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.ScriptTransactionArgumentU256); | ||
serializer.serializeU256(this.value); | ||
} | ||
|
||
static load(deserializer: Deserializer): ScriptTransactionArgumentU256 { | ||
const value = deserializer.deserializeU256(); | ||
return new ScriptTransactionArgumentU256(value); | ||
} | ||
} | ||
|
||
export class ScriptTransactionArgumentAddress extends ScriptTransactionArgument { | ||
public readonly value: AccountAddress; | ||
|
||
constructor(value: AccountAddress) { | ||
super(); | ||
this.value = value; | ||
} | ||
|
||
serialize(serializer: Serializer): void { | ||
serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.ScriptTransactionArgumentAddress); | ||
this.value.serialize(serializer); | ||
} | ||
|
||
static load(deserializer: Deserializer): ScriptTransactionArgumentAddress { | ||
const value = AccountAddress.deserialize(deserializer); | ||
return new ScriptTransactionArgumentAddress(value); | ||
} | ||
} | ||
|
||
export class ScriptTransactionArgumentU8Vector extends ScriptTransactionArgument { | ||
public readonly value: Uint8Array; | ||
|
||
constructor(value: Uint8Array) { | ||
super(); | ||
this.value = value; | ||
} | ||
|
||
serialize(serializer: Serializer): void { | ||
serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.ScriptTransactionArgumentU8Vector); | ||
serializer.serializeBytes(this.value); | ||
} | ||
|
||
static load(deserializer: Deserializer): ScriptTransactionArgumentU8Vector { | ||
const value = deserializer.deserializeBytes(); | ||
return new ScriptTransactionArgumentU8Vector(value); | ||
} | ||
} | ||
|
||
export class ScriptTransactionArgumentBool extends ScriptTransactionArgument { | ||
public readonly value: boolean; | ||
|
||
constructor(value: boolean) { | ||
super(); | ||
this.value = value; | ||
} | ||
|
||
serialize(serializer: Serializer): void { | ||
serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.ScriptTransactionArgumentBool); | ||
serializer.serializeBool(this.value); | ||
} | ||
|
||
static load(deserializer: Deserializer): ScriptTransactionArgumentBool { | ||
const value = deserializer.deserializeBool(); | ||
return new ScriptTransactionArgumentBool(value); | ||
} | ||
} |
Oops, something went wrong.