Skip to content

Commit

Permalink
[email protected] migration
Browse files Browse the repository at this point in the history
  • Loading branch information
doomdabidon authored Oct 26, 2020
1 parent 0bc3538 commit 373d880
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 53 deletions.
2 changes: 1 addition & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ try {
head_block_id:String,
time:String,
next_maintenance_time:String,
last_budget_time:String,
last_maintenance_time:String,
committee_budget:Number,
accounts_registered_this_interval:Number,
recently_missed_count:Number,
Expand Down
11 changes: 5 additions & 6 deletions docs/Constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,11 @@ console.log(constants.OPERATIONS_IDS); // operation id
SIDECHAIN_BTC_WITHDRAW = 62,
SIDECHAIN_BTC_AGGREGATE = 63,
SIDECHAIN_BTC_APPROVE_AGGREGATE = 64,
SIDECHAIN_BTC_BLOCK_PROCESS = 65;
BLOCK_REWARD = 66,// VIRTUAL
EVM_ADDRESS_REGISTER = 67,
DID_CREATE_OPERATION = 68,
DID_UPDATE_OPERATION = 69,
DID_DELETE_OPERATION = 70,
BLOCK_REWARD = 65,// VIRTUAL
EVM_ADDRESS_REGISTER = 66,
DID_CREATE_OPERATION = 67,
DID_UPDATE_OPERATION = 68,
DID_DELETE_OPERATION = 69,
}
*/
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "echojs-lib",
"version": "1.12.3-rc.0",
"version": "1.12.3-rc.1",
"description": "Pure JavaScript ECHO library for node.js",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
Expand Down
11 changes: 5 additions & 6 deletions src/constants/operations-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ export const SIDECHAIN_BTC_DEPOSIT = 61;
export const SIDECHAIN_BTC_WITHDRAW = 62;
export const SIDECHAIN_BTC_AGGREGATE = 63;
export const SIDECHAIN_BTC_APPROVE_AGGREGATE = 64;
export const SIDECHAIN_BTC_BLOCK_PROCESS = 65;
export const BLOCK_REWARD = 66; // VIRTUAL
export const EVM_ADDRESS_REGISTER = 67;
export const DID_CREATE_OPERATION = 68;
export const DID_UPDATE_OPERATION = 69;
export const DID_DELETE_OPERATION = 70;
export const BLOCK_REWARD = 65; // VIRTUAL
export const EVM_ADDRESS_REGISTER = 66;
export const DID_CREATE_OPERATION = 67;
export const DID_UPDATE_OPERATION = 68;
export const DID_DELETE_OPERATION = 69;
70 changes: 66 additions & 4 deletions src/echo/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import { PublicKey } from '../crypto';
import { CHAIN_API } from '../constants/ws-constants';
import { toRawContractLogsFilterOptions } from '../utils/converters';

const { operationHistoryId } = chain.ids;

/** @typedef {import("bignumber.js").default} BigNumber */
/** @typedef {import("../../types/interfaces/vm/types").Log} Log */
/** @typedef {import("./ws-api/database-api").SidechainType} SidechainType */
Expand Down Expand Up @@ -261,7 +263,7 @@ import { toRawContractLogsFilterOptions } from '../utils/converters';
* head_block_id:String,
* time:String,
* next_maintenance_time:String,
* last_budget_time:String,
* last_maintenance_time:String,
* committee_budget:Number,
* accounts_registered_this_interval:Number,
* recently_missed_count:Number,
Expand Down Expand Up @@ -1052,8 +1054,50 @@ class API {
return this.engine.database.getGitRevision();
}

async getIncentivesInfo() {
return this.engine.database.getIncentivesInfo();
/**
* @method getCurrentIncentivesInfo
* @returns {Promise<unknown>}
*/
async getCurrentIncentivesInfo() {
return this.engine.database.getCurrentIncentivesInfo();
}

/**
* @method getIncentivesInfo
* @param {number} blockStart
* @param {number} blockEnd
* @returns {Promise<unknown>}
*/
async getIncentivesInfo(blockStart, blockEnd) {
if (!isNumber(blockStart)) {
throw new Error('Invalid start block number');
}
if (!isNumber(blockEnd)) {
throw new Error('Invalid end block number');
}
if (blockEnd <= blockStart) {
throw new Error('Block start should be less then block end');
}

return this.engine.database.getIncentivesInfo(blockStart, blockEnd);
}

/**
* @method getAccountAddressByLabel
* @param {string} accountNameOrId
* @param {string} label
* @returns {Promise<unknown>}
*/
async getAccountAddressByLabel(accountNameOrId, label) {
if (!(isAccountId(accountNameOrId) || isAccountName(accountNameOrId))) {
throw new Error('AccountNameOrId is invalid');
}

if (!isString(label)) {
throw new Error('Label is invalid');
}

return this.engine.database.getAccountAddressByLabel(accountNameOrId, label);
}

/**
Expand Down Expand Up @@ -2307,6 +2351,24 @@ class API {
return this.engine.history.getRelativeContractHistory(contract, stop, limit, start);
}

/**
* @param {String} address
* @param {Integer_t["uint64"]["__TOutput__"]} stop
* @param {Integer_t["uint32"]["__TOutput__"]} limit
* @param {Integer_t["uint64"]["__TOutput__"]} start
* @returns {Promise}
*/
async getAccountAddressHistory(_address, options = {}) {
const address = chain.ripemd160.toRaw(_address);
const stop = options.stop === undefined ?
API_CONFIG.STOP_OPERATION_HISTORY_ID : operationHistoryId.toRaw(options.stop);
const limit = options.limit === undefined ? 100 : basic.integers.uint32.toRaw(options.limit);
const start = options.start === undefined ?
API_CONFIG.START_OPERATION_HISTORY_ID : operationHistoryId.toRaw(options.start);
if (limit > 100) throw new Error('Limit is greater than 100');
return this.engine.history.getAccountAddressHistory(address, start, stop, limit);
}

/**
* @method getFullContract
* Get contract info.
Expand Down Expand Up @@ -2540,7 +2602,7 @@ class API {
* @param {Number} limit
* @return {*}
*/
getAccountAddresses(accountId, from, limit) {
async getAccountAddresses(accountId, from, limit) {
if (!isAccountId(accountId)) return Promise.reject(new Error('Account id is invalid'));

if (!isNumber(from)) {
Expand Down
28 changes: 26 additions & 2 deletions src/echo/apis/database-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,37 @@ class DatabaseAPI extends BaseEchoApi {
return this.exec('get_git_revision', []);
}

/**
* @method getCurrentIncentivesInfo
*
* @return {Promise}
*/
getCurrentIncentivesInfo() {
return this.exec('get_current_incentives_info', []);
}

/**
* @method getIncentivesInfo
* @param {Number} blockStart
* @param {Number} blockEnd
*
*
* @return {Promise}
*/
getIncentivesInfo(blockStart, blockEnd) {
return this.exec('get_incentives_info', [blockStart, blockEnd]);
}

/**
* @method getAccountAddressByLabel
* @param {String} accountNameOrId
* @param {String} label
*
*
* @return {Promise}
*/
getIncentivesInfo() {
return this.exec('get_incentives_info', []);
getAccountAddressByLabel(accountNameOrId, label) {
return this.exec('get_account_address_by_label', [accountNameOrId, label]);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/echo/apis/history-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ class HistoryAPI extends BaseEchoApi {
return this.exec('get_relative_contract_history', [contract, stop, limit, start]);
}

/**
* @param {String} address
* @param {Integer_t["uint64"]["__TOutput__"]} stop
* @param {Integer_t["uint32"]["__TOutput__"]} limit
* @param {Integer_t["uint64"]["__TOutput__"]} start
* @returns {Promise}
*/
getAccountAddressHistory(address, start, stop, limit) {
return this.exec('get_account_address_history', [address, start, stop, limit]);
}

}

export default HistoryAPI;
95 changes: 89 additions & 6 deletions src/echo/apis/wallet-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import {
isEthereumAddress,
isRipemd160,
isUInt32,
isNumber,
isString,
isOperationHistoryId,
} from '../../utils/validators';

const { ethAddress, accountListing } = serializers.protocol;
Expand All @@ -37,7 +40,7 @@ const {
const { options, bitassetOptions } = serializers.protocol.asset;
const { price, authority } = serializers.protocol;
const { config } = serializers.plugins.echorand;
const { anyObjectId } = serializers.chain.ids;
const { anyObjectId, operationHistoryId } = serializers.chain.ids;

const {
uint64,
Expand Down Expand Up @@ -1066,19 +1069,101 @@ class WalletAPI {

/**
* Get addresses of specified account
* @param {string} idOfAccount ID of the account
* @param {string} accountNameOrId ID of the account
* @param {number} startFrom number of block to start retrieve from
* @param {number} limit maximum number of addresses to return
* @returns {Promise<any[]>} Addresses owned by account in specified ids interval
*/
getAccountAddresses(idOfAccount, startFrom, limit) {
async getAccountAddresses(accountNameOrId, startFrom, limit) {
if (!isAccountIdOrName(accountNameOrId)) {
throw new Error('Accounts id or name should be string and valid');
}
return this.wsProvider.call([0, 'get_account_addresses', [
accountId.toRaw(idOfAccount),
string.toRaw(accountNameOrId),
uint64.toRaw(startFrom),
uint64.toRaw(limit),
]]);
}

async getAccountAddressByLabel(accountNameOrId, label) {
if (!(isAccountId(accountNameOrId) || isAccountName(accountNameOrId))) {
throw new Error('AccountNameOrId is invalid');
}

if (!isString(label)) {
throw new Error('Label is invalid');
}

return this.wsProvider.call([0, 'get_account_address_by_label', [
string.toRaw(accountNameOrId),
string.toRaw(label),
]]);
}

/**
* @param {String} address
* @param {Integer_t["uint64"]["__TOutput__"]} stop
* @param {Integer_t["uint32"]["__TOutput__"]} limit
* @param {Integer_t["uint64"]["__TOutput__"]} start
* @returns {Promise}
*/
async getAccountAddressHistory(_address, _start, _stop, _limit) {
const address = serializers.chain.ripemd160.toRaw(_address);
const stop = _stop === undefined ? API_CONFIG.STOP_OPERATION_HISTORY_ID : operationHistoryId.toRaw(_stop);
const limit = _limit === undefined ? 100 : serializers.basic.integers.uint32.toRaw(_limit);
const start = _start === undefined ? API_CONFIG.START_OPERATION_HISTORY_ID : operationHistoryId.toRaw(_start);
if (limit > 100) throw new Error('Limit is greater than 100');

return this.wsProvider.call([0, 'get_account_address_history', [
address, start, stop, limit,
]]);
}

async getAccountHistoryOperations(
idOfAccount,
operationId,
start = API_CONFIG.START_OPERATION_HISTORY_ID,
stop = API_CONFIG.STOP_OPERATION_HISTORY_ID,
limit = API_CONFIG.ACCOUNT_HISTORY_OPERATIONS_DEFAULT_LIMIT,
) {
const operationNumber = uint64.toRaw(operationId);
if (!isAccountId(idOfAccount)) throw new Error('Account is invalid');
if (!isOperationHistoryId(start)) throw new Error('Start parameter is invalid');
if (!isOperationHistoryId(stop)) throw new Error('Stop parameter is invalid');
if (!isUInt64(limit) || limit > API_CONFIG.ACCOUNT_HISTORY_OPERATIONS_MAX_LIMIT) {
throw new Error(`Limit should be capped at ${API_CONFIG.ACCOUNT_HISTORY_OPERATIONS_MAX_LIMIT}`);
}

return this.wsProvider.call([0, 'get_account_history_operations', [
accountId.toRaw(idOfAccount),
operationNumber,
anyObjectId.toRaw(start),
anyObjectId.toRaw(stop),
uint32.toRaw(limit),
]]);
}

getCurrentIncentivesInfo() {
return this.wsProvider.call([0, 'get_current_incentives_info', []]);
}

getIncentivesInfo(blockStart, blockEnd) {
if (!isNumber(blockStart)) {
throw new Error('Invalid start block number');
}
if (!isNumber(blockEnd)) {
throw new Error('Invalid end block number');
}
if (blockEnd < blockStart) {
throw new Error('Block start should be equal or more then block end');
}

return this.wsProvider.call([0, 'get_incentives_info', [
uint32.toRaw(blockStart),
uint32.toRaw(blockEnd),
]]);
}

/**
* Get owner of specified address.
* @param {string} address address in form of ripemd160 hash
Expand Down Expand Up @@ -1559,8 +1644,6 @@ class WalletAPI {

getGitVersion() { return this.wsProvider.call([0, 'get_git_revision', []]); }

getIncentivesInfo() { return this.wsProvider.call([0, 'get_incentives_info', []]); }

/**
* Returns the blockchain object corresponding to the given id.
* This generic function can be used to retrieve any object from the blockchain that is assigned an ID.
Expand Down
4 changes: 4 additions & 0 deletions src/serializers/chain/id/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const committeeMemberId = new ObjectIdSerializer(
PROTOCOL_OBJECT_TYPE_ID.COMMITTEE_MEMBER,
);
export const proposalId = new ObjectIdSerializer(RESERVED_SPACE_ID.PROTOCOL, PROTOCOL_OBJECT_TYPE_ID.PROPOSAL);
export const operationHistoryId = new ObjectIdSerializer(
RESERVED_SPACE_ID.PROTOCOL,
PROTOCOL_OBJECT_TYPE_ID.OPERATION_HISTORY,
);
export const vestingBalanceId = new ObjectIdSerializer(
RESERVED_SPACE_ID.PROTOCOL,
PROTOCOL_OBJECT_TYPE_ID.VESTING_BALANCE,
Expand Down
1 change: 0 additions & 1 deletion src/serializers/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const operationProps = {
[OPERATIONS_IDS.SIDECHAIN_BTC_WITHDRAW]: protocol.sidechain.btc.withdraw,
[OPERATIONS_IDS.SIDECHAIN_BTC_AGGREGATE]: protocol.sidechain.btc.aggregate,
[OPERATIONS_IDS.SIDECHAIN_BTC_APPROVE_AGGREGATE]: protocol.sidechain.btc.approveAggregate,
[OPERATIONS_IDS.SIDECHAIN_BTC_BLOCK_PROCESS]: protocol.sidechain.btc.blockProcess,
[OPERATIONS_IDS.BLOCK_REWARD]: protocol.blockReward,
[OPERATIONS_IDS.EVM_ADDRESS_REGISTER]: protocol.evmAddress,
[OPERATIONS_IDS.DID_CREATE_OPERATION]: protocol.did.create,
Expand Down
1 change: 0 additions & 1 deletion src/serializers/protocol/fee_parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ const feeParametersSerializer = staticVariant({
[OPERATIONS_IDS.SIDECHAIN_BTC_WITHDRAW]: defaultFeeParametersSerializer,
[OPERATIONS_IDS.SIDECHAIN_BTC_AGGREGATE]: defaultFeeParametersSerializer,
[OPERATIONS_IDS.SIDECHAIN_BTC_APPROVE_AGGREGATE]: defaultFeeParametersSerializer,
[OPERATIONS_IDS.SIDECHAIN_BTC_BLOCK_PROCESS]: defaultFeeParametersSerializer,
[OPERATIONS_IDS.BLOCK_REWARD]: defaultFeeParametersSerializer,
[OPERATIONS_IDS.EVM_ADDRESS_REGISTER]: defaultFeeParametersSerializer,
[OPERATIONS_IDS.DID_CREATE_OPERATION]: defaultFeeParametersSerializer,
Expand Down
9 changes: 2 additions & 7 deletions src/serializers/protocol/sidechain/btc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { btcTransactionDetailsSerializer } from '../../chain/sidechain/btc';
import { struct, set, map, optional } from '../../collections';
import { string as stringSerializer, integers } from '../../basic';
import btcPublicKey from '../btcPublicKey';
import { uint8, uint32, uint64 } from '../../basic/integers';
import { uint8, uint32 } from '../../basic/integers';

export const sidechainBtcCreateAddressOperationPropsSerializer = struct({
fee: asset,
Expand Down Expand Up @@ -74,12 +74,7 @@ export const sidechainBtcApproveAggregateOperationPropsSerializer = struct({
fee: asset,
committee_member_id: accountId,
transaction_id: sha256,
btc_block_number: uint32,
extensions,
});

export const sidechainBtcBlockProcessOperationPropsSerializer = struct({
fee: asset,
committee_member_id: accountId,
block_number: uint64,
extensions,
});
Loading

0 comments on commit 373d880

Please sign in to comment.