Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
remove unused
Browse files Browse the repository at this point in the history
  • Loading branch information
lostman committed Nov 22, 2023
1 parent 8f925f9 commit 1879830
Showing 1 changed file with 0 additions and 81 deletions.
81 changes: 0 additions & 81 deletions packages/fuel-indexer/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,87 +357,6 @@ fn find_many(
}
}

fn find_many_2(
mut env: FunctionEnvMut<IndexEnv>,
type_id: i64,
ptr: u32,
len_ptr: u32,
) -> Result<u32, WasmIndexerError> {
let (idx_env, mut store) = env.data_and_store_mut();

if idx_env
.kill_switch
.load(std::sync::atomic::Ordering::SeqCst)
{
// If the kill switch has been flipped, returning an error will cause an
// early termination of WASM execution.
return Err(WasmIndexerError::KillSwitch);
}

let mem = idx_env
.memory
.as_mut()
.ok_or(WasmIndexerError::UninitializedMemory)?
.view(&store);

let len = WasmPtr::<u32>::new(len_ptr)
.deref(&mem)
.read()
.expect("Failed to read length from memory.");

let constraints = get_object_id(&mem, ptr + 1, len - 1).unwrap();

let rt: tokio::runtime::Handle = tokio::runtime::Handle::current();
let blobs = rt
.block_on(async {
idx_env
.db
.lock()
.await
.find_many(type_id, constraints)
.await
})
.unwrap();

// Pack all the results into a single Vec<u8>.
let mut buf: Vec<u8> = vec![];
// First, the number of items.
buf.extend(blobs.len().to_be_bytes());
for bytes in blobs {
// Then, for each item, the number of bytes.
buf.extend(bytes.len().to_be_bytes());
// And the bytes themselves.
buf.extend(bytes);
}

let alloc_fn = idx_env
.alloc
.as_mut()
.ok_or(WasmIndexerError::AllocMissing)?;

let size = buf.len() as u32;
let result = alloc_fn
.call(&mut store, size)
.map_err(|_| WasmIndexerError::AllocFailed)?;
let range = result as usize..result as usize + size as usize;

let mem = idx_env
.memory
.as_mut()
.expect("Memory unitialized.")
.view(&store);
WasmPtr::<u32>::new(len_ptr)
.deref(&mem)
.write(size)
.expect("Failed to write length to memory.");

unsafe {
mem.data_unchecked_mut()[range].copy_from_slice(&buf);
}

Ok(result)
}

/// Put the given type at the given pointer into memory.
fn put_object(
mut env: FunctionEnvMut<IndexEnv>,
Expand Down

0 comments on commit 1879830

Please sign in to comment.