diff --git a/rpc/src/integration_test.rs b/rpc/src/integration_test.rs index 9fa43b3356..5055e3d5e1 100644 --- a/rpc/src/integration_test.rs +++ b/rpc/src/integration_test.rs @@ -2,7 +2,7 @@ use bigint::H256; use chain::chain::ChainProvider; use ckb_pow::Clicker; use core::header::{BlockNumber, Header}; -use core::transaction::{CellOutput, Transaction}; +use core::transaction::{OutPoint, Transaction}; use jsonrpc_core::{Error, IoHandler, Result}; use jsonrpc_http_server::ServerBuilder; use jsonrpc_server_utils::cors::AccessControlAllowOrigin; @@ -11,7 +11,7 @@ use miner::{build_block_template, BlockTemplate}; use network::NetworkService; use pool::TransactionPool; use std::sync::Arc; -use {BlockWithHash, Config, TransactionWithHash}; +use {BlockWithHash, CellOutputWithOutPoint, Config, TransactionWithHash}; //TODO: build_rpc_trait! do not surppot trait bounds build_rpc_trait! { @@ -46,7 +46,7 @@ build_rpc_trait! { // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_cells_by_redeem_script_hash","params": ["0x1b1c832d02fdb4339f9868c8a8636c3d9dd10bd53ac7ce99595825bd6beeffb3", 1, 10]}' -H 'content-type:application/json' 'http://localhost:3030' #[rpc(name = "get_cells_by_redeem_script_hash")] - fn get_cells_by_redeem_script_hash(&self, H256, u64, u64) -> Result>; + fn get_cells_by_redeem_script_hash(&self, H256, u64, u64) -> Result>; #[rpc(name = "local_node_id")] fn local_node_id(&self) -> Result>; @@ -108,7 +108,7 @@ impl IntegrationTestRpc for RpcImpl { redeem_script_hash: H256, from: u64, to: u64, - ) -> Result> { + ) -> Result> { let mut result = Vec::new(); for block_number in from..=to { if let Some(block_hash) = self.chain.block_hash(block_number) { @@ -123,7 +123,11 @@ impl IntegrationTestRpc for RpcImpl { .ok_or_else(Error::internal_error)?; for (i, output) in transaction.outputs().iter().enumerate() { if output.lock == redeem_script_hash && (!transaction_meta.is_spent(i)) { - result.push(output.clone()); + result.push(CellOutputWithOutPoint { + outpoint: OutPoint::new(transaction.hash(), i as u32), + capacity: output.capacity, + lock: output.lock, + }); } } } diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 0f8d602a88..e3fb18f1d0 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -19,7 +19,7 @@ extern crate ckb_pow; use bigint::H256; use core::block::Block; use core::header::Header; -use core::transaction::Transaction; +use core::transaction::{Capacity, OutPoint, Transaction}; #[cfg(feature = "integration_test")] mod integration_test; @@ -67,6 +67,16 @@ impl From for BlockWithHash { } } +// This is used as return value of get_cells_by_redeem_script_hash RPC: +// it contains both OutPoint data used for referencing a cell, as well as +// cell's own data such as lock and capacity +#[derive(Serialize)] +pub struct CellOutputWithOutPoint { + pub outpoint: OutPoint, + pub capacity: Capacity, + pub lock: H256, +} + #[derive(Clone, Debug, PartialEq, Deserialize)] pub struct Config { pub listen_addr: String, diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index 501f48d262..cf900bc6c7 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -1,7 +1,7 @@ use bigint::H256; use chain::chain::ChainProvider; use core::header::{BlockNumber, Header}; -use core::transaction::{CellOutput, Transaction}; +use core::transaction::{OutPoint, Transaction}; use jsonrpc_core::{Error, IoHandler, Result}; use jsonrpc_http_server::ServerBuilder; use jsonrpc_server_utils::cors::AccessControlAllowOrigin; @@ -10,7 +10,7 @@ use miner::{build_block_template, BlockTemplate}; use network::NetworkService; use pool::TransactionPool; use std::sync::Arc; -use {BlockWithHash, Config, TransactionWithHash}; +use {BlockWithHash, CellOutputWithOutPoint, Config, TransactionWithHash}; build_rpc_trait! { pub trait Rpc { @@ -40,7 +40,7 @@ build_rpc_trait! { // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_cells_by_redeem_script_hash","params": ["0x1b1c832d02fdb4339f9868c8a8636c3d9dd10bd53ac7ce99595825bd6beeffb3", 1, 10]}' -H 'content-type:application/json' 'http://localhost:3030' #[rpc(name = "get_cells_by_redeem_script_hash")] - fn get_cells_by_redeem_script_hash(&self, H256, u64, u64) -> Result>; + fn get_cells_by_redeem_script_hash(&self, H256, u64, u64) -> Result>; } } @@ -90,7 +90,7 @@ impl Rpc for RpcImpl { redeem_script_hash: H256, from: u64, to: u64, - ) -> Result> { + ) -> Result> { let mut result = Vec::new(); for block_number in from..=to { if let Some(block_hash) = self.chain.block_hash(block_number) { @@ -105,7 +105,11 @@ impl Rpc for RpcImpl { .ok_or_else(Error::internal_error)?; for (i, output) in transaction.outputs().iter().enumerate() { if output.lock == redeem_script_hash && (!transaction_meta.is_spent(i)) { - result.push(output.clone()); + result.push(CellOutputWithOutPoint { + outpoint: OutPoint::new(transaction.hash(), i as u32), + capacity: output.capacity, + lock: output.lock, + }); } } }