Socket
Socket
Sign inDemoInstall

@vechain/sdk-network

Package Overview
Dependencies
Maintainers
6
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vechain/sdk-network - npm Package Compare versions

Comparing version 1.0.0-beta.1 to 1.0.0-beta.2

src/thor-client/contracts/model/contract-filter.ts

6

package.json
{
"name": "@vechain/sdk-network",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "This module allows to connect you seamlessly to the VechainThor blockchain",

@@ -37,6 +37,6 @@ "author": "vechain Foundation",

"@types/ws": "^8.5.10",
"@vechain/sdk-core": "1.0.0-beta.1",
"@vechain/sdk-errors": "1.0.0-beta.1",
"@vechain/sdk-core": "1.0.0-beta.2",
"@vechain/sdk-errors": "1.0.0-beta.2",
"axios": "^1.6.7"
}
}

@@ -12,3 +12,3 @@ import { assert, DATA } from '@vechain/sdk-errors';

assertIsRevisionForAccount,
dataUtils
Hex0x
} from '@vechain/sdk-core';

@@ -108,3 +108,3 @@ import { type ThorClient } from '../thor-client';

'getStorageAt',
dataUtils.isHexString(position) && position.length === 66,
Hex0x.isValid(position) && position.length === 66,
DATA.INVALID_DATA_TYPE,

@@ -111,0 +111,0 @@ 'Invalid `position`. The position must be a hex string of 32 bytes (66 characters including `0x` prefix).',

@@ -174,2 +174,3 @@ import { assert, DATA } from '@vechain/sdk-errors';

* @param blockNumber - The block number to wait for.
* @param expanded - A boolean indicating whether to wait for an expanded block.
* @param options - (Optional) Allows to specify timeout and interval in milliseconds

@@ -240,3 +241,3 @@ * @returns A promise that resolves to an object containing the compressed block.

blockNumber,
false,
true,
options

@@ -243,0 +244,0 @@ )) as ExpandedBlockDetail | null;

@@ -124,3 +124,4 @@ import {

functionFragment,
functionData
functionData,
options?.value ?? 0
);

@@ -127,0 +128,0 @@

import {
addressUtils,
coder,
type EventFragment,
type FunctionFragment,
type InterfaceAbi
} from '@vechain/sdk-core';
import type {
SendTransactionResult,
TransactionReceipt
} from '../../transactions';
import type { TransactionReceipt } from '../../transactions';
import { type ThorClient } from '../../thor-client';
import type {
ContractCallOptions,
ContractCallResult,
ContractTransactionOptions
} from '../types';
import type { ContractCallOptions, ContractTransactionOptions } from '../types';
import { buildError, ERROR_CODES } from '@vechain/sdk-errors';
import type { ContractFunctionRead, ContractFunctionTransact } from './types';
import {
type ContractFunctionFilter,
type ContractFunctionRead,
type ContractFunctionTransact
} from './types';
import {
getFilterProxy,
getReadProxy,
getTransactProxy
} from './contract-proxy';

@@ -33,2 +35,3 @@ /**

public transact: ContractFunctionTransact = {};
public filters: ContractFunctionFilter = {};

@@ -58,4 +61,5 @@ private contractCallOptions: ContractCallOptions = {};

this.callerPrivateKey = callerPrivateKey;
this.read = this.getReadProxy();
this.transact = this.getTransactProxy();
this.read = getReadProxy(this);
this.transact = getTransactProxy(this);
this.filters = getFilterProxy(this);
}

@@ -74,3 +78,3 @@

// initialize the proxy with the new options
this.read = this.getReadProxy();
this.read = getReadProxy(this);
return this.contractCallOptions;

@@ -81,6 +85,14 @@ }

* Clears the current contract call options, resetting them to an empty object.
* @returns The updated contract call options.
*/
public getContractReadOptions(): ContractCallOptions {
return this.contractCallOptions;
}
/**
* Clears the current contract call options, resetting them to an empty object.
*/
public clearContractReadOptions(): void {
this.contractCallOptions = {};
this.read = this.getReadProxy();
this.read = getReadProxy(this);
}

@@ -99,6 +111,10 @@

// initialize the proxy with the new options
this.transact = this.getTransactProxy();
this.transact = getTransactProxy(this);
return this.contractTransactionOptions;
}
public getContractTransactOptions(): ContractTransactionOptions {
return this.contractTransactionOptions;
}
/**

@@ -109,3 +125,3 @@ * Clears the current contract transaction options, resetting them to an empty object.

this.contractTransactionOptions = {};
this.transact = this.getTransactProxy();
this.transact = getTransactProxy(this);
}

@@ -121,4 +137,4 @@

// initialize the proxy with the new private key
this.transact = this.getTransactProxy();
this.read = this.getReadProxy();
this.transact = getTransactProxy(this);
this.read = getReadProxy(this);
return this.callerPrivateKey;

@@ -136,68 +152,2 @@ }

/**
* Creates a Proxy object for reading contract functions, allowing for the dynamic invocation of contract read operations.
* @returns A Proxy that intercepts calls to read contract functions, automatically handling the invocation with the configured options.
* @private
*/
private getReadProxy(): ContractFunctionRead {
return new Proxy(this.read, {
get: (_target, prop) => {
// Otherwise, assume that the function is a contract method
return async (
...args: unknown[]
): Promise<ContractCallResult> => {
return await this.thor.contracts.executeContractCall(
this.address,
this.getFunctionFragment(prop),
args,
{
caller:
this.callerPrivateKey !== undefined
? addressUtils.fromPrivateKey(
Buffer.from(
this.callerPrivateKey,
'hex'
)
)
: undefined,
...this.contractCallOptions
}
);
};
}
});
}
/**
* Creates a Proxy object for transacting with contract functions, allowing for the dynamic invocation of contract transaction operations.
* @returns A Proxy that intercepts calls to transaction contract functions, automatically handling the invocation with the configured options.
* @private
*/
private getTransactProxy(): ContractFunctionTransact {
return new Proxy(this.transact, {
get: (_target, prop) => {
// Otherwise, assume that the function is a contract method
return async (
...args: unknown[]
): Promise<SendTransactionResult> => {
if (this.callerPrivateKey === undefined) {
throw buildError(
'Contract.getTransactProxy',
ERROR_CODES.TRANSACTION.MISSING_PRIVATE_KEY,
'Caller private key is required to transact with the contract.',
{ prop }
);
}
return await this.thor.contracts.executeContractTransaction(
this.callerPrivateKey,
this.address,
this.getFunctionFragment(prop),
args,
this.contractTransactionOptions
);
};
}
});
}
/**
* Retrieves the function fragment for the specified function name.

@@ -210,3 +160,3 @@ * @param prop - The name of the function.

*/
private getFunctionFragment(prop: string | symbol): FunctionFragment {
public getFunctionFragment(prop: string | symbol): FunctionFragment {
const functionFragment = coder

@@ -226,4 +176,25 @@ .createInterface(this.abi)

}
/**
* Retrieves the event fragment for the specified event name.
* @param eventName - The name of the event.
* @return The event fragment for the specified event name.
*/
public getEventFragment(eventName: string | symbol): EventFragment {
const eventFragment = coder
.createInterface(this.abi)
.getEvent(eventName.toString());
if (eventFragment == null) {
throw buildError(
'Contract.getFunctionFragment',
ERROR_CODES.ABI.INVALID_FUNCTION,
`Function '${eventName.toString()}' not found in contract ABI.`,
{ eventName }
);
}
return eventFragment;
}
}
export { Contract };
export { ContractFactory } from './contract-factory';
export { Contract } from './contract';
export type { ContractFunction } from './types';
export type { ContractFunctionAsync } from './types';
import type { ContractCallResult } from '../types';
import type { SendTransactionResult } from '../../transactions';
import { type ContractFilter } from './contract-filter';
/**
* Represents a generic contract function type that accepts an arbitrary number of arguments
* and returns a value of generic type `T`. This type is typically used to model the behavior of
* smart contract functions in a blockchain context.
*
* @typeParam T - The expected return type of the function. Defaults to `unknown` if not specified.
* @param args - An array of arguments that the contract function accepts. The types of these arguments
* are not specified, allowing for flexibility in function signatures.
* @returns A value of type `T`, representing the result of the contract function execution.
*/
type ContractFunctionSync<T = unknown> = (...args: unknown[]) => T;
/**
* Represents a generic contract function type that accepts an arbitrary number of arguments
* and returns a promise that resolves to a generic type `T`. This type is typically used to

@@ -14,3 +27,3 @@ * model the behavior of smart contract functions in a blockchain context.

*/
type ContractFunction<T = unknown> = (...args: unknown[]) => Promise<T>;
type ContractFunctionAsync<T = unknown> = (...args: unknown[]) => Promise<T>;

@@ -23,7 +36,7 @@ /**

* The keys of this record represent the names of the contract functions, and the values are the contract
* functions themselves, adhering to the `ContractFunction` type with `ContractCallResult` as the return type.
* functions themselves, adhering to the `ContractFunctionAsync` type with `ContractCallResult` as the return type.
*/
type ContractFunctionRead = Record<
string,
ContractFunction<ContractCallResult>
ContractFunctionAsync<ContractCallResult>
>;

@@ -37,13 +50,36 @@

* The keys of this record represent the names of the contract functions, and the values are the contract
* functions themselves, adhering to the `ContractFunction` type with `SendTransactionResult` as the return type.
* functions themselves, adhering to the `ContractFunctionAsync` type with `SendTransactionResult` as the return type.
*/
type ContractFunctionTransact = Record<
string,
ContractFunction<SendTransactionResult>
ContractFunctionAsync<SendTransactionResult>
>;
/**
* Defines a mapping of contract function names to their corresponding filter contract functions.
* Each function in this record is expected to return a `ContractFilter` instance, which can be used to
* filter events emitted by the contract.
*
* The keys of this record represent the names of the contract functions, and the values are the contract
* functions themselves, adhering to the `ContractFunctionAsync` type with `ContractFilter` as the return type.
*/
type ContractFunctionFilter = Record<
string,
ContractFunctionSync<ContractFilter>
>;
/**
* Represents the amount of VET to transfer in a transaction.
*/
interface TransactionValue {
value: number;
}
export type {
ContractFunction,
ContractFunctionAsync,
ContractFunctionSync,
ContractFunctionRead,
ContractFunctionTransact
ContractFunctionTransact,
ContractFunctionFilter,
TransactionValue
};

@@ -10,6 +10,10 @@ import type {

type ContractTransactionOptions = Omit<TransactionBodyOptions, 'isDelegated'>;
/**
* Defines the options for executing a contract transaction.
*/
type ContractTransactionOptions = { value?: number } & Omit<
TransactionBodyOptions,
'isDelegated'
>;
/* --------- Input types End --------- */
/**

@@ -20,2 +24,7 @@ * Defines the options for executing a contract call within a blockchain environment.

/* --------- Input types End --------- */
/**
* Represents the result of a contract call operation, encapsulating the output of the call.
*/
type ContractCallResult = vechain_sdk_core_ethers.Result;

@@ -22,0 +31,0 @@

@@ -14,3 +14,3 @@ import { type ThorClient } from '../thor-client';

import { assert, DATA } from '@vechain/sdk-errors';
import { addressUtils, dataUtils } from '@vechain/sdk-core';
import { addressUtils, Hex0x } from '@vechain/sdk-core';

@@ -109,3 +109,3 @@ /** The `DebugModule` class encapsulates functionality to handle Debug

'traceContractCall',
dataUtils.isHexString(input.contractInput.data, true),
Hex0x.isValid(input.contractInput.data, true),
DATA.INVALID_DATA_TYPE,

@@ -119,3 +119,3 @@ `Invalid data '${input.contractInput?.data}' given as input for traceContractCall.`,

'traceContractCall',
dataUtils.isHexString(input.contractInput.value, true),
Hex0x.isValid(input.contractInput.value),
DATA.INVALID_DATA_TYPE,

@@ -208,3 +208,3 @@ `Invalid value '${input.contractInput?.value}' given as input for traceContractCall.`,

'validateTarget',
dataUtils.isThorId(target.blockID, true),
Hex0x.isThorId(target.blockID),
DATA.INVALID_DATA_TYPE,

@@ -219,3 +219,3 @@ `Invalid block ID '${target.blockID}' given as input for ${functionName}.`,

'validateTarget',
dataUtils.isThorId(target.transaction, true),
Hex0x.isThorId(target.transaction),
DATA.INVALID_DATA_TYPE,

@@ -222,0 +222,0 @@ `Invalid transaction id '${target.transaction}' given as input for ${functionName}.`,

@@ -229,3 +229,5 @@ /* --- Input options start --- */

EventCriteria,
Range
Range,
PaginationOptions,
EventDisplayOrder
};

@@ -1,2 +0,2 @@

import { Hex, type Transaction } from '@vechain/sdk-core';
import { Hex0x, type Transaction } from '@vechain/sdk-core';
import { type HttpClient } from '../../../utils';

@@ -30,3 +30,3 @@ import {

): Promise<Buffer> => {
const rawTx = Hex.of0x(tx.encoded);
const rawTx = Hex0x.of(tx.encoded);

@@ -33,0 +33,0 @@ /**

@@ -6,3 +6,3 @@ import {

assertValidTransactionID,
dataUtils,
Hex0x,
revisionUtils,

@@ -29,3 +29,2 @@ secp256k1,

} from './types';
import { randomBytes } from 'crypto';
import { assert, buildError, DATA, TRANSACTION } from '@vechain/sdk-errors';

@@ -116,3 +115,3 @@ import { type ThorClient } from '../thor-client';

'sendRawTransaction',
dataUtils.isHexString(raw),
Hex0x.isValid(raw),
DATA.INVALID_DATA_TYPE,

@@ -160,3 +159,3 @@ 'Sending failed: Input must be a valid raw transaction in hex format.',

const rawTx = `0x${signedTx.encoded.toString('hex')}`;
const rawTx = Hex0x.of(signedTx.encoded);

@@ -230,3 +229,3 @@ return await this.sendRawTransaction(rawTx);

const constTxBody = {
nonce: `0x${dataUtils.toHexString(randomBytes(8))}`,
nonce: Hex0x.of(secp256k1.randomBytes(8)),
expiration: options?.expiration ?? 32,

@@ -233,0 +232,0 @@ clauses,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc