Skip to content

Commit

Permalink
Fixing bitcoin API change problems due to PR merges part #2
Browse files Browse the repository at this point in the history
  • Loading branch information
psolstice committed Mar 15, 2020
1 parent 8864384 commit 31591ac
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 44 deletions.
73 changes: 73 additions & 0 deletions src/support/allocators/pooled_secure.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) 2014-2018 The Dash Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_SUPPORT_ALLOCATORS_POOLED_SECURE_H
#define BITCOIN_SUPPORT_ALLOCATORS_POOLED_SECURE_H

#include "support/lockedpool.h"
#include "support/cleanse.h"

#include <string>
#include <vector>

#include <boost/pool/pool_alloc.hpp>

//
// Allocator that allocates memory in chunks from a pool, which in turn allocates larger chunks from secure memory
// Memory is cleaned when freed as well. This allocator is NOT thread safe
//
template <typename T>
struct pooled_secure_allocator : public std::allocator<T> {
// MSVC8 default copy constructor is broken
typedef std::allocator<T> base;
typedef typename base::size_type size_type;
typedef typename base::difference_type difference_type;
typedef typename base::pointer pointer;
typedef typename base::const_pointer const_pointer;
typedef typename base::reference reference;
typedef typename base::const_reference const_reference;
typedef typename base::value_type value_type;
pooled_secure_allocator(const size_type nrequested_size = 32,
const size_type nnext_size = 32,
const size_type nmax_size = 0) throw() :
pool(nrequested_size, nnext_size, nmax_size){}
~pooled_secure_allocator() throw() {}

T* allocate(std::size_t n, const void* hint = 0)
{
size_t chunks = (n * sizeof(T) + pool.get_requested_size() - 1) / pool.get_requested_size();
return static_cast<T*>(pool.ordered_malloc(chunks));
}

void deallocate(T* p, std::size_t n)
{
if (!p) {
return;
}

size_t chunks = (n * sizeof(T) + pool.get_requested_size() - 1) / pool.get_requested_size();
memory_cleanse(p, chunks * pool.get_requested_size());
pool.ordered_free(p, chunks);
}

public:
struct internal_secure_allocator {
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;

static char* malloc(const size_type bytes)
{
return static_cast<char*>(LockedPoolManager::Instance().alloc(bytes));
}

static void free(char* const block)
{
LockedPoolManager::Instance().free(block);
}
};
private:
boost::pool<internal_secure_allocator> pool;
};

#endif // BITCOIN_SUPPORT_ALLOCATORS_POOLED_SECURE_H
6 changes: 3 additions & 3 deletions src/wallet/rpcdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ void ImportScript(CWallet * const pwallet, const CScript& script, const string&
}
}

void ImportAddress(CWallet *pwallet, const CBitcoinAddress& address, const string& strLabel)
void ImportAddress(CWallet * const pwallet, const CBitcoinAddress& address, const string& strLabel)
{
CScript script = GetScriptForDestination(address.Get());
ImportScript(script, strLabel, false);
ImportScript(pwallet, script, strLabel, false);
// add to address book or update label
if (address.IsValid())
pwallet->SetAddressBook(address.Get(), strLabel, "receive");
Expand Down Expand Up @@ -892,7 +892,7 @@ UniValue dumpwallet_zcoin(const JSONRPCRequest& request)
return dumpwallet(newRequest);
}

UniValue ProcessImport(const UniValue& data, const int64_t timestamp)
UniValue ProcessImport(CWallet *pwallet, const UniValue& data, const int64_t timestamp)
{
try {
bool success = false;
Expand Down
Loading

0 comments on commit 31591ac

Please sign in to comment.