Skip to content

Commit 0158979

Browse files
committed
Merge branch 'pbsa-develop' into 'develop'
Sync pbsa-develop and develop See merge request PBSA/PeerplaysIO/tools-libs/peerplaysjs-lib!53
2 parents d313da9 + 0707ade commit 0158979

25 files changed

+14921
-1223
lines changed

CHANGELOG.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5-
### [0.6.5](https://github.com/peerplays-network/peerplaysjs-lib/compare/v0.6.0...v0.6.5) (2019-12-24)
6-
7-
8-
### Bug Fixes
9-
10-
* remove vesting_balance_type from vesting_balance_withdraw_operation ([1ba7f2f](https://github.com/peerplays-network/peerplaysjs-lib/commit/1ba7f2f810bbf48c6cca88a4cd4869ed7d034c6b))
11-
125
### [0.6.4](https://github.com/peerplays-network/peerplaysjs-lib/compare/v0.6.2...v0.6.4) (2019-12-16)
136

147

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ The auths object should contain the auth arrays from the account object. An exam
146146
```json
147147
{
148148
active: [
149-
["GPH5Abm5dCdy3hJ1C5ckXkqUH2Me7dXqi9Y7yjn9ACaiSJ9h8r8mL", 1]
149+
["PPY∂5Abm5dCdy3hJ1C5ckXkqUH2Me7dXqi9Y7yjn9ACaiSJ9h8r8mL", 1]
150150
]
151151
}
152152
```

build/peerplaysjs-lib.js

Lines changed: 511 additions & 24 deletions
Large diffs are not rendered by default.

build/peerplaysjs-lib.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/chain/src/AccountLogin.js

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,49 @@ var AccountLogin = function () {
2323
function AccountLogin() {
2424
_classCallCheck(this, AccountLogin);
2525

26-
var state = { loggedIn: false, roles: ['active', 'owner', 'memo'] };
26+
var state = { loggedIn: false, roles: ['owner', 'active', 'memo'] };
2727
this.get = (0, _state.get)(state);
2828
this.set = (0, _state.set)(state);
2929

3030
this.subs = {};
3131
}
3232

33+
/**
34+
* Subscribe to provided item.
35+
*
36+
* @param {*} cb
37+
* @memberof AccountLogin
38+
*/
39+
40+
3341
AccountLogin.prototype.addSubscription = function addSubscription(cb) {
3442
this.subs[cb] = cb;
3543
};
3644

45+
/**
46+
* Set the roles. Used for key generation.
47+
*
48+
* @param {Array} roles - ['owner', 'active', 'memo']
49+
* @memberof AccountLogin
50+
*/
51+
52+
3753
AccountLogin.prototype.setRoles = function setRoles(roles) {
3854
this.set('roles', roles);
3955
};
4056

57+
/**
58+
* Call this function to generate Peerplays user account keys.
59+
*
60+
* @param {String} accountName - The users' account name (username).
61+
* @param {String} password - The users' password.
62+
* @param {Array} roles - ['owner', 'active', 'memo']
63+
* @param {String} prefix - Optional. The core token symbol (1.3.0 = 'PPY')
64+
* @returns {Object} - Keys object: `{privKeys, pubKeys}`
65+
* @memberof AccountLogin
66+
*/
67+
68+
4169
AccountLogin.prototype.generateKeys = function generateKeys(accountName, password, roles, prefix) {
4270
if (!accountName || !password) {
4371
throw new Error('Account name or password required');
@@ -64,12 +92,32 @@ var AccountLogin = function () {
6492
return { privKeys: privKeys, pubKeys: pubKeys };
6593
};
6694

95+
/**
96+
* Accepts an account name {string}, password {string}, and an auths object. We loop over the
97+
* provided auths whichcontains the keys associated with the account we are working with.
98+
*
99+
* We verify that the keys provided (which are pulled from the blockchain prior) match up with
100+
* keys we generate with the provided account name and password.
101+
*
102+
* This function is dependant upon the roles array being specified in the correct order:
103+
* 1. owner
104+
* 2. active
105+
* 3. memo
106+
*
107+
* @param {Object} {accountName, password, auths} - string, string, array
108+
* @param {String} prefix - Optional. The core token symbol (1.3.0 = 'PPY')
109+
* @returns {Boolean}
110+
* @memberof AccountLogin
111+
*/
112+
113+
67114
AccountLogin.prototype.checkKeys = function checkKeys(_ref) {
68115
var _this = this;
69116

70117
var accountName = _ref.accountName,
71118
password = _ref.password,
72119
auths = _ref.auths;
120+
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'PPY';
73121

74122
if (!accountName || !password || !auths) {
75123
throw new Error('checkKeys: Missing inputs');
@@ -81,11 +129,12 @@ var AccountLogin = function () {
81129
var _loop = function _loop(i, len) {
82130
var role = roles[i];
83131

84-
var _generateKeys = _this.generateKeys(accountName, password, [role]),
132+
var _generateKeys = _this.generateKeys(accountName, password, [role], prefix),
85133
privKeys = _generateKeys.privKeys,
86134
pubKeys = _generateKeys.pubKeys;
87135

88136
auths[role].forEach(function (roleKey) {
137+
// Check if the active key matches
89138
if (roleKey[0] === pubKeys[role]) {
90139
hasKey = true;
91140
_this.set(role, { priv: privKeys[role], pub: pubKeys[role] });
@@ -106,6 +155,18 @@ var AccountLogin = function () {
106155
return hasKey;
107156
};
108157

158+
/**
159+
* Call this function and provide a valid transaction object to sign it with
160+
* the users' Active key.
161+
* Pre-requisite is that AccountLogin.js (`Login`) has had its roles set and
162+
* the users' keys were generated with AccountLogin.js (`Login`)
163+
*
164+
* @param {Object} tr - Transaction object built via TransactionBuilder.js
165+
* @returns {Object} tr - Transaction object that was passed in but signed.
166+
* @memberof AccountLogin
167+
*/
168+
169+
109170
AccountLogin.prototype.signTransaction = function signTransaction(tr) {
110171
var _this2 = this;
111172

dist/chain/src/ChainStore.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ var op_history = parseInt(object_type.operation_history, 10);
3939
var limit_order = parseInt(object_type.limit_order, 10);
4040
var call_order = parseInt(object_type.call_order, 10);
4141
var proposal = parseInt(object_type.proposal, 10);
42+
var balance_type = parseInt(object_type.balance, 10);
43+
var vesting_balance_type = parseInt(object_type.vesting_balance, 10);
4244
var witness_object_type = parseInt(object_type.witness, 10);
4345
var worker_object_type = parseInt(object_type.worker, 10);
4446
var committee_member_object_type = parseInt(object_type.committee_member, 10);
@@ -58,6 +60,7 @@ var account_transaction_history_prefix = '2.' + parseInt(impl_object_type.accoun
5860
var asset_dynamic_data_prefix = '2.' + parseInt(impl_object_type.asset_dynamic_data, 10) + '.';
5961
var bitasset_data_prefix = '2.' + parseInt(impl_object_type.asset_bitasset_data, 10) + '.';
6062
var block_summary_prefix = '2.' + parseInt(impl_object_type.block_summary, 10) + '.';
63+
var vesting_balance_prefix = '1.' + vesting_balance_type + '.';
6164
var witness_prefix = '1.' + witness_object_type + '.';
6265
var worker_prefix = '1.' + worker_object_type + '.';
6366
var committee_prefix = '1.' + committee_member_object_type + '.';
@@ -131,6 +134,8 @@ var ChainStore = function () {
131134
this.recent_blocks_by_id = _immutable2.default.Map();
132135
this.last_processed_block = null;
133136
this.simple_objects_by_id = _immutable2.default.Map();
137+
this.lotteries_ids = _immutable2.default.List();
138+
this.lotteries_ids_initialized = false;
134139

135140
clearTimeout(this.timeout);
136141

@@ -1791,6 +1796,15 @@ var ChainStore = function () {
17911796
current = current.set('bitasset', bad);
17921797
this.objects_by_id = this.objects_by_id.set(object.id, current);
17931798
}
1799+
1800+
//lottery asset
1801+
if (object.lottery_options && this.lotteries_ids.findIndex(function (item) {
1802+
return item === object.id;
1803+
}) === -1) {
1804+
this.lotteries_ids = this.lotteries_ids.push(object.id).sortBy(function (item) {
1805+
return -parseInt(item.split('.')[2]);
1806+
});
1807+
}
17941808
} else if (objectSpace === asset_dynamic_data_prefix) {
17951809
// ASSET DYNAMIC DATA OBJECT
17961810
var asset_id = current.get('asset_id');
@@ -2197,6 +2211,66 @@ var ChainStore = function () {
21972211
return this.recent_operations;
21982212
};
21992213

2214+
ChainStore.prototype.getLastIdLottery = function getLastIdLottery() {
2215+
return _ws.Apis.instance().db_api().exec('get_lotteries', ['1.3.0', 1, '1.3.0']).then(function (lotteries) {
2216+
2217+
if (!lotteries || !lotteries.length) {
2218+
return '1.3.0';
2219+
}
2220+
2221+
return lotteries[0]['id'];
2222+
});
2223+
};
2224+
2225+
ChainStore.prototype.getAllLotteriesIds = function getAllLotteriesIds() {
2226+
var _this27 = this;
2227+
2228+
return new Promise(function (resolve) {
2229+
2230+
if (_this27.lotteries_ids_initialized) {
2231+
return resolve(_this27.lotteries_ids);
2232+
}
2233+
2234+
_this27.getLastIdLottery().then(function (lastId) {
2235+
2236+
var self = _this27;
2237+
2238+
var fetchLotteries = function fetchLotteries(prevId, limit, nextId, isLastRequest) {
2239+
2240+
if (isLastRequest) {
2241+
self.lotteries_ids_initialized = true;
2242+
return resolve(self.lotteries_ids);
2243+
}
2244+
2245+
return _ws.Apis.instance().db_api().exec('get_lotteries', [prevId, limit, nextId]).then(function (lotteries) {
2246+
2247+
if (!lotteries.length) {
2248+
self.lotteries_ids_initialized = true;
2249+
return resolve(self.lotteries_ids);
2250+
}
2251+
2252+
lotteries.forEach(function (lotteryAsset) {
2253+
self._updateObject(lotteryAsset, false, false);
2254+
});
2255+
2256+
if (lotteries.length < limit) {
2257+
self.lotteries_ids_initialized = true;
2258+
return resolve(self.lotteries_ids);
2259+
}
2260+
2261+
var firstId = lotteries[0]['id'],
2262+
firstIdNum = parseInt(firstId.split('.')[2]),
2263+
nextNumId = firstIdNum - limit;
2264+
2265+
return fetchLotteries('1.3.0', limit, '1.3.' + Math.max(nextNumId, 0), firstIdNum - limit < 0 || !nextNumId);
2266+
});
2267+
};
2268+
2269+
fetchLotteries('1.3.0', 100, lastId, false);
2270+
});
2271+
});
2272+
};
2273+
22002274
return ChainStore;
22012275
}();
22022276

dist/chain/src/ChainTypes.js

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ var object_type = {
3434
betting_market_rules: 23,
3535
betting_market_group: 24,
3636
betting_market: 25,
37-
bet: 26
37+
bet: 26,
38+
custom_permission: 27,
39+
custom_account_authority: 28,
40+
offer: 29,
41+
nft_metadata: 30,
42+
nft: 31
3843
};
3944

4045
var impl_object_type = {
@@ -55,11 +60,14 @@ var impl_object_type = {
5560
special_authority: 14,
5661
buyback: 15,
5762
fba_accumulator: 16,
58-
betting_market_position: 17,
59-
global_betting_statistics: 18,
60-
asset_dividend_data: 19,
61-
pending_dividend_payout_balance_for_holder: 20,
62-
distributed_dividend_balance_data: 21
63+
asset_dividend_data: 17,
64+
pending_dividend_payout_balance_for_holder: 18,
65+
distributed_dividend_balance_data: 19,
66+
betting_market_position: 20,
67+
global_betting_statistics: 21,
68+
lottery_balance: 22,
69+
sweeps_vesting_balance: 23,
70+
offer_history: 24
6371
};
6472

6573
var vote_type = {
@@ -141,7 +149,32 @@ var operations = {
141149
bet_canceled: 69,
142150
betting_market_group_update: 70,
143151
betting_market_update: 71,
144-
event_update_status: 72
152+
event_update_status: 72,
153+
sport_delete: 73,
154+
event_group_delete: 74,
155+
affiliate_payout: 75,
156+
affiliate_referral_payout: 76,
157+
lottery_asset_create: 77,
158+
ticket_purchase: 78,
159+
lottery_reward: 79,
160+
lottery_end: 80,
161+
sweeps_vesting_claim: 81,
162+
custom_permission_create: 82,
163+
custom_permission_update: 83,
164+
custom_permission_delete: 84,
165+
custom_account_authority_create: 85,
166+
custom_account_authority_update: 86,
167+
custom_account_authority_delete: 87,
168+
offer: 88,
169+
bid: 89,
170+
cancel_offer: 90,
171+
finalize_offer: 91,
172+
nft_metadata_create: 92,
173+
nft_metadata_update: 93,
174+
nft_mint: 94,
175+
nft_safe_transfer_from: 95,
176+
nft_approve: 96,
177+
nft_set_approval_for_all: 97
145178
};
146179

147180
var ChainTypes = {

dist/ecc/src/PublicKey.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ var PublicKey = function () {
128128
};
129129

130130
/**
131-
@arg {string} public_key - like GPHXyz...
132-
@arg {string} address_prefix - like GPH
131+
@arg {string} public_key - like PPYXyz...
132+
@arg {string} address_prefix - like PPY
133133
@throws {Error} if public key is invalid
134134
@return PublicKey
135135
*/

0 commit comments

Comments
 (0)