Skip to content

Commit

Permalink
Fix: Transform Raw serialization, removed message topics from addresa…
Browse files Browse the repository at this point in the history
…ble entity, EntryPointPayment change
  • Loading branch information
alexmyshchyshyn committed Dec 18, 2024
1 parent 8ac0f71 commit 09564da
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 127 deletions.
7 changes: 0 additions & 7 deletions src/types/AddressableEntity.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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[];
}

/**
Expand Down
11 changes: 10 additions & 1 deletion src/types/EntryPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand Down
107 changes: 3 additions & 104 deletions src/types/Transform.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -24,7 +23,8 @@ import {
RawWriteTransferTransform,
RawWriteUnbonding,
RawWriteWithdrawals,
TranformAddressableEntityRawData
TranformAddressableEntityRawData,
WriteTransfer
} from './TransformRaw';

/**
Expand Down Expand Up @@ -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;
}
110 changes: 107 additions & 3 deletions src/types/TransformRaw.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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.
Expand All @@ -31,7 +135,7 @@ export class RawWriteTransferTransform {
/**
* The write transfer operation.
*/
@jsonMember({ name: 'WriteTransfer', constructor: () => WriteTransfer })
@jsonMember({ name: 'WriteTransfer', constructor: WriteTransfer })
WriteTransfer?: WriteTransfer;
}

Expand Down Expand Up @@ -115,7 +219,7 @@ class WriteNamedKey {
/**
* The named key in the write operation.
*/
@jsonMember({ constructor: () => NamedKeyKind, name: 'NamedKey' })
@jsonMember(() => NamedKeyKind, { name: 'NamedKey' })
NamedKey?: NamedKeyKind;
}

Expand Down
20 changes: 8 additions & 12 deletions src/types/key/Key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -236,9 +233,8 @@ export class Key {
})
eraSummary?: Hash;

@jsonMember({
name: 'Unbond',
constructor: () => AccountHash
@jsonMember(() => AccountHash, {
name: 'Unbond'
})
unbond?: AccountHash;

Expand Down

0 comments on commit 09564da

Please sign in to comment.