Skip to content

Commit

Permalink
hashlookup bn e->d
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Aug 18, 2023
1 parent e37d4bb commit d393026
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
21 changes: 21 additions & 0 deletions lib/ain-rs-exports/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,27 @@ pub fn evm_try_get_block_number_by_hash(result: &mut ffi::CrossBoundaryResult, h
}
}

pub fn evm_try_get_dvm_block_number_by_number(
result: &mut ffi::CrossBoundaryResult,
number: u64,
) -> u64 {
match SERVICES.evm.storage.get_block_by_number(&U256::from(number)) {
Ok(Some(block)) => {
let extra_data = block.header.extra_data;
let data = String::from_utf8(extra_data.to_vec()).unwrap();
let Some(data) = data.split_whitespace().nth(1) else {
return cross_boundary_error_return(result, format!("Expected `DFI: <n>`, actual: {:?}", data));
};
let Ok(dvm_block_number) = data.parse::<u64>() else {
return cross_boundary_error_return(result, "Parse integer error");
};
cross_boundary_success_return(result, dvm_block_number)
}
Ok(None) => cross_boundary_error_return(result, "Invalid block number"),
Err(e) => cross_boundary_error_return(result, e.to_string()),
}
}

pub fn evm_try_get_block_header_by_hash(
result: &mut ffi::CrossBoundaryResult,
hash: &str,
Expand Down
4 changes: 4 additions & 0 deletions lib/ain-rs-exports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ pub mod ffi {
result: &mut CrossBoundaryResult,
hash: &str,
) -> EVMBlockHeader;
fn evm_try_get_dvm_block_number_by_number(
result: &mut CrossBoundaryResult,
height: u64,
) -> u64;
fn evm_try_get_block_count(result: &mut CrossBoundaryResult) -> u64;
fn evm_try_get_tx_by_hash(
result: &mut CrossBoundaryResult,
Expand Down
15 changes: 4 additions & 11 deletions src/masternodes/rpc_evm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,8 @@ UniValue vmmap(const JSONRPCRequest &request) {
throwInvalidParam(DeFiErrors::InvalidBlockNumberString(input).msg.c_str());
}
CrossBoundaryResult result;
auto evmHash = evm_try_get_block_hash_by_number(result, height);
auto evmBlockHash = std::string(evmHash.data(), evmHash.length());
uint64_t blockNumber = evm_try_get_dvm_block_number_by_number(result, height);
crossBoundaryOkOrThrow(result);
ResVal<uint256> dvm_block = pcustomcsview->GetVMDomainBlockEdge(VMDomainEdge::EVMToDVM, evmBlockHash);
if (!dvm_block) {
throwInvalidParam(dvm_block.msg);
}
CBlockIndex *pindex = LookupBlockIndex(*dvm_block.val);
uint64_t blockNumber = pindex->GetBlockHeader().deprecatedHeight;
return finalizeBlockNumberResult(blockNumber, VMDomainRPCMapType::BlockNumberEVMToDVM, height);
};

Expand Down Expand Up @@ -383,9 +376,9 @@ UniValue vmmap(const JSONRPCRequest &request) {
case VMDomainRPCMapType::BlockNumberDVMToEVM: {
return handleMapBlockNumberDVMToEVMRequest(input);
}
// case VMDomainRPCMapType::BlockNumberEVMToDVM: {
// return handleMapBlockNumberEVMToDVMRequest(input);
// }
case VMDomainRPCMapType::BlockNumberEVMToDVM: {
return handleMapBlockNumberEVMToDVMRequest(input);
}
default: {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown map type");
}
Expand Down

0 comments on commit d393026

Please sign in to comment.