forked from ioncoincore/ion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in refactor-token-wallet (pull request ioncoincore#5)
Refactor token wallet Approved-by: Cevap
- Loading branch information
Showing
17 changed files
with
2,014 additions
and
3,541 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ¶ms) | ||
{ | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ¶ms = Params()); | ||
//* Group script helper function | ||
CScript GetScriptForDestination(const CTxDestination &dest, const CTokenGroupID &group, const CAmount &amount); |
Oops, something went wrong.