Merge branch 'master' into pubsub-docs

# Conflicts:
#	rpc/src/v1/tests/mocked/pubsub.rs
This commit is contained in:
Tomasz Drwięga 2017-06-14 11:46:30 +02:00
commit 00b58d1206
No known key found for this signature in database
GPG Key ID: D066F497E62CAF66
10 changed files with 252 additions and 191 deletions

2
Cargo.lock generated
View File

@ -1803,7 +1803,7 @@ dependencies = [
[[package]]
name = "parity-ui-precompiled"
version = "1.4.0"
source = "git+https://github.com/paritytech/js-precompiled.git#0811e57083d75d8e93e03ccd9bba3432703236ce"
source = "git+https://github.com/paritytech/js-precompiled.git#e0cdec722ff2d32de6308638710fc4eb8a07253e"
dependencies = [
"parity-dapps-glue 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

View File

@ -143,8 +143,6 @@ pub fn get_tier_idx (tier: GasPriceTier) -> usize {
pub struct InstructionInfo {
/// Mnemonic name.
pub name: &'static str,
/// Additional code bytes used. Used only for PUSHxx.
pub additional: usize,
/// Number of stack arguments.
pub args: usize,
/// Number of returned stack items.
@ -155,10 +153,9 @@ pub struct InstructionInfo {
impl InstructionInfo {
/// Create new instruction info.
pub fn new(name: &'static str, additional: usize, args: usize, ret: usize, tier: GasPriceTier) -> Self {
pub fn new(name: &'static str, args: usize, ret: usize, tier: GasPriceTier) -> Self {
InstructionInfo {
name: name,
additional: additional,
args: args,
ret: ret,
tier: tier
@ -170,140 +167,140 @@ lazy_static! {
/// Static instruction table.
pub static ref INSTRUCTIONS: [InstructionInfo; 0x100] = {
let mut arr = [InstructionInfo::default(); 0x100];
arr[STOP as usize] = InstructionInfo::new("STOP", 0, 0, 0, GasPriceTier::Zero);
arr[ADD as usize] = InstructionInfo::new("ADD", 0, 2, 1, GasPriceTier::VeryLow);
arr[SUB as usize] = InstructionInfo::new("SUB", 0, 2, 1, GasPriceTier::VeryLow);
arr[MUL as usize] = InstructionInfo::new("MUL", 0, 2, 1, GasPriceTier::Low);
arr[DIV as usize] = InstructionInfo::new("DIV", 0, 2, 1, GasPriceTier::Low);
arr[SDIV as usize] = InstructionInfo::new("SDIV", 0, 2, 1, GasPriceTier::Low);
arr[MOD as usize] = InstructionInfo::new("MOD", 0, 2, 1, GasPriceTier::Low);
arr[SMOD as usize] = InstructionInfo::new("SMOD", 0, 2, 1, GasPriceTier::Low);
arr[EXP as usize] = InstructionInfo::new("EXP", 0, 2, 1, GasPriceTier::Special);
arr[NOT as usize] = InstructionInfo::new("NOT", 0, 1, 1, GasPriceTier::VeryLow);
arr[LT as usize] = InstructionInfo::new("LT", 0, 2, 1, GasPriceTier::VeryLow);
arr[GT as usize] = InstructionInfo::new("GT", 0, 2, 1, GasPriceTier::VeryLow);
arr[SLT as usize] = InstructionInfo::new("SLT", 0, 2, 1, GasPriceTier::VeryLow);
arr[SGT as usize] = InstructionInfo::new("SGT", 0, 2, 1, GasPriceTier::VeryLow);
arr[EQ as usize] = InstructionInfo::new("EQ", 0, 2, 1, GasPriceTier::VeryLow);
arr[ISZERO as usize] = InstructionInfo::new("ISZERO", 0, 1, 1, GasPriceTier::VeryLow);
arr[AND as usize] = InstructionInfo::new("AND", 0, 2, 1, GasPriceTier::VeryLow);
arr[OR as usize] = InstructionInfo::new("OR", 0, 2, 1, GasPriceTier::VeryLow);
arr[XOR as usize] = InstructionInfo::new("XOR", 0, 2, 1, GasPriceTier::VeryLow);
arr[BYTE as usize] = InstructionInfo::new("BYTE", 0, 2, 1, GasPriceTier::VeryLow);
arr[ADDMOD as usize] = InstructionInfo::new("ADDMOD", 0, 3, 1, GasPriceTier::Mid);
arr[MULMOD as usize] = InstructionInfo::new("MULMOD", 0, 3, 1, GasPriceTier::Mid);
arr[SIGNEXTEND as usize] = InstructionInfo::new("SIGNEXTEND", 0, 2, 1, GasPriceTier::Low);
arr[RETURNDATASIZE as usize] = InstructionInfo::new("RETURNDATASIZE", 0, 0, 1, GasPriceTier::Base);
arr[RETURNDATACOPY as usize] = InstructionInfo::new("RETURNDATACOPY", 0, 3, 0, GasPriceTier::VeryLow);
arr[SHA3 as usize] = InstructionInfo::new("SHA3", 0, 2, 1, GasPriceTier::Special);
arr[ADDRESS as usize] = InstructionInfo::new("ADDRESS", 0, 0, 1, GasPriceTier::Base);
arr[BALANCE as usize] = InstructionInfo::new("BALANCE", 0, 1, 1, GasPriceTier::Special);
arr[ORIGIN as usize] = InstructionInfo::new("ORIGIN", 0, 0, 1, GasPriceTier::Base);
arr[CALLER as usize] = InstructionInfo::new("CALLER", 0, 0, 1, GasPriceTier::Base);
arr[CALLVALUE as usize] = InstructionInfo::new("CALLVALUE", 0, 0, 1, GasPriceTier::Base);
arr[CALLDATALOAD as usize] = InstructionInfo::new("CALLDATALOAD", 0, 1, 1, GasPriceTier::VeryLow);
arr[CALLDATASIZE as usize] = InstructionInfo::new("CALLDATASIZE", 0, 0, 1, GasPriceTier::Base);
arr[CALLDATACOPY as usize] = InstructionInfo::new("CALLDATACOPY", 0, 3, 0, GasPriceTier::VeryLow);
arr[CODESIZE as usize] = InstructionInfo::new("CODESIZE", 0, 0, 1, GasPriceTier::Base);
arr[CODECOPY as usize] = InstructionInfo::new("CODECOPY", 0, 3, 0, GasPriceTier::VeryLow);
arr[GASPRICE as usize] = InstructionInfo::new("GASPRICE", 0, 0, 1, GasPriceTier::Base);
arr[EXTCODESIZE as usize] = InstructionInfo::new("EXTCODESIZE", 0, 1, 1, GasPriceTier::Special);
arr[EXTCODECOPY as usize] = InstructionInfo::new("EXTCODECOPY", 0, 4, 0, GasPriceTier::Special);
arr[BLOCKHASH as usize] = InstructionInfo::new("BLOCKHASH", 0, 1, 1, GasPriceTier::Ext);
arr[COINBASE as usize] = InstructionInfo::new("COINBASE", 0, 0, 1, GasPriceTier::Base);
arr[TIMESTAMP as usize] = InstructionInfo::new("TIMESTAMP", 0, 0, 1, GasPriceTier::Base);
arr[NUMBER as usize] = InstructionInfo::new("NUMBER", 0, 0, 1, GasPriceTier::Base);
arr[DIFFICULTY as usize] = InstructionInfo::new("DIFFICULTY", 0, 0, 1, GasPriceTier::Base);
arr[GASLIMIT as usize] = InstructionInfo::new("GASLIMIT", 0, 0, 1, GasPriceTier::Base);
arr[POP as usize] = InstructionInfo::new("POP", 0, 1, 0, GasPriceTier::Base);
arr[MLOAD as usize] = InstructionInfo::new("MLOAD", 0, 1, 1, GasPriceTier::VeryLow);
arr[MSTORE as usize] = InstructionInfo::new("MSTORE", 0, 2, 0, GasPriceTier::VeryLow);
arr[MSTORE8 as usize] = InstructionInfo::new("MSTORE8", 0, 2, 0, GasPriceTier::VeryLow);
arr[SLOAD as usize] = InstructionInfo::new("SLOAD", 0, 1, 1, GasPriceTier::Special);
arr[SSTORE as usize] = InstructionInfo::new("SSTORE", 0, 2, 0, GasPriceTier::Special);
arr[JUMP as usize] = InstructionInfo::new("JUMP", 0, 1, 0, GasPriceTier::Mid);
arr[JUMPI as usize] = InstructionInfo::new("JUMPI", 0, 2, 0, GasPriceTier::High);
arr[PC as usize] = InstructionInfo::new("PC", 0, 0, 1, GasPriceTier::Base);
arr[MSIZE as usize] = InstructionInfo::new("MSIZE", 0, 0, 1, GasPriceTier::Base);
arr[GAS as usize] = InstructionInfo::new("GAS", 0, 0, 1, GasPriceTier::Base);
arr[JUMPDEST as usize] = InstructionInfo::new("JUMPDEST", 0, 0, 0, GasPriceTier::Special);
arr[PUSH1 as usize] = InstructionInfo::new("PUSH1", 1, 0, 1, GasPriceTier::VeryLow);
arr[PUSH2 as usize] = InstructionInfo::new("PUSH2", 2, 0, 1, GasPriceTier::VeryLow);
arr[PUSH3 as usize] = InstructionInfo::new("PUSH3", 3, 0, 1, GasPriceTier::VeryLow);
arr[PUSH4 as usize] = InstructionInfo::new("PUSH4", 4, 0, 1, GasPriceTier::VeryLow);
arr[PUSH5 as usize] = InstructionInfo::new("PUSH5", 5, 0, 1, GasPriceTier::VeryLow);
arr[PUSH6 as usize] = InstructionInfo::new("PUSH6", 6, 0, 1, GasPriceTier::VeryLow);
arr[PUSH7 as usize] = InstructionInfo::new("PUSH7", 7, 0, 1, GasPriceTier::VeryLow);
arr[PUSH8 as usize] = InstructionInfo::new("PUSH8", 8, 0, 1, GasPriceTier::VeryLow);
arr[PUSH9 as usize] = InstructionInfo::new("PUSH9", 9, 0, 1, GasPriceTier::VeryLow);
arr[PUSH10 as usize] = InstructionInfo::new("PUSH10", 10, 0, 1, GasPriceTier::VeryLow);
arr[PUSH11 as usize] = InstructionInfo::new("PUSH11", 11, 0, 1, GasPriceTier::VeryLow);
arr[PUSH12 as usize] = InstructionInfo::new("PUSH12", 12, 0, 1, GasPriceTier::VeryLow);
arr[PUSH13 as usize] = InstructionInfo::new("PUSH13", 13, 0, 1, GasPriceTier::VeryLow);
arr[PUSH14 as usize] = InstructionInfo::new("PUSH14", 14, 0, 1, GasPriceTier::VeryLow);
arr[PUSH15 as usize] = InstructionInfo::new("PUSH15", 15, 0, 1, GasPriceTier::VeryLow);
arr[PUSH16 as usize] = InstructionInfo::new("PUSH16", 16, 0, 1, GasPriceTier::VeryLow);
arr[PUSH17 as usize] = InstructionInfo::new("PUSH17", 17, 0, 1, GasPriceTier::VeryLow);
arr[PUSH18 as usize] = InstructionInfo::new("PUSH18", 18, 0, 1, GasPriceTier::VeryLow);
arr[PUSH19 as usize] = InstructionInfo::new("PUSH19", 19, 0, 1, GasPriceTier::VeryLow);
arr[PUSH20 as usize] = InstructionInfo::new("PUSH20", 20, 0, 1, GasPriceTier::VeryLow);
arr[PUSH21 as usize] = InstructionInfo::new("PUSH21", 21, 0, 1, GasPriceTier::VeryLow);
arr[PUSH22 as usize] = InstructionInfo::new("PUSH22", 22, 0, 1, GasPriceTier::VeryLow);
arr[PUSH23 as usize] = InstructionInfo::new("PUSH23", 23, 0, 1, GasPriceTier::VeryLow);
arr[PUSH24 as usize] = InstructionInfo::new("PUSH24", 24, 0, 1, GasPriceTier::VeryLow);
arr[PUSH25 as usize] = InstructionInfo::new("PUSH25", 25, 0, 1, GasPriceTier::VeryLow);
arr[PUSH26 as usize] = InstructionInfo::new("PUSH26", 26, 0, 1, GasPriceTier::VeryLow);
arr[PUSH27 as usize] = InstructionInfo::new("PUSH27", 27, 0, 1, GasPriceTier::VeryLow);
arr[PUSH28 as usize] = InstructionInfo::new("PUSH28", 28, 0, 1, GasPriceTier::VeryLow);
arr[PUSH29 as usize] = InstructionInfo::new("PUSH29", 29, 0, 1, GasPriceTier::VeryLow);
arr[PUSH30 as usize] = InstructionInfo::new("PUSH30", 30, 0, 1, GasPriceTier::VeryLow);
arr[PUSH31 as usize] = InstructionInfo::new("PUSH31", 31, 0, 1, GasPriceTier::VeryLow);
arr[PUSH32 as usize] = InstructionInfo::new("PUSH32", 32, 0, 1, GasPriceTier::VeryLow);
arr[DUP1 as usize] = InstructionInfo::new("DUP1", 0, 1, 2, GasPriceTier::VeryLow);
arr[DUP2 as usize] = InstructionInfo::new("DUP2", 0, 2, 3, GasPriceTier::VeryLow);
arr[DUP3 as usize] = InstructionInfo::new("DUP3", 0, 3, 4, GasPriceTier::VeryLow);
arr[DUP4 as usize] = InstructionInfo::new("DUP4", 0, 4, 5, GasPriceTier::VeryLow);
arr[DUP5 as usize] = InstructionInfo::new("DUP5", 0, 5, 6, GasPriceTier::VeryLow);
arr[DUP6 as usize] = InstructionInfo::new("DUP6", 0, 6, 7, GasPriceTier::VeryLow);
arr[DUP7 as usize] = InstructionInfo::new("DUP7", 0, 7, 8, GasPriceTier::VeryLow);
arr[DUP8 as usize] = InstructionInfo::new("DUP8", 0, 8, 9, GasPriceTier::VeryLow);
arr[DUP9 as usize] = InstructionInfo::new("DUP9", 0, 9, 10, GasPriceTier::VeryLow);
arr[DUP10 as usize] = InstructionInfo::new("DUP10", 0, 10, 11, GasPriceTier::VeryLow);
arr[DUP11 as usize] = InstructionInfo::new("DUP11", 0, 11, 12, GasPriceTier::VeryLow);
arr[DUP12 as usize] = InstructionInfo::new("DUP12", 0, 12, 13, GasPriceTier::VeryLow);
arr[DUP13 as usize] = InstructionInfo::new("DUP13", 0, 13, 14, GasPriceTier::VeryLow);
arr[DUP14 as usize] = InstructionInfo::new("DUP14", 0, 14, 15, GasPriceTier::VeryLow);
arr[DUP15 as usize] = InstructionInfo::new("DUP15", 0, 15, 16, GasPriceTier::VeryLow);
arr[DUP16 as usize] = InstructionInfo::new("DUP16", 0, 16, 17, GasPriceTier::VeryLow);
arr[SWAP1 as usize] = InstructionInfo::new("SWAP1", 0, 2, 2, GasPriceTier::VeryLow);
arr[SWAP2 as usize] = InstructionInfo::new("SWAP2", 0, 3, 3, GasPriceTier::VeryLow);
arr[SWAP3 as usize] = InstructionInfo::new("SWAP3", 0, 4, 4, GasPriceTier::VeryLow);
arr[SWAP4 as usize] = InstructionInfo::new("SWAP4", 0, 5, 5, GasPriceTier::VeryLow);
arr[SWAP5 as usize] = InstructionInfo::new("SWAP5", 0, 6, 6, GasPriceTier::VeryLow);
arr[SWAP6 as usize] = InstructionInfo::new("SWAP6", 0, 7, 7, GasPriceTier::VeryLow);
arr[SWAP7 as usize] = InstructionInfo::new("SWAP7", 0, 8, 8, GasPriceTier::VeryLow);
arr[SWAP8 as usize] = InstructionInfo::new("SWAP8", 0, 9, 9, GasPriceTier::VeryLow);
arr[SWAP9 as usize] = InstructionInfo::new("SWAP9", 0, 10, 10, GasPriceTier::VeryLow);
arr[SWAP10 as usize] = InstructionInfo::new("SWAP10", 0, 11, 11, GasPriceTier::VeryLow);
arr[SWAP11 as usize] = InstructionInfo::new("SWAP11", 0, 12, 12, GasPriceTier::VeryLow);
arr[SWAP12 as usize] = InstructionInfo::new("SWAP12", 0, 13, 13, GasPriceTier::VeryLow);
arr[SWAP13 as usize] = InstructionInfo::new("SWAP13", 0, 14, 14, GasPriceTier::VeryLow);
arr[SWAP14 as usize] = InstructionInfo::new("SWAP14", 0, 15, 15, GasPriceTier::VeryLow);
arr[SWAP15 as usize] = InstructionInfo::new("SWAP15", 0, 16, 16, GasPriceTier::VeryLow);
arr[SWAP16 as usize] = InstructionInfo::new("SWAP16", 0, 17, 17, GasPriceTier::VeryLow);
arr[LOG0 as usize] = InstructionInfo::new("LOG0", 0, 2, 0, GasPriceTier::Special);
arr[LOG1 as usize] = InstructionInfo::new("LOG1", 0, 3, 0, GasPriceTier::Special);
arr[LOG2 as usize] = InstructionInfo::new("LOG2", 0, 4, 0, GasPriceTier::Special);
arr[LOG3 as usize] = InstructionInfo::new("LOG3", 0, 5, 0, GasPriceTier::Special);
arr[LOG4 as usize] = InstructionInfo::new("LOG4", 0, 6, 0, GasPriceTier::Special);
arr[CREATE as usize] = InstructionInfo::new("CREATE", 0, 3, 1, GasPriceTier::Special);
arr[CALL as usize] = InstructionInfo::new("CALL", 0, 7, 1, GasPriceTier::Special);
arr[CALLCODE as usize] = InstructionInfo::new("CALLCODE", 0, 7, 1, GasPriceTier::Special);
arr[RETURN as usize] = InstructionInfo::new("RETURN", 0, 2, 0, GasPriceTier::Zero);
arr[DELEGATECALL as usize] = InstructionInfo::new("DELEGATECALL", 0, 6, 1, GasPriceTier::Special);
arr[SUICIDE as usize] = InstructionInfo::new("SUICIDE", 0, 1, 0, GasPriceTier::Special);
arr[CREATE2 as usize] = InstructionInfo::new("CREATE2", 0, 3, 1, GasPriceTier::Special);
arr[REVERT as usize] = InstructionInfo::new("REVERT", 0, 2, 0, GasPriceTier::Zero);
arr[STOP as usize] = InstructionInfo::new("STOP", 0, 0, GasPriceTier::Zero);
arr[ADD as usize] = InstructionInfo::new("ADD", 2, 1, GasPriceTier::VeryLow);
arr[SUB as usize] = InstructionInfo::new("SUB", 2, 1, GasPriceTier::VeryLow);
arr[MUL as usize] = InstructionInfo::new("MUL", 2, 1, GasPriceTier::Low);
arr[DIV as usize] = InstructionInfo::new("DIV", 2, 1, GasPriceTier::Low);
arr[SDIV as usize] = InstructionInfo::new("SDIV", 2, 1, GasPriceTier::Low);
arr[MOD as usize] = InstructionInfo::new("MOD", 2, 1, GasPriceTier::Low);
arr[SMOD as usize] = InstructionInfo::new("SMOD", 2, 1, GasPriceTier::Low);
arr[EXP as usize] = InstructionInfo::new("EXP", 2, 1, GasPriceTier::Special);
arr[NOT as usize] = InstructionInfo::new("NOT", 1, 1, GasPriceTier::VeryLow);
arr[LT as usize] = InstructionInfo::new("LT", 2, 1, GasPriceTier::VeryLow);
arr[GT as usize] = InstructionInfo::new("GT", 2, 1, GasPriceTier::VeryLow);
arr[SLT as usize] = InstructionInfo::new("SLT", 2, 1, GasPriceTier::VeryLow);
arr[SGT as usize] = InstructionInfo::new("SGT", 2, 1, GasPriceTier::VeryLow);
arr[EQ as usize] = InstructionInfo::new("EQ", 2, 1, GasPriceTier::VeryLow);
arr[ISZERO as usize] = InstructionInfo::new("ISZERO", 1, 1, GasPriceTier::VeryLow);
arr[AND as usize] = InstructionInfo::new("AND", 2, 1, GasPriceTier::VeryLow);
arr[OR as usize] = InstructionInfo::new("OR", 2, 1, GasPriceTier::VeryLow);
arr[XOR as usize] = InstructionInfo::new("XOR", 2, 1, GasPriceTier::VeryLow);
arr[BYTE as usize] = InstructionInfo::new("BYTE", 2, 1, GasPriceTier::VeryLow);
arr[ADDMOD as usize] = InstructionInfo::new("ADDMOD", 3, 1, GasPriceTier::Mid);
arr[MULMOD as usize] = InstructionInfo::new("MULMOD", 3, 1, GasPriceTier::Mid);
arr[SIGNEXTEND as usize] = InstructionInfo::new("SIGNEXTEND", 2, 1, GasPriceTier::Low);
arr[RETURNDATASIZE as usize] = InstructionInfo::new("RETURNDATASIZE", 0, 1, GasPriceTier::Base);
arr[RETURNDATACOPY as usize] = InstructionInfo::new("RETURNDATACOPY", 3, 0, GasPriceTier::VeryLow);
arr[SHA3 as usize] = InstructionInfo::new("SHA3", 2, 1, GasPriceTier::Special);
arr[ADDRESS as usize] = InstructionInfo::new("ADDRESS", 0, 1, GasPriceTier::Base);
arr[BALANCE as usize] = InstructionInfo::new("BALANCE", 1, 1, GasPriceTier::Special);
arr[ORIGIN as usize] = InstructionInfo::new("ORIGIN", 0, 1, GasPriceTier::Base);
arr[CALLER as usize] = InstructionInfo::new("CALLER", 0, 1, GasPriceTier::Base);
arr[CALLVALUE as usize] = InstructionInfo::new("CALLVALUE", 0, 1, GasPriceTier::Base);
arr[CALLDATALOAD as usize] = InstructionInfo::new("CALLDATALOAD", 1, 1, GasPriceTier::VeryLow);
arr[CALLDATASIZE as usize] = InstructionInfo::new("CALLDATASIZE", 0, 1, GasPriceTier::Base);
arr[CALLDATACOPY as usize] = InstructionInfo::new("CALLDATACOPY", 3, 0, GasPriceTier::VeryLow);
arr[CODESIZE as usize] = InstructionInfo::new("CODESIZE", 0, 1, GasPriceTier::Base);
arr[CODECOPY as usize] = InstructionInfo::new("CODECOPY", 3, 0, GasPriceTier::VeryLow);
arr[GASPRICE as usize] = InstructionInfo::new("GASPRICE", 0, 1, GasPriceTier::Base);
arr[EXTCODESIZE as usize] = InstructionInfo::new("EXTCODESIZE", 1, 1, GasPriceTier::Special);
arr[EXTCODECOPY as usize] = InstructionInfo::new("EXTCODECOPY", 4, 0, GasPriceTier::Special);
arr[BLOCKHASH as usize] = InstructionInfo::new("BLOCKHASH", 1, 1, GasPriceTier::Ext);
arr[COINBASE as usize] = InstructionInfo::new("COINBASE", 0, 1, GasPriceTier::Base);
arr[TIMESTAMP as usize] = InstructionInfo::new("TIMESTAMP", 0, 1, GasPriceTier::Base);
arr[NUMBER as usize] = InstructionInfo::new("NUMBER", 0, 1, GasPriceTier::Base);
arr[DIFFICULTY as usize] = InstructionInfo::new("DIFFICULTY", 0, 1, GasPriceTier::Base);
arr[GASLIMIT as usize] = InstructionInfo::new("GASLIMIT", 0, 1, GasPriceTier::Base);
arr[POP as usize] = InstructionInfo::new("POP", 1, 0, GasPriceTier::Base);
arr[MLOAD as usize] = InstructionInfo::new("MLOAD", 1, 1, GasPriceTier::VeryLow);
arr[MSTORE as usize] = InstructionInfo::new("MSTORE", 2, 0, GasPriceTier::VeryLow);
arr[MSTORE8 as usize] = InstructionInfo::new("MSTORE8", 2, 0, GasPriceTier::VeryLow);
arr[SLOAD as usize] = InstructionInfo::new("SLOAD", 1, 1, GasPriceTier::Special);
arr[SSTORE as usize] = InstructionInfo::new("SSTORE", 2, 0, GasPriceTier::Special);
arr[JUMP as usize] = InstructionInfo::new("JUMP", 1, 0, GasPriceTier::Mid);
arr[JUMPI as usize] = InstructionInfo::new("JUMPI", 2, 0, GasPriceTier::High);
arr[PC as usize] = InstructionInfo::new("PC", 0, 1, GasPriceTier::Base);
arr[MSIZE as usize] = InstructionInfo::new("MSIZE", 0, 1, GasPriceTier::Base);
arr[GAS as usize] = InstructionInfo::new("GAS", 0, 1, GasPriceTier::Base);
arr[JUMPDEST as usize] = InstructionInfo::new("JUMPDEST", 0, 0, GasPriceTier::Special);
arr[PUSH1 as usize] = InstructionInfo::new("PUSH1", 0, 1, GasPriceTier::VeryLow);
arr[PUSH2 as usize] = InstructionInfo::new("PUSH2", 0, 1, GasPriceTier::VeryLow);
arr[PUSH3 as usize] = InstructionInfo::new("PUSH3", 0, 1, GasPriceTier::VeryLow);
arr[PUSH4 as usize] = InstructionInfo::new("PUSH4", 0, 1, GasPriceTier::VeryLow);
arr[PUSH5 as usize] = InstructionInfo::new("PUSH5", 0, 1, GasPriceTier::VeryLow);
arr[PUSH6 as usize] = InstructionInfo::new("PUSH6", 0, 1, GasPriceTier::VeryLow);
arr[PUSH7 as usize] = InstructionInfo::new("PUSH7", 0, 1, GasPriceTier::VeryLow);
arr[PUSH8 as usize] = InstructionInfo::new("PUSH8", 0, 1, GasPriceTier::VeryLow);
arr[PUSH9 as usize] = InstructionInfo::new("PUSH9", 0, 1, GasPriceTier::VeryLow);
arr[PUSH10 as usize] = InstructionInfo::new("PUSH10", 0, 1, GasPriceTier::VeryLow);
arr[PUSH11 as usize] = InstructionInfo::new("PUSH11", 0, 1, GasPriceTier::VeryLow);
arr[PUSH12 as usize] = InstructionInfo::new("PUSH12", 0, 1, GasPriceTier::VeryLow);
arr[PUSH13 as usize] = InstructionInfo::new("PUSH13", 0, 1, GasPriceTier::VeryLow);
arr[PUSH14 as usize] = InstructionInfo::new("PUSH14", 0, 1, GasPriceTier::VeryLow);
arr[PUSH15 as usize] = InstructionInfo::new("PUSH15", 0, 1, GasPriceTier::VeryLow);
arr[PUSH16 as usize] = InstructionInfo::new("PUSH16", 0, 1, GasPriceTier::VeryLow);
arr[PUSH17 as usize] = InstructionInfo::new("PUSH17", 0, 1, GasPriceTier::VeryLow);
arr[PUSH18 as usize] = InstructionInfo::new("PUSH18", 0, 1, GasPriceTier::VeryLow);
arr[PUSH19 as usize] = InstructionInfo::new("PUSH19", 0, 1, GasPriceTier::VeryLow);
arr[PUSH20 as usize] = InstructionInfo::new("PUSH20", 0, 1, GasPriceTier::VeryLow);
arr[PUSH21 as usize] = InstructionInfo::new("PUSH21", 0, 1, GasPriceTier::VeryLow);
arr[PUSH22 as usize] = InstructionInfo::new("PUSH22", 0, 1, GasPriceTier::VeryLow);
arr[PUSH23 as usize] = InstructionInfo::new("PUSH23", 0, 1, GasPriceTier::VeryLow);
arr[PUSH24 as usize] = InstructionInfo::new("PUSH24", 0, 1, GasPriceTier::VeryLow);
arr[PUSH25 as usize] = InstructionInfo::new("PUSH25", 0, 1, GasPriceTier::VeryLow);
arr[PUSH26 as usize] = InstructionInfo::new("PUSH26", 0, 1, GasPriceTier::VeryLow);
arr[PUSH27 as usize] = InstructionInfo::new("PUSH27", 0, 1, GasPriceTier::VeryLow);
arr[PUSH28 as usize] = InstructionInfo::new("PUSH28", 0, 1, GasPriceTier::VeryLow);
arr[PUSH29 as usize] = InstructionInfo::new("PUSH29", 0, 1, GasPriceTier::VeryLow);
arr[PUSH30 as usize] = InstructionInfo::new("PUSH30", 0, 1, GasPriceTier::VeryLow);
arr[PUSH31 as usize] = InstructionInfo::new("PUSH31", 0, 1, GasPriceTier::VeryLow);
arr[PUSH32 as usize] = InstructionInfo::new("PUSH32", 0, 1, GasPriceTier::VeryLow);
arr[DUP1 as usize] = InstructionInfo::new("DUP1", 1, 2, GasPriceTier::VeryLow);
arr[DUP2 as usize] = InstructionInfo::new("DUP2", 2, 3, GasPriceTier::VeryLow);
arr[DUP3 as usize] = InstructionInfo::new("DUP3", 3, 4, GasPriceTier::VeryLow);
arr[DUP4 as usize] = InstructionInfo::new("DUP4", 4, 5, GasPriceTier::VeryLow);
arr[DUP5 as usize] = InstructionInfo::new("DUP5", 5, 6, GasPriceTier::VeryLow);
arr[DUP6 as usize] = InstructionInfo::new("DUP6", 6, 7, GasPriceTier::VeryLow);
arr[DUP7 as usize] = InstructionInfo::new("DUP7", 7, 8, GasPriceTier::VeryLow);
arr[DUP8 as usize] = InstructionInfo::new("DUP8", 8, 9, GasPriceTier::VeryLow);
arr[DUP9 as usize] = InstructionInfo::new("DUP9", 9, 10, GasPriceTier::VeryLow);
arr[DUP10 as usize] = InstructionInfo::new("DUP10", 10, 11, GasPriceTier::VeryLow);
arr[DUP11 as usize] = InstructionInfo::new("DUP11", 11, 12, GasPriceTier::VeryLow);
arr[DUP12 as usize] = InstructionInfo::new("DUP12", 12, 13, GasPriceTier::VeryLow);
arr[DUP13 as usize] = InstructionInfo::new("DUP13", 13, 14, GasPriceTier::VeryLow);
arr[DUP14 as usize] = InstructionInfo::new("DUP14", 14, 15, GasPriceTier::VeryLow);
arr[DUP15 as usize] = InstructionInfo::new("DUP15", 15, 16, GasPriceTier::VeryLow);
arr[DUP16 as usize] = InstructionInfo::new("DUP16", 16, 17, GasPriceTier::VeryLow);
arr[SWAP1 as usize] = InstructionInfo::new("SWAP1", 2, 2, GasPriceTier::VeryLow);
arr[SWAP2 as usize] = InstructionInfo::new("SWAP2", 3, 3, GasPriceTier::VeryLow);
arr[SWAP3 as usize] = InstructionInfo::new("SWAP3", 4, 4, GasPriceTier::VeryLow);
arr[SWAP4 as usize] = InstructionInfo::new("SWAP4", 5, 5, GasPriceTier::VeryLow);
arr[SWAP5 as usize] = InstructionInfo::new("SWAP5", 6, 6, GasPriceTier::VeryLow);
arr[SWAP6 as usize] = InstructionInfo::new("SWAP6", 7, 7, GasPriceTier::VeryLow);
arr[SWAP7 as usize] = InstructionInfo::new("SWAP7", 8, 8, GasPriceTier::VeryLow);
arr[SWAP8 as usize] = InstructionInfo::new("SWAP8", 9, 9, GasPriceTier::VeryLow);
arr[SWAP9 as usize] = InstructionInfo::new("SWAP9", 10, 10, GasPriceTier::VeryLow);
arr[SWAP10 as usize] = InstructionInfo::new("SWAP10", 11, 11, GasPriceTier::VeryLow);
arr[SWAP11 as usize] = InstructionInfo::new("SWAP11", 12, 12, GasPriceTier::VeryLow);
arr[SWAP12 as usize] = InstructionInfo::new("SWAP12", 13, 13, GasPriceTier::VeryLow);
arr[SWAP13 as usize] = InstructionInfo::new("SWAP13", 14, 14, GasPriceTier::VeryLow);
arr[SWAP14 as usize] = InstructionInfo::new("SWAP14", 15, 15, GasPriceTier::VeryLow);
arr[SWAP15 as usize] = InstructionInfo::new("SWAP15", 16, 16, GasPriceTier::VeryLow);
arr[SWAP16 as usize] = InstructionInfo::new("SWAP16", 17, 17, GasPriceTier::VeryLow);
arr[LOG0 as usize] = InstructionInfo::new("LOG0", 2, 0, GasPriceTier::Special);
arr[LOG1 as usize] = InstructionInfo::new("LOG1", 3, 0, GasPriceTier::Special);
arr[LOG2 as usize] = InstructionInfo::new("LOG2", 4, 0, GasPriceTier::Special);
arr[LOG3 as usize] = InstructionInfo::new("LOG3", 5, 0, GasPriceTier::Special);
arr[LOG4 as usize] = InstructionInfo::new("LOG4", 6, 0, GasPriceTier::Special);
arr[CREATE as usize] = InstructionInfo::new("CREATE", 3, 1, GasPriceTier::Special);
arr[CALL as usize] = InstructionInfo::new("CALL", 7, 1, GasPriceTier::Special);
arr[CALLCODE as usize] = InstructionInfo::new("CALLCODE", 7, 1, GasPriceTier::Special);
arr[RETURN as usize] = InstructionInfo::new("RETURN", 2, 0, GasPriceTier::Zero);
arr[DELEGATECALL as usize] = InstructionInfo::new("DELEGATECALL", 6, 1, GasPriceTier::Special);
arr[SUICIDE as usize] = InstructionInfo::new("SUICIDE", 1, 0, GasPriceTier::Special);
arr[CREATE2 as usize] = InstructionInfo::new("CREATE2", 3, 1, GasPriceTier::Special);
arr[REVERT as usize] = InstructionInfo::new("REVERT", 2, 0, GasPriceTier::Zero);
arr
};
}

View File

@ -1,6 +1,6 @@
{
"name": "parity.js",
"version": "1.7.89",
"version": "1.7.90",
"main": "release/index.js",
"jsnext:main": "src/index.js",
"author": "Parity Team <admin@parity.io>",

View File

@ -177,6 +177,7 @@ export default class Contract {
return null;
}
try {
const decoded = event.decodeLog(log.topics, log.data);
log.params = {};
@ -190,6 +191,12 @@ export default class Contract {
});
return log;
} catch (error) {
console.warn('Error decoding log', log);
console.warn(error);
return null;
}
})
.filter((log) => log);
}

View File

@ -16,45 +16,79 @@
//! A map of subscribers.
use std::ops;
use std::{ops, str};
use std::collections::HashMap;
use jsonrpc_macros::pubsub::{Subscriber, Sink, SubscriptionId};
use rand::{Rng, StdRng};
use v1::types::H64;
#[derive(Clone, Debug)]
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
pub struct Id(H64);
impl str::FromStr for Id {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.starts_with("0x") {
Ok(Id(s[2..].parse().map_err(|e| format!("{}", e))?))
} else {
Err("The id must start with 0x".into())
}
}
}
impl Id {
pub fn as_string(&self) -> String {
format!("0x{:?}", self.0)
}
}
#[derive(Clone)]
pub struct Subscribers<T> {
next_id: u64,
subscriptions: HashMap<u64, T>,
rand: StdRng,
subscriptions: HashMap<Id, T>,
}
impl<T> Default for Subscribers<T> {
fn default() -> Self {
Subscribers {
next_id: 0,
rand: StdRng::new().expect("Valid random source is required."),
subscriptions: HashMap::new(),
}
}
}
impl<T> Subscribers<T> {
fn next_id(&mut self) -> u64 {
self.next_id += 1;
self.next_id
/// Create a new Subscribers with given random source.
#[cfg(test)]
pub fn new_test() -> Self {
Subscribers {
rand: ::rand::SeedableRng::from_seed([0usize].as_ref()),
subscriptions: HashMap::new(),
}
}
fn next_id(&mut self) -> Id {
let mut data = H64::default();
self.rand.fill_bytes(&mut data.0);
Id(data)
}
/// Insert new subscription and return assigned id.
pub fn insert(&mut self, val: T) -> SubscriptionId {
let id = self.next_id();
debug!(target: "pubsub", "Adding subscription id={}", id);
debug!(target: "pubsub", "Adding subscription id={:?}", id);
let s = id.as_string();
self.subscriptions.insert(id, val);
SubscriptionId::Number(id)
SubscriptionId::String(s)
}
/// Removes subscription with given id and returns it (if any).
pub fn remove(&mut self, id: &SubscriptionId) -> Option<T> {
trace!(target: "pubsub", "Removing subscription id={:?}", id);
match *id {
SubscriptionId::Number(id) => {
self.subscriptions.remove(&id)
SubscriptionId::String(ref id) => match id.parse() {
Ok(id) => self.subscriptions.remove(&id),
Err(_) => None,
},
_ => None,
}
@ -65,20 +99,15 @@ impl <T> Subscribers<Sink<T>> {
/// Assigns id and adds a subscriber to the list.
pub fn push(&mut self, sub: Subscriber<T>) {
let id = self.next_id();
match sub.assign_id(SubscriptionId::Number(id)) {
Ok(sink) => {
if let Ok(sink) = sub.assign_id(SubscriptionId::String(id.as_string())) {
debug!(target: "pubsub", "Adding subscription id={:?}", id);
self.subscriptions.insert(id, sink);
},
Err(_) => {
self.next_id -= 1;
},
}
}
}
impl<T> ops::Deref for Subscribers<T> {
type Target = HashMap<u64, T>;
type Target = HashMap<Id, T>;
fn deref(&self) -> &Self::Target {
&self.subscriptions

View File

@ -54,6 +54,14 @@ impl<S: core::Middleware<Metadata>> GenericPollManager<S> {
}
}
/// Creates new poll manager with deterministic ids.
#[cfg(test)]
pub fn new_test(rpc: MetaIoHandler<Metadata, S>) -> Self {
let mut manager = Self::new(rpc);
manager.subscribers = Subscribers::new_test();
manager
}
/// Subscribes to update from polling given method.
pub fn subscribe(&mut self, metadata: Metadata, method: String, params: core::Params)
-> (SubscriptionId, mpsc::Receiver<Result<core::Value, core::Error>>)
@ -81,7 +89,7 @@ impl<S: core::Middleware<Metadata>> GenericPollManager<S> {
for (id, subscription) in self.subscribers.iter() {
let call = core::MethodCall {
jsonrpc: Some(core::Version::V2),
id: core::Id::Num(*id as u64),
id: core::Id::Str(id.as_string()),
method: subscription.method.clone(),
params: Some(subscription.params.clone()),
};
@ -139,7 +147,7 @@ mod tests {
Ok(Value::String("world".into()))
}
});
GenericPollManager::new(io)
GenericPollManager::new_test(io)
}
#[test]
@ -148,7 +156,7 @@ mod tests {
let mut el = reactor::Core::new().unwrap();
let mut poll_manager = poll_manager();
let (id, rx) = poll_manager.subscribe(Default::default(), "hello".into(), Params::None);
assert_eq!(id, SubscriptionId::Number(1));
assert_eq!(id, SubscriptionId::String("0x416d77337e24399d".into()));
// then
poll_manager.tick().wait().unwrap();

View File

@ -48,14 +48,22 @@ impl<C> EthPubSubClient<C> {
let heads_subscribers = Arc::new(Mutex::new(Subscribers::default()));
EthPubSubClient {
handler: Arc::new(ChainNotificationHandler {
client: client,
remote: remote,
client,
remote,
heads_subscribers: heads_subscribers.clone(),
}),
heads_subscribers: heads_subscribers,
heads_subscribers,
}
}
/// Creates new `EthPubSubCient` with deterministic subscription ids.
#[cfg(test)]
pub fn new_test(client: Arc<C>, remote: Remote) -> Self {
let client = Self::new(client, remote);
*client.heads_subscribers.lock() = Subscribers::new_test();
client
}
/// Returns a chain notification handler.
pub fn handler(&self) -> Arc<ChainNotificationHandler<C>> {
self.handler.clone()

View File

@ -56,12 +56,22 @@ impl<S: core::Middleware<Metadata>> PubSubClient<S> {
);
PubSubClient {
poll_manager: poll_manager,
remote: remote,
poll_manager,
remote,
}
}
}
impl PubSubClient<core::NoopMiddleware> {
/// Creates new `PubSubClient` with deterministic ids.
#[cfg(test)]
pub fn new_test(rpc: MetaIoHandler<Metadata, core::NoopMiddleware>, remote: Remote) -> Self {
let client = Self::new(MetaIoHandler::with_middleware(Default::default()), remote);
*client.poll_manager.write() = GenericPollManager::new_test(rpc);
client
}
}
impl<S: core::Middleware<Metadata>> PubSub for PubSubClient<S> {
type Metadata = Metadata;

View File

@ -36,7 +36,7 @@ fn should_subscribe_to_new_heads() {
let h2 = client.block_hash_delta_minus(2);
let h1 = client.block_hash_delta_minus(3);
let pubsub = EthPubSubClient::new(Arc::new(client), el.remote());
let pubsub = EthPubSubClient::new_test(Arc::new(client), el.remote());
let handler = pubsub.handler();
let pubsub = pubsub.to_delegate();
@ -49,13 +49,13 @@ fn should_subscribe_to_new_heads() {
// Subscribe
let request = r#"{"jsonrpc": "2.0", "method": "eth_subscribe", "params": ["newHeads"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":1,"id":1}"#;
let response = r#"{"jsonrpc":"2.0","result":"0x416d77337e24399d","id":1}"#;
assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned()));
// Check notifications
handler.new_blocks(vec![], vec![], vec![h1], vec![], vec![], vec![], 0);
let (res, receiver) = receiver.into_future().wait().unwrap();
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x1","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x1","parentHash":"0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":1}}"#;
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x1","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x1","parentHash":"0x0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x416d77337e24399d"}}"#;
assert_eq!(res, Some(response.into()));
// Notify about two blocks
@ -63,14 +63,14 @@ fn should_subscribe_to_new_heads() {
// Receive both
let (res, receiver) = receiver.into_future().wait().unwrap();
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x2","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x44e5ecf454ea99af9d8a8f2ca0daba96964c90de05db7a78f59b84ae9e749706","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x2","parentHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":1}}"#;
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x2","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0x44e5ecf454ea99af9d8a8f2ca0daba96964c90de05db7a78f59b84ae9e749706","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x2","parentHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x416d77337e24399d"}}"#;
assert_eq!(res, Some(response.into()));
let (res, receiver) = receiver.into_future().wait().unwrap();
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x3","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0xdf04a98bb0c6fa8441bd429822f65a46d0cb553f6bcef602b973e65c81497f8e","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x3","parentHash":"0x44e5ecf454ea99af9d8a8f2ca0daba96964c90de05db7a78f59b84ae9e749706","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":1}}"#;
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"author":"0x0000000000000000000000000000000000000000","difficulty":"0x3","extraData":"0x","gasLimit":"0xf4240","gasUsed":"0x0","hash":"0xdf04a98bb0c6fa8441bd429822f65a46d0cb553f6bcef602b973e65c81497f8e","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","miner":"0x0000000000000000000000000000000000000000","number":"0x3","parentHash":"0x44e5ecf454ea99af9d8a8f2ca0daba96964c90de05db7a78f59b84ae9e749706","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","sealFields":[],"sha3Uncles":"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347","size":"0x1c9","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","timestamp":"0x0","transactionsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"},"subscription":"0x416d77337e24399d"}}"#;
assert_eq!(res, Some(response.into()));
// And unsubscribe
let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": [1], "id": 1}"#;
let request = r#"{"jsonrpc": "2.0", "method": "eth_unsubscribe", "params": ["0x416d77337e24399d"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
assert_eq!(io.handle_request_sync(request, metadata), Some(response.to_owned()));
@ -83,7 +83,7 @@ fn should_return_unimplemented() {
// given
let el = EventLoop::spawn();
let client = TestBlockChainClient::new();
let pubsub = EthPubSubClient::new(Arc::new(client), el.remote());
let pubsub = EthPubSubClient::new_test(Arc::new(client), el.remote());
let pubsub = pubsub.to_delegate();
let mut io = MetaIoHandler::default();

View File

@ -42,7 +42,7 @@ fn should_subscribe_to_a_method() {
// given
let el = EventLoop::spawn();
let rpc = rpc();
let pubsub = PubSubClient::new(rpc, el.remote()).to_delegate();
let pubsub = PubSubClient::new_test(rpc, el.remote()).to_delegate();
let mut io = MetaIoHandler::default();
io.extend_with(pubsub);
@ -52,21 +52,23 @@ fn should_subscribe_to_a_method() {
metadata.session = Some(Arc::new(Session::new(sender)));
// Subscribe
let request = r#"{"jsonrpc": "2.0", "method": "parity_subscribe", "params": ["hello"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":1,"id":1}"#;
let request = r#"{"jsonrpc": "2.0", "method": "parity_subscribe", "params": ["hello", []], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":"0x416d77337e24399d","id":1}"#;
assert_eq!(io.handle_request_sync(request, metadata.clone()), Some(response.to_owned()));
// Check notifications
let (res, receiver) = receiver.into_future().wait().unwrap();
let response = r#"{"jsonrpc":"2.0","method":"parity_subscription","params":{"result":"hello","subscription":1}}"#;
let response =
r#"{"jsonrpc":"2.0","method":"parity_subscription","params":{"result":"hello","subscription":"0x416d77337e24399d"}}"#;
assert_eq!(res, Some(response.into()));
let (res, receiver) = receiver.into_future().wait().unwrap();
let response = r#"{"jsonrpc":"2.0","method":"parity_subscription","params":{"result":"world","subscription":1}}"#;
let response =
r#"{"jsonrpc":"2.0","method":"parity_subscription","params":{"result":"world","subscription":"0x416d77337e24399d"}}"#;
assert_eq!(res, Some(response.into()));
// And unsubscribe
let request = r#"{"jsonrpc": "2.0", "method": "parity_unsubscribe", "params": [1], "id": 1}"#;
let request = r#"{"jsonrpc": "2.0", "method": "parity_unsubscribe", "params": ["0x416d77337e24399d"], "id": 1}"#;
let response = r#"{"jsonrpc":"2.0","result":true,"id":1}"#;
assert_eq!(io.handle_request_sync(request, metadata), Some(response.to_owned()));