Skip to content

Commit

Permalink
Merge pull request #485 from casper-ecosystem/extend_transform_parsin…
Browse files Browse the repository at this point in the history
…g_functions

Added transform parsing functions, fromJSON method for InfoGetTransactionResultV1Compatible, fixed an issue with TransactionEntryPoint deserialization
  • Loading branch information
alexmyshchyshyn authored Jan 7, 2025
2 parents c0c61b7 + 80183e2 commit 613aa91
Show file tree
Hide file tree
Showing 7 changed files with 614 additions and 29 deletions.
7 changes: 7 additions & 0 deletions src/rpc/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ export class InfoGetTransactionResultV1Compatible {
}
throw new Error('Incorrect RPC response structure');
}

public static fromJSON(
json: any
): InfoGetTransactionResultV1Compatible | undefined {
const serializer = new TypedJSON(InfoGetTransactionResultV1Compatible);
return serializer.parse(json);
}
}

@jsonObject
Expand Down
21 changes: 3 additions & 18 deletions src/types/EntryPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,6 @@ export class EntryPointArg {
}
}

/**
* Class representing access control options for an entry point.
* This class is used for controlling the permissions required to call the entry point.
*
* TODO: Match with Go code when ready
*/
@jsonObject
export class EntryPointAccess {
/**
* The access control options for this entry point.
*/
@jsonMember({ name: 'access_control_options', constructor: AnyT })
accessControlOptions: any;
}

/**
* Class representing version 1 of an entry point in the Casper VM.
* It contains the entry point's access, arguments, type, payment type, name, and return type.
Expand All @@ -95,9 +80,9 @@ export class EntryPointV1 {
*/
@jsonMember({
name: 'access',
constructor: EntryPointAccess
constructor: AnyT
})
access: EntryPointAccess;
access: any;

/**
* A list of arguments for the entry point.
Expand Down Expand Up @@ -157,7 +142,7 @@ export class EntryPointV1 {
* @param ret The return type of the entry point.
*/
constructor(
access: EntryPointAccess,
access: any,
args: EntryPointArg[],
entryPointType: EntryPointType,
entryPointPayment: EntryPointPayment,
Expand Down
10 changes: 3 additions & 7 deletions src/types/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ export class TransactionV1 {
* @param keys The private key to sign the transaction.
*/
sign(keys: PrivateKey): void {
const signatureBytes = keys.signAndAddAlgorithmBytes(
this.hash.toBytes()
);
const signatureBytes = keys.signAndAddAlgorithmBytes(this.hash.toBytes());
const signature = new HexBytes(signatureBytes);

if (!this.approvals) {
Expand Down Expand Up @@ -494,9 +492,7 @@ export class Transaction {
* @param key The private key to sign the transaction.
*/
sign(key: PrivateKey): void {
const signatureBytes = key.signAndAddAlgorithmBytes(
this.hash.toBytes()
);
const signatureBytes = key.signAndAddAlgorithmBytes(this.hash.toBytes());
this.setSignature(signatureBytes, key.publicKey);
}

Expand Down Expand Up @@ -572,7 +568,7 @@ export class Transaction {
}

if (this.originDeployV1) {
return Deploy.toJSON(this.originDeployV1)
return Deploy.toJSON(this.originDeployV1);
}

throw new Error('Incorrect Transaction instance. Missing origin value');
Expand Down
6 changes: 4 additions & 2 deletions src/types/TransactionEntryPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ export class TransactionEntryPoint {
this.type === TransactionEntryPointEnum.Custom &&
this.customEntryPoint
) {
const entryPointBytes = CLValueString.newCLString(this.customEntryPoint).bytes()
const entryPointBytes = CLValueString.newCLString(
this.customEntryPoint
).bytes();
calltableSerialization.addField(1, entryPointBytes);
}

Expand Down Expand Up @@ -156,7 +158,7 @@ export class TransactionEntryPoint {
* @throws An error if the JSON is invalid or the entry point is unknown.
*/
static fromJSON(json: any): TransactionEntryPoint {
if (json instanceof Object && json.Custom) {
if (json?.Custom) {
return new TransactionEntryPoint(
TransactionEntryPointEnum.Custom,
json.Custom
Expand Down
Loading

0 comments on commit 613aa91

Please sign in to comment.