@concordium/node-sdk
Advanced tools
Comparing version
# Changelog | ||
## 0.8.0 2022-03-15 | ||
## 0.8.0 2022-05-?? | ||
### Added | ||
@@ -19,2 +20,18 @@ | ||
## 0.7.3 2022-05-05 | ||
### Added | ||
- Export of serializeCredentialDeploymentTransactionForSubmission. | ||
### Fixed | ||
- Added missing dependency "google-protobuf" | ||
## 0.7.2 2022-05-05 | ||
### Added | ||
- Export of serializeAccountTransactionForSubmission. | ||
## 0.7.1 2022-03-09 | ||
@@ -21,0 +38,0 @@ |
@@ -453,2 +453,31 @@ # concordium-node-sdk-js | ||
To check if the account is a baker or a delegator, one can use the functions `isDelegatorAccount` and `isBakerAccount`. | ||
```js | ||
... | ||
const accountInfo: AccountInfo = await client.getAccountInfo(accountAddress, blockHash); | ||
if (isDelegatorAccount(accountInfo)) { | ||
const delegationDetails = accountInfo.accountDelegation; | ||
... | ||
} else if (isBakerAccount(accountInfo) { | ||
const bakingDetails = accountInfo.accountBaker; | ||
... | ||
} else { | ||
// Neither a baker nor a delegator | ||
} | ||
``` | ||
Furthermore there are different versions, based on Protocol version, of a baker's accountInfo. | ||
In protocol version 4 the concept of baker pools was introduced, so to get baker pool information one should confirm the version with `isBakerAccountV0` or `isBakerAccountV1`. | ||
```js | ||
... | ||
const accountInfo: AccountInfo = await client.getAccountInfo(accountAddress, blockHash); | ||
if (isBakerAccountV1(accountInfo)) { | ||
const bakerPoolInfo = accountInfo.accountBaker.bakerPoolInfo; | ||
... | ||
} else if (isBakerAccountV0(accountInfo) { | ||
// accountInfo is from protocol version < 4, so it will not contain bakerPoolInfo | ||
... | ||
} | ||
``` | ||
## getNextAccountNonce | ||
@@ -512,2 +541,21 @@ Retrieves the next account nonce, i.e. the nonce that must be set in the account transaction | ||
Blocks before protocol version 4 have a different type than those from higher protocol versions. | ||
To determine the version, use `isBlockSummaryV1` and `isBlockSummaryV0`: | ||
```js | ||
... | ||
const blockSummary: BlockSummary = await client.getBlockSummary(blockHash); | ||
if (isBlockSummaryV0(blockSummary)) { | ||
// This block is from protocol version <= 3, and so the summary has version 0 structure | ||
... | ||
} else if (isBlockSummaryV1(blockSummary) { | ||
// This block is from protocol version >= 4, and so the summary has version 1 structure | ||
... | ||
} else { | ||
// Must be a future version of a blockSummary (or the given object is not a blockSummary) | ||
} | ||
``` | ||
There are also type checks for specific fields in the summary, which can be found in [blockSummaryHelpers](src/blockSummaryHelpers.ts). | ||
## getBlockInfo | ||
@@ -592,2 +640,21 @@ Retrieves information about a specific block. | ||
## getRewardStatus | ||
Retrieves the current amount of funds in the system at a specific block, and the state of the special accounts. | ||
Protocol version 4 expanded the amount of information in the response, so one should check the type to access that. | ||
This information includes information about the payday and total amount of funds staked. | ||
```js | ||
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749"; | ||
const rewardStatus = await client.getRewardStatus(blockHash); | ||
if (isRewardStatusV1(rewardStatus)) { | ||
const nextPaydayTime = rewardStatus.nextPaydayTime; | ||
... | ||
} else if (isRewardStatusV0(rewardStatus)) { | ||
// This status is for a block from protocol version <= 3, so it will only have limited information | ||
... | ||
} | ||
... | ||
``` | ||
## Check block for transfers with memo | ||
@@ -830,2 +897,26 @@ The following example demonstrates how to check and parse a block | ||
## getInstances | ||
Used to get the full list of contract instances on the chain at a specific block. | ||
```js | ||
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749"; | ||
const instances = await client.getInstances(blockHash); | ||
... | ||
``` | ||
## getInstanceInfo | ||
Used to get information about a specific contract instance, at a specific block. | ||
```js | ||
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749"; | ||
const contractAddress = { index: 1n, subindex: 0n }; | ||
const instanceInfo = await client.getInstanceInfo(blockHash, contractAddress); | ||
const name = instanceInfo.name; | ||
... | ||
``` | ||
Note that only version 0 contracts returns the model. (use `isInstanceInfoV0`/`isInstanceInfoV1` to check the version) | ||
## Deserialize contract state | ||
@@ -837,3 +928,3 @@ The following example demonstrates how to deserialize a contract's state: | ||
const schema = Buffer.from(schemaSource); // Load schema from file | ||
const rawContractState = Buffer.from(stateSource); // Could be getinstanceInfo(...).model | ||
const rawContractState = Buffer.from(stateSource); // Could be getinstanceInfo(...).model (if contract is version 0) | ||
const state = deserializeContractState(contractName, schema, rawContractState); | ||
@@ -840,0 +931,0 @@ ``` |
import { ReduceStakePendingChange, RemovalPendingChange, StakePendingChange, StakePendingChangeV1 } from '.'; | ||
import { AccountInfo, AccountInfoBaker, AccountInfoBakerV1, AccountInfoDelegator } from './types'; | ||
import { AccountInfo, AccountInfoBaker, AccountInfoBakerV0, AccountInfoBakerV1, AccountInfoDelegator, StakePendingChangeV0 } from './types'; | ||
export declare const isDelegatorAccount: (ai: AccountInfo) => ai is AccountInfoDelegator; | ||
export declare const isBakerAccount: (ai: AccountInfo) => ai is AccountInfoBaker; | ||
export declare const isBakerAccountV1: (ai: AccountInfo) => ai is AccountInfoBakerV1; | ||
export declare const isBakerAccountV0: (ai: AccountInfo) => ai is AccountInfoBakerV0; | ||
export declare const isStakePendingChangeV1: (spc: StakePendingChange) => spc is StakePendingChangeV1; | ||
export declare const isStakePendingChangeV0: (spc: StakePendingChange) => spc is StakePendingChangeV0; | ||
export declare const isReduceStakePendingChange: (spc: ReduceStakePendingChange | RemovalPendingChange) => spc is ReduceStakePendingChange; | ||
export declare const isRemovalPendingChange: (spc: ReduceStakePendingChange | RemovalPendingChange) => spc is RemovalPendingChange; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isRemovalPendingChange = exports.isReduceStakePendingChange = exports.isStakePendingChangeV1 = exports.isBakerAccountV1 = exports.isBakerAccount = exports.isDelegatorAccount = void 0; | ||
exports.isRemovalPendingChange = exports.isReduceStakePendingChange = exports.isStakePendingChangeV0 = exports.isStakePendingChangeV1 = exports.isBakerAccountV0 = exports.isBakerAccountV1 = exports.isBakerAccount = exports.isDelegatorAccount = void 0; | ||
const isDelegatorAccount = (ai) => ai.accountDelegation !== undefined; | ||
@@ -10,4 +10,8 @@ exports.isDelegatorAccount = isDelegatorAccount; | ||
exports.isBakerAccountV1 = isBakerAccountV1; | ||
const isBakerAccountV0 = (ai) => ai.accountBaker?.bakerPoolInfo === undefined; | ||
exports.isBakerAccountV0 = isBakerAccountV0; | ||
const isStakePendingChangeV1 = (spc) => spc.effectiveTime !== undefined; | ||
exports.isStakePendingChangeV1 = isStakePendingChangeV1; | ||
const isStakePendingChangeV0 = (spc) => spc.epoch !== undefined; | ||
exports.isStakePendingChangeV0 = isStakePendingChangeV0; | ||
const isReduceStakePendingChange = (spc) => spc.newStake !== undefined; | ||
@@ -14,0 +18,0 @@ exports.isReduceStakePendingChange = isReduceStakePendingChange; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k; |
@@ -1,7 +0,13 @@ | ||
import { Authorizations, AuthorizationsV1, BlockSummary, BlockSummaryV1, ChainParameters, ChainParametersV1, Keys, KeysV1, UpdateQueues, UpdateQueuesV1, Updates, UpdatesV1 } from './types'; | ||
import { Authorizations, AuthorizationsV0, AuthorizationsV1, BlockSummary, BlockSummaryV0, BlockSummaryV1, ChainParameters, ChainParametersV0, ChainParametersV1, Keys, KeysV0, KeysV1, UpdateQueues, UpdateQueuesV0, UpdateQueuesV1, Updates, UpdatesV0, UpdatesV1 } from './types'; | ||
export declare const isAuthorizationsV1: (a: Authorizations) => a is AuthorizationsV1; | ||
export declare function isAuthorizationsV0(a: Authorizations): a is AuthorizationsV0; | ||
export declare const isChainParametersV1: (cp: ChainParameters) => cp is ChainParametersV1; | ||
export declare const isChainParametersV0: (cp: ChainParameters) => cp is ChainParametersV0; | ||
export declare const isKeysV1: (k: Keys) => k is KeysV1; | ||
export declare const isKeysV0: (k: Keys) => k is KeysV0; | ||
export declare const isUpdateQueuesV1: (uq: UpdateQueues) => uq is UpdateQueuesV1; | ||
export declare const isUpdateQueuesV0: (uq: UpdateQueues) => uq is UpdateQueuesV0; | ||
export declare const isUpdatesV1: (u: Updates) => u is UpdatesV1; | ||
export declare const isUpdatesV0: (u: Updates) => u is UpdatesV0; | ||
export declare const isBlockSummaryV1: (bs: BlockSummary) => bs is BlockSummaryV1; | ||
export declare const isBlockSummaryV0: (bs: BlockSummary) => bs is BlockSummaryV0; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isBlockSummaryV1 = exports.isUpdatesV1 = exports.isUpdateQueuesV1 = exports.isKeysV1 = exports.isChainParametersV1 = exports.isAuthorizationsV1 = void 0; | ||
exports.isBlockSummaryV0 = exports.isBlockSummaryV1 = exports.isUpdatesV0 = exports.isUpdatesV1 = exports.isUpdateQueuesV0 = exports.isUpdateQueuesV1 = exports.isKeysV0 = exports.isKeysV1 = exports.isChainParametersV0 = exports.isChainParametersV1 = exports.isAuthorizationsV0 = exports.isAuthorizationsV1 = void 0; | ||
const isAuthorizationsV1 = (a) => a.timeParameters !== undefined; | ||
exports.isAuthorizationsV1 = isAuthorizationsV1; | ||
function isAuthorizationsV0(a) { | ||
return a.timeParameters === undefined; | ||
} | ||
exports.isAuthorizationsV0 = isAuthorizationsV0; | ||
const isChainParametersV1 = (cp) => cp.mintPerPayday !== undefined; | ||
exports.isChainParametersV1 = isChainParametersV1; | ||
const isChainParametersV0 = (cp) => cp.minimumThresholdForBaking !== undefined; | ||
exports.isChainParametersV0 = isChainParametersV0; | ||
const isKeysV1 = (k) => (0, exports.isAuthorizationsV1)(k.level2Keys); | ||
exports.isKeysV1 = isKeysV1; | ||
const isKeysV0 = (k) => isAuthorizationsV0(k.level2Keys); | ||
exports.isKeysV0 = isKeysV0; | ||
const isUpdateQueuesV1 = (uq) => uq.timeParameters !== undefined; | ||
exports.isUpdateQueuesV1 = isUpdateQueuesV1; | ||
const isUpdateQueuesV0 = (uq) => uq.bakerStakeThreshold !== undefined; | ||
exports.isUpdateQueuesV0 = isUpdateQueuesV0; | ||
const isUpdatesV1 = (u) => (0, exports.isUpdateQueuesV1)(u.updateQueues); | ||
exports.isUpdatesV1 = isUpdatesV1; | ||
const isUpdatesV0 = (u) => (0, exports.isUpdateQueuesV0)(u.updateQueues); | ||
exports.isUpdatesV0 = isUpdatesV0; | ||
const isBlockSummaryV1 = (bs) => bs.protocolVersion !== undefined && bs.protocolVersion > 3n; | ||
exports.isBlockSummaryV1 = isBlockSummaryV1; | ||
const isBlockSummaryV0 = (bs) => bs.protocolVersion === undefined || bs.protocolVersion <= 3n; | ||
exports.isBlockSummaryV0 = isBlockSummaryV0; |
@@ -343,3 +343,3 @@ "use strict"; | ||
if (result !== undefined) { | ||
const instanceInfo = { | ||
const common = { | ||
amount: new gtuAmount_1.GtuAmount(BigInt(result.amount)), | ||
@@ -350,5 +350,21 @@ sourceModule: new moduleReference_1.ModuleReference(result.sourceModule), | ||
name: result.name, | ||
model: buffer_1.Buffer.from(result.model, 'hex'), | ||
}; | ||
return instanceInfo; | ||
switch (result.version) { | ||
case 1: | ||
return { | ||
version: 1, | ||
...common, | ||
}; | ||
case undefined: | ||
case 0: | ||
return { | ||
version: 0, | ||
...common, | ||
model: buffer_1.Buffer.from(result.model, 'hex'), | ||
}; | ||
default: | ||
throw new Error('InstanceInfo had unsupported version: ' + | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
result.version); | ||
} | ||
} | ||
@@ -355,0 +371,0 @@ } |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k; |
import ConcordiumNodeClient from './client'; | ||
import { getAccountTransactionHash, getAccountTransactionSignDigest, getCredentialDeploymentSignDigest, getCredentialDeploymentTransactionHash, getCredentialForExistingAccountSignDigest, serializeInitContractParameters, serializeUpdateContractParameters } from './serialization'; | ||
import { getAccountTransactionHash, getAccountTransactionSignDigest, getCredentialDeploymentSignDigest, getCredentialDeploymentTransactionHash, getCredentialForExistingAccountSignDigest, serializeInitContractParameters, serializeUpdateContractParameters, serializeAccountTransactionForSubmission, serializeCredentialDeploymentTransactionForSubmission } from './serialization'; | ||
import { sha256 } from './hash'; | ||
@@ -7,3 +7,3 @@ import { getModuleBuffer } from './deserializeSchema'; | ||
export * from './types'; | ||
export { getAccountTransactionHash, getAccountTransactionSignDigest, getCredentialDeploymentSignDigest, getCredentialDeploymentTransactionHash, getCredentialForExistingAccountSignDigest, serializeInitContractParameters, serializeUpdateContractParameters, getModuleBuffer, }; | ||
export { getAccountTransactionHash, getAccountTransactionSignDigest, getCredentialDeploymentSignDigest, getCredentialDeploymentTransactionHash, getCredentialForExistingAccountSignDigest, serializeInitContractParameters, serializeUpdateContractParameters, serializeAccountTransactionForSubmission, serializeCredentialDeploymentTransactionForSubmission, getModuleBuffer, }; | ||
export { sha256 }; | ||
@@ -21,2 +21,4 @@ export { CredentialRegistrationId } from './types/CredentialRegistrationId'; | ||
export { deserializeContractState } from './deserialization'; | ||
export * from './accountHelpers'; | ||
export * from './blockSummaryHelpers'; | ||
export * from './rewardStatusHelpers'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -20,3 +16,3 @@ if (k2 === undefined) k2 = k; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.deserializeContractState = exports.getAlias = exports.isAlias = exports.buildSignedCredentialForExistingAccount = exports.getAccountAddress = exports.createUnsignedCredentialForExistingAccount = exports.createCredentialDeploymentTransaction = exports.decryptMobileWalletExport = exports.ModuleReference = exports.DataBlob = exports.TransactionExpiry = exports.GtuAmount = exports.AccountAddress = exports.CredentialRegistrationId = exports.sha256 = exports.getModuleBuffer = exports.serializeUpdateContractParameters = exports.serializeInitContractParameters = exports.getCredentialForExistingAccountSignDigest = exports.getCredentialDeploymentTransactionHash = exports.getCredentialDeploymentSignDigest = exports.getAccountTransactionSignDigest = exports.getAccountTransactionHash = exports.ConcordiumNodeClient = void 0; | ||
exports.deserializeContractState = exports.getAlias = exports.isAlias = exports.buildSignedCredentialForExistingAccount = exports.getAccountAddress = exports.createUnsignedCredentialForExistingAccount = exports.createCredentialDeploymentTransaction = exports.decryptMobileWalletExport = exports.ModuleReference = exports.DataBlob = exports.TransactionExpiry = exports.GtuAmount = exports.AccountAddress = exports.CredentialRegistrationId = exports.sha256 = exports.getModuleBuffer = exports.serializeCredentialDeploymentTransactionForSubmission = exports.serializeAccountTransactionForSubmission = exports.serializeUpdateContractParameters = exports.serializeInitContractParameters = exports.getCredentialForExistingAccountSignDigest = exports.getCredentialDeploymentTransactionHash = exports.getCredentialDeploymentSignDigest = exports.getAccountTransactionSignDigest = exports.getAccountTransactionHash = exports.ConcordiumNodeClient = void 0; | ||
const client_1 = __importDefault(require("./client")); | ||
@@ -32,2 +28,4 @@ exports.ConcordiumNodeClient = client_1.default; | ||
Object.defineProperty(exports, "serializeUpdateContractParameters", { enumerable: true, get: function () { return serialization_1.serializeUpdateContractParameters; } }); | ||
Object.defineProperty(exports, "serializeAccountTransactionForSubmission", { enumerable: true, get: function () { return serialization_1.serializeAccountTransactionForSubmission; } }); | ||
Object.defineProperty(exports, "serializeCredentialDeploymentTransactionForSubmission", { enumerable: true, get: function () { return serialization_1.serializeCredentialDeploymentTransactionForSubmission; } }); | ||
const hash_1 = require("./hash"); | ||
@@ -62,2 +60,4 @@ Object.defineProperty(exports, "sha256", { enumerable: true, get: function () { return hash_1.sha256; } }); | ||
Object.defineProperty(exports, "deserializeContractState", { enumerable: true, get: function () { return deserialization_1.deserializeContractState; } }); | ||
__exportStar(require("./accountHelpers"), exports); | ||
__exportStar(require("./blockSummaryHelpers"), exports); | ||
__exportStar(require("./rewardStatusHelpers"), exports); |
@@ -1,2 +0,3 @@ | ||
import { RewardStatus, RewardStatusV1 } from './types'; | ||
export declare const isRewardStatusV1: (rs: RewardStatus) => rs is RewardStatusV1; | ||
import { RewardStatus, RewardStatusV0, RewardStatusV1 } from './types'; | ||
export declare function isRewardStatusV1(rs: RewardStatus): rs is RewardStatusV1; | ||
export declare function isRewardStatusV0(rs: RewardStatus): rs is RewardStatusV0; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isRewardStatusV1 = void 0; | ||
const isRewardStatusV1 = (rs) => rs.protocolVersion !== undefined && rs.protocolVersion > 3n; | ||
exports.isRewardStatusV0 = exports.isRewardStatusV1 = void 0; | ||
function isRewardStatusV1(rs) { | ||
return rs.protocolVersion !== undefined && rs.protocolVersion > 3n; | ||
} | ||
exports.isRewardStatusV1 = isRewardStatusV1; | ||
function isRewardStatusV0(rs) { | ||
return rs.protocolVersion === undefined || rs.protocolVersion <= 3n; | ||
} | ||
exports.isRewardStatusV0 = isRewardStatusV0; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k; |
@@ -46,3 +46,3 @@ import { AccountAddress } from './types/accountAddress'; | ||
export interface TransactionEvent { | ||
tag: 'ModuleDeployed' | 'ContractInitialized' | 'AccountCreated' | 'CredentialDeployed' | 'BakerAdded' | 'BakerRemoved' | 'BakerStakeIncreased' | 'BakerStakeDecreased' | 'BakerSetRestakeEarnings' | 'BakerKeysUpdated' | 'CredentialKeysUpdated' | 'NewEncryptedAmount' | 'EncryptedAmountsRemoved' | 'AmountAddedByDecryption' | 'EncryptedSelfAmountAdded' | 'UpdateEnqueued' | 'TransferredWithSchedule' | 'CredentialsUpdated' | 'DataRegistered'; | ||
tag: 'ModuleDeployed' | 'ContractInitialized' | 'AccountCreated' | 'CredentialDeployed' | 'BakerAdded' | 'BakerRemoved' | 'BakerStakeIncreased' | 'BakerStakeDecreased' | 'BakerSetRestakeEarnings' | 'BakerKeysUpdated' | 'CredentialKeysUpdated' | 'NewEncryptedAmount' | 'EncryptedAmountsRemoved' | 'AmountAddedByDecryption' | 'EncryptedSelfAmountAdded' | 'UpdateEnqueued' | 'TransferredWithSchedule' | 'CredentialsUpdated' | 'DataRegistered' | 'Interrupted' | 'Resumed' | 'BakerSetOpenStatus' | 'BakerSetMetadataURL' | 'BakerSetTransactionFeeCommission' | 'BakerSetBakingRewardCommission' | 'BakerSetFinalizationRewardCommission' | 'DelegationStakeIncreased' | 'DelegationStakeDecreased' | 'DelegationSetRestakeEarnings' | 'DelegationSetDelegationTarget' | 'DelegationAdded' | 'DelegationRemoved'; | ||
} | ||
@@ -126,3 +126,17 @@ export interface ContractAddress { | ||
NotAllowedToReceiveEncrypted = "NotAllowedToReceiveEncrypted", | ||
NotAllowedToHandleEncrypted = "NotAllowedToHandleEncrypted" | ||
NotAllowedToHandleEncrypted = "NotAllowedToHandleEncrypted", | ||
MissingBakerAddParameters = "MissingBakerAddParameters", | ||
FinalizationRewardCommissionNotInRange = "FinalizationRewardCommissionNotInRange", | ||
BakingRewardCommissionNotInRange = "BakingRewardCommissionNotInRange", | ||
TransactionFeeCommissionNotInRange = "TransactionFeeCommissionNotInRange", | ||
AlreadyADelegator = "AlreadyADelegator", | ||
InsufficientBalanceForDelegationStake = "InsufficientBalanceForDelegationStake", | ||
MissingDelegationAddParameters = "MissingDelegationAddParameters", | ||
InsufficientDelegationStake = "InsufficientDelegationStake", | ||
DelegatorInCooldown = "DelegatorInCooldown", | ||
NotADelegator = "NotADelegator", | ||
DelegationTargetNotABaker = "DelegationTargetNotABaker", | ||
StakeOverMaximumThresholdForPool = "StakeOverMaximumThresholdForPool", | ||
PoolWouldBecomeOverDelegated = "PoolWouldBecomeOverDelegated", | ||
PoolClosed = "PoolClosed" | ||
} | ||
@@ -926,3 +940,4 @@ export interface RejectReason { | ||
} | ||
export interface InstanceInfo { | ||
export interface InstanceInfoCommon { | ||
version: number; | ||
amount: GtuAmount; | ||
@@ -933,7 +948,17 @@ sourceModule: ModuleReference; | ||
name: string; | ||
} | ||
export interface InstanceInfoV0 extends InstanceInfoCommon { | ||
version: 0; | ||
model: Buffer; | ||
} | ||
export interface InstanceInfoV1 extends InstanceInfoCommon { | ||
version: 1; | ||
} | ||
export declare type InstanceInfo = InstanceInfoV0 | InstanceInfoV1; | ||
export declare const isInstanceInfoV1: (info: InstanceInfo) => info is InstanceInfoV1; | ||
export declare const isInstanceInfoV0: (info: InstanceInfo) => info is InstanceInfoV0; | ||
export declare type CredentialSignature = Record<number, string>; | ||
export declare type AccountTransactionSignature = Record<number, CredentialSignature>; | ||
export interface InstanceInfoSerialized { | ||
export interface InstanceInfoSerializedCommon { | ||
version?: number; | ||
amount: string; | ||
@@ -944,4 +969,11 @@ sourceModule: string; | ||
name: string; | ||
} | ||
export interface InstanceInfoSerializedV0 extends InstanceInfoSerializedCommon { | ||
version?: 0; | ||
model: string; | ||
} | ||
export interface InstanceInfoSerializedV1 extends InstanceInfoSerializedCommon { | ||
version: 1; | ||
} | ||
export declare type InstanceInfoSerialized = InstanceInfoSerializedV0 | InstanceInfoSerializedV1; | ||
export interface CredentialDeploymentTransaction { | ||
@@ -948,0 +980,0 @@ expiry: TransactionExpiry; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ParameterType = exports.AccountTransactionType = exports.BlockItemKind = exports.DelegationTargetType = exports.PoolStatusType = exports.BakerPoolPendingChangeType = exports.OpenStatusText = exports.OpenStatus = exports.StakePendingChangeType = exports.instanceOfTransferWithMemoTransactionSummary = exports.RejectReasonTag = exports.TransactionStatusEnum = exports.AttributesKeys = void 0; | ||
exports.isInstanceInfoV0 = exports.isInstanceInfoV1 = exports.ParameterType = exports.AccountTransactionType = exports.BlockItemKind = exports.DelegationTargetType = exports.PoolStatusType = exports.BakerPoolPendingChangeType = exports.OpenStatusText = exports.OpenStatus = exports.StakePendingChangeType = exports.instanceOfTransferWithMemoTransactionSummary = exports.RejectReasonTag = exports.TransactionStatusEnum = exports.AttributesKeys = void 0; | ||
var AttributesKeys; | ||
@@ -76,2 +76,16 @@ (function (AttributesKeys) { | ||
RejectReasonTag["NotAllowedToHandleEncrypted"] = "NotAllowedToHandleEncrypted"; | ||
RejectReasonTag["MissingBakerAddParameters"] = "MissingBakerAddParameters"; | ||
RejectReasonTag["FinalizationRewardCommissionNotInRange"] = "FinalizationRewardCommissionNotInRange"; | ||
RejectReasonTag["BakingRewardCommissionNotInRange"] = "BakingRewardCommissionNotInRange"; | ||
RejectReasonTag["TransactionFeeCommissionNotInRange"] = "TransactionFeeCommissionNotInRange"; | ||
RejectReasonTag["AlreadyADelegator"] = "AlreadyADelegator"; | ||
RejectReasonTag["InsufficientBalanceForDelegationStake"] = "InsufficientBalanceForDelegationStake"; | ||
RejectReasonTag["MissingDelegationAddParameters"] = "MissingDelegationAddParameters"; | ||
RejectReasonTag["InsufficientDelegationStake"] = "InsufficientDelegationStake"; | ||
RejectReasonTag["DelegatorInCooldown"] = "DelegatorInCooldown"; | ||
RejectReasonTag["NotADelegator"] = "NotADelegator"; | ||
RejectReasonTag["DelegationTargetNotABaker"] = "DelegationTargetNotABaker"; | ||
RejectReasonTag["StakeOverMaximumThresholdForPool"] = "StakeOverMaximumThresholdForPool"; | ||
RejectReasonTag["PoolWouldBecomeOverDelegated"] = "PoolWouldBecomeOverDelegated"; | ||
RejectReasonTag["PoolClosed"] = "PoolClosed"; | ||
})(RejectReasonTag = exports.RejectReasonTag || (exports.RejectReasonTag = {})); | ||
@@ -210,1 +224,5 @@ function instanceOfTransferWithMemoTransactionSummary(object) { | ||
})(ParameterType = exports.ParameterType || (exports.ParameterType = {})); | ||
const isInstanceInfoV1 = (info) => info.version === 1; | ||
exports.isInstanceInfoV1 = isInstanceInfoV1; | ||
const isInstanceInfoV0 = (info) => info.version === undefined || info.version === 0; | ||
exports.isInstanceInfoV0 = isInstanceInfoV0; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k; |
{ | ||
"name": "@concordium/node-sdk", | ||
"version": "0.8.0-alpha.3", | ||
"version": "1.0.0-alpha.0", | ||
"description": "Helpers for interacting with the Concordium node", | ||
@@ -60,2 +60,3 @@ "repository": { | ||
"@grpc/grpc-js": "^1.3.4", | ||
"google-protobuf": "^3.20.1", | ||
"bs58check": "^2.1.2", | ||
@@ -62,0 +63,0 @@ "buffer": "^6.0.3", |
@@ -453,2 +453,31 @@ # concordium-node-sdk-js | ||
To check if the account is a baker or a delegator, one can use the functions `isDelegatorAccount` and `isBakerAccount`. | ||
```js | ||
... | ||
const accountInfo: AccountInfo = await client.getAccountInfo(accountAddress, blockHash); | ||
if (isDelegatorAccount(accountInfo)) { | ||
const delegationDetails = accountInfo.accountDelegation; | ||
... | ||
} else if (isBakerAccount(accountInfo) { | ||
const bakingDetails = accountInfo.accountBaker; | ||
... | ||
} else { | ||
// Neither a baker nor a delegator | ||
} | ||
``` | ||
Furthermore there are different versions, based on Protocol version, of a baker's accountInfo. | ||
In protocol version 4 the concept of baker pools was introduced, so to get baker pool information one should confirm the version with `isBakerAccountV0` or `isBakerAccountV1`. | ||
```js | ||
... | ||
const accountInfo: AccountInfo = await client.getAccountInfo(accountAddress, blockHash); | ||
if (isBakerAccountV1(accountInfo)) { | ||
const bakerPoolInfo = accountInfo.accountBaker.bakerPoolInfo; | ||
... | ||
} else if (isBakerAccountV0(accountInfo) { | ||
// accountInfo is from protocol version < 4, so it will not contain bakerPoolInfo | ||
... | ||
} | ||
``` | ||
## getNextAccountNonce | ||
@@ -512,2 +541,21 @@ Retrieves the next account nonce, i.e. the nonce that must be set in the account transaction | ||
Blocks before protocol version 4 have a different type than those from higher protocol versions. | ||
To determine the version, use `isBlockSummaryV1` and `isBlockSummaryV0`: | ||
```js | ||
... | ||
const blockSummary: BlockSummary = await client.getBlockSummary(blockHash); | ||
if (isBlockSummaryV0(blockSummary)) { | ||
// This block is from protocol version <= 3, and so the summary has version 0 structure | ||
... | ||
} else if (isBlockSummaryV1(blockSummary) { | ||
// This block is from protocol version >= 4, and so the summary has version 1 structure | ||
... | ||
} else { | ||
// Must be a future version of a blockSummary (or the given object is not a blockSummary) | ||
} | ||
``` | ||
There are also type checks for specific fields in the summary, which can be found in [blockSummaryHelpers](src/blockSummaryHelpers.ts). | ||
## getBlockInfo | ||
@@ -592,2 +640,21 @@ Retrieves information about a specific block. | ||
## getRewardStatus | ||
Retrieves the current amount of funds in the system at a specific block, and the state of the special accounts. | ||
Protocol version 4 expanded the amount of information in the response, so one should check the type to access that. | ||
This information includes information about the payday and total amount of funds staked. | ||
```js | ||
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749"; | ||
const rewardStatus = await client.getRewardStatus(blockHash); | ||
if (isRewardStatusV1(rewardStatus)) { | ||
const nextPaydayTime = rewardStatus.nextPaydayTime; | ||
... | ||
} else if (isRewardStatusV0(rewardStatus)) { | ||
// This status is for a block from protocol version <= 3, so it will only have limited information | ||
... | ||
} | ||
... | ||
``` | ||
## Check block for transfers with memo | ||
@@ -830,2 +897,26 @@ The following example demonstrates how to check and parse a block | ||
## getInstances | ||
Used to get the full list of contract instances on the chain at a specific block. | ||
```js | ||
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749"; | ||
const instances = await client.getInstances(blockHash); | ||
... | ||
``` | ||
## getInstanceInfo | ||
Used to get information about a specific contract instance, at a specific block. | ||
```js | ||
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749"; | ||
const contractAddress = { index: 1n, subindex: 0n }; | ||
const instanceInfo = await client.getInstanceInfo(blockHash, contractAddress); | ||
const name = instanceInfo.name; | ||
... | ||
``` | ||
Note that only version 0 contracts returns the model. (use `isInstanceInfoV0`/`isInstanceInfoV1` to check the version) | ||
## Deserialize contract state | ||
@@ -837,3 +928,3 @@ The following example demonstrates how to deserialize a contract's state: | ||
const schema = Buffer.from(schemaSource); // Load schema from file | ||
const rawContractState = Buffer.from(stateSource); // Could be getinstanceInfo(...).model | ||
const rawContractState = Buffer.from(stateSource); // Could be getinstanceInfo(...).model (if contract is version 0) | ||
const state = deserializeContractState(contractName, schema, rawContractState); | ||
@@ -840,0 +931,0 @@ ``` |
2048714
0.63%12126
0.59%960
10.47%5
25%+ Added
+ Added