diff --git a/docs/rpc/api/core-node/get-burn-ops.example.json b/docs/rpc/api/core-node/get-burn-ops.example.json index 641d2d320..37968ff28 100644 --- a/docs/rpc/api/core-node/get-burn-ops.example.json +++ b/docs/rpc/api/core-node/get-burn-ops.example.json @@ -6,7 +6,6 @@ "burn_header_hash": "66b2f18530ccf0e57e82dd054cca9fa41bf5f645f7757171ad9c1546b86387e1", "peg_wallet_address": "tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkgkkf5", "recipient": "S0000000000000000000002AA028H", - "recipient_contract_name": null, "txid": "84808f747841fb26e74f171487e56eda1a51373581eb04a8c87a421a77bd46d2", "vtxindex": 1 } diff --git a/src/chainstate/burn/mod.rs b/src/chainstate/burn/mod.rs index 204330b2c..656c8cc5f 100644 --- a/src/chainstate/burn/mod.rs +++ b/src/chainstate/burn/mod.rs @@ -212,24 +212,16 @@ impl Opcodes { } pub fn from_http_str(input: &str) -> Option { - let opcode = if input == Self::HTTP_PEG_IN { - Opcodes::PegIn - } else if input == Self::HTTP_BLOCK_COMMIT { - Opcodes::LeaderBlockCommit - } else if input == Self::HTTP_KEY_REGISTER { - Opcodes::LeaderKeyRegister - } else if input == Self::HTTP_BURN_SUPPORT { - Opcodes::UserBurnSupport - } else if input == Self::HTTP_STACK_STX { - Opcodes::StackStx - } else if input == Self::HTTP_PRE_STX { - Opcodes::PreStx - } else if input == Self::HTTP_TRANSFER_STX { - Opcodes::TransferStx - } else if input == Self::HTTP_DELEGATE_STX { - Opcodes::DelegateStx - } else { - return None; + let opcode = match input { + Self::HTTP_PEG_IN => Opcodes::PegIn, + Self::HTTP_BLOCK_COMMIT => Opcodes::LeaderBlockCommit, + Self::HTTP_KEY_REGISTER => Opcodes::LeaderKeyRegister, + Self::HTTP_BURN_SUPPORT => Opcodes::UserBurnSupport, + Self::HTTP_STACK_STX => Opcodes::StackStx, + Self::HTTP_PRE_STX => Opcodes::PreStx, + Self::HTTP_TRANSFER_STX => Opcodes::TransferStx, + Self::HTTP_DELEGATE_STX => Opcodes::DelegateStx, + _ => return None, }; Some(opcode) diff --git a/src/chainstate/burn/operations/mod.rs b/src/chainstate/burn/operations/mod.rs index 63b55ba01..ffb9c8fc6 100644 --- a/src/chainstate/burn/operations/mod.rs +++ b/src/chainstate/burn/operations/mod.rs @@ -371,15 +371,6 @@ pub enum BlockstackOperationType { PegIn(PegInOp), } -/// This enum wraps Vecs of a single kind of `BlockstackOperationType`. -/// This allows `handle_get_burn_ops` to use an enum for the different operation -/// types without having to buffer and re-structure a `Vec` -/// from a, e.g., `Vec` -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -pub enum BurnchainOpsVec { - PegIn(Vec), -} - impl BlockstackOperationType { pub fn opcode(&self) -> Opcodes { match *self { diff --git a/src/net/mod.rs b/src/net/mod.rs index 43c557b99..db4392ab8 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -46,7 +46,7 @@ use url; use crate::burnchains::affirmation::AffirmationMap; use crate::burnchains::Error as burnchain_error; use crate::burnchains::Txid; -use crate::chainstate::burn::operations::BurnchainOpsVec; +use crate::chainstate::burn::operations::PegInOp; use crate::chainstate::burn::{ConsensusHash, Opcodes}; use crate::chainstate::coordinator::Error as coordinator_error; use crate::chainstate::stacks::db::blocks::MemPoolRejection; @@ -1659,7 +1659,7 @@ pub enum HttpResponseType { NotFound(HttpResponseMetadata, String), ServerError(HttpResponseMetadata, String), ServiceUnavailable(HttpResponseMetadata, String), - GetBurnchainOps(HttpResponseMetadata, BurnchainOpsVec), + GetBurnchainOps(HttpResponseMetadata, BurnchainOps), Error(HttpResponseMetadata, u16, String), } @@ -1695,6 +1695,15 @@ pub enum StacksMessageID { Reserved = 255, } +/// This enum wraps Vecs of a single kind of `BlockstackOperationType`. +/// This allows `handle_get_burn_ops` to use an enum for the different operation +/// types without having to buffer and re-structure a `Vec` +/// from a, e.g., `Vec` +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub enum BurnchainOps { + PegIn(Vec), +} + /// Message type for all P2P Stacks network messages #[derive(Debug, Clone, PartialEq)] pub struct StacksMessage { diff --git a/src/net/rpc.rs b/src/net/rpc.rs index 14a94584c..e7205d1ba 100644 --- a/src/net/rpc.rs +++ b/src/net/rpc.rs @@ -36,7 +36,6 @@ use crate::burnchains::Burnchain; use crate::burnchains::BurnchainView; use crate::burnchains::*; use crate::chainstate::burn::db::sortdb::SortitionDB; -use crate::chainstate::burn::operations::BurnchainOpsVec; use crate::chainstate::burn::ConsensusHash; use crate::chainstate::burn::Opcodes; use crate::chainstate::stacks::db::blocks::CheckError; @@ -62,6 +61,7 @@ use crate::net::p2p::PeerMap; use crate::net::p2p::PeerNetwork; use crate::net::relay::Relayer; use crate::net::BlocksDatum; +use crate::net::BurnchainOps; use crate::net::Error as net_error; use crate::net::HttpRequestMetadata; use crate::net::HttpRequestType; @@ -771,7 +771,7 @@ impl ConversationHttp { SortitionDB::get_peg_in_ops(sortdb.conn(), &burn_header_hash).map(|ops| { HttpResponseType::GetBurnchainOps( response_metadata.clone(), - BurnchainOpsVec::PegIn(ops), + BurnchainOps::PegIn(ops), ) }) } diff --git a/testnet/stacks-node/src/tests/neon_integrations.rs b/testnet/stacks-node/src/tests/neon_integrations.rs index 79b0cd599..a0bd071e3 100644 --- a/testnet/stacks-node/src/tests/neon_integrations.rs +++ b/testnet/stacks-node/src/tests/neon_integrations.rs @@ -16,7 +16,6 @@ use rusqlite::types::ToSql; use stacks::burnchains::bitcoin::address::{BitcoinAddress, LegacyBitcoinAddressType}; use stacks::burnchains::bitcoin::BitcoinNetworkType; use stacks::burnchains::Txid; -use stacks::chainstate::burn::operations::BurnchainOpsVec; use stacks::chainstate::burn::operations::{ BlockstackOperationType, PegInOp, PreStxOp, TransferStxOp, }; @@ -31,6 +30,7 @@ use stacks::core::{ PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, PEER_VERSION_EPOCH_2_1, }; use stacks::net::atlas::{AtlasConfig, AtlasDB, MAX_ATTACHMENT_INV_PAGES_PER_REQUEST}; +use stacks::net::BurnchainOps; use stacks::net::{ AccountEntryResponse, ContractSrcResponse, GetAttachmentResponse, GetAttachmentsInvResponse, PostTransactionRequestBody, RPCPeerInfoData, StacksBlockAcceptedData, @@ -738,6 +738,18 @@ fn get_tip_anchored_block(conf: &Config) -> (ConsensusHash, StacksBlock) { (stacks_tip_consensus_hash, block) } +fn get_peg_in_ops(conf: &Config, height: u64) -> BurnchainOps { + let http_origin = format!("http://{}", &conf.node.rpc_bind); + let path = format!("{}/v2/burn_ops/{}/peg_in", &http_origin, height); + let client = reqwest::blocking::Client::new(); + + let response: serde_json::Value = client.get(&path).send().unwrap().json().unwrap(); + + eprintln!("{}", response); + + serde_json::from_value(response).unwrap() +} + fn find_microblock_privkey( conf: &Config, pubkey_hash: &Hash160, @@ -10509,20 +10521,8 @@ fn test_submit_and_observe_peg_in_request() { peg_in_op.peg_wallet_address ); - let query_block_height = parsed_peg_in_op.block_height; - - let http_origin = format!("http://{}", &conf.node.rpc_bind); - let path = format!("{}/v2/burn_ops/{}/peg_in", &http_origin, query_block_height); - let client = reqwest::blocking::Client::new(); - - let response: serde_json::Value = client.get(&path).send().unwrap().json().unwrap(); - - eprintln!("{}", response); - - let parsed_resp: BurnchainOpsVec = serde_json::from_value(response).unwrap(); - - let parsed_peg_in_op = match parsed_resp { - BurnchainOpsVec::PegIn(mut vec) => { + let parsed_peg_in_op = match get_peg_in_ops(&conf, parsed_peg_in_op.block_height) { + BurnchainOps::PegIn(mut vec) => { assert_eq!(vec.len(), 1); vec.pop().unwrap() }