@dc3-network/dc3js 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1 +1,19 @@
1
1
  # @dc3-network/dc3js
2
+
3
+ Javascript SDK for the DC3 blockchain
4
+
5
+ ## Package Structure
6
+
7
+ ```text
8
+ dc3js/ # main entry point
9
+ |- client/
10
+ |- config/ # import to customize chain configuration
11
+ |- query/ # import to access query message types and encoders
12
+ |- tx/ # import to access transaction message types and encoders
13
+ ```
14
+
15
+ ## License
16
+
17
+ MIT
18
+
19
+ See [LICENSE](LICENSE) file for details.
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ import {createCosmosQueryClient} from '@interchainjs/cosmos';
4
+ import {getSigner} from 'interchainjs';
5
+ import {valid as validWalletManager} from './walletManager.js';
6
+ import {isArray} from 'lodash';
7
+ import {default as tx} from '../tx/index.js';
8
+
9
+ export const signingClient = async (walletManager, encoders = []) => {
10
+ if (!validWalletManager(walletManager)) {
11
+ throw new Error('Invalid wallet manager');
12
+ }
13
+
14
+ if (!encoders || !isArray(encoders) || encoders.length === 0) {
15
+ encoders = tx.encoders;
16
+ }
17
+
18
+ const {currentChainName, currentWalletName} = walletManager;
19
+
20
+ if (!currentChainName || !currentWalletName) {
21
+ throw new Error('wallet is not connected to a chain');
22
+ }
23
+
24
+ try {
25
+ const chain = walletManager.getChainByName(currentChainName);
26
+ const rpcEndpoint = await walletManager.getRpcEndpoint(currentWalletName, currentChainName);
27
+ const preferredSignType = walletManager.getPreferSignType(currentChainName);
28
+ const offlineSigner = (await walletManager.getOfflineSigner(currentWalletName, currentChainName));
29
+ const defaultSignerOptions = await walletManager.getSignerOptions(currentChainName);
30
+
31
+ const signerOptions = {
32
+ queryClient: await createCosmosQueryClient(rpcEndpoint),
33
+ addressPrefix: chain.bech32Prefix,
34
+ chainId: chain.chainId,
35
+ ...defaultSignerOptions.cosmosSignerConfig,
36
+ };
37
+
38
+ // prefer the sign type from the chain provider if it's set
39
+ if (preferredSignType && typeof preferredSignType === 'string') {
40
+ const signer = getSigner(offlineSigner, {
41
+ preferredSignType: preferredSignType,
42
+ signerOptions,
43
+ });
44
+
45
+ signer.addEncoders(encoders);
46
+
47
+ return signer;
48
+ }
49
+
50
+ // default to legacy 'amino' signing type
51
+ const signer = getSigner(offlineSigner, {
52
+ preferredSignType: 'amino',
53
+ signerOptions,
54
+ })
55
+
56
+ signer.addEncoders(encoders);
57
+
58
+ return signer;
59
+ } catch (e) {
60
+ throw new Error('failed to create signing client: ' + e.message);
61
+ }
62
+ };
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ export * from './client.js';
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ import {isFunction, isString} from 'lodash';
4
+ import {isAsync} from '@smoxy-io/js-utils/lib';
5
+
6
+ const requiredProps = {
7
+ // methods
8
+ getChainByName: isFunction,
9
+ getRpcEndpoint: isAsync,
10
+ getPreferSignType: isFunction,
11
+ getOfflineSigner: isAsync,
12
+ getSignerOptions: isAsync,
13
+
14
+ // members
15
+ currentChainName: isString,
16
+ currentWalletName: isString
17
+ };
18
+
19
+ export const valid = (walletManager) => {
20
+ if (!walletManager) {
21
+ return false;
22
+ }
23
+
24
+ // check for required methods/members
25
+ for (const member in requiredProps) {
26
+ if (!walletManager[member] || !requiredProps[member](walletManager[member])) {
27
+ return false;
28
+ }
29
+ }
30
+
31
+ return true;
32
+ };
@@ -0,0 +1,95 @@
1
+ 'use strict';
2
+
3
+ import {isArray, isPlainObject, isString, merge} from 'lodash';
4
+ import {plain} from '@smoxy-io/js-utils/lib';
5
+ import {DenomUnit} from './denomUnit.js';
6
+
7
+ export const assets = [dc3];
8
+
9
+ export const dc3 = new Asset({
10
+ base: 'udc3',
11
+ denomUnits: [
12
+ {
13
+ denom: 'udc3',
14
+ exponent: 0
15
+ },
16
+ {
17
+ denom: 'dc3',
18
+ exponent: 6
19
+ }
20
+ ],
21
+ description: 'The native token of the DC3 chain',
22
+ display: 'dc3',
23
+ name: 'dc3',
24
+ symbol: 'DC3',
25
+ });
26
+
27
+ export const tdc3 = new Asset({
28
+ base: 'utdc3',
29
+ denomUnits: [
30
+ {
31
+ denom: 'utdc3',
32
+ exponent: 0
33
+ },
34
+ {
35
+ denom: 'tdc3',
36
+ exponent: 6
37
+ }
38
+ ],
39
+ description: 'The native token of the DC3 test chain',
40
+ display: 'tdc3',
41
+ name: 'tdc3',
42
+ symbol: 'tDC3',
43
+ });
44
+
45
+ const defaultOptions = {
46
+ base: '',
47
+ denomUnits: [],
48
+ description: '',
49
+ display: '',
50
+ name: '',
51
+ symbol: '',
52
+ typeAsset: 'sdk.coin'
53
+ };
54
+
55
+ export class Asset {
56
+ constructor(opts = {}) {
57
+ if (!isPlainObject(opts)) {
58
+ if (opts instanceof Asset) {
59
+ opts = plain(opts);
60
+ } else {
61
+ opts = {};
62
+ }
63
+ }
64
+
65
+ if (opts.denomUnits && isArray(opts.denomUnits) && opts.denomUnits.length !== 0) {
66
+ for (let i = 0; i < opts.denomUnits.length; i++) {
67
+ opts.denomUnits[i] = new DenomUnit(opts.denomUnits[i]);
68
+ }
69
+ }
70
+
71
+ merge(this, defaultOptions, opts);
72
+ }
73
+
74
+ hasDenom(denom) {
75
+ const index = this._getDenomIndex(denom);
76
+
77
+ return index !== -1;
78
+ }
79
+
80
+ getDenomUnit(denom) {
81
+ const index = this._getDenomIndex(denom);
82
+
83
+ return index !== -1 ? this.denomUnits[index] : null;
84
+ }
85
+
86
+ _getDenomIndex(denom) {
87
+ if (!denom || !isString(denom) || !this.denomUnits || !isArray(this.denomUnits) || this.denomUnits.length === 0) {
88
+ return -1;
89
+ }
90
+
91
+ return this.denomUnits.findIndex((d) => {
92
+ return d && d.denom === denom;
93
+ });
94
+ }
95
+ }
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+
3
+ import {isArray, isPlainObject, isString, merge} from 'lodash';
4
+ import {plain} from '@smoxy-io/js-utils/lib';
5
+ import {Asset, assets as defaultAssets} from './asset.js';
6
+
7
+ const defaultOptions = {
8
+ $schema: '../assetlist.schema.json',
9
+ chainName: 'dc3',
10
+ assets: []
11
+ };
12
+
13
+ export class AssetList {
14
+ constructor(opts = {}) {
15
+ if (!isPlainObject(opts)) {
16
+ if (opts instanceof AssetList) {
17
+ opts = plain(opts);
18
+ } else {
19
+ opts = {};
20
+ }
21
+ }
22
+
23
+ if (opts.assets && isArray(opts.assets) && opts.assets.length !== 0) {
24
+ for (let i = 0; i < opts.assets.length; i++) {
25
+ opts.assets[i] = new Asset(opts.assets[i]);
26
+ }
27
+ }
28
+
29
+ merge(this, defaultOptions, opts);
30
+ }
31
+
32
+ hasAsset(denom) {
33
+ const index = this._getAssetIndex(denom);
34
+
35
+ return index !== -1;
36
+ }
37
+
38
+ getAsset(denom) {
39
+ const index = this._getAssetIndex(denom);
40
+
41
+ return index !== -1 ? this.assets[index] : null;
42
+ }
43
+
44
+ _getAssetIndex(denom) {
45
+ if (!denom || !isString(denom) || !this.assets || !isArray(this.assets) || this.assets.length === 0) {
46
+ return -1;
47
+ }
48
+
49
+ return this.assets.findIndex((a) => {
50
+ return a && a instanceof Asset && a.hasDenom(denom);
51
+ });
52
+ }
53
+ }
54
+
55
+ export const newAssetList = (chainName = '', assets = []) => {
56
+ if (!isArray(assets)) {
57
+ assets = defaultAssets;
58
+ }
59
+
60
+ if (isArray(chainName)) {
61
+ // assets are passed in as the first argument instead of chainName
62
+ assets = chainName.slice();
63
+ }
64
+
65
+ if (!isString(chainName)) {
66
+ chainName = '';
67
+ }
68
+
69
+ const opts = {};
70
+
71
+ if (chainName) {
72
+ opts.chainName = chainName;
73
+ }
74
+
75
+ if (assets.length !== 0) {
76
+ opts.assets = assets;
77
+ }
78
+
79
+ return new AssetList(opts);
80
+ };
package/config/chain.js CHANGED
@@ -1,109 +1,188 @@
1
1
  'use strict';
2
2
 
3
3
  import {merge, isPlainObject} from 'lodash';
4
+ import {plain} from '@smoxy-io/js-utils/lib';
5
+ import {newAssetList} from './assetList.js';
6
+ import {dc3, tdc3} from './asset.js';
4
7
 
5
- const defaultEndpoints = Object.freeze({
6
- rpc: 'http://localhost:26657',
7
- rest: 'http://localhost:1317'
8
- });
9
-
10
- const localConfig = Object.freeze({
11
- chainId: 'local'
12
- });
13
-
14
- const devConfig = Object.freeze({
15
- chainId: 'devnet'
16
- });
17
-
18
- const testConfig = Object.freeze({
19
- chainId: 'testnet'
20
- });
21
-
22
- const prodConfig = Object.freeze({
23
- chainId: 'mainnet'
24
- });
25
-
26
- const baseConfig = Object.freeze({
27
- chainId: '',
28
- chainName: 'dc3',
29
- rpc: '',
30
- rest: '',
31
- bip44: Object.freeze({
32
- coinType: 118
33
- }),
34
- bech32Config: Object.freeze({
35
- bech32PrefixAccAddr: 'dc3',
36
- bech32PrefixAccPub: 'dc3pub',
37
- bech32PrefixValAddr: 'dc3valoper',
38
- bech32PrefixValPub: 'dc3valoperpub',
39
- bech32PrefixConsAddr: 'dc3valcons',
40
- bech32PrefixConsPub: 'dc3valconspub',
41
- }),
42
- currencies: Object.freeze([
43
- Object.freeze({
44
- coinDenom: 'DC3',
45
- coinMinimalDenom: 'udc3',
46
- coinDecimals: 6,
47
- coinGeckoId: "dc3-identity-token"
48
- })
49
- ]),
50
- feeCurrencies: Object.freeze([
51
- Object.freeze({
52
- coinDenom: 'DC3',
53
- coinMinimalDenom: 'udc3',
54
- coinDecimals: 6,
55
- coinGeckoId: "dc3-identity-token",
56
- gasPriceStep: {
57
- low: 0.001,
58
- average: 0.0015,
59
- high: 0.002
60
- }
61
- })
62
- ]),
63
- stakeCurrency: Object.freeze({
64
- coinDenom: 'DC3',
65
- coinMinimalDenom: 'udc3',
66
- coinDecimals: 6,
67
- coinGeckoId: "dc3-identity-token"
68
- }),
69
- features: Object.freeze([
70
- "ibc-go"
71
- ])
72
- });
8
+ const defaultOptions = {
9
+ $shema: '../chain.schema.json',
10
+ chainName: 'dc3',
11
+ chainId: 'dc3-1',
12
+ chainType: 'cosmos',
13
+ prettyName: 'dc3',
14
+ bech32Prefix: 'dc3',
15
+ bech32Config: {
16
+ bech32PrefixAccAddr: 'dc3',
17
+ bech32PrefixAccPub: 'dc3pub',
18
+ bech32PrefixValAddr: 'dc3valoper',
19
+ bech32PrefixValPub: 'dc3valoperpub',
20
+ bech32PrefixConsAddr: 'dc3valcons',
21
+ bech32PrefixConsPub: 'dc3valconspub',
22
+ },
23
+ networkType: 'mainnet',
24
+ slip44: 118,
25
+ codebase: {
26
+ cosmosSdkVersion: '0.53',
27
+ ibc: {
28
+ type: 'go'
29
+ }
30
+ },
31
+ apis: {
32
+ rpc: [{address: 'https://chain.dc3.network:26657'}],
33
+ rest: [{address: 'https://chain.dc3.network'}]
34
+ },
35
+ fees: {
36
+ feeTokens: [
37
+ {
38
+ denom: 'udc3',
39
+ fixedMinGasPrice: 1,
40
+ lowGasPrice: 1,
41
+ averageGasPrice: 1,
42
+ highGasPrice: 1
43
+ }
44
+ ]
45
+ },
46
+ keyAlgos: ['secp256k1'],
47
+ status: 'upcoming'
48
+ };
49
+
50
+ export class Chain {
51
+ constructor(opts = {}) {
52
+ if (!isPlainObject(opts)) {
53
+ if (opts instanceof Chain) {
54
+ opts = plain(opts);
55
+ } else {
56
+ opts = {};
57
+ }
58
+ }
59
+
60
+ merge(this, defaultOptions, opts);
61
+ }
62
+
63
+ isMainnet() {
64
+ return this.networkType === 'mainnet';
65
+ }
66
+
67
+ isTestnet() {
68
+ return this.networkType === 'testnet';
69
+ }
70
+
71
+ isDevnet() {
72
+ return this.networkType === 'devnet';
73
+ }
74
+
75
+ isLocalnet() {
76
+ return this.networkType === 'devnet' && this.prettyName === 'dc3-local';
77
+ }
78
+
79
+ assetLists() {
80
+ if (this.networkType === 'testnet') {
81
+ return [newAssetList(this.chainName, [tdc3])];
82
+ }
83
+
84
+ return [newAssetList(this.chainName)];
85
+ }
86
+
87
+ signerOptions() {
88
+ return {
89
+ preferredSignType: (chain) => {
90
+ switch (chain) {
91
+ case this.chainName:
92
+ return 'cosmos_direct';
93
+ }
94
+
95
+ return 'cosmos_amino';
96
+ },
97
+ signing: (chain) => {
98
+ switch (chain) {
99
+ case this.chainName:
100
+ return {
101
+ cosmosSignerConfig: {
102
+ gasPrice: '1udc3',
103
+ broadcast: {
104
+ checkTx: true,
105
+ deliverTx: true,
106
+ timeoutMs: 60000
107
+ }
108
+ }
109
+ };
110
+ }
111
+
112
+ return undefined;
113
+ }
114
+ };
115
+ }
116
+
117
+ endpointOptions() {
118
+ return {
119
+ endpoints: {
120
+ [this.chainName]: this.apis
121
+ }
122
+ };
123
+ }
124
+ }
73
125
 
74
126
  export const ChainTypeLocal = 'local';
75
127
  export const ChainTypeDev = 'dev';
76
128
  export const ChainTypeTest = 'test';
77
129
  export const ChainTypeProd = 'prod';
78
130
 
79
- export const getChainConfig = (type, endpoints = defaultEndpoints) => {
80
- let conf = null;
131
+ export const getChainConfig = (type, opts = {}) => {
132
+ let conf = {};
81
133
 
82
134
  switch (type) {
83
135
  case ChainTypeLocal:
84
- conf = localConfig;
136
+ conf.prettyName = 'dc3-local';
137
+ conf.networkType = 'devnet';
138
+ conf.apis = {
139
+ rpc: [{address: 'http://localhost:26657'}],
140
+ rest: [{address: 'http://localhost:1317'}]
141
+ };
142
+
85
143
  break;
144
+
86
145
  case ChainTypeDev:
87
- conf = devConfig;
146
+ conf.prettyName = 'dc3-dev';
147
+ conf.networkType = 'devnet';
148
+ conf.apis = {
149
+ rpc: [{address: 'https://dev.chain.dc3.network:26657'}],
150
+ rest: [{address: 'https://dev.chain.dc3.network:1317'}]
151
+ };
152
+
88
153
  break;
154
+
89
155
  case ChainTypeTest:
90
- conf = testConfig;
156
+ conf.prettyName = 'dc3-test';
157
+ conf.networkType = 'testnet';
158
+ conf.apis = {
159
+ rpc: [{address: 'https://test.chain.dc3.network:26657'}],
160
+ rest: [{address: 'https://test.chain.dc3.network:1317'}]
161
+ };
162
+
91
163
  break;
164
+
165
+ // production config is the default config
92
166
  case ChainTypeProd:
93
- conf = prodConfig;
94
- break;
95
167
  default:
96
- return null;
168
+ break;
97
169
  }
98
170
 
99
- if (!isPlainObject(endpoints)) {
100
- endpoints = {}
101
- }
171
+ return new Chain(merge({}, conf, opts));
172
+ };
173
+
174
+ export const getChain = (opts = {}) => {
175
+ return getChainConfig(ChainTypeProd, opts);
176
+ };
102
177
 
103
- const ep = merge({}, defaultEndpoints, endpoints);
178
+ export const getTestChain = (opts = {}) => {
179
+ return getChainConfig(ChainTypeTest, opts);
180
+ }
104
181
 
105
- conf.rpc = ep.rpc;
106
- conf.rest = ep.rest;
182
+ export const getChainDev = (opts = {}) => {
183
+ return getChainConfig(ChainTypeDev, opts);
184
+ }
107
185
 
108
- return merge({}, baseConfig, conf);
186
+ export const getChainLocal = (opts = {}) => {
187
+ return getChainConfig(ChainTypeLocal, opts);
109
188
  };
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ import {isPlainObject} from 'lodash';
4
+ import {plain} from '@smoxy-io/js-utils/lib';
5
+
6
+ const defaultOptions = {
7
+ denom: '',
8
+ exponent: 0
9
+ };
10
+
11
+ export class DenomUnit {
12
+ constructor(opts = {}) {
13
+ if (!isPlainObject(opts)) {
14
+ if (opts instanceof DenomUnit) {
15
+ opts = plain(opts);
16
+ } else {
17
+ opts = {};
18
+ }
19
+ }
20
+
21
+ Object.assign(this, defaultOptions, opts);
22
+ }
23
+ }
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ export * from './asset.js';
4
+ export * from './assetList.js';
5
+ export * from './chain.js';
6
+ export * from './denomUnit.js';
package/index.js CHANGED
@@ -1,5 +1,32 @@
1
1
  'use strict';
2
2
 
3
- import {getChainConfig} from './config/chain';
3
+ import * as config from './config/index.js';
4
+ import * as tx from './tx/index.js';
5
+ import * as query from './query/index.js';
4
6
 
5
- export const chainConfig = getChainConfig;
7
+ export {name, license, repository, version} from './package.json' with {type: 'json'};
8
+ export * from './client/index.js';
9
+
10
+ export const mainnet = config.getChain();
11
+ export const testnet = config.getTestChain();
12
+ export const devnet = config.getChainDev();
13
+
14
+ export const chains = [mainnet];
15
+ export const testChains = [testnet];
16
+ export const devChains = [devnet];
17
+
18
+ export const assetLists = mainnet.assetLists();
19
+ export const testAssetLists = testnet.assetLists();
20
+ export const devAssetLists = devnet.assetLists();
21
+
22
+ export const encoders = [
23
+ ...query.encoders,
24
+ ...tx.encoders
25
+ ];
26
+
27
+ export const versionedEncoders = {
28
+ v1: [
29
+ ...query.v1.encoders,
30
+ ...tx.v1.encoders
31
+ ]
32
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dc3-network/dc3js",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "DC3 blockchain sdk",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -20,8 +20,12 @@
20
20
  },
21
21
  "homepage": "https://github.com/dc3-network/dc3js#readme",
22
22
  "dependencies": {
23
+ "@dc3-network/x-job-types": "^0.1.0",
23
24
  "@dc3-network/x-node-types": "^0.2.0",
24
25
  "@dc3-network/x-org-types": "^0.1.0",
26
+ "@interchainjs/cosmos": "^1.19.3",
27
+ "@smoxy-io/js-utils": "^1.2.5",
28
+ "interchainjs": "^1.19.3",
25
29
  "lodash": "^4.17.23"
26
30
  },
27
31
  "publishConfig": {
@@ -29,7 +33,9 @@
29
33
  },
30
34
  "exports": {
31
35
  ".": "./index.js",
32
- "./tx": "./tx/index.js",
33
- "./config": "./config/chain.js"
36
+ "./client": "./client/index.js",
37
+ "./config": "./config/index.js",
38
+ "./query": "./query/index.js",
39
+ "./tx": "./tx/index.js"
34
40
  }
35
41
  }
package/query/index.js ADDED
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ import * as v1 from './v1/index.js';
4
+
5
+ // export default version
6
+ export * from './v1/index.js';
7
+
8
+ // export all versions
9
+ export {
10
+ v1
11
+ };
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ import {forEach} from 'lodash';
4
+
5
+ // import all dc3 chain messages
6
+ import * as nodeMsgPkg from '@dc3-network/x-node-types/v1/query';
7
+ import * as orgMsgPkg from '@dc3-network/x-org-types/v1/query';
8
+ import * as jobMsgPkg from '@dc3-network/x-job-types/v1/query';
9
+
10
+ // export all dc3 chain messages
11
+ export * from '@dc3-network/x-node-types/v1/query';
12
+ export * from '@dc3-network/x-org-types/v1/query';
13
+ export * from '@dc3-network/x-job-types/v1/query';
14
+
15
+ export const encoders = [];
16
+
17
+ const registerEncoders = (pkg) => {
18
+ if (!pkg || !pkg.protobufPackage) {
19
+ return;
20
+ }
21
+
22
+ const protoPkg = pkg.protobufPackage;
23
+
24
+ if (!protoPkg) {
25
+ return;
26
+ }
27
+
28
+ forEach(pkg, (v, k) => {
29
+ if (k.substring(-7) !== 'Request' && k.substring(-8) !== 'Response') {
30
+ return;
31
+ }
32
+
33
+ if (!v.typeUrl) {
34
+ v.typeUrl = '/' + protoPkg + '.' + k;
35
+ }
36
+
37
+ encoders.push(v);
38
+ });
39
+ };
40
+
41
+ forEach([nodeMsgPkg, orgMsgPkg, jobMsgPkg], registerEncoders);
package/tx/index.js CHANGED
@@ -1,3 +1,11 @@
1
1
  'use strict';
2
2
 
3
- export * from './v1';
3
+ import * as v1 from './v1/index.js';
4
+
5
+ // export default version
6
+ export * from './v1/index.js';
7
+
8
+ // export all versions
9
+ export {
10
+ v1
11
+ };
package/tx/v1/index.js CHANGED
@@ -5,10 +5,16 @@ import {forEach} from 'lodash';
5
5
  // import all dc3 chain messages
6
6
  import * as nodeMsgPkg from '@dc3-network/x-node-types/v1/tx';
7
7
  import * as orgMsgPkg from '@dc3-network/x-org-types/v1/tx';
8
+ import * as jobMsgPkg from '@dc3-network/x-job-types/v1/tx';
8
9
 
9
- const messages = [];
10
+ // export all dc3 chain messages
11
+ export * from '@dc3-network/x-node-types/v1/tx';
12
+ export * from '@dc3-network/x-org-types/v1/tx';
13
+ export * from '@dc3-network/x-job-types/v1/tx';
10
14
 
11
- const registerMessages = (pkg) => {
15
+ export const encoders = [];
16
+
17
+ const registerEncoders = (pkg) => {
12
18
  if (!pkg || !pkg.protobufPackage) {
13
19
  return;
14
20
  }
@@ -20,7 +26,7 @@ const registerMessages = (pkg) => {
20
26
  }
21
27
 
22
28
  forEach(pkg, (v, k) => {
23
- if (k.substring(0, 3) !== 'Msg' || k.substring(0, 10) === 'MsgService' || k.substring(0, 9) === 'MsgClient') {
29
+ if (k.substring(-7) !== 'Request' && k.substring(-8) !== 'Response') {
24
30
  return;
25
31
  }
26
32
 
@@ -28,12 +34,8 @@ const registerMessages = (pkg) => {
28
34
  v.typeUrl = '/' + protoPkg + '.' + k;
29
35
  }
30
36
 
31
- messages.push(v);
37
+ encoders.push(v);
32
38
  });
33
39
  };
34
40
 
35
- forEach([nodeMsgPkg, orgMsgPkg], registerMessages);
36
-
37
- export const getMessages = () => {
38
- return messages;
39
- };
41
+ forEach([nodeMsgPkg, orgMsgPkg, jobMsgPkg], registerEncoders);