Skip to content

Commit

Permalink
[email protected] migration
Browse files Browse the repository at this point in the history
  • Loading branch information
doomdabidon authored Nov 11, 2020
1 parent 373d880 commit f8e6381
Show file tree
Hide file tree
Showing 26 changed files with 229 additions and 42 deletions.
17 changes: 14 additions & 3 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ try {
<dd></dd>
<dt><a href="#getContractBalances">getContractBalances(contractId, force)</a> ⇒ <code>Promise.&lt;Object&gt;</code></dt>
<dd></dd>
<dt><a href="#getRecentTransactionById">getRecentTransactionById(transactionId)</a> ⇒ <code>Promise.&lt;*&gt;</code></dt>
<dt><a href="#getTransactionById">getTransactionById(transactionId)</a> ⇒ <code>Promise.&lt;*&gt;</code></dt>
<dd></dd>
<dt><a href="#getBtcStakeAddress">getBtcStakeAddress(accountNameOrId)</a> ⇒ <code>Promise.&lt;*&gt;</code></dt>
<dd></dd>
<dt><a href="#getFeePool">getFeePool(assetId)</a> ⇒ <code>Promise.&lt;BigNumber&gt;</code></dt>
<dd></dd>
Expand Down Expand Up @@ -702,15 +704,24 @@ try {
| contractId | <code>String</code> | [Id of the contract to retrieve] |
| force | <code>Boolean</code> | [If force equal to true then he will first see if you have this object in the cache] |

<a name="getRecentTransactionById"></a>
<a name="getTransactionById"></a>

## getRecentTransactionById(transactionId) ⇒ <code>Promise.&lt;\*&gt;</code>
## getTransactionById(transactionId) ⇒ <code>Promise.&lt;\*&gt;</code>
**Kind**: global function

| Param | Type | Description |
| --- | --- | --- |
| transactionId | <code>String</code> | [Id of the transaction to retrieve] |

<a name="getBtcStakeAddress"></a>

## getBtcStakeAddress(accountNameOrId) ⇒ <code>Promise.&lt;\*&gt;</code>
**Kind**: global function

| Param | Type | Description |
| --- | --- | --- |
| accountNameOrId | <code>String</code> | [Id or name of account] |

<a name="getFeePool"></a>

## getFeePool(assetId) ⇒ <code>Promise.&lt;BigNumber&gt;</code>
Expand Down
13 changes: 8 additions & 5 deletions docs/Constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,14 @@ console.log(constants.OPERATIONS_IDS); // operation id
SIDECHAIN_BTC_WITHDRAW = 62,
SIDECHAIN_BTC_AGGREGATE = 63,
SIDECHAIN_BTC_APPROVE_AGGREGATE = 64,
BLOCK_REWARD = 65,// VIRTUAL
EVM_ADDRESS_REGISTER = 66,
DID_CREATE_OPERATION = 67,
DID_UPDATE_OPERATION = 68,
DID_DELETE_OPERATION = 69,
SIDECHAIN_STAKE_ETH_UPDATE = 65,
SIDECHAIN_BTC_CREATE_STAKE_SCRIPT = 66,
SIDECHAIN_STAKE_BTC_UPDATE = 67,
BLOCK_REWARD = 68, // VIRTUAL
EVM_ADDRESS_REGISTER = 69,
DID_CREATE_OPERATION = 70,
DID_UPDATE_OPERATION = 71,
DID_DELETE_OPERATION = 72,
}
*/
```
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.1",
"version": "1.13.0",
"description": "Pure JavaScript ECHO library for node.js",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
Expand Down
9 changes: 5 additions & 4 deletions src/constants/object-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const BTC_INTERMEDIATE_DEPOSIT = 20;
export const BTC_DEPOSIT = 21;
export const BTC_WITHDRAW = 22;
export const BTC_AGGREGATING = 23;
export const BTC_BLOCK = 24;
export const EVM_ADDRESS = 25;
export const DID_OBJECT = 26;

export const EVM_ADDRESS = 24;
export const DID_OBJECT = 25;
export const STAKE_BTC_SCRIPT = 26;
export const STAKE_BTC_VOUT = 27;
export const STAKE_ETH_UPDATE = 28;
13 changes: 8 additions & 5 deletions src/constants/operations-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ 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 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;
export const SIDECHAIN_STAKE_ETH_UPDATE = 65;
export const SIDECHAIN_BTC_CREATE_STAKE_SCRIPT = 66;
export const SIDECHAIN_STAKE_BTC_UPDATE = 67;
export const BLOCK_REWARD = 68; // VIRTUAL
export const EVM_ADDRESS_REGISTER = 69;
export const DID_CREATE_OPERATION = 70;
export const DID_UPDATE_OPERATION = 71;
export const DID_DELETE_OPERATION = 72;
21 changes: 18 additions & 3 deletions src/echo/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2133,16 +2133,31 @@ class API {
}

/**
* @method getRecentTransactionById
* @method getTransactionById
*
* @param {String} transactionId
*
* @return {Promise.<*>}
*/
async getRecentTransactionById(transactionId) {
async getTransactionById(transactionId) {
if (!isRipemd160(transactionId)) throw new Error('Transaction id should be a 20 bytes hex string');

return this.engine.database.getRecentTransactionById(transactionId);
return this.engine.database.getTransactionById(transactionId);
}

/**
* @method getBtcStakeAddress
*
* @param {String} account
*
* @return {Promise.<*>}
*/
async getBtcStakeAddress(accountNameOrId) {
if (!(isAccountId(accountNameOrId) || isAccountName(accountNameOrId))) {
throw new Error('AccountNameOrId is invalid');
}

return this.engine.database.getBtcStakeAddress(accountNameOrId);
}

/**
Expand Down
17 changes: 14 additions & 3 deletions src/echo/apis/database-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,14 +651,25 @@ class DatabaseAPI extends BaseEchoApi {
}

/**
* @method getRecentTransactionById
* @method getTransactionById
*
* @param {String} transactionId
*
* @return {Promise}
*/
getRecentTransactionById(transactionId) {
return this.exec('get_recent_transaction_by_id', [transactionId]);
getTransactionById(transactionId) {
return this.exec('get_transaction_by_id', [transactionId]);
}

/**
* @method getBtcStakeAddress
*
* @param {String} accountNameOrId
*
* @return {Promise}
*/
getBtcStakeAddress(accountNameOrId) {
return this.exec('get_btc_stake_address', [accountNameOrId]);
}

/**
Expand Down
43 changes: 43 additions & 0 deletions src/echo/apis/wallet-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ class WalletAPI {
*/
getTransactionId(tr) { return this.wsProvider.call([0, 'get_transaction_id', [signedTransaction.toRaw(tr)]]); }

getTransactionById(trId) { return this.wsProvider.call([0, 'get_transaction_by_id', [ripemd160.toRaw(trId)]]); }

getTransaction(blockNumber, trIndex) {
return this.wsProvider.call([0, 'get_transaction', [
uint64.toRaw(blockNumber),
uint64.toRaw(trIndex),
]]);
}

/**
* Get the WIF private key corresponding to a public key. The private key must already be in the wallet.
* @param {string} accountPublicKey public key of an account
Expand Down Expand Up @@ -1863,6 +1872,40 @@ class WalletAPI {
return this.wsProvider.call([0, 'get_btc_deposit_script', [btcDepositAddress]]);
}

/**
* @method createBtcStakeAddress
* @param {string} account
* @param {string} userPubkey
* @param {bool} broadcast
* @returns {Promise<any>}
*/
createBtcStakeAddress(accountNameOrId, userPubkey, broadcast) {
if (!isAccountIdOrName(accountNameOrId)) {
return Promise.reject(new Error('Accounts id or name should be string and valid'));
}

return this.wsProvider.call([0, 'create_btc_stake_address', [
string.toRaw(accountNameOrId),
string.toRaw(userPubkey),
bool.toRaw(broadcast),
]]);
}

/**
* @method getBtcStakeAddress
* @param {string} accountNameOrId
* @returns {Promise<any>}
*/
getBtcStakeAddress(accountNameOrId) {
if (!isAccountIdOrName(accountNameOrId)) {
return Promise.reject(new Error('Accounts id or name should be string and valid'));
}

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

/**
* @method withdrawBtc
* @param {String} accountIdOrName
Expand Down
14 changes: 12 additions & 2 deletions src/serializers/chain/id/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,17 @@ export const btcAggregatingId = new ObjectIdSerializer(
RESERVED_SPACE_ID.PROTOCOL,
PROTOCOL_OBJECT_TYPE_ID.BTC_AGGREGATING,
);
export const btcBlockId = new ObjectIdSerializer(RESERVED_SPACE_ID.PROTOCOL, PROTOCOL_OBJECT_TYPE_ID.BTC_BLOCK);

export const evmAddressId = new ObjectIdSerializer(RESERVED_SPACE_ID.PROTOCOL, PROTOCOL_OBJECT_TYPE_ID.EVM_ADDRESS);
export const didObjectId = new ObjectIdSerializer(RESERVED_SPACE_ID.PROTOCOL, PROTOCOL_OBJECT_TYPE_ID.DID_OBJECT);
export const stakeBtcScriptId = new ObjectIdSerializer(
RESERVED_SPACE_ID.PROTOCOL,
PROTOCOL_OBJECT_TYPE_ID.STAKE_BTC_SCRIPT,
);
export const stakeBtcVoutId = new ObjectIdSerializer(
RESERVED_SPACE_ID.PROTOCOL,
PROTOCOL_OBJECT_TYPE_ID.STAKE_BTC_VOUT,
);
export const stakeEthUpdateId = new ObjectIdSerializer(
RESERVED_SPACE_ID.PROTOCOL,
PROTOCOL_OBJECT_TYPE_ID.STAKE_ETH_UPDATE,
);
3 changes: 3 additions & 0 deletions src/serializers/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ 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_STAKE_ETH_UPDATE]: protocol.sidechain.eth.stakeUpdate,
[OPERATIONS_IDS.SIDECHAIN_BTC_CREATE_STAKE_SCRIPT]: protocol.sidechain.btc.createStakeScript,
[OPERATIONS_IDS.SIDECHAIN_STAKE_BTC_UPDATE]: protocol.sidechain.btc.stakeUpdate,
[OPERATIONS_IDS.BLOCK_REWARD]: protocol.blockReward,
[OPERATIONS_IDS.EVM_ADDRESS_REGISTER]: protocol.evmAddress,
[OPERATIONS_IDS.DID_CREATE_OPERATION]: protocol.did.create,
Expand Down
3 changes: 3 additions & 0 deletions src/serializers/protocol/fee_parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ 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_STAKE_ETH_UPDATE]: defaultFeeParametersSerializer,
[OPERATIONS_IDS.SIDECHAIN_BTC_CREATE_STAKE_SCRIPT]: defaultFeeParametersSerializer,
[OPERATIONS_IDS.SIDECHAIN_STAKE_BTC_UPDATE]: defaultFeeParametersSerializer,
[OPERATIONS_IDS.BLOCK_REWARD]: defaultFeeParametersSerializer,
[OPERATIONS_IDS.EVM_ADDRESS_REGISTER]: defaultFeeParametersSerializer,
[OPERATIONS_IDS.DID_CREATE_OPERATION]: defaultFeeParametersSerializer,
Expand Down
19 changes: 17 additions & 2 deletions src/serializers/protocol/sidechain/btc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { asset, extensions, sha256 } from '../../chain';
import { asset, extensions, sha256, ripemd160 } from '../../chain';
import {
accountId,
btcAddressId,
Expand All @@ -9,7 +9,7 @@ import {
} from '../../chain/id/protocol';
import { btcTransactionDetailsSerializer } from '../../chain/sidechain/btc';
import { struct, set, map, optional } from '../../collections';
import { string as stringSerializer, integers } from '../../basic';
import { string as stringSerializer, integers, bool } from '../../basic';
import btcPublicKey from '../btcPublicKey';
import { uint8, uint32 } from '../../basic/integers';

Expand Down Expand Up @@ -78,3 +78,18 @@ export const sidechainBtcApproveAggregateOperationPropsSerializer = struct({
extensions,
});

export const sidechainBtcCreateStakeScriptOperationPropsSerializer = struct({
fee: asset,
account: accountId,
user_pubkey_hash: ripemd160,
extensions,
});

export const sidechainStakeBtcUpdateOperationPropsSerializer = struct({
fee: asset,
committee_member_id: accountId,
owner: accountId,
btc_tx_info: btcTransactionDetailsSerializer,
is_vin: bool,
extensions,
});
12 changes: 11 additions & 1 deletion src/serializers/protocol/sidechain/eth.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ethAddress from '../ethAddress';
import { uint64 } from '../../basic/integers';
import { asset, extensions, sha256 } from '../../chain';
import { accountId, ethDepositId, ethWithdrawId } from '../../chain/id/protocol';
import { accountId, ethDepositId, ethWithdrawId, assetId } from '../../chain/id/protocol';
import { struct, vector } from '../../collections';

export const sidechainEthCreateAddressOperationPropsSerializer = struct({
Expand Down Expand Up @@ -65,3 +65,13 @@ export const sidechainEthUpdateContractAddressOperationPropsSerializer = struct(
new_addr: ethAddress,
extensions,
});

export const sidechainStakeEthUpdateOperationPropsSerializer = struct({
fee: asset,
committee_member_id: accountId,
asset_id: assetId,
current_balance: uint64,
account: accountId,
transaction_hash: sha256,
extensions,
});
3 changes: 3 additions & 0 deletions src/serializers/protocol/sidechain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const eth = {
sendWithdraw: _eth.sidechainEthSendWithdrawOperationPropsSerializer,
approveWithdraw: _eth.sidechainEthApproveWithdrawOperationPropsSerializer,
updateContractAddress: _eth.sidechainEthUpdateContractAddressOperationPropsSerializer,
stakeUpdate: _eth.sidechainStakeEthUpdateOperationPropsSerializer,
};

export const btc = {
Expand All @@ -52,4 +53,6 @@ export const btc = {
withdraw: _btc.sidechainBtcWithdrawOperationPropsSerializer,
aggregate: _btc.sidechainBtcAggregateOperationPropsSerializer,
approveAggregate: _btc.sidechainBtcApproveAggregateOperationPropsSerializer,
createStakeScript: _btc.sidechainBtcCreateStakeScriptOperationPropsSerializer,
stakeUpdate: _btc.sidechainStakeBtcUpdateOperationPropsSerializer,
};
8 changes: 7 additions & 1 deletion types/echo/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ export default class Api {
getObjects(objectIds: string, force?: boolean): Promise<Array<Object>>;
getPotentialSignatures(tr: Object): Promise<any>;
getProposedTransactions(accountNameOrId: string): Promise<any>;
getRecentTransactionById(transactionId: string): Promise<any>;
getTransactionById(transactionId: string): Promise<any>;
getBtcStakeAddress(accountNameOrId: string): Promise<{
id: string,
account: string,
stake_script: string,
p2sh_address: string,
}>;
getRelativeAccountHistory(accountId: string, stop: number, limit: number, start: number): Promise<AccountHistory[]>;
getRequiredFees(operations: Array<Object>, assetId: string): Promise<Array<{asset_id: string, amount: number}>>;
getRequiredSignatures(tr: Object, availableKey: Array<string>): Promise<any>;
Expand Down
2 changes: 2 additions & 0 deletions types/interfaces/GlobalProperties.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export default interface GlobalProperties {
id: string,
parameters: object,
pending_parameters?: object,
active_committee_members: Array<Array<string>>,
consensus_assets_prices: Array<Array<string | number>>
}
13 changes: 8 additions & 5 deletions types/interfaces/OperationId.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ declare enum OperationId {
SIDECHAIN_BTC_WITHDRAW = 62,
SIDECHAIN_BTC_AGGREGATE = 63,
SIDECHAIN_BTC_APPROVE_AGGREGATE = 64,
BLOCK_REWARD = 65, // VIRTUAL
EVM_ADDRESS_REGISTER = 66,
DID_CREATE_OPERATION = 67,
DID_UPDATE_OPERATION = 68,
DID_DELETE_OPERATION = 69,
SIDECHAIN_STAKE_ETH_UPDATE = 65,
SIDECHAIN_BTC_CREATE_STAKE_SCRIPT = 66,
SIDECHAIN_STAKE_BTC_UPDATE = 67,
BLOCK_REWARD = 68, // VIRTUAL
EVM_ADDRESS_REGISTER = 69,
DID_CREATE_OPERATION = 70,
DID_UPDATE_OPERATION = 71,
DID_DELETE_OPERATION = 72,
}
5 changes: 4 additions & 1 deletion types/serializers/chain/id/protocol.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ export declare const btcIntermediateDepositId: ObjectIdSerializer<RESERVED_SPACE
export declare const btcDepositId: ObjectIdSerializer<RESERVED_SPACE_ID.PROTOCOL>;
export declare const btcWithdrawId: ObjectIdSerializer<RESERVED_SPACE_ID.PROTOCOL>;
export declare const btcAggregatingId: ObjectIdSerializer<RESERVED_SPACE_ID.PROTOCOL>;
export declare const evmAddressId: ObjectIdSerializer<RESERVED_SPACE_ID.PROTOCOL>;
export declare const evmAddressId: ObjectIdSerializer<RESERVED_SPACE_ID.PROTOCOL>;
export declare const didObjectId: ObjectIdSerializer<RESERVED_SPACE_ID.PROTOCOL>;
export declare const stakeBtcScriptId: ObjectIdSerializer<RESERVED_SPACE_ID.PROTOCOL>;
export declare const stakeBtcVoutId: ObjectIdSerializer<RESERVED_SPACE_ID.PROTOCOL>;
export declare const stakeEthUpdateId: ObjectIdSerializer<RESERVED_SPACE_ID.PROTOCOL>;
3 changes: 3 additions & 0 deletions types/serializers/operation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export type OperationPropsSerializer<T extends OperationId> = {
[OperationId.SIDECHAIN_BTC_WITHDRAW]: typeof protocol.sidechain.btc.withdraw,
[OperationId.SIDECHAIN_BTC_AGGREGATE]: typeof protocol.sidechain.btc.aggregate,
[OperationId.SIDECHAIN_BTC_APPROVE_AGGREGATE]: typeof protocol.sidechain.btc.approveAggregate,
[OperationId.SIDECHAIN_STAKE_ETH_UPDATE]: typeof protocol.sidechain.eth.stakeUpdate,
[OperationId.SIDECHAIN_BTC_CREATE_STAKE_SCRIPT]: typeof protocol.sidechain.btc.createStakeScript,
[OperationId.SIDECHAIN_STAKE_BTC_UPDATE]: typeof protocol.sidechain.btc.stakeUpdate,
[OperationId.BLOCK_REWARD]: typeof protocol.blockReward,
[OperationId.EVM_ADDRESS_REGISTER]: typeof protocol.evmAddress,
[OperationId.DID_CREATE_OPERATION]: typeof protocol.did.create,
Expand Down
5 changes: 5 additions & 0 deletions types/serializers/plugins/sidechain/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ export declare const sidechainERC20ConfigSerializer: StructSerializer<{
burn_method: typeof ethMethodSerializer,
issue_method: typeof ethMethodSerializer,
}>;

export declare const sidechainStakeConfigSerializer: StructSerializer<{
eth_address_type: typeof ethAddress,
eth_topic_type: typeof ethTopicSerializer,
}>;
Loading

0 comments on commit f8e6381

Please sign in to comment.