@1coinnetwork/node-types 中文文档教程

发布于 3年前 浏览 26 项目主页 更新于 3年前

coinnet-node-types

Usage

这个 repo 包含自定义 coinnet-node 模块的 Typescript 绑定。

为了针对 1COIN Network 使用标准 API,您必须按如下方式初始化 API 的选项对象:

import { spec } from '@1coinnetwork/node-types';

const options: ApiOptions = {
  provider : new WsProvider('ws://localhost:9944'),
  ...spec,
};

const api = new ApiPromise(options);

您还需要更新项目的 tsconfig.json 以包含以下内容:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@polkadot/api/augment": ["./node_modules/@1coinnetwork/node-types/interfaces/augment-api.d.ts"],
      "@polkadot/types/augment": ["./node_modules/@1coinnetwork/node-types/interfaces/augment-types.d.ts"],
    }
  }
}

Dependencies

您项目的 @polkadot- js 依赖版本必须匹配本项目中使用的版本,包括@polkadot/api@polkadot/keyring,以及所有相关的包,作为以及 rxjs(如果使用 ApiRx 而不是 ApiPromise)和 typescript。 要验证所需的版本,请检查 @polkadot package.json 文件以了解此项目的 package.json 中指定的版本。

Building

这个项目依赖于 @polkadot/typegen 项目,它有一个构建此项目的分步指南。

1COIN 特定版本如下:

  1. 确保 package.json @polkadot/api 设置为正确的版本,并且 < code>@polkadot/typegen 设置为与 @polkadot/api 相同的版本。 如果需要发布,请增加 @1coinnetwork/node-types 版本。

  2. 如果任何 1coin 网络模块发生变化,请确保 src/interfaces 中的所有 definitions.ts 文件都更新为每种类型的最新版本。

  3. 在本地主机上运行 coinnet-node 链。

  4. 您会注意到 lint 命令的输出包含一个错误。 这是因为 typegen 脚本不能很好地处理相互依赖的自定义模块的相对路径。 您必须手动更改 signaling/types.ts 如下:

   - import { VoteStage } from './voting';
   + import { VoteStage } from '../voting';
  1. 升级所有 spec文件 根据 @polkadot-js 更新日志 和链的底层 Substrate 版本。

  2. 要将 Typescript 编译为 Javascript 以用于 npm 发布,请运行 yarn build。 此命令不应产生任何错误,并将构建文件输出到 dist 目录。

  3. 使用 yarn verify [mainnet | 对实时 coinnet 节点运行新构建的 API 的简单测试 测试网]。

  4. 使用 npm publish 发布新版本。

coinnet-node-types

Usage

This repo contains Typescript bindings for custom coinnet-node modules.

In order to use the standard API against 1COIN Network you must initialize the API's options object as follows:

import { spec } from '@1coinnetwork/node-types';

const options: ApiOptions = {
  provider : new WsProvider('ws://localhost:9944'),
  ...spec,
};

const api = new ApiPromise(options);

You will also need to update the tsconfig.json of your project to include the following:

{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@polkadot/api/augment": ["./node_modules/@1coinnetwork/node-types/interfaces/augment-api.d.ts"],
      "@polkadot/types/augment": ["./node_modules/@1coinnetwork/node-types/interfaces/augment-types.d.ts"],
    }
  }
}

Dependencies

Your project's @polkadot-js dependency versions must match the versions used in this project, including @polkadot/api, @polkadot/keyring, and all associated packages, as well as rxjs (if using ApiRx instead of ApiPromise) and typescript. To verify the versions required, inspect the @polkadot package.json files for the version specified in this project's package.json.

Building

This project depends on the @polkadot/typegen project, which has a step-by-step guide to building this project.

The 1COIN-specific version is as follows:

  1. Ensure in package.json that @polkadot/api is set to the correct version, and that @polkadot/typegen is set to the same version as @polkadot/api. Increase the @1coinnetwork/node-types version if necessary for publication.

  2. Ensure that all the definitions.ts files in src/interfaces are updated to the latest versions of each type, if any 1coin network modules changed.

  3. Run an coinnet-node chain on localhost.

  4. You will notice that the output of the lint command contains an error. This is because the typegen script does not handle relative paths well for custom modules that depend on each other. You will have to make a manual change to signaling/types.ts as follows:

   - import { VoteStage } from './voting';
   + import { VoteStage } from '../voting';
  1. Upgrade all spec files with any changes necessary as per the @polkadot-js changelog and the underlying Substrate version of the chain.

  2. To compile the Typescript to Javascript for npm publication, run yarn build. This command should not produce any errors and will output build files to the dist directory.

  3. Run a simple test of the newly-built API against a live coinnet node with yarn verify [mainnet | testnet].

  4. Publish the new version with npm publish.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文