Skip to content

Commit

Permalink
chore: update management canister interface with latest bitcoin featu…
Browse files Browse the repository at this point in the history
…res (#890)

* chore: update management canister interface with latest bitcoin features

* updating actor and management_service

* feat: automation to update the management canister IDL

* cleaning up ts errors
  • Loading branch information
krpeacock authored Jun 5, 2024
1 parent 602b70a commit fa0404b
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 243 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ commands to keep in mind;

The following scripts can be found in [./bin](./bin):

- update-management-idl - Update the management canister IDL in @dfinity/agent

Monorepo-related scripts run in this order, but are usually invoked by `npm install`:

- npm-postinstall - Run with `npm run postinstall` in this monorepo package.
Expand Down
49 changes: 49 additions & 0 deletions bin/update-management-idl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { $, cd, fetch } from 'zx';
import path from 'path';

fetch(
'https://raw.githubusercontent.com/dfinity/interface-spec/master/spec/_attachments/ic.did',
).then(async res => {
res.text().then(async text => {
const root = path.resolve(__dirname, '..');

const candid = text;

await cd(`${root}/packages/agent/src/canisters`);

await $`echo ${candid} > management.did`;
let ts = (await $`didc bind management.did -t ts`).toString();
let js = (await $`didc bind management.did -t js`).toString();

const didcVersion = await $`didc --version`;

const prefix = `/*
* This file is generated from the candid for asset management.
* didc version: ${didcVersion.toString().split(' ')[1].trim()}
*/
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
`;

// replace first line of service

ts = ts.replace(`export interface _SERVICE {`, `export default interface _SERVICE {`);
js = js.replace(`export const idlFactory = ({ IDL }) => {`, `export default ({ IDL }) => {`);

// remove init function
js = js.split('export const init = ({ IDL }) => {')[0];

ts = prefix + ts;
js = prefix + js;

await $`echo ${js} > management_idl.ts`;
await $`echo ${ts} > management_service.ts`;

await cd(`${root}`);

await $`npm run prettier:format`;

console.log('Done!');
});
});
2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
### Added

- feat!: add support for proof of absence in Certificate lookups
- feat: `update-management-idl` automation to update the management canister IDL in `@dfinity/agent`

### Changed

- chore: update management canister interface with latest bitcoin features
- fix: publish script will correctly update the `package-lock.json` file with the correct dependencies when making a new release
- chore: updates agent error response to read "Gateway returns error" instead of "Server"`
- chore: updates dfinity/conventional-pr-title-action to v4.0.0
Expand Down
24 changes: 21 additions & 3 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"typescript": "^5.2.2",
"url": "^0.11.3",
"webcrypto-core": "^1.7.7",
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"zx": "^8.1.2"
},
"engines": {
"node": "^12 || ^14 || ^16 || >=17",
Expand All @@ -68,7 +69,8 @@
"prepare": "husky install",
"prettier:check": "npx -p prettier -p pretty-quick pretty-quick --check",
"prettier:format": "npx -p prettier -p pretty-quick pretty-quick",
"postversion": "npm run prettier:format"
"postversion": "npm run prettier:format",
"update-management-idl": "ts-node bin/update-management-idl.ts"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions packages/agent/src/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { RequestId } from './request_id';
import { toHex } from './utils/buffer';
import { CreateCertificateOptions } from './certificate';
import managementCanisterIdl from './canisters/management_idl';
import _SERVICE, { canister_settings } from './canisters/management_service';
import _SERVICE, { canister_install_mode, canister_settings } from './canisters/management_service';

export class ActorCallError extends AgentError {
constructor(
Expand Down Expand Up @@ -243,7 +243,7 @@ export class Actor {
public static async install(
fields: {
module: ArrayBuffer;
mode?: CanisterInstallMode;
mode?: canister_install_mode;
arg?: ArrayBuffer;
},
config: ActorConfig,
Expand Down
Loading

0 comments on commit fa0404b

Please sign in to comment.