Skip to content

Commit

Permalink
Merge pull request #385 from Concordium/release/web-sdk/8
Browse files Browse the repository at this point in the history
web SDK v8
  • Loading branch information
soerenbf authored Sep 10, 2024
2 parents 98a2736 + b262717 commit 48ecde2
Show file tree
Hide file tree
Showing 31 changed files with 328 additions and 218 deletions.
4 changes: 3 additions & 1 deletion examples/nodejs/client/getEmbeddedSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
const schema = await client.getEmbeddedSchema(moduleRef);
// #endregion documentation-snippet

fs.writeFileSync(cli.flags.outPath, schema);
if (schema) {
fs.writeFileSync(cli.flags.outPath, new Uint8Array(schema.buffer));
}

console.log('Wrote schema to file: ', cli.flags.outPath);
})();
14 changes: 10 additions & 4 deletions examples/nodejs/client/getPoolInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
const blockHash = cli.flags.block === undefined ? undefined : BlockHash.fromHexString(cli.flags.block);
const bakerPool: BakerPoolStatus = await client.getPoolInfo(BigInt(cli.flags.poolOwner), blockHash);

console.log('Open status:', bakerPool.poolInfo.openStatus);
console.log('Open status:', bakerPool.poolInfo?.openStatus);
console.log('Baker address:', bakerPool.bakerAddress);
console.log('CCD provided by the baker to the pool:', CcdAmount.toCcd(bakerPool.bakerEquityCapital));
console.log('CCD provided by the delegators to the pool:', CcdAmount.toCcd(bakerPool.delegatedCapital));
console.log(
'CCD provided by the baker to the pool:',
bakerPool.bakerEquityCapital !== undefined ? CcdAmount.toCcd(bakerPool.bakerEquityCapital) : undefined
);
console.log(
'CCD provided by the delegators to the pool:',
bakerPool.delegatedCapital !== undefined ? CcdAmount.toCcd(bakerPool.delegatedCapital) : undefined
);
console.log('Total capital in CCD of ALL pools:', CcdAmount.toCcd(bakerPool.allPoolTotalCapital));
console.log('Pool commision rates:', bakerPool.poolInfo.commissionRates);
console.log('Pool commision rates:', bakerPool.poolInfo?.commissionRates);
// #endregion documentation-snippet
})();
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
const schema = await client.getEmbeddedSchema(moduleRef);
// #endregion documentation-snippet

fs.writeFileSync(cli.flags.outPath, schema);
if (schema) {
fs.writeFileSync(cli.flags.outPath, new Uint8Array(schema.buffer));
}

console.log('Wrote schema to file: ', cli.flags.outPath);
})();
6 changes: 3 additions & 3 deletions examples/nodejs/composed-examples/initAndUpdateContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
sender,
};

const initParams = serializeInitContractParameters(contractName, sunnyWeather, schema);
const initParams = serializeInitContractParameters(contractName, sunnyWeather, schema!.buffer);

const initPayload: InitContractPayload = {
amount: CcdAmount.zero(),
Expand Down Expand Up @@ -142,7 +142,7 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
contractName,
EntrypointName.fromString('set'),
rainyWeather,
schema
schema!.buffer
);

const updatePayload: UpdateContractPayload = {
Expand Down Expand Up @@ -187,7 +187,7 @@ const client = new ConcordiumGRPCNodeClient(address, Number(port), credentials.c
const rawReturnValue = unwrap(invokedPostInit.returnValue);
const returnValue = deserializeReceiveReturnValue(
ReturnValue.toBuffer(rawReturnValue),
schema,
schema!.buffer,
contractName,
EntrypointName.fromString('get')
);
Expand Down
2 changes: 1 addition & 1 deletion examples/reactnative/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -716,4 +716,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: c70448f9d8b13c40c47391af88ee9f69ffe85d63

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
6 changes: 5 additions & 1 deletion packages/ccd-js-gen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog - ccd-js-gen

## Unreleased
## 1.2.1

### Changed

- Update peer depedency for `@concordium/web-sdk` to support any version above `7`

## 1.2.0

Expand Down
4 changes: 2 additions & 2 deletions packages/ccd-js-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
},
"license": "Apache-2.0",
"peerDependencies": {
"@concordium/web-sdk": "7.x"
"@concordium/web-sdk": ">= 7"
},
"dependencies": {
"@concordium/web-sdk": "workspace:^7.0.0",
"@concordium/web-sdk": "workspace:^",
"buffer": "^6.0.3",
"commander": "^11.0.0",
"sanitize-filename": "^1.6.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/ccd-js-gen/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ async function generateCode(
}
notifier.done('Parse smart contract module.');

const moduleSchema = rawModuleSchema === null ? null : SDK.parseRawModuleSchema(rawModuleSchema);
const moduleSchema = rawModuleSchema && SDK.parseRawModuleSchema(rawModuleSchema);

const outputFilePath = path.format({
dir: outDirPath,
Expand Down
6 changes: 6 additions & 0 deletions packages/react-components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.1]

### Changed

- Update peer depedency for `@concordium/web-sdk` to support any version above `7`

## [0.6.0] - 2024-06-12

### Changed
Expand Down
4 changes: 2 additions & 2 deletions packages/react-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@concordium/react-components",
"version": "0.6.0",
"version": "0.6.1",
"description": "Utility library of React components for building dApps that interact with the Concordium blockchain.",
"author": "Concordium Software",
"license": "Apache-2.0",
Expand Down Expand Up @@ -42,7 +42,7 @@
"typescript": "^5.2.2"
},
"peerDependencies": {
"@concordium/web-sdk": "7.x",
"@concordium/web-sdk": ">= 7",
"react": "^18"
}
}
6 changes: 3 additions & 3 deletions packages/rust-bindings/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 8.0.1

### Breaking changes

- `getEmbeddedModuleSchema` now uses the module version to determine in which custom wasm sections to look for the schema.
- `ConcordiumGRPCClient.getEmbeddedSchema` now delegates to `getEmbeddedModuleSchema` instead of `wasmToSchema`
(which was removed as it was just a less capable version of `getEmbeddedModuleSchema`).
This means that it returns the complete `RawModuleSchema` instead of only the schema bytes.
It also means that it returns `null` instead of an error when no embedded schema was found.
- Update `AccountInfo` and `BakerPoolStatus` according to the changes introduced in the GRPC types introduced with node version 7

## 7.5.1

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@concordium/web-sdk",
"version": "7.5.1",
"version": "8.0.1",
"license": "Apache-2.0",
"engines": {
"node": ">=16"
Expand Down
9 changes: 5 additions & 4 deletions packages/sdk/src/GenericContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,11 @@ export class Contract<E extends string = string, V extends string = string> exte
if (!schema) {
try {
const raw = await grpcClient.getEmbeddedSchema(instanceInfo.sourceModule);
const encoded = Buffer.from(raw).toString('base64');

if (encoded) {
mSchema = encoded;
if (raw) {
const encoded = Buffer.from(raw.buffer).toString('base64');
if (encoded) {
mSchema = encoded;
}
}
} catch {
// Do nothing.
Expand Down
19 changes: 12 additions & 7 deletions packages/sdk/src/grpc/GRPCClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { calculateEnergyCost } from '../energyCost.js';
import { HealthClient } from '../grpc-api/v2/concordium/health.client.js';
import { QueriesClient } from '../grpc-api/v2/concordium/service.client.js';
import * as v2 from '../grpc-api/v2/concordium/types.js';
import { RawModuleSchema } from '../schemaTypes.js';
import { serializeAccountTransactionPayload } from '../serialization.js';
import * as v1 from '../types.js';
import { HexString, isRpcError } from '../types.js';
Expand All @@ -29,8 +30,9 @@ import * as SequenceNumber from '../types/SequenceNumber.js';
import * as Timestamp from '../types/Timestamp.js';
import * as TransactionExpiry from '../types/TransactionExpiry.js';
import * as TransactionHash from '../types/TransactionHash.js';
import { getEmbeddedModuleSchema } from '../types/VersionedModuleSource.js';
import type { BlockItemStatus, BlockItemSummary } from '../types/blockItemSummary.js';
import { countSignatures, isHex, isValidIp, mapRecord, mapStream, unwrap, wasmToSchema } from '../util.js';
import { countSignatures, isHex, isValidIp, mapRecord, mapStream, unwrap } from '../util.js';
import * as translate from './translation.js';

/**
Expand Down Expand Up @@ -199,13 +201,16 @@ export class ConcordiumGRPCClient {
* @param moduleRef the module's reference, represented by the ModuleReference class.
* @param blockHash optional block hash to get the module embedded schema at, otherwise retrieves from last finalized block
*
* @returns the module schema as a buffer.
* @throws An error of type `RpcError` if not found in the block.
* @throws If the module or schema cannot be parsed
* @returns the module schema as a {@link RawModuleSchema} or `null` if not found in the block.
* @throws An error of type `RpcError` if the module was not found in the block.
* @throws If the module source cannot be parsed or contains duplicate schema sections.
*/
async getEmbeddedSchema(moduleRef: ModuleReference.Type, blockHash?: BlockHash.Type): Promise<Uint8Array> {
const versionedSource = await this.getModuleSource(moduleRef, blockHash);
return wasmToSchema(versionedSource.source);
async getEmbeddedSchema(
moduleRef: ModuleReference.Type,
blockHash?: BlockHash.Type
): Promise<RawModuleSchema | undefined> {
const source = await this.getModuleSource(moduleRef, blockHash);
return getEmbeddedModuleSchema(source);
}

/**
Expand Down
Loading

0 comments on commit 48ecde2

Please sign in to comment.