From 3d1b6a045988b9efba6175a0f05ecd2c532d45dd Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Thu, 30 Jun 2022 13:52:18 -0700 Subject: [PATCH] make codec required, some pvm types (#89) * wip * xchain * rename to avm * nits * wip * wip * add test * refactor type --- src/common/types.ts | 3 +-- src/components/avax/baseTx.ts | 6 ++--- src/components/avax/transferableInput.ts | 4 +-- src/components/avax/transferableOp.ts | 8 +++--- src/components/avax/transferableOutput.ts | 7 +++-- src/components/avax/utxo.ts | 4 +-- src/components/avax/utxoId.ts | 6 ++--- src/fxs/nft/mintOperation.ts | 12 ++++----- src/fxs/nft/mintOutput.ts | 17 ++++++------ src/fxs/nft/transferOperation.ts | 6 ++--- src/fxs/nft/transferOutput.ts | 6 ++--- src/fxs/secp256k1/credential.ts | 9 ++++--- src/fxs/secp256k1/input.ts | 4 +-- src/fxs/secp256k1/mintOperation.ts | 8 +++--- src/fxs/secp256k1/mintOutput.ts | 8 +++--- src/fxs/secp256k1/outputOwners.ts | 20 +++++++------- src/fxs/secp256k1/outputOwnersList.ts | 8 +++--- src/fxs/secp256k1/transferInput.ts | 6 ++--- src/fxs/secp256k1/transferOutput.ts | 6 ++--- src/utils/serializeList.spec.ts | 6 +++-- src/utils/serializeList.ts | 12 ++++----- src/utils/struct.ts | 33 ++--------------------- src/vms/avm/createAssetTx.ts | 9 +++---- src/vms/avm/exportTx.ts | 4 +-- src/vms/avm/importTx.ts | 6 ++--- src/vms/pvm/addValidatorTx.ts | 6 ++--- src/vms/pvm/subnetValidator.ts | 4 +-- src/vms/pvm/validator.ts | 4 +-- 28 files changed, 102 insertions(+), 130 deletions(-) diff --git a/src/common/types.ts b/src/common/types.ts index 5fc0d4dea..ec8eeb186 100644 --- a/src/common/types.ts +++ b/src/common/types.ts @@ -3,13 +3,12 @@ import type { Codec } from '../codec'; export interface Serializable { _type: symbol; - toBytes(codec?: Codec): Uint8Array; + toBytes(codec: Codec): Uint8Array; } export interface SerializableStatic { new (...args: any[]): Serializable; - fromBytes(bytes: Uint8Array, codec?: Codec): [Serializable, Uint8Array]; fromBytes(bytes: Uint8Array, codec: Codec): [Serializable, Uint8Array]; } diff --git a/src/components/avax/baseTx.ts b/src/components/avax/baseTx.ts index 80321c684..3336cdc43 100644 --- a/src/components/avax/baseTx.ts +++ b/src/components/avax/baseTx.ts @@ -1,11 +1,11 @@ -import { concatBytes } from '../../utils/buffer'; import type { Codec } from '../../codec/codec'; import { serializable } from '../../common/types'; import { TransferableInput, TransferableOutput } from '../../components/avax'; import { Id } from '../../fxs/common/id'; import { Bytes, Int } from '../../primitives'; +import { concatBytes } from '../../utils/buffer'; import { convertListStruct, packList } from '../../utils/serializeList'; -import { packSimple, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; const _symbol = Symbol('avax.BaseTx'); @@ -45,7 +45,7 @@ export class BaseTx { toBytes(codec) { return concatBytes( - packSimple(this.NetworkId, this.BlockchainId), + pack([this.NetworkId, this.BlockchainId], codec), packList(this.outputs, codec), packList(this.inputs, codec), this.memo.toBytes(), diff --git a/src/components/avax/transferableInput.ts b/src/components/avax/transferableInput.ts index 29040ca2a..a184cd6ab 100644 --- a/src/components/avax/transferableInput.ts +++ b/src/components/avax/transferableInput.ts @@ -4,7 +4,7 @@ import type { Serializable } from '../../common/types'; import { serializable } from '../../common/types'; import { Id } from '../../fxs/common/id'; import { concatBytes } from '../../utils/buffer'; -import { packSimple, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; const _symbol = Symbol('avax.TransferableInput'); @@ -38,7 +38,7 @@ export class TransferableInput { toBytes(codec: Codec) { return concatBytes( - packSimple(this.utxoID, this.assetId), + pack([this.utxoID, this.assetId], codec), codec.PackPrefix(this.input), ); } diff --git a/src/components/avax/transferableOp.ts b/src/components/avax/transferableOp.ts index db9c99b7e..ec0092341 100644 --- a/src/components/avax/transferableOp.ts +++ b/src/components/avax/transferableOp.ts @@ -1,11 +1,11 @@ -import { concatBytes } from '../../utils/buffer'; import { UTXOID } from '.'; import { Codec } from '../../codec/codec'; import type { Serializable } from '../../common/types'; import { serializable } from '../../common/types'; import { Id } from '../../fxs/common/id'; +import { concatBytes } from '../../utils/buffer'; import { convertListStruct, packList } from '../../utils/serializeList'; -import { packSimpleWithCodec, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; const _symbol = Symbol('avax.TransferableOp'); @@ -37,8 +37,8 @@ export class TransferableOp { toBytes(codec: Codec) { return concatBytes( - packSimpleWithCodec([this.assetId], codec), - packList(this.UTXOId), + pack([this.assetId], codec), + packList(this.UTXOId, codec), codec.PackPrefix(this.transferOp), ); } diff --git a/src/components/avax/transferableOutput.ts b/src/components/avax/transferableOutput.ts index 0679b7596..f5da331ac 100644 --- a/src/components/avax/transferableOutput.ts +++ b/src/components/avax/transferableOutput.ts @@ -3,7 +3,7 @@ import type { Amounter } from '../../common/types'; import { serializable } from '../../common/types'; import { Id } from '../../fxs/common/id'; import { concatBytes } from '../../utils/buffer'; -import { packSimple, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; const _symbol = Symbol('avax.TransferableOutput'); @@ -29,6 +29,9 @@ export class TransferableOutput { } toBytes(codec: Codec) { - return concatBytes(packSimple(this.assetId), codec.PackPrefix(this.output)); + return concatBytes( + pack([this.assetId], codec), + codec.PackPrefix(this.output), + ); } } diff --git a/src/components/avax/utxo.ts b/src/components/avax/utxo.ts index 1f51bb463..515c69f45 100644 --- a/src/components/avax/utxo.ts +++ b/src/components/avax/utxo.ts @@ -3,7 +3,7 @@ import { Codec } from '../../codec/codec'; import { Serializable, serializable } from '../../common/types'; import { UTXOID } from '../../components/avax'; import { Id } from '../../fxs/common'; -import { packSimpleWithCodec, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; const _symbol = Symbol('avax.Utxo'); @@ -31,7 +31,7 @@ export class Utxo { toBytes(codec) { return concatBytes( - packSimpleWithCodec([this.utxoId, this.assetId], codec), + pack([this.utxoId, this.assetId], codec), codec.PackPrefix(this.output), ); } diff --git a/src/components/avax/utxoId.ts b/src/components/avax/utxoId.ts index 7459f9e64..9f4c909ac 100644 --- a/src/components/avax/utxoId.ts +++ b/src/components/avax/utxoId.ts @@ -4,7 +4,7 @@ import { Id } from '../../fxs/common/id'; import { BigIntPr, Int } from '../../primitives'; import { base58check } from '../../utils/base58'; import { concatBytes } from '../../utils/buffer'; -import { packSimple, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; const _symbol = Symbol('avax.UTXOID'); @@ -23,8 +23,8 @@ export class UTXOID { return [new UTXOID(txID, outputIdx), remaining]; } - toBytes() { - return packSimple(this.txID, this.outputIdx); + toBytes(codec) { + return pack([this.txID, this.outputIdx], codec); } ID() { diff --git a/src/fxs/nft/mintOperation.ts b/src/fxs/nft/mintOperation.ts index 687c85dc6..1c95f893a 100644 --- a/src/fxs/nft/mintOperation.ts +++ b/src/fxs/nft/mintOperation.ts @@ -1,7 +1,7 @@ import { serializable } from '../../common/types'; import { Bytes, Int } from '../../primitives'; +import { pack, unpack } from '../../utils/struct'; import { Input, OutputOwnersList } from '../secp256k1'; -import { packSimple, unpack } from '../../utils/struct'; const _symbol = Symbol('nftfx.MintOperation'); @@ -30,12 +30,10 @@ export class MintOperation { ]; } - toBytes() { - return packSimple( - this.input, - this.groupId, - this.payload, - this.outputOwnerList, + toBytes(codec) { + return pack( + [this.input, this.groupId, this.payload, this.outputOwnerList], + codec, ); } } diff --git a/src/fxs/nft/mintOutput.ts b/src/fxs/nft/mintOutput.ts index f46815833..d3774e317 100644 --- a/src/fxs/nft/mintOutput.ts +++ b/src/fxs/nft/mintOutput.ts @@ -1,6 +1,6 @@ import { serializable } from '../../common/types'; import { Int } from '../../primitives'; -import { packSimple, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; import { OutputOwners } from '../secp256k1'; const _symbol = Symbol('nftfx.MintOutput'); @@ -15,16 +15,17 @@ export class MintOutput { constructor(private groupId: Int, private outputOwners: OutputOwners) {} - static fromBytes(bytes: Uint8Array): [MintOutput, Uint8Array] { - const [groupId, owners, remaining] = unpack(bytes, [ - Int, - OutputOwners, - ] as const); + static fromBytes(bytes: Uint8Array, codec): [MintOutput, Uint8Array] { + const [groupId, owners, remaining] = unpack( + bytes, + [Int, OutputOwners] as const, + codec, + ); return [new MintOutput(groupId, owners), remaining]; } - toBytes() { - return packSimple(this.groupId, this.outputOwners); + toBytes(codec) { + return pack([this.groupId, this.outputOwners], codec); } } diff --git a/src/fxs/nft/transferOperation.ts b/src/fxs/nft/transferOperation.ts index 65eae5374..d2cb9a553 100644 --- a/src/fxs/nft/transferOperation.ts +++ b/src/fxs/nft/transferOperation.ts @@ -1,5 +1,5 @@ import { serializable } from '../../common/types'; -import { packSimple, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; import { Input } from '../secp256k1'; import { TransferOutput } from './transferOutput'; @@ -21,7 +21,7 @@ export class TransferOperation { return [new TransferOperation(input, output), remaining]; } - toBytes() { - return packSimple(this.input, this.output); + toBytes(codec) { + return pack([this.input, this.output], codec); } } diff --git a/src/fxs/nft/transferOutput.ts b/src/fxs/nft/transferOutput.ts index 65afb8acc..2c4ff30a2 100644 --- a/src/fxs/nft/transferOutput.ts +++ b/src/fxs/nft/transferOutput.ts @@ -1,6 +1,6 @@ import { serializable } from '../../common/types'; import { Bytes, Int } from '../../primitives'; -import { packSimple, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; import { OutputOwners } from '../secp256k1'; const _symbol = Symbol('nftfx.TransferOutput'); @@ -29,7 +29,7 @@ export class TransferOutput { return [new TransferOutput(groupId, payload, outputOwners), remaining]; } - toBytes() { - return packSimple(this.groupId, this.payload, this.outputOwners); + toBytes(codec) { + return pack([this.groupId, this.payload, this.outputOwners], codec); } } diff --git a/src/fxs/secp256k1/credential.ts b/src/fxs/secp256k1/credential.ts index ca86373e9..d1e079746 100644 --- a/src/fxs/secp256k1/credential.ts +++ b/src/fxs/secp256k1/credential.ts @@ -1,3 +1,4 @@ +import { Codec } from '../../codec'; import { serializable } from '../../common/types'; import { packList, unpackList } from '../../utils/serializeList'; import { Signature } from './signature'; @@ -13,12 +14,12 @@ export class Credential { constructor(private signatures: Signature[]) {} - static fromBytes(bytes: Uint8Array): [Credential, Uint8Array] { - const [sigs, remaining] = unpackList(bytes, Signature); + static fromBytes(bytes: Uint8Array, codec: Codec): [Credential, Uint8Array] { + const [sigs, remaining] = unpackList(bytes, Signature, codec); return [new Credential(sigs), remaining]; } - toBytes() { - return packList(this.signatures); + toBytes(codec) { + return packList(this.signatures, codec); } } diff --git a/src/fxs/secp256k1/input.ts b/src/fxs/secp256k1/input.ts index 34e575734..2574e4049 100644 --- a/src/fxs/secp256k1/input.ts +++ b/src/fxs/secp256k1/input.ts @@ -22,7 +22,7 @@ export class Input { return [new Input(sigIndices), remaining]; } - toBytes() { - return packList(this.sigIndices); + toBytes(codec) { + return packList(this.sigIndices, codec); } } diff --git a/src/fxs/secp256k1/mintOperation.ts b/src/fxs/secp256k1/mintOperation.ts index eb8766200..7eb49eeab 100644 --- a/src/fxs/secp256k1/mintOperation.ts +++ b/src/fxs/secp256k1/mintOperation.ts @@ -29,11 +29,11 @@ export class MintOperation { return [new MintOperation(input, mintOutput, transferOutput), remaining]; } - toBytes() { + toBytes(codec) { return concatBytes( - this.input.toBytes(), - this.mintOutput.toBytes(), - this.transferOutput.toBytes(), + this.input.toBytes(codec), + this.mintOutput.toBytes(codec), + this.transferOutput.toBytes(codec), ); } } diff --git a/src/fxs/secp256k1/mintOutput.ts b/src/fxs/secp256k1/mintOutput.ts index f934269d1..26b54ae8e 100644 --- a/src/fxs/secp256k1/mintOutput.ts +++ b/src/fxs/secp256k1/mintOutput.ts @@ -13,14 +13,14 @@ export class MintOutput { constructor(private outputOwners: OutputOwners) {} - static fromBytes(bytes: Uint8Array): [MintOutput, Uint8Array] { + static fromBytes(bytes: Uint8Array, codec): [MintOutput, Uint8Array] { let owners: OutputOwners; - [owners, bytes] = OutputOwners.fromBytes(bytes); + [owners, bytes] = OutputOwners.fromBytes(bytes, codec); return [new MintOutput(owners), bytes]; } - toBytes() { - return this.outputOwners.toBytes(); + toBytes(codec) { + return this.outputOwners.toBytes(codec); } } diff --git a/src/fxs/secp256k1/outputOwners.ts b/src/fxs/secp256k1/outputOwners.ts index 87523e453..f6a567248 100644 --- a/src/fxs/secp256k1/outputOwners.ts +++ b/src/fxs/secp256k1/outputOwners.ts @@ -2,7 +2,7 @@ import { concatBytes } from '@noble/hashes/utils'; import { serializable } from '../../common/types'; import { BigIntPr, Int } from '../../primitives'; import { convertListStruct, packList } from '../../utils/serializeList'; -import { packSimple, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; import { Address } from '../common'; const _symbol = Symbol('secp256k1fx.OutputOwners'); @@ -21,20 +21,20 @@ export class OutputOwners { public readonly addrs: Address[], ) {} - static fromBytes(bytes: Uint8Array): [OutputOwners, Uint8Array] { - const [locktime, threshold, addresses, remaining] = unpack(bytes, [ - BigIntPr, - Int, - convertListStruct(Address), - ]); + static fromBytes(bytes: Uint8Array, codec): [OutputOwners, Uint8Array] { + const [locktime, threshold, addresses, remaining] = unpack( + bytes, + [BigIntPr, Int, convertListStruct(Address)], + codec, + ); return [new OutputOwners(locktime, threshold, addresses), remaining]; } - toBytes() { + toBytes(codec) { return concatBytes( - packSimple(this.locktime, this.threshold), - packList(this.addrs), + pack([this.locktime, this.threshold], codec), + packList(this.addrs, codec), ); } } diff --git a/src/fxs/secp256k1/outputOwnersList.ts b/src/fxs/secp256k1/outputOwnersList.ts index 8a9f79503..e11e91a40 100644 --- a/src/fxs/secp256k1/outputOwnersList.ts +++ b/src/fxs/secp256k1/outputOwnersList.ts @@ -14,12 +14,12 @@ export class OutputOwnersList { constructor(private outputOwners: OutputOwners[]) {} - static fromBytes(bytes: Uint8Array): [OutputOwnersList, Uint8Array] { - const [owners, remaining] = unpackList(bytes, OutputOwners); + static fromBytes(bytes: Uint8Array, codec): [OutputOwnersList, Uint8Array] { + const [owners, remaining] = unpackList(bytes, OutputOwners, codec); return [new OutputOwnersList(owners), remaining]; } - toBytes() { - return packList(this.outputOwners); + toBytes(codec) { + return packList(this.outputOwners, codec); } } diff --git a/src/fxs/secp256k1/transferInput.ts b/src/fxs/secp256k1/transferInput.ts index be9c3cd47..9dc1127c4 100644 --- a/src/fxs/secp256k1/transferInput.ts +++ b/src/fxs/secp256k1/transferInput.ts @@ -1,7 +1,7 @@ import { Input } from '.'; import { serializable } from '../../common/types'; import { BigIntPr } from '../../primitives'; -import { packSimple, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; const _symbol = Symbol('secp256k1fx.TransferInput'); @@ -22,7 +22,7 @@ export class TransferInput { return [new TransferInput(amt, input), remaining]; } - toBytes() { - return packSimple(this.amt, this.input); + toBytes(codec) { + return pack([this.amt, this.input], codec); } } diff --git a/src/fxs/secp256k1/transferOutput.ts b/src/fxs/secp256k1/transferOutput.ts index 5a8e57419..5071b9e6e 100644 --- a/src/fxs/secp256k1/transferOutput.ts +++ b/src/fxs/secp256k1/transferOutput.ts @@ -1,7 +1,7 @@ import { OutputOwners } from '.'; import { serializable } from '../../common/types'; import { BigIntPr } from '../../primitives'; -import { packSimple, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; const _symbol = Symbol('secp256k1fx.TransferOutput'); @@ -30,7 +30,7 @@ export class TransferOutput { return [new TransferOutput(amt, owners), remaining]; } - toBytes() { - return packSimple(this.amt, this.outputOwners); + toBytes(codec) { + return pack([this.amt, this.outputOwners], codec); } } diff --git a/src/utils/serializeList.spec.ts b/src/utils/serializeList.spec.ts index c24037b3d..c7ceb164c 100644 --- a/src/utils/serializeList.spec.ts +++ b/src/utils/serializeList.spec.ts @@ -9,14 +9,16 @@ import { unpack } from './struct'; describe('SerializeList', () => { it('unpacks list', () => { const adds = addressesBytes(); - expect(unpackList(adds, Address)).toEqual([ + expect(unpackList(adds, Address, testCodec())).toEqual([ [address(), address()], new Uint8Array([]), ]); }); it('unpacks list', () => { - expect(packList([address(), address()])).toEqual(addressesBytes()); + expect(packList([address(), address()], testCodec())).toEqual( + addressesBytes(), + ); }); it('unpack for list type', () => { diff --git a/src/utils/serializeList.ts b/src/utils/serializeList.ts index 92ef3872e..30b10f3e3 100644 --- a/src/utils/serializeList.ts +++ b/src/utils/serializeList.ts @@ -1,15 +1,15 @@ import type { Codec } from '../codec'; import type { Serializable, SerializableStatic } from '../common/types'; -import { Int } from '../primitives'; import { bytesForInt } from '../fixtures/utils/bytesFor'; +import { Int } from '../primitives'; import { concatBytes } from './buffer'; -type unpackFunc = (buf: Uint8Array, codec?: Codec) => [any, Uint8Array]; +type unpackFunc = (buf: Uint8Array, codec: Codec) => [any, Uint8Array]; export const unpackList = ( buf: Uint8Array, serializable: T, - codec?: Codec, + codec: Codec, ): [ReturnType[0][], Uint8Array] => { return unpackListForEach(buf, serializable.fromBytes, codec); }; @@ -17,7 +17,7 @@ export const unpackList = ( export const unpackListForEach = ( buf: Uint8Array, callback: T, - codec?: Codec, + codec: Codec, ): [ReturnType[0][], Uint8Array] => { let len; [len, buf] = Int.fromBytes(buf); @@ -36,7 +36,7 @@ export const unpackListForEach = ( export const convertListStruct = ( serializable: T, ) => ({ - fromBytes: (buff: Uint8Array, codec?: Codec) => + fromBytes: (buff: Uint8Array, codec: Codec) => unpackList(buff, serializable, codec), }); @@ -52,7 +52,7 @@ export const unpackCodecList = { export const packList = ( serializables: Serializable[], - codec?: Codec, + codec: Codec, ): Uint8Array => { return concatBytes( bytesForInt(serializables.length), diff --git a/src/utils/struct.ts b/src/utils/struct.ts index 220169674..2c8ffb116 100644 --- a/src/utils/struct.ts +++ b/src/utils/struct.ts @@ -1,5 +1,5 @@ import type { Codec } from '../codec'; -import type { Serializable, SerializableStatic } from '../common/types'; +import type { Serializable } from '../common/types'; import { concatBytes } from './buffer'; export type FromBytesReturn = T extends { @@ -12,12 +12,6 @@ export type FromBytesReturn = T extends { ? rType : never; -type ConstructorReturnType = T extends { - new (...args: any[]): infer rType; -} - ? rType - : never; - export type ReturnTypes = { [i in keyof T]: FromBytesReturn; }; @@ -40,29 +34,6 @@ export function unpack( return [...unpacked, buffer] as unknown as [...ReturnTypes, Uint8Array]; } -export function packSimple(...serializables: Serializable[]) { - return concatBytes(...serializables.map((ser) => ser.toBytes())); -} - -export function packSimpleWithCodec( - serializables: Serializable[], - codec?: Codec, -) { +export function pack(serializables: Serializable[], codec: Codec) { return concatBytes(...serializables.map((ser) => ser.toBytes(codec))); } - -export function unpackV2< - O extends readonly any[], - T extends SerializableStatic, ->( - buf: Uint8Array, - sers: O, - outerClass: T, - codec?: Codec, -): [ConstructorReturnType, Uint8Array] { - const results = unpack(buf, sers, codec); - return [ - new outerClass(...results.slice(0, -1)), - results[results.length - 1], - ] as unknown as [ConstructorReturnType, Uint8Array]; -} diff --git a/src/vms/avm/createAssetTx.ts b/src/vms/avm/createAssetTx.ts index 5bbe1d50f..4c7fc7210 100644 --- a/src/vms/avm/createAssetTx.ts +++ b/src/vms/avm/createAssetTx.ts @@ -1,10 +1,10 @@ -import { concatBytes } from '../../utils/buffer'; import type { Codec } from '../../codec/codec'; import { serializable } from '../../common/types'; import { BaseTx } from '../../components/avax'; import { Byte, Stringpr } from '../../primitives'; +import { concatBytes } from '../../utils/buffer'; import { convertListStruct, packList } from '../../utils/serializeList'; -import { packSimpleWithCodec, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; import { InitialState } from './initialState'; const _symbol = Symbol('avm.CreateAssetTx'); @@ -41,10 +41,7 @@ export class CreateAssetTx { toBytes(codec: Codec) { return concatBytes( - packSimpleWithCodec( - [this.baseTx, this.name, this.symbol, this.denomination], - codec, - ), + pack([this.baseTx, this.name, this.symbol, this.denomination], codec), packList(this.initialStates, codec), ); } diff --git a/src/vms/avm/exportTx.ts b/src/vms/avm/exportTx.ts index 9f7b364d5..92e6f4552 100644 --- a/src/vms/avm/exportTx.ts +++ b/src/vms/avm/exportTx.ts @@ -4,7 +4,7 @@ import { BaseTx, TransferableOutput } from '../../components/avax'; import { Id } from '../../fxs/common'; import { concatBytes } from '../../utils/buffer'; import { convertListStruct, packList } from '../../utils/serializeList'; -import { packSimpleWithCodec, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; const _symbol = Symbol('avm.ExportTx'); @@ -32,7 +32,7 @@ export class ExportTx { toBytes(codec: Codec) { return concatBytes( - packSimpleWithCodec([this.baseTx, this.destination], codec), + pack([this.baseTx, this.destination], codec), packList(this.outs, codec), ); } diff --git a/src/vms/avm/importTx.ts b/src/vms/avm/importTx.ts index 76000c453..267534b5b 100644 --- a/src/vms/avm/importTx.ts +++ b/src/vms/avm/importTx.ts @@ -1,10 +1,10 @@ -import { concatBytes } from '../../utils/buffer'; import type { Codec } from '../../codec/codec'; import { serializable } from '../../common/types'; import { BaseTx, TransferableInput } from '../../components/avax'; import { Id } from '../../fxs/common'; +import { concatBytes } from '../../utils/buffer'; import { convertListStruct, packList } from '../../utils/serializeList'; -import { packSimpleWithCodec, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; const _symbol = Symbol('avm.ImportTx'); @@ -32,7 +32,7 @@ export class ImportTx { toBytes(codec: Codec) { return concatBytes( - packSimpleWithCodec([this.baseTx, this.sourceChain], codec), + pack([this.baseTx, this.sourceChain], codec), packList(this.ins, codec), ); } diff --git a/src/vms/pvm/addValidatorTx.ts b/src/vms/pvm/addValidatorTx.ts index db3697505..c1533c667 100644 --- a/src/vms/pvm/addValidatorTx.ts +++ b/src/vms/pvm/addValidatorTx.ts @@ -5,7 +5,7 @@ import { OutputOwners } from '../../fxs/secp256k1'; import { Int } from '../../primitives'; import { concatBytes } from '../../utils/buffer'; import { convertListStruct, packList } from '../../utils/serializeList'; -import { packSimpleWithCodec, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; import { Validator } from './validator'; const _symbol = Symbol('pvm.AddValidatorTx'); @@ -48,9 +48,9 @@ export class AddValidatorTx { toBytes(codec: Codec) { return concatBytes( - packSimpleWithCodec([this.baseTx, this.validator], codec), + pack([this.baseTx, this.validator], codec), packList(this.stake, codec), - packSimpleWithCodec([this.rewardsOwner, this.shares], codec), + pack([this.rewardsOwner, this.shares], codec), ); } } diff --git a/src/vms/pvm/subnetValidator.ts b/src/vms/pvm/subnetValidator.ts index f96a41a25..49dedea21 100644 --- a/src/vms/pvm/subnetValidator.ts +++ b/src/vms/pvm/subnetValidator.ts @@ -1,7 +1,7 @@ import type { Codec } from '../../codec/codec'; import { serializable } from '../../common/types'; import { Id } from '../../fxs/common'; -import { packSimpleWithCodec, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; import { Validator } from './validator'; const _symbol = Symbol('pvm.SubnetValidator'); @@ -27,6 +27,6 @@ export class SubnetValidator { } toBytes(codec: Codec) { - return packSimpleWithCodec([this.validator, this.subnetId], codec); + return pack([this.validator, this.subnetId], codec); } } diff --git a/src/vms/pvm/validator.ts b/src/vms/pvm/validator.ts index 13ba57d9a..b116c5794 100644 --- a/src/vms/pvm/validator.ts +++ b/src/vms/pvm/validator.ts @@ -2,7 +2,7 @@ import type { Codec } from '../../codec/codec'; import { serializable } from '../../common/types'; import { Id } from '../../fxs/common'; import { BigIntPr } from '../../primitives'; -import { packSimpleWithCodec, unpack } from '../../utils/struct'; +import { pack, unpack } from '../../utils/struct'; const _symbol = Symbol('pvm.Validator'); @@ -30,7 +30,7 @@ export class Validator { } toBytes(codec: Codec) { - return packSimpleWithCodec( + return pack( [this.nodeId, this.startTime, this.endTime, this.weight], codec, );