openethereum/rpc/src/v1/traits/parity.rs

223 lines
8.2 KiB
Rust
Raw Normal View History

// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Parity-specific rpc interface.
use std::collections::BTreeMap;
2016-12-13 14:27:27 +01:00
2017-11-14 11:38:17 +01:00
use jsonrpc_core::{BoxFuture, Result};
2016-12-13 14:27:27 +01:00
use jsonrpc_macros::Trailing;
2016-11-16 17:54:54 +01:00
use v1::types::{
H160, H256, H512, U256, U64, Bytes, CallRequest,
2016-11-16 17:54:54 +01:00
Peers, Transaction, RpcSettings, Histogram,
TransactionStats, LocalTransactionStatus,
2016-12-12 02:57:19 +01:00
BlockNumber, ConsensusCapability, VersionInfo,
OperationsInfo, DappId, ChainStatus,
AccountInfo, HwAccountInfo, RichHeader,
2016-11-16 17:54:54 +01:00
};
build_rpc_trait! {
/// Parity-specific rpc interface.
pub trait Parity {
type Metadata;
/// Returns accounts information.
#[rpc(name = "parity_accountsInfo")]
2017-11-14 11:38:17 +01:00
fn accounts_info(&self, Trailing<DappId>) -> Result<BTreeMap<H160, AccountInfo>>;
/// Returns hardware accounts information.
#[rpc(name = "parity_hardwareAccountsInfo")]
2017-11-14 11:38:17 +01:00
fn hardware_accounts_info(&self) -> Result<BTreeMap<H160, HwAccountInfo>>;
Trezor Support (#6403) * Copy modal from keepkey branch and generalize The keepkey PinMatrix modal needs to be the same for Trezor, but we should probably try to keep it general since it can be used for both. * Add trezor communication code This is a result of much trial-and-error and a couple of dead-ends in how to communicate and wire everything up. Code here is still a bit WIP with lots of debug prints and stuff. The test works though, it is possible to sign a transaction. * Extend the basic lib to allow Trezor This is kind of ugly and needs some cleanup and generalization. I’ve just copy-pasted some things to bring in the trezor wallets. I’ve also had to add a lock to the USB API so that only one thing talks to the USB at once. * Add RPC plumbing needed We need to be able to get “locked” devices from the frontend to figure out if we’re going to display the PinMatrix or not. Then we need to be able to send a pin to a device. * Add logic to query backend for Trezor and display PinMatrix There’s a bug somewhere here because signing a transaction fails if you take too long to press the confirm button on the device. * Change back to paritytech branch As my fork has been merged in. * Converting spaces to tabs, as it should be * Incorporate correct handling of EIP-155 Turns out the Trezor was adjusting the v part of the signature, and we’re already doing that so it was done twice. * Some circular logic here that was incorrect BE-encoded U256 is almost the same as RLP encoded without the size-byte, except for <u8 sized values. What’s really done is BE-encoded U256 and then left-trimmed to the smallest size. Kind of obvious in hindsight. * Resolve issue where not clicking fast enough fails The device will not repeat a ButtonRequest when you read from it, so you need to have a blocking `read` for whatever amount of time that you want to give the user to click. You could also have a shorter timeout but keep retrying for some amount of time, but it would amount to the same thing. * Scan after pin entry to make accepting it faster * Remove ability to cancel pin request * Some slight cleanup * Probe for the correct HID Version to determine padding * Move the PinMatrix from Accounts to Application * Removing unused dependencies * Mistake in copying over stuff from keepkey branch * Simplify FormattedMessage * Move generated code to external crate * Remove ethcore-util dependency * Fix broken import in test This test is useless without a connected Trezor, not sure how to make it useful without one. * Merge branch 'master' into fh-4500-trezor-support # Conflicts: # rpc/src/v1/helpers/dispatch.rs * Ignore test that can't be run without trezor device * Fixing grumbles * Avoiding owning data in RPC method * Checking for overflow in v part of signature * s/network_id/chain_id * Propagating an error from the HID Api * Condensing code a little bit * Fixing UI. * Debugging trezor. * Minor styling tweak * Make message type into an actual type This makes the message type that the RPC message accepts into an actual type as opposed to just a string, based on feedback. Although I’m not 100% sure this has actually improved the situation. Overall I think the hardware wallet interface needs some refactoring love. * Split the trezor RPC endpoint It’s split into two more generic endpoints that should be suitable for any hardware wallets with the same behavior to sit behind. * Reflect RPC method split in javascript * Fix bug with pin entry * Fix deadlock for Ledger * Avoid having a USB lock in just listing locked wallets * Fix javascript issue (see #6509) * Replace Mutex with RwLock * Update Ledger test * Fix typo causing faulty signatures (sometimes) * *Actually* fix tests * Update git submodule Needed to make tests pass * Swap line orders to prevent possible deadlock * Make setPinMatrixRequest an @action
2017-09-14 19:28:43 +02:00
/// Get a list of paths to locked hardware wallets
#[rpc(name = "parity_lockedHardwareAccountsInfo")]
2017-11-14 11:38:17 +01:00
fn locked_hardware_accounts_info(&self) -> Result<Vec<String>>;
Trezor Support (#6403) * Copy modal from keepkey branch and generalize The keepkey PinMatrix modal needs to be the same for Trezor, but we should probably try to keep it general since it can be used for both. * Add trezor communication code This is a result of much trial-and-error and a couple of dead-ends in how to communicate and wire everything up. Code here is still a bit WIP with lots of debug prints and stuff. The test works though, it is possible to sign a transaction. * Extend the basic lib to allow Trezor This is kind of ugly and needs some cleanup and generalization. I’ve just copy-pasted some things to bring in the trezor wallets. I’ve also had to add a lock to the USB API so that only one thing talks to the USB at once. * Add RPC plumbing needed We need to be able to get “locked” devices from the frontend to figure out if we’re going to display the PinMatrix or not. Then we need to be able to send a pin to a device. * Add logic to query backend for Trezor and display PinMatrix There’s a bug somewhere here because signing a transaction fails if you take too long to press the confirm button on the device. * Change back to paritytech branch As my fork has been merged in. * Converting spaces to tabs, as it should be * Incorporate correct handling of EIP-155 Turns out the Trezor was adjusting the v part of the signature, and we’re already doing that so it was done twice. * Some circular logic here that was incorrect BE-encoded U256 is almost the same as RLP encoded without the size-byte, except for <u8 sized values. What’s really done is BE-encoded U256 and then left-trimmed to the smallest size. Kind of obvious in hindsight. * Resolve issue where not clicking fast enough fails The device will not repeat a ButtonRequest when you read from it, so you need to have a blocking `read` for whatever amount of time that you want to give the user to click. You could also have a shorter timeout but keep retrying for some amount of time, but it would amount to the same thing. * Scan after pin entry to make accepting it faster * Remove ability to cancel pin request * Some slight cleanup * Probe for the correct HID Version to determine padding * Move the PinMatrix from Accounts to Application * Removing unused dependencies * Mistake in copying over stuff from keepkey branch * Simplify FormattedMessage * Move generated code to external crate * Remove ethcore-util dependency * Fix broken import in test This test is useless without a connected Trezor, not sure how to make it useful without one. * Merge branch 'master' into fh-4500-trezor-support # Conflicts: # rpc/src/v1/helpers/dispatch.rs * Ignore test that can't be run without trezor device * Fixing grumbles * Avoiding owning data in RPC method * Checking for overflow in v part of signature * s/network_id/chain_id * Propagating an error from the HID Api * Condensing code a little bit * Fixing UI. * Debugging trezor. * Minor styling tweak * Make message type into an actual type This makes the message type that the RPC message accepts into an actual type as opposed to just a string, based on feedback. Although I’m not 100% sure this has actually improved the situation. Overall I think the hardware wallet interface needs some refactoring love. * Split the trezor RPC endpoint It’s split into two more generic endpoints that should be suitable for any hardware wallets with the same behavior to sit behind. * Reflect RPC method split in javascript * Fix bug with pin entry * Fix deadlock for Ledger * Avoid having a USB lock in just listing locked wallets * Fix javascript issue (see #6509) * Replace Mutex with RwLock * Update Ledger test * Fix typo causing faulty signatures (sometimes) * *Actually* fix tests * Update git submodule Needed to make tests pass * Swap line orders to prevent possible deadlock * Make setPinMatrixRequest an @action
2017-09-14 19:28:43 +02:00
/// Returns default account for dapp.
#[rpc(meta, name = "parity_defaultAccount")]
2017-11-14 11:38:17 +01:00
fn default_account(&self, Self::Metadata) -> Result<H160>;
/// Returns current transactions limit.
#[rpc(name = "parity_transactionsLimit")]
2017-11-14 11:38:17 +01:00
fn transactions_limit(&self) -> Result<usize>;
/// Returns mining extra data.
#[rpc(name = "parity_extraData")]
2017-11-14 11:38:17 +01:00
fn extra_data(&self) -> Result<Bytes>;
/// Returns mining gas floor target.
#[rpc(name = "parity_gasFloorTarget")]
2017-11-14 11:38:17 +01:00
fn gas_floor_target(&self) -> Result<U256>;
/// Returns mining gas floor cap.
#[rpc(name = "parity_gasCeilTarget")]
2017-11-14 11:38:17 +01:00
fn gas_ceil_target(&self) -> Result<U256>;
/// Returns minimal gas price for transaction to be included in queue.
#[rpc(name = "parity_minGasPrice")]
2017-11-14 11:38:17 +01:00
fn min_gas_price(&self) -> Result<U256>;
/// Returns latest logs
#[rpc(name = "parity_devLogs")]
2017-11-14 11:38:17 +01:00
fn dev_logs(&self) -> Result<Vec<String>>;
/// Returns logs levels
#[rpc(name = "parity_devLogsLevels")]
2017-11-14 11:38:17 +01:00
fn dev_logs_levels(&self) -> Result<String>;
/// Returns chain name - DEPRECATED. Use `parity_chainName` instead.
#[rpc(name = "parity_netChain")]
2017-11-14 11:38:17 +01:00
fn net_chain(&self) -> Result<String>;
/// Returns peers details
#[rpc(name = "parity_netPeers")]
2017-11-14 11:38:17 +01:00
fn net_peers(&self) -> Result<Peers>;
/// Returns network port
#[rpc(name = "parity_netPort")]
2017-11-14 11:38:17 +01:00
fn net_port(&self) -> Result<u16>;
/// Returns rpc settings
#[rpc(name = "parity_rpcSettings")]
2017-11-14 11:38:17 +01:00
fn rpc_settings(&self) -> Result<RpcSettings>;
/// Returns node name
#[rpc(name = "parity_nodeName")]
2017-11-14 11:38:17 +01:00
fn node_name(&self) -> Result<String>;
/// Returns default extra data
#[rpc(name = "parity_defaultExtraData")]
2017-11-14 11:38:17 +01:00
fn default_extra_data(&self) -> Result<Bytes>;
/// Returns distribution of gas price in latest blocks.
#[rpc(name = "parity_gasPriceHistogram")]
2017-11-14 11:38:17 +01:00
fn gas_price_histogram(&self) -> BoxFuture<Histogram>;
/// Returns number of unsigned transactions waiting in the signer queue (if signer enabled)
/// Returns error when signer is disabled
#[rpc(name = "parity_unsignedTransactionsCount")]
2017-11-14 11:38:17 +01:00
fn unsigned_transactions_count(&self) -> Result<usize>;
/// Returns a cryptographically random phrase sufficient for securely seeding a secret key.
#[rpc(name = "parity_generateSecretPhrase")]
2017-11-14 11:38:17 +01:00
fn generate_secret_phrase(&self) -> Result<String>;
/// Returns whatever address would be derived from the given phrase if it were to seed a brainwallet.
#[rpc(name = "parity_phraseToAddress")]
2017-11-14 11:38:17 +01:00
fn phrase_to_address(&self, String) -> Result<H160>;
/// Returns the value of the registrar for this network.
#[rpc(name = "parity_registryAddress")]
2017-11-14 11:38:17 +01:00
fn registry_address(&self) -> Result<Option<H160>>;
/// Returns all addresses if Fat DB is enabled (`--fat-db`), or null if not.
#[rpc(name = "parity_listAccounts")]
2017-11-14 11:38:17 +01:00
fn list_accounts(&self, u64, Option<H160>, Trailing<BlockNumber>) -> Result<Option<Vec<H160>>>;
/// Returns all storage keys of the given address (first parameter) if Fat DB is enabled (`--fat-db`),
/// or null if not.
#[rpc(name = "parity_listStorageKeys")]
2017-11-14 11:38:17 +01:00
fn list_storage_keys(&self, H160, u64, Option<H256>, Trailing<BlockNumber>) -> Result<Option<Vec<H256>>>;
/// Encrypt some data with a public key under ECIES.
/// First parameter is the 512-byte destination public key, second is the message.
#[rpc(name = "parity_encryptMessage")]
2017-11-14 11:38:17 +01:00
fn encrypt_message(&self, H512, Bytes) -> Result<Bytes>;
/// Returns all pending transactions from transaction queue.
#[rpc(name = "parity_pendingTransactions")]
fn pending_transactions(&self, Trailing<usize>) -> Result<Vec<Transaction>>;
New Transaction Queue implementation (#8074) * Implementation of Verifier, Scoring and Ready. * Queue in progress. * TransactionPool. * Prepare for txpool release. * Miner refactor [WiP] * WiP reworking miner. * Make it compile. * Add some docs. * Split blockchain access to a separate file. * Work on miner API. * Fix ethcore tests. * Refactor miner interface for sealing/work packages. * Implement next nonce. * RPC compiles. * Implement couple of missing methdods for RPC. * Add transaction queue listeners. * Compiles! * Clean-up and parallelize. * Get rid of RefCell in header. * Revert "Get rid of RefCell in header." This reverts commit 0f2424c9b7319a786e1565ea2a8a6d801a21b4fb. * Override Sync requirement. * Fix status display. * Unify logging. * Extract some cheap checks. * Measurements and optimizations. * Fix scoring bug, heap size of bug and add cache * Disable tx queueing and parallel verification. * Make ethcore and ethcore-miner compile again. * Make RPC compile again. * Bunch of txpool tests. * Migrate transaction queue tests. * Nonce Cap * Nonce cap cache and tests. * Remove stale future transactions from the queue. * Optimize scoring and write some tests. * Simple penalization. * Clean up and support for different scoring algorithms. * Add CLI parameters for the new queue. * Remove banning queue. * Disable debug build. * Change per_sender limit to be 1% instead of 5% * Avoid cloning when propagating transactions. * Remove old todo. * Post-review fixes. * Fix miner options default. * Implement back ready transactions for light client. * Get rid of from_pending_block * Pass rejection reason. * Add more details to drop. * Rollback heap size of. * Avoid cloning hashes when propagating and include more details on rejection. * Fix tests. * Introduce nonces cache. * Remove uneccessary hashes allocation. * Lower the mem limit. * Re-enable parallel verification. * Add miner log. Don't check the type if not below min_gas_price. * Add more traces, fix disabling miner. * Fix creating pending blocks twice on AuRa authorities. * Fix tests. * re-use pending blocks in AuRa * Use reseal_min_period to prevent too frequent update_sealing. * Fix log to contain hash not sender. * Optimize local transactions. * Fix aura tests. * Update locks comments. * Get rid of unsafe Sync impl. * Review fixes. * Remove excessive matches. * Fix compilation errors. * Use new pool in private transactions. * Fix private-tx test. * Fix secret store tests. * Actually use gas_floor_target * Fix config tests. * Fix pool tests. * Address grumbles.
2018-04-13 17:34:27 +02:00
/// Returns all transactions from transaction queue.
///
/// Some of them might not be ready to be included in a block yet.
#[rpc(name = "parity_allTransactions")]
fn all_transactions(&self) -> Result<Vec<Transaction>>;
/// Returns all future transactions from transaction queue (deprecated)
2016-12-15 18:19:19 +01:00
#[rpc(name = "parity_futureTransactions")]
2017-11-14 11:38:17 +01:00
fn future_transactions(&self) -> Result<Vec<Transaction>>;
2016-12-15 18:19:19 +01:00
2016-11-16 13:37:21 +01:00
/// Returns propagation statistics on transactions pending in the queue.
#[rpc(name = "parity_pendingTransactionsStats")]
2017-11-14 11:38:17 +01:00
fn pending_transactions_stats(&self) -> Result<BTreeMap<H256, TransactionStats>>;
2016-11-16 13:37:21 +01:00
2016-11-16 17:54:54 +01:00
/// Returns a list of current and past local transactions with status details.
#[rpc(name = "parity_localTransactions")]
2017-11-14 11:38:17 +01:00
fn local_transactions(&self) -> Result<BTreeMap<H256, LocalTransactionStatus>>;
2016-11-16 17:54:54 +01:00
/// Returns current WS Server interface and port or an error if ws server is disabled.
#[rpc(name = "parity_wsUrl")]
2017-11-14 11:38:17 +01:00
fn ws_url(&self) -> Result<String>;
2016-10-27 19:29:55 +02:00
/// Returns next nonce for particular sender. Should include all transactions in the queue.
#[rpc(name = "parity_nextNonce")]
2017-11-14 11:38:17 +01:00
fn next_nonce(&self, H160) -> BoxFuture<U256>;
/// Get the mode. Returns one of: "active", "passive", "dark", "offline".
#[rpc(name = "parity_mode")]
2017-11-14 11:38:17 +01:00
fn mode(&self) -> Result<String>;
/// Returns the chain ID used for transaction signing at the
/// current best block. None is returned if not
/// available.
#[rpc(name = "parity_chainId")]
2017-11-14 11:38:17 +01:00
fn chain_id(&self) -> Result<Option<U64>>;
/// Get the chain name. Returns one of: "foundation", "kovan", &c. of a filename.
#[rpc(name = "parity_chain")]
2017-11-14 11:38:17 +01:00
fn chain(&self) -> Result<String>;
/// Get the enode of this node.
#[rpc(name = "parity_enode")]
2017-11-14 11:38:17 +01:00
fn enode(&self) -> Result<String>;
2016-12-11 23:36:38 +01:00
/// Returns information on current consensus capability.
#[rpc(name = "parity_consensusCapability")]
2017-11-14 11:38:17 +01:00
fn consensus_capability(&self) -> Result<ConsensusCapability>;
2016-12-12 02:57:19 +01:00
/// Get our version information in a nice object.
#[rpc(name = "parity_versionInfo")]
2017-11-14 11:38:17 +01:00
fn version_info(&self) -> Result<VersionInfo>;
2016-12-12 02:57:19 +01:00
/// Get information concerning the latest releases if available.
#[rpc(name = "parity_releasesInfo")]
2017-11-14 11:38:17 +01:00
fn releases_info(&self) -> Result<Option<OperationsInfo>>;
/// Get the current chain status.
#[rpc(name = "parity_chainStatus")]
2017-11-14 11:38:17 +01:00
fn chain_status(&self) -> Result<ChainStatus>;
/// Get node kind info.
#[rpc(name = "parity_nodeKind")]
2017-11-14 11:38:17 +01:00
fn node_kind(&self) -> Result<::v1::types::NodeKind>;
/// Get block header.
/// Same as `eth_getBlockByNumber` but without uncles and transactions.
#[rpc(name = "parity_getBlockHeaderByNumber")]
2017-11-14 11:38:17 +01:00
fn block_header(&self, Trailing<BlockNumber>) -> BoxFuture<RichHeader>;
/// Get IPFS CIDv0 given protobuf encoded bytes.
#[rpc(name = "parity_cidV0")]
2017-11-14 11:38:17 +01:00
fn ipfs_cid(&self, Bytes) -> Result<String>;
/// Call contract, returning the output data.
#[rpc(meta, name = "parity_call")]
2017-11-14 11:38:17 +01:00
fn call(&self, Self::Metadata, Vec<CallRequest>, Trailing<BlockNumber>) -> Result<Vec<Bytes>>;
}
2016-10-24 12:21:15 +02:00
}