Skip to content

Commit

Permalink
Merge pull request #192 from Concordium/release/7.0
Browse files Browse the repository at this point in the history
Release/7.0
  • Loading branch information
rasmus-kirk authored May 16, 2023
2 parents 3226f42 + 25d6dbe commit 246b544
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 77 deletions.
22 changes: 11 additions & 11 deletions docs/CIS2Contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ The CIS2Contract class wraps the [ConcordiumNodeClient]('./gRPC.md'), defining a
## Creating a CIS2Contract
The contract relies on a `ConcordiumNodeClient` instance to communicate with the node along with a contract address of the CIS-2 contract to invoke functions on.

```js
```ts
const contractAddress = {index: 1234n, subindex: 0n};
const contract = await CIS2Contract.create(nodeClient, contractAddress); // Implied that you already have a `ConcordiumNodeClient` instance of some form.
```

This gets the relevant contract information from the node and checks that the contract is in fact a CIS-2 contract (through the [CIS-0 supports function](../packages/common/README.md#check-smart-contract-for-support-for-standards)), hence why it is async. You can also instantiate using the `new` keyword, circumventing standard checks:

```js
```ts
const contract = new CIS2Contract(nodeClient, contractAddress, 'my_contract_name');
```

Expand All @@ -37,7 +37,7 @@ This relies on using private keys for the sender account to sign the transaction

See the signing a transaction section for the [common package](../packages/common/README.md#sign-an-account-transaction) for create an `AccountSigner`.

```js
```ts
const tokenId = ''; // HEX string representing a token ID defined in the contract.
const from = '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd';
const to = '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'; // An account receiver.
Expand All @@ -61,7 +61,7 @@ const txHash = await contract.transfer(
### Create transfer transaction
This creates a CIS-2 "transfer" transaction, that can then be submitted the transaction through a Concordium compatible wallet, which handles signing and submitting.

```js
```ts
const tokenId = ''; // HEX string representing a token ID defined in the contract.
const from = '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd';
const to = '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'; // An account receiver.
Expand Down Expand Up @@ -94,7 +94,7 @@ This relies on using private keys for the sender account to sign the transaction

See the signing a transaction section for the [common package](../packages/common/README.md#sign-an-account-transaction) for create an `AccountSigner`.

```js
```ts
const owner = '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd';
const type = 'add'; // or 'remove';
const address = '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'; // Address to add as operator of owner
Expand All @@ -117,7 +117,7 @@ const txHash = await contract.updateOperator(
### Create update operator transaction
This creates a CIS-2 "updateOperator" transaction, that can then be submitted the transaction through a Concordium compatible wallet, which handles signing and submitting.

```js
```ts
const owner = '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd';
const type = 'add'; // or 'remove';
const address = '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'; // Address to add as operator of owner
Expand Down Expand Up @@ -146,7 +146,7 @@ const {
## Querying for balance of token(s)
The following example demonstrates how to send either a single/list of CIS-2 "balanceOf" queries using a `CIS2Contract` instance. The response for the query will be either a single/list of bigint balances corresponding to the queries.

```js
```ts
const tokenId = ''; // HEX string representing a token ID defined in the contract.
const address = '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd';

Expand All @@ -164,7 +164,7 @@ const [balance1, balance2, balance3] = await contract.balanceOf([query1, query2,
## Querying for operator of
The following example demonstrates how to send either a single/list of CIS-2 "operatorOf" queries using a `CIS2Contract` instance. The response for the query will be either a single/list of boolean values corresponding to the queries, each signaling whether the specified `address` is an operator of the specified `owner`.

```js
```ts
const owner = '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd';
const address = '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'; // Address to check if operator of owner
// const address = {index: 1234n, 0n}; // Example of contract address operator.
Expand All @@ -186,7 +186,7 @@ The following example demonstrates how to send either a single/list of CIS-2 "to

To get the actual metadata JSON for the contract, a subsequent request to the URL returned would have to be made.

```js
```ts
const tokenId = ''; // HEX string representing a token ID defined in the contract.
const metadataUrl = await contract.tokenMetadata(tokenId);

Expand All @@ -205,7 +205,7 @@ One common use case is to check the energy needed to execute the update which ca
### Token transfer(s) dry-run
The following example demonstrates how to perform a dry-run of CIS-2 "transfer" with either a single/list of transfers using a `CIS2Contract` instance. The response will be an object containing information about the function invocation.

```js
```ts
const tokenId = ''; // HEX string representing a token ID defined in the contract.
const from = '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd';
const to = '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'; // An account receiver.
Expand All @@ -222,7 +222,7 @@ const result = await contract.dryRun.transfer(from, update);
### Operator updates(s) dry-run
The following example demonstrates how to perform a dry-run of CIS-2 "updateOperator" with either a single/list of updates using a `CIS2Contract` instance. The response will be an object containing information about the function invocation.

```js
```ts
const owner = '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd';
const type = 'add'; // or 'remove';
const address = '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'; // Address to add as operator of owner
Expand Down
12 changes: 6 additions & 6 deletions docs/gRPC.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,11 @@ Note that some of the parts of the context are optional:
## getModuleSource
This commands gets the source of a module on the chain.
Note that this returns the raw bytes of the source, as a Uint8Array.
```ts
const blockHash = 'fe88ff35454079c3df11d8ae13d5777babd61f28be58494efe51b6593e30716e';
const moduleRef = '7e8398adc406a97db4d869c3fd7adc813a3183667a3a7db078ebae6f7dce5f64';
const source = await client.getModuleSource(moduleReference, blockHash);
const versionedSource = await client.getModuleSource(moduleReference, blockHash);

const version: 0 | 1 = versionedSource.version
const rawSource: Buffer = versionedSource.source
```
## getBlocks
Expand Down Expand Up @@ -920,8 +920,8 @@ if (blockFinalizationSummary.tag === "record") {
Gets a stream of finalized blocks from the specified block height. The stream continues indefinitely unless receiving an abort signal.
```ts
const bis = await client.getFinalizedBlocksFrom(123n);
for await (const bi of bis) {
const blockInfoStream = await client.getFinalizedBlocksFrom(123n);
for await (const blockInfo of blockInfoStream) {
// Do something with the block.
}
```
Expand Down
62 changes: 31 additions & 31 deletions docs/grpc-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ a concordium-node.
## Creating a client
The current node setup only allows for insecure connections, which can be set up in the following way.
The access is controlled by the credentials and the metadata.
```js
```ts
import { credentials, Metadata } from "@grpc/grpc-js";
import { ConcordiumNodeClient } from "@concordium/node-sdk";

Expand All @@ -58,7 +58,7 @@ The following example demonstrates how to send any account transaction.
See the Constructing transactions section for the [common package](../common#constructing-transactions) for how to create an account transaction.
See the signing a transaction section for the [common package](../common#sign-an-account-transaction) for how to sign an account transaction.

```js
```ts

let accountTransaction: AccountTransaction;
// Create the transaction
Expand Down Expand Up @@ -87,7 +87,7 @@ const transactionStatus = await client.getTransactionStatus(transactionHash);
The following example demonstrates how to create a new account on an existing
identity. The `credentialIndex` should be the next unused credential index for that identity, and keeping track of that index is done off-chain. Note that index `0` is used by the initial account that was created together with the identity.
See [Construct IdentityInput](#Construct-identityInput-for-creating-credentials) for how to construct an IdentityInput.
```js
```ts
const lastFinalizedBlockHash = (await client.getConsensusStatus()).lastFinalizedBlock;
const cryptographicParameters = await client.getCryptographicParameters(lastFinalizedBlockHash);
if (!cryptographicParameters) {
Expand Down Expand Up @@ -180,7 +180,7 @@ To create accounts/credentials on that identity, this SDK expects an "IdentityIn

Below is an example of how to construct the identityInput, with a plaintext id-use-data.json from the [user-cli guide](https://github.com/Concordium/concordium-base/blob/main/rust-bins/docs/user-cli.md#generate-a-request-for-the-identity-object), and an id-object file.

```js
```ts
// First we load the files. We assume here that they are available as local files.
const rawIdUseData = fs.readFileSync(
'path/to/id-use-data.json',
Expand Down Expand Up @@ -212,7 +212,7 @@ const identityInput: IdentityInput = {

The following is an example of how to construct the identityInput for the _i_-th identity from a mobile wallet export:

```js
```ts
// We assume the export is available as a local file:
const rawData = fs.readFileSync(
'path/to/export.concordiumwallet',
Expand All @@ -239,7 +239,7 @@ If a credential registration id is provided, then the node returns the informati
which the corresponding credential is (or was) deployed to.
If there is no account that matches the address or credential id at the provided
block, then undefined will be returned.
```js
```ts
const accountAddress = new AccountAddress("3sAHwfehRNEnXk28W7A3XB3GzyBiuQkXLNRmDwDGPUe8JsoAcU");
const blockHash = "6b01f2043d5621192480f4223644ef659dd5cda1e54a78fc64ad642587c73def";
const accountInfo: AccountInfo = await client.getAccountInfo(accountAddress, blockHash);
Expand All @@ -250,7 +250,7 @@ const nationality: string = accountInfo.accountCredentials[0].value.contents.pol
```

To check if the account is a baker or a delegator, one can use the functions `isDelegatorAccount` and `isBakerAccount`.
```js
```ts
...
const accountInfo: AccountInfo = await client.getAccountInfo(accountAddress, blockHash);
if (isDelegatorAccount(accountInfo)) {
Expand All @@ -266,7 +266,7 @@ if (isDelegatorAccount(accountInfo)) {
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
```ts
...
const accountInfo: AccountInfo = await client.getAccountInfo(accountAddress, blockHash);
if (isBakerAccountV1(accountInfo)) {
Expand All @@ -283,7 +283,7 @@ Retrieves the next account nonce, i.e. the nonce that must be set in the account
header for the next transaction submitted by that account. Along with the nonce there is a boolean
that indicates whether all transactions are finalized. If this is true, then the nonce is reliable,
if not then the next nonce might be off.
```js
```ts
const accountAddress = new AccountAddress("3VwCfvVskERFAJ3GeJy2mNFrzfChqUymSJJCvoLAP9rtAwMGYt");
const nextAccountNonce: NextAccountNonce = await client.getNextAccountNonce(accountAddress);
const nonce: bigint = nextAccountNonce.nonce;
Expand All @@ -295,28 +295,28 @@ if (allFinal) {
## getTransactionStatus
Retrieves status information about a transaction.
```js
```ts
const transactionHash = "f1f5f966e36b95d5474e6b85b85c273c81bac347c38621a0d8fefe68b69a430f";
const transactionStatus: TransactionStatus = await client.getTransactionStatus(transactionHash);
const isFinalized = transactionStatus.status === TransactionStatusEnum.Finalized;
...
```
Note that there will be no outcomes for a transaction that has only been received:
```js
```ts
if (transactionStatus.status === TransactionStatusEnum.Received) {
const outcomes = Object.values(transactionStatus.outcomes);
// outcomes.length === 0.
}
```
If the transaction has been finalized, then there is exactly one outcome:
```js
```ts
if (transactionStatus.status === TransactionStatusEnum.Finalized) {
const outcomes = Object.values(transactionStatus.outcomes);
// outcomes.length === 1.
}
```
A transaction was successful if it is finalized and it has a successful outcome:
```js
```ts
if (transactionStatus.status === TransactionStatusEnum.Finalized) {
const event = Object.values(response.outcomes)[0];
if (event.result.outcome === "success") {
Expand All @@ -329,7 +329,7 @@ if (transactionStatus.status === TransactionStatusEnum.Finalized) {
Retrives a summary for a specific block. The summary contains information about finalization, the
current chain parameters, a list of the governance keys, information about any queued chain parameter
updates and a summary of any transactions within the block.
```js
```ts
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8761d08554756f42bf268a42749";
const blockSummary: BlockSummary = await client.getBlockSummary(blockHash);
const numberOfFinalizers = blockSummary.finalizationData.finalizers.length;
Expand All @@ -339,7 +339,7 @@ const numberOfFinalizers = blockSummary.finalizationData.finalizers.length;
Blocks before protocol version 4 have a different type than those from higher protocol versions.
To determine the version, use `isBlockSummaryV1` and `isBlockSummaryV0`:
```js
```ts
...
const blockSummary: BlockSummary = await client.getBlockSummary(blockHash);
if (isBlockSummaryV0(blockSummary)) {
Expand All @@ -357,7 +357,7 @@ There are also type checks for specific fields in the summary, which can be foun
## getBlockInfo
Retrieves information about a specific block.
```js
```ts
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8761d08554756f42bf268a42749";
const blockInfo: BlockInfo = await client.getBlockInfo(blockHash);
const transactionsCount = blockInfo.transactionCount;
Expand All @@ -366,14 +366,14 @@ const transactionsCount = blockInfo.transactionCount;
## getBlocksAtHeight
Retrieves the hashes of blocks at a specific height.
```js
```ts
const blockHeight: bigint = 5310n;
const blocksAtHeight: string[] = await client.getBlocksAtHeight(blockHeight);
```
## getConsensusStatus
Retrieves the current consensus status from the node.
```js
```ts
const consensusStatus: ConsensusStatus = await client.getConsensusStatus();
const bestBlock = consensusStatus.bestBlock;
...
Expand All @@ -382,23 +382,23 @@ const bestBlock = consensusStatus.bestBlock;
## getCryptographicParameters
Retrieves the global cryptographic parameters for the blockchain at a specific block.
These are a required input for e.g. creating credentials.
```js
```ts
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8761d08554756f42bf268a42749"
const cryptographicParameters = await client.getCryptographicParameters(blockHash);
...
```
## getIdentityProviders
Retrieves the list of identity providers at a specific block.
```js
```ts
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749";
const identityProviders = await client.getIdentityProviders(blockHash);
...
```
## getAnonymityRevokers
Retrieves the list of anonymity revokers at a specific block.
```js
```ts
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749";
const identityProviders = await client.getAnonymityRevokers(blockHash);
...
Expand All @@ -408,15 +408,15 @@ const identityProviders = await client.getAnonymityRevokers(blockHash);
Retrieves the list of peers that the node is connected to, including some
connection information about them. A boolean parameter determines if this
should include bootstrapper nodes or not.
```js
```ts
const peerListResponse = await client.getPeerList(false);
const peersList = peerListResponse.getPeersList();
...
```
## getBakerList
Retrieves the list of ID's for registered bakers on the network at a specific block.
```js
```ts
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749";
const bakerIds = await client.getBakerList(blockHash);
...
Expand All @@ -425,7 +425,7 @@ const bakerIds = await client.getBakerList(blockHash);
## getPoolStatus
Retrieves the status of a pool (either a specific baker or passive delegation) at a specific block.
If a baker ID is specified, the status of that baker is returned. To get the status of passive delegation, baker ID should be left undefined.
```js
```ts
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749";
const bakerId = BigInt(1);

Expand All @@ -436,15 +436,15 @@ const passiveDelegationStatus = await client.getPoolStatus(blockHash);
## getRewardStatus
Retrieves the current amount of funds in the system at a specific block, and the state of the special accounts.
```js
```ts
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749";

const rewardStatus = await client.getRewardStatus(blockHash);
```
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
```ts
if (isRewardStatusV1(rewardStatus)) {
const nextPaydayTime = rewardStatus.nextPaydayTime;
...
Expand All @@ -454,7 +454,7 @@ if (isRewardStatusV1(rewardStatus)) {
## Check block for transfers with memo
The following example demonstrates how to check and parse a block
for transfers with a memo.
```js
```ts
const blockHash = "b49bb1c06c697b7d6539c987082c5a0dc6d86d91208874517ab17da752472edf";
const blockSummary = await client.getBlockSummary(blockHash);
const transactionSummaries = blockSummary.transactionSummaries;
Expand All @@ -476,7 +476,7 @@ for (const transactionSummary of transactionSummaries) {
## getInstances
Used to get the full list of contract instances on the chain at a specific block.
```js
```ts
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749";

const instances = await client.getInstances(blockHash);
Expand All @@ -486,7 +486,7 @@ const instances = await client.getInstances(blockHash);
## getInstanceInfo
Used to get information about a specific contract instance, at a specific block.
```js
```ts
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749";
const contractAddress = { index: 1n, subindex: 0n };

Expand All @@ -500,7 +500,7 @@ Note that only version 0 contracts returns the model. (use `isInstanceInfoV0`/`i
## invokeContract
Used to simulate a contract update, and to trigger view functions.
```js
```ts
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749";
const contractAddress = { index: 1n, subindex: 0n };
const invoker = new AccountAddress('3tXiu8d4CWeuC12irAB7YVb1hzp3YxsmmmNzzkdujCPqQ9EjDm');
Expand Down Expand Up @@ -541,7 +541,7 @@ Note that some of the parts of the context are optional:
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
```ts
const blockHash = "7f7409679e53875567e2ae812c9fcefe90ced8961d08554756f42bf268a42749";
const moduleReference = "c0e51cd55ccbff4fa8da9bb76c9917e83ae8286d86b47647104bf715b4821c1a";
const source = await client.getModuleSource(moduleReference, blockHash);
Expand Down
Loading

0 comments on commit 246b544

Please sign in to comment.