@cityofzion/bs-neo3 1.16.3 → 1.16.4

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.
Files changed (43) hide show
  1. package/dist/BSNeo3.d.ts +39 -30
  2. package/dist/BSNeo3.js +102 -54
  3. package/dist/constants/BSNeo3Constants.d.ts +12 -17
  4. package/dist/constants/BSNeo3Constants.js +221 -37
  5. package/dist/helpers/BSNeo3Helper.d.ts +5 -6
  6. package/dist/helpers/BSNeo3Helper.js +9 -8
  7. package/dist/helpers/BSNeo3NeonDappKitSingletonHelper.d.ts +6 -0
  8. package/dist/helpers/BSNeo3NeonDappKitSingletonHelper.js +26 -0
  9. package/dist/helpers/BSNeo3NeonJsSingletonHelper.d.ts +7 -0
  10. package/dist/helpers/BSNeo3NeonJsSingletonHelper.js +26 -0
  11. package/dist/index.d.ts +3 -2
  12. package/dist/index.js +3 -2
  13. package/dist/services/blockchain-data/DoraBDSNeo3.d.ts +13 -12
  14. package/dist/services/blockchain-data/DoraBDSNeo3.js +130 -140
  15. package/dist/services/blockchain-data/RpcBDSNeo3.d.ts +13 -19
  16. package/dist/services/blockchain-data/RpcBDSNeo3.js +28 -62
  17. package/dist/services/chaim-data/RpcCDSNeo3.d.ts +7 -0
  18. package/dist/services/chaim-data/RpcCDSNeo3.js +27 -0
  19. package/dist/services/exchange-data/FlamingoForthewinEDSNeo3.d.ts +6 -7
  20. package/dist/services/exchange-data/FlamingoForthewinEDSNeo3.js +4 -19
  21. package/dist/services/explorer/DoraESNeo3.d.ts +5 -5
  22. package/dist/services/explorer/DoraESNeo3.js +19 -22
  23. package/dist/services/ledger/NeonDappKitLedgerServiceNeo3.d.ts +10 -10
  24. package/dist/services/ledger/NeonDappKitLedgerServiceNeo3.js +28 -38
  25. package/dist/services/neo3neoXBridge/Neo3NeoXBridgeService.d.ts +10 -9
  26. package/dist/services/neo3neoXBridge/Neo3NeoXBridgeService.js +26 -25
  27. package/dist/services/nft-data/GhostMarketNDSNeo3.d.ts +7 -11
  28. package/dist/services/nft-data/GhostMarketNDSNeo3.js +41 -79
  29. package/dist/services/vote/DoraVoteServiceNeo3.d.ts +8 -29
  30. package/dist/services/vote/DoraVoteServiceNeo3.js +81 -21
  31. package/dist/types.d.ts +84 -0
  32. package/dist/types.js +18 -0
  33. package/package.json +25 -25
  34. package/dist/assets/tokens/mainnet.json +0 -194
  35. package/dist/assets/tokens/native.json +0 -14
  36. package/dist/builder/invocation/NeonDappKitInvocationBuilderNeo3.d.ts +0 -34
  37. package/dist/builder/invocation/NeonDappKitInvocationBuilderNeo3.js +0 -102
  38. package/dist/interfaces.d.ts +0 -41
  39. package/dist/interfaces.js +0 -2
  40. package/dist/services/nft-data/RpcNDSNeo3.d.ts +0 -9
  41. package/dist/services/nft-data/RpcNDSNeo3.js +0 -59
  42. package/dist/services/vote/RpcVoteServiceNeo3.d.ts +0 -10
  43. package/dist/services/vote/RpcVoteServiceNeo3.js +0 -88
@@ -27,19 +27,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.Neo3NeoXBridgeService = void 0;
28
28
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
29
29
  const BSNeo3Constants_1 = require("../../constants/BSNeo3Constants");
30
- const neon_dappkit_1 = require("@cityofzion/neon-dappkit");
30
+ const axios_1 = __importDefault(require("axios"));
31
31
  const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
32
32
  const DoraBDSNeo3_1 = require("../blockchain-data/DoraBDSNeo3");
33
- const axios_1 = __importDefault(require("axios"));
33
+ const BSNeo3NeonDappKitSingletonHelper_1 = require("../../helpers/BSNeo3NeonDappKitSingletonHelper");
34
34
  class Neo3NeoXBridgeService {
35
35
  constructor(service) {
36
- this.BRIDGE_SCRIPT_HASH = '0xbb19cfc864b73159277e1fd39694b3fd5fc613d2';
37
36
  _Neo3NeoXBridgeService_service.set(this, void 0);
38
37
  __classPrivateFieldSet(this, _Neo3NeoXBridgeService_service, service, "f");
39
- this.tokens = [
40
- Object.assign(Object.assign({}, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN), { multichainId: 'gas', blockchain: service.name }),
41
- Object.assign(Object.assign({}, BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN), { multichainId: 'neo', blockchain: service.name }),
42
- ];
38
+ this.gasToken = Object.assign(Object.assign({}, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN), { blockchain: service.name, multichainId: 'gas' });
39
+ this.neoToken = Object.assign(Object.assign({}, BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN), { blockchain: service.name, multichainId: 'neo' });
43
40
  }
44
41
  getApprovalFee() {
45
42
  return __awaiter(this, void 0, void 0, function* () {
@@ -48,33 +45,34 @@ class Neo3NeoXBridgeService {
48
45
  }
49
46
  getBridgeConstants(token) {
50
47
  return __awaiter(this, void 0, void 0, function* () {
51
- const invoker = yield neon_dappkit_1.NeonInvoker.init({
48
+ const { TypeChecker, NeonInvoker } = BSNeo3NeonDappKitSingletonHelper_1.BSNeo3NeonDappKitSingletonHelper.getInstance();
49
+ const invoker = yield NeonInvoker.init({
52
50
  rpcAddress: __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.url,
53
51
  });
54
52
  const isNativeToken = __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").tokenService.predicateByHash(token, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN);
55
53
  let invocations;
56
54
  if (isNativeToken) {
57
55
  invocations = [
58
- { operation: 'nativeDepositFee', scriptHash: this.BRIDGE_SCRIPT_HASH, args: [] },
59
- { operation: 'minNativeDeposit', scriptHash: this.BRIDGE_SCRIPT_HASH, args: [] },
60
- { operation: 'maxNativeDeposit', scriptHash: this.BRIDGE_SCRIPT_HASH, args: [] },
56
+ { operation: 'nativeDepositFee', scriptHash: Neo3NeoXBridgeService.BRIDGE_SCRIPT_HASH, args: [] },
57
+ { operation: 'minNativeDeposit', scriptHash: Neo3NeoXBridgeService.BRIDGE_SCRIPT_HASH, args: [] },
58
+ { operation: 'maxNativeDeposit', scriptHash: Neo3NeoXBridgeService.BRIDGE_SCRIPT_HASH, args: [] },
61
59
  ];
62
60
  }
63
61
  else {
64
62
  invocations = [
65
63
  {
66
64
  operation: 'tokenDepositFee',
67
- scriptHash: this.BRIDGE_SCRIPT_HASH,
65
+ scriptHash: Neo3NeoXBridgeService.BRIDGE_SCRIPT_HASH,
68
66
  args: [{ type: 'Hash160', value: token.hash }],
69
67
  },
70
68
  {
71
69
  operation: 'minTokenDeposit',
72
- scriptHash: this.BRIDGE_SCRIPT_HASH,
70
+ scriptHash: Neo3NeoXBridgeService.BRIDGE_SCRIPT_HASH,
73
71
  args: [{ type: 'Hash160', value: token.hash }],
74
72
  },
75
73
  {
76
74
  operation: 'maxTokenDeposit',
77
- scriptHash: this.BRIDGE_SCRIPT_HASH,
75
+ scriptHash: Neo3NeoXBridgeService.BRIDGE_SCRIPT_HASH,
78
76
  args: [{ type: 'Hash160', value: token.hash }],
79
77
  },
80
78
  ];
@@ -83,9 +81,9 @@ class Neo3NeoXBridgeService {
83
81
  invocations,
84
82
  });
85
83
  const [depositFeeItem, minDepositItem, maxDepositItem] = response.stack;
86
- if (!neon_dappkit_1.TypeChecker.isStackTypeInteger(depositFeeItem) ||
87
- !neon_dappkit_1.TypeChecker.isStackTypeInteger(minDepositItem) ||
88
- !neon_dappkit_1.TypeChecker.isStackTypeInteger(maxDepositItem))
84
+ if (!TypeChecker.isStackTypeInteger(depositFeeItem) ||
85
+ !TypeChecker.isStackTypeInteger(minDepositItem) ||
86
+ !TypeChecker.isStackTypeInteger(maxDepositItem))
89
87
  throw new blockchain_service_1.BSError('Invalid response', 'INVALID_RESPONSE');
90
88
  const bridgeFeeBn = blockchain_service_1.BSBigNumberHelper.fromDecimals(depositFeeItem.value, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.decimals).toString();
91
89
  const minAmountBn = blockchain_service_1.BSBigNumberHelper.fromDecimals(minDepositItem.value, token.decimals).toString();
@@ -101,19 +99,20 @@ class Neo3NeoXBridgeService {
101
99
  });
102
100
  }
103
101
  bridge(params) {
104
- var _a, _b;
105
102
  return __awaiter(this, void 0, void 0, function* () {
106
- if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network))
103
+ var _a, _b;
104
+ if (!BSNeo3Helper_1.BSNeo3Helper.isMainnetNetwork(__classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network))
107
105
  throw new blockchain_service_1.BSError('Bridging to NeoX is only supported on mainnet', 'UNSUPPORTED_NETWORK');
108
106
  const { account } = params;
109
107
  const { neonJsAccount, signingCallback } = yield __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").generateSigningCallback(account);
110
- const invoker = yield neon_dappkit_1.NeonInvoker.init({
108
+ const { NeonInvoker } = BSNeo3NeonDappKitSingletonHelper_1.BSNeo3NeonDappKitSingletonHelper.getInstance();
109
+ const invoker = yield NeonInvoker.init({
111
110
  rpcAddress: __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.url,
112
111
  account: neonJsAccount,
113
112
  signingCallback: signingCallback,
114
113
  });
115
114
  const contractInvocation = {
116
- scriptHash: this.BRIDGE_SCRIPT_HASH,
115
+ scriptHash: Neo3NeoXBridgeService.BRIDGE_SCRIPT_HASH,
117
116
  operation: 'depositNative',
118
117
  args: [
119
118
  { type: 'Hash160', value: neonJsAccount.address },
@@ -130,7 +129,7 @@ class Neo3NeoXBridgeService {
130
129
  };
131
130
  const signer = {
132
131
  scopes: 16,
133
- allowedContracts: [this.BRIDGE_SCRIPT_HASH, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.hash],
132
+ allowedContracts: [Neo3NeoXBridgeService.BRIDGE_SCRIPT_HASH, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN.hash],
134
133
  };
135
134
  const isNativeToken = __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").tokenService.predicateByHash(params.token, BSNeo3Constants_1.BSNeo3Constants.GAS_TOKEN);
136
135
  if (!isNativeToken) {
@@ -144,11 +143,12 @@ class Neo3NeoXBridgeService {
144
143
  });
145
144
  }
146
145
  getNonce(params) {
147
- var _a, _b;
148
146
  return __awaiter(this, void 0, void 0, function* () {
147
+ var _a, _b;
149
148
  let log;
150
149
  try {
151
- log = yield DoraBDSNeo3_1.DoraNeoRest.log(params.transactionHash, __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.id);
150
+ const api = DoraBDSNeo3_1.DoraBDSNeo3.getClient();
151
+ log = yield api.log(params.transactionHash, __classPrivateFieldGet(this, _Neo3NeoXBridgeService_service, "f").network.id);
152
152
  }
153
153
  catch (error) {
154
154
  throw new blockchain_service_1.BSError('Failed to get nonce from transaction log', 'FAILED_TO_GET_NONCE', error);
@@ -181,7 +181,7 @@ class Neo3NeoXBridgeService {
181
181
  jsonrpc: '2.0',
182
182
  method: 'GetBridgeTxByNonce',
183
183
  params: {
184
- ContractHash: this.BRIDGE_SCRIPT_HASH,
184
+ ContractHash: Neo3NeoXBridgeService.BRIDGE_SCRIPT_HASH,
185
185
  TokenHash: isNativeToken ? '' : BSNeo3Constants_1.BSNeo3Constants.NEO_TOKEN.hash,
186
186
  Nonce: Number(params.nonce),
187
187
  },
@@ -207,3 +207,4 @@ class Neo3NeoXBridgeService {
207
207
  }
208
208
  exports.Neo3NeoXBridgeService = Neo3NeoXBridgeService;
209
209
  _Neo3NeoXBridgeService_service = new WeakMap();
210
+ Neo3NeoXBridgeService.BRIDGE_SCRIPT_HASH = '0xbb19cfc864b73159277e1fd39694b3fd5fc613d2';
@@ -1,13 +1,9 @@
1
- import { GetNftParam, GetNftsByAddressParams, Network, NftResponse, NftsResponse } from '@cityofzion/blockchain-service';
2
- import { BSNeo3NetworkId } from '../../constants/BSNeo3Constants';
3
- import { RpcNDSNeo3 } from './RpcNDSNeo3';
4
- export declare class GhostMarketNDSNeo3 extends RpcNDSNeo3 {
1
+ import { GhostMarketNDS, THasTokenParam } from '@cityofzion/blockchain-service';
2
+ import { IBSNeo3, TBSNeo3NetworkId } from '../../types';
3
+ export declare class GhostMarketNDSNeo3<N extends string> extends GhostMarketNDS {
5
4
  #private;
6
- static CONFIG_BY_NETWORK_ID: Partial<Record<BSNeo3NetworkId, {
7
- url: string;
8
- chain: string;
9
- }>>;
10
- constructor(network: Network<BSNeo3NetworkId>);
11
- getNftsByAddress({ address, size, cursor }: GetNftsByAddressParams): Promise<NftsResponse>;
12
- getNft({ collectionHash, tokenHash }: GetNftParam): Promise<NftResponse>;
5
+ static readonly CHAIN_BY_NETWORK_ID: Record<TBSNeo3NetworkId, string>;
6
+ constructor(service: IBSNeo3<N>);
7
+ hasToken({ collectionHash, address }: THasTokenParam): Promise<boolean>;
8
+ getChain(): string;
13
9
  }
@@ -19,91 +19,53 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
19
19
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
20
20
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
21
  };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- var _GhostMarketNDSNeo3_instances, _GhostMarketNDSNeo3_network, _GhostMarketNDSNeo3_treatGhostMarketImage, _GhostMarketNDSNeo3_getUrlWithParams, _GhostMarketNDSNeo3_parse;
22
+ var _GhostMarketNDSNeo3_service;
26
23
  Object.defineProperty(exports, "__esModule", { value: true });
27
24
  exports.GhostMarketNDSNeo3 = void 0;
28
- const axios_1 = __importDefault(require("axios"));
29
- const query_string_1 = __importDefault(require("query-string"));
30
- const RpcNDSNeo3_1 = require("./RpcNDSNeo3");
31
- class GhostMarketNDSNeo3 extends RpcNDSNeo3_1.RpcNDSNeo3 {
32
- constructor(network) {
33
- super(network);
34
- _GhostMarketNDSNeo3_instances.add(this);
35
- _GhostMarketNDSNeo3_network.set(this, void 0);
36
- __classPrivateFieldSet(this, _GhostMarketNDSNeo3_network, network, "f");
25
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
26
+ const BSNeo3NeonDappKitSingletonHelper_1 = require("../../helpers/BSNeo3NeonDappKitSingletonHelper");
27
+ class GhostMarketNDSNeo3 extends blockchain_service_1.GhostMarketNDS {
28
+ constructor(service) {
29
+ super();
30
+ _GhostMarketNDSNeo3_service.set(this, void 0);
31
+ __classPrivateFieldSet(this, _GhostMarketNDSNeo3_service, service, "f");
37
32
  }
38
- getNftsByAddress({ address, size = 18, cursor }) {
39
- var _a;
40
- return __awaiter(this, void 0, void 0, function* () {
41
- const url = __classPrivateFieldGet(this, _GhostMarketNDSNeo3_instances, "m", _GhostMarketNDSNeo3_getUrlWithParams).call(this, {
42
- size,
43
- owners: [address],
44
- cursor: cursor,
45
- });
46
- const { data } = yield axios_1.default.get(url);
47
- const nfts = (_a = data.assets) !== null && _a !== void 0 ? _a : [];
48
- return { nextCursor: data.next, items: nfts.map(__classPrivateFieldGet(this, _GhostMarketNDSNeo3_instances, "m", _GhostMarketNDSNeo3_parse).bind(this)) };
33
+ hasToken(_a) {
34
+ return __awaiter(this, arguments, void 0, function* ({ collectionHash, address }) {
35
+ const { NeonParser, NeonInvoker } = BSNeo3NeonDappKitSingletonHelper_1.BSNeo3NeonDappKitSingletonHelper.getInstance();
36
+ const invoker = yield NeonInvoker.init({ rpcAddress: __classPrivateFieldGet(this, _GhostMarketNDSNeo3_service, "f").network.url });
37
+ try {
38
+ const result = yield invoker.testInvoke({
39
+ invocations: [
40
+ {
41
+ scriptHash: collectionHash,
42
+ operation: 'balanceOf',
43
+ args: [
44
+ {
45
+ type: 'Hash160',
46
+ value: address,
47
+ },
48
+ ],
49
+ },
50
+ ],
51
+ });
52
+ return NeonParser.parseRpcResponse(result.stack[0], { type: 'Integer' }) > 0;
53
+ }
54
+ catch (_b) {
55
+ throw new Error(`Token not found: ${collectionHash}`);
56
+ }
49
57
  });
50
58
  }
51
- getNft({ collectionHash, tokenHash }) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const url = __classPrivateFieldGet(this, _GhostMarketNDSNeo3_instances, "m", _GhostMarketNDSNeo3_getUrlWithParams).call(this, {
54
- contract: collectionHash,
55
- tokenIds: [tokenHash],
56
- });
57
- const { data } = yield axios_1.default.get(url);
58
- return __classPrivateFieldGet(this, _GhostMarketNDSNeo3_instances, "m", _GhostMarketNDSNeo3_parse).call(this, data.assets[0]);
59
- });
59
+ getChain() {
60
+ const chain = GhostMarketNDSNeo3.CHAIN_BY_NETWORK_ID[__classPrivateFieldGet(this, _GhostMarketNDSNeo3_service, "f").network.id];
61
+ if (!chain)
62
+ throw new Error('Network not supported');
63
+ return chain;
60
64
  }
61
65
  }
62
66
  exports.GhostMarketNDSNeo3 = GhostMarketNDSNeo3;
63
- _GhostMarketNDSNeo3_network = new WeakMap(), _GhostMarketNDSNeo3_instances = new WeakSet(), _GhostMarketNDSNeo3_treatGhostMarketImage = function _GhostMarketNDSNeo3_treatGhostMarketImage(srcImage) {
64
- if (!srcImage) {
65
- return;
66
- }
67
- if (srcImage.startsWith('ipfs://')) {
68
- const splitImage = srcImage.split('/');
69
- const imageId = splitImage.slice(-2).filter(Boolean).join('/');
70
- return `https://ghostmarket.mypinata.cloud/ipfs/${imageId}`;
71
- }
72
- return srcImage;
73
- }, _GhostMarketNDSNeo3_getUrlWithParams = function _GhostMarketNDSNeo3_getUrlWithParams(params) {
74
- const config = GhostMarketNDSNeo3.CONFIG_BY_NETWORK_ID[__classPrivateFieldGet(this, _GhostMarketNDSNeo3_network, "f").id];
75
- const chain = config === null || config === void 0 ? void 0 : config.chain;
76
- if (!chain)
77
- throw new Error('GhostMarketNDSNeo3 does not support this network');
78
- const parameters = query_string_1.default.stringify(Object.assign({ chain, ownersChains: [chain] }, params), { arrayFormat: 'bracket' });
79
- return `${config.url}/assets?${parameters}`;
80
- }, _GhostMarketNDSNeo3_parse = function _GhostMarketNDSNeo3_parse(data) {
81
- var _a, _b;
82
- const nftResponse = {
83
- hash: data.tokenId,
84
- collection: {
85
- hash: data.contract.hash,
86
- name: (_a = data.collection) === null || _a === void 0 ? void 0 : _a.name,
87
- image: __classPrivateFieldGet(this, _GhostMarketNDSNeo3_instances, "m", _GhostMarketNDSNeo3_treatGhostMarketImage).call(this, (_b = data.collection) === null || _b === void 0 ? void 0 : _b.logoUrl),
88
- },
89
- symbol: data.contract.symbol,
90
- image: __classPrivateFieldGet(this, _GhostMarketNDSNeo3_instances, "m", _GhostMarketNDSNeo3_treatGhostMarketImage).call(this, data.metadata.mediaUri),
91
- isSVG: String(data.metadata.mediaType).includes('svg+xml'),
92
- name: data.metadata.name,
93
- creator: {
94
- address: data.creator.address,
95
- name: data.creator.offchainName,
96
- },
97
- };
98
- return nftResponse;
99
- };
100
- GhostMarketNDSNeo3.CONFIG_BY_NETWORK_ID = {
101
- mainnet: {
102
- url: 'https://api.ghostmarket.io/api/v2',
103
- chain: 'n3',
104
- },
105
- testnet: {
106
- url: 'https://api.ghostmarket.io/api/v2',
107
- chain: 'n3t',
108
- },
67
+ _GhostMarketNDSNeo3_service = new WeakMap();
68
+ GhostMarketNDSNeo3.CHAIN_BY_NETWORK_ID = {
69
+ mainnet: 'n3',
70
+ testnet: 'n3t',
109
71
  };
@@ -1,31 +1,10 @@
1
- import { RpcVoteServiceNeo3 } from './RpcVoteServiceNeo3';
2
- import { GetCandidatesToVoteResponse, GetVoteDetailsByAddressResponse } from '../../interfaces';
3
- import { BSNeo3 } from '../../BSNeo3';
4
- type AxiosCandidate = {
5
- scripthash: string;
6
- name: string;
7
- description: string;
8
- location: string;
9
- website: string;
10
- email: string;
11
- github: string;
12
- telegram: string;
13
- twitter: string;
14
- logo: string;
15
- votes: number;
16
- pubkey: string;
17
- };
18
- export type AxiosGetCandidatesToVoteResponse = AxiosCandidate[];
19
- export type AxiosGetVoteDetailsByAddressResponse = {
20
- vote: string;
21
- candidate: string;
22
- candidatePubkey: string;
23
- balance: number;
24
- };
25
- export declare class DoraVoteServiceNeo3<BSName extends string> extends RpcVoteServiceNeo3<BSName> {
1
+ import { IBSNeo3, IVoteService, TVoteServiceCandidate, TVoteServiceDetailsByAddressResponse, TVoteServiceVoteParams } from '../../types';
2
+ export declare class DoraVoteServiceNeo3<N extends string> implements IVoteService<N> {
26
3
  #private;
27
- constructor(service: BSNeo3<BSName>);
28
- getCandidatesToVote(): Promise<GetCandidatesToVoteResponse>;
29
- getVoteDetailsByAddress(address: string): Promise<GetVoteDetailsByAddressResponse>;
4
+ readonly _service: IBSNeo3<N>;
5
+ constructor(service: IBSNeo3<N>);
6
+ getCandidatesToVote(): Promise<TVoteServiceCandidate[]>;
7
+ getVoteDetailsByAddress(address: string): Promise<TVoteServiceDetailsByAddressResponse>;
8
+ vote({ account, candidatePubKey }: TVoteServiceVoteParams<N>): Promise<string>;
9
+ calculateVoteFee({ account, candidatePubKey }: TVoteServiceVoteParams<N>): Promise<string>;
30
10
  }
31
- export {};
@@ -8,17 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
11
16
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
17
  if (kind === "m") throw new TypeError("Private method is not writable");
13
18
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
19
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
20
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
21
  };
17
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
18
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
19
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
20
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
- };
22
22
  var __rest = (this && this.__rest) || function (s, e) {
23
23
  var t = {};
24
24
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -33,26 +33,25 @@ var __rest = (this && this.__rest) || function (s, e) {
33
33
  var __importDefault = (this && this.__importDefault) || function (mod) {
34
34
  return (mod && mod.__esModule) ? mod : { "default": mod };
35
35
  };
36
- var _DoraVoteServiceNeo3_service, _DoraVoteServiceNeo3_doraAxiosInstance;
36
+ var _DoraVoteServiceNeo3_instances, _DoraVoteServiceNeo3_apiInstance, _DoraVoteServiceNeo3_api_get, _DoraVoteServiceNeo3_getVoteCIM;
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.DoraVoteServiceNeo3 = void 0;
39
- const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
40
39
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
41
40
  const axios_1 = __importDefault(require("axios"));
42
- const RpcVoteServiceNeo3_1 = require("./RpcVoteServiceNeo3");
43
- class DoraVoteServiceNeo3 extends RpcVoteServiceNeo3_1.RpcVoteServiceNeo3 {
41
+ const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
42
+ const BSNeo3NeonJsSingletonHelper_1 = require("../../helpers/BSNeo3NeonJsSingletonHelper");
43
+ const BSNeo3NeonDappKitSingletonHelper_1 = require("../../helpers/BSNeo3NeonDappKitSingletonHelper");
44
+ class DoraVoteServiceNeo3 {
44
45
  constructor(service) {
45
- super(service);
46
- _DoraVoteServiceNeo3_service.set(this, void 0);
47
- _DoraVoteServiceNeo3_doraAxiosInstance.set(this, void 0);
48
- __classPrivateFieldSet(this, _DoraVoteServiceNeo3_service, service, "f");
49
- __classPrivateFieldSet(this, _DoraVoteServiceNeo3_doraAxiosInstance, axios_1.default.create({ baseURL: `${blockchain_service_1.BSCommonConstants.DORA_URL}/api/v2/neo3` }), "f");
46
+ _DoraVoteServiceNeo3_instances.add(this);
47
+ _DoraVoteServiceNeo3_apiInstance.set(this, void 0);
48
+ this._service = service;
50
49
  }
51
50
  getCandidatesToVote() {
52
51
  return __awaiter(this, void 0, void 0, function* () {
53
- if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _DoraVoteServiceNeo3_service, "f").network))
52
+ if (!BSNeo3Helper_1.BSNeo3Helper.isMainnetNetwork(this._service.network))
54
53
  throw new Error('Only Mainnet is supported');
55
- const { data } = yield __classPrivateFieldGet(this, _DoraVoteServiceNeo3_doraAxiosInstance, "f").get('/mainnet/committee');
54
+ const { data } = yield __classPrivateFieldGet(this, _DoraVoteServiceNeo3_instances, "a", _DoraVoteServiceNeo3_api_get).get('/mainnet/committee');
56
55
  return data.map((_a, index) => {
57
56
  var { logo } = _a, candidate = __rest(_a, ["logo"]);
58
57
  const position = index + 1;
@@ -73,15 +72,15 @@ class DoraVoteServiceNeo3 extends RpcVoteServiceNeo3_1.RpcVoteServiceNeo3 {
73
72
  });
74
73
  }
75
74
  getVoteDetailsByAddress(address) {
76
- var _a, _b;
77
75
  return __awaiter(this, void 0, void 0, function* () {
78
- if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _DoraVoteServiceNeo3_service, "f").network))
76
+ var _a, _b;
77
+ if (!BSNeo3Helper_1.BSNeo3Helper.isMainnetNetwork(this._service.network))
79
78
  throw new Error('Only Mainnet is supported');
80
79
  if (!address)
81
80
  throw new Error('Missing address');
82
- if (!__classPrivateFieldGet(this, _DoraVoteServiceNeo3_service, "f").validateAddress(address))
81
+ if (!this._service.validateAddress(address))
83
82
  throw new Error('Invalid address');
84
- const { data } = yield __classPrivateFieldGet(this, _DoraVoteServiceNeo3_doraAxiosInstance, "f").get(`/mainnet/voter/${address}`);
83
+ const { data } = yield __classPrivateFieldGet(this, _DoraVoteServiceNeo3_instances, "a", _DoraVoteServiceNeo3_api_get).get(`/mainnet/voter/${address}`);
85
84
  return {
86
85
  candidateName: (_a = data.candidate) !== null && _a !== void 0 ? _a : undefined,
87
86
  candidatePubKey: (_b = data.candidatePubkey) !== null && _b !== void 0 ? _b : undefined,
@@ -90,6 +89,67 @@ class DoraVoteServiceNeo3 extends RpcVoteServiceNeo3_1.RpcVoteServiceNeo3 {
90
89
  };
91
90
  });
92
91
  }
92
+ vote(_a) {
93
+ return __awaiter(this, arguments, void 0, function* ({ account, candidatePubKey }) {
94
+ if (!BSNeo3Helper_1.BSNeo3Helper.isMainnetNetwork(this._service.network))
95
+ throw new Error('Only Mainnet is supported');
96
+ if (!candidatePubKey)
97
+ throw new Error('Missing candidatePubKey param');
98
+ const { neonJsAccount, signingCallback } = yield this._service.generateSigningCallback(account);
99
+ const { NeonInvoker } = BSNeo3NeonDappKitSingletonHelper_1.BSNeo3NeonDappKitSingletonHelper.getInstance();
100
+ const invoker = yield NeonInvoker.init({
101
+ rpcAddress: this._service.network.url,
102
+ account: neonJsAccount,
103
+ signingCallback,
104
+ });
105
+ const cim = __classPrivateFieldGet(this, _DoraVoteServiceNeo3_instances, "m", _DoraVoteServiceNeo3_getVoteCIM).call(this, {
106
+ address: account.address,
107
+ candidatePubKey,
108
+ });
109
+ const transactionHash = yield invoker.invokeFunction(cim);
110
+ return transactionHash;
111
+ });
112
+ }
113
+ calculateVoteFee(_a) {
114
+ return __awaiter(this, arguments, void 0, function* ({ account, candidatePubKey }) {
115
+ if (!BSNeo3Helper_1.BSNeo3Helper.isMainnetNetwork(this._service.network))
116
+ throw new Error('Only Mainnet is supported');
117
+ if (!candidatePubKey)
118
+ throw new Error('Missing candidatePubKey param');
119
+ const { neonJsAccount } = yield this._service.generateSigningCallback(account);
120
+ const { NeonInvoker } = BSNeo3NeonDappKitSingletonHelper_1.BSNeo3NeonDappKitSingletonHelper.getInstance();
121
+ const invoker = yield NeonInvoker.init({
122
+ rpcAddress: this._service.network.url,
123
+ account: neonJsAccount,
124
+ });
125
+ const cim = __classPrivateFieldGet(this, _DoraVoteServiceNeo3_instances, "m", _DoraVoteServiceNeo3_getVoteCIM).call(this, {
126
+ address: account.address,
127
+ candidatePubKey,
128
+ });
129
+ const { total } = yield invoker.calculateFee(cim);
130
+ return blockchain_service_1.BSBigNumberHelper.format(total, { decimals: this._service.feeToken.decimals });
131
+ });
132
+ }
93
133
  }
94
134
  exports.DoraVoteServiceNeo3 = DoraVoteServiceNeo3;
95
- _DoraVoteServiceNeo3_service = new WeakMap(), _DoraVoteServiceNeo3_doraAxiosInstance = new WeakMap();
135
+ _DoraVoteServiceNeo3_apiInstance = new WeakMap(), _DoraVoteServiceNeo3_instances = new WeakSet(), _DoraVoteServiceNeo3_api_get = function _DoraVoteServiceNeo3_api_get() {
136
+ if (!__classPrivateFieldGet(this, _DoraVoteServiceNeo3_apiInstance, "f")) {
137
+ __classPrivateFieldSet(this, _DoraVoteServiceNeo3_apiInstance, axios_1.default.create({ baseURL: `${blockchain_service_1.BSCommonConstants.DORA_URL}/api/v2/neo3` }), "f");
138
+ }
139
+ return __classPrivateFieldGet(this, _DoraVoteServiceNeo3_apiInstance, "f");
140
+ }, _DoraVoteServiceNeo3_getVoteCIM = function _DoraVoteServiceNeo3_getVoteCIM({ address, candidatePubKey }) {
141
+ const { tx } = BSNeo3NeonJsSingletonHelper_1.BSNeo3NeonJsSingletonHelper.getInstance();
142
+ return {
143
+ invocations: [
144
+ {
145
+ scriptHash: 'ef4073a0f2b305a38ec4050e4d3d28bc40ea63f5',
146
+ operation: 'vote',
147
+ args: [
148
+ { type: 'Hash160', value: address },
149
+ { type: 'PublicKey', value: candidatePubKey },
150
+ ],
151
+ },
152
+ ],
153
+ signers: [{ scopes: tx.WitnessScope.CalledByEntry }],
154
+ };
155
+ };
@@ -0,0 +1,84 @@
1
+ import { TBSAccount, IBlockchainService, IBSWithClaim, IBSWithEncryption, IBSWithExplorer, IBSWithFee, IBSWithLedger, IBSWithNameService, IBSWithNeo3NeoXBridge, IBSWithNft, TBSNetworkId } from '@cityofzion/blockchain-service';
2
+ import { wallet, api } from './helpers/BSNeo3NeonJsSingletonHelper';
3
+ export type TBSNeo3NetworkId = TBSNetworkId<'mainnet' | 'testnet'>;
4
+ export interface IBSNeo3<N extends string = string> extends IBlockchainService<N, TBSNeo3NetworkId>, IBSWithClaim<N>, IBSWithNameService, IBSWithFee<N>, IBSWithNft, IBSWithExplorer, IBSWithLedger<N>, IBSWithNeo3NeoXBridge<N>, IBSWithEncryption<N> {
5
+ generateSigningCallback(account: TBSAccount<N>): Promise<{
6
+ neonJsAccount: wallet.Account;
7
+ signingCallback: api.SigningFunction;
8
+ }>;
9
+ }
10
+ export type TVoteServiceCandidate = {
11
+ position: number;
12
+ name: string;
13
+ description: string;
14
+ location: string;
15
+ email: string;
16
+ website: string;
17
+ hash: string;
18
+ pubKey: string;
19
+ votes: number;
20
+ logoUrl?: string;
21
+ type: 'consensus' | 'council';
22
+ };
23
+ export type TVoteServiceDetailsByAddressResponse = {
24
+ candidateName?: string;
25
+ candidatePubKey?: string;
26
+ neoBalance: number;
27
+ address: string;
28
+ };
29
+ export type TVoteServiceVoteParams<BSName extends string> = {
30
+ account: TBSAccount<BSName>;
31
+ candidatePubKey: string;
32
+ };
33
+ export type TDoraVoteServiceNeo3GetVoteCIMParams = {
34
+ address: string;
35
+ candidatePubKey: string;
36
+ };
37
+ export type TDoraVoteServiceNeo3GetCommitteeApiResponse = {
38
+ scripthash: string;
39
+ name: string;
40
+ description: string;
41
+ location: string;
42
+ website: string;
43
+ email: string;
44
+ github: string;
45
+ telegram: string;
46
+ twitter: string;
47
+ logo: string;
48
+ votes: number;
49
+ pubkey: string;
50
+ };
51
+ export type TDoraVoteServiceNeo3GetVoteDetailsByAddressApiResponse = {
52
+ vote: string;
53
+ candidate: string;
54
+ candidatePubkey: string;
55
+ balance: number;
56
+ };
57
+ export interface IVoteService<BSName extends string> {
58
+ getCandidatesToVote(): Promise<TVoteServiceCandidate[]>;
59
+ getVoteDetailsByAddress(address: string): Promise<TVoteServiceDetailsByAddressResponse>;
60
+ vote(params: TVoteServiceVoteParams<BSName>): Promise<string>;
61
+ calculateVoteFee(params: TVoteServiceVoteParams<BSName>): Promise<string>;
62
+ }
63
+ export type TRpcVoteServiceNeo3GetVoteCIMParams = {
64
+ address: string;
65
+ candidatePubKey: string;
66
+ };
67
+ export type TNeo3NeoXBridgeServiceGetBridgeTxByNonceApiResponse = {
68
+ result: {
69
+ Vmstate: string;
70
+ txid: string;
71
+ };
72
+ };
73
+ export declare enum ENeonDappKitLedgerServiceNeo3Status {
74
+ OK = 36864
75
+ }
76
+ export declare enum ENeonDappKitLedgerServiceNeo3Command {
77
+ GET_APP_NAME = 0,
78
+ GET_PUBLIC_KEY = 4,
79
+ SIGN = 2
80
+ }
81
+ export declare enum ENeonDappKitLedgerServiceNeo3SecondParameter {
82
+ MORE_DATA = 128,
83
+ LAST_DATA = 0
84
+ }
package/dist/types.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENeonDappKitLedgerServiceNeo3SecondParameter = exports.ENeonDappKitLedgerServiceNeo3Command = exports.ENeonDappKitLedgerServiceNeo3Status = void 0;
4
+ var ENeonDappKitLedgerServiceNeo3Status;
5
+ (function (ENeonDappKitLedgerServiceNeo3Status) {
6
+ ENeonDappKitLedgerServiceNeo3Status[ENeonDappKitLedgerServiceNeo3Status["OK"] = 36864] = "OK";
7
+ })(ENeonDappKitLedgerServiceNeo3Status || (exports.ENeonDappKitLedgerServiceNeo3Status = ENeonDappKitLedgerServiceNeo3Status = {}));
8
+ var ENeonDappKitLedgerServiceNeo3Command;
9
+ (function (ENeonDappKitLedgerServiceNeo3Command) {
10
+ ENeonDappKitLedgerServiceNeo3Command[ENeonDappKitLedgerServiceNeo3Command["GET_APP_NAME"] = 0] = "GET_APP_NAME";
11
+ ENeonDappKitLedgerServiceNeo3Command[ENeonDappKitLedgerServiceNeo3Command["GET_PUBLIC_KEY"] = 4] = "GET_PUBLIC_KEY";
12
+ ENeonDappKitLedgerServiceNeo3Command[ENeonDappKitLedgerServiceNeo3Command["SIGN"] = 2] = "SIGN";
13
+ })(ENeonDappKitLedgerServiceNeo3Command || (exports.ENeonDappKitLedgerServiceNeo3Command = ENeonDappKitLedgerServiceNeo3Command = {}));
14
+ var ENeonDappKitLedgerServiceNeo3SecondParameter;
15
+ (function (ENeonDappKitLedgerServiceNeo3SecondParameter) {
16
+ ENeonDappKitLedgerServiceNeo3SecondParameter[ENeonDappKitLedgerServiceNeo3SecondParameter["MORE_DATA"] = 128] = "MORE_DATA";
17
+ ENeonDappKitLedgerServiceNeo3SecondParameter[ENeonDappKitLedgerServiceNeo3SecondParameter["LAST_DATA"] = 0] = "LAST_DATA";
18
+ })(ENeonDappKitLedgerServiceNeo3SecondParameter || (exports.ENeonDappKitLedgerServiceNeo3SecondParameter = ENeonDappKitLedgerServiceNeo3SecondParameter = {}));