From 09564da63dc1aa88f3c8668ce8854b07369c0911 Mon Sep 17 00:00:00 2001 From: Oleksandr Myshchyshyn Date: Wed, 18 Dec 2024 13:52:51 +0200 Subject: [PATCH] Fix: Transform Raw serialization, removed message topics from addresable entity, EntryPointPayment change --- src/types/AddressableEntity.ts | 7 --- src/types/EntryPoint.ts | 11 +++- src/types/Transform.ts | 107 +------------------------------- src/types/TransformRaw.ts | 110 ++++++++++++++++++++++++++++++++- src/types/key/Key.ts | 20 +++--- 5 files changed, 128 insertions(+), 127 deletions(-) diff --git a/src/types/AddressableEntity.ts b/src/types/AddressableEntity.ts index 83123afd..248f7f64 100644 --- a/src/types/AddressableEntity.ts +++ b/src/types/AddressableEntity.ts @@ -1,6 +1,5 @@ import { jsonObject, jsonMember, jsonArrayMember } from 'typedjson'; import { AssociatedKey } from './Account'; -import { MessageTopic } from './MessageTopic'; import { EntryPointV1 } from './EntryPoint'; import { AccountHash, URef } from './key'; import { TransactionRuntime } from './TransactionTarget'; @@ -127,12 +126,6 @@ export class AddressableEntity { */ @jsonMember({ name: 'protocol_version', constructor: String }) protocolVersion: string; - - /** - * A list of topics for messaging associated with this entity. - */ - @jsonArrayMember(MessageTopic, { name: 'message_topics' }) - messageTopics: MessageTopic[]; } /** diff --git a/src/types/EntryPoint.ts b/src/types/EntryPoint.ts index 6845bc9d..9164700d 100644 --- a/src/types/EntryPoint.ts +++ b/src/types/EntryPoint.ts @@ -16,8 +16,17 @@ export enum EntryPointType { * Enum representing the payment options for an entry point. */ export enum EntryPointPayment { + /** + * The caller must cover cost. + */ Caller = 'Caller', - SelfOnly = 'SelfOnly', + /** + * Will cover cost to execute self but not cost of any subsequent invoked contracts. + */ + DirectInvocationOnly = 'DirectInvocationOnly', + /** + * Will cover cost to execute self and the cost of any subsequent invoked contracts. + */ SelfOnward = 'SelfOnward' } diff --git a/src/types/Transform.ts b/src/types/Transform.ts index d35028e8..cfdf2ef8 100644 --- a/src/types/Transform.ts +++ b/src/types/Transform.ts @@ -1,7 +1,6 @@ import { jsonObject, jsonMember, TypedJSON } from 'typedjson'; -import { BigNumber } from '@ethersproject/bignumber'; -import { AccountHash, Key, Hash, URef } from './key'; +import { Key } from './key'; import { UnbondingPurse } from './UnbondingPurse'; import { AddressableEntity } from './AddressableEntity'; import { Package } from './Package'; @@ -24,7 +23,8 @@ import { RawWriteTransferTransform, RawWriteUnbonding, RawWriteWithdrawals, - TranformAddressableEntityRawData + TranformAddressableEntityRawData, + WriteTransfer } from './TransformRaw'; /** @@ -530,104 +530,3 @@ export class NamedKeyKind { }) public name: Args; } - -/** - * Represents a transfer operation in a transaction. - */ -@jsonObject -export class WriteTransfer { - /** - * The optional ID of the transfer. - */ - @jsonMember({ name: 'id', constructor: Number }) - public id?: number; - - /** - * The recipient of the transfer, represented as an `AccountHash`. - */ - @jsonMember({ - name: 'to', - constructor: AccountHash, - deserializer: json => { - if (!json) return; - return AccountHash.fromJSON(json); - }, - serializer: (value: AccountHash) => { - if (!value) return; - return value.toJSON(); - } - }) - public to?: AccountHash; - - /** - * The deploy hash associated with the transfer. - */ - @jsonMember({ - name: 'deploy_hash', - constructor: Hash, - deserializer: json => { - if (!json) return; - return Hash.fromJSON(json); - }, - serializer: value => { - if (!value) return; - return value.toJSON(); - } - }) - public deployHash: Hash; - - /** - * The sender of the transfer, represented as an `AccountHash`. - */ - @jsonMember({ - name: 'from', - constructor: AccountHash, - deserializer: json => AccountHash.fromJSON(json), - serializer: (value: AccountHash) => value.toJSON() - }) - public from: AccountHash; - - /** - * The amount being transferred, represented as a `CLValueUInt512`. - */ - @jsonMember({ - name: 'amount', - constructor: CLValueUInt512, - deserializer: json => CLValueUInt512.fromJSON(json), - serializer: (value: CLValueUInt512) => value.toJSON() - }) - public amount: CLValueUInt512; - - /** - * The source URef (Universal Reference) of the transfer. - */ - @jsonMember({ - name: 'source', - constructor: URef, - deserializer: json => URef.fromJSON(json), - serializer: (value: URef) => value.toJSON() - }) - public source: URef; - - /** - * The target URef (Universal Reference) of the transfer. - */ - @jsonMember({ - name: 'target', - constructor: URef, - deserializer: json => URef.fromJSON(json), - serializer: (value: URef) => value.toJSON() - }) - public target: URef; - - /** - * The gas used for the transfer. - */ - @jsonMember({ - name: 'gas', - constructor: Number, - deserializer: json => BigNumber.from(json).toNumber(), - serializer: value => BigNumber.from(value).toString() - }) - public gas: number; -} diff --git a/src/types/TransformRaw.ts b/src/types/TransformRaw.ts index 91b0e214..98224ad1 100644 --- a/src/types/TransformRaw.ts +++ b/src/types/TransformRaw.ts @@ -1,7 +1,7 @@ import { jsonArrayMember, jsonMember, jsonObject } from 'typedjson'; import { UnbondingPurse } from './UnbondingPurse'; -import { NamedKeyKind, WriteTransfer } from './Transform'; +import { NamedKeyKind } from './Transform'; import { AddressableEntity } from './AddressableEntity'; import { Package } from './Package'; import { BidKind } from './BidKind'; @@ -10,6 +10,110 @@ import { CLValueUInt512 } from './clvalue'; import { DeployInfo } from './DeployInfo'; import { Args } from './Args'; import { deserializeArgs, serializeArgs } from './SerializationUtils'; +import { BigNumber } from '@ethersproject/bignumber'; +import { AccountHash, Hash, URef } from './key'; + +/** + * Represents a transfer operation in a transaction. + */ +@jsonObject +export class WriteTransfer { + /** + * The optional ID of the transfer. + */ + @jsonMember({ name: 'id', constructor: Number, preserveNull: true }) + public id?: number; + + /** + * The recipient of the transfer, represented as an `AccountHash`. + */ + @jsonMember({ + name: 'to', + constructor: AccountHash, + preserveNull: true, + deserializer: json => { + if (!json) return; + return AccountHash.fromJSON(json); + }, + serializer: (value: AccountHash) => { + if (!value) return; + return value.toJSON(); + } + }) + public to?: AccountHash; + + /** + * The deploy hash associated with the transfer. + */ + @jsonMember({ + name: 'deploy_hash', + constructor: Hash, + deserializer: json => { + if (!json) return; + return Hash.fromJSON(json); + }, + serializer: value => { + if (!value) return; + return value.toJSON(); + } + }) + public deployHash: Hash; + + /** + * The sender of the transfer, represented as an `AccountHash`. + */ + @jsonMember({ + name: 'from', + constructor: AccountHash, + deserializer: json => AccountHash.fromJSON(json), + serializer: (value: AccountHash) => value.toJSON() + }) + public from: AccountHash; + + /** + * The amount being transferred, represented as a `CLValueUInt512`. + */ + @jsonMember({ + name: 'amount', + constructor: CLValueUInt512, + deserializer: json => CLValueUInt512.fromJSON(json), + serializer: (value: CLValueUInt512) => value.toJSON() + }) + public amount: CLValueUInt512; + + /** + * The source URef (Universal Reference) of the transfer. + */ + @jsonMember({ + name: 'source', + constructor: URef, + deserializer: json => URef.fromJSON(json), + serializer: (value: URef) => value.toJSON() + }) + public source: URef; + + /** + * The target URef (Universal Reference) of the transfer. + */ + @jsonMember({ + name: 'target', + constructor: URef, + deserializer: json => URef.fromJSON(json), + serializer: (value: URef) => value.toJSON() + }) + public target: URef; + + /** + * The gas used for the transfer. + */ + @jsonMember({ + name: 'gas', + constructor: Number, + deserializer: json => BigNumber.from(json).toNumber(), + serializer: value => BigNumber.from(value).toString() + }) + public gas: number; +} /** * Represents raw data for a write operation involving withdrawals. @@ -31,7 +135,7 @@ export class RawWriteTransferTransform { /** * The write transfer operation. */ - @jsonMember({ name: 'WriteTransfer', constructor: () => WriteTransfer }) + @jsonMember({ name: 'WriteTransfer', constructor: WriteTransfer }) WriteTransfer?: WriteTransfer; } @@ -115,7 +219,7 @@ class WriteNamedKey { /** * The named key in the write operation. */ - @jsonMember({ constructor: () => NamedKeyKind, name: 'NamedKey' }) + @jsonMember(() => NamedKeyKind, { name: 'NamedKey' }) NamedKey?: NamedKeyKind; } diff --git a/src/types/key/Key.ts b/src/types/key/Key.ts index cf0b6416..78550cbe 100644 --- a/src/types/key/Key.ts +++ b/src/types/key/Key.ts @@ -164,9 +164,8 @@ export class Key { @jsonMember({ name: 'Type', constructor: Number }) type: KeyTypeID; - @jsonMember({ - name: 'Account', - constructor: () => AccountHash + @jsonMember(() => AccountHash, { + name: 'Account' }) account?: AccountHash; @@ -206,15 +205,13 @@ export class Key { }) balance?: Hash; - @jsonMember({ - name: 'Bid', - constructor: () => AccountHash + @jsonMember(() => AccountHash, { + name: 'Bid' }) bid?: AccountHash; - @jsonMember({ - name: 'Withdraw', - constructor: () => AccountHash + @jsonMember(() => AccountHash, { + name: 'Withdraw' }) withdraw?: AccountHash; @@ -236,9 +233,8 @@ export class Key { }) eraSummary?: Hash; - @jsonMember({ - name: 'Unbond', - constructor: () => AccountHash + @jsonMember(() => AccountHash, { + name: 'Unbond' }) unbond?: AccountHash;