Commit 28b10397 authored by Mahdi Yari's avatar Mahdi Yari

Merge branch 'hf24-chainid-swap' into 'master'

Hf24 chainid swap

Closes #7

See merge request !5
parents 89a3d619 379a3d81
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"dev_uri": "", "dev_uri": "",
"stage_uri": "", "stage_uri": "",
"address_prefix": "STM", "address_prefix": "STM",
"chain_id": "0000000000000000000000000000000000000000000000000000000000000000", "chain_id": "beeab0de00000000000000000000000000000000000000000000000000000000",
"alternative_api_endpoints": ["https://api.hive.blog", "https://anyx.io"], "alternative_api_endpoints": ["https://api.hive.blog", "https://anyx.io"],
"failover_threshold": 3 "failover_threshold": 3
} }
{ {
"name": "@hiveio/hive-js", "name": "@hiveio/hive-js",
"version": "0.1.0", "version": "0.8.0",
"description": "Hive.js the JavaScript API for Hive blockchain", "description": "Hive.js the JavaScript API for Hive blockchain",
"main": "lib/index.js", "main": "lib/index.js",
"scripts": { "scripts": {
......
...@@ -8,6 +8,11 @@ import steemApi from '../api'; ...@@ -8,6 +8,11 @@ import steemApi from '../api';
import steemAuth from '../auth'; import steemAuth from '../auth';
import { camelCase } from '../utils'; import { camelCase } from '../utils';
const config = require('../config')
const HF23_CHAIN_ID = '0000000000000000000000000000000000000000000000000000000000000000'
const HF24_CHAIN_ID = 'beeab0de00000000000000000000000000000000000000000000000000000000'
const debug = newDebug('steem:broadcast'); const debug = newDebug('steem:broadcast');
const noop = function() {} const noop = function() {}
const formatter = formatterFactory(steemApi); const formatter = formatterFactory(steemApi);
...@@ -51,19 +56,27 @@ steemBroadcast._prepareTransaction = function steemBroadcast$_prepareTransaction ...@@ -51,19 +56,27 @@ steemBroadcast._prepareTransaction = function steemBroadcast$_prepareTransaction
const propertiesP = steemApi.getDynamicGlobalPropertiesAsync(); const propertiesP = steemApi.getDynamicGlobalPropertiesAsync();
return propertiesP return propertiesP
.then((properties) => { .then((properties) => {
// Set defaults on the transaction const hfVersion = steemApi.getHardforkVersionAsync();
const chainDate = new Date(properties.time + 'Z'); return hfVersion.then(HFV => {
const refBlockNum = (properties.last_irreversible_block_num - 1) & 0xFFFF; if (HFV == '0.23.0') {
return steemApi.getBlockHeaderAsync(properties.last_irreversible_block_num).then((block) => { config.set('chain_id', HF23_CHAIN_ID)
const headBlockId = block ? block.previous : '0000000000000000000000000000000000000000'; } else {
return Object.assign({ config.set('chain_id', HF24_CHAIN_ID)
ref_block_num: refBlockNum, }
ref_block_prefix: new Buffer(headBlockId, 'hex').readUInt32LE(4), // Set defaults on the transaction
expiration: new Date( const chainDate = new Date(properties.time + 'Z');
chainDate.getTime() + const refBlockNum = (properties.last_irreversible_block_num - 1) & 0xFFFF;
600 * 1000 return steemApi.getBlockHeaderAsync(properties.last_irreversible_block_num).then((block) => {
), const headBlockId = block ? block.previous : '0000000000000000000000000000000000000000';
}, tx); return Object.assign({
ref_block_num: refBlockNum,
ref_block_prefix: new Buffer(headBlockId, 'hex').readUInt32LE(4),
expiration: new Date(
chainDate.getTime() +
600 * 1000
),
}, tx);
});
}); });
}); });
}; };
......
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