Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more wrappers in API #270

Merged
merged 28 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0579c5c
Fix minor issues related to generating clients
limemloh Sep 18, 2023
efbae3c
Convert nodejs package to ESM
soerenbf Sep 19, 2023
fe1ef97
ESM file endings common
soerenbf Sep 19, 2023
336c042
All in on ESM
soerenbf Sep 20, 2023
b19ff78
Update docs
soerenbf Sep 20, 2023
967c6bb
Update changelogs
soerenbf Sep 20, 2023
f2f4173
Align web package with the rest
soerenbf Sep 20, 2023
0cebf76
Fix tests
soerenbf Sep 20, 2023
e7f4e3e
Add CI pipeline cache buster
soerenbf Sep 20, 2023
4693fb6
Fix ccd-js-gen example wCCD/client-metadata
limemloh Sep 20, 2023
6bbf9d6
Use schema for parameter when generating clients
limemloh Sep 15, 2023
3595549
Use new types in examples
limemloh Sep 18, 2023
c2e4989
ccd-js-gen: Generate type for parameter when init
limemloh Sep 18, 2023
4710a6e
Update changelog
limemloh Sep 22, 2023
bcb6457
Use schema for parameter when generating clients
limemloh Sep 15, 2023
c9f6bb9
Change api to use stricter types
limemloh Sep 20, 2023
b3887e3
Remove buffer from parts of the api and use newtypes
limemloh Sep 21, 2023
db3e0bb
Fix ccd-js-gen for U64 and I64
limemloh Sep 22, 2023
b528f5a
Merge remote-tracking branch 'origin/release/10' into ccd-js-gen-use-…
limemloh Sep 25, 2023
e1fc3ee
Remove dependency on Buffer being used externally (#273)
soerenbf Sep 26, 2023
4a9e2ab
Remove buffer dependency
soerenbf Sep 26, 2023
0e927b2
Fix buffer deprecation warning
soerenbf Sep 26, 2023
8545066
Merge branch 'ccd-js-gen-use-schema' into api-strict-types
limemloh Sep 26, 2023
90b3ff7
Fix unit tests
limemloh Sep 27, 2023
f939478
Update changelogs
limemloh Sep 28, 2023
a1edc78
Fix examples
limemloh Sep 28, 2023
428e1e1
Revert schema additions in generate client
limemloh Sep 28, 2023
d4c05d3
Remove the need for custom expectToEqual
limemloh Oct 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ name: Build, lint and typecheck examples
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main, release** ]
branches: [main, release**]
pull_request:
branches: [ main, release** ]
branches: [main, release**]
# Don't run on draft PR's, see: https://github.com/orgs/community/discussions/25722#discussioncomment-3248917
types: [ opened, synchronize, reopened, ready_for_review ]
types: [opened, synchronize, reopened, ready_for_review]
# Allows us to run the workflow manually from the Actions tab
workflow_dispatch:


env:
DUMMY: 1 # For cache busting.
NODE_VERSION: 18.16.0
Expand Down
48 changes: 48 additions & 0 deletions docs/pages/misc-pages/upgrade-guide.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
## Common SDK version 10 (Web 7) (Node 10)

### Common

Several types have been replaced with a module containing the type itself together with functions for constructing and
converting the type:

- `AccountAddress` is now a module with functions related to account addresses:
- To refer to `AccountAddress` as a type use `AccountAddress.Type`.
- Constructing `new AccountAddress("<address>")` is now `AccountAddress.fromBase58("<address>")`.
- `isAlias` and `getAlias` are now accessable from `AccountAddress.isAlias` and `AccountAddress.getAlias`.
- `ContractAddresss` is now a module with functions related to contract addresses:
- To refer to `ContractAddress` as a type use `ContractAddress.Type`.
- To construct the type use `ContractAddress.create(index, subindex)`.
- `CredentialRegistrationId` is now a module with functions related to credential registration IDs:
- To refer to `CredentialRegistrationId` as a type use `CredentialRegistrationId.Type`.
- Constructing `new CredentialRegistrationId("<hex-string>")` is now
`CredentialRegistrationId.fromHexString("<hex-string>")`.
- `Duration` is now a module with functions related to durations of time.
- To refer to `Duration` as a type use `Duration.Type`.
- `Timestamp` is now a module with functions related to timestamps.
- To refer to `Timestamp` as a type use `Timestamp.Type`.

The API now uses dedicated types instead of language primitives:

- Uses `AccountAddress` instead of a string with base58 encoding.
Can be constructed using `AccountAddress.fromBase58('<base58>')`.
- Uses `BlockHash` instead of a string with hex encoding.
Can be constructed using `BlockHash.fromHexString('<hex>')`.
- Uses `TranactionHash` instead of a string with hex encoding.
Can be constructed using `TransactionHash.fromHexString('<hex>')`.
- Uses `Energy` instead of a bigint.
Can be constructed using `Energy.create(<integer>)`.
- Uses `ReceiveName` instead of a string.
Can be constructed using `ReceiveName.fromString('<contract>.<function>')`.
- Uses `InitName` instead of a string.
Can be constructed using `Init.fromString('init_<contract>')`.
- Uses `ContractName` instead of a string.
Can be constructed using `ContractName.fromString('<contract>')`.
- Uses `EntrypointName` instead of a string.
Can be constructed using `EntrypointName.fromString('<function>')`.
- Uses `Parameter` instead of a string with hex encoding.
Can be constructed using `Parameter.fromHexString('<hex>')`.
- Uses `SequenceNumber` (formerly called nonce) instead of a bigint.
Can be constructed using `SequenceNumber.create(<integer>)`.
- Uses `Timestamp` instead of a bigint.
Can be constructed using `Timestamp.fromMillis(<integer>)`.
- Uses `Duration` instead of a bigint.
Can be constructed using `Duration.fromMillis(<integer>)`.

### Web

The `@concordium/web-sdk` now requires bundlers to respect `exports` field of
Expand Down
15 changes: 8 additions & 7 deletions examples/ccd-js-gen/wCCD/client-tokenMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { parseEndpoint } from '../../shared/util.js';
// The generated module could be imported directly like below,
// but for this example it is imported dynamicly to improve
// the error message when not generated.
// import * as wCCDModule from './lib/wCCD';
// import * as wCCDContractClient from './lib/cis2_wCCD';

const cli = meow(
`
Expand Down Expand Up @@ -51,10 +51,10 @@ const grpcClient = SDK.createConcordiumClient(
scheme === 'https' ? credentials.createSsl() : credentials.createInsecure()
);

const contractAddress: SDK.ContractAddress = {
index: BigInt(cli.flags.index),
subindex: BigInt(cli.flags.subindex),
};
const contractAddress = SDK.ContractAddress.create(
cli.flags.index,
cli.flags.subindex
);

(async () => {
// Importing the generated smart contract module client.
Expand All @@ -69,15 +69,16 @@ const contractAddress: SDK.ContractAddress = {
throw e;
});

const parameter = SDK.Parameter.fromHexString('010000'); // First 2 bytes for number of tokens to query, 1 byte for the token ID.
const wCCDTokenId = '';
const parameter = [wCCDTokenId];
limemloh marked this conversation as resolved.
Show resolved Hide resolved
const contract = await wCCDContractClient.create(
grpcClient,
contractAddress
);

const result = await wCCDContractClient.dryRunTokenMetadata(
contract,
new SDK.AccountAddress(
SDK.AccountAddress.fromBase58(
'357EYHqrmMiJBmUZTVG5FuaMq4soAhgtgz6XNEAJaXHW3NHaUf'
),
parameter
Expand Down
14 changes: 9 additions & 5 deletions examples/cis2/balanceOf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { createConcordiumClient, CIS2Contract } from '@concordium/node-sdk';
import {
createConcordiumClient,
CIS2Contract,
ContractAddress,
} from '@concordium/node-sdk';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
import { parseAddress, parseEndpoint } from '../shared/util.js';
Expand Down Expand Up @@ -57,10 +61,10 @@ const client = createConcordiumClient(
);

(async () => {
const contract = await CIS2Contract.create(client, {
index: BigInt(cli.flags.index),
subindex: BigInt(cli.flags.subindex),
});
const contract = await CIS2Contract.create(
client,
ContractAddress.create(cli.flags.index, cli.flags.subindex)
);

const accountBalance = await contract.balanceOf({
address: parseAddress(cli.flags.address),
Expand Down
28 changes: 16 additions & 12 deletions examples/cis2/dryRun.transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import {
createConcordiumClient,
CIS2,
CIS2Contract,
ContractAddress,
AccountAddress,
EntrypointName,
} from '@concordium/node-sdk';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
Expand Down Expand Up @@ -74,21 +77,22 @@ const client = createConcordiumClient(
);

(async () => {
const contract = await CIS2Contract.create(client, {
index: BigInt(cli.flags.index),
subindex: BigInt(cli.flags.subindex),
});
const contract = await CIS2Contract.create(
client,
ContractAddress.create(cli.flags.index, cli.flags.subindex)
);

const tokenId = cli.flags.tokenId;
const from = cli.flags.from;
const from = AccountAddress.fromBase58(cli.flags.from);
const toAddress = parseAddress(cli.flags.to);
const to: CIS2.Receiver =
typeof toAddress === 'string'
? toAddress
: {
address: toAddress,
hookName: cli.flags.receiveHookName ?? '',
};
const to: CIS2.Receiver = AccountAddress.isAccountAddress(toAddress)
? toAddress
: {
address: toAddress,
hookName: EntrypointName.fromString(
cli.flags.receiveHookName ?? ''
),
};

const result = await contract.dryRun.transfer(from, {
from,
Expand Down
14 changes: 9 additions & 5 deletions examples/cis2/dryRun.updateOperator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { createConcordiumClient, CIS2Contract } from '@concordium/node-sdk';
import {
createConcordiumClient,
CIS2Contract,
ContractAddress,
} from '@concordium/node-sdk';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
import { parseAddress, parseEndpoint } from '../shared/util.js';
Expand Down Expand Up @@ -57,10 +61,10 @@ const client = createConcordiumClient(
);

(async () => {
const contract = await CIS2Contract.create(client, {
index: BigInt(cli.flags.index),
subindex: BigInt(cli.flags.subindex),
});
const contract = await CIS2Contract.create(
client,
ContractAddress.create(cli.flags.index, cli.flags.subindex)
);

const owner = parseAddress(cli.flags.owner);
const address = parseAddress(cli.flags.address);
Expand Down
14 changes: 9 additions & 5 deletions examples/cis2/operatorOf.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { createConcordiumClient, CIS2Contract } from '@concordium/node-sdk';
import {
createConcordiumClient,
CIS2Contract,
ContractAddress,
} from '@concordium/node-sdk';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
import { parseAddress, parseEndpoint } from '../shared/util.js';
Expand Down Expand Up @@ -57,10 +61,10 @@ const client = createConcordiumClient(
);

(async () => {
const contract = await CIS2Contract.create(client, {
index: BigInt(cli.flags.index),
subindex: BigInt(cli.flags.subindex),
});
const contract = await CIS2Contract.create(
client,
ContractAddress.create(cli.flags.index, cli.flags.subindex)
);

const owner = parseAddress(cli.flags.owner);
const address = parseAddress(cli.flags.address);
Expand Down
14 changes: 9 additions & 5 deletions examples/cis2/tokenMetadata.ts
soerenbf marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { createConcordiumClient, CIS2Contract } from '@concordium/node-sdk';
import {
createConcordiumClient,
CIS2Contract,
ContractAddress,
} from '@concordium/node-sdk';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';

Expand Down Expand Up @@ -54,10 +58,10 @@ if (cli.flags.h) {
}

(async () => {
const contract = await CIS2Contract.create(client, {
index: BigInt(cli.flags.index),
subindex: BigInt(cli.flags.subindex),
});
const contract = await CIS2Contract.create(
client,
ContractAddress.create(cli.flags.index, cli.flags.subindex)
);

const url = await contract.tokenMetadata(cli.flags.tokenId);
console.log('url object:', url);
Expand Down
31 changes: 18 additions & 13 deletions examples/cis2/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import {
CIS2,
CIS2Contract,
buildBasicAccountSigner,
ContractAddress,
AccountAddress,
EntrypointName,
Energy,
} from '@concordium/node-sdk';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
Expand Down Expand Up @@ -81,27 +85,28 @@ const client = createConcordiumClient(
);

(async () => {
const contract = await CIS2Contract.create(client, {
index: BigInt(cli.flags.index),
subindex: BigInt(cli.flags.subindex),
});
const contract = await CIS2Contract.create(
client,
ContractAddress.create(cli.flags.index, cli.flags.subindex)
);

const signer = buildBasicAccountSigner(cli.flags.privateKey);
const tokenId = cli.flags.tokenId;
const from = cli.flags.from;
const from = AccountAddress.fromBase58(cli.flags.from);
const toAddress = parseAddress(cli.flags.to);
const to: CIS2.Receiver =
typeof toAddress === 'string'
? toAddress
: {
address: toAddress,
hookName: cli.flags.receiveHookName ?? '',
};
const to: CIS2.Receiver = AccountAddress.isAccountAddress(toAddress)
? toAddress
: {
address: toAddress,
hookName: EntrypointName.fromString(
cli.flags.receiveHookName ?? ''
),
};

const txHash = await contract.transfer(
{
senderAddress: from,
energy: 10000n,
energy: Energy.create(10000),
},
{
from,
Expand Down
15 changes: 9 additions & 6 deletions examples/cis2/updateOperator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import {
createConcordiumClient,
CIS2Contract,
buildBasicAccountSigner,
ContractAddress,
AccountAddress,
Energy,
} from '@concordium/node-sdk';
import { credentials } from '@grpc/grpc-js';
import meow from 'meow';
Expand Down Expand Up @@ -71,19 +74,19 @@ const client = createConcordiumClient(
);

(async () => {
const contract = await CIS2Contract.create(client, {
index: BigInt(cli.flags.index),
subindex: BigInt(cli.flags.subindex),
});
const contract = await CIS2Contract.create(
client,
ContractAddress.create(cli.flags.index, cli.flags.subindex)
);

const signer = buildBasicAccountSigner(cli.flags.privateKey);
const owner = cli.flags.owner;
const owner = AccountAddress.fromBase58(cli.flags.owner);
const address = parseAddress(cli.flags.address);

const txHash = await contract.updateOperator(
{
senderAddress: owner,
energy: 10000n,
energy: Energy.create(10000),
},
{
type: cli.flags.updateType as 'add' | 'remove',
Expand Down
14 changes: 9 additions & 5 deletions examples/cis4/credentialEntry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import meow from 'meow';
import { credentials } from '@grpc/grpc-js';

import { CIS4Contract, createConcordiumClient } from '@concordium/node-sdk';
import {
CIS4Contract,
ContractAddress,
createConcordiumClient,
} from '@concordium/node-sdk';
import { parseEndpoint } from '../shared/util.js';

const cli = meow(
Expand Down Expand Up @@ -52,10 +56,10 @@ const client = createConcordiumClient(
);

(async () => {
const contract = await CIS4Contract.create(client, {
index: BigInt(cli.flags.index),
subindex: BigInt(cli.flags.subindex),
});
const contract = await CIS4Contract.create(
client,
ContractAddress.create(cli.flags.index, cli.flags.subindex)
);

const credentialEntry = await contract.credentialEntry(cli.flags.credId);
console.log('Credential entry:', credentialEntry);
Expand Down
Loading