Fix up the transaction JSON serialisation for RPC.

This commit is contained in:
Gav Wood
2016-11-27 14:11:37 +01:00
parent a7037f8e5b
commit 3b6d886860
2 changed files with 19 additions and 6 deletions

View File

@@ -57,12 +57,18 @@ pub struct Transaction {
/// Public key of the signer.
#[serde(rename="publicKey")]
pub public_key: Option<H512>,
/// The V field of the signature.
/// The network id of the transaction, if any.
#[serde(rename="networkId")]
pub network_id: Option<u8>,
/// The standardised V field of the signature (0 or 1).
#[serde(rename="standardV")]
pub standard_v: u8,
/// The standardised V field of the signature.
pub v: u8,
/// The R field of the signature.
pub r: H256,
pub r: U256,
/// The S field of the signature.
pub s: H256,
pub s: U256,
}
/// Local Transaction Status
@@ -176,7 +182,9 @@ impl From<LocalizedTransaction> for Transaction {
},
raw: ::rlp::encode(&t.signed).to_vec().into(),
public_key: t.public_key().ok().map(Into::into),
v: signature.v(),
network_id: t.network_id(),
standard_v: t.standard_v(),
v: t.original_v(),
r: signature.r().into(),
s: signature.s().into(),
}
@@ -207,7 +215,9 @@ impl From<SignedTransaction> for Transaction {
},
raw: ::rlp::encode(&t).to_vec().into(),
public_key: t.public_key().ok().map(Into::into),
v: signature.v(),
network_id: t.network_id(),
standard_v: t.standard_v(),
v: t.original_v(),
r: signature.r().into(),
s: signature.s().into(),
}
@@ -238,7 +248,7 @@ mod tests {
fn test_transaction_serialize() {
let t = Transaction::default();
let serialized = serde_json::to_string(&t).unwrap();
assert_eq!(serialized, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x0","gasPrice":"0x0","gas":"0x0","input":"0x","creates":null,"raw":"0x","publicKey":null,"v":0,"r":"0x0000000000000000000000000000000000000000000000000000000000000000","s":"0x0000000000000000000000000000000000000000000000000000000000000000"}"#);
assert_eq!(serialized, r#"{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x0","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x0","gasPrice":"0x0","gas":"0x0","input":"0x","creates":null,"raw":"0x","publicKey":null,"v":0,"r":"0x","s":"0x"}"#);
}
#[test]