Skip to content

Commit

Permalink
/send_raw_transaction, /save_bc, response_base
Browse files Browse the repository at this point in the history
  • Loading branch information
hinto-janai committed Dec 14, 2024
1 parent d4b3033 commit b3314d4
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 136 deletions.
14 changes: 7 additions & 7 deletions binaries/cuprated/src/rpc/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async fn get_blocks(
}

Ok(GetBlocksResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
blocks: todo!(),
start_height: todo!(),
current_height: todo!(),
Expand All @@ -136,7 +136,7 @@ async fn get_blocks_by_height(
.collect::<Result<Vec<BlockCompleteEntry>, Error>>()?;

Ok(GetBlocksByHeightResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
blocks,
})
}
Expand Down Expand Up @@ -178,7 +178,7 @@ async fn get_hashes(
let m_blocks_ids = bytes.split_off(index);

Ok(GetHashesResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
m_blocks_ids,
start_height,
current_height,
Expand All @@ -191,7 +191,7 @@ async fn get_output_indexes(
request: GetOutputIndexesRequest,
) -> Result<GetOutputIndexesResponse, Error> {
Ok(GetOutputIndexesResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
..todo!()
})
}
Expand All @@ -202,7 +202,7 @@ async fn get_outs(
request: GetOutsRequest,
) -> Result<GetOutsResponse, Error> {
Ok(GetOutsResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
..todo!()
})
}
Expand All @@ -213,7 +213,7 @@ async fn get_transaction_pool_hashes(
request: GetTransactionPoolHashesRequest,
) -> Result<GetTransactionPoolHashesResponse, Error> {
Ok(GetTransactionPoolHashesResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
..todo!()
})
}
Expand All @@ -224,7 +224,7 @@ async fn get_output_distribution(
request: GetOutputDistributionRequest,
) -> Result<GetOutputDistributionResponse, Error> {
Ok(GetOutputDistributionResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
..todo!()
})
}
4 changes: 4 additions & 0 deletions binaries/cuprated/src/rpc/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub enum BlockchainManagerRequest {
Box<Block>,
),

/// TODO
Sync,

/// Is the blockchain in the middle of syncing?
///
/// This returning `false` does not necessarily
Expand Down Expand Up @@ -102,6 +105,7 @@ pub enum BlockchainManagerResponse {
/// Response to:
/// - [`BlockchainManagerRequest::Prune`]
/// - [`BlockchainManagerRequest::RelayBlock`]
/// - [`BlockchainManagerRequest::Sync`]
Ok,

/// Response to [`BlockchainManagerRequest::PopBlocks`]
Expand Down
23 changes: 22 additions & 1 deletion binaries/cuprated/src/rpc/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use cuprate_helper::{
cast::{u64_to_usize, usize_to_u64},
map::split_u128_into_low_high_bits,
};
use cuprate_rpc_types::misc::BlockHeader;
use cuprate_rpc_types::{
base::{AccessResponseBase, ResponseBase},
misc::BlockHeader,
};
use cuprate_types::HardFork;

use crate::{
Expand Down Expand Up @@ -166,3 +169,21 @@ pub(super) async fn top_height(state: &mut CupratedRpcHandler) -> Result<(u64, [
let height = chain_height.saturating_sub(1);
Ok((height, hash))
}

/// TODO
pub const fn response_base(is_bootstrap: bool) -> ResponseBase {
if is_bootstrap {
ResponseBase::OK_UNTRUSTED
} else {
ResponseBase::OK
}
}

/// TODO
pub const fn access_response_base(is_bootstrap: bool) -> AccessResponseBase {
if is_bootstrap {
AccessResponseBase::OK_UNTRUSTED
} else {
AccessResponseBase::OK
}
}
54 changes: 27 additions & 27 deletions binaries/cuprated/src/rpc/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ async fn get_block_template(
let wide_difficulty = (difficulty, difficulty_top64).hex_prefix();

Ok(GetBlockTemplateResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
blockhashing_blob,
blocktemplate_blob,
difficulty_top64,
Expand All @@ -215,7 +215,7 @@ async fn get_block_count(
_: GetBlockCountRequest,
) -> Result<GetBlockCountResponse, Error> {
Ok(GetBlockCountResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
count: helper::top_height(&mut state).await?.0,
})
}
Expand Down Expand Up @@ -253,7 +253,7 @@ async fn submit_block(
blockchain_manager::relay_block(&mut state.blockchain_manager, Box::new(block)).await?;

Ok(SubmitBlockResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
block_id,
})
}
Expand Down Expand Up @@ -288,7 +288,7 @@ async fn generate_blocks(
let blocks = blocks.into_iter().map(Hex).collect();

Ok(GenerateBlocksResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
blocks,
height,
})
Expand All @@ -303,7 +303,7 @@ async fn get_last_block_header(
let block_header = helper::block_header(&mut state, height, request.fill_pow_hash).await?;

Ok(GetLastBlockHeaderResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
block_header,
})
}
Expand Down Expand Up @@ -338,7 +338,7 @@ async fn get_block_header_by_hash(
}

Ok(GetBlockHeaderByHashResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
block_header,
block_headers,
})
Expand All @@ -354,7 +354,7 @@ async fn get_block_header_by_height(
helper::block_header(&mut state, request.height, request.fill_pow_hash).await?;

Ok(GetBlockHeaderByHeightResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
block_header,
})
}
Expand Down Expand Up @@ -409,7 +409,7 @@ async fn get_block_headers_range(
}

Ok(GetBlockHeadersRangeResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
headers,
})
}
Expand Down Expand Up @@ -442,7 +442,7 @@ async fn get_block(
};

Ok(GetBlockResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
blob,
json,
miner_tx_hash,
Expand All @@ -459,7 +459,7 @@ async fn get_connections(
let connections = address_book::connection_info::<ClearNet>(&mut DummyAddressBook).await?;

Ok(GetConnectionsResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
connections,
})
}
Expand Down Expand Up @@ -557,7 +557,7 @@ async fn get_info(
let wide_difficulty = format!("{:#x}", c.next_difficulty);

Ok(GetInfoResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
adjusted_time,
alt_blocks_count,
block_size_limit,
Expand Down Expand Up @@ -617,7 +617,7 @@ async fn hard_fork_info(
let info = blockchain_context::hard_fork_info(&mut state.blockchain_context, hard_fork).await?;

Ok(HardForkInfoResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
earliest_height: info.earliest_height,
enabled: info.enabled,
state: info.state,
Expand Down Expand Up @@ -654,7 +654,7 @@ async fn set_bans(
}

Ok(SetBansResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
})
}

Expand Down Expand Up @@ -694,7 +694,7 @@ async fn get_bans(state: CupratedRpcHandler, _: GetBansRequest) -> Result<GetBan
.collect();

Ok(GetBansResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
bans,
})
}
Expand Down Expand Up @@ -777,7 +777,7 @@ async fn get_output_histogram(
.collect();

Ok(GetOutputHistogramResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
histogram,
})
}
Expand All @@ -800,7 +800,7 @@ async fn get_coinbase_tx_sum(
let wide_fee_amount = format!("{emission_amount:#x}");

Ok(GetCoinbaseTxSumResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
emission_amount,
emission_amount_top64,
fee_amount,
Expand Down Expand Up @@ -835,7 +835,7 @@ async fn get_version(
}

Ok(GetVersionResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
version: CORE_RPC_VERSION,
release: RELEASE,
current_height,
Expand All @@ -854,7 +854,7 @@ async fn get_fee_estimate(
.await?;

Ok(GetFeeEstimateResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
fee: estimate.fee,
fees: estimate.fees,
quantization_mask: estimate.quantization_mask,
Expand All @@ -873,7 +873,7 @@ async fn get_alternate_chains(
.collect();

Ok(GetAlternateChainsResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
chains,
})
}
Expand Down Expand Up @@ -925,7 +925,7 @@ async fn sync_info(
let overview = String::from(FIELD_NOT_SUPPORTED);

Ok(SyncInfoResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
height,
next_needed_pruning_seed,
overview,
Expand All @@ -951,7 +951,7 @@ async fn get_transaction_pool_backlog(
.collect();

Ok(GetTransactionPoolBacklogResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
backlog,
})
}
Expand Down Expand Up @@ -984,7 +984,7 @@ async fn get_output_distribution(
}).collect::<Result<Vec<Distribution>, _>>()?;

Ok(GetOutputDistributionResponse {
base: AccessResponseBase::OK,
base: helper::access_response_base(false),
distributions,
})
}
Expand Down Expand Up @@ -1015,7 +1015,7 @@ async fn get_miner_data(
.collect();

Ok(GetMinerDataResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
major_version,
height,
prev_id,
Expand All @@ -1038,7 +1038,7 @@ async fn prune_blockchain(
.compress();

Ok(PruneBlockchainResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
pruned,
pruning_seed,
})
Expand Down Expand Up @@ -1090,7 +1090,7 @@ async fn flush_cache(
// TODO: cuprated doesn't need this call; decide behavior.

Ok(FlushCacheResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
})
}

Expand Down Expand Up @@ -1288,7 +1288,7 @@ fn add_aux_pow_inner(
let aux_pow = aux_pow.into_vec();

Ok(AddAuxPowResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
blocktemplate_blob,
blockhashing_blob,
merkle_root,
Expand All @@ -1306,7 +1306,7 @@ async fn get_tx_ids_loose(
return Err(anyhow!("Not implemented"));

Ok(GetTxIdsLooseResponse {
base: ResponseBase::OK,
base: helper::response_base(false),
txids: todo!(),
})
}
Loading

0 comments on commit b3314d4

Please sign in to comment.