@concordium/node-sdk
Advanced tools
Comparing version
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
import { ChannelCredentials, Metadata } from '@grpc/grpc-js'; | ||
@@ -138,3 +139,3 @@ import { P2PClient } from '../grpc/concordium_p2p_rpc_grpc_pb'; | ||
*/ | ||
getInstanceInfo(blockHash: string, address: ContractAddress): Promise<InstanceInfo | undefined>; | ||
getInstanceInfo(address: ContractAddress, blockHash: string): Promise<InstanceInfo | undefined>; | ||
getRewardStatus(blockHash: string): Promise<RewardStatus | undefined>; | ||
@@ -167,7 +168,14 @@ /** | ||
getPoolStatus(blockHash: string, bakerId?: BakerId): Promise<PoolStatus | undefined>; | ||
getModuleSource(blockHash: string, moduleReference: ModuleReference): Promise<Uint8Array>; | ||
/** | ||
* Retrieves the source of the given module at | ||
* the provided block. | ||
* @param moduleReference the module's reference, which is the hex encoded hash of the source. | ||
* @param blockHash the block to get the cryptographic parameters at | ||
* @returns the source of the module as raw bytes. | ||
*/ | ||
getModuleSource(moduleReference: ModuleReference, blockHash: string): Promise<Buffer | undefined>; | ||
/** | ||
* Invokes a smart contract. | ||
* @param context the collection of details used to invoke the contract. Must include the address of the contract and the method invoked. | ||
* @param blockHash the block hash at which the contract should be invoked at. The contract is invoked in the state at the end of this block. | ||
* @param context the collection of details used to invoke the contract. Must include the address of the contract and the method invoked. | ||
* @returns If the node was able to invoke, then a object describing the outcome is returned. | ||
@@ -181,4 +189,4 @@ * The outcome is determined by the `tag` field, which is either `success` or `failure`. | ||
*/ | ||
invokeContract(blockHash: string, contractContext: ContractContext): Promise<InvokeContractResult | undefined>; | ||
invokeContract(contractContext: ContractContext, blockHash: string): Promise<InvokeContractResult | undefined>; | ||
sendRequest<T>(command: any, input: T): Promise<Uint8Array>; | ||
} |
@@ -331,3 +331,3 @@ "use strict"; | ||
*/ | ||
async getInstanceInfo(blockHash, address) { | ||
async getInstanceInfo(address, blockHash) { | ||
if (!(0, util_1.isValidHash)(blockHash)) { | ||
@@ -428,3 +428,10 @@ throw new Error('The input was not a valid hash: ' + blockHash); | ||
} | ||
async getModuleSource(blockHash, moduleReference) { | ||
/** | ||
* Retrieves the source of the given module at | ||
* the provided block. | ||
* @param moduleReference the module's reference, which is the hex encoded hash of the source. | ||
* @param blockHash the block to get the cryptographic parameters at | ||
* @returns the source of the module as raw bytes. | ||
*/ | ||
async getModuleSource(moduleReference, blockHash) { | ||
if (!(0, util_1.isValidHash)(blockHash)) { | ||
@@ -437,8 +444,11 @@ throw new Error('The input was not a valid hash: ' + blockHash); | ||
const response = await this.sendRequest(this.client.getModuleSource, requestObject); | ||
return response; | ||
if (response.length === 0) { | ||
return undefined; | ||
} | ||
return Buffer.from(response); | ||
} | ||
/** | ||
* Invokes a smart contract. | ||
* @param context the collection of details used to invoke the contract. Must include the address of the contract and the method invoked. | ||
* @param blockHash the block hash at which the contract should be invoked at. The contract is invoked in the state at the end of this block. | ||
* @param context the collection of details used to invoke the contract. Must include the address of the contract and the method invoked. | ||
* @returns If the node was able to invoke, then a object describing the outcome is returned. | ||
@@ -452,30 +462,10 @@ * The outcome is determined by the `tag` field, which is either `success` or `failure`. | ||
*/ | ||
async invokeContract(blockHash, contractContext) { | ||
async invokeContract(contractContext, blockHash) { | ||
if (!(0, util_1.isValidHash)(blockHash)) { | ||
throw new Error('The input was not a valid hash: ' + blockHash); | ||
} | ||
let invoker; | ||
if (!contractContext.invoker) { | ||
invoker = null; | ||
} | ||
else if (contractContext.invoker.address) { | ||
invoker = { | ||
type: 'AddressAccount', | ||
address: contractContext.invoker.address, | ||
}; | ||
} | ||
else { | ||
const invokerContract = contractContext.invoker; | ||
invoker = { | ||
type: 'AddressContract', | ||
address: { | ||
subindex: invokerContract.subindex.toString(), | ||
index: invokerContract.index.toString(), | ||
}, | ||
}; | ||
} | ||
const requestObject = new concordium_p2p_rpc_pb_1.InvokeContractRequest(); | ||
requestObject.setBlockHash(blockHash); | ||
requestObject.setContext((0, util_1.stringToInt)(JSON.stringify({ | ||
invoker, | ||
invoker: (0, common_sdk_1.buildInvoker)(contractContext.invoker), | ||
contract: { | ||
@@ -482,0 +472,0 @@ subindex: contractContext.contract.subindex.toString(), |
124
package.json
{ | ||
"name": "@concordium/node-sdk", | ||
"version": "2.1.1", | ||
"description": "Helpers for interacting with the Concordium node", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Concordium/concordium-node-sdk-js" | ||
}, | ||
"author": { | ||
"name": "Concordium Software", | ||
"email": "support@concordium.software", | ||
"url": "https://concordium.com" | ||
}, | ||
"license": "Apache-2.0", | ||
"engines": { | ||
"node": ">=14.16.0" | ||
}, | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"/grpc/*", | ||
"/lib/**/*" | ||
], | ||
"devDependencies": { | ||
"@noble/ed25519": "^1.6.0", | ||
"@types/google-protobuf": "^3.15.3", | ||
"@types/jest": "^26.0.23", | ||
"@typescript-eslint/eslint-plugin": "^4.28.1", | ||
"@typescript-eslint/parser": "^4.28.1", | ||
"babel-jest": "^27.0.6", | ||
"cross-env": "5.0.5", | ||
"eslint": "^7.29.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.23.4", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"grpc-tools": "^1.11.2", | ||
"grpc_tools_node_protoc_ts": "5.3.0", | ||
"jest": "^27.0.6", | ||
"lint-staged": "^12.0.2", | ||
"prettier": "^2.3.2", | ||
"ts-jest": "^27.0.3", | ||
"typescript": "^4.3.5" | ||
}, | ||
"prettier": { | ||
"singleQuote": true, | ||
"tabWidth": 4 | ||
}, | ||
"scripts": { | ||
"generate-js": "yarn run grpc_tools_node_protoc --js_out=import_style=commonjs,binary:grpc --grpc_out=grpc_js:grpc --plugin=protoc-gen-grpc=../../node_modules/.bin/grpc_tools_node_protoc_plugin -I ../../deps/concordium-grpc-api ../../deps/concordium-grpc-api/*.proto", | ||
"generate-ts": "yarn run grpc_tools_node_protoc --plugin=protoc-gen-ts=../../node_modules/.bin/protoc-gen-ts --ts_out=grpc_js:grpc -I ../../deps/concordium-grpc-api ../../deps/concordium-grpc-api/*.proto", | ||
"generate": "([ -e \"../../deps/concordium-grpc-api\" ] && mkdir -p grpc && yarn generate-js && yarn generate-ts) || echo 'Please checkout submodules before building'; false", | ||
"lint": "eslint . --cache --ext .ts,.tsx --max-warnings 0", | ||
"lint-fix": "yarn --silent lint --fix; exit 0", | ||
"test": "jest", | ||
"build": "([ ! -e \"grpc\" ] && yarn generate) || true && tsc" | ||
}, | ||
"dependencies": { | ||
"@concordium/common-sdk": "2.1.0", | ||
"@grpc/grpc-js": "^1.3.4", | ||
"buffer": "^6.0.3", | ||
"google-protobuf": "^3.20.1" | ||
} | ||
} | ||
"name": "@concordium/node-sdk", | ||
"version": "3.0.0", | ||
"description": "Helpers for interacting with the Concordium node", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Concordium/concordium-node-sdk-js" | ||
}, | ||
"author": { | ||
"name": "Concordium Software", | ||
"email": "support@concordium.software", | ||
"url": "https://concordium.com" | ||
}, | ||
"license": "Apache-2.0", | ||
"engines": { | ||
"node": ">=14.16.0" | ||
}, | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"/grpc/*", | ||
"/lib/**/*" | ||
], | ||
"devDependencies": { | ||
"@noble/ed25519": "^1.6.0", | ||
"@types/google-protobuf": "^3.15.3", | ||
"@types/jest": "^26.0.23", | ||
"@typescript-eslint/eslint-plugin": "^4.28.1", | ||
"@typescript-eslint/parser": "^4.28.1", | ||
"babel-jest": "^27.0.6", | ||
"cross-env": "5.0.5", | ||
"eslint": "^7.29.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.23.4", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"grpc-tools": "^1.11.2", | ||
"grpc_tools_node_protoc_ts": "5.3.0", | ||
"jest": "^27.0.6", | ||
"lint-staged": "^12.0.2", | ||
"prettier": "^2.3.2", | ||
"ts-jest": "^27.0.3", | ||
"typescript": "^4.3.5" | ||
}, | ||
"prettier": { | ||
"singleQuote": true, | ||
"tabWidth": 4 | ||
}, | ||
"scripts": { | ||
"generate-js": "yarn run grpc_tools_node_protoc --js_out=import_style=commonjs,binary:grpc --grpc_out=grpc_js:grpc --plugin=protoc-gen-grpc=../../node_modules/.bin/grpc_tools_node_protoc_plugin -I ../../deps/concordium-grpc-api ../../deps/concordium-grpc-api/*.proto", | ||
"generate-ts": "yarn run grpc_tools_node_protoc --plugin=protoc-gen-ts=../../node_modules/.bin/protoc-gen-ts --ts_out=grpc_js:grpc -I ../../deps/concordium-grpc-api ../../deps/concordium-grpc-api/*.proto", | ||
"generate": "([ -e \"../../deps/concordium-grpc-api\" ] && mkdir -p grpc && yarn generate-js && yarn generate-ts) || echo 'Please checkout submodules before building'; false", | ||
"lint": "eslint . --cache --ext .ts,.tsx --max-warnings 0", | ||
"lint-fix": "yarn --silent lint --fix; exit 0", | ||
"test": "jest", | ||
"build": "([ ! -e \"grpc\" ] && yarn generate) || true && tsc" | ||
}, | ||
"dependencies": { | ||
"@concordium/common-sdk": "2.3.0", | ||
"@grpc/grpc-js": "^1.3.4", | ||
"buffer": "^6.0.3", | ||
"google-protobuf": "^3.20.1" | ||
} | ||
} |
@@ -9,2 +9,3 @@ # Concordium Nodejs SDK | ||
**Table of Contents** | ||
@@ -35,2 +36,4 @@ - [ConcordiumNodeClient](#concordiumnodeclient) | ||
- [getInstanceInfo](#getinstanceinfo) | ||
- [invokeContract](#invokecontract) | ||
- [getModuleSource](#getModuleSource) | ||
- [Build](#build) | ||
@@ -41,3 +44,2 @@ - [Building for a release](#building-for-a-release) | ||
# ConcordiumNodeClient | ||
@@ -506,3 +508,3 @@ | ||
const instanceInfo = await client.getInstanceInfo(blockHash, contractAddress); | ||
const instanceInfo = await client.getInstanceInfo(contractAddress, blockHash); | ||
const name = instanceInfo.name; | ||
@@ -514,3 +516,3 @@ ... | ||
## InvokeContract | ||
## invokeContract | ||
Used to simulate a contract update, and to trigger view functions. | ||
@@ -523,3 +525,2 @@ | ||
const result = await client.invokeContract( | ||
blockHash, | ||
{ | ||
@@ -532,3 +533,4 @@ invoker: invoker, | ||
energy: 30000n, | ||
} | ||
}, | ||
blockHash | ||
); | ||
@@ -556,3 +558,15 @@ | ||
- invoker: uses the zero account address, which can be used instead of finding a random address. | ||
## getModuleSource | ||
This commands gets the source of a module on the chain. | ||
Note that this returns the raw bytes of the source, as a buffer. | ||
```js | ||
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749"; | ||
const moduleReference = "c0e51cd55ccbff4fa8da9bb76c9917e83ae8286d86b47647104bf715b4821c1a"; | ||
const source = await client.getModuleSource(moduleReference, blockHash); | ||
if (!source) { | ||
// the blockHash is unknown or the module doesn't exist at the given blockHash | ||
} | ||
``` | ||
@@ -559,0 +573,0 @@ # Build |
589
2.43%381526
-0.73%16
-5.88%7480
-0.03%+ Added
+ Added
- Removed
- Removed
Updated