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
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import {
|
||||
inAddress, inAddresses, inData, inHex, inNumber16, inOptions, inBlockNumber, inDeriveHash, inDeriveIndex
|
||||
} from '../../format/input';
|
||||
import { outAccountInfo, outAddress, outAddresses, outChainStatus, outHistogram, outHwAccountInfo, outNodeKind, outNumber, outPeers, outRecentDapps, outTransaction, outVaultMeta } from '../../format/output';
|
||||
import { inAddress, inAddresses, inBlockNumber, inData, inDeriveHash, inDeriveIndex, inHex, inNumber16, inOptions } from '../../format/input';
|
||||
import { outAccountInfo, outAddress, outAddresses, outBlock, outChainStatus, outHistogram, outHwAccountInfo, outNodeKind, outNumber, outPeers, outRecentDapps, outTransaction, outVaultMeta } from '../../format/output';
|
||||
|
||||
export default class Parity {
|
||||
constructor (transport) {
|
||||
@ -189,6 +187,12 @@ export default class Parity {
|
||||
.execute('parity_generateSecretPhrase');
|
||||
}
|
||||
|
||||
getBlockHeaderByNumber (blockNumber = 'latest') {
|
||||
return this._transport
|
||||
.execute('parity_getBlockHeaderByNumber', inBlockNumber(blockNumber))
|
||||
.then(outBlock);
|
||||
}
|
||||
|
||||
getDappAddresses (dappId) {
|
||||
return this._transport
|
||||
.execute('parity_getDappAddresses', dappId)
|
||||
|
@ -43,7 +43,7 @@ export const subscribe = (name, from = 0, to = 'pending') =>
|
||||
|
||||
events.forEach((e) => {
|
||||
Promise.all([
|
||||
api.eth.getBlockByNumber(e.blockNumber),
|
||||
api.parity.getBlockHeaderByNumber(e.blockNumber),
|
||||
api.eth.getTransactionByHash(e.transactionHash)
|
||||
])
|
||||
.then(([block, tx]) => {
|
||||
|
@ -158,7 +158,7 @@ export function attachEvents (contract, callback) {
|
||||
}
|
||||
|
||||
export function getBlock (blockNumber) {
|
||||
return api.eth.getBlockByNumber(blockNumber);
|
||||
return api.parity.getBlockHeaderByNumber(blockNumber);
|
||||
}
|
||||
|
||||
export function callRegister (instance, id, options = {}) {
|
||||
|
@ -94,7 +94,7 @@ export default class Event extends Component {
|
||||
|
||||
Promise
|
||||
.all([
|
||||
api.eth.getBlockByNumber(event.blockNumber),
|
||||
api.parity.getBlockHeaderByNumber(event.blockNumber),
|
||||
getCoin(event.params.tokenreg, event.params.coin)
|
||||
])
|
||||
.then(([block, coin]) => {
|
||||
|
@ -97,8 +97,8 @@ export default class Event extends Component {
|
||||
return;
|
||||
}
|
||||
|
||||
api.eth
|
||||
.getBlockByNumber(event.blockNumber)
|
||||
api.parity
|
||||
.getBlockHeaderByNumber(event.blockNumber)
|
||||
.then((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: {
|
||||
section: SECTION_VAULT,
|
||||
desc: 'Returns the metadata for a specific vault',
|
||||
|
@ -134,8 +134,8 @@ export default class Status {
|
||||
|
||||
this._store.dispatch(statusBlockNumber(blockNumber));
|
||||
|
||||
this._api.eth
|
||||
.getBlockByNumber(blockNumber)
|
||||
this._api.parity
|
||||
.getBlockHeaderByNumber(blockNumber)
|
||||
.then((block) => {
|
||||
if (!block) {
|
||||
return;
|
||||
@ -147,7 +147,7 @@ export default class Status {
|
||||
}));
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn('status._subscribeBlockNumber', 'getBlockByNumber', error);
|
||||
console.warn('status._subscribeBlockNumber', 'getBlockHeaderByNumber', error);
|
||||
});
|
||||
})
|
||||
.then((blockNumberSubscriptionId) => {
|
||||
|
@ -70,48 +70,52 @@ export default class Store {
|
||||
}
|
||||
|
||||
loadTransactions (_txhashes) {
|
||||
const { eth } = this._api;
|
||||
|
||||
// Ignore special cases and if the contents of _txhashes && this.sortedHashes are the same
|
||||
if (Array.isArray(_txhashes) || this.sameHashList(_txhashes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove any tx that are edited/cancelled
|
||||
this.sortedHashes
|
||||
.forEach((hash) => {
|
||||
if (!_txhashes.includes(hash)) {
|
||||
this.removeHash(hash);
|
||||
}
|
||||
});
|
||||
this.sortedHashes.forEach((hash) => {
|
||||
if (!_txhashes.includes(hash)) {
|
||||
this.removeHash(hash);
|
||||
}
|
||||
});
|
||||
|
||||
// Add any new tx
|
||||
_txhashes
|
||||
.forEach((txhash) => {
|
||||
if (this.sortedHashes.includes(txhash)) { return; }
|
||||
eth.getTransactionByHash(txhash)
|
||||
.then((tx) => {
|
||||
if (!tx) { return; }
|
||||
this.transactions[txhash] = tx;
|
||||
// If the tx has a blockHash, let's get the blockNumber, otherwise it's ready to be added
|
||||
if (tx.blockHash) {
|
||||
eth.getBlockByNumber(tx.blockNumber)
|
||||
.then((block) => {
|
||||
this.blocks[tx.blockNumber] = block;
|
||||
this.addHash(txhash);
|
||||
});
|
||||
} else {
|
||||
this.addHash(txhash);
|
||||
}
|
||||
});
|
||||
});
|
||||
_txhashes.forEach((txhash) => {
|
||||
if (this.sortedHashes.includes(txhash)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._api.eth
|
||||
.getTransactionByHash(txhash)
|
||||
.then((tx) => {
|
||||
if (!tx) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.transactions[txhash] = tx;
|
||||
|
||||
// If the tx has a blockHash, let's get the blockNumber, otherwise it's ready to be added
|
||||
if (tx.blockHash) {
|
||||
this._api.parity
|
||||
.getBlockHeaderByNumber(tx.blockNumber)
|
||||
.then((block) => {
|
||||
this.blocks[tx.blockNumber] = block;
|
||||
this.addHash(txhash);
|
||||
});
|
||||
} else {
|
||||
this.addHash(txhash);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
cancelTransaction = (txComponent, tx) => {
|
||||
const { parity } = this._api;
|
||||
const { hash } = tx;
|
||||
|
||||
parity
|
||||
this._api.parity
|
||||
.removeTransaction(hash)
|
||||
.then(() => {
|
||||
txComponent.setState({ canceled: true });
|
||||
@ -122,13 +126,12 @@ export default class Store {
|
||||
}
|
||||
|
||||
editTransaction = (txComponent, tx) => {
|
||||
const { parity } = this._api;
|
||||
const { hash, gas, gasPrice, to, from, value, input, condition } = tx;
|
||||
|
||||
parity
|
||||
this._api.parity
|
||||
.removeTransaction(hash)
|
||||
.then(() => {
|
||||
parity.postTransaction({
|
||||
return this._api.parity.postTransaction({
|
||||
from,
|
||||
to,
|
||||
gas,
|
||||
|
@ -146,7 +146,7 @@ export default class Event extends Component {
|
||||
|
||||
Promise
|
||||
.all([
|
||||
api.eth.getBlockByNumber(event.blockNumber),
|
||||
api.parity.getBlockHeaderByNumber(event.blockNumber),
|
||||
api.eth.getTransactionByHash(event.transactionHash)
|
||||
])
|
||||
.then(([block, transaction]) => {
|
||||
|
Loading…
Reference in New Issue
Block a user