hive-keychain-commons
Version:
Platform-agnostic functions used in Hive Keychain mobile and extensions
119 lines (118 loc) • 3.64 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HistoryFiltersUtils = exports.makeBitMaskFilter = void 0;
const jsbi_1 = __importDefault(require("jsbi"));
const operationOrders = {
vote: 0,
// tslint:disable-next-line: object-literal-sort-keys
comment: 1,
transfer: 2,
transfer_to_vesting: 3,
withdraw_vesting: 4,
limit_order_create: 5,
limit_order_cancel: 6,
feed_publish: 7,
convert: 8,
account_create: 9,
account_update: 10,
witness_update: 11,
account_witness_vote: 12,
account_witness_proxy: 13,
pow: 14,
custom: 15,
report_over_production: 16,
delete_comment: 17,
custom_json: 18,
comment_options: 19,
set_withdraw_vesting_route: 20,
limit_order_create2: 21,
claim_account: 22,
create_claimed_account: 23,
request_account_recovery: 24,
recover_account: 25,
change_recovery_account: 26,
escrow_transfer: 27,
escrow_dispute: 28,
escrow_release: 29,
pow2: 30,
escrow_approve: 31,
transfer_to_savings: 32,
transfer_from_savings: 33,
cancel_transfer_from_savings: 34,
custom_binary: 35,
decline_voting_rights: 36,
reset_account: 37,
set_reset_account: 38,
claim_reward_balance: 39,
delegate_vesting_shares: 40,
account_create_with_delegation: 41,
witness_set_properties: 42,
account_update2: 43,
create_proposal: 44,
update_proposal_votes: 45,
remove_proposal: 46,
update_proposal: 47,
collateralized_convert: 48,
recurrent_transfer: 49,
// virtual ops
fill_convert_request: 50,
author_reward: 51,
curation_reward: 52,
comment_reward: 53,
liquidity_reward: 54,
interest: 55,
fill_vesting_withdraw: 56,
fill_order: 57,
shutdown_witness: 58,
fill_transfer_from_savings: 59,
hardfork: 60,
comment_payout_update: 61,
return_vesting_delegation: 62,
comment_benefactor_reward: 63,
producer_reward: 64,
clear_null_account_balance: 65,
proposal_pay: 66,
sps_fund: 67,
hardfork_hive: 68,
hardfork_hive_restore: 69,
delayed_voting: 70,
consolidate_treasury_balance: 71,
effective_comment_vote: 72,
ineffective_delete_comment: 73,
sps_convert: 74,
expired_account_notification: 75,
changed_recovery_account: 76,
transfer_to_vesting_completed: 77,
pow_reward: 78,
vesting_shares_split: 79,
account_created: 80,
fill_collateralized_convert_request: 81,
system_warning: 82,
fill_recurrent_transfer: 83,
failed_recurrent_transfer: 84,
};
function makeBitMaskFilter(allowedOperations) {
const ops = allowedOperations
.reduce(redFunction, [jsbi_1.default.BigInt(0), jsbi_1.default.BigInt(0)])
.map((value) => jsbi_1.default.notEqual(value, jsbi_1.default.BigInt(0)) ? value.toString() : null);
return ops;
}
exports.makeBitMaskFilter = makeBitMaskFilter;
const redFunction = ([low, high], allowedOperation) => {
if (allowedOperation < 64) {
return [
jsbi_1.default.bitwiseOr(low, jsbi_1.default.leftShift(jsbi_1.default.BigInt(1), jsbi_1.default.BigInt(allowedOperation))),
high,
];
}
else {
return [
low,
jsbi_1.default.bitwiseOr(high, jsbi_1.default.leftShift(jsbi_1.default.BigInt(1), jsbi_1.default.BigInt(allowedOperation - 64))),
];
}
};
exports.HistoryFiltersUtils = { operationOrders, makeBitMaskFilter };