Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added transform parsing functions, fromJSON method for InfoGetTransactionResultV1Compatible, fixed an issue with TransactionEntryPoint deserialization #485

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading