Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Linux compile-linker error #261

Merged
merged 1 commit into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 38 additions & 33 deletions src/assets/assettypes.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//
// Copyright (c) 2018 The Raven Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
// Created by Jeremy Anderson on 5/15/18.
//

#ifndef RAVENCOIN_NEWASSET_H
#define RAVENCOIN_NEWASSET_H

#include <amount.h>
#include <string>
#include <unordered_map>
#include "amount.h"
#include "serialize.h"

#define MAX_UNIT 8
Expand All @@ -27,21 +28,9 @@ enum AssetType
INVALID = 7
};

std::string PrintAssetType(AssetType& assetType) {
switch (assetType) {
case ROOT: return "ROOT";
case SUB: return "SUB";
case UNIQUE: return "UNIQUE";
case OWNER: return "OWNER";
case MSGCHANNEL: return "MSGCHANNEL";
case VOTE: return "VOTE";
case REISSUE: return "REISSUE";
case INVALID: return "INVALID";
default: return "UNKNOWN";
}
}

class CNewAsset {

class CNewAsset
{
public:
std::string strName; // MAX 31 Bytes
CAmount nAmount; // 8 Bytes
Expand Down Expand Up @@ -82,7 +71,8 @@ class CNewAsset {
ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(strName);
READWRITE(nAmount);
READWRITE(units);
Expand All @@ -101,7 +91,8 @@ class AssetComparator
}
};

class CAssetTransfer {
class CAssetTransfer
{
public:
std::string strName;
CAmount nAmount;
Expand All @@ -121,7 +112,8 @@ class CAssetTransfer {
ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(strName);
READWRITE(nAmount);
}
Expand All @@ -131,7 +123,8 @@ class CAssetTransfer {
void ConstructTransaction(CScript& script) const;
};

class CReissueAsset {
class CReissueAsset
{
public:
std::string strName;
CAmount nAmount;
Expand All @@ -154,7 +147,8 @@ class CReissueAsset {
ADD_SERIALIZE_METHODS;

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
inline void SerializationOp(Stream& s, Operation ser_action)
{
READWRITE(strName);
READWRITE(nAmount);
READWRITE(nReissuable);
Expand All @@ -180,7 +174,8 @@ struct CAssetCacheNewAsset
this->address = address;
}

bool operator<(const CAssetCacheNewAsset& rhs) const {
bool operator<(const CAssetCacheNewAsset& rhs) const
{
return asset.strName < rhs.asset.strName;
}
};
Expand All @@ -198,7 +193,8 @@ struct CAssetCacheReissueAsset
this->out = out;
}

bool operator<(const CAssetCacheReissueAsset& rhs) const {
bool operator<(const CAssetCacheReissueAsset& rhs) const
{
return out < rhs.out;
}

Expand Down Expand Up @@ -244,7 +240,8 @@ struct CAssetCacheNewOwner
this->address = address;
}

bool operator<(const CAssetCacheNewOwner& rhs) const {
bool operator<(const CAssetCacheNewOwner& rhs) const
{

return assetName < rhs.assetName;
// if (assetName < rhs.assetName)
Expand Down Expand Up @@ -301,12 +298,14 @@ struct CAssetCachePossibleMine

// Least Recently Used Cache
template<typename cache_key_t, typename cache_value_t>
class CLRUCache {
class CLRUCache
{
public:
typedef typename std::pair<cache_key_t, cache_value_t> key_value_pair_t;
typedef typename std::list<key_value_pair_t>::iterator list_iterator_t;

CLRUCache(size_t max_size) : maxSize(max_size) {
CLRUCache(size_t max_size) : maxSize(max_size)
{
}
CLRUCache()
{
Expand All @@ -317,13 +316,15 @@ class CLRUCache {
{
auto it = cacheItemsMap.find(key);
cacheItemsList.push_front(key_value_pair_t(key, value));
if (it != cacheItemsMap.end()) {
if (it != cacheItemsMap.end())
{
cacheItemsList.erase(it->second);
cacheItemsMap.erase(it);
}
cacheItemsMap[key] = cacheItemsList.begin();

if (cacheItemsMap.size() > maxSize) {
if (cacheItemsMap.size() > maxSize)
{
auto last = cacheItemsList.end();
last--;
cacheItemsMap.erase(last->first);
Expand All @@ -334,7 +335,8 @@ class CLRUCache {
void Erase(const cache_key_t& key)
{
auto it = cacheItemsMap.find(key);
if (it != cacheItemsMap.end()) {
if (it != cacheItemsMap.end())
{
cacheItemsList.erase(it->second);
cacheItemsMap.erase(it);
}
Expand All @@ -343,9 +345,12 @@ class CLRUCache {
const cache_value_t& Get(const cache_key_t& key)
{
auto it = cacheItemsMap.find(key);
if (it == cacheItemsMap.end()) {
if (it == cacheItemsMap.end())
{
throw std::range_error("There is no such key in cache");
} else {
}
else
{
cacheItemsList.splice(cacheItemsList.begin(), cacheItemsList, it->second);
return it->second->second;
}
Expand Down
24 changes: 20 additions & 4 deletions src/rpc/assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

//#include <amount.h>
//#include <base58.h>
#include <assets/assets.h>
#include <assets/assetdb.h>
#include "assets/assets.h"
#include "assets/assetdb.h"
#include <map>
#include <tinyformat.h>
#include "tinyformat.h"
//#include <rpc/server.h>
//#include <script/standard.h>
//#include <utilstrencodings.h>
Expand Down Expand Up @@ -41,6 +41,22 @@ std::string AssetActivationWarning()
return AreAssetsDeployed() ? "" : "\nTHIS COMMAND IS NOT YET ACTIVE!\nhttps://github.com/RavenProject/rips/blob/master/rip-0002.mediawiki\n";
}

std::string AssetTypeToString(AssetType& assetType)
{
switch (assetType)
{
case ROOT: return "ROOT";
case SUB: return "SUB";
case UNIQUE: return "UNIQUE";
case OWNER: return "OWNER";
case MSGCHANNEL: return "MSGCHANNEL";
case VOTE: return "VOTE";
case REISSUE: return "REISSUE";
case INVALID: return "INVALID";
default: return "UNKNOWN";
}
}

UniValue UnitValueFromAmount(const CAmount& amount, const std::string asset_name)
{
if (!passets)
Expand Down Expand Up @@ -111,7 +127,7 @@ UniValue issue(const JSONRPCRequest& request)

// Check assetType supported
if (!(assetType == AssetType::ROOT || assetType == AssetType::SUB || assetType == AssetType::UNIQUE)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Unsupported asset type: ") + PrintAssetType(assetType));
throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Unsupported asset type: ") + AssetTypeToString(assetType));
}

CAmount nAmount = COIN;
Expand Down