@vechain/sdk-provider
Advanced tools
Comparing version 1.0.0-beta.2 to 1.0.0-beta.3
{ | ||
"name": "@vechain/sdk-provider", | ||
"version": "1.0.0-beta.2", | ||
"version": "1.0.0-beta.3", | ||
"description": "This module is dedicated to managing the compatibility with ethers and EVM world", | ||
@@ -34,7 +34,7 @@ "author": "vechain Foundation", | ||
"dependencies": { | ||
"@vechain/sdk-network": "1.0.0-beta.2", | ||
"@vechain/sdk-wallet": "1.0.0-beta.2", | ||
"@vechain/sdk-core": "1.0.0-beta.2", | ||
"@vechain/sdk-logging": "1.0.0-beta.2" | ||
"@vechain/sdk-network": "1.0.0-beta.3", | ||
"@vechain/sdk-wallet": "1.0.0-beta.3", | ||
"@vechain/sdk-core": "1.0.0-beta.3", | ||
"@vechain/sdk-logging": "1.0.0-beta.3" | ||
} | ||
} |
@@ -0,2 +1,3 @@ | ||
export * from './ethers-provider'; | ||
export * from './vechain-provider'; | ||
export * from './hardhat-provider'; |
@@ -0,15 +1,46 @@ | ||
import { type BlockQuantityInputRPC } from '../../rpc-mapper'; | ||
import { Hex0x } from '@vechain/sdk-core'; | ||
/** | ||
* Get the correct block number for the given block number. | ||
* | ||
* @param blockNumber - The block number to get as a hex string or "latest" or "finalized". | ||
* @param block - The block tag to get. | ||
* 'latest' or 'earliest' or 'pending' or 'safe' or 'finalized' | ||
* or an object: { blockNumber: number } or { blockHash: string } | ||
* | ||
* @note | ||
* * Standard RPC method `eth_getBlockByNumber` support following block numbers: hex number of block, 'earliest', 'latest', 'safe', 'finalized', 'pending'. (@see https://ethereum.org/en/developers/docs/apis/json-rpc#default-block) | ||
* * Currently, vechain only supports hex number of block, 'latest' and 'finalized'. | ||
* * Currently VechainThor supports 'earliest', 'latest' and 'finalized' as block tags. | ||
* So 'pending' and 'safe' are converted to 'best' which is the alias for 'latest' and 'finalized' in VechainThor. | ||
*/ | ||
const getCorrectBlockNumberRPCToVechain = (blockNumber: string): string => { | ||
if (blockNumber === 'latest') return 'best'; // 'best' is the alias for 'latest' in vechain Thorest | ||
return blockNumber; | ||
const getCorrectBlockNumberRPCToVechain = ( | ||
block: BlockQuantityInputRPC | ||
): string => { | ||
// Tag block number | ||
if (typeof block === 'string') { | ||
// Latest, Finalized, Safe blocks | ||
if ( | ||
block === 'latest' || | ||
block === 'finalized' || | ||
block === 'safe' || | ||
block === 'pending' | ||
) | ||
// 'best' is the alias for 'latest', 'finalized' and 'safe' in vechain Thorest | ||
return 'best'; | ||
// Earliest block | ||
if (block === 'earliest') return Hex0x.of(0); | ||
// Hex number of block | ||
return block; | ||
} | ||
// Object with block number | ||
if (block.blockNumber !== undefined) { | ||
return Hex0x.of(block.blockNumber); | ||
} | ||
// Object with block hash - Default case | ||
return block.blockHash; | ||
}; | ||
export { getCorrectBlockNumberRPCToVechain }; |
@@ -9,2 +9,3 @@ import { | ||
import { type TransactionObjectInput } from './types'; | ||
import { type BlockQuantityInputRPC } from '../../../types'; | ||
@@ -30,5 +31,5 @@ /** | ||
typeof params[0] === 'object' && | ||
typeof params[1] === 'string', | ||
(typeof params[1] === 'object' || typeof params[1] === 'string'), | ||
DATA.INVALID_DATA_TYPE, | ||
`Invalid params length, expected 1 object containing transaction info with following properties: \n {` + | ||
`Invalid params length, expected 1 object containing transaction info with following properties: \n{` + | ||
`\tfrom: 20 bytes [Required] Address the transaction is sent from.` + | ||
@@ -42,3 +43,7 @@ `\tto: 20 bytes - Address the transaction is directed to.` + | ||
`\tdata: Hash of the method signature and encoded parameters` + | ||
`}\n\n and the block number parameter. An hexadecimal number or (latest, earliest or pending).` | ||
`}\n\n and the block tag parameter. 'latest', 'earliest', 'pending', 'safe' or 'finalized' or an object: \n{.` + | ||
'\tblockNumber: The number of the block' + | ||
'\n}\n\nOR\n\n{' + | ||
'\tblockHash: The hash of block' + | ||
'\n}' | ||
); | ||
@@ -49,3 +54,3 @@ | ||
TransactionObjectInput, | ||
string | ||
BlockQuantityInputRPC | ||
]; | ||
@@ -52,0 +57,0 @@ |
import { type ThorClient } from '@vechain/sdk-network'; | ||
import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; | ||
import type { BlockQuantityInputRPC } from '../../../types'; | ||
import { getCorrectBlockNumberRPCToVechain } from '../../../../const'; | ||
@@ -28,15 +30,18 @@ /** | ||
typeof params[0] === 'string' && | ||
typeof params[1] === 'string', | ||
(typeof params[1] === 'object' || typeof params[1] === 'string'), | ||
DATA.INVALID_DATA_TYPE, | ||
'Invalid params length, expected 2.\nThe params should be [address: string, blockNumber: string | "latest"]' | ||
`Invalid params length, expected 2.\nThe params should be address: string` + | ||
`and the block tag parameter. 'latest', 'earliest', 'pending', 'safe' or 'finalized' or an object: \n{.` + | ||
`\tblockNumber: The number of the block` + | ||
`\n}\n\nOR\n\n{` + | ||
`\tblockHash: The hash of block` + | ||
`\n}` | ||
); | ||
try { | ||
let [address, blockNumber] = params as [string, string]; | ||
const [address, block] = params as [string, BlockQuantityInputRPC]; | ||
if (blockNumber === 'latest') blockNumber = 'best'; | ||
// Get the account details | ||
const accountDetails = await thorClient.accounts.getAccount(address, { | ||
revision: blockNumber | ||
revision: getCorrectBlockNumberRPCToVechain(block) | ||
}); | ||
@@ -43,0 +48,0 @@ |
@@ -29,3 +29,2 @@ import { type ThorClient } from '@vechain/sdk-network'; | ||
typeof params[0] === 'string' && | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
Boolean(Hex0x.isThorId(params[0])) && | ||
@@ -32,0 +31,0 @@ typeof params[1] === 'boolean', |
import { type ThorClient } from '@vechain/sdk-network'; | ||
import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; | ||
import type { BlockQuantityInputRPC } from '../../../types'; | ||
import { getCorrectBlockNumberRPCToVechain } from '../../../../const'; | ||
@@ -28,15 +30,19 @@ /** | ||
typeof params[0] === 'string' && | ||
typeof params[1] === 'string', | ||
(typeof params[1] === 'object' || typeof params[1] === 'string'), | ||
DATA.INVALID_DATA_TYPE, | ||
'Invalid params length, expected 2.\nThe params should be [address: string, blockNumber: string | "latest"]' | ||
`Invalid params length, expected 2.` + | ||
`\nThe params should be address: string` + | ||
`\nand the block tag parameter. 'latest', 'earliest', 'pending', 'safe' or 'finalized' or an object: \n{.` + | ||
`\tblockNumber: The number of the block` + | ||
`\n}\n\nOR\n\n{` + | ||
`\tblockHash: The hash of block` + | ||
`\n}` | ||
); | ||
try { | ||
let [address, blockNumber] = params as [string, string]; | ||
const [address, block] = params as [string, BlockQuantityInputRPC]; | ||
if (blockNumber === 'latest') blockNumber = 'best'; | ||
// Get the account details | ||
return await thorClient.accounts.getBytecode(address, { | ||
revision: blockNumber | ||
revision: getCorrectBlockNumberRPCToVechain(block) | ||
}); | ||
@@ -43,0 +49,0 @@ } catch (e) { |
import { Hex0x } from '@vechain/sdk-core'; | ||
import { assert, buildProviderError, DATA, JSONRPC } from '@vechain/sdk-errors'; | ||
import { type ThorClient } from '@vechain/sdk-network'; | ||
import type { BlockQuantityInputRPC } from '../../../types'; | ||
import { getCorrectBlockNumberRPCToVechain } from '../../../../const'; | ||
@@ -31,16 +33,21 @@ /** | ||
typeof params[1] === 'string' && | ||
typeof params[2] === 'string', | ||
(typeof params[2] === 'object' || typeof params[2] === 'string'), | ||
DATA.INVALID_DATA_TYPE, | ||
'Invalid params length, expected 3.\nThe params should be [address: string, storagePosition: string, blockNumber: string | "latest"]' | ||
`Invalid params length, expected 3.` + | ||
`\nThe params should be:` + | ||
`\naddress: string, storagePosition: string` + | ||
`\nand the block tag parameter. 'latest', 'earliest', 'pending', 'safe' or 'finalized' or an object: \n{.` + | ||
`\tblockNumber: The number of the block` + | ||
`\n}\n\nOR\n\n{` + | ||
`\tblockHash: The hash of block` + | ||
`\n}` | ||
); | ||
try { | ||
let [address, storagePosition, blockNumber] = params as [ | ||
const [address, storagePosition, block] = params as [ | ||
string, | ||
string, | ||
string | ||
BlockQuantityInputRPC | ||
]; | ||
if (blockNumber === 'latest') blockNumber = 'best'; | ||
// Get the account details | ||
@@ -51,3 +58,3 @@ return await thorClient.accounts.getStorageAt( | ||
{ | ||
revision: blockNumber | ||
revision: getCorrectBlockNumberRPCToVechain(block) | ||
} | ||
@@ -54,0 +61,0 @@ ); |
@@ -14,3 +14,4 @@ import { assert, DATA } from '@vechain/sdk-errors'; | ||
* @note: To respect differences between vechain and Ethereum, in this function we will give a random number as output. | ||
* Basically Ethereum to get nonce use the number of transactions sent from an address, while vechain use a random number. | ||
* Basically Ethereum to get nonce to use the number of transactions sent from an address, | ||
* while vechain uses a random number. | ||
* | ||
@@ -25,5 +26,12 @@ * @throws {InvalidDataTypeError} - When address parameter is invalid. | ||
typeof params[0] === 'string' && | ||
typeof params[1] === 'string', | ||
(typeof params[1] === 'object' || typeof params[1] === 'string'), | ||
DATA.INVALID_DATA_TYPE, | ||
'Invalid params length, expected 2.\nThe params should be [address: string, blockNumber: string]' | ||
`Invalid params length, expected 2.` + | ||
`\nThe params should be address: string` + | ||
`\nand the block tag parameter. 'latest', 'earliest', 'pending', 'safe' or 'finalized' or an object: \n{.` + | ||
`\tblockNumber: The number of the block` + | ||
`\n}\n\nOR\n\n{` + | ||
`\tblockHash: The hash of block` + | ||
`\n}` | ||
); | ||
@@ -30,0 +38,0 @@ |
@@ -72,2 +72,4 @@ import { | ||
} | ||
// Strange cases when the fetched best block is null | ||
return { | ||
@@ -74,0 +76,0 @@ currentBlock: null, |
@@ -9,2 +9,12 @@ /** | ||
export { type MethodHandlerType }; | ||
/** | ||
* Block type for RPC methods. | ||
* | ||
* It can be a block hash or a block number or a string ('0x...', 'latest', 'earliest', 'pending'). | ||
*/ | ||
type BlockQuantityInputRPC = | ||
| string | ||
| { blockHash: string; blockNumber: never } | ||
| { blockHash: never; blockNumber: number }; | ||
export { type MethodHandlerType, type BlockQuantityInputRPC }; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
628655
205
14008
+ Added@vechain/sdk-core@1.0.0-beta.3(transitive)
+ Added@vechain/sdk-errors@1.0.0-beta.3(transitive)
+ Added@vechain/sdk-logging@1.0.0-beta.3(transitive)
+ Added@vechain/sdk-network@1.0.0-beta.3(transitive)
+ Added@vechain/sdk-wallet@1.0.0-beta.3(transitive)
- Removed@vechain/sdk-core@1.0.0-beta.2(transitive)
- Removed@vechain/sdk-errors@1.0.0-beta.2(transitive)
- Removed@vechain/sdk-logging@1.0.0-beta.2(transitive)
- Removed@vechain/sdk-network@1.0.0-beta.2(transitive)
- Removed@vechain/sdk-wallet@1.0.0-beta.2(transitive)