Skip to content

Commit

Permalink
Merge branch 'pbsa-develop' into 'develop'
Browse files Browse the repository at this point in the history
Sync pbsa-develop and develop

See merge request PBSA/PeerplaysIO/tools-libs/peerplaysjs-lib!53
  • Loading branch information
RoshanSyed committed Aug 11, 2020
2 parents d313da9 + 0707ade commit 0158979
Show file tree
Hide file tree
Showing 25 changed files with 14,921 additions and 1,223 deletions.
7 changes: 0 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

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.

### [0.6.5](https://github.com/peerplays-network/peerplaysjs-lib/compare/v0.6.0...v0.6.5) (2019-12-24)


### Bug Fixes

* remove vesting_balance_type from vesting_balance_withdraw_operation ([1ba7f2f](https://github.com/peerplays-network/peerplaysjs-lib/commit/1ba7f2f810bbf48c6cca88a4cd4869ed7d034c6b))

### [0.6.4](https://github.com/peerplays-network/peerplaysjs-lib/compare/v0.6.2...v0.6.4) (2019-12-16)


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ The auths object should contain the auth arrays from the account object. An exam
```json
{
active: [
["GPH5Abm5dCdy3hJ1C5ckXkqUH2Me7dXqi9Y7yjn9ACaiSJ9h8r8mL", 1]
["PPY∂5Abm5dCdy3hJ1C5ckXkqUH2Me7dXqi9Y7yjn9ACaiSJ9h8r8mL", 1]
]
}
```
Expand Down
535 changes: 511 additions & 24 deletions build/peerplaysjs-lib.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/peerplaysjs-lib.min.js

Large diffs are not rendered by default.

65 changes: 63 additions & 2 deletions dist/chain/src/AccountLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,49 @@ var AccountLogin = function () {
function AccountLogin() {
_classCallCheck(this, AccountLogin);

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

this.subs = {};
}

/**
* Subscribe to provided item.
*
* @param {*} cb
* @memberof AccountLogin
*/


AccountLogin.prototype.addSubscription = function addSubscription(cb) {
this.subs[cb] = cb;
};

/**
* Set the roles. Used for key generation.
*
* @param {Array} roles - ['owner', 'active', 'memo']
* @memberof AccountLogin
*/


AccountLogin.prototype.setRoles = function setRoles(roles) {
this.set('roles', roles);
};

/**
* Call this function to generate Peerplays user account keys.
*
* @param {String} accountName - The users' account name (username).
* @param {String} password - The users' password.
* @param {Array} roles - ['owner', 'active', 'memo']
* @param {String} prefix - Optional. The core token symbol (1.3.0 = 'PPY')
* @returns {Object} - Keys object: `{privKeys, pubKeys}`
* @memberof AccountLogin
*/


AccountLogin.prototype.generateKeys = function generateKeys(accountName, password, roles, prefix) {
if (!accountName || !password) {
throw new Error('Account name or password required');
Expand All @@ -64,12 +92,32 @@ var AccountLogin = function () {
return { privKeys: privKeys, pubKeys: pubKeys };
};

/**
* Accepts an account name {string}, password {string}, and an auths object. We loop over the
* provided auths whichcontains the keys associated with the account we are working with.
*
* We verify that the keys provided (which are pulled from the blockchain prior) match up with
* keys we generate with the provided account name and password.
*
* This function is dependant upon the roles array being specified in the correct order:
* 1. owner
* 2. active
* 3. memo
*
* @param {Object} {accountName, password, auths} - string, string, array
* @param {String} prefix - Optional. The core token symbol (1.3.0 = 'PPY')
* @returns {Boolean}
* @memberof AccountLogin
*/


AccountLogin.prototype.checkKeys = function checkKeys(_ref) {
var _this = this;

var accountName = _ref.accountName,
password = _ref.password,
auths = _ref.auths;
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'PPY';

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

var _generateKeys = _this.generateKeys(accountName, password, [role]),
var _generateKeys = _this.generateKeys(accountName, password, [role], prefix),
privKeys = _generateKeys.privKeys,
pubKeys = _generateKeys.pubKeys;

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

/**
* Call this function and provide a valid transaction object to sign it with
* the users' Active key.
* Pre-requisite is that AccountLogin.js (`Login`) has had its roles set and
* the users' keys were generated with AccountLogin.js (`Login`)
*
* @param {Object} tr - Transaction object built via TransactionBuilder.js
* @returns {Object} tr - Transaction object that was passed in but signed.
* @memberof AccountLogin
*/


AccountLogin.prototype.signTransaction = function signTransaction(tr) {
var _this2 = this;

Expand Down
74 changes: 74 additions & 0 deletions dist/chain/src/ChainStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ var op_history = parseInt(object_type.operation_history, 10);
var limit_order = parseInt(object_type.limit_order, 10);
var call_order = parseInt(object_type.call_order, 10);
var proposal = parseInt(object_type.proposal, 10);
var balance_type = parseInt(object_type.balance, 10);
var vesting_balance_type = parseInt(object_type.vesting_balance, 10);
var witness_object_type = parseInt(object_type.witness, 10);
var worker_object_type = parseInt(object_type.worker, 10);
var committee_member_object_type = parseInt(object_type.committee_member, 10);
Expand All @@ -58,6 +60,7 @@ var account_transaction_history_prefix = '2.' + parseInt(impl_object_type.accoun
var asset_dynamic_data_prefix = '2.' + parseInt(impl_object_type.asset_dynamic_data, 10) + '.';
var bitasset_data_prefix = '2.' + parseInt(impl_object_type.asset_bitasset_data, 10) + '.';
var block_summary_prefix = '2.' + parseInt(impl_object_type.block_summary, 10) + '.';
var vesting_balance_prefix = '1.' + vesting_balance_type + '.';
var witness_prefix = '1.' + witness_object_type + '.';
var worker_prefix = '1.' + worker_object_type + '.';
var committee_prefix = '1.' + committee_member_object_type + '.';
Expand Down Expand Up @@ -131,6 +134,8 @@ var ChainStore = function () {
this.recent_blocks_by_id = _immutable2.default.Map();
this.last_processed_block = null;
this.simple_objects_by_id = _immutable2.default.Map();
this.lotteries_ids = _immutable2.default.List();
this.lotteries_ids_initialized = false;

clearTimeout(this.timeout);

Expand Down Expand Up @@ -1791,6 +1796,15 @@ var ChainStore = function () {
current = current.set('bitasset', bad);
this.objects_by_id = this.objects_by_id.set(object.id, current);
}

//lottery asset
if (object.lottery_options && this.lotteries_ids.findIndex(function (item) {
return item === object.id;
}) === -1) {
this.lotteries_ids = this.lotteries_ids.push(object.id).sortBy(function (item) {
return -parseInt(item.split('.')[2]);
});
}
} else if (objectSpace === asset_dynamic_data_prefix) {
// ASSET DYNAMIC DATA OBJECT
var asset_id = current.get('asset_id');
Expand Down Expand Up @@ -2197,6 +2211,66 @@ var ChainStore = function () {
return this.recent_operations;
};

ChainStore.prototype.getLastIdLottery = function getLastIdLottery() {
return _ws.Apis.instance().db_api().exec('get_lotteries', ['1.3.0', 1, '1.3.0']).then(function (lotteries) {

if (!lotteries || !lotteries.length) {
return '1.3.0';
}

return lotteries[0]['id'];
});
};

ChainStore.prototype.getAllLotteriesIds = function getAllLotteriesIds() {
var _this27 = this;

return new Promise(function (resolve) {

if (_this27.lotteries_ids_initialized) {
return resolve(_this27.lotteries_ids);
}

_this27.getLastIdLottery().then(function (lastId) {

var self = _this27;

var fetchLotteries = function fetchLotteries(prevId, limit, nextId, isLastRequest) {

if (isLastRequest) {
self.lotteries_ids_initialized = true;
return resolve(self.lotteries_ids);
}

return _ws.Apis.instance().db_api().exec('get_lotteries', [prevId, limit, nextId]).then(function (lotteries) {

if (!lotteries.length) {
self.lotteries_ids_initialized = true;
return resolve(self.lotteries_ids);
}

lotteries.forEach(function (lotteryAsset) {
self._updateObject(lotteryAsset, false, false);
});

if (lotteries.length < limit) {
self.lotteries_ids_initialized = true;
return resolve(self.lotteries_ids);
}

var firstId = lotteries[0]['id'],
firstIdNum = parseInt(firstId.split('.')[2]),
nextNumId = firstIdNum - limit;

return fetchLotteries('1.3.0', limit, '1.3.' + Math.max(nextNumId, 0), firstIdNum - limit < 0 || !nextNumId);
});
};

fetchLotteries('1.3.0', 100, lastId, false);
});
});
};

return ChainStore;
}();

Expand Down
47 changes: 40 additions & 7 deletions dist/chain/src/ChainTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ var object_type = {
betting_market_rules: 23,
betting_market_group: 24,
betting_market: 25,
bet: 26
bet: 26,
custom_permission: 27,
custom_account_authority: 28,
offer: 29,
nft_metadata: 30,
nft: 31
};

var impl_object_type = {
Expand All @@ -55,11 +60,14 @@ var impl_object_type = {
special_authority: 14,
buyback: 15,
fba_accumulator: 16,
betting_market_position: 17,
global_betting_statistics: 18,
asset_dividend_data: 19,
pending_dividend_payout_balance_for_holder: 20,
distributed_dividend_balance_data: 21
asset_dividend_data: 17,
pending_dividend_payout_balance_for_holder: 18,
distributed_dividend_balance_data: 19,
betting_market_position: 20,
global_betting_statistics: 21,
lottery_balance: 22,
sweeps_vesting_balance: 23,
offer_history: 24
};

var vote_type = {
Expand Down Expand Up @@ -141,7 +149,32 @@ var operations = {
bet_canceled: 69,
betting_market_group_update: 70,
betting_market_update: 71,
event_update_status: 72
event_update_status: 72,
sport_delete: 73,
event_group_delete: 74,
affiliate_payout: 75,
affiliate_referral_payout: 76,
lottery_asset_create: 77,
ticket_purchase: 78,
lottery_reward: 79,
lottery_end: 80,
sweeps_vesting_claim: 81,
custom_permission_create: 82,
custom_permission_update: 83,
custom_permission_delete: 84,
custom_account_authority_create: 85,
custom_account_authority_update: 86,
custom_account_authority_delete: 87,
offer: 88,
bid: 89,
cancel_offer: 90,
finalize_offer: 91,
nft_metadata_create: 92,
nft_metadata_update: 93,
nft_mint: 94,
nft_safe_transfer_from: 95,
nft_approve: 96,
nft_set_approval_for_all: 97
};

var ChainTypes = {
Expand Down
4 changes: 2 additions & 2 deletions dist/ecc/src/PublicKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ var PublicKey = function () {
};

/**
@arg {string} public_key - like GPHXyz...
@arg {string} address_prefix - like GPH
@arg {string} public_key - like PPYXyz...
@arg {string} address_prefix - like PPY
@throws {Error} if public key is invalid
@return PublicKey
*/
Expand Down
Loading

0 comments on commit 0158979

Please sign in to comment.