Hex-encoded block numbers
This commit is contained in:
parent
27580586e0
commit
e1dd986c41
@ -82,8 +82,8 @@ impl<C: 'static, M: 'static> SignerClient<C, M> where C: MiningBlockChainClient,
|
|||||||
if let Some(gas) = modification.gas {
|
if let Some(gas) = modification.gas {
|
||||||
request.gas = gas.into();
|
request.gas = gas.into();
|
||||||
}
|
}
|
||||||
if let Some(min_block) = modification.min_block {
|
if let Some(ref min_block) = modification.min_block {
|
||||||
request.min_block = min_block;
|
request.min_block = min_block.as_ref().and_then(|b| b.to_min_block_num());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let result = f(&*client, &*miner, &*accounts, payload);
|
let result = f(&*client, &*miner, &*accounts, payload);
|
||||||
|
@ -14,12 +14,12 @@
|
|||||||
// 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/>.
|
||||||
|
|
||||||
use serde::{Deserialize, Deserializer, Error};
|
use serde::{Deserialize, Deserializer, Error, Serialize, Serializer};
|
||||||
use serde::de::Visitor;
|
use serde::de::Visitor;
|
||||||
use ethcore::client::BlockId;
|
use ethcore::client::BlockId;
|
||||||
|
|
||||||
/// Represents rpc api block number param.
|
/// Represents rpc api block number param.
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone, Hash, Eq)]
|
||||||
pub enum BlockNumber {
|
pub enum BlockNumber {
|
||||||
/// Number
|
/// Number
|
||||||
Num(u64),
|
Num(u64),
|
||||||
@ -44,6 +44,27 @@ impl Deserialize for BlockNumber {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl BlockNumber {
|
||||||
|
/// Convert block number to min block target.
|
||||||
|
pub fn to_min_block_num(&self) -> Option<u64> {
|
||||||
|
match *self {
|
||||||
|
BlockNumber::Num(ref x) => Some(*x),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Serialize for BlockNumber {
|
||||||
|
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: Serializer {
|
||||||
|
match *self {
|
||||||
|
BlockNumber::Num(ref x) => serializer.serialize_str(&format!("0x{:x}", x)),
|
||||||
|
BlockNumber::Latest => serializer.serialize_str("latest"),
|
||||||
|
BlockNumber::Earliest => serializer.serialize_str("earliest"),
|
||||||
|
BlockNumber::Pending => serializer.serialize_str("pending"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct BlockNumberVisitor;
|
struct BlockNumberVisitor;
|
||||||
|
|
||||||
impl Visitor for BlockNumberVisitor {
|
impl Visitor for BlockNumberVisitor {
|
||||||
|
@ -20,7 +20,7 @@ use std::fmt;
|
|||||||
use serde::{Serialize, Serializer};
|
use serde::{Serialize, Serializer};
|
||||||
use util::log::Colour;
|
use util::log::Colour;
|
||||||
|
|
||||||
use v1::types::{U256, TransactionRequest, RichRawTransaction, H160, H256, H520, Bytes};
|
use v1::types::{U256, TransactionRequest, RichRawTransaction, H160, H256, H520, Bytes, BlockNumber};
|
||||||
use v1::helpers;
|
use v1::helpers;
|
||||||
|
|
||||||
/// Confirmation waiting in a queue
|
/// Confirmation waiting in a queue
|
||||||
@ -195,7 +195,7 @@ pub struct TransactionModification {
|
|||||||
pub gas: Option<U256>,
|
pub gas: Option<U256>,
|
||||||
/// Modified min block
|
/// Modified min block
|
||||||
#[serde(rename="minBlock")]
|
#[serde(rename="minBlock")]
|
||||||
pub min_block: Option<Option<u64>>,
|
pub min_block: Option<Option<BlockNumber>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents two possible return values.
|
/// Represents two possible return values.
|
||||||
@ -237,7 +237,7 @@ impl<A, B> Serialize for Either<A, B> where
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use v1::types::{U256, H256};
|
use v1::types::{U256, H256, BlockNumber};
|
||||||
use v1::helpers;
|
use v1::helpers;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -330,7 +330,7 @@ mod tests {
|
|||||||
// given
|
// given
|
||||||
let s1 = r#"{
|
let s1 = r#"{
|
||||||
"gasPrice":"0xba43b7400",
|
"gasPrice":"0xba43b7400",
|
||||||
"minBlock":42
|
"minBlock":"0x42"
|
||||||
}"#;
|
}"#;
|
||||||
let s2 = r#"{"gas": "0x1233"}"#;
|
let s2 = r#"{"gas": "0x1233"}"#;
|
||||||
let s3 = r#"{}"#;
|
let s3 = r#"{}"#;
|
||||||
@ -344,7 +344,7 @@ mod tests {
|
|||||||
assert_eq!(res1, TransactionModification {
|
assert_eq!(res1, TransactionModification {
|
||||||
gas_price: Some(U256::from_str("0ba43b7400").unwrap()),
|
gas_price: Some(U256::from_str("0ba43b7400").unwrap()),
|
||||||
gas: None,
|
gas: None,
|
||||||
min_block: Some(Some(42)),
|
min_block: Some(Some(BlockNumber::Num(0x42))),
|
||||||
});
|
});
|
||||||
assert_eq!(res2, TransactionModification {
|
assert_eq!(res2, TransactionModification {
|
||||||
gas_price: None,
|
gas_price: None,
|
||||||
|
@ -19,7 +19,7 @@ use ethcore::miner;
|
|||||||
use ethcore::contract_address;
|
use ethcore::contract_address;
|
||||||
use ethcore::transaction::{LocalizedTransaction, Action, PendingTransaction, SignedTransaction};
|
use ethcore::transaction::{LocalizedTransaction, Action, PendingTransaction, SignedTransaction};
|
||||||
use v1::helpers::errors;
|
use v1::helpers::errors;
|
||||||
use v1::types::{Bytes, H160, H256, U256, H512};
|
use v1::types::{Bytes, H160, H256, U256, H512, BlockNumber};
|
||||||
|
|
||||||
/// Transaction
|
/// Transaction
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Serialize)]
|
#[derive(Debug, Default, Clone, PartialEq, Serialize)]
|
||||||
@ -71,7 +71,7 @@ pub struct Transaction {
|
|||||||
pub s: U256,
|
pub s: U256,
|
||||||
/// Transaction activates at specified block.
|
/// Transaction activates at specified block.
|
||||||
#[serde(rename="minBlock")]
|
#[serde(rename="minBlock")]
|
||||||
pub min_block: Option<u64>,
|
pub min_block: Option<BlockNumber>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Local Transaction Status
|
/// Local Transaction Status
|
||||||
@ -232,7 +232,7 @@ impl From<SignedTransaction> for Transaction {
|
|||||||
impl From<PendingTransaction> for Transaction {
|
impl From<PendingTransaction> for Transaction {
|
||||||
fn from(t: PendingTransaction) -> Transaction {
|
fn from(t: PendingTransaction) -> Transaction {
|
||||||
let mut r = Transaction::from(t.transaction);
|
let mut r = Transaction::from(t.transaction);
|
||||||
r.min_block = t.min_block;
|
r.min_block = t.min_block.map(|b| BlockNumber::Num(b));
|
||||||
r
|
r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
//! `TransactionRequest` type
|
//! `TransactionRequest` type
|
||||||
|
|
||||||
use v1::types::{Bytes, H160, U256};
|
use v1::types::{Bytes, H160, U256, BlockNumber};
|
||||||
use v1::helpers;
|
use v1::helpers;
|
||||||
use util::log::Colour;
|
use util::log::Colour;
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ pub struct TransactionRequest {
|
|||||||
pub nonce: Option<U256>,
|
pub nonce: Option<U256>,
|
||||||
/// Delay until this block if specified.
|
/// Delay until this block if specified.
|
||||||
#[serde(rename="minBlock")]
|
#[serde(rename="minBlock")]
|
||||||
pub min_block: Option<u64>,
|
pub min_block: Option<BlockNumber>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format_ether(i: U256) -> String {
|
pub fn format_ether(i: U256) -> String {
|
||||||
@ -93,7 +93,7 @@ impl From<helpers::TransactionRequest> for TransactionRequest {
|
|||||||
value: r.value.map(Into::into),
|
value: r.value.map(Into::into),
|
||||||
data: r.data.map(Into::into),
|
data: r.data.map(Into::into),
|
||||||
nonce: r.nonce.map(Into::into),
|
nonce: r.nonce.map(Into::into),
|
||||||
min_block: r.min_block,
|
min_block: r.min_block.map(|b| BlockNumber::Num(b)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ impl From<helpers::FilledTransactionRequest> for TransactionRequest {
|
|||||||
value: Some(r.value.into()),
|
value: Some(r.value.into()),
|
||||||
data: Some(r.data.into()),
|
data: Some(r.data.into()),
|
||||||
nonce: r.nonce.map(Into::into),
|
nonce: r.nonce.map(Into::into),
|
||||||
min_block: r.min_block,
|
min_block: r.min_block.map(|b| BlockNumber::Num(b)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,7 +123,7 @@ impl Into<helpers::TransactionRequest> for TransactionRequest {
|
|||||||
value: self.value.map(Into::into),
|
value: self.value.map(Into::into),
|
||||||
data: self.data.map(Into::into),
|
data: self.data.map(Into::into),
|
||||||
nonce: self.nonce.map(Into::into),
|
nonce: self.nonce.map(Into::into),
|
||||||
min_block: self.min_block,
|
min_block: self.min_block.and_then(|b| b.to_min_block_num()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ mod tests {
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use rustc_serialize::hex::FromHex;
|
use rustc_serialize::hex::FromHex;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use v1::types::{U256, H160};
|
use v1::types::{U256, H160, BlockNumber};
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -147,7 +147,7 @@ mod tests {
|
|||||||
"value":"0x3",
|
"value":"0x3",
|
||||||
"data":"0x123456",
|
"data":"0x123456",
|
||||||
"nonce":"0x4",
|
"nonce":"0x4",
|
||||||
"minBlock":13
|
"minBlock":"0x13"
|
||||||
}"#;
|
}"#;
|
||||||
let deserialized: TransactionRequest = serde_json::from_str(s).unwrap();
|
let deserialized: TransactionRequest = serde_json::from_str(s).unwrap();
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ mod tests {
|
|||||||
value: Some(U256::from(3)),
|
value: Some(U256::from(3)),
|
||||||
data: Some(vec![0x12, 0x34, 0x56].into()),
|
data: Some(vec![0x12, 0x34, 0x56].into()),
|
||||||
nonce: Some(U256::from(4)),
|
nonce: Some(U256::from(4)),
|
||||||
min_block: Some(13),
|
min_block: Some(BlockNumber::Num(0x13)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user