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

Minor refactoring: use "isTyped" #446

Merged
merged 1 commit into from
May 27, 2024
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
9 changes: 2 additions & 7 deletions src/smartContractQueriesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Err } from "./errors";
import { IContractQueryResponse } from "./interfaceOfNetwork";
import { SmartContractQuery, SmartContractQueryResponse } from "./smartContractQuery";
import { ArgSerializer, ContractFunction, EndpointDefinition, NativeSerializer, ResultsParser } from "./smartcontracts";
import { isTyped } from "./smartcontracts/typesystem";

interface IAbi {
getEndpoint(name: string | ContractFunction): EndpointDefinition;
Expand Down Expand Up @@ -62,13 +63,7 @@ export class SmartContractQueriesController {
}

private areArgsOfTypedValue(args: any[]): boolean {
for (const arg of args) {
if (!arg.belongsToTypesystem) {
return false;
}
}

return true;
return args.every((arg) => isTyped(arg));
}

private areArgsBuffers(args: any[]): boolean {
Expand Down
3 changes: 2 additions & 1 deletion src/smartcontracts/nativeSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
I64Value,
I8Type,
I8Value,
isTyped,
List,
ListType,
NumericalType,
Expand Down Expand Up @@ -168,7 +169,7 @@ export namespace NativeSerializer {
}

function convertToTypedValue(value: any, type: Type, errorContext: ArgumentErrorContext): TypedValue {
if (value && value.belongsToTypesystem) {
if (value && isTyped(value)) {
// Value is already typed, no need to convert it.
return value;
}
Expand Down
9 changes: 2 additions & 7 deletions src/transactionsFactories/smartContractTransactionsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IAddress } from "../interface";
import { Logger } from "../logger";
import { ArgSerializer, CodeMetadata, ContractFunction, EndpointDefinition } from "../smartcontracts";
import { NativeSerializer } from "../smartcontracts/nativeSerializer";
import { isTyped } from "../smartcontracts/typesystem";
import { TokenComputer, TokenTransfer } from "../tokens";
import { Transaction } from "../transaction";
import { byteArrayToHex, utf8ToHex } from "../utils.codec";
Expand Down Expand Up @@ -228,12 +229,6 @@ export class SmartContractTransactionsFactory {
}

private areArgsOfTypedValue(args: any[]): boolean {
for (const arg of args) {
if (!arg.belongsToTypesystem) {
return false;
}
}

return true;
return args.every((arg) => isTyped(arg));
}
}
Loading