Skip to content

Commit

Permalink
[email protected] migration
Browse files Browse the repository at this point in the history
  • Loading branch information
doomdabidon authored Sep 23, 2020
1 parent eb347c7 commit 6388983
Show file tree
Hide file tree
Showing 22 changed files with 252 additions and 60 deletions.
80 changes: 41 additions & 39 deletions docs/Constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ console.log(constants.CHAIN_TYPES) // information about ids
ACCOUNT_ADDRESS: 14,
CONTRACT_POOL: 15,
MALICIOUS_COMMITTEEMEN: 16,
REWARDS_POOL: 17,
INCENTIVES_POOL: 17,
},
VOTE_TYPE_ID: {
COMMITTEE: 0,
Expand Down Expand Up @@ -285,44 +285,46 @@ console.log(constants.OPERATIONS_IDS); // operation id
BALANCE_CLAIM: 28,
BALANCE_FREEZE: 29,
BALANCE_UNFREEZE: 30,
CONTRACT_CREATE: 31,
CONTRACT_CALL: 32,
CONTRACT_INTERNAL_CREATE: 33, // VIRTUAL
CONTRACT_INTERNAL_CALL: 34, // VIRTUAL
CONTRACT_SELFDESTRUCT: 35, // VIRTUAL
CONTRACT_UPDATE: 36,
CONTRACT_FUND_POOL: 37,
CONTRACT_WHITELIST: 38,
SIDECHAIN_ETH_CREATE_ADDRESS: 39,
SIDECHAIN_ETH_APPROVE_ADDRESS: 40,
SIDECHAIN_ETH_DEPOSIT: 41,
SIDECHAIN_ETH_SEND_DEPOSIT = 42,
SIDECHAIN_ETH_WITHDRAW = 43,
SIDECHAIN_ETH_SEND_WITHDRAW = 44,
SIDECHAIN_ETH_APPROVE_WITHDRAW = 45,
SIDECHAIN_ETH_UPDATE_CONTRACT_ADDRESS = 46,
SIDECHAIN_ISSUE = 47, // VIRTUAL
SIDECHAIN_BURN = 48, // VIRTUAL
SIDECHAIN_ERC20_REGISTER_TOKEN = 49,
SIDECHAIN_ERC20_DEPOSIT_TOKEN = 50,
SIDECHAIN_ERC20_SEND_DEPOSIT_TOKEN = 51,
SIDECHAIN_ERC20_WITHDRAW_TOKEN = 52,
SIDECHAIN_ERC20_SEND_WITHDRAW_TOKEN = 53,
SIDECHAIN_ERC20_APPROVE_TOKEN_WITHDRAW = 54,
SIDECHAIN_ERC20_ISSUE = 55, // VIRTUAL
SIDECHAIN_ERC20_BURN = 56, // VIRTUAL
SIDECHAIN_BTC_CREATE_ADDRESS = 57,
SIDECHAIN_BTC_CREATE_INTERMEDIATE_DEPOSIT = 58,
SIDECHAIN_BTC_INTERMEDIATE_DEPOSIT = 59,
SIDECHAIN_BTC_DEPOSIT = 60,
SIDECHAIN_BTC_WITHDRAW = 61,
SIDECHAIN_BTC_AGGREGATE = 62,
SIDECHAIN_BTC_APPROVE_AGGREGATE = 63,
BLOCK_REWARD = 64,// VIRTUAL
EVM_ADDRESS_REGISTER = 65,
DID_CREATE_OPERATION = 66,
DID_UPDATE_OPERATION = 67,
DID_DELETE_OPERATION = 68,
REQUEST_BALANCE_UNFREEZE: 31,
CONTRACT_CREATE: 32,
CONTRACT_CALL: 33,
CONTRACT_INTERNAL_CREATE: 34, // VIRTUAL
CONTRACT_INTERNAL_CALL: 35, // VIRTUAL
CONTRACT_SELFDESTRUCT: 36, // VIRTUAL
CONTRACT_UPDATE: 37,
CONTRACT_FUND_POOL: 38,
CONTRACT_WHITELIST: 39,
SIDECHAIN_ETH_CREATE_ADDRESS: 40,
SIDECHAIN_ETH_APPROVE_ADDRESS: 41,
SIDECHAIN_ETH_DEPOSIT: 42,
SIDECHAIN_ETH_SEND_DEPOSIT = 43,
SIDECHAIN_ETH_WITHDRAW = 44,
SIDECHAIN_ETH_SEND_WITHDRAW = 45,
SIDECHAIN_ETH_APPROVE_WITHDRAW = 46,
SIDECHAIN_ETH_UPDATE_CONTRACT_ADDRESS = 47,
SIDECHAIN_ISSUE = 48, // VIRTUAL
SIDECHAIN_BURN = 49, // VIRTUAL
SIDECHAIN_ERC20_REGISTER_TOKEN = 50,
SIDECHAIN_ERC20_DEPOSIT_TOKEN = 51,
SIDECHAIN_ERC20_SEND_DEPOSIT_TOKEN = 52,
SIDECHAIN_ERC20_WITHDRAW_TOKEN = 53,
SIDECHAIN_ERC20_SEND_WITHDRAW_TOKEN = 54,
SIDECHAIN_ERC20_APPROVE_TOKEN_WITHDRAW = 55,
SIDECHAIN_ERC20_ISSUE = 56, // VIRTUAL
SIDECHAIN_ERC20_BURN = 57, // VIRTUAL
SIDECHAIN_BTC_CREATE_ADDRESS = 58,
SIDECHAIN_BTC_CREATE_INTERMEDIATE_DEPOSIT = 59,
SIDECHAIN_BTC_INTERMEDIATE_DEPOSIT = 60,
SIDECHAIN_BTC_DEPOSIT = 61,
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,
}
*/
```
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.1-rc.1",
"version": "1.12.2",
"description": "Pure JavaScript ECHO library for node.js",
"main": "./dist/index.js",
"types": "./types/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/constants/chain-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const RESERVED_SPACE_ID = {
* @property {14} ACCOUNT_ADDRESS
* @property {15} CONTRACT_POOL
* @property {16} MALICIOUS_COMMITTEEMEN
* @property {17} REWARDS_POOL
* @property {17} INCENTIVES_POOL
*/

/** @typedef {IMPLEMENTATION_OBJECT_TYPE_t[keyof IMPLEMENTATION_OBJECT_TYPE_t]} ImplementationObjectTypeId */
Expand All @@ -57,7 +57,7 @@ export const IMPLEMENTATION_OBJECT_TYPE_ID = {
ACCOUNT_ADDRESS: 14,
CONTRACT_POOL: 15,
MALICIOUS_COMMITTEEMEN: 16,
REWARDS_POOL: 17,
INCENTIVES_POOL: 17,
};

/** @typedef {0} VoteType */
Expand Down
5 changes: 3 additions & 2 deletions src/constants/object-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const BTC_INTERMEDIATE_DEPOSIT = 20;
export const BTC_DEPOSIT = 21;
export const BTC_WITHDRAW = 22;
export const BTC_AGGREGATING = 23;
export const EVM_ADDRESS = 24;
export const DID_OBJECT = 25;
export const BTC_BLOCK = 24;
export const EVM_ADDRESS = 25;
export const DID_OBJECT = 26;

11 changes: 6 additions & 5 deletions src/constants/operations-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ 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_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;
4 changes: 4 additions & 0 deletions src/echo/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,10 @@ class API {
return this.engine.database.getGitRevision();
}

async getIncentivesInfo() {
return this.engine.database.getIncentivesInfo();
}

/**
* @method getKeyReferences
* @param {Array<String|PublicKey>} keys [public keys]
Expand Down
14 changes: 14 additions & 0 deletions src/echo/apis/database-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,24 @@ class DatabaseAPI extends BaseEchoApi {
return this.exec('get_dynamic_global_properties', []);
}

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

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

/**
* @method getKeyReferences
* @param {Array<String>} keys [public keys]
Expand Down
145 changes: 144 additions & 1 deletion src/echo/apis/wallet-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
isFrozenBalanceId,
isEthAddressId,
isEthereumAddress,
isRipemd160,
isUInt32,
} from '../../utils/validators';

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

Expand Down Expand Up @@ -618,6 +620,35 @@ class WalletAPI {
]]);
}

/**
* Transfer an amount from one account to address.
* @param {string} fromAccountNameOrId the name or id of the account sending the funds
* @param {string} address address in form of ripemd160 hash
* @param {string} amount the amount to send (in nominal units -- to send half of a BTS, specify 0.5)
* @param {string} assetIdOrName the symbol or id of the asset to send
* @param {boolean} shouldDoBroadcastToNetwork true to broadcast the transaction on the network
* @returns {Promise<SignedTransaction>} the signed transaction transferring funds
*/
transferToAddress(fromAccountNameOrId, address, amount, assetIdOrName, shouldDoBroadcastToNetwork) {
if (!isAccountIdOrName(fromAccountNameOrId)) {
return Promise.reject(new Error('Accounts id or name should be string and valid'));
}
if (!isRipemd160(address)) {
return Promise.reject(new Error('Address should be ripemd160 hash'));
}
if (!isValidAmount(amount)) return Promise.reject(new Error('Invalid number'));
if (!isAssetIdOrName(assetIdOrName)) {
return Promise.reject(new Error('Assets id or name should be string and valid'));
}
return this.wsProvider.call([0, 'transfer_to_address', [
string.toRaw(fromAccountNameOrId),
ripemd160.toRaw(address),
string.toRaw(amount),
string.toRaw(assetIdOrName),
bool.toRaw(shouldDoBroadcastToNetwork),
]]);
}

/**
* This method works just like transfer, except it always broadcasts and
* returns the transaction ID along with the signed transaction.
Expand Down Expand Up @@ -680,6 +711,31 @@ class WalletAPI {
]]);
}

/**
* @method updateAccount
* @param {string} account Id or account name
* @param {any} newOptions variant options
* @param {boolean} shouldDoBroadcastToNetwork true to broadcast the transaction on the network
* @param {any} newActive new active
* @param {string} newEchorandKey new echorand key
* @returns {Promise<SignedTransaction>} the signed transaction
*/
updateAccount(account, newOptions, shouldDoBroadcastToNetwork, newActive, newEchorandKey) {
if (!isAccountIdOrName(account)) {
return Promise.reject(new Error('Accounts id or name should be string and valid'));
}
if (!isPublicKey(newEchorandKey)) {
return Promise.reject(new Error('New echorand key should be string and valid'));
}
return this.wsProvider.call([0, 'update_account', [
string.toRaw(account),
variantObject.toRaw(newOptions),
bool.toRaw(shouldDoBroadcastToNetwork),
optional(authority).toRaw(newActive),
optional(publicKey).toRaw(newEchorandKey),
]]);
}

/**
* Get information about a vesting balance object.
* @param {string} accountNameOrId an account name, account ID, or vesting balance object ID
Expand Down Expand Up @@ -1501,6 +1557,10 @@ class WalletAPI {
*/
getDynamicGlobalProperties() { return this.wsProvider.call([0, 'get_dynamic_global_properties', []]); }

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 Expand Up @@ -1869,6 +1929,89 @@ class WalletAPI {
]]);
}

/**
* @method createVestingLinearPolicy
* @param {String} creatorName name of the creator
* @param {String} ownerName name of the owner
* @param {string} amount the amount of vesting
* @param {string} assetName the symbol of the asset
* @param {number} vestingCliffSeconds vesting cliff in seconds
* @param {number} vestingDurationSeconds vesting duration in seconds
* @param {Boolean} broadcast
* @returns {Promise<SignedTransaction>}
*/
createVestingLinearPolicy(
creatorName,
ownerName,
amount,
assetName,
vestingCliffSeconds,
vestingDurationSeconds,
broadcast = false,
) {
if (!isAccountName(creatorName)) return Promise.reject(new Error('creator account name is invalid'));
if (!isAccountName(ownerName)) return Promise.reject(new Error('owner account name is invalid'));
if (!isValidAmount(amount)) return Promise.reject(new Error('Invalid amount'));
if (!isAssetName(assetName)) {
return Promise.reject(new Error('Assets id or name should be string and valid'));
}
if (!isUInt32(vestingCliffSeconds)) {
return Promise.reject(new Error('Vesting cliff should be uint 32'));
}
if (!isUInt32(vestingDurationSeconds)) {
return Promise.reject(new Error('Vesting duration should be uint 32'));
}

return this.wsProvider.call([0, 'create_vesting_linear_policy', [
string.toRaw(creatorName),
string.toRaw(ownerName),
string.toRaw(amount),
string.toRaw(assetName),
uint32.toRaw(vestingCliffSeconds),
uint32.toRaw(vestingDurationSeconds),
bool.toRaw(broadcast),
]]);
}

/**
* @method createVestingCddPolicy
* @param {String} creatorName name of the creator
* @param {String} ownerName name of the owner
* @param {string} amount the amount of vesting
* @param {string} assetName the symbol of the asset
* @param {number} vestingCliffSeconds vesting cliff in seconds
* @param {number} vestingDurationSeconds vesting duration in seconds
* @param {Boolean} broadcast
* @returns {Promise<SignedTransaction>}
*/
createVestingCddPolicy(
creatorName,
ownerName,
amount,
assetName,
vestingSeconds,
broadcast = false,
) {
if (!isAccountName(creatorName)) return Promise.reject(new Error('creator account name is invalid'));
if (!isAccountName(ownerName)) return Promise.reject(new Error('owner account name is invalid'));
if (!isValidAmount(amount)) return Promise.reject(new Error('Invalid amount'));
if (!isAssetName(assetName)) {
return Promise.reject(new Error('Assets id or name should be string and valid'));
}
if (!isUInt32(vestingSeconds)) {
return Promise.reject(new Error('Vesting seconds should be uint 32'));
}

return this.wsProvider.call([0, 'create_vesting_cdd_policy', [
string.toRaw(creatorName),
string.toRaw(ownerName),
string.toRaw(amount),
string.toRaw(assetName),
uint32.toRaw(vestingSeconds),
bool.toRaw(broadcast),
]]);
}

/**
* @method createActivateCommitteeMemberProposal
* @param {String} sender
Expand Down
1 change: 1 addition & 0 deletions src/serializers/chain/id/protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ 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);
1 change: 1 addition & 0 deletions src/serializers/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ 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: 1 addition & 0 deletions src/serializers/protocol/fee_parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ 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
Loading

0 comments on commit 6388983

Please sign in to comment.