Skip to content

Commit eae21a9

Browse files
Update TransactionRuntime / TransactionTarget serialization
1 parent 7122398 commit eae21a9

7 files changed

+186
-169
lines changed

src/types/AddressableEntity.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { AssociatedKey } from './Account';
33
import { MessageTopic } from './MessageTopic';
44
import { EntryPointV1 } from './EntryPoint';
55
import { AccountHash, URef } from './key';
6-
7-
export type SystemEntityType = string;
8-
export type TransactionRuntime = 'VmCasperV1' | 'VmCasperV2';
6+
import { TransactionRuntime } from './TransactionTarget';
97

108
/**
119
* Defines different kinds of entities within the system, such as system entities,
@@ -17,7 +15,7 @@ export class EntityKind {
1715
* Represents a system entity type, allowing flexible naming of system-specific entities.
1816
*/
1917
@jsonMember({ name: 'System', constructor: String })
20-
system?: SystemEntityType;
18+
system?: string;
2119

2220
/**
2321
* Represents an account entity, identified by an `AccountHash`.
@@ -35,7 +33,12 @@ export class EntityKind {
3533
*/
3634
@jsonMember({
3735
name: 'SmartContract',
38-
constructor: String
36+
constructor: TransactionRuntime,
37+
deserializer: json => {
38+
if (!json) return;
39+
return TransactionRuntime.fromJSON(json);
40+
},
41+
serializer: (value: TransactionRuntime) => value.toJSON()
3942
})
4043
smartContract?: TransactionRuntime;
4144
}

src/types/ContractWasm.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { jsonObject, jsonMember } from 'typedjson';
2+
3+
/**
4+
* A container for contract's WASM bytes.
5+
*/
6+
@jsonObject
7+
export class ContractWasm {
8+
/**
9+
* The WASM bytes of the contract as a string.
10+
*/
11+
@jsonMember({ name: 'bytes', constructor: String })
12+
public bytes!: string;
13+
14+
constructor(bytes: string) {
15+
this.bytes = bytes;
16+
}
17+
}

src/types/StoredValue.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { AnyT, jsonArrayMember, jsonMember, jsonObject } from 'typedjson';
1+
import { jsonArrayMember, jsonMember, jsonObject } from 'typedjson';
22

33
import { Account } from './Account';
4-
import { TransferV1 } from './Transfer';
4+
import { Transfer } from './Transfer';
55
import { DeployInfo } from './DeployInfo';
66
import { EraInfo } from './EraInfo';
77
import { Bid } from './Bid';
@@ -17,6 +17,7 @@ import { Contract } from './Contract';
1717
import { ContractPackage } from './ContractPackage';
1818
import { CLValue, CLValueParser } from './clvalue';
1919
import { SystemByteCode } from './ByteCode';
20+
import { ContractWasm } from './ContractWasm';
2021

2122
/**
2223
* Represents a stored value in a decentralized system. The value can be of different types
@@ -57,8 +58,8 @@ export class StoredValue {
5758
/**
5859
* The WebAssembly (WASM) bytecode for the contract, represented as `AnyT`.
5960
*/
60-
@jsonMember({ name: 'ContractWASM', constructor: AnyT })
61-
contractWASM?: any;
61+
@jsonMember({ name: 'ContractWasm', constructor: ContractWasm })
62+
ContractWasm?: ContractWasm;
6263

6364
/**
6465
* The stored contract package information.
@@ -67,10 +68,17 @@ export class StoredValue {
6768
contractPackage?: ContractPackage;
6869

6970
/**
70-
* The legacy transfer information, representing a historical transfer.
71+
* The transfer information, representing a historical transfer.
7172
*/
72-
@jsonMember({ name: 'LegacyTransfer', constructor: TransferV1 })
73-
legacyTransfer?: TransferV1;
73+
@jsonMember({
74+
name: 'Transfer',
75+
constructor: Transfer,
76+
deserializer: json => {
77+
if (!json) return;
78+
return Transfer.fromJSON(json);
79+
}
80+
})
81+
transfer?: Transfer;
7482

7583
/**
7684
* The information related to a deploy operation.
@@ -117,8 +125,8 @@ export class StoredValue {
117125
/**
118126
* The stored package information, typically a contract or executable package.
119127
*/
120-
@jsonMember({ name: 'Package', constructor: Package })
121-
package?: Package;
128+
@jsonMember({ name: 'SmartContract', constructor: Package })
129+
smartContract?: Package;
122130

123131
/**
124132
* The stored bytecode, representing compiled contract or executable code.
@@ -162,4 +170,10 @@ export class StoredValue {
162170
*/
163171
@jsonMember({ name: 'EntryPoint', constructor: EntryPointValue })
164172
entryPoint?: EntryPointValue;
173+
174+
/**
175+
* Raw bytes. Similar to a [`crate::StoredValue::CLValue`] but does not incur overhead of a [`crate::CLValue`] and [`crate::CLType`].
176+
*/
177+
@jsonMember({ name: 'RawBytes', constructor: String })
178+
rawBytes?: string;
165179
}

src/types/Transaction.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { TransactionV1 } from './Transaction';
66
import { InitiatorAddr } from './InitiatorAddr';
77
import { FixedMode, PricingMode } from './PricingMode';
88
import { KeyAlgorithm, PrivateKey, PublicKey } from './keypair';
9-
import { SessionTarget, TransactionTarget } from './TransactionTarget';
9+
import {
10+
SessionTarget,
11+
TransactionRuntime,
12+
TransactionTarget
13+
} from './TransactionTarget';
1014
import {
1115
TransactionEntryPoint,
1216
TransactionEntryPointEnum
@@ -20,7 +24,6 @@ import {
2024
CLValueUInt64
2125
} from './clvalue';
2226
import { TransactionV1Payload } from './TransactionV1Payload';
23-
import { Hash } from './key';
2427

2528
describe('Test Transaction', () => {
2629
it('should create a TransactionV1 with correct payload instance', async () => {
@@ -45,13 +48,9 @@ describe('Test Transaction', () => {
4548

4649
const sessionTarget = new SessionTarget();
4750

48-
sessionTarget.runtime = 'VmCasperV1';
49-
sessionTarget.transferredValue = 1000;
51+
sessionTarget.runtime = TransactionRuntime.vmCasperV1();
5052
sessionTarget.moduleBytes = Uint8Array.from([1]);
5153
sessionTarget.isInstallUpgrade = false;
52-
sessionTarget.seed = Hash.fromHex(
53-
'8bf9d406ab901428d43ecd3a6f214b864e7ef8316934e5e0f049650a65b40d73'
54-
);
5554

5655
const transactionTarget = new TransactionTarget(
5756
undefined,

src/types/TransactionEntryPoint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export enum TransactionEntryPointEnum {
2525
* These tags are used to simplify storage and facilitate efficient comparison of entry points.
2626
*/
2727
export enum TransactionEntryPointTag {
28-
Custom = 0,
29-
Call = 1,
28+
Call = 0,
29+
Custom = 1,
3030
Transfer = 2,
3131
AddBid = 3,
3232
WithdrawBid = 4,

0 commit comments

Comments
 (0)