@cityofzion/bs-neo3 1.13.2 → 1.14.1

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/dist/BSNeo3.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSCalculableFee, BSClaimable, BSWithExplorerService, BSWithLedger, BSWithNameService, BSWithNft, ExchangeDataService, ExplorerService, GetLedgerTransport, Network, NftDataService, Token, TransferParam } from '@cityofzion/blockchain-service';
2
- import Neon from '@cityofzion/neon-core';
3
- import { api } from '@cityofzion/neon-js';
4
2
  import { NeonDappKitLedgerServiceNeo3 } from './services/ledger/NeonDappKitLedgerServiceNeo3';
5
3
  import { BSNeo3NetworkId } from './constants/BSNeo3Constants';
4
+ import { GenerateSigningCallbackResponse, VoteService } from './interfaces';
6
5
  export declare class BSNeo3<BSName extends string = string> implements BlockchainService<BSName, BSNeo3NetworkId>, BSClaimable<BSName>, BSWithNameService, BSCalculableFee<BSName>, BSWithNft, BSWithExplorerService, BSWithLedger<BSName> {
7
6
  #private;
8
7
  name: BSName;
@@ -17,12 +16,10 @@ export declare class BSNeo3<BSName extends string = string> implements Blockchai
17
16
  ledgerService: NeonDappKitLedgerServiceNeo3<BSName>;
18
17
  exchangeDataService: ExchangeDataService;
19
18
  explorerService: ExplorerService;
19
+ voteService: VoteService<BSName>;
20
20
  network: Network<BSNeo3NetworkId>;
21
21
  constructor(name: BSName, network?: Network<BSNeo3NetworkId>, getLedgerTransport?: GetLedgerTransport<BSName>);
22
- generateSigningCallback(account: Account<BSName>): Promise<{
23
- neonJsAccount: Neon.wallet.Account;
24
- signingCallback: api.SigningFunction;
25
- }>;
22
+ generateSigningCallback(account: Account<BSName>): Promise<GenerateSigningCallbackResponse>;
26
23
  testNetwork(network: Network<BSNeo3NetworkId>): Promise<void>;
27
24
  setNetwork(network: Network<BSNeo3NetworkId>): void;
28
25
  validateAddress(address: string): boolean;
package/dist/BSNeo3.js CHANGED
@@ -27,6 +27,7 @@ const NeonDappKitLedgerServiceNeo3_1 = require("./services/ledger/NeonDappKitLed
27
27
  const GhostMarketNDSNeo3_1 = require("./services/nft-data/GhostMarketNDSNeo3");
28
28
  const BSNeo3Constants_1 = require("./constants/BSNeo3Constants");
29
29
  const RpcBDSNeo3_1 = require("./services/blockchain-data/RpcBDSNeo3");
30
+ const DoraVoteServiceNeo3_1 = require("./services/vote/DoraVoteServiceNeo3");
30
31
  class BSNeo3 {
31
32
  constructor(name, network, getLedgerTransport) {
32
33
  _BSNeo3_instances.add(this);
@@ -67,6 +68,7 @@ class BSNeo3 {
67
68
  this.network = network;
68
69
  this.nftDataService = new GhostMarketNDSNeo3_1.GhostMarketNDSNeo3(network);
69
70
  this.explorerService = new DoraESNeo3_1.DoraESNeo3(network);
71
+ this.voteService = new DoraVoteServiceNeo3_1.DoraVoteServiceNeo3(this);
70
72
  this.blockchainDataService = new DoraBDSNeo3_1.DoraBDSNeo3(network, this.feeToken, this.claimToken, this.tokens, this.nftDataService, this.explorerService);
71
73
  this.exchangeDataService = new FlamingoForthewinEDSNeo3_1.FlamingoForthewinEDSNeo3(network);
72
74
  }
@@ -0,0 +1,41 @@
1
+ import { Account } from '@cityofzion/blockchain-service';
2
+ import Neon from '@cityofzion/neon-core';
3
+ import { api } from '@cityofzion/neon-js';
4
+ export type GenerateSigningCallbackResponse = {
5
+ neonJsAccount: Neon.wallet.Account;
6
+ signingCallback: api.SigningFunction;
7
+ };
8
+ type Candidate = {
9
+ position: number;
10
+ name: string;
11
+ description: string;
12
+ location: string;
13
+ email: string;
14
+ website: string;
15
+ hash: string;
16
+ pubKey: string;
17
+ votes: number;
18
+ logoUrl?: string;
19
+ type: 'consensus' | 'council';
20
+ };
21
+ export type GetCandidatesToVoteResponse = Candidate[];
22
+ export type GetVoteDetailsByAddressResponse = {
23
+ candidateName: string;
24
+ candidatePubKey: string;
25
+ neoBalance: number;
26
+ };
27
+ export type VoteParams<BSName extends string> = {
28
+ account: Account<BSName>;
29
+ candidatePubKey: string;
30
+ };
31
+ export type VoteResponse = {
32
+ transactionHash: string;
33
+ };
34
+ export type CalculateVoteFeeParams<BSName extends string> = VoteParams<BSName>;
35
+ export interface VoteService<BSName extends string> {
36
+ getCandidatesToVote(): Promise<GetCandidatesToVoteResponse>;
37
+ getVoteDetailsByAddress(address: string): Promise<GetVoteDetailsByAddressResponse>;
38
+ vote(params: VoteParams<BSName>): Promise<VoteResponse>;
39
+ calculateVoteFee(params: CalculateVoteFeeParams<BSName>): Promise<string>;
40
+ }
41
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -30,7 +30,7 @@ var __rest = (this && this.__rest) || function (s, e) {
30
30
  }
31
31
  return t;
32
32
  };
33
- var _DoraBDSNeo3_instances, _DoraBDSNeo3_supportedNep11Standards, _DoraBDSNeo3_nftDataService, _DoraBDSNeo3_explorerService, _DoraBDSNeo3_validateFullTransactionsByAddressParams, _DoraBDSNeo3_validateGetFullTransactionsByAddressParams;
33
+ var _DoraBDSNeo3_instances, _DoraBDSNeo3_supportedNep11Standards, _DoraBDSNeo3_nftDataService, _DoraBDSNeo3_explorerService, _DoraBDSNeo3_validateAddress, _DoraBDSNeo3_validateFullTransactionsByAddressParams, _DoraBDSNeo3_validateGetFullTransactionsByAddressParams;
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
35
  exports.DoraBDSNeo3 = void 0;
36
36
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
@@ -342,11 +342,13 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
342
342
  }
343
343
  }
344
344
  exports.DoraBDSNeo3 = DoraBDSNeo3;
345
- _DoraBDSNeo3_supportedNep11Standards = new WeakMap(), _DoraBDSNeo3_nftDataService = new WeakMap(), _DoraBDSNeo3_explorerService = new WeakMap(), _DoraBDSNeo3_instances = new WeakSet(), _DoraBDSNeo3_validateFullTransactionsByAddressParams = function _DoraBDSNeo3_validateFullTransactionsByAddressParams(params) {
345
+ _DoraBDSNeo3_supportedNep11Standards = new WeakMap(), _DoraBDSNeo3_nftDataService = new WeakMap(), _DoraBDSNeo3_explorerService = new WeakMap(), _DoraBDSNeo3_instances = new WeakSet(), _DoraBDSNeo3_validateAddress = function _DoraBDSNeo3_validateAddress(address) {
346
+ return neon_js_1.wallet.isAddress(address, 53);
347
+ }, _DoraBDSNeo3_validateFullTransactionsByAddressParams = function _DoraBDSNeo3_validateFullTransactionsByAddressParams(params) {
346
348
  if (BSNeo3Helper_1.BSNeo3Helper.isCustomNet(this._network))
347
349
  throw new Error('Only Mainnet and Testnet are supported');
348
350
  blockchain_service_1.BSFullTransactionsByAddressHelper.validateFullTransactionsByAddressParams(params);
349
- if (!neon_js_1.wallet.isAddress(params.address))
351
+ if (!__classPrivateFieldGet(this, _DoraBDSNeo3_instances, "m", _DoraBDSNeo3_validateAddress).call(this, params.address))
350
352
  throw new Error('Invalid address param');
351
353
  }, _DoraBDSNeo3_validateGetFullTransactionsByAddressParams = function _DoraBDSNeo3_validateGetFullTransactionsByAddressParams(_a) {
352
354
  var { pageSize } = _a, params = __rest(_a, ["pageSize"]);
@@ -0,0 +1,31 @@
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> {
26
+ #private;
27
+ constructor(service: BSNeo3<BSName>);
28
+ getCandidatesToVote(): Promise<GetCandidatesToVoteResponse>;
29
+ getVoteDetailsByAddress(address: string): Promise<GetVoteDetailsByAddressResponse>;
30
+ }
31
+ export {};
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
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
+ var __rest = (this && this.__rest) || function (s, e) {
23
+ var t = {};
24
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
25
+ t[p] = s[p];
26
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
27
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
28
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
29
+ t[p[i]] = s[p[i]];
30
+ }
31
+ return t;
32
+ };
33
+ var __importDefault = (this && this.__importDefault) || function (mod) {
34
+ return (mod && mod.__esModule) ? mod : { "default": mod };
35
+ };
36
+ var _DoraVoteServiceNeo3_service, _DoraVoteServiceNeo3_doraAxiosInstance;
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.DoraVoteServiceNeo3 = void 0;
39
+ const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
40
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
41
+ const axios_1 = __importDefault(require("axios"));
42
+ const RpcVoteServiceNeo3_1 = require("./RpcVoteServiceNeo3");
43
+ class DoraVoteServiceNeo3 extends RpcVoteServiceNeo3_1.RpcVoteServiceNeo3 {
44
+ 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");
50
+ }
51
+ getCandidatesToVote() {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _DoraVoteServiceNeo3_service, "f").network))
54
+ throw new Error('Only Mainnet is supported');
55
+ const { data } = yield __classPrivateFieldGet(this, _DoraVoteServiceNeo3_doraAxiosInstance, "f").get('/mainnet/committee');
56
+ return data.map((_a, index) => {
57
+ var { logo } = _a, candidate = __rest(_a, ["logo"]);
58
+ const position = index + 1;
59
+ return {
60
+ position,
61
+ name: candidate.name,
62
+ description: candidate.description,
63
+ location: candidate.location,
64
+ email: candidate.email,
65
+ website: candidate.website,
66
+ hash: candidate.scripthash,
67
+ pubKey: candidate.pubkey,
68
+ votes: candidate.votes,
69
+ logoUrl: logo.startsWith('https://') ? logo : undefined,
70
+ type: position <= 7 ? 'consensus' : 'council',
71
+ };
72
+ });
73
+ });
74
+ }
75
+ getVoteDetailsByAddress(address) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _DoraVoteServiceNeo3_service, "f").network))
78
+ throw new Error('Only Mainnet is supported');
79
+ if (!address)
80
+ throw new Error('Missing address');
81
+ if (!__classPrivateFieldGet(this, _DoraVoteServiceNeo3_service, "f").validateAddress(address))
82
+ throw new Error('Invalid address');
83
+ const _a = (yield __classPrivateFieldGet(this, _DoraVoteServiceNeo3_doraAxiosInstance, "f").get(`/mainnet/voter/${address}`)).data, { candidatePubkey } = _a, data = __rest(_a, ["candidatePubkey"]);
84
+ if (!candidatePubkey)
85
+ throw new Error('There was a problem to get vote details by address');
86
+ return {
87
+ candidateName: data.candidate,
88
+ candidatePubKey: candidatePubkey,
89
+ neoBalance: data.balance,
90
+ };
91
+ });
92
+ }
93
+ }
94
+ exports.DoraVoteServiceNeo3 = DoraVoteServiceNeo3;
95
+ _DoraVoteServiceNeo3_service = new WeakMap(), _DoraVoteServiceNeo3_doraAxiosInstance = new WeakMap();
@@ -0,0 +1,10 @@
1
+ import { CalculateVoteFeeParams, GetCandidatesToVoteResponse, GetVoteDetailsByAddressResponse, VoteParams, VoteResponse, VoteService } from '../../interfaces';
2
+ import { BSNeo3 } from '../../BSNeo3';
3
+ export declare abstract class RpcVoteServiceNeo3<BSName extends string> implements VoteService<BSName> {
4
+ #private;
5
+ protected constructor(service: BSNeo3<BSName>);
6
+ abstract getCandidatesToVote(): Promise<GetCandidatesToVoteResponse>;
7
+ abstract getVoteDetailsByAddress(_address: string): Promise<GetVoteDetailsByAddressResponse>;
8
+ vote({ account, candidatePubKey }: VoteParams<BSName>): Promise<VoteResponse>;
9
+ calculateVoteFee({ account, candidatePubKey }: CalculateVoteFeeParams<BSName>): Promise<string>;
10
+ }
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ 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
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
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
+ var _RpcVoteServiceNeo3_instances, _RpcVoteServiceNeo3_service, _RpcVoteServiceNeo3_getVoteCIM;
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.RpcVoteServiceNeo3 = void 0;
25
+ const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
26
+ const neon_dappkit_1 = require("@cityofzion/neon-dappkit");
27
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
28
+ const neon_js_1 = require("@cityofzion/neon-js");
29
+ class RpcVoteServiceNeo3 {
30
+ constructor(service) {
31
+ _RpcVoteServiceNeo3_instances.add(this);
32
+ _RpcVoteServiceNeo3_service.set(this, void 0);
33
+ __classPrivateFieldSet(this, _RpcVoteServiceNeo3_service, service, "f");
34
+ }
35
+ vote({ account, candidatePubKey }) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _RpcVoteServiceNeo3_service, "f").network))
38
+ throw new Error('Only Mainnet is supported');
39
+ if (!candidatePubKey)
40
+ throw new Error('Missing candidatePubKey param');
41
+ const { neonJsAccount, signingCallback } = yield __classPrivateFieldGet(this, _RpcVoteServiceNeo3_service, "f").generateSigningCallback(account);
42
+ const invoker = yield neon_dappkit_1.NeonInvoker.init({
43
+ rpcAddress: __classPrivateFieldGet(this, _RpcVoteServiceNeo3_service, "f").network.url,
44
+ account: neonJsAccount,
45
+ signingCallback,
46
+ });
47
+ const transactionHash = yield invoker.invokeFunction(__classPrivateFieldGet(this, _RpcVoteServiceNeo3_instances, "m", _RpcVoteServiceNeo3_getVoteCIM).call(this, {
48
+ address: account.address,
49
+ candidatePubKey,
50
+ }));
51
+ return { transactionHash };
52
+ });
53
+ }
54
+ calculateVoteFee({ account, candidatePubKey }) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(__classPrivateFieldGet(this, _RpcVoteServiceNeo3_service, "f").network))
57
+ throw new Error('Only Mainnet is supported');
58
+ if (!candidatePubKey)
59
+ throw new Error('Missing candidatePubKey param');
60
+ const { neonJsAccount } = yield __classPrivateFieldGet(this, _RpcVoteServiceNeo3_service, "f").generateSigningCallback(account);
61
+ const invoker = yield neon_dappkit_1.NeonInvoker.init({
62
+ rpcAddress: __classPrivateFieldGet(this, _RpcVoteServiceNeo3_service, "f").network.url,
63
+ account: neonJsAccount,
64
+ });
65
+ const { total } = yield invoker.calculateFee(__classPrivateFieldGet(this, _RpcVoteServiceNeo3_instances, "m", _RpcVoteServiceNeo3_getVoteCIM).call(this, {
66
+ address: account.address,
67
+ candidatePubKey,
68
+ }));
69
+ return blockchain_service_1.BSNumberHelper.formatNumber(total, { decimals: __classPrivateFieldGet(this, _RpcVoteServiceNeo3_service, "f").feeToken.decimals });
70
+ });
71
+ }
72
+ }
73
+ exports.RpcVoteServiceNeo3 = RpcVoteServiceNeo3;
74
+ _RpcVoteServiceNeo3_service = new WeakMap(), _RpcVoteServiceNeo3_instances = new WeakSet(), _RpcVoteServiceNeo3_getVoteCIM = function _RpcVoteServiceNeo3_getVoteCIM({ address, candidatePubKey }) {
75
+ return {
76
+ invocations: [
77
+ {
78
+ scriptHash: 'ef4073a0f2b305a38ec4050e4d3d28bc40ea63f5',
79
+ operation: 'vote',
80
+ args: [
81
+ { type: 'Hash160', value: address },
82
+ { type: 'PublicKey', value: candidatePubKey },
83
+ ],
84
+ },
85
+ ],
86
+ signers: [{ scopes: neon_js_1.tx.WitnessScope.CalledByEntry }],
87
+ };
88
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-neo3",
3
- "version": "1.13.2",
3
+ "version": "1.14.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",