Skip to content

Commit

Permalink
Merge pull request #160 from echoprotocol/merge_1.10_and_echo_node_17-18
Browse files Browse the repository at this point in the history
merge echo1.10 && echo0.17-0.18
  • Loading branch information
AlinaLoz authored Apr 2, 2020
2 parents 32620d2 + 8fad8f4 commit 615ecbd
Show file tree
Hide file tree
Showing 69 changed files with 1,126 additions and 397 deletions.
6 changes: 3 additions & 3 deletions .test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "2"

services:
echo:
image: echoprotocol/echo:0.17.1-rc.5
image: echoprotocol/echo:0.18.0-rc.7
command:
--start-echorand
--account-info="[\"1.2.6\", \"5KkYp8qdQBaRmLqLz8WVrGjzkt7E13qVcr7cpdLowgJ1mjRyDx2\"]"
Expand All @@ -24,11 +24,11 @@ services:
container_name: echo

echo-wallet:
image: echoprotocol/echo-wallet:0.17.1-rc.5
image: echoprotocol/echo-wallet:0.18.0-rc.7
container_name: echo-wallet
command:
-s ws://echo:6311
--chain-id="8cc5ced88147e2b6bef07d0c016274fb3dca8db8d1f20f1d15b5e34fa80cb89f"
--chain-id="ae55e9cc332c46bdc8d4eac06e6e909ca51ad074150ce42775ee90345fdeff0e"
--wallet-file="/echo/walletdata/wallet.json"
--history-file="/echo/walletdata/history"
-r 0.0.0.0:6312
Expand Down
4 changes: 2 additions & 2 deletions .test/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
"eth_update_addr_method": { "method": "7ff203ab", "gas": 1000000 },
"eth_withdraw_token_method": { "method": "1c69c0e2", "gas": 1000000 },
"eth_collect_tokens_method": { "method": "5940a240", "gas": 1000000 },
"eth_update_contract_address": { "method": "3659cfe6", "gas": 1000000 },
"eth_committee_updated_topic": "514bf7702a7d2aca90dcf3d947158aad29563a17c1dbdc76d2eae84c22420142",
"eth_gen_address_topic": "1855f12530a368418f19b2b15227f19225915b8113c7e17d4c276e2a10225039",
"eth_deposit_topic": "77227a376c41a7533c952ebde8d7b44ee36c7a6cec0d3448f1a1e4231398356f",
Expand Down Expand Up @@ -217,6 +218,5 @@
"eth_address": "298915A83Bd8a0D536aDBe300F12cA1e4388C3BA",
"btc_public_key": "02c16e97132e72738c9c0163656348cd1be03521de17efeb07e496e742ac84512e"
}],
"initial_chain_id": "aa34045518f1469a28fa4578240d5f039afa9959c0b95ce3b39674efa691fb21",
"immutable_parameters": { "min_committee_member_count": 5 }
"initial_chain_id": "aa34045518f1469a28fa4578240d5f039afa9959c0b95ce3b39674efa691fb21"
}
15 changes: 6 additions & 9 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -988,9 +988,6 @@ try {
{
id:String,
chain_id:String,
immutable_parameters:{
min_committee_member_count:Number
}
}
```

Expand Down Expand Up @@ -1039,6 +1036,7 @@ try {
eth_gen_address_method:{method:String,gas:Number},
eth_withdraw_method:{method:String,gas:Number},
eth_update_addr_method:{method:String,gas:Number},
eth_update_contract_address:{method:String,gas:Number},
eth_withdraw_token_method:{method:String,gas:Number},
eth_collect_tokens_method:{method:String,gas:Number},
eth_committee_updated_topic:String,
Expand All @@ -1048,14 +1046,13 @@ try {
erc20_deposit_topic:String,
erc20_withdraw_topic:String,
ETH_asset_id:String,
waiting_eth_blocks:Number,
fines:{generate_eth_address:Number},
waiting_blocks:Number,
BTC_asset_id:String,
waiting_btc_blocks:Number,
fines:{generate_eth_address:Number|String},
gas_price:Number|String,
satoshis_per_byte:Number,
echo_blocks_per_aggregation:Number,
gas_price:String,
coefficient_waiting_blocks:Number,
btc_deposit_withdrawal_min:Number|String,
btc_deposit_withdrawal_fee:Number|String,
},
gas_price:{
price:Number|String,
Expand Down
15 changes: 8 additions & 7 deletions docs/Serializers.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ Available protocol object id serializers:
* `vestingBalanceId`
* `balanceId`
* `contractId`
* `depositId`
* `withdrawId`
* `ethDepositId`
* `ethWithdrawId`
* `erc20TokenId`

Example:
Expand Down Expand Up @@ -434,6 +434,7 @@ console.log(s.serialize(input).toString('hex'));
|eth_gen_address_method|[`eth method`](#eth-method)|
|eth_withdraw_method|[`eth method`](#eth-method)|
|eth_update_addr_method|[`eth method`](#eth-method)|
|eth_update_contract_address|[`eth method`](#eth-method)|
|eth_withdraw_token_method|[`eth method`](#eth-method)|
|eth_collect_tokens_method|[`eth method`](#eth-method)|
|eth_committee_updated_topic|[`eth topic`](#eth-topic)|
Expand All @@ -443,13 +444,13 @@ console.log(s.serialize(input).toString('hex'));
|erc20_deposit_topic|[`eth topic`](#eth-topic)|
|erc20_withdraw_topic|[`eth topic`](#eth-topic)|
|ETH_asset_id|[`assetId`](#protocol-object-id)|
|waiting_eth_blocks|[`uint32`](#integers)|
|fines|[`fines`](#fines)|
|waiting_blocks|[`uint32`](#integers)|
|BTC_asset_id|[`assetId`](#protocol-object-id)|
|waiting_btc_blocks|[`uint32`](#integers)|
|fines|[`fines`](#fines)|: typeof sidechainFinesSerializer,
|gas_price|[`uint64`](#integers)|
|satoshis_per_byte|[`uint32`](#integers)|
|echo_blocks_per_aggregation|[`uint32`](#integers)|
|coefficient_waiting_blocks|[`uint32`](#integers)|
|btc_deposit_withdrawal_min|[`uint64`](#integers)|
|btc_deposit_withdrawal_fee|[`uint64`](#integers)|

#### ERC20 config

Expand Down
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.0-rc.0",
"version": "1.12.0-rc.1",
"description": "Pure JavaScript ECHO library for node.js",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/constants/chain-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const ADDRESS_PREFIX = 'ECHO';
export const EXPIRE_IN_SECONDS = 15;
export const EXPIRE_IN_SECONDS_PROPOSAL = 24 * 60 * 60;
export const REVIEW_IN_SECONDS_COMMITTEE = 24 * 60 * 60;
export const CHAIN_ID_LENGTH = 64;

export const NETWORKS = {
ECHO_DEV: {
Expand Down
2 changes: 2 additions & 0 deletions src/constants/chain/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line import/prefer-default-export
export const ECHO_MAX_SHARE_SUPPLY = 1000000000000000;
4 changes: 4 additions & 0 deletions src/constants/chain/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as config from './config';

// eslint-disable-next-line import/prefer-default-export
export { config };
2 changes: 2 additions & 0 deletions src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import BigNumber from 'bignumber.js';

import * as API_CONFIG from './api-config';
import * as CACHE_MAPS from './cache-maps';
import * as chain from './chain';
import * as CHAIN_CONFIG from './chain-config';
import * as CHAIN_TYPES from './chain-types';
import * as PROTOCOL_OBJECT_TYPE_ID from './object-types';
Expand Down Expand Up @@ -35,6 +36,7 @@ export const DEFAULT_MIN_CACHE_CLEANING_TIME = 500;
/** @typedef {typeof OPERATIONS_IDS[keyof typeof OPERATIONS_IDS]} OperationId */

export {
chain,
OPERATIONS_IDS,
CACHE_MAPS,
CHAIN_TYPES,
Expand Down
4 changes: 2 additions & 2 deletions src/constants/object-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export const ETH_ADDRESS = 13;
export const SIDECHAIN_ETH_DEPOSIT = 14;
export const SIDECHAIN_ETH_WITHDRAW = 15;
export const ERC20_TOKEN = 16;
export const SIDECHAIN_ERC20_DEPOSIT_TOKEN = 17;
export const SIDECHAIN_ERC20_WITHDRAW_TOKEN = 18;
export const ERC20_DEPOSIT_TOKEN = 17;
export const ERC20_WITHDRAW_TOKEN = 18;
export const BTC_ADDRESS = 19;
export const BTC_INTERMEDIATE_DEPOSIT = 20;
export const BTC_DEPOSIT = 21;
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/ecdsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { validateUnsignedSafeInteger } from '../utils/validators';
*/
export function deterministicGenerateK(curve, hash, d, checkSig, nonce) {
if (nonce) hash = sha256(Buffer.concat([hash, Buffer.alloc(nonce)]));
// sanity check
// sanity transaction.js
if (hash.length !== 32) throw new Error('invalid sha256 hash length');
const x = d.toBuffer(32);
let k = Buffer.alloc(32);
Expand Down
77 changes: 51 additions & 26 deletions src/echo/api.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-continue,no-await-in-loop,camelcase,no-restricted-syntax */
import * as assert from 'assert';
import { ok } from 'assert';
import BigNumber from 'bignumber.js';
import { Map, List, fromJS } from 'immutable';

import BigNumber from 'bignumber.js';
import {
isNumber,
isArray,
Expand All @@ -27,21 +27,24 @@ import {
isOperationId,
isDynamicGlobalObjectId,
isBtcAddressId,
isUInt32,
isObject,
isInt64,
validateSidechainType,
validateSidechainType, isUInt32,
} from '../utils/validators';

import { solveRegistrationTask, validateRegistrationOptions } from '../utils/pow-solver';

/** @typedef {import('./ws-api').default} WSAPI */

import { ECHO_ASSET_ID, DYNAMIC_GLOBAL_OBJECT_ID, API_CONFIG, CACHE_MAPS } from '../constants';
import { transaction, signedTransaction, operation, basic } from '../serializers';
import { transaction, signedTransaction, operation, basic, chain } from '../serializers';
import { PublicKey } from '../crypto';
import { toRawContractLogsFilterOptions } from '../utils/converters';

/** @typedef {import("bignumber.js").default} BigNumber */
/** @typedef {import("../../types/interfaces/vm/types").Log} Log */
/** @typedef {import("./ws-api/database-api").SidechainType} SidechainType */
/** @typedef {typeof basic.integers["uint64"]["__TInput__"]} UInt64 */

/** @typedef {
* {
Expand Down Expand Up @@ -108,9 +111,6 @@ import { PublicKey } from '../crypto';
* {
* id:String,
* chain_id:String,
* immutable_parameters:{
* min_committee_member_count:Number
* }
* }
* } ChainProperties */

Expand Down Expand Up @@ -156,6 +156,7 @@ import { PublicKey } from '../crypto';
* eth_gen_address_method:{method:String,gas:Number},
* eth_withdraw_method:{method:String,gas:Number},
* eth_update_addr_method:{method:String,gas:Number},
* eth_update_contract_address:{method:String,gas:Number},
* eth_withdraw_token_method:{method:String,gas:Number},
* eth_collect_tokens_method:{method:String,gas:Number},
* eth_committee_updated_topic:String,
Expand All @@ -165,14 +166,13 @@ import { PublicKey } from '../crypto';
* erc20_deposit_topic:String,
* erc20_withdraw_topic:String,
* ETH_asset_id:String,
* waiting_eth_blocks:Number,
* fines:{generate_eth_address:Number},
* waiting_blocks:Number,
* BTC_asset_id:String,
* waiting_btc_blocks:Number,
* fines:{generate_eth_address:Number|String},
* gas_price:Number|String,
* satoshis_per_byte:Number,
* echo_blocks_per_aggregation:Number,
* gas_price:String,
* coefficient_waiting_blocks:Number,
* btc_deposit_withdrawal_min:Number|String,
* btc_deposit_withdrawal_fee:Number|String,
* },
* gas_price:{
* price:Number|String,
Expand Down Expand Up @@ -1943,13 +1943,13 @@ class API {
*/
async getContractLogs(opts = { }) {
if (opts.contracts !== undefined) {
ok(Array.isArray(opts.contracts), '"contracts" option is not an array');
for (const contractId of opts.contracts) ok(isContractId(contractId));
ok(Array.isArray(opts.contracts), 'contracts: vector is not an array');
for (const contractId of opts.contracts) ok(isContractId(contractId), 'invalid object type id');
}
/** @type {typeof opts["topics"]} */
let topics;
if (opts.topics !== undefined) {
ok(Array.isArray(opts.topics), '"topics" option is not an array');
ok(Array.isArray(opts.topics), '`topics` is not an array');
topics = new Array(opts.topics.length).fill(null);
for (let topicIndex = 0; topicIndex < opts.topics.length; topicIndex += 1) {
let topicVariants = opts.topics[topicIndex];
Expand Down Expand Up @@ -1983,6 +1983,24 @@ class API {
});
}

/**
* @param {(result: Log[]) => any} callback
* @param {ContractLogsFilterOptions_t} [opts]
* @returns {Promise<Log[]>}
*/
async subscribeContractLogs(callback, opts = {}) {
return this.wsApi.database.subscribeContractLogs((result) => {
assert.ok(Array.isArray(result));
assert.strictEqual(result.length, 1);
callback(result[0]);
}, toRawContractLogsFilterOptions(opts));
}

/** @param {UInt64} subscribeId */
async unsubscribeContractLogs(subscribeId) {
return this.wsApi.database.unsubscribeContractLogs(basic.integers.uint64.toRaw(subscribeId));
}

/**
* @method getContractResult
*
Expand Down Expand Up @@ -2301,6 +2319,22 @@ class API {
);
}

/**
* @param {typeof chain.ids["protocol"]["contractId"]["__TInput__"]} contract
* @param {Object} [options]
* @param {typeof basic.integers["uint64"]["__TInput__"]} [options.stop]
* @param {typeof basic.integers["uint32"]["__TInput__"]} [options.limit]
* @param {typeof basic.integers["uint64"]["__TInput__"]} [options.start]
*/
async getRelativeContractHistory(contract, options = {}) {
contract = chain.ids.protocol.contractId.toRaw(contract);
const stop = options.stop === undefined ? 0 : basic.integers.uint64.toRaw(options.stop);
const limit = options.limit === undefined ? 100 : basic.integers.uint32.toRaw(options.limit);
const start = options.stop === undefined ? 0 : basic.integers.uint64.toRaw(options.start);
if (limit > 100) throw new Error('Limit is greater than 100');
return this.wsApi.history.getRelativeContractHistory(contract, stop, limit, start);
}

/**
* @method getFullContract
* Get contract info.
Expand Down Expand Up @@ -2466,15 +2500,6 @@ class API {
return this.wsApi.database.getBalanceObjects(keys);
}

/**
* @method getBlockRewards
* @param {typeof uint32["__TInput__"]} blockNum
* @returns {Promise<unknown>}
*/
getBlockRewards(blockNum) {
return this.wsApi.database.getBlockRewards(basic.integers.uint32.toRaw(blockNum));
}

/**
*
* @param {Number} blockNum
Expand Down
Loading

0 comments on commit 615ecbd

Please sign in to comment.