Skip to content

Commit

Permalink
Merge pull request #446 from multiversx/refactor-05-13
Browse files Browse the repository at this point in the history
Minor refactoring: use "isTyped"
  • Loading branch information
andreibancioiu authored May 27, 2024
2 parents ddea99b + 1d41828 commit a62a324
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
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 @@ -236,12 +237,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));
}
}

0 comments on commit a62a324

Please sign in to comment.