Commit 9e1e3f6d authored by Jason Salyers's avatar Jason Salyers

Merge branch 'remove-hf23-refrences' into 'master'

Remove hf23 references

Closes #14

See merge request !15
parents f9bfa0e0 aea804d8
......@@ -8,6 +8,5 @@
"address_prefix": "STM",
"chain_id": "beeab0de00000000000000000000000000000000000000000000000000000000",
"alternative_api_endpoints": ["https://api.hive.blog", "https://anyx.io"],
"failover_threshold": 3,
"rebranded_api": false
"failover_threshold": 3
}
......@@ -55,17 +55,6 @@ hive.config.set('address_prefix','STM');
hive.config.set('chain_id','beeab0de00000000000000000000000000000000000000000000000000000000');
hive.config.set('alternative_api_endpoints', ['https://api.hive.blog', 'https://anyx.io']);
```
### rebranded_api
Set `rebranded_api` to `true` for connecting to eclipse (hf24) RPC nodes.
**It is highly recommended to change this option in the config.json file!**
OR
```
hive.config.set('rebranded_api','true');
hive.broadcast.updateOperations(); // Necessary to update the already loaded operations
```
### set
```
......@@ -1010,18 +999,6 @@ hive.broadcast.witnessSetProperties('Private Signing Key', owner, witnessOps.pro
});
```
### Auto Detect API Version
Get API version and update `rebranded_api` in config.
Note: this will update the config too based on the result.
```
var apiVersion = await hive.utils.autoDetectApiVersion();
console.log(apiVersion);
// => { rebranded_api: true }
hive.broadcast.updateOperations(); // Necessary to update the already loaded operations
```
## Tutorials
[How to use HiveJs on React Native](https://peakd.com/hive-139531/@stoodkev/how-to-use-hivejs-or-other-modules-referencing-core-node-js-modules-on-react-native)
{
"name": "@hiveio/hive-js",
"version": "0.8.8",
"version": "0.8.9",
"description": "Hive.js the JavaScript API for Hive blockchain",
"main": "lib/index.js",
"scripts": {
......
......@@ -14,16 +14,6 @@ var Auth = {};
var transaction = operations.transaction;
var signed_transaction = operations.signed_transaction;
// this function can be removed after hf24
const updateOperations = () => {
delete require.cache[require.resolve('./serializer/src/operations')];
operations = require('./serializer/src/operations');
transaction = operations.transaction;
signed_transaction = operations.signed_transaction;
}
updateOperations()
Auth.updateOperations = updateOperations
Auth.verify = function (name, password, auths) {
var hasKey = false;
var roles = [];
......
......@@ -35,9 +35,6 @@ import types from "./types"
import SerializerImpl from "./serializer"
import config from "../../../config"
const hiveVar = () => config.get("rebranded_api") ? "hive" : "steem"
const hbdVar = () => config.get("rebranded_api") ? "hbd" : "sbd"
const {
//id_type,
//varint32, uint8, int64, fixed_array, object_id_type, vote_id, address,
......@@ -92,7 +89,7 @@ const allowed_vote_assets = new Serializer(1, {
const smt_generation_unit = new Serializer(
"smt_generation_unit", {
[hiveVar() + "_unit"]: map((string), (uint16)),
hive_unit: map((string), (uint16)),
token_unit: map((string), (uint16))
});
......@@ -336,7 +333,7 @@ let chain_properties = new Serializer(
"chain_properties", {
account_creation_fee: asset,
maximum_block_size: uint32,
[hbdVar() + "_interest_rate"]: uint16
hbd_interest_rate: uint16
}
);
......@@ -411,7 +408,7 @@ let comment_options = new Serializer(
author: string,
permlink: string,
max_accepted_payout: asset,
["percent_" + (hiveVar() === "hive" ? "hbd" : "steem_dollars")]: uint16,
percent_hbd: uint16,
allow_votes: bool,
allow_curation_rewards: bool,
extensions: set(static_variant([
......@@ -492,8 +489,8 @@ let escrow_transfer = new Serializer(
"escrow_transfer", {
from: string,
to: string,
[hbdVar() + "_amount"]: asset,
[hiveVar() + "_amount"]: asset,
hbd_amount: asset,
hive_amount: asset,
escrow_id: uint32,
agent: string,
fee: asset,
......@@ -521,8 +518,8 @@ let escrow_release = new Serializer(
who: string,
receiver: string,
escrow_id: uint32,
[hbdVar() + "_amount"]: asset,
[hiveVar() + "_amount"]: asset
hbd_amount: asset,
hive_amount: asset
}
);
......@@ -633,8 +630,8 @@ let set_reset_account = new Serializer(
let claim_reward_balance = new Serializer(
"claim_reward_balance", {
account: string,
["reward_" + hiveVar()]: asset,
["reward_" + hbdVar()]: asset,
reward_hive: asset,
reward_hbd: asset,
reward_vests: asset
}
);
......@@ -749,7 +746,7 @@ let smt_setup = new Serializer(
contribution_begin_time: time_point_sec,
contribution_end_time: time_point_sec,
launch_time: time_point_sec,
[hiveVar() + "_units_min"]: int64,
hive_units_min: int64,
min_unit_ratio: uint32,
max_unit_ratio: uint32,
extensions: set(future_extensions)
......@@ -781,7 +778,7 @@ let smt_setup_ico_tier = new Serializer(
"smt_setup_ico_tier", {
control_account: string,
symbol: asset_symbol,
[hiveVar() + "_units_cap"]: int64,
hive_units_cap: int64,
generation_policy: static_variant([
smt_capped_generation_policy
]),
......@@ -838,8 +835,8 @@ let author_reward = new Serializer(
"author_reward", {
author: string,
permlink: string,
[hbdVar() + "_payout"]: asset,
[hiveVar() + "_payout"]: asset,
hbd_payout: asset,
hive_payout: asset,
vesting_payout: asset
}
);
......
......@@ -55,86 +55,69 @@ hiveBroadcast._prepareTransaction = function hiveBroadcast$_prepareTransaction(t
const propertiesP = hiveApi.getDynamicGlobalPropertiesAsync();
return propertiesP
.then((properties) => {
const hfVersion = hiveApi.getHardforkVersionAsync();
return hfVersion.then(HFV => {
if (HFV == '0.23.0') {
config.set('chain_id', HF23_CHAIN_ID)
} else {
config.set('chain_id', HF24_CHAIN_ID)
}
// Set defaults on the transaction
const chainDate = new Date(properties.time + 'Z');
const refBlockNum = (properties.last_irreversible_block_num - 1) & 0xFFFF;
return hiveApi.getBlockHeaderAsync(properties.last_irreversible_block_num).then((block) => {
const headBlockId = block ? block.previous : '0000000000000000000000000000000000000000';
return Object.assign({
ref_block_num: refBlockNum,
ref_block_prefix: new Buffer(headBlockId, 'hex').readUInt32LE(4),
expiration: new Date(
chainDate.getTime() +
600 * 1000
),
}, tx);
});
// Set defaults on the transaction
const chainDate = new Date(properties.time + 'Z');
const refBlockNum = (properties.last_irreversible_block_num - 1) & 0xFFFF;
return hiveApi.getBlockHeaderAsync(properties.last_irreversible_block_num).then((block) => {
const headBlockId = block ? block.previous : '0000000000000000000000000000000000000000';
return Object.assign({
ref_block_num: refBlockNum,
ref_block_prefix: new Buffer(headBlockId, 'hex').readUInt32LE(4),
expiration: new Date(
chainDate.getTime() +
600 * 1000
),
}, tx);
});
});
};
// Generated wrapper ----------------------------------------------------------
// Generate operations from operations.json
const updateOperations = () => {
// This function declaration + module redeclaration can be removed after hf24
delete require.cache[require.resolve('./operations')];
operations = require('./operations');
hiveAuth.updateOperations();
// end module redeclaration
operations.forEach((operation) => {
const operationName = camelCase(operation.operation);
const operationParams = operation.params || [];
const useCommentPermlink =
operationParams.indexOf('parent_author') !== -1 &&
operationParams.indexOf('parent_permlink') !== -1;
hiveBroadcast[`${operationName}With`] =
function hiveBroadcast$specializedSendWith(wif, options, callback) {
debug(`Sending operation "${operationName}" with`, {options, callback});
const keys = {};
if (operation.roles && operation.roles.length) {
keys[operation.roles[0]] = wif; // TODO - Automatically pick a role? Send all?
}
return hiveBroadcast.send({
extensions: [],
operations: [[operation.operation, Object.assign(
{},
options,
options.json_metadata != null ? {
json_metadata: toString(options.json_metadata),
} : {},
useCommentPermlink && options.permlink == null ? {
permlink: formatter.commentPermlink(options.parent_author, options.parent_permlink),
} : {}
)]],
}, keys, callback);
};
hiveBroadcast[operationName] =
function hiveBroadcast$specializedSend(wif, ...args) {
debug(`Parsing operation "${operationName}" with`, {args});
const options = operationParams.reduce((memo, param, i) => {
memo[param] = args[i]; // eslint-disable-line no-param-reassign
return memo;
}, {});
const callback = args[operationParams.length];
return hiveBroadcast[`${operationName}With`](wif, options, callback);
};
});
};
hiveBroadcast.updateOperations = updateOperations
updateOperations()
operations.forEach((operation) => {
const operationName = camelCase(operation.operation);
const operationParams = operation.params || [];
const useCommentPermlink =
operationParams.indexOf('parent_author') !== -1 &&
operationParams.indexOf('parent_permlink') !== -1;
hiveBroadcast[`${operationName}With`] =
function hiveBroadcast$specializedSendWith(wif, options, callback) {
debug(`Sending operation "${operationName}" with`, {options, callback});
const keys = {};
if (operation.roles && operation.roles.length) {
keys[operation.roles[0]] = wif; // TODO - Automatically pick a role? Send all?
}
return hiveBroadcast.send({
extensions: [],
operations: [[operation.operation, Object.assign(
{},
options,
options.json_metadata != null ? {
json_metadata: toString(options.json_metadata),
} : {},
useCommentPermlink && options.permlink == null ? {
permlink: formatter.commentPermlink(options.parent_author, options.parent_permlink),
} : {}
)]],
}, keys, callback);
};
hiveBroadcast[operationName] =
function hiveBroadcast$specializedSend(wif, ...args) {
debug(`Parsing operation "${operationName}" with`, {args});
const options = operationParams.reduce((memo, param, i) => {
memo[param] = args[i]; // eslint-disable-line no-param-reassign
return memo;
}, {});
const callback = args[operationParams.length];
return hiveBroadcast[`${operationName}With`](wif, options, callback);
};
});
hiveBroadcast.updateOperations = () => {
console.log('Warning: updateOperations() is not necessary anymore')
}
const toString = obj => typeof obj === 'object' ? JSON.stringify(obj) : obj;
broadcastHelpers(hiveBroadcast);
......
const config = require("../config")
const hiveVar = () => config.get("rebranded_api") ? "hive" : "steem"
const hbdVar = () => config.get("rebranded_api") ? "hbd" : "sbd"
module.exports = [
{
......@@ -196,7 +194,7 @@ module.exports = [
"author",
"permlink",
"max_accepted_payout",
"percent_" + hiveVar() === 'hive' ? "hbd" : "steem_dollars",
"percent_hbd",
"allow_votes",
"allow_curation_rewards",
"extensions"
......@@ -284,8 +282,8 @@ module.exports = [
"to",
"agent",
"escrow_id",
hbdVar() + "_amount",
hiveVar() + "_amount",
"hbd_amount",
"hive_amount",
"fee",
"ratification_deadline",
"escrow_expiration",
......@@ -313,8 +311,8 @@ module.exports = [
"who",
"receiver",
"escrow_id",
hbdVar() + "_amount",
hiveVar() + "_amount"
"hbd_amount",
"hive_amount"
]
},
{
......@@ -405,8 +403,8 @@ module.exports = [
"operation": "claim_reward_balance",
"params": [
"account",
"reward_" + hiveVar(),
"reward_" + hbdVar(),
"reward_hive",
"reward_hbd",
"reward_vests"
]
},
......@@ -532,7 +530,7 @@ module.exports = [
"contribution_begin_time",
"contribution_end_time",
"launch_time",
hiveVar() + "_units_min",
"hive_units_min",
"min_unit_ratio",
"max_unit_ratio",
"extensions"
......@@ -566,7 +564,7 @@ module.exports = [
"params": [
"control_account",
"symbol",
hiveVar() + "_units_cap",
"hive_units_cap",
"generation_policy",
"remove",
"extensions"
......
......@@ -2,9 +2,6 @@ import get from "lodash/get";
import { key_utils } from "./auth/ecc";
import config from "./config"
const hiveVar = () => config.get("rebranded_api") ? "hive" : "steem"
const hbdVar = () => config.get("rebranded_api") ? "hbd" : "sbd"
module.exports = hiveAPI => {
function numberWithCommas(x) {
return x.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
......@@ -15,7 +12,7 @@ module.exports = hiveAPI => {
const vests = parseFloat(account.vesting_shares.split(" ")[0]);
const total_vests = parseFloat(gprops.total_vesting_shares.split(" ")[0]);
const total_vest_hive = parseFloat(
gprops['total_vesting_fund_' + hiveVar()].split(" ")[0]
gprops['total_vesting_fund_hive'].split(" ")[0]
);
const vesting_hivef = total_vest_hive * (vests / total_vests);
return vesting_hivef;
......@@ -123,10 +120,10 @@ module.exports = hiveAPI => {
let price_per_hive = pricePerHive(feed_price);
const savings_balance = account.savings_balance;
const savings_hbd_balance = account["savings_" + hbdVar() + "_balance"];
const savings_hbd_balance = account["savings_hbd_balance"];
const balance_hive = parseFloat(account.balance.split(" ")[0]);
const saving_balance_hive = parseFloat(savings_balance.split(" ")[0]);
const hbd_balance = parseFloat(account[hbdVar() + "_balance"]);
const hbd_balance = parseFloat(account["hbd_balance"]);
const hbd_balance_savings = parseFloat(savings_hbd_balance.split(" ")[0]);
let conversionValue = 0;
......
......@@ -98,20 +98,12 @@ export function buildWitnessUpdateOp(
case "maximum_block_size":
type = uint32;
break;
// TODO: remove sbd_interest_rate
case "sbd_interest_rate":
type = uint16;
break;
case "hbd_interest_rate":
type = uint16;
break;
case "url":
type = string;
break;
// TODO: remove sbd_exchange_rate
case "sbd_exchange_rate":
type = price;
break;
case "hbd_exchange_rate":
type = price;
break;
......@@ -128,15 +120,5 @@ export function buildWitnessUpdateOp(
}
export function autoDetectApiVersion() {
return new Promise((resolve, reject) => {
jsonRpc(config.get('url'), { method: 'condenser_api.get_version', params: [], id: 1 }).then(res => {
if (res.blockchain_version !== "0.23.0") {
config.set("rebranded_api", true)
resolve({ rebranded_api: true })
} else {
config.set("rebranded_api", false)
resolve({ rebranded_api: false })
}
})
})
console.log('Warning: autoDetectApiVersion() removed - it is not necessary anymore')
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment