Skip to content

Commit

Permalink
Merge pull request #53 from hax0kartik/rust-wrapper-cleanup
Browse files Browse the repository at this point in the history
General cleanup
  • Loading branch information
brunoerg authored Jul 1, 2024
2 parents 1b667c9 + 22293c3 commit 18b619a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
22 changes: 8 additions & 14 deletions rust_bitcoin_lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
use std::ffi::CStr;
use std::ffi::CString;
use std::os::raw::c_char;
use std::slice;
use std::str::FromStr;
use std::str::Utf8Error;
use std::os::raw::c_char;
use std::ffi::{CStr, CString};
use std::str::{FromStr, Utf8Error};

use bitcoin::bip152::PrefilledTransaction;
use bitcoin::bip152::HeaderAndShortIds;
use bitcoin::consensus::deserialize_partial;
use bitcoin::consensus::encode;
use bitcoin::Block;
use miniscript::bitcoin::script;
use bitcoin::bip152::{PrefilledTransaction,HeaderAndShortIds};
use bitcoin::consensus::{deserialize_partial, encode};

use miniscript::{Miniscript, Segwitv0, Tap};
use miniscript::bitcoin::{script, PublicKey};
use miniscript::bitcoin::secp256k1::XOnlyPublicKey;
use miniscript::bitcoin::PublicKey;
use miniscript::Miniscript;
use miniscript::Segwitv0;
use miniscript::Tap;

/// Creates a Rust str from a C string.
///
Expand Down
9 changes: 4 additions & 5 deletions targets/addrv2.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <fuzzer/FuzzedDataProvider.h>
#include <string>
#include <iostream>
#include <optional>
#include <stdio.h>

Expand All @@ -11,7 +10,7 @@
extern "C" bool rust_bitcoin_addrv2(uint8_t *data, size_t len, uint64_t *count);
extern "C" bool go_btcd_addrv2(uint8_t *data, size_t len, uint64_t *count);

std::optional<std::pair<uint64_t, uint64_t>> Core(Span<const uint8_t> buffer)
std::optional<std::pair<uint64_t, uint64_t>> Addrv2Core(Span<const uint8_t> buffer)
{
std::vector<CAddress> addrs;
DataStream ds{buffer};
Expand All @@ -34,9 +33,9 @@ void Addrv2(FuzzedDataProvider& provider)
{
std::vector<uint8_t> buffer{provider.ConsumeRemainingBytes<uint8_t>()};
uint64_t count_rust = 0, count_btcd = 0;
bool rust_bitcoin{rust_bitcoin_addrv2(buffer.data(), buffer.size(), &count_rust)};
bool btcd{go_btcd_addrv2(buffer.data(), buffer.size(), &count_btcd)};
auto core{Core(buffer)};
[[maybe_unused]] bool rust_bitcoin{rust_bitcoin_addrv2(buffer.data(), buffer.size(), &count_rust)};
[[maybe_unused]] bool btcd{go_btcd_addrv2(buffer.data(), buffer.size(), &count_btcd)};
auto core{Addrv2Core(buffer)};
if (core.has_value() && core->first > 0) {
assert(core->first == count_rust);
assert(core->second == count_btcd);
Expand Down

0 comments on commit 18b619a

Please sign in to comment.