diff --git a/packages/godwoken/schemas/index.d.ts b/packages/godwoken/schemas/index.d.ts index 694d05b5..b603cc2a 100644 --- a/packages/godwoken/schemas/index.d.ts +++ b/packages/godwoken/schemas/index.d.ts @@ -13,32 +13,6 @@ export interface UnionType { value: any; } -export function SerializeByte32Opt(value: CanCastToArrayBuffer | null): ArrayBuffer; -export class Byte32Opt { - constructor(reader: CanCastToArrayBuffer, options?: CreateOptions); - validate(compatible?: boolean): void; - value(): Byte32; - hasValue(): boolean; -} - -export function SerializeByte20(value: CanCastToArrayBuffer): ArrayBuffer; -export class Byte20 { - constructor(reader: CanCastToArrayBuffer, options?: CreateOptions); - validate(compatible?: boolean): void; - indexAt(i: number): number; - raw(): ArrayBuffer; - static size(): Number; -} - -export function SerializeSignature(value: CanCastToArrayBuffer): ArrayBuffer; -export class Signature { - constructor(reader: CanCastToArrayBuffer, options?: CreateOptions); - validate(compatible?: boolean): void; - indexAt(i: number): number; - raw(): ArrayBuffer; - static size(): Number; -} - export function SerializeBlockMerkleState(value: object): ArrayBuffer; export class BlockMerkleState { constructor(reader: CanCastToArrayBuffer, options?: CreateOptions); @@ -86,7 +60,6 @@ export class RollupConfig { getRequiredStakingCapacity(): Uint64; getChallengeMaturityBlocks(): Uint64; getFinalityBlocks(): Uint64; - getCompatibleChainId(): Uint32; getRewardBurnRate(): number; getAllowedEoaTypeHashes(): Byte32Vec; getAllowedContractTypeHashes(): Byte32Vec; @@ -107,7 +80,7 @@ export class L2Transaction { constructor(reader: CanCastToArrayBuffer, options?: CreateOptions); validate(compatible?: boolean): void; getRaw(): RawL2Transaction; - getSignature(): Signature; + getSignature(): Bytes; } export function SerializeL2TransactionVec(value: Array): ArrayBuffer; @@ -204,6 +177,7 @@ export class RawWithdrawalRequest { getSellCapacity(): Uint64; getOwnerLockHash(): Byte32; getPaymentLockHash(): Byte32; + getFee(): Fee; } export function SerializeWithdrawalRequestVec(value: Array): ArrayBuffer; @@ -218,9 +192,8 @@ export function SerializeWithdrawalRequest(value: object): ArrayBuffer; export class WithdrawalRequest { constructor(reader: CanCastToArrayBuffer, options?: CreateOptions); validate(compatible?: boolean): void; - static size(): Number; getRaw(): RawWithdrawalRequest; - getSignature(): Signature; + getSignature(): Bytes; } export function SerializeKVPair(value: object): ArrayBuffer; @@ -336,11 +309,21 @@ export class MetaContractArgs { value(): any; } +export function SerializeFee(value: object): ArrayBuffer; +export class Fee { + constructor(reader: CanCastToArrayBuffer, options?: CreateOptions); + validate(compatible?: boolean): void; + static size(): Number; + getSudtId(): Uint32; + getAmount(): Uint128; +} + export function SerializeCreateAccount(value: object): ArrayBuffer; export class CreateAccount { constructor(reader: CanCastToArrayBuffer, options?: CreateOptions); validate(compatible?: boolean): void; getScript(): Script; + getFee(): Fee; } export function SerializeSUDTArgs(value: UnionType): ArrayBuffer; @@ -355,16 +338,14 @@ export function SerializeSUDTQuery(value: object): ArrayBuffer; export class SUDTQuery { constructor(reader: CanCastToArrayBuffer, options?: CreateOptions); validate(compatible?: boolean): void; - static size(): Number; - getAccountId(): Uint32; + getShortAddress(): Bytes; } export function SerializeSUDTTransfer(value: object): ArrayBuffer; export class SUDTTransfer { constructor(reader: CanCastToArrayBuffer, options?: CreateOptions); validate(compatible?: boolean): void; - static size(): Number; - getTo(): Uint32; + getTo(): Bytes; getAmount(): Uint128; getFee(): Uint128; } @@ -443,8 +424,8 @@ export class VerifyTransactionWitness { getContext(): VerifyTransactionContext; } -export function SerializeVerifySignatureContext(value: object): ArrayBuffer; -export class VerifySignatureContext { +export function SerializeVerifyTransactionSignatureContext(value: object): ArrayBuffer; +export class VerifyTransactionSignatureContext { constructor(reader: CanCastToArrayBuffer, options?: CreateOptions); validate(compatible?: boolean): void; getAccountCount(): Uint32; @@ -456,12 +437,11 @@ export function SerializeVerifyTransactionSignatureWitness(value: object): Array export class VerifyTransactionSignatureWitness { constructor(reader: CanCastToArrayBuffer, options?: CreateOptions); validate(compatible?: boolean): void; - getL2Tx(): L2Transaction; getRawL2Block(): RawL2Block; + getL2Tx(): L2Transaction; getTxProof(): Bytes; getKvStateProof(): Bytes; - getBlockHashesProof(): Bytes; - getContext(): VerifySignatureContext; + getContext(): VerifyTransactionSignatureContext; } export function SerializeVerifyWithdrawalWitness(value: object): ArrayBuffer; @@ -469,10 +449,8 @@ export class VerifyWithdrawalWitness { constructor(reader: CanCastToArrayBuffer, options?: CreateOptions); validate(compatible?: boolean): void; getRawL2Block(): RawL2Block; - getKvStateProof(): Bytes; getWithdrawalRequest(): WithdrawalRequest; getWithdrawalProof(): Bytes; - getContext(): VerifySignatureContext; } export function SerializeRollupSubmitBlock(value: object): ArrayBuffer; @@ -542,6 +520,8 @@ export class Uint64 { validate(compatible?: boolean): void; indexAt(i: number): number; raw(): ArrayBuffer; + toBigEndianUint64(): BigInt; + toLittleEndianUint64(): BigInt; static size(): Number; } diff --git a/packages/godwoken/schemas/index.esm.js b/packages/godwoken/schemas/index.esm.js index 8bcb8873..966824bb 100644 --- a/packages/godwoken/schemas/index.esm.js +++ b/packages/godwoken/schemas/index.esm.js @@ -1,3872 +1,3979 @@ -function dataLengthError(actual, required) { - throw new Error(`Invalid data length! Required: ${required}, actual: ${actual}`); -} +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.GodwokenCore = {})); +}(this, (function (exports) { 'use strict'; -function assertDataLength(actual, required) { - if (actual !== required) { - dataLengthError(actual, required); + function dataLengthError(actual, required) { + throw new Error(`Invalid data length! Required: ${required}, actual: ${actual}`); } -} -function assertArrayBuffer(reader) { - if (reader instanceof Object && reader.toArrayBuffer instanceof Function) { - reader = reader.toArrayBuffer(); - } - if (!(reader instanceof ArrayBuffer)) { - throw new Error("Provided value must be an ArrayBuffer or can be transformed into ArrayBuffer!"); + function assertDataLength(actual, required) { + if (actual !== required) { + dataLengthError(actual, required); + } } - return reader; -} -function verifyAndExtractOffsets(view, expectedFieldCount, compatible) { - if (view.byteLength < 4) { - dataLengthError(view.byteLength, ">4"); - } - const requiredByteLength = view.getUint32(0, true); - assertDataLength(view.byteLength, requiredByteLength); - if (requiredByteLength === 4) { - return [requiredByteLength]; - } - if (requiredByteLength < 8) { - dataLengthError(view.byteLength, ">8"); - } - const firstOffset = view.getUint32(4, true); - if (firstOffset % 4 !== 0 || firstOffset < 8) { - throw new Error(`Invalid first offset: ${firstOffset}`); - } - const itemCount = firstOffset / 4 - 1; - if (itemCount < expectedFieldCount) { - throw new Error(`Item count not enough! Required: ${expectedFieldCount}, actual: ${itemCount}`); - } else if ((!compatible) && itemCount > expectedFieldCount) { - throw new Error(`Item count is more than required! Required: ${expectedFieldCount}, actual: ${itemCount}`); - } - if (requiredByteLength < firstOffset) { - throw new Error(`First offset is larger than byte length: ${firstOffset}`); - } - const offsets = []; - for (let i = 0; i < itemCount; i++) { - const start = 4 + i * 4; - offsets.push(view.getUint32(start, true)); + function assertArrayBuffer(reader) { + if (reader instanceof Object && reader.toArrayBuffer instanceof Function) { + reader = reader.toArrayBuffer(); + } + if (!(reader instanceof ArrayBuffer)) { + throw new Error("Provided value must be an ArrayBuffer or can be transformed into ArrayBuffer!"); + } + return reader; } - offsets.push(requiredByteLength); - for (let i = 0; i < offsets.length - 1; i++) { - if (offsets[i] > offsets[i + 1]) { - throw new Error(`Offset index ${i}: ${offsets[i]} is larger than offset index ${i + 1}: ${offsets[i + 1]}`); + + function verifyAndExtractOffsets(view, expectedFieldCount, compatible) { + if (view.byteLength < 4) { + dataLengthError(view.byteLength, ">4"); + } + const requiredByteLength = view.getUint32(0, true); + assertDataLength(view.byteLength, requiredByteLength); + if (requiredByteLength === 4) { + return [requiredByteLength]; + } + if (requiredByteLength < 8) { + dataLengthError(view.byteLength, ">8"); + } + const firstOffset = view.getUint32(4, true); + if (firstOffset % 4 !== 0 || firstOffset < 8) { + throw new Error(`Invalid first offset: ${firstOffset}`); } + const itemCount = firstOffset / 4 - 1; + if (itemCount < expectedFieldCount) { + throw new Error(`Item count not enough! Required: ${expectedFieldCount}, actual: ${itemCount}`); + } else if ((!compatible) && itemCount > expectedFieldCount) { + throw new Error(`Item count is more than required! Required: ${expectedFieldCount}, actual: ${itemCount}`); + } + if (requiredByteLength < firstOffset) { + throw new Error(`First offset is larger than byte length: ${firstOffset}`); + } + const offsets = []; + for (let i = 0; i < itemCount; i++) { + const start = 4 + i * 4; + offsets.push(view.getUint32(start, true)); + } + offsets.push(requiredByteLength); + for (let i = 0; i < offsets.length - 1; i++) { + if (offsets[i] > offsets[i + 1]) { + throw new Error(`Offset index ${i}: ${offsets[i]} is larger than offset index ${i + 1}: ${offsets[i + 1]}`); + } + } + return offsets; } - return offsets; -} -function serializeTable(buffers) { - const itemCount = buffers.length; - let totalSize = 4 * (itemCount + 1); - const offsets = []; + function serializeTable(buffers) { + const itemCount = buffers.length; + let totalSize = 4 * (itemCount + 1); + const offsets = []; - for (let i = 0; i < itemCount; i++) { - offsets.push(totalSize); - totalSize += buffers[i].byteLength; - } + for (let i = 0; i < itemCount; i++) { + offsets.push(totalSize); + totalSize += buffers[i].byteLength; + } - const buffer = new ArrayBuffer(totalSize); - const array = new Uint8Array(buffer); - const view = new DataView(buffer); + const buffer = new ArrayBuffer(totalSize); + const array = new Uint8Array(buffer); + const view = new DataView(buffer); - view.setUint32(0, totalSize, true); - for (let i = 0; i < itemCount; i++) { - view.setUint32(4 + i * 4, offsets[i], true); - array.set(new Uint8Array(buffers[i]), offsets[i]); + view.setUint32(0, totalSize, true); + for (let i = 0; i < itemCount; i++) { + view.setUint32(4 + i * 4, offsets[i], true); + array.set(new Uint8Array(buffers[i]), offsets[i]); + } + return buffer; } - return buffer; -} -export class Byte32Opt { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class BlockMerkleState { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - validate(compatible = false) { - if (this.hasValue()) { - this.value().validate(compatible); + getMerkleRoot() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); } - } - value() { - return new Byte32(this.view.buffer, { validate: false }); - } + getCount() { + return new Uint64(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint64.size()), { validate: false }); + } - hasValue() { - return this.view.byteLength > 0; + validate(compatible = false) { + assertDataLength(this.view.byteLength, BlockMerkleState.size()); + this.getMerkleRoot().validate(compatible); + this.getCount().validate(compatible); + } + static size() { + return 0 + Byte32.size() + Uint64.size(); + } } -} -export function SerializeByte32Opt(value) { - if (value) { - return SerializeByte32(value); - } else { - return new ArrayBuffer(0); + function SerializeBlockMerkleState(value) { + const array = new Uint8Array(0 + Byte32.size() + Uint64.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.merkle_root)), 0); + array.set(new Uint8Array(SerializeUint64(value.count)), 0 + Byte32.size()); + return array.buffer; } -} -export class Byte20 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class AccountMerkleState { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - validate(compatible = false) { - assertDataLength(this.view.byteLength, 20); - } + getMerkleRoot() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + } - indexAt(i) { - return this.view.getUint8(i); - } + getCount() { + return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); + } - raw() { - return this.view.buffer; + validate(compatible = false) { + assertDataLength(this.view.byteLength, AccountMerkleState.size()); + this.getMerkleRoot().validate(compatible); + this.getCount().validate(compatible); + } + static size() { + return 0 + Byte32.size() + Uint32.size(); + } } - static size() { - return 20; + function SerializeAccountMerkleState(value) { + const array = new Uint8Array(0 + Byte32.size() + Uint32.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.merkle_root)), 0); + array.set(new Uint8Array(SerializeUint32(value.count)), 0 + Byte32.size()); + return array.buffer; } -} -export function SerializeByte20(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 20); - return buffer; -} - -export class Signature { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class GlobalState { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - validate(compatible = false) { - assertDataLength(this.view.byteLength, 65); - } + getRollupConfigHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + } - indexAt(i) { - return this.view.getUint8(i); - } + getAccount() { + return new AccountMerkleState(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + AccountMerkleState.size()), { validate: false }); + } - raw() { - return this.view.buffer; - } + getBlock() { + return new BlockMerkleState(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size()), { validate: false }); + } - static size() { - return 65; - } -} + getRevertedBlockRoot() { + return new Byte32(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size()), { validate: false }); + } -export function SerializeSignature(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 65); - return buffer; -} + getTipBlockHash() { + return new Byte32(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size()), { validate: false }); + } -export class BlockMerkleState { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getLastFinalizedBlockNumber() { + return new Uint64(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size()), { validate: false }); } - } - getMerkleRoot() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } + getStatus() { + return this.view.getUint8(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size()); + } - getCount() { - return new Uint64(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint64.size()), { validate: false }); + validate(compatible = false) { + assertDataLength(this.view.byteLength, GlobalState.size()); + this.getRollupConfigHash().validate(compatible); + this.getAccount().validate(compatible); + this.getBlock().validate(compatible); + this.getRevertedBlockRoot().validate(compatible); + this.getTipBlockHash().validate(compatible); + this.getLastFinalizedBlockNumber().validate(compatible); + } + static size() { + return 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size() + 1; + } } - validate(compatible = false) { - assertDataLength(this.view.byteLength, BlockMerkleState.size()); - this.getMerkleRoot().validate(compatible); - this.getCount().validate(compatible); - } - static size() { - return 0 + Byte32.size() + Uint64.size(); + function SerializeGlobalState(value) { + const array = new Uint8Array(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size() + 1); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.rollup_config_hash)), 0); + array.set(new Uint8Array(SerializeAccountMerkleState(value.account)), 0 + Byte32.size()); + array.set(new Uint8Array(SerializeBlockMerkleState(value.block)), 0 + Byte32.size() + AccountMerkleState.size()); + array.set(new Uint8Array(SerializeByte32(value.reverted_block_root)), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size()); + array.set(new Uint8Array(SerializeByte32(value.tip_block_hash)), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size()); + array.set(new Uint8Array(SerializeUint64(value.last_finalized_block_number)), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size()); + view.setUint8(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size(), value.status); + return array.buffer; } -} -export function SerializeBlockMerkleState(value) { - const array = new Uint8Array(0 + Byte32.size() + Uint64.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeByte32(value.merkle_root)), 0); - array.set(new Uint8Array(SerializeUint64(value.count)), 0 + Byte32.size()); - return array.buffer; -} - -export class AccountMerkleState { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class RollupConfig { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - getMerkleRoot() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[6], offsets[7]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[7], offsets[8]), { validate: false }).validate(); + new Uint64(this.view.buffer.slice(offsets[8], offsets[9]), { validate: false }).validate(); + new Uint64(this.view.buffer.slice(offsets[9], offsets[10]), { validate: false }).validate(); + new Uint64(this.view.buffer.slice(offsets[10], offsets[11]), { validate: false }).validate(); + if (offsets[12] - offsets[11] !== 1) { + throw new Error(`Invalid offset for reward_burn_rate: ${offsets[11]} - ${offsets[12]}`) + } + new Byte32Vec(this.view.buffer.slice(offsets[12], offsets[13]), { validate: false }).validate(); + new Byte32Vec(this.view.buffer.slice(offsets[13], offsets[14]), { validate: false }).validate(); + } - getCount() { - return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); - } + getL1SudtScriptTypeHash() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, AccountMerkleState.size()); - this.getMerkleRoot().validate(compatible); - this.getCount().validate(compatible); - } - static size() { - return 0 + Byte32.size() + Uint32.size(); - } -} + getCustodianScriptTypeHash() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export function SerializeAccountMerkleState(value) { - const array = new Uint8Array(0 + Byte32.size() + Uint32.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeByte32(value.merkle_root)), 0); - array.set(new Uint8Array(SerializeUint32(value.count)), 0 + Byte32.size()); - return array.buffer; -} + getDepositScriptTypeHash() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export class GlobalState { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getWithdrawalScriptTypeHash() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - getRollupConfigHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } + getChallengeScriptTypeHash() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getAccount() { - return new AccountMerkleState(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + AccountMerkleState.size()), { validate: false }); - } + getStakeScriptTypeHash() { + const start = 24; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getL2SudtValidatorScriptTypeHash() { + const start = 28; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getBurnLockHash() { + const start = 32; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getRequiredStakingCapacity() { + const start = 36; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getChallengeMaturityBlocks() { + const start = 40; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getBlock() { - return new BlockMerkleState(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size()), { validate: false }); - } + getFinalityBlocks() { + const start = 44; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getRevertedBlockRoot() { - return new Byte32(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size()), { validate: false }); - } + getRewardBurnRate() { + const start = 48; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new DataView(this.view.buffer.slice(offset, offset_end)).getUint8(0); + } - getTipBlockHash() { - return new Byte32(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size()), { validate: false }); - } + getAllowedEoaTypeHashes() { + const start = 52; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getLastFinalizedBlockNumber() { - return new Uint64(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size()), { validate: false }); + getAllowedContractTypeHashes() { + const start = 56; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getStatus() { - return this.view.getUint8(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size()); + function SerializeRollupConfig(value) { + const buffers = []; + buffers.push(SerializeByte32(value.l1_sudt_script_type_hash)); + buffers.push(SerializeByte32(value.custodian_script_type_hash)); + buffers.push(SerializeByte32(value.deposit_script_type_hash)); + buffers.push(SerializeByte32(value.withdrawal_script_type_hash)); + buffers.push(SerializeByte32(value.challenge_script_type_hash)); + buffers.push(SerializeByte32(value.stake_script_type_hash)); + buffers.push(SerializeByte32(value.l2_sudt_validator_script_type_hash)); + buffers.push(SerializeByte32(value.burn_lock_hash)); + buffers.push(SerializeUint64(value.required_staking_capacity)); + buffers.push(SerializeUint64(value.challenge_maturity_blocks)); + buffers.push(SerializeUint64(value.finality_blocks)); + const rewardBurnRateView = new DataView(new ArrayBuffer(1)); + rewardBurnRateView.setUint8(0, value.reward_burn_rate); + buffers.push(rewardBurnRateView.buffer); + buffers.push(SerializeByte32Vec(value.allowed_eoa_type_hashes)); + buffers.push(SerializeByte32Vec(value.allowed_contract_type_hashes)); + return serializeTable(buffers); } - validate(compatible = false) { - assertDataLength(this.view.byteLength, GlobalState.size()); - this.getRollupConfigHash().validate(compatible); - this.getAccount().validate(compatible); - this.getBlock().validate(compatible); - this.getRevertedBlockRoot().validate(compatible); - this.getTipBlockHash().validate(compatible); - this.getLastFinalizedBlockNumber().validate(compatible); - } - static size() { - return 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size() + 1; - } -} + class RawL2Transaction { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeGlobalState(value) { - const array = new Uint8Array(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size() + 1); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeByte32(value.rollup_config_hash)), 0); - array.set(new Uint8Array(SerializeAccountMerkleState(value.account)), 0 + Byte32.size()); - array.set(new Uint8Array(SerializeBlockMerkleState(value.block)), 0 + Byte32.size() + AccountMerkleState.size()); - array.set(new Uint8Array(SerializeByte32(value.reverted_block_root)), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size()); - array.set(new Uint8Array(SerializeByte32(value.tip_block_hash)), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size()); - array.set(new Uint8Array(SerializeUint64(value.last_finalized_block_number)), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size()); - view.setUint8(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size(), value.status); - return array.buffer; -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Uint32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Uint32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + } -export class RollupConfig { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getFromId() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[6], offsets[7]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[7], offsets[8]), { validate: false }).validate(); - new Uint64(this.view.buffer.slice(offsets[8], offsets[9]), { validate: false }).validate(); - new Uint64(this.view.buffer.slice(offsets[9], offsets[10]), { validate: false }).validate(); - new Uint64(this.view.buffer.slice(offsets[10], offsets[11]), { validate: false }).validate(); - new Uint32(this.view.buffer.slice(offsets[11], offsets[12]), { validate: false }).validate(); - if (offsets[13] - offsets[12] !== 1) { - throw new Error(`Invalid offset for reward_burn_rate: ${offsets[12]} - ${offsets[13]}`) + getToId() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - new Byte32Vec(this.view.buffer.slice(offsets[13], offsets[14]), { validate: false }).validate(); - new Byte32Vec(this.view.buffer.slice(offsets[14], offsets[15]), { validate: false }).validate(); - } - getL1SudtScriptTypeHash() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getNonce() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getCustodianScriptTypeHash() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + getArgs() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getDepositScriptTypeHash() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeRawL2Transaction(value) { + const buffers = []; + buffers.push(SerializeUint32(value.from_id)); + buffers.push(SerializeUint32(value.to_id)); + buffers.push(SerializeUint32(value.nonce)); + buffers.push(SerializeBytes(value.args)); + return serializeTable(buffers); } - getWithdrawalScriptTypeHash() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + class L2Transaction { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getChallengeScriptTypeHash() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getStakeScriptTypeHash() { - const start = 24; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getL2SudtValidatorScriptTypeHash() { - const start = 28; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getBurnLockHash() { - const start = 32; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getRequiredStakingCapacity() { - const start = 36; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getChallengeMaturityBlocks() { - const start = 40; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getFinalityBlocks() { - const start = 44; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawL2Transaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + } - getCompatibleChainId() { - const start = 48; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getRewardBurnRate() { - const start = 52; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new DataView(this.view.buffer.slice(offset, offset_end)).getUint8(0); - } + getRaw() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getAllowedEoaTypeHashes() { - const start = 56; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); + getSignature() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getAllowedContractTypeHashes() { - const start = 60; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeL2Transaction(value) { + const buffers = []; + buffers.push(SerializeRawL2Transaction(value.raw)); + buffers.push(SerializeBytes(value.signature)); + return serializeTable(buffers); } -} -export function SerializeRollupConfig(value) { - const buffers = []; - buffers.push(SerializeByte32(value.l1_sudt_script_type_hash)); - buffers.push(SerializeByte32(value.custodian_script_type_hash)); - buffers.push(SerializeByte32(value.deposit_script_type_hash)); - buffers.push(SerializeByte32(value.withdrawal_script_type_hash)); - buffers.push(SerializeByte32(value.challenge_script_type_hash)); - buffers.push(SerializeByte32(value.stake_script_type_hash)); - buffers.push(SerializeByte32(value.l2_sudt_validator_script_type_hash)); - buffers.push(SerializeByte32(value.burn_lock_hash)); - buffers.push(SerializeUint64(value.required_staking_capacity)); - buffers.push(SerializeUint64(value.challenge_maturity_blocks)); - buffers.push(SerializeUint64(value.finality_blocks)); - buffers.push(SerializeUint32(value.compatible_chain_id)); - const rewardBurnRateView = new DataView(new ArrayBuffer(1)); - rewardBurnRateView.setUint8(0, value.reward_burn_rate); - buffers.push(rewardBurnRateView.buffer) - buffers.push(SerializeByte32Vec(value.allowed_eoa_type_hashes)); - buffers.push(SerializeByte32Vec(value.allowed_contract_type_hashes)); - return serializeTable(buffers); -} + class L2TransactionVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class RawL2Transaction { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new L2Transaction(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + } } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Uint32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Uint32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - } + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; + } + } - getFromId() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); + } + return new L2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getToId() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeL2TransactionVec(value) { + return serializeTable(value.map(item => SerializeL2Transaction(item))); } - getNonce() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + class SubmitTransactions { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getArgs() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Uint32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + } -export function SerializeRawL2Transaction(value) { - const buffers = []; - buffers.push(SerializeUint32(value.from_id)); - buffers.push(SerializeUint32(value.to_id)); - buffers.push(SerializeUint32(value.nonce)); - buffers.push(SerializeBytes(value.args)); - return serializeTable(buffers); -} + getTxWitnessRoot() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export class L2Transaction { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getTxCount() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new RawL2Transaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Signature(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + getPrevStateCheckpoint() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getRaw() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeSubmitTransactions(value) { + const buffers = []; + buffers.push(SerializeByte32(value.tx_witness_root)); + buffers.push(SerializeUint32(value.tx_count)); + buffers.push(SerializeByte32(value.prev_state_checkpoint)); + return serializeTable(buffers); } - getSignature() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Signature(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} - -export function SerializeL2Transaction(value) { - const buffers = []; - buffers.push(SerializeRawL2Transaction(value.raw)); - buffers.push(SerializeSignature(value.signature)); - return serializeTable(buffers); -} - -export class L2TransactionVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class SubmitWithdrawals { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new L2Transaction(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + getWithdrawalWitnessRoot() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); } - } - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; + getWithdrawalCount() { + return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); } - } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); + validate(compatible = false) { + assertDataLength(this.view.byteLength, SubmitWithdrawals.size()); + this.getWithdrawalWitnessRoot().validate(compatible); + this.getWithdrawalCount().validate(compatible); } - return new L2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} - -export function SerializeL2TransactionVec(value) { - return serializeTable(value.map(item => SerializeL2Transaction(item))); -} - -export class SubmitTransactions { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + static size() { + return 0 + Byte32.size() + Uint32.size(); } } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Uint32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - } - - getTxWitnessRoot() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getTxCount() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getPrevStateCheckpoint() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeSubmitWithdrawals(value) { + const array = new Uint8Array(0 + Byte32.size() + Uint32.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.withdrawal_witness_root)), 0); + array.set(new Uint8Array(SerializeUint32(value.withdrawal_count)), 0 + Byte32.size()); + return array.buffer; } -} -export function SerializeSubmitTransactions(value) { - const buffers = []; - buffers.push(SerializeByte32(value.tx_witness_root)); - buffers.push(SerializeUint32(value.tx_count)); - buffers.push(SerializeByte32(value.prev_state_checkpoint)); - return serializeTable(buffers); -} + class RawL2Block { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class SubmitWithdrawals { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Uint32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new Uint64(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); + new AccountMerkleState(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); + new AccountMerkleState(this.view.buffer.slice(offsets[6], offsets[7]), { validate: false }).validate(); + new Byte32Vec(this.view.buffer.slice(offsets[7], offsets[8]), { validate: false }).validate(); + new SubmitWithdrawals(this.view.buffer.slice(offsets[8], offsets[9]), { validate: false }).validate(); + new SubmitTransactions(this.view.buffer.slice(offsets[9], offsets[10]), { validate: false }).validate(); } - } - getWithdrawalWitnessRoot() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } + getNumber() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getWithdrawalCount() { - return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); - } + getBlockProducerId() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, SubmitWithdrawals.size()); - this.getWithdrawalWitnessRoot().validate(compatible); - this.getWithdrawalCount().validate(compatible); - } - static size() { - return 0 + Byte32.size() + Uint32.size(); - } -} + getParentBlockHash() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export function SerializeSubmitWithdrawals(value) { - const array = new Uint8Array(0 + Byte32.size() + Uint32.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeByte32(value.withdrawal_witness_root)), 0); - array.set(new Uint8Array(SerializeUint32(value.withdrawal_count)), 0 + Byte32.size()); - return array.buffer; -} + getStakeCellOwnerLockHash() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export class RawL2Block { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getTimestamp() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Uint32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new Uint64(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - new AccountMerkleState(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); - new AccountMerkleState(this.view.buffer.slice(offsets[6], offsets[7]), { validate: false }).validate(); - new Byte32Vec(this.view.buffer.slice(offsets[7], offsets[8]), { validate: false }).validate(); - new SubmitWithdrawals(this.view.buffer.slice(offsets[8], offsets[9]), { validate: false }).validate(); - new SubmitTransactions(this.view.buffer.slice(offsets[9], offsets[10]), { validate: false }).validate(); - } + getPrevAccount() { + const start = 24; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new AccountMerkleState(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getNumber() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getPostAccount() { + const start = 28; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new AccountMerkleState(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getBlockProducerId() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getStateCheckpointList() { + const start = 32; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getParentBlockHash() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getSubmitWithdrawals() { + const start = 36; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new SubmitWithdrawals(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getStakeCellOwnerLockHash() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + getSubmitTransactions() { + const start = 40; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new SubmitTransactions(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getTimestamp() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeRawL2Block(value) { + const buffers = []; + buffers.push(SerializeUint64(value.number)); + buffers.push(SerializeUint32(value.block_producer_id)); + buffers.push(SerializeByte32(value.parent_block_hash)); + buffers.push(SerializeByte32(value.stake_cell_owner_lock_hash)); + buffers.push(SerializeUint64(value.timestamp)); + buffers.push(SerializeAccountMerkleState(value.prev_account)); + buffers.push(SerializeAccountMerkleState(value.post_account)); + buffers.push(SerializeByte32Vec(value.state_checkpoint_list)); + buffers.push(SerializeSubmitWithdrawals(value.submit_withdrawals)); + buffers.push(SerializeSubmitTransactions(value.submit_transactions)); + return serializeTable(buffers); } - getPrevAccount() { - const start = 24; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new AccountMerkleState(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + class RawL2BlockVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getPostAccount() { - const start = 28; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new AccountMerkleState(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new RawL2Block(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + } + } - getStateCheckpointList() { - const start = 32; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; + } + } - getSubmitWithdrawals() { - const start = 36; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new SubmitWithdrawals(this.view.buffer.slice(offset, offset_end), { validate: false }); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); + } + return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getSubmitTransactions() { - const start = 40; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new SubmitTransactions(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeRawL2BlockVec(value) { + return serializeTable(value.map(item => SerializeRawL2Block(item))); } -} - -export function SerializeRawL2Block(value) { - const buffers = []; - buffers.push(SerializeUint64(value.number)); - buffers.push(SerializeUint32(value.block_producer_id)); - buffers.push(SerializeByte32(value.parent_block_hash)); - buffers.push(SerializeByte32(value.stake_cell_owner_lock_hash)); - buffers.push(SerializeUint64(value.timestamp)); - buffers.push(SerializeAccountMerkleState(value.prev_account)); - buffers.push(SerializeAccountMerkleState(value.post_account)); - buffers.push(SerializeByte32Vec(value.state_checkpoint_list)); - buffers.push(SerializeSubmitWithdrawals(value.submit_withdrawals)); - buffers.push(SerializeSubmitTransactions(value.submit_transactions)); - return serializeTable(buffers); -} -export class RawL2BlockVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class L2Block { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new RawL2Block(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new KVPairVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new L2TransactionVec(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); + new WithdrawalRequestVec(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); } - } - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; + getRaw() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); + getKvState() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new KVPairVec(this.view.buffer.slice(offset, offset_end), { validate: false }); } - return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} -export function SerializeRawL2BlockVec(value) { - return serializeTable(value.map(item => SerializeRawL2Block(item))); -} - -export class L2Block { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getKvStateProof() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new KVPairVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new L2TransactionVec(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - new WithdrawalRequestVec(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); - } - getRaw() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getKvState() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new KVPairVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getKvStateProof() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getTransactions() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new L2TransactionVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getBlockProof() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getWithdrawals() { - const start = 24; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new WithdrawalRequestVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} - -export function SerializeL2Block(value) { - const buffers = []; - buffers.push(SerializeRawL2Block(value.raw)); - buffers.push(SerializeKVPairVec(value.kv_state)); - buffers.push(SerializeBytes(value.kv_state_proof)); - buffers.push(SerializeL2TransactionVec(value.transactions)); - buffers.push(SerializeBytes(value.block_proof)); - buffers.push(SerializeWithdrawalRequestVec(value.withdrawals)); - return serializeTable(buffers); -} - -export class DepositRequest { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getTransactions() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new L2TransactionVec(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Uint128(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Script(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - } - getCapacity() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getAmount() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint128(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getBlockProof() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getSudtScriptHash() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + getWithdrawals() { + const start = 24; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new WithdrawalRequestVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getScript() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeL2Block(value) { + const buffers = []; + buffers.push(SerializeRawL2Block(value.raw)); + buffers.push(SerializeKVPairVec(value.kv_state)); + buffers.push(SerializeBytes(value.kv_state_proof)); + buffers.push(SerializeL2TransactionVec(value.transactions)); + buffers.push(SerializeBytes(value.block_proof)); + buffers.push(SerializeWithdrawalRequestVec(value.withdrawals)); + return serializeTable(buffers); } -} - -export function SerializeDepositRequest(value) { - const buffers = []; - buffers.push(SerializeUint64(value.capacity)); - buffers.push(SerializeUint128(value.amount)); - buffers.push(SerializeByte32(value.sudt_script_hash)); - buffers.push(SerializeScript(value.script)); - return serializeTable(buffers); -} -export class DepositRequestVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class DepositRequest { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new DepositRequest(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Uint128(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Script(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); } - } - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; + getCapacity() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); + getAmount() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint128(this.view.buffer.slice(offset, offset_end), { validate: false }); } - return new DepositRequest(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} -export function SerializeDepositRequestVec(value) { - return serializeTable(value.map(item => SerializeDepositRequest(item))); -} - -export class RawWithdrawalRequest { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getSudtScriptHash() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - getNonce() { - return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); + getScript() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getCapacity() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint64.size()), { validate: false }); + function SerializeDepositRequest(value) { + const buffers = []; + buffers.push(SerializeUint64(value.capacity)); + buffers.push(SerializeUint128(value.amount)); + buffers.push(SerializeByte32(value.sudt_script_hash)); + buffers.push(SerializeScript(value.script)); + return serializeTable(buffers); } - getAmount() { - return new Uint128(this.view.buffer.slice(0 + Uint32.size() + Uint64.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size()), { validate: false }); - } + class DepositRequestVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getSudtScriptHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size()), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new DepositRequest(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + } + } - getAccountScriptHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size()), { validate: false }); - } + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; + } + } - getSellAmount() { - return new Uint128(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size()), { validate: false }); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); + } + return new DepositRequest(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getSellCapacity() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size()), { validate: false }); + function SerializeDepositRequestVec(value) { + return serializeTable(value.map(item => SerializeDepositRequest(item))); } - getOwnerLockHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()), { validate: false }); - } + class RawWithdrawalRequest { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getPaymentLockHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()), { validate: false }); - } + getNonce() { + return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, RawWithdrawalRequest.size()); - this.getNonce().validate(compatible); - this.getCapacity().validate(compatible); - this.getAmount().validate(compatible); - this.getSudtScriptHash().validate(compatible); - this.getAccountScriptHash().validate(compatible); - this.getSellAmount().validate(compatible); - this.getSellCapacity().validate(compatible); - this.getOwnerLockHash().validate(compatible); - this.getPaymentLockHash().validate(compatible); - } - static size() { - return 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size(); - } -} + getCapacity() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint64.size()), { validate: false }); + } -export function SerializeRawWithdrawalRequest(value) { - const array = new Uint8Array(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeUint32(value.nonce)), 0); - array.set(new Uint8Array(SerializeUint64(value.capacity)), 0 + Uint32.size()); - array.set(new Uint8Array(SerializeUint128(value.amount)), 0 + Uint32.size() + Uint64.size()); - array.set(new Uint8Array(SerializeByte32(value.sudt_script_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size()); - array.set(new Uint8Array(SerializeByte32(value.account_script_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size()); - array.set(new Uint8Array(SerializeUint128(value.sell_amount)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size()); - array.set(new Uint8Array(SerializeUint64(value.sell_capacity)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size()); - array.set(new Uint8Array(SerializeByte32(value.owner_lock_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size()); - array.set(new Uint8Array(SerializeByte32(value.payment_lock_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()); - return array.buffer; -} + getAmount() { + return new Uint128(this.view.buffer.slice(0 + Uint32.size() + Uint64.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size()), { validate: false }); + } -export class WithdrawalRequestVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getSudtScriptHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size()), { validate: false }); } - } - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4"); + getAccountScriptHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size()), { validate: false }); } - const requiredByteLength = this.length() * WithdrawalRequest.size() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); - for (let i = 0; i < 0; i++) { - const item = this.indexAt(i); - item.validate(compatible); + + getSellAmount() { + return new Uint128(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size()), { validate: false }); } - } - indexAt(i) { - return new WithdrawalRequest(this.view.buffer.slice(4 + i * WithdrawalRequest.size(), 4 + (i + 1) * WithdrawalRequest.size()), { validate: false }); - } + getSellCapacity() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size()), { validate: false }); + } - length() { - return this.view.getUint32(0, true); - } -} + getOwnerLockHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()), { validate: false }); + } -export function SerializeWithdrawalRequestVec(value) { - const array = new Uint8Array(4 + WithdrawalRequest.size() * value.length); - (new DataView(array.buffer)).setUint32(0, value.length, true); - for (let i = 0; i < value.length; i++) { - const itemBuffer = SerializeWithdrawalRequest(value[i]); - array.set(new Uint8Array(itemBuffer), 4 + i * WithdrawalRequest.size()); - } - return array.buffer; -} + getPaymentLockHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()), { validate: false }); + } -export class WithdrawalRequest { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getFee() { + return new Fee(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size() + Fee.size()), { validate: false }); } - } - getRaw() { - return new RawWithdrawalRequest(this.view.buffer.slice(0, 0 + RawWithdrawalRequest.size()), { validate: false }); + validate(compatible = false) { + assertDataLength(this.view.byteLength, RawWithdrawalRequest.size()); + this.getNonce().validate(compatible); + this.getCapacity().validate(compatible); + this.getAmount().validate(compatible); + this.getSudtScriptHash().validate(compatible); + this.getAccountScriptHash().validate(compatible); + this.getSellAmount().validate(compatible); + this.getSellCapacity().validate(compatible); + this.getOwnerLockHash().validate(compatible); + this.getPaymentLockHash().validate(compatible); + this.getFee().validate(compatible); + } + static size() { + return 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size() + Fee.size(); + } } - getSignature() { - return new Signature(this.view.buffer.slice(0 + RawWithdrawalRequest.size(), 0 + RawWithdrawalRequest.size() + Signature.size()), { validate: false }); + function SerializeRawWithdrawalRequest(value) { + const array = new Uint8Array(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size() + Fee.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeUint32(value.nonce)), 0); + array.set(new Uint8Array(SerializeUint64(value.capacity)), 0 + Uint32.size()); + array.set(new Uint8Array(SerializeUint128(value.amount)), 0 + Uint32.size() + Uint64.size()); + array.set(new Uint8Array(SerializeByte32(value.sudt_script_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size()); + array.set(new Uint8Array(SerializeByte32(value.account_script_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size()); + array.set(new Uint8Array(SerializeUint128(value.sell_amount)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size()); + array.set(new Uint8Array(SerializeUint64(value.sell_capacity)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size()); + array.set(new Uint8Array(SerializeByte32(value.owner_lock_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size()); + array.set(new Uint8Array(SerializeByte32(value.payment_lock_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()); + array.set(new Uint8Array(SerializeFee(value.fee)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()); + return array.buffer; } - validate(compatible = false) { - assertDataLength(this.view.byteLength, WithdrawalRequest.size()); - this.getRaw().validate(compatible); - this.getSignature().validate(compatible); - } - static size() { - return 0 + RawWithdrawalRequest.size() + Signature.size(); - } -} + class WithdrawalRequestVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeWithdrawalRequest(value) { - const array = new Uint8Array(0 + RawWithdrawalRequest.size() + Signature.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeRawWithdrawalRequest(value.raw)), 0); - array.set(new Uint8Array(SerializeSignature(value.signature)), 0 + RawWithdrawalRequest.size()); - return array.buffer; -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new WithdrawalRequest(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + } + } -export class KVPair { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; + } } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); + } + return new WithdrawalRequest(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getK() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeWithdrawalRequestVec(value) { + return serializeTable(value.map(item => SerializeWithdrawalRequest(item))); } - getV() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + class WithdrawalRequest { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeKVPair(value) { - const buffers = []; - buffers.push(SerializeByte32(value.k)); - buffers.push(SerializeByte32(value.v)); - return serializeTable(buffers); -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawWithdrawalRequest(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + } -export class KVPairVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getRaw() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawWithdrawalRequest(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new KVPair(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + getSignature() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); } } - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; - } + function SerializeWithdrawalRequest(value) { + const buffers = []; + buffers.push(SerializeRawWithdrawalRequest(value.raw)); + buffers.push(SerializeBytes(value.signature)); + return serializeTable(buffers); } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); + class KVPair { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - return new KVPair(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} -export function SerializeKVPairVec(value) { - return serializeTable(value.map(item => SerializeKVPair(item))); -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + } -export class BlockInfo { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getK() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - getBlockProducerId() { - return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); + getV() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getNumber() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint64.size()), { validate: false }); + function SerializeKVPair(value) { + const buffers = []; + buffers.push(SerializeByte32(value.k)); + buffers.push(SerializeByte32(value.v)); + return serializeTable(buffers); } - getTimestamp() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint64.size(), 0 + Uint32.size() + Uint64.size() + Uint64.size()), { validate: false }); - } + class KVPairVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, BlockInfo.size()); - this.getBlockProducerId().validate(compatible); - this.getNumber().validate(compatible); - this.getTimestamp().validate(compatible); - } - static size() { - return 0 + Uint32.size() + Uint64.size() + Uint64.size(); - } -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new KVPair(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + } + } -export function SerializeBlockInfo(value) { - const array = new Uint8Array(0 + Uint32.size() + Uint64.size() + Uint64.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeUint32(value.block_producer_id)), 0); - array.set(new Uint8Array(SerializeUint64(value.number)), 0 + Uint32.size()); - array.set(new Uint8Array(SerializeUint64(value.timestamp)), 0 + Uint32.size() + Uint64.size()); - return array.buffer; -} + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; + } + } -export class DepositLockArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); + } + return new KVPair(this.view.buffer.slice(offset, offset_end), { validate: false }); } } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Script(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Uint64(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + function SerializeKVPairVec(value) { + return serializeTable(value.map(item => SerializeKVPair(item))); } - getOwnerLockHash() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + class BlockInfo { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getLayer2Lock() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getBlockProducerId() { + return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); + } - getCancelTimeout() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + getNumber() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint64.size()), { validate: false }); + } -export function SerializeDepositLockArgs(value) { - const buffers = []; - buffers.push(SerializeByte32(value.owner_lock_hash)); - buffers.push(SerializeScript(value.layer2_lock)); - buffers.push(SerializeUint64(value.cancel_timeout)); - return serializeTable(buffers); -} + getTimestamp() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint64.size(), 0 + Uint32.size() + Uint64.size() + Uint64.size()), { validate: false }); + } -export class CustodianLockArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + assertDataLength(this.view.byteLength, BlockInfo.size()); + this.getBlockProducerId().validate(compatible); + this.getNumber().validate(compatible); + this.getTimestamp().validate(compatible); + } + static size() { + return 0 + Uint32.size() + Uint64.size() + Uint64.size(); } } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new DepositLockArgs(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Uint64(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + function SerializeBlockInfo(value) { + const array = new Uint8Array(0 + Uint32.size() + Uint64.size() + Uint64.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeUint32(value.block_producer_id)), 0); + array.set(new Uint8Array(SerializeUint64(value.number)), 0 + Uint32.size()); + array.set(new Uint8Array(SerializeUint64(value.timestamp)), 0 + Uint32.size() + Uint64.size()); + return array.buffer; } - getDepositLockArgs() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new DepositLockArgs(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + class DepositLockArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getDepositBlockHash() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Script(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Uint64(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + } - getDepositBlockNumber() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + getOwnerLockHash() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export function SerializeCustodianLockArgs(value) { - const buffers = []; - buffers.push(SerializeDepositLockArgs(value.deposit_lock_args)); - buffers.push(SerializeByte32(value.deposit_block_hash)); - buffers.push(SerializeUint64(value.deposit_block_number)); - return serializeTable(buffers); -} + getLayer2Lock() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export class UnlockCustodianViaRevertWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getCancelTimeout() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); } } - getDepositLockHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + function SerializeDepositLockArgs(value) { + const buffers = []; + buffers.push(SerializeByte32(value.owner_lock_hash)); + buffers.push(SerializeScript(value.layer2_lock)); + buffers.push(SerializeUint64(value.cancel_timeout)); + return serializeTable(buffers); } - validate(compatible = false) { - assertDataLength(this.view.byteLength, UnlockCustodianViaRevertWitness.size()); - this.getDepositLockHash().validate(compatible); - } - static size() { - return 0 + Byte32.size(); - } -} + class CustodianLockArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeUnlockCustodianViaRevertWitness(value) { - const array = new Uint8Array(0 + Byte32.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeByte32(value.deposit_lock_hash)), 0); - return array.buffer; -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new DepositLockArgs(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Uint64(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + } -export class WithdrawalLockArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getDepositLockArgs() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new DepositLockArgs(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - getAccountScriptHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } + getDepositBlockHash() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getWithdrawalBlockHash() { - return new Byte32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Byte32.size()), { validate: false }); + getDepositBlockNumber() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getWithdrawalBlockNumber() { - return new Uint64(this.view.buffer.slice(0 + Byte32.size() + Byte32.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size()), { validate: false }); + function SerializeCustodianLockArgs(value) { + const buffers = []; + buffers.push(SerializeDepositLockArgs(value.deposit_lock_args)); + buffers.push(SerializeByte32(value.deposit_block_hash)); + buffers.push(SerializeUint64(value.deposit_block_number)); + return serializeTable(buffers); } - getSudtScriptHash() { - return new Byte32(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size()), { validate: false }); - } + class UnlockCustodianViaRevertWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getSellAmount() { - return new Uint128(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size()), { validate: false }); - } + getDepositLockHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + } - getSellCapacity() { - return new Uint64(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size()), { validate: false }); + validate(compatible = false) { + assertDataLength(this.view.byteLength, UnlockCustodianViaRevertWitness.size()); + this.getDepositLockHash().validate(compatible); + } + static size() { + return 0 + Byte32.size(); + } } - getOwnerLockHash() { - return new Byte32(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()), { validate: false }); + function SerializeUnlockCustodianViaRevertWitness(value) { + const array = new Uint8Array(0 + Byte32.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.deposit_lock_hash)), 0); + return array.buffer; } - getPaymentLockHash() { - return new Byte32(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()), { validate: false }); - } + class WithdrawalLockArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, WithdrawalLockArgs.size()); - this.getAccountScriptHash().validate(compatible); - this.getWithdrawalBlockHash().validate(compatible); - this.getWithdrawalBlockNumber().validate(compatible); - this.getSudtScriptHash().validate(compatible); - this.getSellAmount().validate(compatible); - this.getSellCapacity().validate(compatible); - this.getOwnerLockHash().validate(compatible); - this.getPaymentLockHash().validate(compatible); - } - static size() { - return 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size(); - } -} + getAccountScriptHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + } -export function SerializeWithdrawalLockArgs(value) { - const array = new Uint8Array(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeByte32(value.account_script_hash)), 0); - array.set(new Uint8Array(SerializeByte32(value.withdrawal_block_hash)), 0 + Byte32.size()); - array.set(new Uint8Array(SerializeUint64(value.withdrawal_block_number)), 0 + Byte32.size() + Byte32.size()); - array.set(new Uint8Array(SerializeByte32(value.sudt_script_hash)), 0 + Byte32.size() + Byte32.size() + Uint64.size()); - array.set(new Uint8Array(SerializeUint128(value.sell_amount)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size()); - array.set(new Uint8Array(SerializeUint64(value.sell_capacity)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size()); - array.set(new Uint8Array(SerializeByte32(value.owner_lock_hash)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size()); - array.set(new Uint8Array(SerializeByte32(value.payment_lock_hash)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()); - return array.buffer; -} + getWithdrawalBlockHash() { + return new Byte32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Byte32.size()), { validate: false }); + } -export class UnlockWithdrawalWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getWithdrawalBlockNumber() { + return new Uint64(this.view.buffer.slice(0 + Byte32.size() + Byte32.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size()), { validate: false }); } - } - validate(compatible = false) { - if (this.view.byteLength < 4) { - assertDataLength(this.view.byteLength, ">4"); + getSudtScriptHash() { + return new Byte32(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size()), { validate: false }); } - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - new UnlockWithdrawalViaFinalize(this.view.buffer.slice(4), { validate: false }).validate(); - break; - case 1: - new UnlockWithdrawalViaRevert(this.view.buffer.slice(4), { validate: false }).validate(); - break; - case 2: - new UnlockWithdrawalViaTrade(this.view.buffer.slice(4), { validate: false }).validate(); - break; - default: - throw new Error(`Invalid type: ${t}`); + + getSellAmount() { + return new Uint128(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size()), { validate: false }); } - } - unionType() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return "UnlockWithdrawalViaFinalize"; - case 1: - return "UnlockWithdrawalViaRevert"; - case 2: - return "UnlockWithdrawalViaTrade"; - default: - throw new Error(`Invalid type: ${t}`); + getSellCapacity() { + return new Uint64(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size()), { validate: false }); } - } - value() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return new UnlockWithdrawalViaFinalize(this.view.buffer.slice(4), { validate: false }); - case 1: - return new UnlockWithdrawalViaRevert(this.view.buffer.slice(4), { validate: false }); - case 2: - return new UnlockWithdrawalViaTrade(this.view.buffer.slice(4), { validate: false }); - default: - throw new Error(`Invalid type: ${t}`); + getOwnerLockHash() { + return new Byte32(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()), { validate: false }); } - } -} -export function SerializeUnlockWithdrawalWitness(value) { - switch (value.type) { - case "UnlockWithdrawalViaFinalize": - { - const itemBuffer = SerializeUnlockWithdrawalViaFinalize(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 0, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; + getPaymentLockHash() { + return new Byte32(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()), { validate: false }); } - case "UnlockWithdrawalViaRevert": - { - const itemBuffer = SerializeUnlockWithdrawalViaRevert(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 1, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; + + validate(compatible = false) { + assertDataLength(this.view.byteLength, WithdrawalLockArgs.size()); + this.getAccountScriptHash().validate(compatible); + this.getWithdrawalBlockHash().validate(compatible); + this.getWithdrawalBlockNumber().validate(compatible); + this.getSudtScriptHash().validate(compatible); + this.getSellAmount().validate(compatible); + this.getSellCapacity().validate(compatible); + this.getOwnerLockHash().validate(compatible); + this.getPaymentLockHash().validate(compatible); } - case "UnlockWithdrawalViaTrade": - { - const itemBuffer = SerializeUnlockWithdrawalViaTrade(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 2, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; + static size() { + return 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size(); } - default: - throw new Error(`Invalid type: ${value.type}`); } - -} - -export class UnlockWithdrawalViaFinalize { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + + function SerializeWithdrawalLockArgs(value) { + const array = new Uint8Array(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.account_script_hash)), 0); + array.set(new Uint8Array(SerializeByte32(value.withdrawal_block_hash)), 0 + Byte32.size()); + array.set(new Uint8Array(SerializeUint64(value.withdrawal_block_number)), 0 + Byte32.size() + Byte32.size()); + array.set(new Uint8Array(SerializeByte32(value.sudt_script_hash)), 0 + Byte32.size() + Byte32.size() + Uint64.size()); + array.set(new Uint8Array(SerializeUint128(value.sell_amount)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size()); + array.set(new Uint8Array(SerializeUint64(value.sell_capacity)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size()); + array.set(new Uint8Array(SerializeByte32(value.owner_lock_hash)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size()); + array.set(new Uint8Array(SerializeByte32(value.payment_lock_hash)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()); + return array.buffer; + } + + class UnlockWithdrawalWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } + + validate(compatible = false) { + if (this.view.byteLength < 4) { + assertDataLength(this.view.byteLength, ">4"); + } + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + new UnlockWithdrawalViaFinalize(this.view.buffer.slice(4), { validate: false }).validate(); + break; + case 1: + new UnlockWithdrawalViaRevert(this.view.buffer.slice(4), { validate: false }).validate(); + break; + case 2: + new UnlockWithdrawalViaTrade(this.view.buffer.slice(4), { validate: false }).validate(); + break; + default: + throw new Error(`Invalid type: ${t}`); + } + } + + unionType() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return "UnlockWithdrawalViaFinalize"; + case 1: + return "UnlockWithdrawalViaRevert"; + case 2: + return "UnlockWithdrawalViaTrade"; + default: + throw new Error(`Invalid type: ${t}`); + } + } + + value() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return new UnlockWithdrawalViaFinalize(this.view.buffer.slice(4), { validate: false }); + case 1: + return new UnlockWithdrawalViaRevert(this.view.buffer.slice(4), { validate: false }); + case 2: + return new UnlockWithdrawalViaTrade(this.view.buffer.slice(4), { validate: false }); + default: + throw new Error(`Invalid type: ${t}`); + } + } + } + + function SerializeUnlockWithdrawalWitness(value) { + switch (value.type) { + case "UnlockWithdrawalViaFinalize": + { + const itemBuffer = SerializeUnlockWithdrawalViaFinalize(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 0, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; + } + case "UnlockWithdrawalViaRevert": + { + const itemBuffer = SerializeUnlockWithdrawalViaRevert(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 1, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; + } + case "UnlockWithdrawalViaTrade": + { + const itemBuffer = SerializeUnlockWithdrawalViaTrade(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 2, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; + } + default: + throw new Error(`Invalid type: ${value.type}`); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); } -} - -export function SerializeUnlockWithdrawalViaFinalize(value) { - const buffers = []; - return serializeTable(buffers); -} + class UnlockWithdrawalViaFinalize { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class UnlockWithdrawalViaRevert { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + verifyAndExtractOffsets(this.view, 0, true); } - } - getCustodianLockHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); } - validate(compatible = false) { - assertDataLength(this.view.byteLength, UnlockWithdrawalViaRevert.size()); - this.getCustodianLockHash().validate(compatible); + function SerializeUnlockWithdrawalViaFinalize(value) { + const buffers = []; + return serializeTable(buffers); } - static size() { - return 0 + Byte32.size(); - } -} -export function SerializeUnlockWithdrawalViaRevert(value) { - const array = new Uint8Array(0 + Byte32.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeByte32(value.custodian_lock_hash)), 0); - return array.buffer; -} + class UnlockWithdrawalViaRevert { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class UnlockWithdrawalViaTrade { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getCustodianLockHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Script(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + validate(compatible = false) { + assertDataLength(this.view.byteLength, UnlockWithdrawalViaRevert.size()); + this.getCustodianLockHash().validate(compatible); + } + static size() { + return 0 + Byte32.size(); + } } - getOwnerLock() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeUnlockWithdrawalViaRevert(value) { + const array = new Uint8Array(0 + Byte32.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.custodian_lock_hash)), 0); + return array.buffer; } -} -export function SerializeUnlockWithdrawalViaTrade(value) { - const buffers = []; - buffers.push(SerializeScript(value.owner_lock)); - return serializeTable(buffers); -} + class UnlockWithdrawalViaTrade { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class StakeLockArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Script(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); } - } - getOwnerLockHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + getOwnerLock() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getStakeBlockNumber() { - return new Uint64(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint64.size()), { validate: false }); + function SerializeUnlockWithdrawalViaTrade(value) { + const buffers = []; + buffers.push(SerializeScript(value.owner_lock)); + return serializeTable(buffers); } - validate(compatible = false) { - assertDataLength(this.view.byteLength, StakeLockArgs.size()); - this.getOwnerLockHash().validate(compatible); - this.getStakeBlockNumber().validate(compatible); - } - static size() { - return 0 + Byte32.size() + Uint64.size(); - } -} + class StakeLockArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeStakeLockArgs(value) { - const array = new Uint8Array(0 + Byte32.size() + Uint64.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeByte32(value.owner_lock_hash)), 0); - array.set(new Uint8Array(SerializeUint64(value.stake_block_number)), 0 + Byte32.size()); - return array.buffer; -} + getOwnerLockHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + } -export class MetaContractArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getStakeBlockNumber() { + return new Uint64(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint64.size()), { validate: false }); } - } - validate(compatible = false) { - if (this.view.byteLength < 4) { - assertDataLength(this.view.byteLength, ">4"); + validate(compatible = false) { + assertDataLength(this.view.byteLength, StakeLockArgs.size()); + this.getOwnerLockHash().validate(compatible); + this.getStakeBlockNumber().validate(compatible); } - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - new CreateAccount(this.view.buffer.slice(4), { validate: false }).validate(); - break; - default: - throw new Error(`Invalid type: ${t}`); + static size() { + return 0 + Byte32.size() + Uint64.size(); } } - unionType() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return "CreateAccount"; - default: - throw new Error(`Invalid type: ${t}`); - } + function SerializeStakeLockArgs(value) { + const array = new Uint8Array(0 + Byte32.size() + Uint64.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.owner_lock_hash)), 0); + array.set(new Uint8Array(SerializeUint64(value.stake_block_number)), 0 + Byte32.size()); + return array.buffer; } - value() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return new CreateAccount(this.view.buffer.slice(4), { validate: false }); - default: - throw new Error(`Invalid type: ${t}`); + class MetaContractArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } -} -export function SerializeMetaContractArgs(value) { - switch (value.type) { - case "CreateAccount": - { - const itemBuffer = SerializeCreateAccount(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 0, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; + validate(compatible = false) { + if (this.view.byteLength < 4) { + assertDataLength(this.view.byteLength, ">4"); + } + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + new CreateAccount(this.view.buffer.slice(4), { validate: false }).validate(); + break; + default: + throw new Error(`Invalid type: ${t}`); + } } - default: - throw new Error(`Invalid type: ${value.type}`); - } - -} -export class CreateAccount { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + unionType() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return "CreateAccount"; + default: + throw new Error(`Invalid type: ${t}`); + } } - } - - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Script(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - } - - getScript() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} - -export function SerializeCreateAccount(value) { - const buffers = []; - buffers.push(SerializeScript(value.script)); - return serializeTable(buffers); -} -export class SUDTArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + value() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return new CreateAccount(this.view.buffer.slice(4), { validate: false }); + default: + throw new Error(`Invalid type: ${t}`); + } } } - validate(compatible = false) { - if (this.view.byteLength < 4) { - assertDataLength(this.view.byteLength, ">4"); - } - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - new SUDTQuery(this.view.buffer.slice(4), { validate: false }).validate(); - break; - case 1: - new SUDTTransfer(this.view.buffer.slice(4), { validate: false }).validate(); - break; + function SerializeMetaContractArgs(value) { + switch (value.type) { + case "CreateAccount": + { + const itemBuffer = SerializeCreateAccount(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 0, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; + } default: - throw new Error(`Invalid type: ${t}`); + throw new Error(`Invalid type: ${value.type}`); } - } - unionType() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return "SUDTQuery"; - case 1: - return "SUDTTransfer"; - default: - throw new Error(`Invalid type: ${t}`); - } } - value() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return new SUDTQuery(this.view.buffer.slice(4), { validate: false }); - case 1: - return new SUDTTransfer(this.view.buffer.slice(4), { validate: false }); - default: - throw new Error(`Invalid type: ${t}`); + class Fee { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } -} -export function SerializeSUDTArgs(value) { - switch (value.type) { - case "SUDTQuery": - { - const itemBuffer = SerializeSUDTQuery(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 0, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } - case "SUDTTransfer": - { - const itemBuffer = SerializeSUDTTransfer(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 1, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; + getSudtId() { + return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); } - default: - throw new Error(`Invalid type: ${value.type}`); - } - -} -export class SUDTQuery { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getAmount() { + return new Uint128(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint128.size()), { validate: false }); } - } - getAccountId() { - return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); + validate(compatible = false) { + assertDataLength(this.view.byteLength, Fee.size()); + this.getSudtId().validate(compatible); + this.getAmount().validate(compatible); + } + static size() { + return 0 + Uint32.size() + Uint128.size(); + } } - validate(compatible = false) { - assertDataLength(this.view.byteLength, SUDTQuery.size()); - this.getAccountId().validate(compatible); - } - static size() { - return 0 + Uint32.size(); + function SerializeFee(value) { + const array = new Uint8Array(0 + Uint32.size() + Uint128.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeUint32(value.sudt_id)), 0); + array.set(new Uint8Array(SerializeUint128(value.amount)), 0 + Uint32.size()); + return array.buffer; } -} -export function SerializeSUDTQuery(value) { - const array = new Uint8Array(0 + Uint32.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeUint32(value.account_id)), 0); - return array.buffer; -} - -export class SUDTTransfer { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class CreateAccount { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - getTo() { - return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Script(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Fee(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + } - getAmount() { - return new Uint128(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint128.size()), { validate: false }); - } + getScript() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getFee() { - return new Uint128(this.view.buffer.slice(0 + Uint32.size() + Uint128.size(), 0 + Uint32.size() + Uint128.size() + Uint128.size()), { validate: false }); + getFee() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Fee(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - validate(compatible = false) { - assertDataLength(this.view.byteLength, SUDTTransfer.size()); - this.getTo().validate(compatible); - this.getAmount().validate(compatible); - this.getFee().validate(compatible); + function SerializeCreateAccount(value) { + const buffers = []; + buffers.push(SerializeScript(value.script)); + buffers.push(SerializeFee(value.fee)); + return serializeTable(buffers); } - static size() { - return 0 + Uint32.size() + Uint128.size() + Uint128.size(); - } -} - -export function SerializeSUDTTransfer(value) { - const array = new Uint8Array(0 + Uint32.size() + Uint128.size() + Uint128.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeUint32(value.to)), 0); - array.set(new Uint8Array(SerializeUint128(value.amount)), 0 + Uint32.size()); - array.set(new Uint8Array(SerializeUint128(value.fee)), 0 + Uint32.size() + Uint128.size()); - return array.buffer; -} -export class ChallengeTarget { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class SUDTArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - getBlockHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } - - getTargetIndex() { - return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); - } + validate(compatible = false) { + if (this.view.byteLength < 4) { + assertDataLength(this.view.byteLength, ">4"); + } + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + new SUDTQuery(this.view.buffer.slice(4), { validate: false }).validate(); + break; + case 1: + new SUDTTransfer(this.view.buffer.slice(4), { validate: false }).validate(); + break; + default: + throw new Error(`Invalid type: ${t}`); + } + } - getTargetType() { - return this.view.getUint8(0 + Byte32.size() + Uint32.size()); - } + unionType() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return "SUDTQuery"; + case 1: + return "SUDTTransfer"; + default: + throw new Error(`Invalid type: ${t}`); + } + } + + value() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return new SUDTQuery(this.view.buffer.slice(4), { validate: false }); + case 1: + return new SUDTTransfer(this.view.buffer.slice(4), { validate: false }); + default: + throw new Error(`Invalid type: ${t}`); + } + } + } + + function SerializeSUDTArgs(value) { + switch (value.type) { + case "SUDTQuery": + { + const itemBuffer = SerializeSUDTQuery(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 0, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; + } + case "SUDTTransfer": + { + const itemBuffer = SerializeSUDTTransfer(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 1, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; + } + default: + throw new Error(`Invalid type: ${value.type}`); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, ChallengeTarget.size()); - this.getBlockHash().validate(compatible); - this.getTargetIndex().validate(compatible); - } - static size() { - return 0 + Byte32.size() + Uint32.size() + 1; } -} -export function SerializeChallengeTarget(value) { - const array = new Uint8Array(0 + Byte32.size() + Uint32.size() + 1); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeByte32(value.block_hash)), 0); - array.set(new Uint8Array(SerializeUint32(value.target_index)), 0 + Byte32.size()); - view.setUint8(0 + Byte32.size() + Uint32.size(), value.target_type); - return array.buffer; -} + class SUDTQuery { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class ChallengeLockArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Bytes(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new ChallengeTarget(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Script(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + getShortAddress() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getTarget() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new ChallengeTarget(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeSUDTQuery(value) { + const buffers = []; + buffers.push(SerializeBytes(value.short_address)); + return serializeTable(buffers); } - getRewardsReceiverLock() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + class SUDTTransfer { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeChallengeLockArgs(value) { - const buffers = []; - buffers.push(SerializeChallengeTarget(value.target)); - buffers.push(SerializeScript(value.rewards_receiver_lock)); - return serializeTable(buffers); -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Bytes(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Uint128(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Uint128(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + } -export class ChallengeWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getTo() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - } + getAmount() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint128(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getRawL2Block() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); + getFee() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Uint128(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getBlockProof() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeSUDTTransfer(value) { + const buffers = []; + buffers.push(SerializeBytes(value.to)); + buffers.push(SerializeUint128(value.amount)); + buffers.push(SerializeUint128(value.fee)); + return serializeTable(buffers); } -} - -export function SerializeChallengeWitness(value) { - const buffers = []; - buffers.push(SerializeRawL2Block(value.raw_l2block)); - buffers.push(SerializeBytes(value.block_proof)); - return serializeTable(buffers); -} -export class ScriptVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class ChallengeTarget { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new Script(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + getBlockHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); } - } - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; + getTargetIndex() { + return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); } - } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); + getTargetType() { + return this.view.getUint8(0 + Byte32.size() + Uint32.size()); } - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} -export function SerializeScriptVec(value) { - return serializeTable(value.map(item => SerializeScript(item))); -} - -export class BlockHashEntry { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + assertDataLength(this.view.byteLength, ChallengeTarget.size()); + this.getBlockHash().validate(compatible); + this.getTargetIndex().validate(compatible); + } + static size() { + return 0 + Byte32.size() + Uint32.size() + 1; } } - getNumber() { - return new Uint64(this.view.buffer.slice(0, 0 + Uint64.size()), { validate: false }); - } - - getHash() { - return new Byte32(this.view.buffer.slice(0 + Uint64.size(), 0 + Uint64.size() + Byte32.size()), { validate: false }); - } - - validate(compatible = false) { - assertDataLength(this.view.byteLength, BlockHashEntry.size()); - this.getNumber().validate(compatible); - this.getHash().validate(compatible); - } - static size() { - return 0 + Uint64.size() + Byte32.size(); + function SerializeChallengeTarget(value) { + const array = new Uint8Array(0 + Byte32.size() + Uint32.size() + 1); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.block_hash)), 0); + array.set(new Uint8Array(SerializeUint32(value.target_index)), 0 + Byte32.size()); + view.setUint8(0 + Byte32.size() + Uint32.size(), value.target_type); + return array.buffer; } -} -export function SerializeBlockHashEntry(value) { - const array = new Uint8Array(0 + Uint64.size() + Byte32.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeUint64(value.number)), 0); - array.set(new Uint8Array(SerializeByte32(value.hash)), 0 + Uint64.size()); - return array.buffer; -} - -export class BlockHashEntryVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class ChallengeLockArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4"); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new ChallengeTarget(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Script(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); } - const requiredByteLength = this.length() * BlockHashEntry.size() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); - for (let i = 0; i < 0; i++) { - const item = this.indexAt(i); - item.validate(compatible); - } - } - indexAt(i) { - return new BlockHashEntry(this.view.buffer.slice(4 + i * BlockHashEntry.size(), 4 + (i + 1) * BlockHashEntry.size()), { validate: false }); - } + getTarget() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new ChallengeTarget(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - length() { - return this.view.getUint32(0, true); + getRewardsReceiverLock() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } -} -export function SerializeBlockHashEntryVec(value) { - const array = new Uint8Array(4 + BlockHashEntry.size() * value.length); - (new DataView(array.buffer)).setUint32(0, value.length, true); - for (let i = 0; i < value.length; i++) { - const itemBuffer = SerializeBlockHashEntry(value[i]); - array.set(new Uint8Array(itemBuffer), 4 + i * BlockHashEntry.size()); + function SerializeChallengeLockArgs(value) { + const buffers = []; + buffers.push(SerializeChallengeTarget(value.target)); + buffers.push(SerializeScript(value.rewards_receiver_lock)); + return serializeTable(buffers); } - return array.buffer; -} -export class VerifyTransactionContext { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class ChallengeWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new KVPairVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new ScriptVec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new BlockHashEntryVec(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + } - getAccountCount() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getRawL2Block() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getKvState() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new KVPairVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + getBlockProof() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getScripts() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new ScriptVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeChallengeWitness(value) { + const buffers = []; + buffers.push(SerializeRawL2Block(value.raw_l2block)); + buffers.push(SerializeBytes(value.block_proof)); + return serializeTable(buffers); } - getReturnDataHash() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + class ScriptVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getBlockHashes() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new BlockHashEntryVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new Script(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + } + } -export function SerializeVerifyTransactionContext(value) { - const buffers = []; - buffers.push(SerializeUint32(value.account_count)); - buffers.push(SerializeKVPairVec(value.kv_state)); - buffers.push(SerializeScriptVec(value.scripts)); - buffers.push(SerializeByte32(value.return_data_hash)); - buffers.push(SerializeBlockHashEntryVec(value.block_hashes)); - return serializeTable(buffers); -} + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; + } + } -export class VerifyTransactionWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); + } + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); } } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new L2Transaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new RawL2Block(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - new VerifyTransactionContext(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); + function SerializeScriptVec(value) { + return serializeTable(value.map(item => SerializeScript(item))); } - getL2Tx() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new L2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + class BlockHashEntry { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getRawL2Block() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getNumber() { + return new Uint64(this.view.buffer.slice(0, 0 + Uint64.size()), { validate: false }); + } - getTxProof() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getHash() { + return new Byte32(this.view.buffer.slice(0 + Uint64.size(), 0 + Uint64.size() + Byte32.size()), { validate: false }); + } - getKvStateProof() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + validate(compatible = false) { + assertDataLength(this.view.byteLength, BlockHashEntry.size()); + this.getNumber().validate(compatible); + this.getHash().validate(compatible); + } + static size() { + return 0 + Uint64.size() + Byte32.size(); + } } - getBlockHashesProof() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeBlockHashEntry(value) { + const array = new Uint8Array(0 + Uint64.size() + Byte32.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeUint64(value.number)), 0); + array.set(new Uint8Array(SerializeByte32(value.hash)), 0 + Uint64.size()); + return array.buffer; } - getContext() { - const start = 24; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new VerifyTransactionContext(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + class BlockHashEntryVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeVerifyTransactionWitness(value) { - const buffers = []; - buffers.push(SerializeL2Transaction(value.l2tx)); - buffers.push(SerializeRawL2Block(value.raw_l2block)); - buffers.push(SerializeBytes(value.tx_proof)); - buffers.push(SerializeBytes(value.kv_state_proof)); - buffers.push(SerializeBytes(value.block_hashes_proof)); - buffers.push(SerializeVerifyTransactionContext(value.context)); - return serializeTable(buffers); -} + validate(compatible = false) { + if (this.view.byteLength < 4) { + dataLengthError(this.view.byteLength, ">4"); + } + const requiredByteLength = this.length() * BlockHashEntry.size() + 4; + assertDataLength(this.view.byteLength, requiredByteLength); + for (let i = 0; i < 0; i++) { + const item = this.indexAt(i); + item.validate(compatible); + } + } -export class VerifySignatureContext { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + indexAt(i) { + return new BlockHashEntry(this.view.buffer.slice(4 + i * BlockHashEntry.size(), 4 + (i + 1) * BlockHashEntry.size()), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new KVPairVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new ScriptVec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + length() { + return this.view.getUint32(0, true); + } } - getAccountCount() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getKvState() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new KVPairVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeBlockHashEntryVec(value) { + const array = new Uint8Array(4 + BlockHashEntry.size() * value.length); + (new DataView(array.buffer)).setUint32(0, value.length, true); + for (let i = 0; i < value.length; i++) { + const itemBuffer = SerializeBlockHashEntry(value[i]); + array.set(new Uint8Array(itemBuffer), 4 + i * BlockHashEntry.size()); + } + return array.buffer; } - getScripts() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new ScriptVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + class VerifyTransactionContext { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeVerifySignatureContext(value) { - const buffers = []; - buffers.push(SerializeUint32(value.account_count)); - buffers.push(SerializeKVPairVec(value.kv_state)); - buffers.push(SerializeScriptVec(value.scripts)); - return serializeTable(buffers); -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new KVPairVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new ScriptVec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new BlockHashEntryVec(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); + } -export class VerifyTransactionSignatureWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getAccountCount() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new L2Transaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new RawL2Block(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - new VerifySignatureContext(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); - } + getKvState() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new KVPairVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getL2Tx() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new L2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getScripts() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new ScriptVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getRawL2Block() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getReturnDataHash() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getTxProof() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getKvStateProof() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + getBlockHashes() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new BlockHashEntryVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getBlockHashesProof() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeVerifyTransactionContext(value) { + const buffers = []; + buffers.push(SerializeUint32(value.account_count)); + buffers.push(SerializeKVPairVec(value.kv_state)); + buffers.push(SerializeScriptVec(value.scripts)); + buffers.push(SerializeByte32(value.return_data_hash)); + buffers.push(SerializeBlockHashEntryVec(value.block_hashes)); + return serializeTable(buffers); } - getContext() { - const start = 24; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new VerifySignatureContext(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + class VerifyTransactionWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeVerifyTransactionSignatureWitness(value) { - const buffers = []; - buffers.push(SerializeL2Transaction(value.l2tx)); - buffers.push(SerializeRawL2Block(value.raw_l2block)); - buffers.push(SerializeBytes(value.tx_proof)); - buffers.push(SerializeBytes(value.kv_state_proof)); - buffers.push(SerializeBytes(value.block_hashes_proof)); - buffers.push(SerializeVerifySignatureContext(value.context)); - return serializeTable(buffers); -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new L2Transaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new RawL2Block(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); + new VerifyTransactionContext(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); + } -export class VerifyWithdrawalWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getL2Tx() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new L2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new WithdrawalRequest(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new VerifySignatureContext(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - } + getRawL2Block() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getRawL2Block() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getTxProof() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getKvStateProof() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getKvStateProof() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getWithdrawalRequest() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new WithdrawalRequest(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getBlockHashesProof() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getWithdrawalProof() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + getContext() { + const start = 24; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new VerifyTransactionContext(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getContext() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new VerifySignatureContext(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeVerifyTransactionWitness(value) { + const buffers = []; + buffers.push(SerializeL2Transaction(value.l2tx)); + buffers.push(SerializeRawL2Block(value.raw_l2block)); + buffers.push(SerializeBytes(value.tx_proof)); + buffers.push(SerializeBytes(value.kv_state_proof)); + buffers.push(SerializeBytes(value.block_hashes_proof)); + buffers.push(SerializeVerifyTransactionContext(value.context)); + return serializeTable(buffers); } -} -export function SerializeVerifyWithdrawalWitness(value) { - const buffers = []; - buffers.push(SerializeRawL2Block(value.raw_l2block)); - buffers.push(SerializeBytes(value.kv_state_proof)); - buffers.push(SerializeWithdrawalRequest(value.withdrawal_request)); - buffers.push(SerializeBytes(value.withdrawal_proof)); - buffers.push(SerializeVerifySignatureContext(value.context)); - return serializeTable(buffers); -} + class VerifyTransactionSignatureContext { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class RollupSubmitBlock { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new KVPairVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new ScriptVec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new L2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Byte32Vec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - } + getAccountCount() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getBlock() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new L2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getKvState() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new KVPairVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getRevertedBlockHashes() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); + getScripts() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new ScriptVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getRevertedBlockProof() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeVerifyTransactionSignatureContext(value) { + const buffers = []; + buffers.push(SerializeUint32(value.account_count)); + buffers.push(SerializeKVPairVec(value.kv_state)); + buffers.push(SerializeScriptVec(value.scripts)); + return serializeTable(buffers); } -} -export function SerializeRollupSubmitBlock(value) { - const buffers = []; - buffers.push(SerializeL2Block(value.block)); - buffers.push(SerializeByte32Vec(value.reverted_block_hashes)); - buffers.push(SerializeBytes(value.reverted_block_proof)); - return serializeTable(buffers); -} + class VerifyTransactionSignatureWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } + + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new L2Transaction(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new VerifyTransactionSignatureContext(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); + } -export class RollupEnterChallenge { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getRawL2Block() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new ChallengeWitness(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - } + getL2Tx() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new L2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getWitness() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new ChallengeWitness(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + getTxProof() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export function SerializeRollupEnterChallenge(value) { - const buffers = []; - buffers.push(SerializeChallengeWitness(value.witness)); - return serializeTable(buffers); -} + getKvStateProof() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export class RollupCancelChallenge { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getContext() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new VerifyTransactionSignatureContext(this.view.buffer.slice(offset, offset_end), { validate: false }); } } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); + function SerializeVerifyTransactionSignatureWitness(value) { + const buffers = []; + buffers.push(SerializeRawL2Block(value.raw_l2block)); + buffers.push(SerializeL2Transaction(value.l2tx)); + buffers.push(SerializeBytes(value.tx_proof)); + buffers.push(SerializeBytes(value.kv_state_proof)); + buffers.push(SerializeVerifyTransactionSignatureContext(value.context)); + return serializeTable(buffers); } -} - -export function SerializeRollupCancelChallenge(value) { - const buffers = []; - return serializeTable(buffers); -} + class VerifyWithdrawalWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class RollupRevert { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new WithdrawalRequest(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new RawL2BlockVec(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - } + getRawL2Block() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getRevertedBlocks() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2BlockVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getWithdrawalRequest() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new WithdrawalRequest(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getBlockProof() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + getWithdrawalProof() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getRevertedBlockProof() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeVerifyWithdrawalWitness(value) { + const buffers = []; + buffers.push(SerializeRawL2Block(value.raw_l2block)); + buffers.push(SerializeWithdrawalRequest(value.withdrawal_request)); + buffers.push(SerializeBytes(value.withdrawal_proof)); + return serializeTable(buffers); } -} -export function SerializeRollupRevert(value) { - const buffers = []; - buffers.push(SerializeRawL2BlockVec(value.reverted_blocks)); - buffers.push(SerializeBytes(value.block_proof)); - buffers.push(SerializeBytes(value.reverted_block_proof)); - return serializeTable(buffers); -} + class RollupSubmitBlock { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class RollupAction { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new L2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Byte32Vec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); } - } - validate(compatible = false) { - if (this.view.byteLength < 4) { - assertDataLength(this.view.byteLength, ">4"); + getBlock() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new L2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); } - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - new RollupSubmitBlock(this.view.buffer.slice(4), { validate: false }).validate(); - break; - case 1: - new RollupEnterChallenge(this.view.buffer.slice(4), { validate: false }).validate(); - break; - case 2: - new RollupCancelChallenge(this.view.buffer.slice(4), { validate: false }).validate(); - break; - case 3: - new RollupRevert(this.view.buffer.slice(4), { validate: false }).validate(); - break; - default: - throw new Error(`Invalid type: ${t}`); + + getRevertedBlockHashes() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - unionType() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return "RollupSubmitBlock"; - case 1: - return "RollupEnterChallenge"; - case 2: - return "RollupCancelChallenge"; - case 3: - return "RollupRevert"; - default: - throw new Error(`Invalid type: ${t}`); + getRevertedBlockProof() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); } } - value() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return new RollupSubmitBlock(this.view.buffer.slice(4), { validate: false }); - case 1: - return new RollupEnterChallenge(this.view.buffer.slice(4), { validate: false }); - case 2: - return new RollupCancelChallenge(this.view.buffer.slice(4), { validate: false }); - case 3: - return new RollupRevert(this.view.buffer.slice(4), { validate: false }); - default: - throw new Error(`Invalid type: ${t}`); - } + function SerializeRollupSubmitBlock(value) { + const buffers = []; + buffers.push(SerializeL2Block(value.block)); + buffers.push(SerializeByte32Vec(value.reverted_block_hashes)); + buffers.push(SerializeBytes(value.reverted_block_proof)); + return serializeTable(buffers); } -} -export function SerializeRollupAction(value) { - switch (value.type) { - case "RollupSubmitBlock": - { - const itemBuffer = SerializeRollupSubmitBlock(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 0, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } - case "RollupEnterChallenge": - { - const itemBuffer = SerializeRollupEnterChallenge(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 1, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } - case "RollupCancelChallenge": - { - const itemBuffer = SerializeRollupCancelChallenge(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 2, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; + class RollupEnterChallenge { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - case "RollupRevert": - { - const itemBuffer = SerializeRollupRevert(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 3, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } - default: - throw new Error(`Invalid type: ${value.type}`); - } -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new ChallengeWitness(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + } -export class Uint16 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getWitness() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new ChallengeWitness(this.view.buffer.slice(offset, offset_end), { validate: false }); } } - validate(compatible = false) { - assertDataLength(this.view.byteLength, 2); + function SerializeRollupEnterChallenge(value) { + const buffers = []; + buffers.push(SerializeChallengeWitness(value.witness)); + return serializeTable(buffers); } - indexAt(i) { - return this.view.getUint8(i); - } + class RollupCancelChallenge { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - raw() { - return this.view.buffer; - } + validate(compatible = false) { + verifyAndExtractOffsets(this.view, 0, true); + } - toBigEndianUint16() { - return this.view.getUint16(0, false); } - toLittleEndianUint16() { - return this.view.getUint16(0, true); + function SerializeRollupCancelChallenge(value) { + const buffers = []; + return serializeTable(buffers); } - static size() { - return 2; - } -} + class RollupRevert { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeUint16(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 2); - return buffer; -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawL2BlockVec(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + } -export class Uint32 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getRevertedBlocks() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2BlockVec(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - validate(compatible = false) { - assertDataLength(this.view.byteLength, 4); - } + getBlockProof() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getRevertedBlockProof() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + } + + function SerializeRollupRevert(value) { + const buffers = []; + buffers.push(SerializeRawL2BlockVec(value.reverted_blocks)); + buffers.push(SerializeBytes(value.block_proof)); + buffers.push(SerializeBytes(value.reverted_block_proof)); + return serializeTable(buffers); + } + + class RollupAction { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } + + validate(compatible = false) { + if (this.view.byteLength < 4) { + assertDataLength(this.view.byteLength, ">4"); + } + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + new RollupSubmitBlock(this.view.buffer.slice(4), { validate: false }).validate(); + break; + case 1: + new RollupEnterChallenge(this.view.buffer.slice(4), { validate: false }).validate(); + break; + case 2: + new RollupCancelChallenge(this.view.buffer.slice(4), { validate: false }).validate(); + break; + case 3: + new RollupRevert(this.view.buffer.slice(4), { validate: false }).validate(); + break; + default: + throw new Error(`Invalid type: ${t}`); + } + } + + unionType() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return "RollupSubmitBlock"; + case 1: + return "RollupEnterChallenge"; + case 2: + return "RollupCancelChallenge"; + case 3: + return "RollupRevert"; + default: + throw new Error(`Invalid type: ${t}`); + } + } + + value() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return new RollupSubmitBlock(this.view.buffer.slice(4), { validate: false }); + case 1: + return new RollupEnterChallenge(this.view.buffer.slice(4), { validate: false }); + case 2: + return new RollupCancelChallenge(this.view.buffer.slice(4), { validate: false }); + case 3: + return new RollupRevert(this.view.buffer.slice(4), { validate: false }); + default: + throw new Error(`Invalid type: ${t}`); + } + } + } + + function SerializeRollupAction(value) { + switch (value.type) { + case "RollupSubmitBlock": + { + const itemBuffer = SerializeRollupSubmitBlock(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 0, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; + } + case "RollupEnterChallenge": + { + const itemBuffer = SerializeRollupEnterChallenge(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 1, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; + } + case "RollupCancelChallenge": + { + const itemBuffer = SerializeRollupCancelChallenge(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 2, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; + } + case "RollupRevert": + { + const itemBuffer = SerializeRollupRevert(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 3, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; + } + default: + throw new Error(`Invalid type: ${value.type}`); + } - indexAt(i) { - return this.view.getUint8(i); } - raw() { - return this.view.buffer; - } + class Uint16 { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - toBigEndianUint32() { - return this.view.getUint32(0, false); - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, 2); + } - toLittleEndianUint32() { - return this.view.getUint32(0, true); - } + indexAt(i) { + return this.view.getUint8(i); + } - static size() { - return 4; - } -} + raw() { + return this.view.buffer; + } -export function SerializeUint32(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 4); - return buffer; -} + toBigEndianUint16() { + return this.view.getUint16(0, false); + } -export class Uint64 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + toLittleEndianUint16() { + return this.view.getUint16(0, true); } - } - validate(compatible = false) { - assertDataLength(this.view.byteLength, 8); + static size() { + return 2; + } } - indexAt(i) { - return this.view.getUint8(i); + function SerializeUint16(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 2); + return buffer; } - raw() { - return this.view.buffer; - } + class Uint32 { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - static size() { - return 8; - } -} + validate(compatible = false) { + assertDataLength(this.view.byteLength, 4); + } -export function SerializeUint64(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 8); - return buffer; -} + indexAt(i) { + return this.view.getUint8(i); + } -export class Uint128 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + raw() { + return this.view.buffer; } - } - validate(compatible = false) { - assertDataLength(this.view.byteLength, 16); - } + toBigEndianUint32() { + return this.view.getUint32(0, false); + } - indexAt(i) { - return this.view.getUint8(i); - } + toLittleEndianUint32() { + return this.view.getUint32(0, true); + } - raw() { - return this.view.buffer; + static size() { + return 4; + } } - static size() { - return 16; + function SerializeUint32(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 4); + return buffer; } -} -export function SerializeUint128(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 16); - return buffer; -} - -export class Byte32 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class Uint64 { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - - validate(compatible = false) { - assertDataLength(this.view.byteLength, 32); - } - indexAt(i) { - return this.view.getUint8(i); - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, 8); + } - raw() { - return this.view.buffer; - } + indexAt(i) { + return this.view.getUint8(i); + } - static size() { - return 32; - } -} + raw() { + return this.view.buffer; + } -export function SerializeByte32(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 32); - return buffer; -} + toBigEndianBigUint64() { + return this.view.getBigUint64(0, false); + } -export class Uint256 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + toLittleEndianBigUint64() { + return this.view.getUint64(0, true); } - } - validate(compatible = false) { - assertDataLength(this.view.byteLength, 32); + static size() { + return 8; + } } - indexAt(i) { - return this.view.getUint8(i); + function SerializeUint64(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 8); + return buffer; } - raw() { - return this.view.buffer; - } + class Uint128 { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - static size() { - return 32; - } -} + validate(compatible = false) { + assertDataLength(this.view.byteLength, 16); + } -export function SerializeUint256(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 32); - return buffer; -} + indexAt(i) { + return this.view.getUint8(i); + } -export class Bytes { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + raw() { + return this.view.buffer; } - } - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4") + static size() { + return 16; } - const requiredByteLength = this.length() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); } - raw() { - return this.view.buffer.slice(4); + function SerializeUint128(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 16); + return buffer; } - indexAt(i) { - return this.view.getUint8(4 + i); - } + class Byte32 { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - length() { - return this.view.getUint32(0, true); - } -} + validate(compatible = false) { + assertDataLength(this.view.byteLength, 32); + } -export function SerializeBytes(value) { - const item = assertArrayBuffer(value); - const array = new Uint8Array(4 + item.byteLength); - (new DataView(array.buffer)).setUint32(0, item.byteLength, true); - array.set(new Uint8Array(item), 4); - return array.buffer; -} + indexAt(i) { + return this.view.getUint8(i); + } -export class BytesOpt { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + raw() { + return this.view.buffer; } - } - validate(compatible = false) { - if (this.hasValue()) { - this.value().validate(compatible); + static size() { + return 32; } } - value() { - return new Bytes(this.view.buffer, { validate: false }); + function SerializeByte32(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 32); + return buffer; } - hasValue() { - return this.view.byteLength > 0; - } -} + class Uint256 { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeBytesOpt(value) { - if (value) { - return SerializeBytes(value); - } else { - return new ArrayBuffer(0); - } -} + validate(compatible = false) { + assertDataLength(this.view.byteLength, 32); + } -export class BytesVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + indexAt(i) { + return this.view.getUint8(i); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new Bytes(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + raw() { + return this.view.buffer; } - } - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; + static size() { + return 32; } } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); - } - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeUint256(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 32); + return buffer; } -} -export function SerializeBytesVec(value) { - return serializeTable(value.map(item => SerializeBytes(item))); -} + class Bytes { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class Byte32Vec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + if (this.view.byteLength < 4) { + dataLengthError(this.view.byteLength, ">4"); + } + const requiredByteLength = this.length() + 4; + assertDataLength(this.view.byteLength, requiredByteLength); } - } - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4"); + raw() { + return this.view.buffer.slice(4); } - const requiredByteLength = this.length() * Byte32.size() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); - for (let i = 0; i < 0; i++) { - const item = this.indexAt(i); - item.validate(compatible); + + indexAt(i) { + return this.view.getUint8(4 + i); } - } - indexAt(i) { - return new Byte32(this.view.buffer.slice(4 + i * Byte32.size(), 4 + (i + 1) * Byte32.size()), { validate: false }); + length() { + return this.view.getUint32(0, true); + } } - length() { - return this.view.getUint32(0, true); + function SerializeBytes(value) { + const item = assertArrayBuffer(value); + const array = new Uint8Array(4 + item.byteLength); + (new DataView(array.buffer)).setUint32(0, item.byteLength, true); + array.set(new Uint8Array(item), 4); + return array.buffer; } -} -export function SerializeByte32Vec(value) { - const array = new Uint8Array(4 + Byte32.size() * value.length); - (new DataView(array.buffer)).setUint32(0, value.length, true); - for (let i = 0; i < value.length; i++) { - const itemBuffer = SerializeByte32(value[i]); - array.set(new Uint8Array(itemBuffer), 4 + i * Byte32.size()); - } - return array.buffer; -} + class BytesOpt { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class ScriptOpt { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + if (this.hasValue()) { + this.value().validate(compatible); + } } - } - validate(compatible = false) { - if (this.hasValue()) { - this.value().validate(compatible); + value() { + return new Bytes(this.view.buffer, { validate: false }); } - } - value() { - return new Script(this.view.buffer, { validate: false }); + hasValue() { + return this.view.byteLength > 0; + } } - hasValue() { - return this.view.byteLength > 0; + function SerializeBytesOpt(value) { + if (value) { + return SerializeBytes(value); + } else { + return new ArrayBuffer(0); + } } -} -export function SerializeScriptOpt(value) { - if (value) { - return SerializeScript(value); - } else { - return new ArrayBuffer(0); - } -} + class BytesVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class ProposalShortId { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new Bytes(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + } } - } - validate(compatible = false) { - assertDataLength(this.view.byteLength, 10); - } + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; + } + } - indexAt(i) { - return this.view.getUint8(i); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); + } + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - raw() { - return this.view.buffer; + function SerializeBytesVec(value) { + return serializeTable(value.map(item => SerializeBytes(item))); } - static size() { - return 10; - } -} + class Byte32Vec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeProposalShortId(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 10); - return buffer; -} + validate(compatible = false) { + if (this.view.byteLength < 4) { + dataLengthError(this.view.byteLength, ">4"); + } + const requiredByteLength = this.length() * Byte32.size() + 4; + assertDataLength(this.view.byteLength, requiredByteLength); + for (let i = 0; i < 0; i++) { + const item = this.indexAt(i); + item.validate(compatible); + } + } -export class UncleBlockVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + indexAt(i) { + return new Byte32(this.view.buffer.slice(4 + i * Byte32.size(), 4 + (i + 1) * Byte32.size()), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new UncleBlock(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + length() { + return this.view.getUint32(0, true); } } - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; + function SerializeByte32Vec(value) { + const array = new Uint8Array(4 + Byte32.size() * value.length); + (new DataView(array.buffer)).setUint32(0, value.length, true); + for (let i = 0; i < value.length; i++) { + const itemBuffer = SerializeByte32(value[i]); + array.set(new Uint8Array(itemBuffer), 4 + i * Byte32.size()); } + return array.buffer; } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); + class ScriptOpt { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - return new UncleBlock(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} -export function SerializeUncleBlockVec(value) { - return serializeTable(value.map(item => SerializeUncleBlock(item))); -} + validate(compatible = false) { + if (this.hasValue()) { + this.value().validate(compatible); + } + } -export class TransactionVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + value() { + return new Script(this.view.buffer, { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new Transaction(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + hasValue() { + return this.view.byteLength > 0; } } - length() { - if (this.view.byteLength < 8) { - return 0; + function SerializeScriptOpt(value) { + if (value) { + return SerializeScript(value); } else { - return this.view.getUint32(4, true) / 4 - 1; + return new ArrayBuffer(0); } } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); + class ProposalShortId { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - return new Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} -export function SerializeTransactionVec(value) { - return serializeTable(value.map(item => SerializeTransaction(item))); -} + validate(compatible = false) { + assertDataLength(this.view.byteLength, 10); + } -export class ProposalShortIdVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + indexAt(i) { + return this.view.getUint8(i); } - } - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4"); + raw() { + return this.view.buffer; } - const requiredByteLength = this.length() * ProposalShortId.size() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); - for (let i = 0; i < 0; i++) { - const item = this.indexAt(i); - item.validate(compatible); + + static size() { + return 10; } } - indexAt(i) { - return new ProposalShortId(this.view.buffer.slice(4 + i * ProposalShortId.size(), 4 + (i + 1) * ProposalShortId.size()), { validate: false }); + function SerializeProposalShortId(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 10); + return buffer; } - length() { - return this.view.getUint32(0, true); + class UncleBlockVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } + + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new UncleBlock(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + } + } + + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; + } + } + + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); + } + return new UncleBlock(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } -} -export function SerializeProposalShortIdVec(value) { - const array = new Uint8Array(4 + ProposalShortId.size() * value.length); - (new DataView(array.buffer)).setUint32(0, value.length, true); - for (let i = 0; i < value.length; i++) { - const itemBuffer = SerializeProposalShortId(value[i]); - array.set(new Uint8Array(itemBuffer), 4 + i * ProposalShortId.size()); + function SerializeUncleBlockVec(value) { + return serializeTable(value.map(item => SerializeUncleBlock(item))); } - return array.buffer; -} -export class CellDepVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class TransactionVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4"); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new Transaction(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + } } - const requiredByteLength = this.length() * CellDep.size() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); - for (let i = 0; i < 0; i++) { - const item = this.indexAt(i); - item.validate(compatible); + + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; + } } - } - indexAt(i) { - return new CellDep(this.view.buffer.slice(4 + i * CellDep.size(), 4 + (i + 1) * CellDep.size()), { validate: false }); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); + } + return new Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - length() { - return this.view.getUint32(0, true); + function SerializeTransactionVec(value) { + return serializeTable(value.map(item => SerializeTransaction(item))); } -} -export function SerializeCellDepVec(value) { - const array = new Uint8Array(4 + CellDep.size() * value.length); - (new DataView(array.buffer)).setUint32(0, value.length, true); - for (let i = 0; i < value.length; i++) { - const itemBuffer = SerializeCellDep(value[i]); - array.set(new Uint8Array(itemBuffer), 4 + i * CellDep.size()); - } - return array.buffer; -} + class ProposalShortIdVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class CellInputVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + if (this.view.byteLength < 4) { + dataLengthError(this.view.byteLength, ">4"); + } + const requiredByteLength = this.length() * ProposalShortId.size() + 4; + assertDataLength(this.view.byteLength, requiredByteLength); + for (let i = 0; i < 0; i++) { + const item = this.indexAt(i); + item.validate(compatible); + } } - } - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4"); + indexAt(i) { + return new ProposalShortId(this.view.buffer.slice(4 + i * ProposalShortId.size(), 4 + (i + 1) * ProposalShortId.size()), { validate: false }); } - const requiredByteLength = this.length() * CellInput.size() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); - for (let i = 0; i < 0; i++) { - const item = this.indexAt(i); - item.validate(compatible); + + length() { + return this.view.getUint32(0, true); } } - indexAt(i) { - return new CellInput(this.view.buffer.slice(4 + i * CellInput.size(), 4 + (i + 1) * CellInput.size()), { validate: false }); + function SerializeProposalShortIdVec(value) { + const array = new Uint8Array(4 + ProposalShortId.size() * value.length); + (new DataView(array.buffer)).setUint32(0, value.length, true); + for (let i = 0; i < value.length; i++) { + const itemBuffer = SerializeProposalShortId(value[i]); + array.set(new Uint8Array(itemBuffer), 4 + i * ProposalShortId.size()); + } + return array.buffer; } - length() { - return this.view.getUint32(0, true); - } -} + class CellDepVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeCellInputVec(value) { - const array = new Uint8Array(4 + CellInput.size() * value.length); - (new DataView(array.buffer)).setUint32(0, value.length, true); - for (let i = 0; i < value.length; i++) { - const itemBuffer = SerializeCellInput(value[i]); - array.set(new Uint8Array(itemBuffer), 4 + i * CellInput.size()); - } - return array.buffer; -} + validate(compatible = false) { + if (this.view.byteLength < 4) { + dataLengthError(this.view.byteLength, ">4"); + } + const requiredByteLength = this.length() * CellDep.size() + 4; + assertDataLength(this.view.byteLength, requiredByteLength); + for (let i = 0; i < 0; i++) { + const item = this.indexAt(i); + item.validate(compatible); + } + } -export class CellOutputVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + indexAt(i) { + return new CellDep(this.view.buffer.slice(4 + i * CellDep.size(), 4 + (i + 1) * CellDep.size()), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new CellOutput(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + length() { + return this.view.getUint32(0, true); } } - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; + function SerializeCellDepVec(value) { + const array = new Uint8Array(4 + CellDep.size() * value.length); + (new DataView(array.buffer)).setUint32(0, value.length, true); + for (let i = 0; i < value.length; i++) { + const itemBuffer = SerializeCellDep(value[i]); + array.set(new Uint8Array(itemBuffer), 4 + i * CellDep.size()); } + return array.buffer; } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); + class CellInputVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - return new CellOutput(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} -export function SerializeCellOutputVec(value) { - return serializeTable(value.map(item => SerializeCellOutput(item))); -} + validate(compatible = false) { + if (this.view.byteLength < 4) { + dataLengthError(this.view.byteLength, ">4"); + } + const requiredByteLength = this.length() * CellInput.size() + 4; + assertDataLength(this.view.byteLength, requiredByteLength); + for (let i = 0; i < 0; i++) { + const item = this.indexAt(i); + item.validate(compatible); + } + } -export class Script { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + indexAt(i) { + return new CellInput(this.view.buffer.slice(4 + i * CellInput.size(), 4 + (i + 1) * CellInput.size()), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - if (offsets[2] - offsets[1] !== 1) { - throw new Error(`Invalid offset for hash_type: ${offsets[1]} - ${offsets[2]}`) + length() { + return this.view.getUint32(0, true); } - new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); } - getCodeHash() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeCellInputVec(value) { + const array = new Uint8Array(4 + CellInput.size() * value.length); + (new DataView(array.buffer)).setUint32(0, value.length, true); + for (let i = 0; i < value.length; i++) { + const itemBuffer = SerializeCellInput(value[i]); + array.set(new Uint8Array(itemBuffer), 4 + i * CellInput.size()); + } + return array.buffer; } - getHashType() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new DataView(this.view.buffer.slice(offset, offset_end)).getUint8(0); - } + class CellOutputVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getArgs() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new CellOutput(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + } + } -export function SerializeScript(value) { - const buffers = []; - buffers.push(SerializeByte32(value.code_hash)); - const hashTypeView = new DataView(new ArrayBuffer(1)); - hashTypeView.setUint8(0, value.hash_type); - buffers.push(hashTypeView.buffer) - buffers.push(SerializeBytes(value.args)); - return serializeTable(buffers); -} + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; + } + } -export class OutPoint { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); + } + return new CellOutput(this.view.buffer.slice(offset, offset_end), { validate: false }); } } - getTxHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + function SerializeCellOutputVec(value) { + return serializeTable(value.map(item => SerializeCellOutput(item))); } - getIndex() { - return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); - } + class Script { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, OutPoint.size()); - this.getTxHash().validate(compatible); - this.getIndex().validate(compatible); - } - static size() { - return 0 + Byte32.size() + Uint32.size(); - } -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + if (offsets[2] - offsets[1] !== 1) { + throw new Error(`Invalid offset for hash_type: ${offsets[1]} - ${offsets[2]}`) + } + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + } -export function SerializeOutPoint(value) { - const array = new Uint8Array(0 + Byte32.size() + Uint32.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeByte32(value.tx_hash)), 0); - array.set(new Uint8Array(SerializeUint32(value.index)), 0 + Byte32.size()); - return array.buffer; -} + getCodeHash() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export class CellInput { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getHashType() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new DataView(this.view.buffer.slice(offset, offset_end)).getUint8(0); } - } - getSince() { - return new Uint64(this.view.buffer.slice(0, 0 + Uint64.size()), { validate: false }); + getArgs() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getPreviousOutput() { - return new OutPoint(this.view.buffer.slice(0 + Uint64.size(), 0 + Uint64.size() + OutPoint.size()), { validate: false }); + function SerializeScript(value) { + const buffers = []; + buffers.push(SerializeByte32(value.code_hash)); + const hashTypeView = new DataView(new ArrayBuffer(1)); + hashTypeView.setUint8(0, value.hash_type); + buffers.push(hashTypeView.buffer); + buffers.push(SerializeBytes(value.args)); + return serializeTable(buffers); } - validate(compatible = false) { - assertDataLength(this.view.byteLength, CellInput.size()); - this.getSince().validate(compatible); - this.getPreviousOutput().validate(compatible); - } - static size() { - return 0 + Uint64.size() + OutPoint.size(); - } -} + class OutPoint { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeCellInput(value) { - const array = new Uint8Array(0 + Uint64.size() + OutPoint.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeUint64(value.since)), 0); - array.set(new Uint8Array(SerializeOutPoint(value.previous_output)), 0 + Uint64.size()); - return array.buffer; -} + getTxHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + } -export class CellOutput { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getIndex() { + return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Script(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new ScriptOpt(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + validate(compatible = false) { + assertDataLength(this.view.byteLength, OutPoint.size()); + this.getTxHash().validate(compatible); + this.getIndex().validate(compatible); + } + static size() { + return 0 + Byte32.size() + Uint32.size(); + } } - getCapacity() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeOutPoint(value) { + const array = new Uint8Array(0 + Byte32.size() + Uint32.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.tx_hash)), 0); + array.set(new Uint8Array(SerializeUint32(value.index)), 0 + Byte32.size()); + return array.buffer; } - getLock() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + class CellInput { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getType() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new ScriptOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + getSince() { + return new Uint64(this.view.buffer.slice(0, 0 + Uint64.size()), { validate: false }); + } -export function SerializeCellOutput(value) { - const buffers = []; - buffers.push(SerializeUint64(value.capacity)); - buffers.push(SerializeScript(value.lock)); - buffers.push(SerializeScriptOpt(value.type_)); - return serializeTable(buffers); -} + getPreviousOutput() { + return new OutPoint(this.view.buffer.slice(0 + Uint64.size(), 0 + Uint64.size() + OutPoint.size()), { validate: false }); + } -export class CellDep { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + validate(compatible = false) { + assertDataLength(this.view.byteLength, CellInput.size()); + this.getSince().validate(compatible); + this.getPreviousOutput().validate(compatible); + } + static size() { + return 0 + Uint64.size() + OutPoint.size(); } } - getOutPoint() { - return new OutPoint(this.view.buffer.slice(0, 0 + OutPoint.size()), { validate: false }); + function SerializeCellInput(value) { + const array = new Uint8Array(0 + Uint64.size() + OutPoint.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeUint64(value.since)), 0); + array.set(new Uint8Array(SerializeOutPoint(value.previous_output)), 0 + Uint64.size()); + return array.buffer; } - getDepType() { - return this.view.getUint8(0 + OutPoint.size()); - } + class CellOutput { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, CellDep.size()); - this.getOutPoint().validate(compatible); - } - static size() { - return 0 + OutPoint.size() + 1; - } -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Script(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new ScriptOpt(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + } -export function SerializeCellDep(value) { - const array = new Uint8Array(0 + OutPoint.size() + 1); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeOutPoint(value.out_point)), 0); - view.setUint8(0 + OutPoint.size(), value.dep_type); - return array.buffer; -} + getCapacity() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export class RawTransaction { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getLock() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new CellDepVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Byte32Vec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new CellInputVec(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new CellOutputVec(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - new BytesVec(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); + getType() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new ScriptOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getVersion() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeCellOutput(value) { + const buffers = []; + buffers.push(SerializeUint64(value.capacity)); + buffers.push(SerializeScript(value.lock)); + buffers.push(SerializeScriptOpt(value.type_)); + return serializeTable(buffers); } - getCellDeps() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new CellDepVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + class CellDep { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getHeaderDeps() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getOutPoint() { + return new OutPoint(this.view.buffer.slice(0, 0 + OutPoint.size()), { validate: false }); + } - getInputs() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new CellInputVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getDepType() { + return this.view.getUint8(0 + OutPoint.size()); + } - getOutputs() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new CellOutputVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + validate(compatible = false) { + assertDataLength(this.view.byteLength, CellDep.size()); + this.getOutPoint().validate(compatible); + } + static size() { + return 0 + OutPoint.size() + 1; + } } - getOutputsData() { - const start = 24; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new BytesVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeCellDep(value) { + const array = new Uint8Array(0 + OutPoint.size() + 1); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeOutPoint(value.out_point)), 0); + view.setUint8(0 + OutPoint.size(), value.dep_type); + return array.buffer; } -} - -export function SerializeRawTransaction(value) { - const buffers = []; - buffers.push(SerializeUint32(value.version)); - buffers.push(SerializeCellDepVec(value.cell_deps)); - buffers.push(SerializeByte32Vec(value.header_deps)); - buffers.push(SerializeCellInputVec(value.inputs)); - buffers.push(SerializeCellOutputVec(value.outputs)); - buffers.push(SerializeBytesVec(value.outputs_data)); - return serializeTable(buffers); -} -export class Transaction { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + class RawTransaction { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new RawTransaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new BytesVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new CellDepVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Byte32Vec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new CellInputVec(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new CellOutputVec(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); + new BytesVec(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); + } - getRaw() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawTransaction(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getVersion() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getWitnesses() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new BytesVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + getCellDeps() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new CellDepVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export function SerializeTransaction(value) { - const buffers = []; - buffers.push(SerializeRawTransaction(value.raw)); - buffers.push(SerializeBytesVec(value.witnesses)); - return serializeTable(buffers); -} + getHeaderDeps() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export class RawHeader { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getInputs() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new CellInputVec(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - getVersion() { - return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); - } + getOutputs() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new CellOutputVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getCompactTarget() { - return new Uint32(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint32.size()), { validate: false }); + getOutputsData() { + const start = 24; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new BytesVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getTimestamp() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size()), { validate: false }); + function SerializeRawTransaction(value) { + const buffers = []; + buffers.push(SerializeUint32(value.version)); + buffers.push(SerializeCellDepVec(value.cell_deps)); + buffers.push(SerializeByte32Vec(value.header_deps)); + buffers.push(SerializeCellInputVec(value.inputs)); + buffers.push(SerializeCellOutputVec(value.outputs)); + buffers.push(SerializeBytesVec(value.outputs_data)); + return serializeTable(buffers); } - getNumber() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size()), { validate: false }); - } + class Transaction { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getEpoch() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size()), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawTransaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new BytesVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + } - getParentHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size()), { validate: false }); - } + getRaw() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawTransaction(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getTransactionsRoot() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size()), { validate: false }); + getWitnesses() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new BytesVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getProposalsHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size()), { validate: false }); + function SerializeTransaction(value) { + const buffers = []; + buffers.push(SerializeRawTransaction(value.raw)); + buffers.push(SerializeBytesVec(value.witnesses)); + return serializeTable(buffers); } - getUnclesHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()), { validate: false }); - } + class RawHeader { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getDao() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()), { validate: false }); - } + getVersion() { + return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, RawHeader.size()); - this.getVersion().validate(compatible); - this.getCompactTarget().validate(compatible); - this.getTimestamp().validate(compatible); - this.getNumber().validate(compatible); - this.getEpoch().validate(compatible); - this.getParentHash().validate(compatible); - this.getTransactionsRoot().validate(compatible); - this.getProposalsHash().validate(compatible); - this.getUnclesHash().validate(compatible); - this.getDao().validate(compatible); - } - static size() { - return 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size(); - } -} + getCompactTarget() { + return new Uint32(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint32.size()), { validate: false }); + } -export function SerializeRawHeader(value) { - const array = new Uint8Array(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeUint32(value.version)), 0); - array.set(new Uint8Array(SerializeUint32(value.compact_target)), 0 + Uint32.size()); - array.set(new Uint8Array(SerializeUint64(value.timestamp)), 0 + Uint32.size() + Uint32.size()); - array.set(new Uint8Array(SerializeUint64(value.number)), 0 + Uint32.size() + Uint32.size() + Uint64.size()); - array.set(new Uint8Array(SerializeUint64(value.epoch)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size()); - array.set(new Uint8Array(SerializeByte32(value.parent_hash)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size()); - array.set(new Uint8Array(SerializeByte32(value.transactions_root)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size()); - array.set(new Uint8Array(SerializeByte32(value.proposals_hash)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size()); - array.set(new Uint8Array(SerializeByte32(value.uncles_hash)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size()); - array.set(new Uint8Array(SerializeByte32(value.dao)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()); - return array.buffer; -} + getTimestamp() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size()), { validate: false }); + } -export class Header { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getNumber() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size()), { validate: false }); } - } - getRaw() { - return new RawHeader(this.view.buffer.slice(0, 0 + RawHeader.size()), { validate: false }); - } + getEpoch() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size()), { validate: false }); + } - getNonce() { - return new Uint128(this.view.buffer.slice(0 + RawHeader.size(), 0 + RawHeader.size() + Uint128.size()), { validate: false }); - } + getParentHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size()), { validate: false }); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, Header.size()); - this.getRaw().validate(compatible); - this.getNonce().validate(compatible); - } - static size() { - return 0 + RawHeader.size() + Uint128.size(); - } -} + getTransactionsRoot() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size()), { validate: false }); + } -export function SerializeHeader(value) { - const array = new Uint8Array(0 + RawHeader.size() + Uint128.size()); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeRawHeader(value.raw)), 0); - array.set(new Uint8Array(SerializeUint128(value.nonce)), 0 + RawHeader.size()); - return array.buffer; -} + getProposalsHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size()), { validate: false }); + } -export class UncleBlock { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getUnclesHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Header(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new ProposalShortIdVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - } + getDao() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()), { validate: false }); + } - getHeader() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Header(this.view.buffer.slice(offset, offset_end), { validate: false }); + validate(compatible = false) { + assertDataLength(this.view.byteLength, RawHeader.size()); + this.getVersion().validate(compatible); + this.getCompactTarget().validate(compatible); + this.getTimestamp().validate(compatible); + this.getNumber().validate(compatible); + this.getEpoch().validate(compatible); + this.getParentHash().validate(compatible); + this.getTransactionsRoot().validate(compatible); + this.getProposalsHash().validate(compatible); + this.getUnclesHash().validate(compatible); + this.getDao().validate(compatible); + } + static size() { + return 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size(); + } } - getProposals() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeRawHeader(value) { + const array = new Uint8Array(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeUint32(value.version)), 0); + array.set(new Uint8Array(SerializeUint32(value.compact_target)), 0 + Uint32.size()); + array.set(new Uint8Array(SerializeUint64(value.timestamp)), 0 + Uint32.size() + Uint32.size()); + array.set(new Uint8Array(SerializeUint64(value.number)), 0 + Uint32.size() + Uint32.size() + Uint64.size()); + array.set(new Uint8Array(SerializeUint64(value.epoch)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size()); + array.set(new Uint8Array(SerializeByte32(value.parent_hash)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size()); + array.set(new Uint8Array(SerializeByte32(value.transactions_root)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size()); + array.set(new Uint8Array(SerializeByte32(value.proposals_hash)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size()); + array.set(new Uint8Array(SerializeByte32(value.uncles_hash)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size()); + array.set(new Uint8Array(SerializeByte32(value.dao)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()); + return array.buffer; } -} -export function SerializeUncleBlock(value) { - const buffers = []; - buffers.push(SerializeHeader(value.header)); - buffers.push(SerializeProposalShortIdVec(value.proposals)); - return serializeTable(buffers); -} + class Header { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export class Block { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getRaw() { + return new RawHeader(this.view.buffer.slice(0, 0 + RawHeader.size()), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Header(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new UncleBlockVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new TransactionVec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new ProposalShortIdVec(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - } + getNonce() { + return new Uint128(this.view.buffer.slice(0 + RawHeader.size(), 0 + RawHeader.size() + Uint128.size()), { validate: false }); + } - getHeader() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Header(this.view.buffer.slice(offset, offset_end), { validate: false }); + validate(compatible = false) { + assertDataLength(this.view.byteLength, Header.size()); + this.getRaw().validate(compatible); + this.getNonce().validate(compatible); + } + static size() { + return 0 + RawHeader.size() + Uint128.size(); + } } - getUncles() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new UncleBlockVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeHeader(value) { + const array = new Uint8Array(0 + RawHeader.size() + Uint128.size()); + new DataView(array.buffer); + array.set(new Uint8Array(SerializeRawHeader(value.raw)), 0); + array.set(new Uint8Array(SerializeUint128(value.nonce)), 0 + RawHeader.size()); + return array.buffer; } - getTransactions() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new TransactionVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + class UncleBlock { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getProposals() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Header(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new ProposalShortIdVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + } -export function SerializeBlock(value) { - const buffers = []; - buffers.push(SerializeHeader(value.header)); - buffers.push(SerializeUncleBlockVec(value.uncles)); - buffers.push(SerializeTransactionVec(value.transactions)); - buffers.push(SerializeProposalShortIdVec(value.proposals)); - return serializeTable(buffers); -} + getHeader() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Header(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export class CellbaseWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getProposals() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), { validate: false }); } } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Script(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + function SerializeUncleBlock(value) { + const buffers = []; + buffers.push(SerializeHeader(value.header)); + buffers.push(SerializeProposalShortIdVec(value.proposals)); + return serializeTable(buffers); } - getLock() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + class Block { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } - getMessage() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Header(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new UncleBlockVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new TransactionVec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new ProposalShortIdVec(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + } -export function SerializeCellbaseWitness(value) { - const buffers = []; - buffers.push(SerializeScript(value.lock)); - buffers.push(SerializeBytes(value.message)); - return serializeTable(buffers); -} + getHeader() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Header(this.view.buffer.slice(offset, offset_end), { validate: false }); + } -export class WitnessArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); + getUncles() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new UncleBlockVec(this.view.buffer.slice(offset, offset_end), { validate: false }); } - } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new BytesOpt(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new BytesOpt(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new BytesOpt(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - } + getTransactions() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new TransactionVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getLock() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new BytesOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); + getProposals() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } } - getInputType() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new BytesOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); + function SerializeBlock(value) { + const buffers = []; + buffers.push(SerializeHeader(value.header)); + buffers.push(SerializeUncleBlockVec(value.uncles)); + buffers.push(SerializeTransactionVec(value.transactions)); + buffers.push(SerializeProposalShortIdVec(value.proposals)); + return serializeTable(buffers); } - getOutputType() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new BytesOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); - } -} + class CellbaseWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } -export function SerializeWitnessArgs(value) { - const buffers = []; - buffers.push(SerializeBytesOpt(value.lock)); - buffers.push(SerializeBytesOpt(value.input_type)); - buffers.push(SerializeBytesOpt(value.output_type)); - return serializeTable(buffers); -} + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Script(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + } + getLock() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getMessage() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + } + + function SerializeCellbaseWitness(value) { + const buffers = []; + buffers.push(SerializeScript(value.lock)); + buffers.push(SerializeBytes(value.message)); + return serializeTable(buffers); + } + + class WitnessArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); + } + } + + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new BytesOpt(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new BytesOpt(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new BytesOpt(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + } + + getLock() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new BytesOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getInputType() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new BytesOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getOutputType() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new BytesOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + } + + function SerializeWitnessArgs(value) { + const buffers = []; + buffers.push(SerializeBytesOpt(value.lock)); + buffers.push(SerializeBytesOpt(value.input_type)); + buffers.push(SerializeBytesOpt(value.output_type)); + return serializeTable(buffers); + } + + exports.AccountMerkleState = AccountMerkleState; + exports.Block = Block; + exports.BlockHashEntry = BlockHashEntry; + exports.BlockHashEntryVec = BlockHashEntryVec; + exports.BlockInfo = BlockInfo; + exports.BlockMerkleState = BlockMerkleState; + exports.Byte32 = Byte32; + exports.Byte32Vec = Byte32Vec; + exports.Bytes = Bytes; + exports.BytesOpt = BytesOpt; + exports.BytesVec = BytesVec; + exports.CellDep = CellDep; + exports.CellDepVec = CellDepVec; + exports.CellInput = CellInput; + exports.CellInputVec = CellInputVec; + exports.CellOutput = CellOutput; + exports.CellOutputVec = CellOutputVec; + exports.CellbaseWitness = CellbaseWitness; + exports.ChallengeLockArgs = ChallengeLockArgs; + exports.ChallengeTarget = ChallengeTarget; + exports.ChallengeWitness = ChallengeWitness; + exports.CreateAccount = CreateAccount; + exports.CustodianLockArgs = CustodianLockArgs; + exports.DepositLockArgs = DepositLockArgs; + exports.DepositRequest = DepositRequest; + exports.DepositRequestVec = DepositRequestVec; + exports.Fee = Fee; + exports.GlobalState = GlobalState; + exports.Header = Header; + exports.KVPair = KVPair; + exports.KVPairVec = KVPairVec; + exports.L2Block = L2Block; + exports.L2Transaction = L2Transaction; + exports.L2TransactionVec = L2TransactionVec; + exports.MetaContractArgs = MetaContractArgs; + exports.OutPoint = OutPoint; + exports.ProposalShortId = ProposalShortId; + exports.ProposalShortIdVec = ProposalShortIdVec; + exports.RawHeader = RawHeader; + exports.RawL2Block = RawL2Block; + exports.RawL2BlockVec = RawL2BlockVec; + exports.RawL2Transaction = RawL2Transaction; + exports.RawTransaction = RawTransaction; + exports.RawWithdrawalRequest = RawWithdrawalRequest; + exports.RollupAction = RollupAction; + exports.RollupCancelChallenge = RollupCancelChallenge; + exports.RollupConfig = RollupConfig; + exports.RollupEnterChallenge = RollupEnterChallenge; + exports.RollupRevert = RollupRevert; + exports.RollupSubmitBlock = RollupSubmitBlock; + exports.SUDTArgs = SUDTArgs; + exports.SUDTQuery = SUDTQuery; + exports.SUDTTransfer = SUDTTransfer; + exports.Script = Script; + exports.ScriptOpt = ScriptOpt; + exports.ScriptVec = ScriptVec; + exports.SerializeAccountMerkleState = SerializeAccountMerkleState; + exports.SerializeBlock = SerializeBlock; + exports.SerializeBlockHashEntry = SerializeBlockHashEntry; + exports.SerializeBlockHashEntryVec = SerializeBlockHashEntryVec; + exports.SerializeBlockInfo = SerializeBlockInfo; + exports.SerializeBlockMerkleState = SerializeBlockMerkleState; + exports.SerializeByte32 = SerializeByte32; + exports.SerializeByte32Vec = SerializeByte32Vec; + exports.SerializeBytes = SerializeBytes; + exports.SerializeBytesOpt = SerializeBytesOpt; + exports.SerializeBytesVec = SerializeBytesVec; + exports.SerializeCellDep = SerializeCellDep; + exports.SerializeCellDepVec = SerializeCellDepVec; + exports.SerializeCellInput = SerializeCellInput; + exports.SerializeCellInputVec = SerializeCellInputVec; + exports.SerializeCellOutput = SerializeCellOutput; + exports.SerializeCellOutputVec = SerializeCellOutputVec; + exports.SerializeCellbaseWitness = SerializeCellbaseWitness; + exports.SerializeChallengeLockArgs = SerializeChallengeLockArgs; + exports.SerializeChallengeTarget = SerializeChallengeTarget; + exports.SerializeChallengeWitness = SerializeChallengeWitness; + exports.SerializeCreateAccount = SerializeCreateAccount; + exports.SerializeCustodianLockArgs = SerializeCustodianLockArgs; + exports.SerializeDepositLockArgs = SerializeDepositLockArgs; + exports.SerializeDepositRequest = SerializeDepositRequest; + exports.SerializeDepositRequestVec = SerializeDepositRequestVec; + exports.SerializeFee = SerializeFee; + exports.SerializeGlobalState = SerializeGlobalState; + exports.SerializeHeader = SerializeHeader; + exports.SerializeKVPair = SerializeKVPair; + exports.SerializeKVPairVec = SerializeKVPairVec; + exports.SerializeL2Block = SerializeL2Block; + exports.SerializeL2Transaction = SerializeL2Transaction; + exports.SerializeL2TransactionVec = SerializeL2TransactionVec; + exports.SerializeMetaContractArgs = SerializeMetaContractArgs; + exports.SerializeOutPoint = SerializeOutPoint; + exports.SerializeProposalShortId = SerializeProposalShortId; + exports.SerializeProposalShortIdVec = SerializeProposalShortIdVec; + exports.SerializeRawHeader = SerializeRawHeader; + exports.SerializeRawL2Block = SerializeRawL2Block; + exports.SerializeRawL2BlockVec = SerializeRawL2BlockVec; + exports.SerializeRawL2Transaction = SerializeRawL2Transaction; + exports.SerializeRawTransaction = SerializeRawTransaction; + exports.SerializeRawWithdrawalRequest = SerializeRawWithdrawalRequest; + exports.SerializeRollupAction = SerializeRollupAction; + exports.SerializeRollupCancelChallenge = SerializeRollupCancelChallenge; + exports.SerializeRollupConfig = SerializeRollupConfig; + exports.SerializeRollupEnterChallenge = SerializeRollupEnterChallenge; + exports.SerializeRollupRevert = SerializeRollupRevert; + exports.SerializeRollupSubmitBlock = SerializeRollupSubmitBlock; + exports.SerializeSUDTArgs = SerializeSUDTArgs; + exports.SerializeSUDTQuery = SerializeSUDTQuery; + exports.SerializeSUDTTransfer = SerializeSUDTTransfer; + exports.SerializeScript = SerializeScript; + exports.SerializeScriptOpt = SerializeScriptOpt; + exports.SerializeScriptVec = SerializeScriptVec; + exports.SerializeStakeLockArgs = SerializeStakeLockArgs; + exports.SerializeSubmitTransactions = SerializeSubmitTransactions; + exports.SerializeSubmitWithdrawals = SerializeSubmitWithdrawals; + exports.SerializeTransaction = SerializeTransaction; + exports.SerializeTransactionVec = SerializeTransactionVec; + exports.SerializeUint128 = SerializeUint128; + exports.SerializeUint16 = SerializeUint16; + exports.SerializeUint256 = SerializeUint256; + exports.SerializeUint32 = SerializeUint32; + exports.SerializeUint64 = SerializeUint64; + exports.SerializeUncleBlock = SerializeUncleBlock; + exports.SerializeUncleBlockVec = SerializeUncleBlockVec; + exports.SerializeUnlockCustodianViaRevertWitness = SerializeUnlockCustodianViaRevertWitness; + exports.SerializeUnlockWithdrawalViaFinalize = SerializeUnlockWithdrawalViaFinalize; + exports.SerializeUnlockWithdrawalViaRevert = SerializeUnlockWithdrawalViaRevert; + exports.SerializeUnlockWithdrawalViaTrade = SerializeUnlockWithdrawalViaTrade; + exports.SerializeUnlockWithdrawalWitness = SerializeUnlockWithdrawalWitness; + exports.SerializeVerifyTransactionContext = SerializeVerifyTransactionContext; + exports.SerializeVerifyTransactionSignatureContext = SerializeVerifyTransactionSignatureContext; + exports.SerializeVerifyTransactionSignatureWitness = SerializeVerifyTransactionSignatureWitness; + exports.SerializeVerifyTransactionWitness = SerializeVerifyTransactionWitness; + exports.SerializeVerifyWithdrawalWitness = SerializeVerifyWithdrawalWitness; + exports.SerializeWithdrawalLockArgs = SerializeWithdrawalLockArgs; + exports.SerializeWithdrawalRequest = SerializeWithdrawalRequest; + exports.SerializeWithdrawalRequestVec = SerializeWithdrawalRequestVec; + exports.SerializeWitnessArgs = SerializeWitnessArgs; + exports.StakeLockArgs = StakeLockArgs; + exports.SubmitTransactions = SubmitTransactions; + exports.SubmitWithdrawals = SubmitWithdrawals; + exports.Transaction = Transaction; + exports.TransactionVec = TransactionVec; + exports.Uint128 = Uint128; + exports.Uint16 = Uint16; + exports.Uint256 = Uint256; + exports.Uint32 = Uint32; + exports.Uint64 = Uint64; + exports.UncleBlock = UncleBlock; + exports.UncleBlockVec = UncleBlockVec; + exports.UnlockCustodianViaRevertWitness = UnlockCustodianViaRevertWitness; + exports.UnlockWithdrawalViaFinalize = UnlockWithdrawalViaFinalize; + exports.UnlockWithdrawalViaRevert = UnlockWithdrawalViaRevert; + exports.UnlockWithdrawalViaTrade = UnlockWithdrawalViaTrade; + exports.UnlockWithdrawalWitness = UnlockWithdrawalWitness; + exports.VerifyTransactionContext = VerifyTransactionContext; + exports.VerifyTransactionSignatureContext = VerifyTransactionSignatureContext; + exports.VerifyTransactionSignatureWitness = VerifyTransactionSignatureWitness; + exports.VerifyTransactionWitness = VerifyTransactionWitness; + exports.VerifyWithdrawalWitness = VerifyWithdrawalWitness; + exports.WithdrawalLockArgs = WithdrawalLockArgs; + exports.WithdrawalRequest = WithdrawalRequest; + exports.WithdrawalRequestVec = WithdrawalRequestVec; + exports.WitnessArgs = WitnessArgs; + + Object.defineProperty(exports, '__esModule', { value: true }); + +}))); diff --git a/packages/godwoken/schemas/index.js b/packages/godwoken/schemas/index.js index 525aa7d3..85347a11 100644 --- a/packages/godwoken/schemas/index.js +++ b/packages/godwoken/schemas/index.js @@ -1,4033 +1,3805 @@ -(function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : - typeof define === 'function' && define.amd ? define(['exports'], factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Godwoken = {})); -}(this, (function (exports) { 'use strict'; +function dataLengthError(actual, required) { + throw new Error(`Invalid data length! Required: ${required}, actual: ${actual}`); +} - function dataLengthError(actual, required) { - throw new Error(`Invalid data length! Required: ${required}, actual: ${actual}`); +function assertDataLength(actual, required) { + if (actual !== required) { + dataLengthError(actual, required); } +} - function assertDataLength(actual, required) { - if (actual !== required) { - dataLengthError(actual, required); - } +function assertArrayBuffer(reader) { + if (reader instanceof Object && reader.toArrayBuffer instanceof Function) { + reader = reader.toArrayBuffer(); } - - function assertArrayBuffer(reader) { - if (reader instanceof Object && reader.toArrayBuffer instanceof Function) { - reader = reader.toArrayBuffer(); - } - if (!(reader instanceof ArrayBuffer)) { - throw new Error("Provided value must be an ArrayBuffer or can be transformed into ArrayBuffer!"); - } - return reader; + if (!(reader instanceof ArrayBuffer)) { + throw new Error("Provided value must be an ArrayBuffer or can be transformed into ArrayBuffer!"); } + return reader; +} - function verifyAndExtractOffsets(view, expectedFieldCount, compatible) { - if (view.byteLength < 4) { - dataLengthError(view.byteLength, ">4"); - } - const requiredByteLength = view.getUint32(0, true); - assertDataLength(view.byteLength, requiredByteLength); - if (requiredByteLength === 4) { - return [requiredByteLength]; - } - if (requiredByteLength < 8) { - dataLengthError(view.byteLength, ">8"); - } - const firstOffset = view.getUint32(4, true); - if (firstOffset % 4 !== 0 || firstOffset < 8) { - throw new Error(`Invalid first offset: ${firstOffset}`); - } - const itemCount = firstOffset / 4 - 1; - if (itemCount < expectedFieldCount) { - throw new Error(`Item count not enough! Required: ${expectedFieldCount}, actual: ${itemCount}`); - } else if ((!compatible) && itemCount > expectedFieldCount) { - throw new Error(`Item count is more than required! Required: ${expectedFieldCount}, actual: ${itemCount}`); - } - if (requiredByteLength < firstOffset) { - throw new Error(`First offset is larger than byte length: ${firstOffset}`); - } - const offsets = []; - for (let i = 0; i < itemCount; i++) { - const start = 4 + i * 4; - offsets.push(view.getUint32(start, true)); - } - offsets.push(requiredByteLength); - for (let i = 0; i < offsets.length - 1; i++) { - if (offsets[i] > offsets[i + 1]) { - throw new Error(`Offset index ${i}: ${offsets[i]} is larger than offset index ${i + 1}: ${offsets[i + 1]}`); - } +function verifyAndExtractOffsets(view, expectedFieldCount, compatible) { + if (view.byteLength < 4) { + dataLengthError(view.byteLength, ">4"); + } + const requiredByteLength = view.getUint32(0, true); + assertDataLength(view.byteLength, requiredByteLength); + if (requiredByteLength === 4) { + return [requiredByteLength]; + } + if (requiredByteLength < 8) { + dataLengthError(view.byteLength, ">8"); + } + const firstOffset = view.getUint32(4, true); + if (firstOffset % 4 !== 0 || firstOffset < 8) { + throw new Error(`Invalid first offset: ${firstOffset}`); + } + const itemCount = firstOffset / 4 - 1; + if (itemCount < expectedFieldCount) { + throw new Error(`Item count not enough! Required: ${expectedFieldCount}, actual: ${itemCount}`); + } else if ((!compatible) && itemCount > expectedFieldCount) { + throw new Error(`Item count is more than required! Required: ${expectedFieldCount}, actual: ${itemCount}`); + } + if (requiredByteLength < firstOffset) { + throw new Error(`First offset is larger than byte length: ${firstOffset}`); + } + const offsets = []; + for (let i = 0; i < itemCount; i++) { + const start = 4 + i * 4; + offsets.push(view.getUint32(start, true)); + } + offsets.push(requiredByteLength); + for (let i = 0; i < offsets.length - 1; i++) { + if (offsets[i] > offsets[i + 1]) { + throw new Error(`Offset index ${i}: ${offsets[i]} is larger than offset index ${i + 1}: ${offsets[i + 1]}`); } - return offsets; } + return offsets; +} - function serializeTable(buffers) { - const itemCount = buffers.length; - let totalSize = 4 * (itemCount + 1); - const offsets = []; +function serializeTable(buffers) { + const itemCount = buffers.length; + let totalSize = 4 * (itemCount + 1); + const offsets = []; - for (let i = 0; i < itemCount; i++) { - offsets.push(totalSize); - totalSize += buffers[i].byteLength; - } + for (let i = 0; i < itemCount; i++) { + offsets.push(totalSize); + totalSize += buffers[i].byteLength; + } - const buffer = new ArrayBuffer(totalSize); - const array = new Uint8Array(buffer); - const view = new DataView(buffer); + const buffer = new ArrayBuffer(totalSize); + const array = new Uint8Array(buffer); + const view = new DataView(buffer); - view.setUint32(0, totalSize, true); - for (let i = 0; i < itemCount; i++) { - view.setUint32(4 + i * 4, offsets[i], true); - array.set(new Uint8Array(buffers[i]), offsets[i]); - } - return buffer; + view.setUint32(0, totalSize, true); + for (let i = 0; i < itemCount; i++) { + view.setUint32(4 + i * 4, offsets[i], true); + array.set(new Uint8Array(buffers[i]), offsets[i]); } + return buffer; +} - class Byte32Opt { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } +export class BlockMerkleState { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - validate(compatible = false) { - if (this.hasValue()) { - this.value().validate(compatible); - } - } + getMerkleRoot() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + } - value() { - return new Byte32(this.view.buffer, { validate: false }); - } + getCount() { + return new Uint64(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint64.size()), { validate: false }); + } - hasValue() { - return this.view.byteLength > 0; - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, BlockMerkleState.size()); + this.getMerkleRoot().validate(compatible); + this.getCount().validate(compatible); + } + static size() { + return 0 + Byte32.size() + Uint64.size(); } +} - function SerializeByte32Opt(value) { - if (value) { - return SerializeByte32(value); - } else { - return new ArrayBuffer(0); +export function SerializeBlockMerkleState(value) { + const array = new Uint8Array(0 + Byte32.size() + Uint64.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.merkle_root)), 0); + array.set(new Uint8Array(SerializeUint64(value.count)), 0 + Byte32.size()); + return array.buffer; +} + +export class AccountMerkleState { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - class Byte20 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getMerkleRoot() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, 20); - } + getCount() { + return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); + } - indexAt(i) { - return this.view.getUint8(i); - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, AccountMerkleState.size()); + this.getMerkleRoot().validate(compatible); + this.getCount().validate(compatible); + } + static size() { + return 0 + Byte32.size() + Uint32.size(); + } +} - raw() { - return this.view.buffer; - } +export function SerializeAccountMerkleState(value) { + const array = new Uint8Array(0 + Byte32.size() + Uint32.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.merkle_root)), 0); + array.set(new Uint8Array(SerializeUint32(value.count)), 0 + Byte32.size()); + return array.buffer; +} - static size() { - return 20; +export class GlobalState { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeByte20(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 20); - return buffer; + getRollupConfigHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); } - class Signature { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getAccount() { + return new AccountMerkleState(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + AccountMerkleState.size()), { validate: false }); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, 65); - } + getBlock() { + return new BlockMerkleState(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size()), { validate: false }); + } - indexAt(i) { - return this.view.getUint8(i); - } + getRevertedBlockRoot() { + return new Byte32(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size()), { validate: false }); + } - raw() { - return this.view.buffer; - } + getTipBlockHash() { + return new Byte32(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size()), { validate: false }); + } - static size() { - return 65; - } + getLastFinalizedBlockNumber() { + return new Uint64(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size()), { validate: false }); } - function SerializeSignature(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 65); - return buffer; + getStatus() { + return this.view.getUint8(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size()); } - class BlockMerkleState { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, GlobalState.size()); + this.getRollupConfigHash().validate(compatible); + this.getAccount().validate(compatible); + this.getBlock().validate(compatible); + this.getRevertedBlockRoot().validate(compatible); + this.getTipBlockHash().validate(compatible); + this.getLastFinalizedBlockNumber().validate(compatible); + } + static size() { + return 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size() + 1; + } +} - getMerkleRoot() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } +export function SerializeGlobalState(value) { + const array = new Uint8Array(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size() + 1); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.rollup_config_hash)), 0); + array.set(new Uint8Array(SerializeAccountMerkleState(value.account)), 0 + Byte32.size()); + array.set(new Uint8Array(SerializeBlockMerkleState(value.block)), 0 + Byte32.size() + AccountMerkleState.size()); + array.set(new Uint8Array(SerializeByte32(value.reverted_block_root)), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size()); + array.set(new Uint8Array(SerializeByte32(value.tip_block_hash)), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size()); + array.set(new Uint8Array(SerializeUint64(value.last_finalized_block_number)), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size()); + view.setUint8(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size(), value.status); + return array.buffer; +} - getCount() { - return new Uint64(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint64.size()), { validate: false }); +export class RollupConfig { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, BlockMerkleState.size()); - this.getMerkleRoot().validate(compatible); - this.getCount().validate(compatible); - } - static size() { - return 0 + Byte32.size() + Uint64.size(); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[6], offsets[7]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[7], offsets[8]), { validate: false }).validate(); + new Uint64(this.view.buffer.slice(offsets[8], offsets[9]), { validate: false }).validate(); + new Uint64(this.view.buffer.slice(offsets[9], offsets[10]), { validate: false }).validate(); + new Uint64(this.view.buffer.slice(offsets[10], offsets[11]), { validate: false }).validate(); + if (offsets[12] - offsets[11] !== 1) { + throw new Error(`Invalid offset for reward_burn_rate: ${offsets[11]} - ${offsets[12]}`) } + new Byte32Vec(this.view.buffer.slice(offsets[12], offsets[13]), { validate: false }).validate(); + new Byte32Vec(this.view.buffer.slice(offsets[13], offsets[14]), { validate: false }).validate(); } - function SerializeBlockMerkleState(value) { - const array = new Uint8Array(0 + Byte32.size() + Uint64.size()); - array.set(new Uint8Array(SerializeByte32(value.merkle_root)), 0); - array.set(new Uint8Array(SerializeUint64(value.count)), 0 + Byte32.size()); - return array.buffer; + getL1SudtScriptTypeHash() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class AccountMerkleState { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getCustodianScriptTypeHash() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getMerkleRoot() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } + getDepositScriptTypeHash() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getCount() { - return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); - } + getWithdrawalScriptTypeHash() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, AccountMerkleState.size()); - this.getMerkleRoot().validate(compatible); - this.getCount().validate(compatible); - } - static size() { - return 0 + Byte32.size() + Uint32.size(); - } + getChallengeScriptTypeHash() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getStakeScriptTypeHash() { + const start = 24; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getL2SudtValidatorScriptTypeHash() { + const start = 28; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getBurnLockHash() { + const start = 32; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getRequiredStakingCapacity() { + const start = 36; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getChallengeMaturityBlocks() { + const start = 40; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getFinalityBlocks() { + const start = 44; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getRewardBurnRate() { + const start = 48; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new DataView(this.view.buffer.slice(offset, offset_end)).getUint8(0); + } + + getAllowedEoaTypeHashes() { + const start = 52; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); } - function SerializeAccountMerkleState(value) { - const array = new Uint8Array(0 + Byte32.size() + Uint32.size()); - array.set(new Uint8Array(SerializeByte32(value.merkle_root)), 0); - array.set(new Uint8Array(SerializeUint32(value.count)), 0 + Byte32.size()); - return array.buffer; + getAllowedContractTypeHashes() { + const start = 56; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); } +} - class GlobalState { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } +export function SerializeRollupConfig(value) { + const buffers = []; + buffers.push(SerializeByte32(value.l1_sudt_script_type_hash)); + buffers.push(SerializeByte32(value.custodian_script_type_hash)); + buffers.push(SerializeByte32(value.deposit_script_type_hash)); + buffers.push(SerializeByte32(value.withdrawal_script_type_hash)); + buffers.push(SerializeByte32(value.challenge_script_type_hash)); + buffers.push(SerializeByte32(value.stake_script_type_hash)); + buffers.push(SerializeByte32(value.l2_sudt_validator_script_type_hash)); + buffers.push(SerializeByte32(value.burn_lock_hash)); + buffers.push(SerializeUint64(value.required_staking_capacity)); + buffers.push(SerializeUint64(value.challenge_maturity_blocks)); + buffers.push(SerializeUint64(value.finality_blocks)); + const rewardBurnRateView = new DataView(new ArrayBuffer(1)); + rewardBurnRateView.setUint8(0, value.reward_burn_rate); + buffers.push(rewardBurnRateView.buffer) + buffers.push(SerializeByte32Vec(value.allowed_eoa_type_hashes)); + buffers.push(SerializeByte32Vec(value.allowed_contract_type_hashes)); + return serializeTable(buffers); +} - getRollupConfigHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); +export class RawL2Transaction { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getAccount() { - return new AccountMerkleState(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + AccountMerkleState.size()), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Uint32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Uint32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + } - getBlock() { - return new BlockMerkleState(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size()), { validate: false }); - } + getFromId() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getRevertedBlockRoot() { - return new Byte32(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size()), { validate: false }); - } + getToId() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getTipBlockHash() { - return new Byte32(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size()), { validate: false }); - } + getNonce() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getLastFinalizedBlockNumber() { - return new Uint64(this.view.buffer.slice(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size(), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size()), { validate: false }); - } + getArgs() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getStatus() { - return this.view.getUint8(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size()); - } +export function SerializeRawL2Transaction(value) { + const buffers = []; + buffers.push(SerializeUint32(value.from_id)); + buffers.push(SerializeUint32(value.to_id)); + buffers.push(SerializeUint32(value.nonce)); + buffers.push(SerializeBytes(value.args)); + return serializeTable(buffers); +} - validate(compatible = false) { - assertDataLength(this.view.byteLength, GlobalState.size()); - this.getRollupConfigHash().validate(compatible); - this.getAccount().validate(compatible); - this.getBlock().validate(compatible); - this.getRevertedBlockRoot().validate(compatible); - this.getTipBlockHash().validate(compatible); - this.getLastFinalizedBlockNumber().validate(compatible); - } - static size() { - return 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size() + 1; +export class L2Transaction { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeGlobalState(value) { - const array = new Uint8Array(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size() + 1); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeByte32(value.rollup_config_hash)), 0); - array.set(new Uint8Array(SerializeAccountMerkleState(value.account)), 0 + Byte32.size()); - array.set(new Uint8Array(SerializeBlockMerkleState(value.block)), 0 + Byte32.size() + AccountMerkleState.size()); - array.set(new Uint8Array(SerializeByte32(value.reverted_block_root)), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size()); - array.set(new Uint8Array(SerializeByte32(value.tip_block_hash)), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size()); - array.set(new Uint8Array(SerializeUint64(value.last_finalized_block_number)), 0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size()); - view.setUint8(0 + Byte32.size() + AccountMerkleState.size() + BlockMerkleState.size() + Byte32.size() + Byte32.size() + Uint64.size(), value.status); - return array.buffer; + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawL2Transaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); } - class RollupConfig { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getRaw() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[6], offsets[7]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[7], offsets[8]), { validate: false }).validate(); - new Uint64(this.view.buffer.slice(offsets[8], offsets[9]), { validate: false }).validate(); - new Uint64(this.view.buffer.slice(offsets[9], offsets[10]), { validate: false }).validate(); - new Uint64(this.view.buffer.slice(offsets[10], offsets[11]), { validate: false }).validate(); - new Uint32(this.view.buffer.slice(offsets[11], offsets[12]), { validate: false }).validate(); - if (offsets[13] - offsets[12] !== 1) { - throw new Error(`Invalid offset for reward_burn_rate: ${offsets[12]} - ${offsets[13]}`) - } - new Byte32Vec(this.view.buffer.slice(offsets[13], offsets[14]), { validate: false }).validate(); - new Byte32Vec(this.view.buffer.slice(offsets[14], offsets[15]), { validate: false }).validate(); - } + getSignature() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getL1SudtScriptTypeHash() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +export function SerializeL2Transaction(value) { + const buffers = []; + buffers.push(SerializeRawL2Transaction(value.raw)); + buffers.push(SerializeBytes(value.signature)); + return serializeTable(buffers); +} - getCustodianScriptTypeHash() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class L2TransactionVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getDepositScriptTypeHash() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new L2Transaction(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); } + } - getWithdrawalScriptTypeHash() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getChallengeScriptTypeHash() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; } + } - getStakeScriptTypeHash() { - const start = 24; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getL2SudtValidatorScriptTypeHash() { - const start = 28; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getBurnLockHash() { - const start = 32; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getRequiredStakingCapacity() { - const start = 36; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getChallengeMaturityBlocks() { - const start = 40; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getFinalityBlocks() { - const start = 44; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); } + return new L2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getCompatibleChainId() { - const start = 48; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +export function SerializeL2TransactionVec(value) { + return serializeTable(value.map(item => SerializeL2Transaction(item))); +} - getRewardBurnRate() { - const start = 52; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new DataView(this.view.buffer.slice(offset, offset_end)).getUint8(0); +export class SubmitTransactions { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getAllowedEoaTypeHashes() { - const start = 56; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Uint32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + } - getAllowedContractTypeHashes() { - const start = 60; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getTxWitnessRoot() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - function SerializeRollupConfig(value) { - const buffers = []; - buffers.push(SerializeByte32(value.l1_sudt_script_type_hash)); - buffers.push(SerializeByte32(value.custodian_script_type_hash)); - buffers.push(SerializeByte32(value.deposit_script_type_hash)); - buffers.push(SerializeByte32(value.withdrawal_script_type_hash)); - buffers.push(SerializeByte32(value.challenge_script_type_hash)); - buffers.push(SerializeByte32(value.stake_script_type_hash)); - buffers.push(SerializeByte32(value.l2_sudt_validator_script_type_hash)); - buffers.push(SerializeByte32(value.burn_lock_hash)); - buffers.push(SerializeUint64(value.required_staking_capacity)); - buffers.push(SerializeUint64(value.challenge_maturity_blocks)); - buffers.push(SerializeUint64(value.finality_blocks)); - buffers.push(SerializeUint32(value.compatible_chain_id)); - const rewardBurnRateView = new DataView(new ArrayBuffer(1)); - rewardBurnRateView.setUint8(0, value.reward_burn_rate); - buffers.push(rewardBurnRateView.buffer); - buffers.push(SerializeByte32Vec(value.allowed_eoa_type_hashes)); - buffers.push(SerializeByte32Vec(value.allowed_contract_type_hashes)); - return serializeTable(buffers); + getTxCount() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class RawL2Transaction { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getPrevStateCheckpoint() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Uint32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Uint32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - } +export function SerializeSubmitTransactions(value) { + const buffers = []; + buffers.push(SerializeByte32(value.tx_witness_root)); + buffers.push(SerializeUint32(value.tx_count)); + buffers.push(SerializeByte32(value.prev_state_checkpoint)); + return serializeTable(buffers); +} - getFromId() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class SubmitWithdrawals { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getToId() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getWithdrawalWitnessRoot() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + } - getNonce() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getWithdrawalCount() { + return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); + } - getArgs() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + validate(compatible = false) { + assertDataLength(this.view.byteLength, SubmitWithdrawals.size()); + this.getWithdrawalWitnessRoot().validate(compatible); + this.getWithdrawalCount().validate(compatible); + } + static size() { + return 0 + Byte32.size() + Uint32.size(); + } +} + +export function SerializeSubmitWithdrawals(value) { + const array = new Uint8Array(0 + Byte32.size() + Uint32.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.withdrawal_witness_root)), 0); + array.set(new Uint8Array(SerializeUint32(value.withdrawal_count)), 0 + Byte32.size()); + return array.buffer; +} + +export class RawL2Block { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeRawL2Transaction(value) { - const buffers = []; - buffers.push(SerializeUint32(value.from_id)); - buffers.push(SerializeUint32(value.to_id)); - buffers.push(SerializeUint32(value.nonce)); - buffers.push(SerializeBytes(value.args)); - return serializeTable(buffers); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Uint32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new Uint64(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); + new AccountMerkleState(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); + new AccountMerkleState(this.view.buffer.slice(offsets[6], offsets[7]), { validate: false }).validate(); + new Byte32Vec(this.view.buffer.slice(offsets[7], offsets[8]), { validate: false }).validate(); + new SubmitWithdrawals(this.view.buffer.slice(offsets[8], offsets[9]), { validate: false }).validate(); + new SubmitTransactions(this.view.buffer.slice(offsets[9], offsets[10]), { validate: false }).validate(); } - class L2Transaction { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getNumber() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new RawL2Transaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Signature(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - } + getBlockProducerId() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getRaw() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getParentBlockHash() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getSignature() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Signature(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getStakeCellOwnerLockHash() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - function SerializeL2Transaction(value) { - const buffers = []; - buffers.push(SerializeRawL2Transaction(value.raw)); - buffers.push(SerializeSignature(value.signature)); - return serializeTable(buffers); + getTimestamp() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class L2TransactionVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getPrevAccount() { + const start = 24; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new AccountMerkleState(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new L2Transaction(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); - } - } + getPostAccount() { + const start = 28; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new AccountMerkleState(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; - } - } + getStateCheckpointList() { + const start = 32; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); - } - return new L2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getSubmitWithdrawals() { + const start = 36; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new SubmitWithdrawals(this.view.buffer.slice(offset, offset_end), { validate: false }); } - function SerializeL2TransactionVec(value) { - return serializeTable(value.map(item => SerializeL2Transaction(item))); + getSubmitTransactions() { + const start = 40; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new SubmitTransactions(this.view.buffer.slice(offset, offset_end), { validate: false }); } +} - class SubmitTransactions { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } +export function SerializeRawL2Block(value) { + const buffers = []; + buffers.push(SerializeUint64(value.number)); + buffers.push(SerializeUint32(value.block_producer_id)); + buffers.push(SerializeByte32(value.parent_block_hash)); + buffers.push(SerializeByte32(value.stake_cell_owner_lock_hash)); + buffers.push(SerializeUint64(value.timestamp)); + buffers.push(SerializeAccountMerkleState(value.prev_account)); + buffers.push(SerializeAccountMerkleState(value.post_account)); + buffers.push(SerializeByte32Vec(value.state_checkpoint_list)); + buffers.push(SerializeSubmitWithdrawals(value.submit_withdrawals)); + buffers.push(SerializeSubmitTransactions(value.submit_transactions)); + return serializeTable(buffers); +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Uint32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); +export class RawL2BlockVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getTxWitnessRoot() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new RawL2Block(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); } + } - getTxCount() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; } + } - getPrevStateCheckpoint() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); } + return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); } +} - function SerializeSubmitTransactions(value) { - const buffers = []; - buffers.push(SerializeByte32(value.tx_witness_root)); - buffers.push(SerializeUint32(value.tx_count)); - buffers.push(SerializeByte32(value.prev_state_checkpoint)); - return serializeTable(buffers); - } +export function SerializeRawL2BlockVec(value) { + return serializeTable(value.map(item => SerializeRawL2Block(item))); +} - class SubmitWithdrawals { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } +export class L2Block { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getWithdrawalWitnessRoot() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new KVPairVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new L2TransactionVec(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); + new WithdrawalRequestVec(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); + } - getWithdrawalCount() { - return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); - } + getRaw() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, SubmitWithdrawals.size()); - this.getWithdrawalWitnessRoot().validate(compatible); - this.getWithdrawalCount().validate(compatible); - } - static size() { - return 0 + Byte32.size() + Uint32.size(); - } + getKvState() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new KVPairVec(this.view.buffer.slice(offset, offset_end), { validate: false }); } - function SerializeSubmitWithdrawals(value) { - const array = new Uint8Array(0 + Byte32.size() + Uint32.size()); - array.set(new Uint8Array(SerializeByte32(value.withdrawal_witness_root)), 0); - array.set(new Uint8Array(SerializeUint32(value.withdrawal_count)), 0 + Byte32.size()); - return array.buffer; + getKvStateProof() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class RawL2Block { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getTransactions() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new L2TransactionVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Uint32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new Uint64(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - new AccountMerkleState(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); - new AccountMerkleState(this.view.buffer.slice(offsets[6], offsets[7]), { validate: false }).validate(); - new Byte32Vec(this.view.buffer.slice(offsets[7], offsets[8]), { validate: false }).validate(); - new SubmitWithdrawals(this.view.buffer.slice(offsets[8], offsets[9]), { validate: false }).validate(); - new SubmitTransactions(this.view.buffer.slice(offsets[9], offsets[10]), { validate: false }).validate(); - } + getBlockProof() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getNumber() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getWithdrawals() { + const start = 24; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new WithdrawalRequestVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getBlockProducerId() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +export function SerializeL2Block(value) { + const buffers = []; + buffers.push(SerializeRawL2Block(value.raw)); + buffers.push(SerializeKVPairVec(value.kv_state)); + buffers.push(SerializeBytes(value.kv_state_proof)); + buffers.push(SerializeL2TransactionVec(value.transactions)); + buffers.push(SerializeBytes(value.block_proof)); + buffers.push(SerializeWithdrawalRequestVec(value.withdrawals)); + return serializeTable(buffers); +} - getParentBlockHash() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class DepositRequest { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getStakeCellOwnerLockHash() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Uint128(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Script(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + } - getTimestamp() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getCapacity() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getPrevAccount() { - const start = 24; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new AccountMerkleState(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getAmount() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint128(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getPostAccount() { - const start = 28; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new AccountMerkleState(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getSudtScriptHash() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getStateCheckpointList() { - const start = 32; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getScript() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getSubmitWithdrawals() { - const start = 36; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new SubmitWithdrawals(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +export function SerializeDepositRequest(value) { + const buffers = []; + buffers.push(SerializeUint64(value.capacity)); + buffers.push(SerializeUint128(value.amount)); + buffers.push(SerializeByte32(value.sudt_script_hash)); + buffers.push(SerializeScript(value.script)); + return serializeTable(buffers); +} - getSubmitTransactions() { - const start = 40; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new SubmitTransactions(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class DepositRequestVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeRawL2Block(value) { - const buffers = []; - buffers.push(SerializeUint64(value.number)); - buffers.push(SerializeUint32(value.block_producer_id)); - buffers.push(SerializeByte32(value.parent_block_hash)); - buffers.push(SerializeByte32(value.stake_cell_owner_lock_hash)); - buffers.push(SerializeUint64(value.timestamp)); - buffers.push(SerializeAccountMerkleState(value.prev_account)); - buffers.push(SerializeAccountMerkleState(value.post_account)); - buffers.push(SerializeByte32Vec(value.state_checkpoint_list)); - buffers.push(SerializeSubmitWithdrawals(value.submit_withdrawals)); - buffers.push(SerializeSubmitTransactions(value.submit_transactions)); - return serializeTable(buffers); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new DepositRequest(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); + } } - class RawL2BlockVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; } + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new RawL2Block(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); - } + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); } + return new DepositRequest(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; - } - } +export function SerializeDepositRequestVec(value) { + return serializeTable(value.map(item => SerializeDepositRequest(item))); +} - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); - } - return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class RawWithdrawalRequest { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeRawL2BlockVec(value) { - return serializeTable(value.map(item => SerializeRawL2Block(item))); + getNonce() { + return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); } - class L2Block { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getCapacity() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint64.size()), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new KVPairVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new L2TransactionVec(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - new WithdrawalRequestVec(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); - } + getAmount() { + return new Uint128(this.view.buffer.slice(0 + Uint32.size() + Uint64.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size()), { validate: false }); + } - getRaw() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getSudtScriptHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size()), { validate: false }); + } - getKvState() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new KVPairVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getAccountScriptHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size()), { validate: false }); + } - getKvStateProof() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getSellAmount() { + return new Uint128(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size()), { validate: false }); + } - getTransactions() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new L2TransactionVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getSellCapacity() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size()), { validate: false }); + } - getBlockProof() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getOwnerLockHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()), { validate: false }); + } - getWithdrawals() { - const start = 24; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new WithdrawalRequestVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getPaymentLockHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()), { validate: false }); } - function SerializeL2Block(value) { - const buffers = []; - buffers.push(SerializeRawL2Block(value.raw)); - buffers.push(SerializeKVPairVec(value.kv_state)); - buffers.push(SerializeBytes(value.kv_state_proof)); - buffers.push(SerializeL2TransactionVec(value.transactions)); - buffers.push(SerializeBytes(value.block_proof)); - buffers.push(SerializeWithdrawalRequestVec(value.withdrawals)); - return serializeTable(buffers); + getFee() { + return new Fee(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size() + Fee.size()), { validate: false }); } - class DepositRequest { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, RawWithdrawalRequest.size()); + this.getNonce().validate(compatible); + this.getCapacity().validate(compatible); + this.getAmount().validate(compatible); + this.getSudtScriptHash().validate(compatible); + this.getAccountScriptHash().validate(compatible); + this.getSellAmount().validate(compatible); + this.getSellCapacity().validate(compatible); + this.getOwnerLockHash().validate(compatible); + this.getPaymentLockHash().validate(compatible); + this.getFee().validate(compatible); + } + static size() { + return 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size() + Fee.size(); + } +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Uint128(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Script(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); +export function SerializeRawWithdrawalRequest(value) { + const array = new Uint8Array(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size() + Fee.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeUint32(value.nonce)), 0); + array.set(new Uint8Array(SerializeUint64(value.capacity)), 0 + Uint32.size()); + array.set(new Uint8Array(SerializeUint128(value.amount)), 0 + Uint32.size() + Uint64.size()); + array.set(new Uint8Array(SerializeByte32(value.sudt_script_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size()); + array.set(new Uint8Array(SerializeByte32(value.account_script_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size()); + array.set(new Uint8Array(SerializeUint128(value.sell_amount)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size()); + array.set(new Uint8Array(SerializeUint64(value.sell_capacity)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size()); + array.set(new Uint8Array(SerializeByte32(value.owner_lock_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size()); + array.set(new Uint8Array(SerializeByte32(value.payment_lock_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()); + array.set(new Uint8Array(SerializeFee(value.fee)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()); + return array.buffer; +} + +export class WithdrawalRequestVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getCapacity() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new WithdrawalRequest(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); } + } - getAmount() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint128(this.view.buffer.slice(offset, offset_end), { validate: false }); + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; } + } - getSudtScriptHash() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); } + return new WithdrawalRequest(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} + +export function SerializeWithdrawalRequestVec(value) { + return serializeTable(value.map(item => SerializeWithdrawalRequest(item))); +} - getScript() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class WithdrawalRequest { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeDepositRequest(value) { - const buffers = []; - buffers.push(SerializeUint64(value.capacity)); - buffers.push(SerializeUint128(value.amount)); - buffers.push(SerializeByte32(value.sudt_script_hash)); - buffers.push(SerializeScript(value.script)); - return serializeTable(buffers); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawWithdrawalRequest(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); } - class DepositRequestVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getRaw() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawWithdrawalRequest(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new DepositRequest(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); - } - } + getSignature() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; - } - } +export function SerializeWithdrawalRequest(value) { + const buffers = []; + buffers.push(SerializeRawWithdrawalRequest(value.raw)); + buffers.push(SerializeBytes(value.signature)); + return serializeTable(buffers); +} - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); - } - return new DepositRequest(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class KVPair { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeDepositRequestVec(value) { - return serializeTable(value.map(item => SerializeDepositRequest(item))); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); } - class RawWithdrawalRequest { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getK() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getNonce() { - return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); - } + getV() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getCapacity() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint64.size()), { validate: false }); - } +export function SerializeKVPair(value) { + const buffers = []; + buffers.push(SerializeByte32(value.k)); + buffers.push(SerializeByte32(value.v)); + return serializeTable(buffers); +} - getAmount() { - return new Uint128(this.view.buffer.slice(0 + Uint32.size() + Uint64.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size()), { validate: false }); +export class KVPairVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getSudtScriptHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size()), { validate: false }); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new KVPair(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); } + } - getAccountScriptHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size()), { validate: false }); + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; } + } - getSellAmount() { - return new Uint128(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size()), { validate: false }); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); } + return new KVPair(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getSellCapacity() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size()), { validate: false }); - } +export function SerializeKVPairVec(value) { + return serializeTable(value.map(item => SerializeKVPair(item))); +} - getOwnerLockHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()), { validate: false }); +export class BlockInfo { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getPaymentLockHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size(), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()), { validate: false }); - } + getBlockProducerId() { + return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, RawWithdrawalRequest.size()); - this.getNonce().validate(compatible); - this.getCapacity().validate(compatible); - this.getAmount().validate(compatible); - this.getSudtScriptHash().validate(compatible); - this.getAccountScriptHash().validate(compatible); - this.getSellAmount().validate(compatible); - this.getSellCapacity().validate(compatible); - this.getOwnerLockHash().validate(compatible); - this.getPaymentLockHash().validate(compatible); - } - static size() { - return 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size(); - } + getNumber() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint64.size()), { validate: false }); } - function SerializeRawWithdrawalRequest(value) { - const array = new Uint8Array(0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()); - array.set(new Uint8Array(SerializeUint32(value.nonce)), 0); - array.set(new Uint8Array(SerializeUint64(value.capacity)), 0 + Uint32.size()); - array.set(new Uint8Array(SerializeUint128(value.amount)), 0 + Uint32.size() + Uint64.size()); - array.set(new Uint8Array(SerializeByte32(value.sudt_script_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size()); - array.set(new Uint8Array(SerializeByte32(value.account_script_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size()); - array.set(new Uint8Array(SerializeUint128(value.sell_amount)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size()); - array.set(new Uint8Array(SerializeUint64(value.sell_capacity)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size()); - array.set(new Uint8Array(SerializeByte32(value.owner_lock_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size()); - array.set(new Uint8Array(SerializeByte32(value.payment_lock_hash)), 0 + Uint32.size() + Uint64.size() + Uint128.size() + Byte32.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()); - return array.buffer; + getTimestamp() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint64.size(), 0 + Uint32.size() + Uint64.size() + Uint64.size()), { validate: false }); } - class WithdrawalRequestVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, BlockInfo.size()); + this.getBlockProducerId().validate(compatible); + this.getNumber().validate(compatible); + this.getTimestamp().validate(compatible); + } + static size() { + return 0 + Uint32.size() + Uint64.size() + Uint64.size(); + } +} - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4"); - } - const requiredByteLength = this.length() * WithdrawalRequest.size() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); - for (let i = 0; i < 0; i++) { - const item = this.indexAt(i); - item.validate(compatible); - } - } +export function SerializeBlockInfo(value) { + const array = new Uint8Array(0 + Uint32.size() + Uint64.size() + Uint64.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeUint32(value.block_producer_id)), 0); + array.set(new Uint8Array(SerializeUint64(value.number)), 0 + Uint32.size()); + array.set(new Uint8Array(SerializeUint64(value.timestamp)), 0 + Uint32.size() + Uint64.size()); + return array.buffer; +} - indexAt(i) { - return new WithdrawalRequest(this.view.buffer.slice(4 + i * WithdrawalRequest.size(), 4 + (i + 1) * WithdrawalRequest.size()), { validate: false }); +export class DepositLockArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - length() { - return this.view.getUint32(0, true); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Script(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Uint64(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); } - function SerializeWithdrawalRequestVec(value) { - const array = new Uint8Array(4 + WithdrawalRequest.size() * value.length); - (new DataView(array.buffer)).setUint32(0, value.length, true); - for (let i = 0; i < value.length; i++) { - const itemBuffer = SerializeWithdrawalRequest(value[i]); - array.set(new Uint8Array(itemBuffer), 4 + i * WithdrawalRequest.size()); - } - return array.buffer; + getOwnerLockHash() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class WithdrawalRequest { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getLayer2Lock() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getRaw() { - return new RawWithdrawalRequest(this.view.buffer.slice(0, 0 + RawWithdrawalRequest.size()), { validate: false }); - } + getCancelTimeout() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getSignature() { - return new Signature(this.view.buffer.slice(0 + RawWithdrawalRequest.size(), 0 + RawWithdrawalRequest.size() + Signature.size()), { validate: false }); - } +export function SerializeDepositLockArgs(value) { + const buffers = []; + buffers.push(SerializeByte32(value.owner_lock_hash)); + buffers.push(SerializeScript(value.layer2_lock)); + buffers.push(SerializeUint64(value.cancel_timeout)); + return serializeTable(buffers); +} - validate(compatible = false) { - assertDataLength(this.view.byteLength, WithdrawalRequest.size()); - this.getRaw().validate(compatible); - this.getSignature().validate(compatible); - } - static size() { - return 0 + RawWithdrawalRequest.size() + Signature.size(); +export class CustodianLockArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeWithdrawalRequest(value) { - const array = new Uint8Array(0 + RawWithdrawalRequest.size() + Signature.size()); - array.set(new Uint8Array(SerializeRawWithdrawalRequest(value.raw)), 0); - array.set(new Uint8Array(SerializeSignature(value.signature)), 0 + RawWithdrawalRequest.size()); - return array.buffer; + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new DepositLockArgs(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Uint64(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); } - class KVPair { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getDepositLockArgs() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new DepositLockArgs(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - } + getDepositBlockHash() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getK() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getDepositBlockNumber() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} + +export function SerializeCustodianLockArgs(value) { + const buffers = []; + buffers.push(SerializeDepositLockArgs(value.deposit_lock_args)); + buffers.push(SerializeByte32(value.deposit_block_hash)); + buffers.push(SerializeUint64(value.deposit_block_number)); + return serializeTable(buffers); +} - getV() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class UnlockCustodianViaRevertWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeKVPair(value) { - const buffers = []; - buffers.push(SerializeByte32(value.k)); - buffers.push(SerializeByte32(value.v)); - return serializeTable(buffers); + getDepositLockHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); } - class KVPairVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, UnlockCustodianViaRevertWitness.size()); + this.getDepositLockHash().validate(compatible); + } + static size() { + return 0 + Byte32.size(); + } +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new KVPair(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); - } - } +export function SerializeUnlockCustodianViaRevertWitness(value) { + const array = new Uint8Array(0 + Byte32.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.deposit_lock_hash)), 0); + return array.buffer; +} - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; - } +export class WithdrawalLockArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); - } - return new KVPair(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getAccountScriptHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); } - function SerializeKVPairVec(value) { - return serializeTable(value.map(item => SerializeKVPair(item))); + getWithdrawalBlockHash() { + return new Byte32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Byte32.size()), { validate: false }); } - class BlockInfo { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getWithdrawalBlockNumber() { + return new Uint64(this.view.buffer.slice(0 + Byte32.size() + Byte32.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size()), { validate: false }); + } - getBlockProducerId() { - return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); - } + getSudtScriptHash() { + return new Byte32(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size()), { validate: false }); + } - getNumber() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint64.size()), { validate: false }); - } + getSellAmount() { + return new Uint128(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size()), { validate: false }); + } - getTimestamp() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint64.size(), 0 + Uint32.size() + Uint64.size() + Uint64.size()), { validate: false }); - } + getSellCapacity() { + return new Uint64(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size()), { validate: false }); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, BlockInfo.size()); - this.getBlockProducerId().validate(compatible); - this.getNumber().validate(compatible); - this.getTimestamp().validate(compatible); - } - static size() { - return 0 + Uint32.size() + Uint64.size() + Uint64.size(); - } + getOwnerLockHash() { + return new Byte32(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()), { validate: false }); } - function SerializeBlockInfo(value) { - const array = new Uint8Array(0 + Uint32.size() + Uint64.size() + Uint64.size()); - array.set(new Uint8Array(SerializeUint32(value.block_producer_id)), 0); - array.set(new Uint8Array(SerializeUint64(value.number)), 0 + Uint32.size()); - array.set(new Uint8Array(SerializeUint64(value.timestamp)), 0 + Uint32.size() + Uint64.size()); - return array.buffer; + getPaymentLockHash() { + return new Byte32(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()), { validate: false }); } - class DepositLockArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, WithdrawalLockArgs.size()); + this.getAccountScriptHash().validate(compatible); + this.getWithdrawalBlockHash().validate(compatible); + this.getWithdrawalBlockNumber().validate(compatible); + this.getSudtScriptHash().validate(compatible); + this.getSellAmount().validate(compatible); + this.getSellCapacity().validate(compatible); + this.getOwnerLockHash().validate(compatible); + this.getPaymentLockHash().validate(compatible); + } + static size() { + return 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size(); + } +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Script(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Uint64(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - } +export function SerializeWithdrawalLockArgs(value) { + const array = new Uint8Array(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.account_script_hash)), 0); + array.set(new Uint8Array(SerializeByte32(value.withdrawal_block_hash)), 0 + Byte32.size()); + array.set(new Uint8Array(SerializeUint64(value.withdrawal_block_number)), 0 + Byte32.size() + Byte32.size()); + array.set(new Uint8Array(SerializeByte32(value.sudt_script_hash)), 0 + Byte32.size() + Byte32.size() + Uint64.size()); + array.set(new Uint8Array(SerializeUint128(value.sell_amount)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size()); + array.set(new Uint8Array(SerializeUint64(value.sell_capacity)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size()); + array.set(new Uint8Array(SerializeByte32(value.owner_lock_hash)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size()); + array.set(new Uint8Array(SerializeByte32(value.payment_lock_hash)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()); + return array.buffer; +} - getOwnerLockHash() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class UnlockWithdrawalWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getLayer2Lock() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + validate(compatible = false) { + if (this.view.byteLength < 4) { + assertDataLength(this.view.byteLength, ">4"); } - - getCancelTimeout() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + new UnlockWithdrawalViaFinalize(this.view.buffer.slice(4), { validate: false }).validate(); + break; + case 1: + new UnlockWithdrawalViaRevert(this.view.buffer.slice(4), { validate: false }).validate(); + break; + case 2: + new UnlockWithdrawalViaTrade(this.view.buffer.slice(4), { validate: false }).validate(); + break; + default: + throw new Error(`Invalid type: ${t}`); } } - function SerializeDepositLockArgs(value) { - const buffers = []; - buffers.push(SerializeByte32(value.owner_lock_hash)); - buffers.push(SerializeScript(value.layer2_lock)); - buffers.push(SerializeUint64(value.cancel_timeout)); - return serializeTable(buffers); + unionType() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return "UnlockWithdrawalViaFinalize"; + case 1: + return "UnlockWithdrawalViaRevert"; + case 2: + return "UnlockWithdrawalViaTrade"; + default: + throw new Error(`Invalid type: ${t}`); + } } - class CustodianLockArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } + value() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return new UnlockWithdrawalViaFinalize(this.view.buffer.slice(4), { validate: false }); + case 1: + return new UnlockWithdrawalViaRevert(this.view.buffer.slice(4), { validate: false }); + case 2: + return new UnlockWithdrawalViaTrade(this.view.buffer.slice(4), { validate: false }); + default: + throw new Error(`Invalid type: ${t}`); } + } +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new DepositLockArgs(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Uint64(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); +export function SerializeUnlockWithdrawalWitness(value) { + switch (value.type) { + case "UnlockWithdrawalViaFinalize": + { + const itemBuffer = SerializeUnlockWithdrawalViaFinalize(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 0, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; } - - getDepositLockArgs() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new DepositLockArgs(this.view.buffer.slice(offset, offset_end), { validate: false }); + case "UnlockWithdrawalViaRevert": + { + const itemBuffer = SerializeUnlockWithdrawalViaRevert(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 1, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; } - - getDepositBlockHash() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + case "UnlockWithdrawalViaTrade": + { + const itemBuffer = SerializeUnlockWithdrawalViaTrade(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 2, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; } + default: + throw new Error(`Invalid type: ${value.type}`); + } + +} - getDepositBlockNumber() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class UnlockWithdrawalViaFinalize { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeCustodianLockArgs(value) { - const buffers = []; - buffers.push(SerializeDepositLockArgs(value.deposit_lock_args)); - buffers.push(SerializeByte32(value.deposit_block_hash)); - buffers.push(SerializeUint64(value.deposit_block_number)); - return serializeTable(buffers); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); } - class UnlockCustodianViaRevertWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } +} - getDepositLockHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } +export function SerializeUnlockWithdrawalViaFinalize(value) { + const buffers = []; + return serializeTable(buffers); +} - validate(compatible = false) { - assertDataLength(this.view.byteLength, UnlockCustodianViaRevertWitness.size()); - this.getDepositLockHash().validate(compatible); - } - static size() { - return 0 + Byte32.size(); +export class UnlockWithdrawalViaRevert { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeUnlockCustodianViaRevertWitness(value) { - const array = new Uint8Array(0 + Byte32.size()); - array.set(new Uint8Array(SerializeByte32(value.deposit_lock_hash)), 0); - return array.buffer; + getCustodianLockHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); } - class WithdrawalLockArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, UnlockWithdrawalViaRevert.size()); + this.getCustodianLockHash().validate(compatible); + } + static size() { + return 0 + Byte32.size(); + } +} - getAccountScriptHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } +export function SerializeUnlockWithdrawalViaRevert(value) { + const array = new Uint8Array(0 + Byte32.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.custodian_lock_hash)), 0); + return array.buffer; +} - getWithdrawalBlockHash() { - return new Byte32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Byte32.size()), { validate: false }); +export class UnlockWithdrawalViaTrade { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getWithdrawalBlockNumber() { - return new Uint64(this.view.buffer.slice(0 + Byte32.size() + Byte32.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size()), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Script(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + } - getSudtScriptHash() { - return new Byte32(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size()), { validate: false }); - } + getOwnerLock() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getSellAmount() { - return new Uint128(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size()), { validate: false }); - } +export function SerializeUnlockWithdrawalViaTrade(value) { + const buffers = []; + buffers.push(SerializeScript(value.owner_lock)); + return serializeTable(buffers); +} - getSellCapacity() { - return new Uint64(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size()), { validate: false }); +export class StakeLockArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getOwnerLockHash() { - return new Byte32(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()), { validate: false }); - } + getOwnerLockHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + } + + getStakeBlockNumber() { + return new Uint64(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint64.size()), { validate: false }); + } + + validate(compatible = false) { + assertDataLength(this.view.byteLength, StakeLockArgs.size()); + this.getOwnerLockHash().validate(compatible); + this.getStakeBlockNumber().validate(compatible); + } + static size() { + return 0 + Byte32.size() + Uint64.size(); + } +} + +export function SerializeStakeLockArgs(value) { + const array = new Uint8Array(0 + Byte32.size() + Uint64.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.owner_lock_hash)), 0); + array.set(new Uint8Array(SerializeUint64(value.stake_block_number)), 0 + Byte32.size()); + return array.buffer; +} - getPaymentLockHash() { - return new Byte32(this.view.buffer.slice(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size(), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()), { validate: false }); +export class MetaContractArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, WithdrawalLockArgs.size()); - this.getAccountScriptHash().validate(compatible); - this.getWithdrawalBlockHash().validate(compatible); - this.getWithdrawalBlockNumber().validate(compatible); - this.getSudtScriptHash().validate(compatible); - this.getSellAmount().validate(compatible); - this.getSellCapacity().validate(compatible); - this.getOwnerLockHash().validate(compatible); - this.getPaymentLockHash().validate(compatible); + validate(compatible = false) { + if (this.view.byteLength < 4) { + assertDataLength(this.view.byteLength, ">4"); } - static size() { - return 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size(); + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + new CreateAccount(this.view.buffer.slice(4), { validate: false }).validate(); + break; + default: + throw new Error(`Invalid type: ${t}`); } } - function SerializeWithdrawalLockArgs(value) { - const array = new Uint8Array(0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size() + Byte32.size()); - array.set(new Uint8Array(SerializeByte32(value.account_script_hash)), 0); - array.set(new Uint8Array(SerializeByte32(value.withdrawal_block_hash)), 0 + Byte32.size()); - array.set(new Uint8Array(SerializeUint64(value.withdrawal_block_number)), 0 + Byte32.size() + Byte32.size()); - array.set(new Uint8Array(SerializeByte32(value.sudt_script_hash)), 0 + Byte32.size() + Byte32.size() + Uint64.size()); - array.set(new Uint8Array(SerializeUint128(value.sell_amount)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size()); - array.set(new Uint8Array(SerializeUint64(value.sell_capacity)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size()); - array.set(new Uint8Array(SerializeByte32(value.owner_lock_hash)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size()); - array.set(new Uint8Array(SerializeByte32(value.payment_lock_hash)), 0 + Byte32.size() + Byte32.size() + Uint64.size() + Byte32.size() + Uint128.size() + Uint64.size() + Byte32.size()); - return array.buffer; - } - - class UnlockWithdrawalWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } - - validate(compatible = false) { - if (this.view.byteLength < 4) { - assertDataLength(this.view.byteLength, ">4"); - } - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - new UnlockWithdrawalViaFinalize(this.view.buffer.slice(4), { validate: false }).validate(); - break; - case 1: - new UnlockWithdrawalViaRevert(this.view.buffer.slice(4), { validate: false }).validate(); - break; - case 2: - new UnlockWithdrawalViaTrade(this.view.buffer.slice(4), { validate: false }).validate(); - break; - default: - throw new Error(`Invalid type: ${t}`); - } - } - - unionType() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return "UnlockWithdrawalViaFinalize"; - case 1: - return "UnlockWithdrawalViaRevert"; - case 2: - return "UnlockWithdrawalViaTrade"; - default: - throw new Error(`Invalid type: ${t}`); - } - } - - value() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return new UnlockWithdrawalViaFinalize(this.view.buffer.slice(4), { validate: false }); - case 1: - return new UnlockWithdrawalViaRevert(this.view.buffer.slice(4), { validate: false }); - case 2: - return new UnlockWithdrawalViaTrade(this.view.buffer.slice(4), { validate: false }); - default: - throw new Error(`Invalid type: ${t}`); - } - } - } - - function SerializeUnlockWithdrawalWitness(value) { - switch (value.type) { - case "UnlockWithdrawalViaFinalize": - { - const itemBuffer = SerializeUnlockWithdrawalViaFinalize(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 0, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } - case "UnlockWithdrawalViaRevert": - { - const itemBuffer = SerializeUnlockWithdrawalViaRevert(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 1, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } - case "UnlockWithdrawalViaTrade": - { - const itemBuffer = SerializeUnlockWithdrawalViaTrade(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 2, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } + unionType() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return "CreateAccount"; default: - throw new Error(`Invalid type: ${value.type}`); + throw new Error(`Invalid type: ${t}`); } + } + value() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return new CreateAccount(this.view.buffer.slice(4), { validate: false }); + default: + throw new Error(`Invalid type: ${t}`); + } } +} - class UnlockWithdrawalViaFinalize { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } +export function SerializeMetaContractArgs(value) { + switch (value.type) { + case "CreateAccount": + { + const itemBuffer = SerializeCreateAccount(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 0, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; } + default: + throw new Error(`Invalid type: ${value.type}`); + } + +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); +export class Fee { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } + + getSudtId() { + return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); + } + getAmount() { + return new Uint128(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint128.size()), { validate: false }); } - function SerializeUnlockWithdrawalViaFinalize(value) { - const buffers = []; - return serializeTable(buffers); + validate(compatible = false) { + assertDataLength(this.view.byteLength, Fee.size()); + this.getSudtId().validate(compatible); + this.getAmount().validate(compatible); } + static size() { + return 0 + Uint32.size() + Uint128.size(); + } +} + +export function SerializeFee(value) { + const array = new Uint8Array(0 + Uint32.size() + Uint128.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeUint32(value.sudt_id)), 0); + array.set(new Uint8Array(SerializeUint128(value.amount)), 0 + Uint32.size()); + return array.buffer; +} - class UnlockWithdrawalViaRevert { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } +export class CreateAccount { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getCustodianLockHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Script(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Fee(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + } + + getScript() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getFee() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Fee(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} + +export function SerializeCreateAccount(value) { + const buffers = []; + buffers.push(SerializeScript(value.script)); + buffers.push(SerializeFee(value.fee)); + return serializeTable(buffers); +} + +export class SUDTArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, UnlockWithdrawalViaRevert.size()); - this.getCustodianLockHash().validate(compatible); + validate(compatible = false) { + if (this.view.byteLength < 4) { + assertDataLength(this.view.byteLength, ">4"); } - static size() { - return 0 + Byte32.size(); + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + new SUDTQuery(this.view.buffer.slice(4), { validate: false }).validate(); + break; + case 1: + new SUDTTransfer(this.view.buffer.slice(4), { validate: false }).validate(); + break; + default: + throw new Error(`Invalid type: ${t}`); } } - function SerializeUnlockWithdrawalViaRevert(value) { - const array = new Uint8Array(0 + Byte32.size()); - array.set(new Uint8Array(SerializeByte32(value.custodian_lock_hash)), 0); - return array.buffer; + unionType() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return "SUDTQuery"; + case 1: + return "SUDTTransfer"; + default: + throw new Error(`Invalid type: ${t}`); + } } - class UnlockWithdrawalViaTrade { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } + value() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return new SUDTQuery(this.view.buffer.slice(4), { validate: false }); + case 1: + return new SUDTTransfer(this.view.buffer.slice(4), { validate: false }); + default: + throw new Error(`Invalid type: ${t}`); } + } +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Script(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); +export function SerializeSUDTArgs(value) { + switch (value.type) { + case "SUDTQuery": + { + const itemBuffer = SerializeSUDTQuery(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 0, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; } + case "SUDTTransfer": + { + const itemBuffer = SerializeSUDTTransfer(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 1, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; + } + default: + throw new Error(`Invalid type: ${value.type}`); + } - getOwnerLock() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); +} + +export class SUDTQuery { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeUnlockWithdrawalViaTrade(value) { - const buffers = []; - buffers.push(SerializeScript(value.owner_lock)); - return serializeTable(buffers); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Bytes(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); } - class StakeLockArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getShortAddress() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getOwnerLockHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } +export function SerializeSUDTQuery(value) { + const buffers = []; + buffers.push(SerializeBytes(value.short_address)); + return serializeTable(buffers); +} - getStakeBlockNumber() { - return new Uint64(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint64.size()), { validate: false }); +export class SUDTTransfer { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, StakeLockArgs.size()); - this.getOwnerLockHash().validate(compatible); - this.getStakeBlockNumber().validate(compatible); - } - static size() { - return 0 + Byte32.size() + Uint64.size(); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Bytes(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Uint128(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Uint128(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); } - function SerializeStakeLockArgs(value) { - const array = new Uint8Array(0 + Byte32.size() + Uint64.size()); - array.set(new Uint8Array(SerializeByte32(value.owner_lock_hash)), 0); - array.set(new Uint8Array(SerializeUint64(value.stake_block_number)), 0 + Byte32.size()); - return array.buffer; + getTo() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class MetaContractArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getAmount() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint128(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - if (this.view.byteLength < 4) { - assertDataLength(this.view.byteLength, ">4"); - } - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - new CreateAccount(this.view.buffer.slice(4), { validate: false }).validate(); - break; - default: - throw new Error(`Invalid type: ${t}`); - } - } + getFee() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Uint128(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - unionType() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return "CreateAccount"; - default: - throw new Error(`Invalid type: ${t}`); - } - } +export function SerializeSUDTTransfer(value) { + const buffers = []; + buffers.push(SerializeBytes(value.to)); + buffers.push(SerializeUint128(value.amount)); + buffers.push(SerializeUint128(value.fee)); + return serializeTable(buffers); +} - value() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return new CreateAccount(this.view.buffer.slice(4), { validate: false }); - default: - throw new Error(`Invalid type: ${t}`); - } +export class ChallengeTarget { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeMetaContractArgs(value) { - switch (value.type) { - case "CreateAccount": - { - const itemBuffer = SerializeCreateAccount(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 0, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } - default: - throw new Error(`Invalid type: ${value.type}`); - } - - } - - class CreateAccount { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } - - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Script(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - } - - getScript() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - } - - function SerializeCreateAccount(value) { - const buffers = []; - buffers.push(SerializeScript(value.script)); - return serializeTable(buffers); - } - - class SUDTArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } - - validate(compatible = false) { - if (this.view.byteLength < 4) { - assertDataLength(this.view.byteLength, ">4"); - } - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - new SUDTQuery(this.view.buffer.slice(4), { validate: false }).validate(); - break; - case 1: - new SUDTTransfer(this.view.buffer.slice(4), { validate: false }).validate(); - break; - default: - throw new Error(`Invalid type: ${t}`); - } - } - - unionType() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return "SUDTQuery"; - case 1: - return "SUDTTransfer"; - default: - throw new Error(`Invalid type: ${t}`); - } - } - - value() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return new SUDTQuery(this.view.buffer.slice(4), { validate: false }); - case 1: - return new SUDTTransfer(this.view.buffer.slice(4), { validate: false }); - default: - throw new Error(`Invalid type: ${t}`); - } - } - } - - function SerializeSUDTArgs(value) { - switch (value.type) { - case "SUDTQuery": - { - const itemBuffer = SerializeSUDTQuery(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 0, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } - case "SUDTTransfer": - { - const itemBuffer = SerializeSUDTTransfer(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 1, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } - default: - throw new Error(`Invalid type: ${value.type}`); - } + getBlockHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); + } + getTargetIndex() { + return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); } - class SUDTQuery { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getTargetType() { + return this.view.getUint8(0 + Byte32.size() + Uint32.size()); + } - getAccountId() { - return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, ChallengeTarget.size()); + this.getBlockHash().validate(compatible); + this.getTargetIndex().validate(compatible); + } + static size() { + return 0 + Byte32.size() + Uint32.size() + 1; + } +} - validate(compatible = false) { - assertDataLength(this.view.byteLength, SUDTQuery.size()); - this.getAccountId().validate(compatible); - } - static size() { - return 0 + Uint32.size(); +export function SerializeChallengeTarget(value) { + const array = new Uint8Array(0 + Byte32.size() + Uint32.size() + 1); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.block_hash)), 0); + array.set(new Uint8Array(SerializeUint32(value.target_index)), 0 + Byte32.size()); + view.setUint8(0 + Byte32.size() + Uint32.size(), value.target_type); + return array.buffer; +} + +export class ChallengeLockArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeSUDTQuery(value) { - const array = new Uint8Array(0 + Uint32.size()); - array.set(new Uint8Array(SerializeUint32(value.account_id)), 0); - return array.buffer; + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new ChallengeTarget(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Script(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); } - class SUDTTransfer { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getTarget() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new ChallengeTarget(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getTo() { - return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); - } + getRewardsReceiverLock() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getAmount() { - return new Uint128(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint128.size()), { validate: false }); - } +export function SerializeChallengeLockArgs(value) { + const buffers = []; + buffers.push(SerializeChallengeTarget(value.target)); + buffers.push(SerializeScript(value.rewards_receiver_lock)); + return serializeTable(buffers); +} - getFee() { - return new Uint128(this.view.buffer.slice(0 + Uint32.size() + Uint128.size(), 0 + Uint32.size() + Uint128.size() + Uint128.size()), { validate: false }); +export class ChallengeWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, SUDTTransfer.size()); - this.getTo().validate(compatible); - this.getAmount().validate(compatible); - this.getFee().validate(compatible); - } - static size() { - return 0 + Uint32.size() + Uint128.size() + Uint128.size(); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); } - function SerializeSUDTTransfer(value) { - const array = new Uint8Array(0 + Uint32.size() + Uint128.size() + Uint128.size()); - array.set(new Uint8Array(SerializeUint32(value.to)), 0); - array.set(new Uint8Array(SerializeUint128(value.amount)), 0 + Uint32.size()); - array.set(new Uint8Array(SerializeUint128(value.fee)), 0 + Uint32.size() + Uint128.size()); - return array.buffer; + getRawL2Block() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class ChallengeTarget { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getBlockProof() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getBlockHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } +export function SerializeChallengeWitness(value) { + const buffers = []; + buffers.push(SerializeRawL2Block(value.raw_l2block)); + buffers.push(SerializeBytes(value.block_proof)); + return serializeTable(buffers); +} - getTargetIndex() { - return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); +export class ScriptVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getTargetType() { - return this.view.getUint8(0 + Byte32.size() + Uint32.size()); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new Script(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); } + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, ChallengeTarget.size()); - this.getBlockHash().validate(compatible); - this.getTargetIndex().validate(compatible); - } - static size() { - return 0 + Byte32.size() + Uint32.size() + 1; + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; } } - function SerializeChallengeTarget(value) { - const array = new Uint8Array(0 + Byte32.size() + Uint32.size() + 1); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeByte32(value.block_hash)), 0); - array.set(new Uint8Array(SerializeUint32(value.target_index)), 0 + Byte32.size()); - view.setUint8(0 + Byte32.size() + Uint32.size(), value.target_type); - return array.buffer; + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); + } + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); } +} - class ChallengeLockArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } +export function SerializeScriptVec(value) { + return serializeTable(value.map(item => SerializeScript(item))); +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new ChallengeTarget(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Script(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); +export class BlockHashEntry { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getTarget() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new ChallengeTarget(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getNumber() { + return new Uint64(this.view.buffer.slice(0, 0 + Uint64.size()), { validate: false }); + } - getRewardsReceiverLock() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getHash() { + return new Byte32(this.view.buffer.slice(0 + Uint64.size(), 0 + Uint64.size() + Byte32.size()), { validate: false }); } - function SerializeChallengeLockArgs(value) { - const buffers = []; - buffers.push(SerializeChallengeTarget(value.target)); - buffers.push(SerializeScript(value.rewards_receiver_lock)); - return serializeTable(buffers); + validate(compatible = false) { + assertDataLength(this.view.byteLength, BlockHashEntry.size()); + this.getNumber().validate(compatible); + this.getHash().validate(compatible); } + static size() { + return 0 + Uint64.size() + Byte32.size(); + } +} - class ChallengeWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } +export function SerializeBlockHashEntry(value) { + const array = new Uint8Array(0 + Uint64.size() + Byte32.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeUint64(value.number)), 0); + array.set(new Uint8Array(SerializeByte32(value.hash)), 0 + Uint64.size()); + return array.buffer; +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); +export class BlockHashEntryVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getRawL2Block() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); + validate(compatible = false) { + if (this.view.byteLength < 4) { + dataLengthError(this.view.byteLength, ">4"); } - - getBlockProof() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + const requiredByteLength = this.length() * BlockHashEntry.size() + 4; + assertDataLength(this.view.byteLength, requiredByteLength); + for (let i = 0; i < 0; i++) { + const item = this.indexAt(i); + item.validate(compatible); } } - function SerializeChallengeWitness(value) { - const buffers = []; - buffers.push(SerializeRawL2Block(value.raw_l2block)); - buffers.push(SerializeBytes(value.block_proof)); - return serializeTable(buffers); + indexAt(i) { + return new BlockHashEntry(this.view.buffer.slice(4 + i * BlockHashEntry.size(), 4 + (i + 1) * BlockHashEntry.size()), { validate: false }); } - class ScriptVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + length() { + return this.view.getUint32(0, true); + } +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new Script(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); - } - } +export function SerializeBlockHashEntryVec(value) { + const array = new Uint8Array(4 + BlockHashEntry.size() * value.length); + (new DataView(array.buffer)).setUint32(0, value.length, true); + for (let i = 0; i < value.length; i++) { + const itemBuffer = SerializeBlockHashEntry(value[i]); + array.set(new Uint8Array(itemBuffer), 4 + i * BlockHashEntry.size()); + } + return array.buffer; +} - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; - } +export class VerifyTransactionContext { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); - } - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new KVPairVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new ScriptVec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Byte32(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new BlockHashEntryVec(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); } - function SerializeScriptVec(value) { - return serializeTable(value.map(item => SerializeScript(item))); + getAccountCount() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class BlockHashEntry { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getKvState() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new KVPairVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getNumber() { - return new Uint64(this.view.buffer.slice(0, 0 + Uint64.size()), { validate: false }); - } + getScripts() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new ScriptVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getHash() { - return new Byte32(this.view.buffer.slice(0 + Uint64.size(), 0 + Uint64.size() + Byte32.size()), { validate: false }); - } + getReturnDataHash() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, BlockHashEntry.size()); - this.getNumber().validate(compatible); - this.getHash().validate(compatible); - } - static size() { - return 0 + Uint64.size() + Byte32.size(); + getBlockHashes() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new BlockHashEntryVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} + +export function SerializeVerifyTransactionContext(value) { + const buffers = []; + buffers.push(SerializeUint32(value.account_count)); + buffers.push(SerializeKVPairVec(value.kv_state)); + buffers.push(SerializeScriptVec(value.scripts)); + buffers.push(SerializeByte32(value.return_data_hash)); + buffers.push(SerializeBlockHashEntryVec(value.block_hashes)); + return serializeTable(buffers); +} + +export class VerifyTransactionWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeBlockHashEntry(value) { - const array = new Uint8Array(0 + Uint64.size() + Byte32.size()); - array.set(new Uint8Array(SerializeUint64(value.number)), 0); - array.set(new Uint8Array(SerializeByte32(value.hash)), 0 + Uint64.size()); - return array.buffer; + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new L2Transaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new RawL2Block(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); + new VerifyTransactionContext(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); } - class BlockHashEntryVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getL2Tx() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new L2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4"); - } - const requiredByteLength = this.length() * BlockHashEntry.size() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); - for (let i = 0; i < 0; i++) { - const item = this.indexAt(i); - item.validate(compatible); - } - } + getRawL2Block() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - indexAt(i) { - return new BlockHashEntry(this.view.buffer.slice(4 + i * BlockHashEntry.size(), 4 + (i + 1) * BlockHashEntry.size()), { validate: false }); - } + getTxProof() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - length() { - return this.view.getUint32(0, true); - } + getKvStateProof() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); } - function SerializeBlockHashEntryVec(value) { - const array = new Uint8Array(4 + BlockHashEntry.size() * value.length); - (new DataView(array.buffer)).setUint32(0, value.length, true); - for (let i = 0; i < value.length; i++) { - const itemBuffer = SerializeBlockHashEntry(value[i]); - array.set(new Uint8Array(itemBuffer), 4 + i * BlockHashEntry.size()); - } - return array.buffer; + getBlockHashesProof() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class VerifyTransactionContext { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getContext() { + const start = 24; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new VerifyTransactionContext(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new KVPairVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new ScriptVec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Byte32(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new BlockHashEntryVec(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - } +export function SerializeVerifyTransactionWitness(value) { + const buffers = []; + buffers.push(SerializeL2Transaction(value.l2tx)); + buffers.push(SerializeRawL2Block(value.raw_l2block)); + buffers.push(SerializeBytes(value.tx_proof)); + buffers.push(SerializeBytes(value.kv_state_proof)); + buffers.push(SerializeBytes(value.block_hashes_proof)); + buffers.push(SerializeVerifyTransactionContext(value.context)); + return serializeTable(buffers); +} - getAccountCount() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class VerifyTransactionSignatureContext { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getKvState() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new KVPairVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new KVPairVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new ScriptVec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + } - getScripts() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new ScriptVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getAccountCount() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getReturnDataHash() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getKvState() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new KVPairVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getBlockHashes() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new BlockHashEntryVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + getScripts() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new ScriptVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} + +export function SerializeVerifyTransactionSignatureContext(value) { + const buffers = []; + buffers.push(SerializeUint32(value.account_count)); + buffers.push(SerializeKVPairVec(value.kv_state)); + buffers.push(SerializeScriptVec(value.scripts)); + return serializeTable(buffers); +} + +export class VerifyTransactionSignatureWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeVerifyTransactionContext(value) { - const buffers = []; - buffers.push(SerializeUint32(value.account_count)); - buffers.push(SerializeKVPairVec(value.kv_state)); - buffers.push(SerializeScriptVec(value.scripts)); - buffers.push(SerializeByte32(value.return_data_hash)); - buffers.push(SerializeBlockHashEntryVec(value.block_hashes)); - return serializeTable(buffers); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new L2Transaction(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new VerifyTransactionSignatureContext(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); } - class VerifyTransactionWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getRawL2Block() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new L2Transaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new RawL2Block(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - new VerifyTransactionContext(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); - } + getL2Tx() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new L2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getL2Tx() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new L2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getTxProof() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getRawL2Block() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getKvStateProof() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getTxProof() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getContext() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new VerifyTransactionSignatureContext(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getKvStateProof() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +export function SerializeVerifyTransactionSignatureWitness(value) { + const buffers = []; + buffers.push(SerializeRawL2Block(value.raw_l2block)); + buffers.push(SerializeL2Transaction(value.l2tx)); + buffers.push(SerializeBytes(value.tx_proof)); + buffers.push(SerializeBytes(value.kv_state_proof)); + buffers.push(SerializeVerifyTransactionSignatureContext(value.context)); + return serializeTable(buffers); +} - getBlockHashesProof() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class VerifyWithdrawalWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getContext() { - const start = 24; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new VerifyTransactionContext(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new WithdrawalRequest(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); } - function SerializeVerifyTransactionWitness(value) { - const buffers = []; - buffers.push(SerializeL2Transaction(value.l2tx)); - buffers.push(SerializeRawL2Block(value.raw_l2block)); - buffers.push(SerializeBytes(value.tx_proof)); - buffers.push(SerializeBytes(value.kv_state_proof)); - buffers.push(SerializeBytes(value.block_hashes_proof)); - buffers.push(SerializeVerifyTransactionContext(value.context)); - return serializeTable(buffers); + getRawL2Block() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class VerifySignatureContext { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getWithdrawalRequest() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new WithdrawalRequest(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new KVPairVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new ScriptVec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - } + getWithdrawalProof() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getAccountCount() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +export function SerializeVerifyWithdrawalWitness(value) { + const buffers = []; + buffers.push(SerializeRawL2Block(value.raw_l2block)); + buffers.push(SerializeWithdrawalRequest(value.withdrawal_request)); + buffers.push(SerializeBytes(value.withdrawal_proof)); + return serializeTable(buffers); +} - getKvState() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new KVPairVec(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class RollupSubmitBlock { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getScripts() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new ScriptVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new L2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Byte32Vec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); } - function SerializeVerifySignatureContext(value) { - const buffers = []; - buffers.push(SerializeUint32(value.account_count)); - buffers.push(SerializeKVPairVec(value.kv_state)); - buffers.push(SerializeScriptVec(value.scripts)); - return serializeTable(buffers); + getBlock() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new L2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class VerifyTransactionSignatureWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getRevertedBlockHashes() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } + + getRevertedBlockProof() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} + +export function SerializeRollupSubmitBlock(value) { + const buffers = []; + buffers.push(SerializeL2Block(value.block)); + buffers.push(SerializeByte32Vec(value.reverted_block_hashes)); + buffers.push(SerializeBytes(value.reverted_block_proof)); + return serializeTable(buffers); +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new L2Transaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new RawL2Block(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - new VerifySignatureContext(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); +export class RollupEnterChallenge { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } + + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new ChallengeWitness(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + } + + getWitness() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new ChallengeWitness(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getL2Tx() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new L2Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +export function SerializeRollupEnterChallenge(value) { + const buffers = []; + buffers.push(SerializeChallengeWitness(value.witness)); + return serializeTable(buffers); +} - getRawL2Block() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class RollupCancelChallenge { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getTxProof() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + } - getKvStateProof() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +} - getBlockHashesProof() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +export function SerializeRollupCancelChallenge(value) { + const buffers = []; + return serializeTable(buffers); +} - getContext() { - const start = 24; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new VerifySignatureContext(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class RollupRevert { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeVerifyTransactionSignatureWitness(value) { - const buffers = []; - buffers.push(SerializeL2Transaction(value.l2tx)); - buffers.push(SerializeRawL2Block(value.raw_l2block)); - buffers.push(SerializeBytes(value.tx_proof)); - buffers.push(SerializeBytes(value.kv_state_proof)); - buffers.push(SerializeBytes(value.block_hashes_proof)); - buffers.push(SerializeVerifySignatureContext(value.context)); - return serializeTable(buffers); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawL2BlockVec(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); } - class VerifyWithdrawalWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getRevertedBlocks() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawL2BlockVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new RawL2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new WithdrawalRequest(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new VerifySignatureContext(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - } + getBlockProof() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getRawL2Block() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getRevertedBlockProof() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getKvStateProof() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +export function SerializeRollupRevert(value) { + const buffers = []; + buffers.push(SerializeRawL2BlockVec(value.reverted_blocks)); + buffers.push(SerializeBytes(value.block_proof)); + buffers.push(SerializeBytes(value.reverted_block_proof)); + return serializeTable(buffers); +} - getWithdrawalRequest() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new WithdrawalRequest(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class RollupAction { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getWithdrawalProof() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + validate(compatible = false) { + if (this.view.byteLength < 4) { + assertDataLength(this.view.byteLength, ">4"); } - - getContext() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new VerifySignatureContext(this.view.buffer.slice(offset, offset_end), { validate: false }); + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + new RollupSubmitBlock(this.view.buffer.slice(4), { validate: false }).validate(); + break; + case 1: + new RollupEnterChallenge(this.view.buffer.slice(4), { validate: false }).validate(); + break; + case 2: + new RollupCancelChallenge(this.view.buffer.slice(4), { validate: false }).validate(); + break; + case 3: + new RollupRevert(this.view.buffer.slice(4), { validate: false }).validate(); + break; + default: + throw new Error(`Invalid type: ${t}`); } } - function SerializeVerifyWithdrawalWitness(value) { - const buffers = []; - buffers.push(SerializeRawL2Block(value.raw_l2block)); - buffers.push(SerializeBytes(value.kv_state_proof)); - buffers.push(SerializeWithdrawalRequest(value.withdrawal_request)); - buffers.push(SerializeBytes(value.withdrawal_proof)); - buffers.push(SerializeVerifySignatureContext(value.context)); - return serializeTable(buffers); + unionType() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return "RollupSubmitBlock"; + case 1: + return "RollupEnterChallenge"; + case 2: + return "RollupCancelChallenge"; + case 3: + return "RollupRevert"; + default: + throw new Error(`Invalid type: ${t}`); + } } - class RollupSubmitBlock { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } + value() { + const t = this.view.getUint32(0, true); + switch (t) { + case 0: + return new RollupSubmitBlock(this.view.buffer.slice(4), { validate: false }); + case 1: + return new RollupEnterChallenge(this.view.buffer.slice(4), { validate: false }); + case 2: + return new RollupCancelChallenge(this.view.buffer.slice(4), { validate: false }); + case 3: + return new RollupRevert(this.view.buffer.slice(4), { validate: false }); + default: + throw new Error(`Invalid type: ${t}`); } + } +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new L2Block(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Byte32Vec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); +export function SerializeRollupAction(value) { + switch (value.type) { + case "RollupSubmitBlock": + { + const itemBuffer = SerializeRollupSubmitBlock(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 0, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; } - - getBlock() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new L2Block(this.view.buffer.slice(offset, offset_end), { validate: false }); + case "RollupEnterChallenge": + { + const itemBuffer = SerializeRollupEnterChallenge(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 1, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; } - - getRevertedBlockHashes() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); + case "RollupCancelChallenge": + { + const itemBuffer = SerializeRollupCancelChallenge(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 2, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; } - - getRevertedBlockProof() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + case "RollupRevert": + { + const itemBuffer = SerializeRollupRevert(value.value); + const array = new Uint8Array(4 + itemBuffer.byteLength); + const view = new DataView(array.buffer); + view.setUint32(0, 3, true); + array.set(new Uint8Array(itemBuffer), 4); + return array.buffer; } + default: + throw new Error(`Invalid type: ${value.type}`); } - function SerializeRollupSubmitBlock(value) { - const buffers = []; - buffers.push(SerializeL2Block(value.block)); - buffers.push(SerializeByte32Vec(value.reverted_block_hashes)); - buffers.push(SerializeBytes(value.reverted_block_proof)); - return serializeTable(buffers); - } - - class RollupEnterChallenge { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new ChallengeWitness(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); +export class Uint16 { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getWitness() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new ChallengeWitness(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, 2); } - function SerializeRollupEnterChallenge(value) { - const buffers = []; - buffers.push(SerializeChallengeWitness(value.witness)); - return serializeTable(buffers); + indexAt(i) { + return this.view.getUint8(i); } - class RollupCancelChallenge { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + raw() { + return this.view.buffer; + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - } + toBigEndianUint16() { + return this.view.getUint16(0, false); + } + toLittleEndianUint16() { + return this.view.getUint16(0, true); } - function SerializeRollupCancelChallenge(value) { - const buffers = []; - return serializeTable(buffers); + static size() { + return 2; } +} - class RollupRevert { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } +export function SerializeUint16(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 2); + return buffer; +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new RawL2BlockVec(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); +export class Uint32 { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getRevertedBlocks() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawL2BlockVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, 4); + } - getBlockProof() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getRevertedBlockProof() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - } - - function SerializeRollupRevert(value) { - const buffers = []; - buffers.push(SerializeRawL2BlockVec(value.reverted_blocks)); - buffers.push(SerializeBytes(value.block_proof)); - buffers.push(SerializeBytes(value.reverted_block_proof)); - return serializeTable(buffers); - } - - class RollupAction { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } - - validate(compatible = false) { - if (this.view.byteLength < 4) { - assertDataLength(this.view.byteLength, ">4"); - } - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - new RollupSubmitBlock(this.view.buffer.slice(4), { validate: false }).validate(); - break; - case 1: - new RollupEnterChallenge(this.view.buffer.slice(4), { validate: false }).validate(); - break; - case 2: - new RollupCancelChallenge(this.view.buffer.slice(4), { validate: false }).validate(); - break; - case 3: - new RollupRevert(this.view.buffer.slice(4), { validate: false }).validate(); - break; - default: - throw new Error(`Invalid type: ${t}`); - } - } - - unionType() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return "RollupSubmitBlock"; - case 1: - return "RollupEnterChallenge"; - case 2: - return "RollupCancelChallenge"; - case 3: - return "RollupRevert"; - default: - throw new Error(`Invalid type: ${t}`); - } - } - - value() { - const t = this.view.getUint32(0, true); - switch (t) { - case 0: - return new RollupSubmitBlock(this.view.buffer.slice(4), { validate: false }); - case 1: - return new RollupEnterChallenge(this.view.buffer.slice(4), { validate: false }); - case 2: - return new RollupCancelChallenge(this.view.buffer.slice(4), { validate: false }); - case 3: - return new RollupRevert(this.view.buffer.slice(4), { validate: false }); - default: - throw new Error(`Invalid type: ${t}`); - } - } - } - - function SerializeRollupAction(value) { - switch (value.type) { - case "RollupSubmitBlock": - { - const itemBuffer = SerializeRollupSubmitBlock(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 0, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } - case "RollupEnterChallenge": - { - const itemBuffer = SerializeRollupEnterChallenge(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 1, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } - case "RollupCancelChallenge": - { - const itemBuffer = SerializeRollupCancelChallenge(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 2, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } - case "RollupRevert": - { - const itemBuffer = SerializeRollupRevert(value.value); - const array = new Uint8Array(4 + itemBuffer.byteLength); - const view = new DataView(array.buffer); - view.setUint32(0, 3, true); - array.set(new Uint8Array(itemBuffer), 4); - return array.buffer; - } - default: - throw new Error(`Invalid type: ${value.type}`); - } + indexAt(i) { + return this.view.getUint8(i); + } + raw() { + return this.view.buffer; } - class Uint16 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + toBigEndianUint32() { + return this.view.getUint32(0, false); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, 2); - } + toLittleEndianUint32() { + return this.view.getUint32(0, true); + } - indexAt(i) { - return this.view.getUint8(i); - } + static size() { + return 4; + } +} - raw() { - return this.view.buffer; - } +export function SerializeUint32(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 4); + return buffer; +} - toBigEndianUint16() { - return this.view.getUint16(0, false); +export class Uint64 { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - toLittleEndianUint16() { - return this.view.getUint16(0, true); - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, 8); + } - static size() { - return 2; - } + indexAt(i) { + return this.view.getUint8(i); } - function SerializeUint16(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 2); - return buffer; + raw() { + return this.view.buffer; } - class Uint32 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + toBigEndianBigUint64() { + return this.view.getBigUint64(0, false); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, 4); - } + toLittleEndianBigUint64() { + return this.view.getUint64(0, true); + } - indexAt(i) { - return this.view.getUint8(i); - } + static size() { + return 8; + } +} - raw() { - return this.view.buffer; - } +export function SerializeUint64(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 8); + return buffer; +} - toBigEndianUint32() { - return this.view.getUint32(0, false); +export class Uint128 { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - toLittleEndianUint32() { - return this.view.getUint32(0, true); - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, 16); + } - static size() { - return 4; - } + indexAt(i) { + return this.view.getUint8(i); } - function SerializeUint32(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 4); - return buffer; + raw() { + return this.view.buffer; } - class Uint64 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + static size() { + return 16; + } +} - validate(compatible = false) { - assertDataLength(this.view.byteLength, 8); - } +export function SerializeUint128(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 16); + return buffer; +} - indexAt(i) { - return this.view.getUint8(i); +export class Byte32 { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - raw() { - return this.view.buffer; - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, 32); + } - static size() { - return 8; - } + indexAt(i) { + return this.view.getUint8(i); } - function SerializeUint64(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 8); - return buffer; + raw() { + return this.view.buffer; } - class Uint128 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + static size() { + return 32; + } +} - validate(compatible = false) { - assertDataLength(this.view.byteLength, 16); - } +export function SerializeByte32(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 32); + return buffer; +} - indexAt(i) { - return this.view.getUint8(i); +export class Uint256 { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - raw() { - return this.view.buffer; - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, 32); + } - static size() { - return 16; - } + indexAt(i) { + return this.view.getUint8(i); } - function SerializeUint128(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 16); - return buffer; + raw() { + return this.view.buffer; } - class Byte32 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + static size() { + return 32; + } +} - validate(compatible = false) { - assertDataLength(this.view.byteLength, 32); - } +export function SerializeUint256(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 32); + return buffer; +} - indexAt(i) { - return this.view.getUint8(i); +export class Bytes { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - raw() { - return this.view.buffer; + validate(compatible = false) { + if (this.view.byteLength < 4) { + dataLengthError(this.view.byteLength, ">4") } + const requiredByteLength = this.length() + 4; + assertDataLength(this.view.byteLength, requiredByteLength); + } - static size() { - return 32; - } + raw() { + return this.view.buffer.slice(4); } - function SerializeByte32(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 32); - return buffer; + indexAt(i) { + return this.view.getUint8(4 + i); } - class Uint256 { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + length() { + return this.view.getUint32(0, true); + } +} - validate(compatible = false) { - assertDataLength(this.view.byteLength, 32); - } +export function SerializeBytes(value) { + const item = assertArrayBuffer(value); + const array = new Uint8Array(4 + item.byteLength); + (new DataView(array.buffer)).setUint32(0, item.byteLength, true); + array.set(new Uint8Array(item), 4); + return array.buffer; +} - indexAt(i) { - return this.view.getUint8(i); +export class BytesOpt { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - raw() { - return this.view.buffer; + validate(compatible = false) { + if (this.hasValue()) { + this.value().validate(compatible); } + } - static size() { - return 32; - } + value() { + return new Bytes(this.view.buffer, { validate: false }); } - function SerializeUint256(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 32); - return buffer; + hasValue() { + return this.view.byteLength > 0; } +} - class Bytes { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } +export function SerializeBytesOpt(value) { + if (value) { + return SerializeBytes(value); + } else { + return new ArrayBuffer(0); + } +} - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4"); - } - const requiredByteLength = this.length() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); +export class BytesVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - raw() { - return this.view.buffer.slice(4); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new Bytes(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); } + } - indexAt(i) { - return this.view.getUint8(4 + i); + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; } + } - length() { - return this.view.getUint32(0, true); + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); } + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); } +} - function SerializeBytes(value) { - const item = assertArrayBuffer(value); - const array = new Uint8Array(4 + item.byteLength); - (new DataView(array.buffer)).setUint32(0, item.byteLength, true); - array.set(new Uint8Array(item), 4); - return array.buffer; - } +export function SerializeBytesVec(value) { + return serializeTable(value.map(item => SerializeBytes(item))); +} - class BytesOpt { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } +export class Byte32Vec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - validate(compatible = false) { - if (this.hasValue()) { - this.value().validate(compatible); - } + validate(compatible = false) { + if (this.view.byteLength < 4) { + dataLengthError(this.view.byteLength, ">4"); } - - value() { - return new Bytes(this.view.buffer, { validate: false }); + const requiredByteLength = this.length() * Byte32.size() + 4; + assertDataLength(this.view.byteLength, requiredByteLength); + for (let i = 0; i < 0; i++) { + const item = this.indexAt(i); + item.validate(compatible); } + } - hasValue() { - return this.view.byteLength > 0; - } + indexAt(i) { + return new Byte32(this.view.buffer.slice(4 + i * Byte32.size(), 4 + (i + 1) * Byte32.size()), { validate: false }); } - function SerializeBytesOpt(value) { - if (value) { - return SerializeBytes(value); - } else { - return new ArrayBuffer(0); - } + length() { + return this.view.getUint32(0, true); } +} - class BytesVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } +export function SerializeByte32Vec(value) { + const array = new Uint8Array(4 + Byte32.size() * value.length); + (new DataView(array.buffer)).setUint32(0, value.length, true); + for (let i = 0; i < value.length; i++) { + const itemBuffer = SerializeByte32(value[i]); + array.set(new Uint8Array(itemBuffer), 4 + i * Byte32.size()); + } + return array.buffer; +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new Bytes(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); - } +export class ScriptOpt { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; - } + validate(compatible = false) { + if (this.hasValue()) { + this.value().validate(compatible); } + } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); - } - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + value() { + return new Script(this.view.buffer, { validate: false }); } - function SerializeBytesVec(value) { - return serializeTable(value.map(item => SerializeBytes(item))); + hasValue() { + return this.view.byteLength > 0; } +} - class Byte32Vec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } +export function SerializeScriptOpt(value) { + if (value) { + return SerializeScript(value); + } else { + return new ArrayBuffer(0); + } +} - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4"); - } - const requiredByteLength = this.length() * Byte32.size() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); - for (let i = 0; i < 0; i++) { - const item = this.indexAt(i); - item.validate(compatible); - } +export class ProposalShortId { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - indexAt(i) { - return new Byte32(this.view.buffer.slice(4 + i * Byte32.size(), 4 + (i + 1) * Byte32.size()), { validate: false }); - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, 10); + } - length() { - return this.view.getUint32(0, true); - } + indexAt(i) { + return this.view.getUint8(i); } - function SerializeByte32Vec(value) { - const array = new Uint8Array(4 + Byte32.size() * value.length); - (new DataView(array.buffer)).setUint32(0, value.length, true); - for (let i = 0; i < value.length; i++) { - const itemBuffer = SerializeByte32(value[i]); - array.set(new Uint8Array(itemBuffer), 4 + i * Byte32.size()); - } - return array.buffer; + raw() { + return this.view.buffer; } - class ScriptOpt { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + static size() { + return 10; + } +} - validate(compatible = false) { - if (this.hasValue()) { - this.value().validate(compatible); - } - } +export function SerializeProposalShortId(value) { + const buffer = assertArrayBuffer(value); + assertDataLength(buffer.byteLength, 10); + return buffer; +} - value() { - return new Script(this.view.buffer, { validate: false }); +export class UncleBlockVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - hasValue() { - return this.view.byteLength > 0; + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new UncleBlock(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); } } - function SerializeScriptOpt(value) { - if (value) { - return SerializeScript(value); + length() { + if (this.view.byteLength < 8) { + return 0; } else { - return new ArrayBuffer(0); + return this.view.getUint32(4, true) / 4 - 1; } } - class ProposalShortId { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); } + return new UncleBlock(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - validate(compatible = false) { - assertDataLength(this.view.byteLength, 10); - } +export function SerializeUncleBlockVec(value) { + return serializeTable(value.map(item => SerializeUncleBlock(item))); +} - indexAt(i) { - return this.view.getUint8(i); +export class TransactionVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - raw() { - return this.view.buffer; + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new Transaction(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); } + } - static size() { - return 10; + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; } } - function SerializeProposalShortId(value) { - const buffer = assertArrayBuffer(value); - assertDataLength(buffer.byteLength, 10); - return buffer; + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); + } + return new Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); } +} - class UncleBlockVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } +export function SerializeTransactionVec(value) { + return serializeTable(value.map(item => SerializeTransaction(item))); +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new UncleBlock(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); - } +export class ProposalShortIdVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; - } + validate(compatible = false) { + if (this.view.byteLength < 4) { + dataLengthError(this.view.byteLength, ">4"); } - - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); - } - return new UncleBlock(this.view.buffer.slice(offset, offset_end), { validate: false }); + const requiredByteLength = this.length() * ProposalShortId.size() + 4; + assertDataLength(this.view.byteLength, requiredByteLength); + for (let i = 0; i < 0; i++) { + const item = this.indexAt(i); + item.validate(compatible); } } - function SerializeUncleBlockVec(value) { - return serializeTable(value.map(item => SerializeUncleBlock(item))); + indexAt(i) { + return new ProposalShortId(this.view.buffer.slice(4 + i * ProposalShortId.size(), 4 + (i + 1) * ProposalShortId.size()), { validate: false }); } - class TransactionVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + length() { + return this.view.getUint32(0, true); + } +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new Transaction(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); - } - } +export function SerializeProposalShortIdVec(value) { + const array = new Uint8Array(4 + ProposalShortId.size() * value.length); + (new DataView(array.buffer)).setUint32(0, value.length, true); + for (let i = 0; i < value.length; i++) { + const itemBuffer = SerializeProposalShortId(value[i]); + array.set(new Uint8Array(itemBuffer), 4 + i * ProposalShortId.size()); + } + return array.buffer; +} - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; - } +export class CellDepVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); - } - return new Transaction(this.view.buffer.slice(offset, offset_end), { validate: false }); + validate(compatible = false) { + if (this.view.byteLength < 4) { + dataLengthError(this.view.byteLength, ">4"); + } + const requiredByteLength = this.length() * CellDep.size() + 4; + assertDataLength(this.view.byteLength, requiredByteLength); + for (let i = 0; i < 0; i++) { + const item = this.indexAt(i); + item.validate(compatible); } } - function SerializeTransactionVec(value) { - return serializeTable(value.map(item => SerializeTransaction(item))); + indexAt(i) { + return new CellDep(this.view.buffer.slice(4 + i * CellDep.size(), 4 + (i + 1) * CellDep.size()), { validate: false }); } - class ProposalShortIdVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + length() { + return this.view.getUint32(0, true); + } +} - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4"); - } - const requiredByteLength = this.length() * ProposalShortId.size() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); - for (let i = 0; i < 0; i++) { - const item = this.indexAt(i); - item.validate(compatible); - } - } +export function SerializeCellDepVec(value) { + const array = new Uint8Array(4 + CellDep.size() * value.length); + (new DataView(array.buffer)).setUint32(0, value.length, true); + for (let i = 0; i < value.length; i++) { + const itemBuffer = SerializeCellDep(value[i]); + array.set(new Uint8Array(itemBuffer), 4 + i * CellDep.size()); + } + return array.buffer; +} - indexAt(i) { - return new ProposalShortId(this.view.buffer.slice(4 + i * ProposalShortId.size(), 4 + (i + 1) * ProposalShortId.size()), { validate: false }); +export class CellInputVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - length() { - return this.view.getUint32(0, true); + validate(compatible = false) { + if (this.view.byteLength < 4) { + dataLengthError(this.view.byteLength, ">4"); + } + const requiredByteLength = this.length() * CellInput.size() + 4; + assertDataLength(this.view.byteLength, requiredByteLength); + for (let i = 0; i < 0; i++) { + const item = this.indexAt(i); + item.validate(compatible); } } - function SerializeProposalShortIdVec(value) { - const array = new Uint8Array(4 + ProposalShortId.size() * value.length); - (new DataView(array.buffer)).setUint32(0, value.length, true); - for (let i = 0; i < value.length; i++) { - const itemBuffer = SerializeProposalShortId(value[i]); - array.set(new Uint8Array(itemBuffer), 4 + i * ProposalShortId.size()); - } - return array.buffer; + indexAt(i) { + return new CellInput(this.view.buffer.slice(4 + i * CellInput.size(), 4 + (i + 1) * CellInput.size()), { validate: false }); } - class CellDepVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + length() { + return this.view.getUint32(0, true); + } +} - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4"); - } - const requiredByteLength = this.length() * CellDep.size() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); - for (let i = 0; i < 0; i++) { - const item = this.indexAt(i); - item.validate(compatible); - } - } +export function SerializeCellInputVec(value) { + const array = new Uint8Array(4 + CellInput.size() * value.length); + (new DataView(array.buffer)).setUint32(0, value.length, true); + for (let i = 0; i < value.length; i++) { + const itemBuffer = SerializeCellInput(value[i]); + array.set(new Uint8Array(itemBuffer), 4 + i * CellInput.size()); + } + return array.buffer; +} - indexAt(i) { - return new CellDep(this.view.buffer.slice(4 + i * CellDep.size(), 4 + (i + 1) * CellDep.size()), { validate: false }); +export class CellOutputVec { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - length() { - return this.view.getUint32(0, true); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + for (let i = 0; i < len(offsets) - 1; i++) { + new CellOutput(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); } } - function SerializeCellDepVec(value) { - const array = new Uint8Array(4 + CellDep.size() * value.length); - (new DataView(array.buffer)).setUint32(0, value.length, true); - for (let i = 0; i < value.length; i++) { - const itemBuffer = SerializeCellDep(value[i]); - array.set(new Uint8Array(itemBuffer), 4 + i * CellDep.size()); + length() { + if (this.view.byteLength < 8) { + return 0; + } else { + return this.view.getUint32(4, true) / 4 - 1; } - return array.buffer; } - class CellInputVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } + indexAt(i) { + const start = 4 + i * 4; + const offset = this.view.getUint32(start, true); + let offset_end = this.view.byteLength; + if (i + 1 < this.length()) { + offset_end = this.view.getUint32(start + 4, true); } + return new CellOutput(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - validate(compatible = false) { - if (this.view.byteLength < 4) { - dataLengthError(this.view.byteLength, ">4"); - } - const requiredByteLength = this.length() * CellInput.size() + 4; - assertDataLength(this.view.byteLength, requiredByteLength); - for (let i = 0; i < 0; i++) { - const item = this.indexAt(i); - item.validate(compatible); - } - } +export function SerializeCellOutputVec(value) { + return serializeTable(value.map(item => SerializeCellOutput(item))); +} - indexAt(i) { - return new CellInput(this.view.buffer.slice(4 + i * CellInput.size(), 4 + (i + 1) * CellInput.size()), { validate: false }); +export class Script { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - length() { - return this.view.getUint32(0, true); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + if (offsets[2] - offsets[1] !== 1) { + throw new Error(`Invalid offset for hash_type: ${offsets[1]} - ${offsets[2]}`) } + new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); } - function SerializeCellInputVec(value) { - const array = new Uint8Array(4 + CellInput.size() * value.length); - (new DataView(array.buffer)).setUint32(0, value.length, true); - for (let i = 0; i < value.length; i++) { - const itemBuffer = SerializeCellInput(value[i]); - array.set(new Uint8Array(itemBuffer), 4 + i * CellInput.size()); - } - return array.buffer; + getCodeHash() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class CellOutputVec { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getHashType() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new DataView(this.view.buffer.slice(offset, offset_end)).getUint8(0); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - for (let i = 0; i < len(offsets) - 1; i++) { - new CellOutput(this.view.buffer.slice(offsets[i], offsets[i + 1]), { validate: false }).validate(); - } - } + getArgs() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - length() { - if (this.view.byteLength < 8) { - return 0; - } else { - return this.view.getUint32(4, true) / 4 - 1; - } - } +export function SerializeScript(value) { + const buffers = []; + buffers.push(SerializeByte32(value.code_hash)); + const hashTypeView = new DataView(new ArrayBuffer(1)); + hashTypeView.setUint8(0, value.hash_type); + buffers.push(hashTypeView.buffer) + buffers.push(SerializeBytes(value.args)); + return serializeTable(buffers); +} - indexAt(i) { - const start = 4 + i * 4; - const offset = this.view.getUint32(start, true); - let offset_end = this.view.byteLength; - if (i + 1 < this.length()) { - offset_end = this.view.getUint32(start + 4, true); - } - return new CellOutput(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class OutPoint { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeCellOutputVec(value) { - return serializeTable(value.map(item => SerializeCellOutput(item))); + getTxHash() { + return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); } - class Script { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getIndex() { + return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Byte32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - if (offsets[2] - offsets[1] !== 1) { - throw new Error(`Invalid offset for hash_type: ${offsets[1]} - ${offsets[2]}`) - } - new Bytes(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, OutPoint.size()); + this.getTxHash().validate(compatible); + this.getIndex().validate(compatible); + } + static size() { + return 0 + Byte32.size() + Uint32.size(); + } +} - getCodeHash() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +export function SerializeOutPoint(value) { + const array = new Uint8Array(0 + Byte32.size() + Uint32.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeByte32(value.tx_hash)), 0); + array.set(new Uint8Array(SerializeUint32(value.index)), 0 + Byte32.size()); + return array.buffer; +} - getHashType() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new DataView(this.view.buffer.slice(offset, offset_end)).getUint8(0); +export class CellInput { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getArgs() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getSince() { + return new Uint64(this.view.buffer.slice(0, 0 + Uint64.size()), { validate: false }); } - function SerializeScript(value) { - const buffers = []; - buffers.push(SerializeByte32(value.code_hash)); - const hashTypeView = new DataView(new ArrayBuffer(1)); - hashTypeView.setUint8(0, value.hash_type); - buffers.push(hashTypeView.buffer); - buffers.push(SerializeBytes(value.args)); - return serializeTable(buffers); + getPreviousOutput() { + return new OutPoint(this.view.buffer.slice(0 + Uint64.size(), 0 + Uint64.size() + OutPoint.size()), { validate: false }); } - class OutPoint { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, CellInput.size()); + this.getSince().validate(compatible); + this.getPreviousOutput().validate(compatible); + } + static size() { + return 0 + Uint64.size() + OutPoint.size(); + } +} - getTxHash() { - return new Byte32(this.view.buffer.slice(0, 0 + Byte32.size()), { validate: false }); - } +export function SerializeCellInput(value) { + const array = new Uint8Array(0 + Uint64.size() + OutPoint.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeUint64(value.since)), 0); + array.set(new Uint8Array(SerializeOutPoint(value.previous_output)), 0 + Uint64.size()); + return array.buffer; +} - getIndex() { - return new Uint32(this.view.buffer.slice(0 + Byte32.size(), 0 + Byte32.size() + Uint32.size()), { validate: false }); +export class CellOutput { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, OutPoint.size()); - this.getTxHash().validate(compatible); - this.getIndex().validate(compatible); - } - static size() { - return 0 + Byte32.size() + Uint32.size(); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Script(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new ScriptOpt(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); } - function SerializeOutPoint(value) { - const array = new Uint8Array(0 + Byte32.size() + Uint32.size()); - array.set(new Uint8Array(SerializeByte32(value.tx_hash)), 0); - array.set(new Uint8Array(SerializeUint32(value.index)), 0 + Byte32.size()); - return array.buffer; + getCapacity() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class CellInput { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getLock() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getSince() { - return new Uint64(this.view.buffer.slice(0, 0 + Uint64.size()), { validate: false }); - } + getType() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new ScriptOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getPreviousOutput() { - return new OutPoint(this.view.buffer.slice(0 + Uint64.size(), 0 + Uint64.size() + OutPoint.size()), { validate: false }); - } +export function SerializeCellOutput(value) { + const buffers = []; + buffers.push(SerializeUint64(value.capacity)); + buffers.push(SerializeScript(value.lock)); + buffers.push(SerializeScriptOpt(value.type_)); + return serializeTable(buffers); +} - validate(compatible = false) { - assertDataLength(this.view.byteLength, CellInput.size()); - this.getSince().validate(compatible); - this.getPreviousOutput().validate(compatible); - } - static size() { - return 0 + Uint64.size() + OutPoint.size(); +export class CellDep { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeCellInput(value) { - const array = new Uint8Array(0 + Uint64.size() + OutPoint.size()); - array.set(new Uint8Array(SerializeUint64(value.since)), 0); - array.set(new Uint8Array(SerializeOutPoint(value.previous_output)), 0 + Uint64.size()); - return array.buffer; + getOutPoint() { + return new OutPoint(this.view.buffer.slice(0, 0 + OutPoint.size()), { validate: false }); } - class CellOutput { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getDepType() { + return this.view.getUint8(0 + OutPoint.size()); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint64(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Script(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new ScriptOpt(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, CellDep.size()); + this.getOutPoint().validate(compatible); + } + static size() { + return 0 + OutPoint.size() + 1; + } +} - getCapacity() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint64(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +export function SerializeCellDep(value) { + const array = new Uint8Array(0 + OutPoint.size() + 1); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeOutPoint(value.out_point)), 0); + view.setUint8(0 + OutPoint.size(), value.dep_type); + return array.buffer; +} - getLock() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class RawTransaction { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getType() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new ScriptOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new CellDepVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new Byte32Vec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new CellInputVec(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); + new CellOutputVec(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); + new BytesVec(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); } - function SerializeCellOutput(value) { - const buffers = []; - buffers.push(SerializeUint64(value.capacity)); - buffers.push(SerializeScript(value.lock)); - buffers.push(SerializeScriptOpt(value.type_)); - return serializeTable(buffers); + getVersion() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class CellDep { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getCellDeps() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new CellDepVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getOutPoint() { - return new OutPoint(this.view.buffer.slice(0, 0 + OutPoint.size()), { validate: false }); - } + getHeaderDeps() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getDepType() { - return this.view.getUint8(0 + OutPoint.size()); - } + getInputs() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new CellInputVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, CellDep.size()); - this.getOutPoint().validate(compatible); - } - static size() { - return 0 + OutPoint.size() + 1; - } + getOutputs() { + const start = 20; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new CellOutputVec(this.view.buffer.slice(offset, offset_end), { validate: false }); } - function SerializeCellDep(value) { - const array = new Uint8Array(0 + OutPoint.size() + 1); - const view = new DataView(array.buffer); - array.set(new Uint8Array(SerializeOutPoint(value.out_point)), 0); - view.setUint8(0 + OutPoint.size(), value.dep_type); - return array.buffer; + getOutputsData() { + const start = 24; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new BytesVec(this.view.buffer.slice(offset, offset_end), { validate: false }); } +} - class RawTransaction { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } +export function SerializeRawTransaction(value) { + const buffers = []; + buffers.push(SerializeUint32(value.version)); + buffers.push(SerializeCellDepVec(value.cell_deps)); + buffers.push(SerializeByte32Vec(value.header_deps)); + buffers.push(SerializeCellInputVec(value.inputs)); + buffers.push(SerializeCellOutputVec(value.outputs)); + buffers.push(SerializeBytesVec(value.outputs_data)); + return serializeTable(buffers); +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Uint32(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new CellDepVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new Byte32Vec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new CellInputVec(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - new CellOutputVec(this.view.buffer.slice(offsets[4], offsets[5]), { validate: false }).validate(); - new BytesVec(this.view.buffer.slice(offsets[5], offsets[6]), { validate: false }).validate(); +export class Transaction { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getVersion() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Uint32(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new RawTransaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new BytesVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + } - getCellDeps() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new CellDepVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getRaw() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new RawTransaction(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getHeaderDeps() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Byte32Vec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getWitnesses() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new BytesVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getInputs() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new CellInputVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +export function SerializeTransaction(value) { + const buffers = []; + buffers.push(SerializeRawTransaction(value.raw)); + buffers.push(SerializeBytesVec(value.witnesses)); + return serializeTable(buffers); +} - getOutputs() { - const start = 20; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new CellOutputVec(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class RawHeader { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getOutputsData() { - const start = 24; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new BytesVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getVersion() { + return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); } - function SerializeRawTransaction(value) { - const buffers = []; - buffers.push(SerializeUint32(value.version)); - buffers.push(SerializeCellDepVec(value.cell_deps)); - buffers.push(SerializeByte32Vec(value.header_deps)); - buffers.push(SerializeCellInputVec(value.inputs)); - buffers.push(SerializeCellOutputVec(value.outputs)); - buffers.push(SerializeBytesVec(value.outputs_data)); - return serializeTable(buffers); + getCompactTarget() { + return new Uint32(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint32.size()), { validate: false }); } - class Transaction { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getTimestamp() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size()), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new RawTransaction(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new BytesVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - } + getNumber() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size()), { validate: false }); + } - getRaw() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new RawTransaction(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getEpoch() { + return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size()), { validate: false }); + } - getWitnesses() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new BytesVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getParentHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size()), { validate: false }); } - function SerializeTransaction(value) { - const buffers = []; - buffers.push(SerializeRawTransaction(value.raw)); - buffers.push(SerializeBytesVec(value.witnesses)); - return serializeTable(buffers); + getTransactionsRoot() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size()), { validate: false }); } - class RawHeader { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getProposalsHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size()), { validate: false }); + } - getVersion() { - return new Uint32(this.view.buffer.slice(0, 0 + Uint32.size()), { validate: false }); - } + getUnclesHash() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()), { validate: false }); + } - getCompactTarget() { - return new Uint32(this.view.buffer.slice(0 + Uint32.size(), 0 + Uint32.size() + Uint32.size()), { validate: false }); - } + getDao() { + return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()), { validate: false }); + } - getTimestamp() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size()), { validate: false }); - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, RawHeader.size()); + this.getVersion().validate(compatible); + this.getCompactTarget().validate(compatible); + this.getTimestamp().validate(compatible); + this.getNumber().validate(compatible); + this.getEpoch().validate(compatible); + this.getParentHash().validate(compatible); + this.getTransactionsRoot().validate(compatible); + this.getProposalsHash().validate(compatible); + this.getUnclesHash().validate(compatible); + this.getDao().validate(compatible); + } + static size() { + return 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size(); + } +} - getNumber() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size()), { validate: false }); - } +export function SerializeRawHeader(value) { + const array = new Uint8Array(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeUint32(value.version)), 0); + array.set(new Uint8Array(SerializeUint32(value.compact_target)), 0 + Uint32.size()); + array.set(new Uint8Array(SerializeUint64(value.timestamp)), 0 + Uint32.size() + Uint32.size()); + array.set(new Uint8Array(SerializeUint64(value.number)), 0 + Uint32.size() + Uint32.size() + Uint64.size()); + array.set(new Uint8Array(SerializeUint64(value.epoch)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size()); + array.set(new Uint8Array(SerializeByte32(value.parent_hash)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size()); + array.set(new Uint8Array(SerializeByte32(value.transactions_root)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size()); + array.set(new Uint8Array(SerializeByte32(value.proposals_hash)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size()); + array.set(new Uint8Array(SerializeByte32(value.uncles_hash)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size()); + array.set(new Uint8Array(SerializeByte32(value.dao)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()); + return array.buffer; +} - getEpoch() { - return new Uint64(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size()), { validate: false }); +export class Header { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getParentHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size()), { validate: false }); - } + getRaw() { + return new RawHeader(this.view.buffer.slice(0, 0 + RawHeader.size()), { validate: false }); + } - getTransactionsRoot() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size()), { validate: false }); - } + getNonce() { + return new Uint128(this.view.buffer.slice(0 + RawHeader.size(), 0 + RawHeader.size() + Uint128.size()), { validate: false }); + } - getProposalsHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size()), { validate: false }); - } + validate(compatible = false) { + assertDataLength(this.view.byteLength, Header.size()); + this.getRaw().validate(compatible); + this.getNonce().validate(compatible); + } + static size() { + return 0 + RawHeader.size() + Uint128.size(); + } +} - getUnclesHash() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()), { validate: false }); - } +export function SerializeHeader(value) { + const array = new Uint8Array(0 + RawHeader.size() + Uint128.size()); + const view = new DataView(array.buffer); + array.set(new Uint8Array(SerializeRawHeader(value.raw)), 0); + array.set(new Uint8Array(SerializeUint128(value.nonce)), 0 + RawHeader.size()); + return array.buffer; +} - getDao() { - return new Byte32(this.view.buffer.slice(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size(), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()), { validate: false }); +export class UncleBlock { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, RawHeader.size()); - this.getVersion().validate(compatible); - this.getCompactTarget().validate(compatible); - this.getTimestamp().validate(compatible); - this.getNumber().validate(compatible); - this.getEpoch().validate(compatible); - this.getParentHash().validate(compatible); - this.getTransactionsRoot().validate(compatible); - this.getProposalsHash().validate(compatible); - this.getUnclesHash().validate(compatible); - this.getDao().validate(compatible); - } - static size() { - return 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size(); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Header(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new ProposalShortIdVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); } - function SerializeRawHeader(value) { - const array = new Uint8Array(0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()); - array.set(new Uint8Array(SerializeUint32(value.version)), 0); - array.set(new Uint8Array(SerializeUint32(value.compact_target)), 0 + Uint32.size()); - array.set(new Uint8Array(SerializeUint64(value.timestamp)), 0 + Uint32.size() + Uint32.size()); - array.set(new Uint8Array(SerializeUint64(value.number)), 0 + Uint32.size() + Uint32.size() + Uint64.size()); - array.set(new Uint8Array(SerializeUint64(value.epoch)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size()); - array.set(new Uint8Array(SerializeByte32(value.parent_hash)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size()); - array.set(new Uint8Array(SerializeByte32(value.transactions_root)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size()); - array.set(new Uint8Array(SerializeByte32(value.proposals_hash)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size()); - array.set(new Uint8Array(SerializeByte32(value.uncles_hash)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size()); - array.set(new Uint8Array(SerializeByte32(value.dao)), 0 + Uint32.size() + Uint32.size() + Uint64.size() + Uint64.size() + Uint64.size() + Byte32.size() + Byte32.size() + Byte32.size() + Byte32.size()); - return array.buffer; + getHeader() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Header(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class Header { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getProposals() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getRaw() { - return new RawHeader(this.view.buffer.slice(0, 0 + RawHeader.size()), { validate: false }); - } +export function SerializeUncleBlock(value) { + const buffers = []; + buffers.push(SerializeHeader(value.header)); + buffers.push(SerializeProposalShortIdVec(value.proposals)); + return serializeTable(buffers); +} - getNonce() { - return new Uint128(this.view.buffer.slice(0 + RawHeader.size(), 0 + RawHeader.size() + Uint128.size()), { validate: false }); +export class Block { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - validate(compatible = false) { - assertDataLength(this.view.byteLength, Header.size()); - this.getRaw().validate(compatible); - this.getNonce().validate(compatible); - } - static size() { - return 0 + RawHeader.size() + Uint128.size(); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Header(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new UncleBlockVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new TransactionVec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + new ProposalShortIdVec(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); } - function SerializeHeader(value) { - const array = new Uint8Array(0 + RawHeader.size() + Uint128.size()); - array.set(new Uint8Array(SerializeRawHeader(value.raw)), 0); - array.set(new Uint8Array(SerializeUint128(value.nonce)), 0 + RawHeader.size()); - return array.buffer; + getHeader() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Header(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class UncleBlock { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getUncles() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new UncleBlockVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Header(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new ProposalShortIdVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - } + getTransactions() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new TransactionVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - getHeader() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Header(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getProposals() { + const start = 16; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} + +export function SerializeBlock(value) { + const buffers = []; + buffers.push(SerializeHeader(value.header)); + buffers.push(SerializeUncleBlockVec(value.uncles)); + buffers.push(SerializeTransactionVec(value.transactions)); + buffers.push(SerializeProposalShortIdVec(value.proposals)); + return serializeTable(buffers); +} - getProposals() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class CellbaseWitness { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } } - function SerializeUncleBlock(value) { - const buffers = []; - buffers.push(SerializeHeader(value.header)); - buffers.push(SerializeProposalShortIdVec(value.proposals)); - return serializeTable(buffers); + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new Script(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); } - class Block { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getLock() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); + } - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Header(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new UncleBlockVec(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new TransactionVec(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - new ProposalShortIdVec(this.view.buffer.slice(offsets[3], offsets[4]), { validate: false }).validate(); - } + getMessage() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - getHeader() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Header(this.view.buffer.slice(offset, offset_end), { validate: false }); - } +export function SerializeCellbaseWitness(value) { + const buffers = []; + buffers.push(SerializeScript(value.lock)); + buffers.push(SerializeBytes(value.message)); + return serializeTable(buffers); +} - getUncles() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new UncleBlockVec(this.view.buffer.slice(offset, offset_end), { validate: false }); +export class WitnessArgs { + constructor(reader, { validate = true } = {}) { + this.view = new DataView(assertArrayBuffer(reader)); + if (validate) { + this.validate(); } + } - getTransactions() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new TransactionVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + validate(compatible = false) { + const offsets = verifyAndExtractOffsets(this.view, 0, true); + new BytesOpt(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); + new BytesOpt(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); + new BytesOpt(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); + } - getProposals() { - const start = 16; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new ProposalShortIdVec(this.view.buffer.slice(offset, offset_end), { validate: false }); - } + getLock() { + const start = 4; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new BytesOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); } - function SerializeBlock(value) { - const buffers = []; - buffers.push(SerializeHeader(value.header)); - buffers.push(SerializeUncleBlockVec(value.uncles)); - buffers.push(SerializeTransactionVec(value.transactions)); - buffers.push(SerializeProposalShortIdVec(value.proposals)); - return serializeTable(buffers); + getInputType() { + const start = 8; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.getUint32(start + 4, true); + return new BytesOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); } - class CellbaseWitness { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } + getOutputType() { + const start = 12; + const offset = this.view.getUint32(start, true); + const offset_end = this.view.byteLength; + return new BytesOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); + } +} - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new Script(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new Bytes(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - } +export function SerializeWitnessArgs(value) { + const buffers = []; + buffers.push(SerializeBytesOpt(value.lock)); + buffers.push(SerializeBytesOpt(value.input_type)); + buffers.push(SerializeBytesOpt(value.output_type)); + return serializeTable(buffers); +} - getLock() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new Script(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getMessage() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new Bytes(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - } - - function SerializeCellbaseWitness(value) { - const buffers = []; - buffers.push(SerializeScript(value.lock)); - buffers.push(SerializeBytes(value.message)); - return serializeTable(buffers); - } - - class WitnessArgs { - constructor(reader, { validate = true } = {}) { - this.view = new DataView(assertArrayBuffer(reader)); - if (validate) { - this.validate(); - } - } - - validate(compatible = false) { - const offsets = verifyAndExtractOffsets(this.view, 0, true); - new BytesOpt(this.view.buffer.slice(offsets[0], offsets[1]), { validate: false }).validate(); - new BytesOpt(this.view.buffer.slice(offsets[1], offsets[2]), { validate: false }).validate(); - new BytesOpt(this.view.buffer.slice(offsets[2], offsets[3]), { validate: false }).validate(); - } - - getLock() { - const start = 4; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new BytesOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getInputType() { - const start = 8; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.getUint32(start + 4, true); - return new BytesOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - - getOutputType() { - const start = 12; - const offset = this.view.getUint32(start, true); - const offset_end = this.view.byteLength; - return new BytesOpt(this.view.buffer.slice(offset, offset_end), { validate: false }); - } - } - - function SerializeWitnessArgs(value) { - const buffers = []; - buffers.push(SerializeBytesOpt(value.lock)); - buffers.push(SerializeBytesOpt(value.input_type)); - buffers.push(SerializeBytesOpt(value.output_type)); - return serializeTable(buffers); - } - - exports.AccountMerkleState = AccountMerkleState; - exports.Block = Block; - exports.BlockHashEntry = BlockHashEntry; - exports.BlockHashEntryVec = BlockHashEntryVec; - exports.BlockInfo = BlockInfo; - exports.BlockMerkleState = BlockMerkleState; - exports.Byte20 = Byte20; - exports.Byte32 = Byte32; - exports.Byte32Opt = Byte32Opt; - exports.Byte32Vec = Byte32Vec; - exports.Bytes = Bytes; - exports.BytesOpt = BytesOpt; - exports.BytesVec = BytesVec; - exports.CellDep = CellDep; - exports.CellDepVec = CellDepVec; - exports.CellInput = CellInput; - exports.CellInputVec = CellInputVec; - exports.CellOutput = CellOutput; - exports.CellOutputVec = CellOutputVec; - exports.CellbaseWitness = CellbaseWitness; - exports.ChallengeLockArgs = ChallengeLockArgs; - exports.ChallengeTarget = ChallengeTarget; - exports.ChallengeWitness = ChallengeWitness; - exports.CreateAccount = CreateAccount; - exports.CustodianLockArgs = CustodianLockArgs; - exports.DepositLockArgs = DepositLockArgs; - exports.DepositRequest = DepositRequest; - exports.DepositRequestVec = DepositRequestVec; - exports.GlobalState = GlobalState; - exports.Header = Header; - exports.KVPair = KVPair; - exports.KVPairVec = KVPairVec; - exports.L2Block = L2Block; - exports.L2Transaction = L2Transaction; - exports.L2TransactionVec = L2TransactionVec; - exports.MetaContractArgs = MetaContractArgs; - exports.OutPoint = OutPoint; - exports.ProposalShortId = ProposalShortId; - exports.ProposalShortIdVec = ProposalShortIdVec; - exports.RawHeader = RawHeader; - exports.RawL2Block = RawL2Block; - exports.RawL2BlockVec = RawL2BlockVec; - exports.RawL2Transaction = RawL2Transaction; - exports.RawTransaction = RawTransaction; - exports.RawWithdrawalRequest = RawWithdrawalRequest; - exports.RollupAction = RollupAction; - exports.RollupCancelChallenge = RollupCancelChallenge; - exports.RollupConfig = RollupConfig; - exports.RollupEnterChallenge = RollupEnterChallenge; - exports.RollupRevert = RollupRevert; - exports.RollupSubmitBlock = RollupSubmitBlock; - exports.SUDTArgs = SUDTArgs; - exports.SUDTQuery = SUDTQuery; - exports.SUDTTransfer = SUDTTransfer; - exports.Script = Script; - exports.ScriptOpt = ScriptOpt; - exports.ScriptVec = ScriptVec; - exports.SerializeAccountMerkleState = SerializeAccountMerkleState; - exports.SerializeBlock = SerializeBlock; - exports.SerializeBlockHashEntry = SerializeBlockHashEntry; - exports.SerializeBlockHashEntryVec = SerializeBlockHashEntryVec; - exports.SerializeBlockInfo = SerializeBlockInfo; - exports.SerializeBlockMerkleState = SerializeBlockMerkleState; - exports.SerializeByte20 = SerializeByte20; - exports.SerializeByte32 = SerializeByte32; - exports.SerializeByte32Opt = SerializeByte32Opt; - exports.SerializeByte32Vec = SerializeByte32Vec; - exports.SerializeBytes = SerializeBytes; - exports.SerializeBytesOpt = SerializeBytesOpt; - exports.SerializeBytesVec = SerializeBytesVec; - exports.SerializeCellDep = SerializeCellDep; - exports.SerializeCellDepVec = SerializeCellDepVec; - exports.SerializeCellInput = SerializeCellInput; - exports.SerializeCellInputVec = SerializeCellInputVec; - exports.SerializeCellOutput = SerializeCellOutput; - exports.SerializeCellOutputVec = SerializeCellOutputVec; - exports.SerializeCellbaseWitness = SerializeCellbaseWitness; - exports.SerializeChallengeLockArgs = SerializeChallengeLockArgs; - exports.SerializeChallengeTarget = SerializeChallengeTarget; - exports.SerializeChallengeWitness = SerializeChallengeWitness; - exports.SerializeCreateAccount = SerializeCreateAccount; - exports.SerializeCustodianLockArgs = SerializeCustodianLockArgs; - exports.SerializeDepositLockArgs = SerializeDepositLockArgs; - exports.SerializeDepositRequest = SerializeDepositRequest; - exports.SerializeDepositRequestVec = SerializeDepositRequestVec; - exports.SerializeGlobalState = SerializeGlobalState; - exports.SerializeHeader = SerializeHeader; - exports.SerializeKVPair = SerializeKVPair; - exports.SerializeKVPairVec = SerializeKVPairVec; - exports.SerializeL2Block = SerializeL2Block; - exports.SerializeL2Transaction = SerializeL2Transaction; - exports.SerializeL2TransactionVec = SerializeL2TransactionVec; - exports.SerializeMetaContractArgs = SerializeMetaContractArgs; - exports.SerializeOutPoint = SerializeOutPoint; - exports.SerializeProposalShortId = SerializeProposalShortId; - exports.SerializeProposalShortIdVec = SerializeProposalShortIdVec; - exports.SerializeRawHeader = SerializeRawHeader; - exports.SerializeRawL2Block = SerializeRawL2Block; - exports.SerializeRawL2BlockVec = SerializeRawL2BlockVec; - exports.SerializeRawL2Transaction = SerializeRawL2Transaction; - exports.SerializeRawTransaction = SerializeRawTransaction; - exports.SerializeRawWithdrawalRequest = SerializeRawWithdrawalRequest; - exports.SerializeRollupAction = SerializeRollupAction; - exports.SerializeRollupCancelChallenge = SerializeRollupCancelChallenge; - exports.SerializeRollupConfig = SerializeRollupConfig; - exports.SerializeRollupEnterChallenge = SerializeRollupEnterChallenge; - exports.SerializeRollupRevert = SerializeRollupRevert; - exports.SerializeRollupSubmitBlock = SerializeRollupSubmitBlock; - exports.SerializeSUDTArgs = SerializeSUDTArgs; - exports.SerializeSUDTQuery = SerializeSUDTQuery; - exports.SerializeSUDTTransfer = SerializeSUDTTransfer; - exports.SerializeScript = SerializeScript; - exports.SerializeScriptOpt = SerializeScriptOpt; - exports.SerializeScriptVec = SerializeScriptVec; - exports.SerializeSignature = SerializeSignature; - exports.SerializeStakeLockArgs = SerializeStakeLockArgs; - exports.SerializeSubmitTransactions = SerializeSubmitTransactions; - exports.SerializeSubmitWithdrawals = SerializeSubmitWithdrawals; - exports.SerializeTransaction = SerializeTransaction; - exports.SerializeTransactionVec = SerializeTransactionVec; - exports.SerializeUint128 = SerializeUint128; - exports.SerializeUint16 = SerializeUint16; - exports.SerializeUint256 = SerializeUint256; - exports.SerializeUint32 = SerializeUint32; - exports.SerializeUint64 = SerializeUint64; - exports.SerializeUncleBlock = SerializeUncleBlock; - exports.SerializeUncleBlockVec = SerializeUncleBlockVec; - exports.SerializeUnlockCustodianViaRevertWitness = SerializeUnlockCustodianViaRevertWitness; - exports.SerializeUnlockWithdrawalViaFinalize = SerializeUnlockWithdrawalViaFinalize; - exports.SerializeUnlockWithdrawalViaRevert = SerializeUnlockWithdrawalViaRevert; - exports.SerializeUnlockWithdrawalViaTrade = SerializeUnlockWithdrawalViaTrade; - exports.SerializeUnlockWithdrawalWitness = SerializeUnlockWithdrawalWitness; - exports.SerializeVerifySignatureContext = SerializeVerifySignatureContext; - exports.SerializeVerifyTransactionContext = SerializeVerifyTransactionContext; - exports.SerializeVerifyTransactionSignatureWitness = SerializeVerifyTransactionSignatureWitness; - exports.SerializeVerifyTransactionWitness = SerializeVerifyTransactionWitness; - exports.SerializeVerifyWithdrawalWitness = SerializeVerifyWithdrawalWitness; - exports.SerializeWithdrawalLockArgs = SerializeWithdrawalLockArgs; - exports.SerializeWithdrawalRequest = SerializeWithdrawalRequest; - exports.SerializeWithdrawalRequestVec = SerializeWithdrawalRequestVec; - exports.SerializeWitnessArgs = SerializeWitnessArgs; - exports.Signature = Signature; - exports.StakeLockArgs = StakeLockArgs; - exports.SubmitTransactions = SubmitTransactions; - exports.SubmitWithdrawals = SubmitWithdrawals; - exports.Transaction = Transaction; - exports.TransactionVec = TransactionVec; - exports.Uint128 = Uint128; - exports.Uint16 = Uint16; - exports.Uint256 = Uint256; - exports.Uint32 = Uint32; - exports.Uint64 = Uint64; - exports.UncleBlock = UncleBlock; - exports.UncleBlockVec = UncleBlockVec; - exports.UnlockCustodianViaRevertWitness = UnlockCustodianViaRevertWitness; - exports.UnlockWithdrawalViaFinalize = UnlockWithdrawalViaFinalize; - exports.UnlockWithdrawalViaRevert = UnlockWithdrawalViaRevert; - exports.UnlockWithdrawalViaTrade = UnlockWithdrawalViaTrade; - exports.UnlockWithdrawalWitness = UnlockWithdrawalWitness; - exports.VerifySignatureContext = VerifySignatureContext; - exports.VerifyTransactionContext = VerifyTransactionContext; - exports.VerifyTransactionSignatureWitness = VerifyTransactionSignatureWitness; - exports.VerifyTransactionWitness = VerifyTransactionWitness; - exports.VerifyWithdrawalWitness = VerifyWithdrawalWitness; - exports.WithdrawalLockArgs = WithdrawalLockArgs; - exports.WithdrawalRequest = WithdrawalRequest; - exports.WithdrawalRequestVec = WithdrawalRequestVec; - exports.WitnessArgs = WitnessArgs; - - Object.defineProperty(exports, '__esModule', { value: true }); - -}))); diff --git a/packages/godwoken/schemas/index.json b/packages/godwoken/schemas/index.json index b5a8aaba..ce1d01f8 100644 --- a/packages/godwoken/schemas/index.json +++ b/packages/godwoken/schemas/index.json @@ -8,23 +8,6 @@ } ], "declarations": [ - { - "type": "option", - "name": "Byte32Opt", - "item": "Byte32" - }, - { - "type": "array", - "name": "Byte20", - "item": "byte", - "item_count": 20 - }, - { - "type": "array", - "name": "Signature", - "item": "byte", - "item_count": 65 - }, { "type": "struct", "name": "BlockMerkleState", @@ -135,10 +118,6 @@ "name": "finality_blocks", "type": "Uint64" }, - { - "name": "compatible_chain_id", - "type": "Uint32" - }, { "name": "reward_burn_rate", "type": "byte" @@ -185,7 +164,7 @@ }, { "name": "signature", - "type": "Signature" + "type": "Bytes" } ] }, @@ -373,16 +352,20 @@ { "name": "payment_lock_hash", "type": "Byte32" + }, + { + "name": "fee", + "type": "Fee" } ] }, { - "type": "fixvec", + "type": "dynvec", "name": "WithdrawalRequestVec", "item": "WithdrawalRequest" }, { - "type": "struct", + "type": "table", "name": "WithdrawalRequest", "fields": [ { @@ -391,7 +374,7 @@ }, { "name": "signature", - "type": "Signature" + "type": "Bytes" } ] }, @@ -571,6 +554,20 @@ "CreateAccount" ] }, + { + "type": "struct", + "name": "Fee", + "fields": [ + { + "name": "sudt_id", + "type": "Uint32" + }, + { + "name": "amount", + "type": "Uint128" + } + ] + }, { "type": "table", "name": "CreateAccount", @@ -578,6 +575,10 @@ { "name": "script", "type": "Script" + }, + { + "name": "fee", + "type": "Fee" } ] }, @@ -590,22 +591,22 @@ ] }, { - "type": "struct", + "type": "table", "name": "SUDTQuery", "fields": [ { - "name": "account_id", - "type": "Uint32" + "name": "short_address", + "type": "Bytes" } ] }, { - "type": "struct", + "type": "table", "name": "SUDTTransfer", "fields": [ { "name": "to", - "type": "Uint32" + "type": "Bytes" }, { "name": "amount", @@ -745,7 +746,7 @@ }, { "type": "table", - "name": "VerifySignatureContext", + "name": "VerifyTransactionSignatureContext", "fields": [ { "name": "account_count", @@ -765,29 +766,25 @@ "type": "table", "name": "VerifyTransactionSignatureWitness", "fields": [ - { - "name": "l2tx", - "type": "L2Transaction" - }, { "name": "raw_l2block", "type": "RawL2Block" }, { - "name": "tx_proof", - "type": "Bytes" + "name": "l2tx", + "type": "L2Transaction" }, { - "name": "kv_state_proof", + "name": "tx_proof", "type": "Bytes" }, { - "name": "block_hashes_proof", + "name": "kv_state_proof", "type": "Bytes" }, { "name": "context", - "type": "VerifySignatureContext" + "type": "VerifyTransactionSignatureContext" } ] }, @@ -799,10 +796,6 @@ "name": "raw_l2block", "type": "RawL2Block" }, - { - "name": "kv_state_proof", - "type": "Bytes" - }, { "name": "withdrawal_request", "type": "WithdrawalRequest" @@ -810,10 +803,6 @@ { "name": "withdrawal_proof", "type": "Bytes" - }, - { - "name": "context", - "type": "VerifySignatureContext" } ] }, diff --git a/packages/godwoken/src/types.ts b/packages/godwoken/src/types.ts index baf45c64..91ae33f8 100644 --- a/packages/godwoken/src/types.ts +++ b/packages/godwoken/src/types.ts @@ -85,6 +85,16 @@ export interface L2Transaction { signature: HexString; } +export function NormalizeFee( + fee: object, + { debugPath = "fee" } = {} +) { + return normalizeObject(debugPath, fee, { + sudt_id: normalizeHexNumber(4), + amount: normalizeHexNumber(16), + }) +} + export function NormalizeRawL2Transaction( rawL2Transaction: object, { debugPath = "raw_l2_transaction" } = {}