Retrieve block headers only for header-only info (#5480)
* Add parity_getBlockHeaderByNumber * Use parity_getBlockHeaderByNumber for retrieval
This commit is contained in:
parent
0658e42dad
commit
70e87677b3
@ -14,10 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import {
|
import { inAddress, inAddresses, inBlockNumber, inData, inDeriveHash, inDeriveIndex, inHex, inNumber16, inOptions } from '../../format/input';
|
||||||
inAddress, inAddresses, inData, inHex, inNumber16, inOptions, inBlockNumber, inDeriveHash, inDeriveIndex
|
import { outAccountInfo, outAddress, outAddresses, outBlock, outChainStatus, outHistogram, outHwAccountInfo, outNodeKind, outNumber, outPeers, outRecentDapps, outTransaction, outVaultMeta } from '../../format/output';
|
||||||
} from '../../format/input';
|
|
||||||
import { outAccountInfo, outAddress, outAddresses, outChainStatus, outHistogram, outHwAccountInfo, outNodeKind, outNumber, outPeers, outRecentDapps, outTransaction, outVaultMeta } from '../../format/output';
|
|
||||||
|
|
||||||
export default class Parity {
|
export default class Parity {
|
||||||
constructor (transport) {
|
constructor (transport) {
|
||||||
@ -189,6 +187,12 @@ export default class Parity {
|
|||||||
.execute('parity_generateSecretPhrase');
|
.execute('parity_generateSecretPhrase');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getBlockHeaderByNumber (blockNumber = 'latest') {
|
||||||
|
return this._transport
|
||||||
|
.execute('parity_getBlockHeaderByNumber', inBlockNumber(blockNumber))
|
||||||
|
.then(outBlock);
|
||||||
|
}
|
||||||
|
|
||||||
getDappAddresses (dappId) {
|
getDappAddresses (dappId) {
|
||||||
return this._transport
|
return this._transport
|
||||||
.execute('parity_getDappAddresses', dappId)
|
.execute('parity_getDappAddresses', dappId)
|
||||||
|
@ -43,7 +43,7 @@ export const subscribe = (name, from = 0, to = 'pending') =>
|
|||||||
|
|
||||||
events.forEach((e) => {
|
events.forEach((e) => {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
api.eth.getBlockByNumber(e.blockNumber),
|
api.parity.getBlockHeaderByNumber(e.blockNumber),
|
||||||
api.eth.getTransactionByHash(e.transactionHash)
|
api.eth.getTransactionByHash(e.transactionHash)
|
||||||
])
|
])
|
||||||
.then(([block, tx]) => {
|
.then(([block, tx]) => {
|
||||||
|
@ -158,7 +158,7 @@ export function attachEvents (contract, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getBlock (blockNumber) {
|
export function getBlock (blockNumber) {
|
||||||
return api.eth.getBlockByNumber(blockNumber);
|
return api.parity.getBlockHeaderByNumber(blockNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function callRegister (instance, id, options = {}) {
|
export function callRegister (instance, id, options = {}) {
|
||||||
|
@ -94,7 +94,7 @@ export default class Event extends Component {
|
|||||||
|
|
||||||
Promise
|
Promise
|
||||||
.all([
|
.all([
|
||||||
api.eth.getBlockByNumber(event.blockNumber),
|
api.parity.getBlockHeaderByNumber(event.blockNumber),
|
||||||
getCoin(event.params.tokenreg, event.params.coin)
|
getCoin(event.params.tokenreg, event.params.coin)
|
||||||
])
|
])
|
||||||
.then(([block, coin]) => {
|
.then(([block, coin]) => {
|
||||||
|
@ -97,8 +97,8 @@ export default class Event extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
api.eth
|
api.parity
|
||||||
.getBlockByNumber(event.blockNumber)
|
.getBlockHeaderByNumber(event.blockNumber)
|
||||||
.then((block) => {
|
.then((block) => {
|
||||||
this.setState({ block });
|
this.setState({ block });
|
||||||
});
|
});
|
||||||
|
@ -296,6 +296,19 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getBlockHeaderByNumber: {
|
||||||
|
section: SECTION_NET,
|
||||||
|
desc: 'Returns block header information by number (same as eth_getBlockByNumber without transactions and uncles)',
|
||||||
|
params: [
|
||||||
|
{
|
||||||
|
type: BlockNumber,
|
||||||
|
desc: 'integer of a block number, or the string `\'earliest\'`, `\'latest\'` or `\'pending\'`, as in the [default block parameter](#the-default-block-parameter).',
|
||||||
|
example: fromDecimal(436)
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: 'See [eth_getBlockByHash](#eth_getblockbyhash) (without transactions and uncles)'
|
||||||
|
},
|
||||||
|
|
||||||
getVaultMeta: {
|
getVaultMeta: {
|
||||||
section: SECTION_VAULT,
|
section: SECTION_VAULT,
|
||||||
desc: 'Returns the metadata for a specific vault',
|
desc: 'Returns the metadata for a specific vault',
|
||||||
|
@ -134,8 +134,8 @@ export default class Status {
|
|||||||
|
|
||||||
this._store.dispatch(statusBlockNumber(blockNumber));
|
this._store.dispatch(statusBlockNumber(blockNumber));
|
||||||
|
|
||||||
this._api.eth
|
this._api.parity
|
||||||
.getBlockByNumber(blockNumber)
|
.getBlockHeaderByNumber(blockNumber)
|
||||||
.then((block) => {
|
.then((block) => {
|
||||||
if (!block) {
|
if (!block) {
|
||||||
return;
|
return;
|
||||||
@ -147,7 +147,7 @@ export default class Status {
|
|||||||
}));
|
}));
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.warn('status._subscribeBlockNumber', 'getBlockByNumber', error);
|
console.warn('status._subscribeBlockNumber', 'getBlockHeaderByNumber', error);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then((blockNumberSubscriptionId) => {
|
.then((blockNumberSubscriptionId) => {
|
||||||
|
@ -70,32 +70,37 @@ export default class Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadTransactions (_txhashes) {
|
loadTransactions (_txhashes) {
|
||||||
const { eth } = this._api;
|
|
||||||
|
|
||||||
// Ignore special cases and if the contents of _txhashes && this.sortedHashes are the same
|
// Ignore special cases and if the contents of _txhashes && this.sortedHashes are the same
|
||||||
if (Array.isArray(_txhashes) || this.sameHashList(_txhashes)) {
|
if (Array.isArray(_txhashes) || this.sameHashList(_txhashes)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any tx that are edited/cancelled
|
// Remove any tx that are edited/cancelled
|
||||||
this.sortedHashes
|
this.sortedHashes.forEach((hash) => {
|
||||||
.forEach((hash) => {
|
|
||||||
if (!_txhashes.includes(hash)) {
|
if (!_txhashes.includes(hash)) {
|
||||||
this.removeHash(hash);
|
this.removeHash(hash);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add any new tx
|
// Add any new tx
|
||||||
_txhashes
|
_txhashes.forEach((txhash) => {
|
||||||
.forEach((txhash) => {
|
if (this.sortedHashes.includes(txhash)) {
|
||||||
if (this.sortedHashes.includes(txhash)) { return; }
|
return;
|
||||||
eth.getTransactionByHash(txhash)
|
}
|
||||||
|
|
||||||
|
this._api.eth
|
||||||
|
.getTransactionByHash(txhash)
|
||||||
.then((tx) => {
|
.then((tx) => {
|
||||||
if (!tx) { return; }
|
if (!tx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.transactions[txhash] = tx;
|
this.transactions[txhash] = tx;
|
||||||
|
|
||||||
// If the tx has a blockHash, let's get the blockNumber, otherwise it's ready to be added
|
// If the tx has a blockHash, let's get the blockNumber, otherwise it's ready to be added
|
||||||
if (tx.blockHash) {
|
if (tx.blockHash) {
|
||||||
eth.getBlockByNumber(tx.blockNumber)
|
this._api.parity
|
||||||
|
.getBlockHeaderByNumber(tx.blockNumber)
|
||||||
.then((block) => {
|
.then((block) => {
|
||||||
this.blocks[tx.blockNumber] = block;
|
this.blocks[tx.blockNumber] = block;
|
||||||
this.addHash(txhash);
|
this.addHash(txhash);
|
||||||
@ -108,10 +113,9 @@ export default class Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cancelTransaction = (txComponent, tx) => {
|
cancelTransaction = (txComponent, tx) => {
|
||||||
const { parity } = this._api;
|
|
||||||
const { hash } = tx;
|
const { hash } = tx;
|
||||||
|
|
||||||
parity
|
this._api.parity
|
||||||
.removeTransaction(hash)
|
.removeTransaction(hash)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
txComponent.setState({ canceled: true });
|
txComponent.setState({ canceled: true });
|
||||||
@ -122,13 +126,12 @@ export default class Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
editTransaction = (txComponent, tx) => {
|
editTransaction = (txComponent, tx) => {
|
||||||
const { parity } = this._api;
|
|
||||||
const { hash, gas, gasPrice, to, from, value, input, condition } = tx;
|
const { hash, gas, gasPrice, to, from, value, input, condition } = tx;
|
||||||
|
|
||||||
parity
|
this._api.parity
|
||||||
.removeTransaction(hash)
|
.removeTransaction(hash)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
parity.postTransaction({
|
return this._api.parity.postTransaction({
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
gas,
|
gas,
|
||||||
|
@ -146,7 +146,7 @@ export default class Event extends Component {
|
|||||||
|
|
||||||
Promise
|
Promise
|
||||||
.all([
|
.all([
|
||||||
api.eth.getBlockByNumber(event.blockNumber),
|
api.parity.getBlockHeaderByNumber(event.blockNumber),
|
||||||
api.eth.getTransactionByHash(event.transactionHash)
|
api.eth.getTransactionByHash(event.transactionHash)
|
||||||
])
|
])
|
||||||
.then(([block, transaction]) => {
|
.then(([block, transaction]) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user