Skip to content

Commit

Permalink
Merged in refactor-token-wallet (pull request ioncoincore#5)
Browse files Browse the repository at this point in the history
Refactor token wallet

Approved-by: Cevap
  • Loading branch information
FornaxA authored and Cevap committed Dec 24, 2019
2 parents 4bdaa61 + 6e06411 commit 70a0dba
Show file tree
Hide file tree
Showing 17 changed files with 2,014 additions and 3,541 deletions.
13 changes: 8 additions & 5 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ BITCOIN_CORE_H = \
script/sigcache.h \
script/sign.h \
script/standard.h \
script/tokengroup.h \
script/ismine.h \
spork.h \
stacktraces.h \
Expand Down Expand Up @@ -377,7 +378,6 @@ libion_server_a_SOURCES = \
script/ismine.cpp \
spork.cpp \
timedata.cpp \
tokens/tokendb.cpp \
torcontrol.cpp \
txdb.cpp \
txmempool.cpp \
Expand Down Expand Up @@ -416,10 +416,7 @@ libion_wallet_a_SOURCES = \
pos/staking-manager.cpp \
privatesend/privatesend-client.cpp \
privatesend/privatesend-util.cpp \
tokens/rpctokens.cpp \
tokens/tokengroupconfiguration.cpp \
tokens/tokengroupdescription.cpp \
tokens/tokengroupmanager.cpp \
tokens/rpctokenwallet.cpp \
tokens/tokengroupwallet.cpp \
wallet/crypter.cpp \
wallet/db.cpp \
Expand Down Expand Up @@ -611,7 +608,13 @@ libion_common_a_SOURCES = \
saltedhasher.cpp \
scheduler.cpp \
script/standard.cpp \
script/tokengroup.cpp \
script/sign.cpp \
tokens/rpctokens.cpp \
tokens/tokendb.cpp \
tokens/tokengroupconfiguration.cpp \
tokens/tokengroupdescription.cpp \
tokens/tokengroupmanager.cpp \
warnings.cpp \
xion/accumulators.cpp \
xion/accumulatorcheckpoints.cpp \
Expand Down
19 changes: 3 additions & 16 deletions src/consensus/tokengroups.cpp
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
// Copyright (c) 2015-2017 The Bitcoin Unlimited developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <algorithm>

#include "clientversion.h"
#include "coins.h"
#include "consensus/tokengroups.h"
#include "dstencode.h"
#include "init.h"
#include "primitives/transaction.h"
#include "rpc/protocol.h"
#include "script/script.h"
#include "script/standard.h"
#include "pubkey.h"
#include "ionaddrenc.h"
#include "random.h"
#include "rpc/server.h"
#include "streams.h"
#include "tokens/tokengroupmanager.h"
#include "util.h"
#include "utilmoneystr.h"
#include "wallet/coincontrol.h"
#include "wallet/wallet.h"
#include "tokens/tokengroupwallet.h"

#include <unordered_map>
#include <univalue.h>

CTokenGroupID NoGroup; // No group specified.

Expand Down
3 changes: 1 addition & 2 deletions src/consensus/tokengroups.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
#define TOKEN_GROUPS_H

#include "chainparams.h"
#include "coins.h"
#include "consensus/validation.h"
#include "pubkey.h"
#include "util.h"
#include <unordered_map>

class CWallet;
class CCoinsViewCache;

/** Transaction cannot be committed on my fork */
static const unsigned int REJECT_GROUP_IMBALANCE = 0x104;
Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,7 @@ bool AppInitParameterInteraction()
RegisterAllCoreRPCCommands(tableRPC);
#ifdef ENABLE_WALLET
RegisterWalletRPCCommands(tableRPC);
RegisterTokenWalletRPCCommands(tableRPC);
#endif

nConnectTimeout = gArgs.GetArg("-timeout", DEFAULT_CONNECT_TIMEOUT);
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ void RegisterEvoRPCCommands(CRPCTable &tableRPC);
void RegisterQuorumsRPCCommands(CRPCTable &tableRPC);
/** Register Tokens RPC commands */
void RegisterTokensRPCCommands(CRPCTable &tableRPC);
/** Register Tokens RPC commands */
void RegisterTokenWalletRPCCommands(CRPCTable &tableRPC);

static inline void RegisterAllCoreRPCCommands(CRPCTable &t)
{
Expand Down
89 changes: 89 additions & 0 deletions src/script/tokengroup.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) 2015-2017 The Bitcoin Unlimited developers
// Copyright (c) 2019 The ION Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "script/tokengroup.h"

#include "consensus/tokengroups.h"
#include "ionaddrenc.h"

class CTxDestinationTokenGroupExtractor : public boost::static_visitor<CTokenGroupID>
{
public:
CTokenGroupID operator()(const CKeyID &id) const { return CTokenGroupID(id); }
CTokenGroupID operator()(const CScriptID &id) const { return CTokenGroupID(id); }
CTokenGroupID operator()(const CNoDestination &) const { return CTokenGroupID(); }
};

CTokenGroupID GetTokenGroup(const CTxDestination &id)
{
return boost::apply_visitor(CTxDestinationTokenGroupExtractor(), id);
}

CTokenGroupID GetTokenGroup(const std::string &addr, const CChainParams &params)
{
IONAddrContent cac = DecodeIONAddrContent(addr, params);
if (cac.type == IONAddrType::GROUP_TYPE)
return CTokenGroupID(cac.hash);
// otherwise it becomes NoGroup (i.e. data is size 0)
return CTokenGroupID();
}


class CGroupScriptVisitor : public boost::static_visitor<bool>
{
private:
CScript *script;
CTokenGroupID group;
CAmount quantity;

public:
CGroupScriptVisitor(CTokenGroupID grp, CAmount qty, CScript *scriptin) : group(grp), quantity(qty)
{
script = scriptin;
}
bool operator()(const CNoDestination &dest) const
{
script->clear();
return false;
}

bool operator()(const CKeyID &keyID) const
{
script->clear();
if (group.isUserGroup())
{
*script << group.bytes() << SerializeAmount(quantity) << OP_GROUP << OP_DROP << OP_DROP << OP_DUP
<< OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
}
else
{
*script << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG;
}
return true;
}

bool operator()(const CScriptID &scriptID) const
{
script->clear();
if (group.isUserGroup())
{
*script << group.bytes() << SerializeAmount(quantity) << OP_GROUP << OP_DROP << OP_DROP << OP_HASH160
<< ToByteVector(scriptID) << OP_EQUAL;
}
else
{
*script << OP_HASH160 << ToByteVector(scriptID) << OP_EQUAL;
}
return true;
}
};

CScript GetScriptForDestination(const CTxDestination &dest, const CTokenGroupID &group, const CAmount &amount)
{
CScript script;

boost::apply_visitor(CGroupScriptVisitor(group, amount, &script), dest);
return script;
}
18 changes: 18 additions & 0 deletions src/script/tokengroup.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2015-2017 The Bitcoin Unlimited developers
// Copyright (c) 2019 The ION Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "chainparams.h"
#include "script/standard.h"

class CTokenGroupID;

// Token group helper functions

//* Initialize the group id from an address
CTokenGroupID GetTokenGroup(const CTxDestination &id);
//* Initialize a group ID from a string representation
CTokenGroupID GetTokenGroup(const std::string &ionAddrGrpId, const CChainParams &params = Params());
//* Group script helper function
CScript GetScriptForDestination(const CTxDestination &dest, const CTokenGroupID &group, const CAmount &amount);
Loading

0 comments on commit 70a0dba

Please sign in to comment.