@cityofzion/bs-neo3 1.13.1 → 1.14.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/dist/BSNeo3.d.ts +3 -6
- package/dist/BSNeo3.js +2 -0
- package/dist/interfaces.d.ts +41 -0
- package/dist/interfaces.js +2 -0
- package/dist/services/blockchain-data/DoraBDSNeo3.js +22 -13
- package/dist/services/vote/DoraVoteServiceNeo3.d.ts +31 -0
- package/dist/services/vote/DoraVoteServiceNeo3.js +93 -0
- package/dist/services/vote/RpcVoteServiceNeo3.d.ts +11 -0
- package/dist/services/vote/RpcVoteServiceNeo3.js +81 -0
- package/package.json +2 -2
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 {};
|
|
@@ -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");
|
|
@@ -169,7 +169,8 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
|
|
|
169
169
|
const txTemplateUrl = __classPrivateFieldGet(this, _DoraBDSNeo3_explorerService, "f").getTxTemplateUrl();
|
|
170
170
|
const nftTemplateUrl = __classPrivateFieldGet(this, _DoraBDSNeo3_explorerService, "f").getNftTemplateUrl();
|
|
171
171
|
const contractTemplateUrl = __classPrivateFieldGet(this, _DoraBDSNeo3_explorerService, "f").getContractTemplateUrl();
|
|
172
|
-
const itemPromises = items.map((
|
|
172
|
+
const itemPromises = items.map((_d) => __awaiter(this, void 0, void 0, function* () {
|
|
173
|
+
var { networkFeeAmount, systemFeeAmount } = _d, item = __rest(_d, ["networkFeeAmount", "systemFeeAmount"]);
|
|
173
174
|
const txId = item.transactionID;
|
|
174
175
|
const newItem = {
|
|
175
176
|
txId,
|
|
@@ -178,28 +179,32 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
|
|
|
178
179
|
date: item.date,
|
|
179
180
|
invocationCount: item.invocationCount,
|
|
180
181
|
notificationCount: item.notificationCount,
|
|
181
|
-
networkFeeAmount:
|
|
182
|
-
|
|
182
|
+
networkFeeAmount: networkFeeAmount
|
|
183
|
+
? blockchain_service_1.BSNumberHelper.formatNumber(networkFeeAmount, { decimals: this._feeToken.decimals })
|
|
184
|
+
: undefined,
|
|
185
|
+
systemFeeAmount: systemFeeAmount
|
|
186
|
+
? blockchain_service_1.BSNumberHelper.formatNumber(systemFeeAmount, { decimals: this._feeToken.decimals })
|
|
187
|
+
: undefined,
|
|
183
188
|
events: [],
|
|
184
189
|
};
|
|
185
190
|
const eventPromises = item.events.map((event) => __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
var
|
|
191
|
+
var _e, _f, _g, _h, _j, _k;
|
|
187
192
|
let nftEvent;
|
|
188
193
|
let assetEvent;
|
|
189
194
|
const { methodName, tokenID: tokenId, contractHash: hash } = event;
|
|
190
|
-
const from = (
|
|
191
|
-
const to = (
|
|
195
|
+
const from = (_e = event.from) !== null && _e !== void 0 ? _e : undefined;
|
|
196
|
+
const to = (_f = event.to) !== null && _f !== void 0 ? _f : undefined;
|
|
192
197
|
const fromUrl = from ? addressTemplateUrl === null || addressTemplateUrl === void 0 ? void 0 : addressTemplateUrl.replace('{address}', from) : undefined;
|
|
193
198
|
const toUrl = to ? addressTemplateUrl === null || addressTemplateUrl === void 0 ? void 0 : addressTemplateUrl.replace('{address}', to) : undefined;
|
|
194
199
|
const hashUrl = hash ? contractTemplateUrl === null || contractTemplateUrl === void 0 ? void 0 : contractTemplateUrl.replace('{hash}', hash) : undefined;
|
|
195
|
-
const standard = (
|
|
200
|
+
const standard = (_j = (_h = (_g = event.supportedStandards) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.toLowerCase()) !== null && _j !== void 0 ? _j : '';
|
|
196
201
|
const isNft = __classPrivateFieldGet(this, _DoraBDSNeo3_supportedNep11Standards, "f").includes(standard) && !!tokenId;
|
|
197
202
|
if (isNft) {
|
|
198
203
|
const [nft] = yield blockchain_service_1.BSPromisesHelper.tryCatch(() => __classPrivateFieldGet(this, _DoraBDSNeo3_nftDataService, "f").getNft({ contractHash: hash, tokenId }));
|
|
199
204
|
const nftUrl = hash ? nftTemplateUrl === null || nftTemplateUrl === void 0 ? void 0 : nftTemplateUrl.replace('{hash}', hash).replace('{tokenId}', tokenId) : undefined;
|
|
200
205
|
nftEvent = {
|
|
201
206
|
eventType: 'nft',
|
|
202
|
-
amount:
|
|
207
|
+
amount: undefined,
|
|
203
208
|
methodName,
|
|
204
209
|
from,
|
|
205
210
|
fromUrl,
|
|
@@ -217,10 +222,12 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
|
|
|
217
222
|
}
|
|
218
223
|
else {
|
|
219
224
|
const [token] = yield blockchain_service_1.BSPromisesHelper.tryCatch(() => this.getTokenInfo(hash));
|
|
220
|
-
const
|
|
225
|
+
const { amount } = event;
|
|
221
226
|
assetEvent = {
|
|
222
227
|
eventType: 'token',
|
|
223
|
-
amount
|
|
228
|
+
amount: amount
|
|
229
|
+
? blockchain_service_1.BSNumberHelper.formatNumber(amount, { decimals: (_k = token === null || token === void 0 ? void 0 : token.decimals) !== null && _k !== void 0 ? _k : event.tokenDecimals })
|
|
230
|
+
: undefined,
|
|
224
231
|
methodName,
|
|
225
232
|
from,
|
|
226
233
|
fromUrl,
|
|
@@ -335,11 +342,13 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RpcBDSNeo3 {
|
|
|
335
342
|
}
|
|
336
343
|
}
|
|
337
344
|
exports.DoraBDSNeo3 = DoraBDSNeo3;
|
|
338
|
-
_DoraBDSNeo3_supportedNep11Standards = new WeakMap(), _DoraBDSNeo3_nftDataService = new WeakMap(), _DoraBDSNeo3_explorerService = new WeakMap(), _DoraBDSNeo3_instances = new WeakSet(),
|
|
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) {
|
|
339
348
|
if (BSNeo3Helper_1.BSNeo3Helper.isCustomNet(this._network))
|
|
340
349
|
throw new Error('Only Mainnet and Testnet are supported');
|
|
341
350
|
blockchain_service_1.BSFullTransactionsByAddressHelper.validateFullTransactionsByAddressParams(params);
|
|
342
|
-
if (!
|
|
351
|
+
if (!__classPrivateFieldGet(this, _DoraBDSNeo3_instances, "m", _DoraBDSNeo3_validateAddress).call(this, params.address))
|
|
343
352
|
throw new Error('Invalid address param');
|
|
344
353
|
}, _DoraBDSNeo3_validateGetFullTransactionsByAddressParams = function _DoraBDSNeo3_validateGetFullTransactionsByAddressParams(_a) {
|
|
345
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,93 @@
|
|
|
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_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_doraAxiosInstance.set(this, void 0);
|
|
47
|
+
__classPrivateFieldSet(this, _DoraVoteServiceNeo3_doraAxiosInstance, axios_1.default.create({ baseURL: `${blockchain_service_1.BSCommonConstants.DORA_URL}/api/v2/neo3` }), "f");
|
|
48
|
+
}
|
|
49
|
+
getCandidatesToVote() {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(this._service.network))
|
|
52
|
+
throw new Error('Only Mainnet is supported');
|
|
53
|
+
const { data } = yield __classPrivateFieldGet(this, _DoraVoteServiceNeo3_doraAxiosInstance, "f").get('/mainnet/committee');
|
|
54
|
+
return data.map((_a, index) => {
|
|
55
|
+
var { logo } = _a, candidate = __rest(_a, ["logo"]);
|
|
56
|
+
const position = index + 1;
|
|
57
|
+
return {
|
|
58
|
+
position,
|
|
59
|
+
name: candidate.name,
|
|
60
|
+
description: candidate.description,
|
|
61
|
+
location: candidate.location,
|
|
62
|
+
email: candidate.email,
|
|
63
|
+
website: candidate.website,
|
|
64
|
+
hash: candidate.scripthash,
|
|
65
|
+
pubKey: candidate.pubkey,
|
|
66
|
+
votes: candidate.votes,
|
|
67
|
+
logoUrl: logo.startsWith('https://') ? logo : undefined,
|
|
68
|
+
type: position <= 7 ? 'consensus' : 'council',
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
getVoteDetailsByAddress(address) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(this._service.network))
|
|
76
|
+
throw new Error('Only Mainnet is supported');
|
|
77
|
+
if (!address)
|
|
78
|
+
throw new Error('Missing address');
|
|
79
|
+
if (!this._service.validateAddress(address))
|
|
80
|
+
throw new Error('Invalid address');
|
|
81
|
+
const _a = (yield __classPrivateFieldGet(this, _DoraVoteServiceNeo3_doraAxiosInstance, "f").get(`/mainnet/voter/${address}`)).data, { candidatePubkey } = _a, data = __rest(_a, ["candidatePubkey"]);
|
|
82
|
+
if (!candidatePubkey)
|
|
83
|
+
throw new Error('There was a problem to get vote details by address');
|
|
84
|
+
return {
|
|
85
|
+
candidateName: data.candidate,
|
|
86
|
+
candidatePubKey: candidatePubkey,
|
|
87
|
+
neoBalance: data.balance,
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.DoraVoteServiceNeo3 = DoraVoteServiceNeo3;
|
|
93
|
+
_DoraVoteServiceNeo3_doraAxiosInstance = new WeakMap();
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
readonly _service: BSNeo3<BSName>;
|
|
6
|
+
protected constructor(service: BSNeo3<BSName>);
|
|
7
|
+
abstract getCandidatesToVote(): Promise<GetCandidatesToVoteResponse>;
|
|
8
|
+
abstract getVoteDetailsByAddress(_address: string): Promise<GetVoteDetailsByAddressResponse>;
|
|
9
|
+
vote({ account, candidatePubKey }: VoteParams<BSName>): Promise<VoteResponse>;
|
|
10
|
+
calculateVoteFee({ account, candidatePubKey }: CalculateVoteFeeParams<BSName>): Promise<string>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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 __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
|
+
};
|
|
16
|
+
var _RpcVoteServiceNeo3_instances, _RpcVoteServiceNeo3_getVoteCIM;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.RpcVoteServiceNeo3 = void 0;
|
|
19
|
+
const BSNeo3Helper_1 = require("../../helpers/BSNeo3Helper");
|
|
20
|
+
const neon_dappkit_1 = require("@cityofzion/neon-dappkit");
|
|
21
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
22
|
+
const neon_js_1 = require("@cityofzion/neon-js");
|
|
23
|
+
class RpcVoteServiceNeo3 {
|
|
24
|
+
constructor(service) {
|
|
25
|
+
_RpcVoteServiceNeo3_instances.add(this);
|
|
26
|
+
this._service = service;
|
|
27
|
+
}
|
|
28
|
+
vote({ account, candidatePubKey }) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(this._service.network))
|
|
31
|
+
throw new Error('Only Mainnet is supported');
|
|
32
|
+
if (!candidatePubKey)
|
|
33
|
+
throw new Error('Missing candidatePubKey param');
|
|
34
|
+
const { neonJsAccount, signingCallback } = yield this._service.generateSigningCallback(account);
|
|
35
|
+
const invoker = yield neon_dappkit_1.NeonInvoker.init({
|
|
36
|
+
rpcAddress: this._service.network.url,
|
|
37
|
+
account: neonJsAccount,
|
|
38
|
+
signingCallback,
|
|
39
|
+
});
|
|
40
|
+
const transactionHash = yield invoker.invokeFunction(__classPrivateFieldGet(this, _RpcVoteServiceNeo3_instances, "m", _RpcVoteServiceNeo3_getVoteCIM).call(this, {
|
|
41
|
+
address: account.address,
|
|
42
|
+
candidatePubKey,
|
|
43
|
+
}));
|
|
44
|
+
return { transactionHash };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
calculateVoteFee({ account, candidatePubKey }) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (!BSNeo3Helper_1.BSNeo3Helper.isMainnet(this._service.network))
|
|
50
|
+
throw new Error('Only Mainnet is supported');
|
|
51
|
+
if (!candidatePubKey)
|
|
52
|
+
throw new Error('Missing candidatePubKey param');
|
|
53
|
+
const { neonJsAccount } = yield this._service.generateSigningCallback(account);
|
|
54
|
+
const invoker = yield neon_dappkit_1.NeonInvoker.init({
|
|
55
|
+
rpcAddress: this._service.network.url,
|
|
56
|
+
account: neonJsAccount,
|
|
57
|
+
});
|
|
58
|
+
const { total } = yield invoker.calculateFee(__classPrivateFieldGet(this, _RpcVoteServiceNeo3_instances, "m", _RpcVoteServiceNeo3_getVoteCIM).call(this, {
|
|
59
|
+
address: account.address,
|
|
60
|
+
candidatePubKey,
|
|
61
|
+
}));
|
|
62
|
+
return blockchain_service_1.BSNumberHelper.formatNumber(total, { decimals: this._service.feeToken.decimals });
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.RpcVoteServiceNeo3 = RpcVoteServiceNeo3;
|
|
67
|
+
_RpcVoteServiceNeo3_instances = new WeakSet(), _RpcVoteServiceNeo3_getVoteCIM = function _RpcVoteServiceNeo3_getVoteCIM({ address, candidatePubKey }) {
|
|
68
|
+
return {
|
|
69
|
+
invocations: [
|
|
70
|
+
{
|
|
71
|
+
scriptHash: 'ef4073a0f2b305a38ec4050e4d3d28bc40ea63f5',
|
|
72
|
+
operation: 'vote',
|
|
73
|
+
args: [
|
|
74
|
+
{ type: 'Hash160', value: address },
|
|
75
|
+
{ type: 'PublicKey', value: candidatePubKey },
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
signers: [{ scopes: neon_js_1.tx.WitnessScope.CalledByEntry }],
|
|
80
|
+
};
|
|
81
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/bs-neo3",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"isomorphic-ws": "^5.0.0",
|
|
22
22
|
"lodash.clonedeep": "^4.5.0",
|
|
23
23
|
"date-fns": "~4.1.0",
|
|
24
|
-
"@cityofzion/blockchain-service": "1.18.
|
|
24
|
+
"@cityofzion/blockchain-service": "1.18.2",
|
|
25
25
|
"@cityofzion/bs-asteroid-sdk": "0.9.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|