Skip to content

Commit 8d5cf12

Browse files
authored
Merge pull request #641 from RavenProject/transfer_formatting
Fix asset transfer formatting
2 parents 2deeb83 + a320bb9 commit 8d5cf12

File tree

2 files changed

+112
-112
lines changed

2 files changed

+112
-112
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
22
AC_PREREQ([2.60])
33
define(_CLIENT_VERSION_MAJOR, 2)
44
define(_CLIENT_VERSION_MINOR, 5)
5-
define(_CLIENT_VERSION_REVISION, 0)
5+
define(_CLIENT_VERSION_REVISION, 1)
66
define(_CLIENT_VERSION_BUILD, 0)
77
define(_CLIENT_VERSION_IS_RELEASE, true)
88
define(_COPYRIGHT_YEAR, 2018)

src/assets/assets.cpp

Lines changed: 111 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,117 +2568,6 @@ bool CreateAssetTransaction(CWallet* pwallet, CCoinControl& coinControl, const C
25682568
return CreateAssetTransaction(pwallet, coinControl, assets, address, error, wtxNew, reservekey, nFeeRequired);
25692569
}
25702570

2571-
bool CreateAssetTransaction(CWallet* pwallet, CCoinControl& coinControl, const std::vector<CNewAsset> assets, const std::string& address, std::pair<int, std::string>& error, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRequired)
2572-
{
2573-
std::string change_address = EncodeDestination(coinControl.destChange);
2574-
2575-
auto currentActiveAssetCache = GetCurrentAssetCache();
2576-
// Validate the assets data
2577-
std::string strError;
2578-
for (auto asset : assets) {
2579-
if (!asset.IsValid(strError, *currentActiveAssetCache)) {
2580-
error = std::make_pair(RPC_INVALID_PARAMETER, strError);
2581-
return false;
2582-
}
2583-
}
2584-
2585-
if (!change_address.empty()) {
2586-
CTxDestination destination = DecodeDestination(change_address);
2587-
if (!IsValidDestination(destination)) {
2588-
error = std::make_pair(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Raven address: ") + change_address);
2589-
return false;
2590-
}
2591-
} else {
2592-
// no coin control: send change to newly generated address
2593-
CKeyID keyID;
2594-
std::string strFailReason;
2595-
if (!pwallet->CreateNewChangeAddress(reservekey, keyID, strFailReason)) {
2596-
error = std::make_pair(RPC_WALLET_KEYPOOL_RAN_OUT, strFailReason);
2597-
return false;
2598-
}
2599-
2600-
change_address = EncodeDestination(keyID);
2601-
coinControl.destChange = DecodeDestination(change_address);
2602-
}
2603-
2604-
AssetType assetType;
2605-
std::string parentName;
2606-
for (auto asset : assets) {
2607-
if (!IsAssetNameValid(asset.strName, assetType)) {
2608-
error = std::make_pair(RPC_INVALID_PARAMETER, "Asset name not valid");
2609-
return false;
2610-
}
2611-
if (assets.size() > 1 && assetType != AssetType::UNIQUE) {
2612-
error = std::make_pair(RPC_INVALID_PARAMETER, "Only unique assets can be issued in bulk.");
2613-
return false;
2614-
}
2615-
std::string parent = GetParentName(asset.strName);
2616-
if (parentName.empty())
2617-
parentName = parent;
2618-
if (parentName != parent) {
2619-
error = std::make_pair(RPC_INVALID_PARAMETER, "All assets must have the same parent.");
2620-
return false;
2621-
}
2622-
}
2623-
2624-
// Assign the correct burn amount and the correct burn address depending on the type of asset issuance that is happening
2625-
CAmount burnAmount = GetBurnAmount(assetType) * assets.size();
2626-
CScript scriptPubKey = GetScriptForDestination(DecodeDestination(GetBurnAddress(assetType)));
2627-
2628-
CAmount curBalance = pwallet->GetBalance();
2629-
2630-
// Check to make sure the wallet has the RVN required by the burnAmount
2631-
if (curBalance < burnAmount) {
2632-
error = std::make_pair(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
2633-
return false;
2634-
}
2635-
2636-
if (pwallet->GetBroadcastTransactions() && !g_connman) {
2637-
error = std::make_pair(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
2638-
return false;
2639-
}
2640-
2641-
LOCK2(cs_main, pwallet->cs_wallet);
2642-
2643-
// Create and send the transaction
2644-
std::string strTxError;
2645-
std::vector<CRecipient> vecSend;
2646-
int nChangePosRet = -1;
2647-
bool fSubtractFeeFromAmount = false;
2648-
2649-
CRecipient recipient = {scriptPubKey, burnAmount, fSubtractFeeFromAmount};
2650-
vecSend.push_back(recipient);
2651-
2652-
// If the asset is a subasset or unique asset. We need to send the ownertoken change back to ourselfs
2653-
if (assetType == AssetType::SUB || assetType == AssetType::UNIQUE) {
2654-
// Get the script for the destination address for the assets
2655-
CScript scriptTransferOwnerAsset = GetScriptForDestination(DecodeDestination(change_address));
2656-
2657-
CAssetTransfer assetTransfer(parentName + OWNER_TAG, OWNER_ASSET_AMOUNT);
2658-
assetTransfer.ConstructTransaction(scriptTransferOwnerAsset);
2659-
CRecipient rec = {scriptTransferOwnerAsset, 0, fSubtractFeeFromAmount};
2660-
// vecSend.push_back(rec);
2661-
}
2662-
2663-
// Get the owner outpoints if this is a subasset or unique asset
2664-
if (assetType == AssetType::SUB || assetType == AssetType::UNIQUE) {
2665-
// Verify that this wallet is the owner for the asset, and get the owner asset outpoint
2666-
for (auto asset : assets) {
2667-
if (!VerifyWalletHasAsset(parentName + OWNER_TAG, error)) {
2668-
return false;
2669-
}
2670-
}
2671-
}
2672-
2673-
if (!pwallet->CreateTransactionWithAssets(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strTxError, coinControl, assets, DecodeDestination(address), assetType)) {
2674-
if (!fSubtractFeeFromAmount && burnAmount + nFeeRequired > curBalance)
2675-
strTxError = strprintf("Error: This transaction requires a transaction fee of at least %s", FormatMoney(nFeeRequired));
2676-
error = std::make_pair(RPC_WALLET_ERROR, strTxError);
2677-
return false;
2678-
}
2679-
return true;
2680-
}
2681-
26822571
bool CreateReissueAssetTransaction(CWallet* pwallet, CCoinControl& coinControl, const CReissueAsset& reissueAsset, const std::string& address, std::pair<int, std::string>& error, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRequired)
26832572
{
26842573
std::string asset_name = reissueAsset.strName;
@@ -2860,6 +2749,117 @@ bool CreateTransferAssetTransaction(CWallet* pwallet, const CCoinControl& coinCo
28602749
return true;
28612750
}
28622751

2752+
bool CreateAssetTransaction(CWallet* pwallet, CCoinControl& coinControl, const std::vector<CNewAsset> assets, const std::string& address, std::pair<int, std::string>& error, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRequired)
2753+
{
2754+
std::string change_address = EncodeDestination(coinControl.destChange);
2755+
2756+
auto currentActiveAssetCache = GetCurrentAssetCache();
2757+
// Validate the assets data
2758+
std::string strError;
2759+
for (auto asset : assets) {
2760+
if (!asset.IsValid(strError, *currentActiveAssetCache)) {
2761+
error = std::make_pair(RPC_INVALID_PARAMETER, strError);
2762+
return false;
2763+
}
2764+
}
2765+
2766+
if (!change_address.empty()) {
2767+
CTxDestination destination = DecodeDestination(change_address);
2768+
if (!IsValidDestination(destination)) {
2769+
error = std::make_pair(RPC_INVALID_ADDRESS_OR_KEY, std::string("Invalid Raven address: ") + change_address);
2770+
return false;
2771+
}
2772+
} else {
2773+
// no coin control: send change to newly generated address
2774+
CKeyID keyID;
2775+
std::string strFailReason;
2776+
if (!pwallet->CreateNewChangeAddress(reservekey, keyID, strFailReason)) {
2777+
error = std::make_pair(RPC_WALLET_KEYPOOL_RAN_OUT, strFailReason);
2778+
return false;
2779+
}
2780+
2781+
change_address = EncodeDestination(keyID);
2782+
coinControl.destChange = DecodeDestination(change_address);
2783+
}
2784+
2785+
AssetType assetType;
2786+
std::string parentName;
2787+
for (auto asset : assets) {
2788+
if (!IsAssetNameValid(asset.strName, assetType)) {
2789+
error = std::make_pair(RPC_INVALID_PARAMETER, "Asset name not valid");
2790+
return false;
2791+
}
2792+
if (assets.size() > 1 && assetType != AssetType::UNIQUE) {
2793+
error = std::make_pair(RPC_INVALID_PARAMETER, "Only unique assets can be issued in bulk.");
2794+
return false;
2795+
}
2796+
std::string parent = GetParentName(asset.strName);
2797+
if (parentName.empty())
2798+
parentName = parent;
2799+
if (parentName != parent) {
2800+
error = std::make_pair(RPC_INVALID_PARAMETER, "All assets must have the same parent.");
2801+
return false;
2802+
}
2803+
}
2804+
2805+
// Assign the correct burn amount and the correct burn address depending on the type of asset issuance that is happening
2806+
CAmount burnAmount = GetBurnAmount(assetType) * assets.size();
2807+
CScript scriptPubKey = GetScriptForDestination(DecodeDestination(GetBurnAddress(assetType)));
2808+
2809+
CAmount curBalance = pwallet->GetBalance();
2810+
2811+
// Check to make sure the wallet has the RVN required by the burnAmount
2812+
if (curBalance < burnAmount) {
2813+
error = std::make_pair(RPC_WALLET_INSUFFICIENT_FUNDS, "Insufficient funds");
2814+
return false;
2815+
}
2816+
2817+
if (pwallet->GetBroadcastTransactions() && !g_connman) {
2818+
error = std::make_pair(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
2819+
return false;
2820+
}
2821+
2822+
LOCK2(cs_main, pwallet->cs_wallet);
2823+
2824+
// Create and send the transaction
2825+
std::string strTxError;
2826+
std::vector<CRecipient> vecSend;
2827+
int nChangePosRet = -1;
2828+
bool fSubtractFeeFromAmount = false;
2829+
2830+
CRecipient recipient = {scriptPubKey, burnAmount, fSubtractFeeFromAmount};
2831+
vecSend.push_back(recipient);
2832+
2833+
// If the asset is a subasset or unique asset. We need to send the ownertoken change back to ourselfs
2834+
if (assetType == AssetType::SUB || assetType == AssetType::UNIQUE) {
2835+
// Get the script for the destination address for the assets
2836+
CScript scriptTransferOwnerAsset = GetScriptForDestination(DecodeDestination(change_address));
2837+
2838+
CAssetTransfer assetTransfer(parentName + OWNER_TAG, OWNER_ASSET_AMOUNT);
2839+
assetTransfer.ConstructTransaction(scriptTransferOwnerAsset);
2840+
CRecipient rec = {scriptTransferOwnerAsset, 0, fSubtractFeeFromAmount};
2841+
vecSend.push_back(rec);
2842+
}
2843+
2844+
// Get the owner outpoints if this is a subasset or unique asset
2845+
if (assetType == AssetType::SUB || assetType == AssetType::UNIQUE) {
2846+
// Verify that this wallet is the owner for the asset, and get the owner asset outpoint
2847+
for (auto asset : assets) {
2848+
if (!VerifyWalletHasAsset(parentName + OWNER_TAG, error)) {
2849+
return false;
2850+
}
2851+
}
2852+
}
2853+
2854+
if (!pwallet->CreateTransactionWithAssets(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosRet, strTxError, coinControl, assets, DecodeDestination(address), assetType)) {
2855+
if (!fSubtractFeeFromAmount && burnAmount + nFeeRequired > curBalance)
2856+
strTxError = strprintf("Error: This transaction requires a transaction fee of at least %s", FormatMoney(nFeeRequired));
2857+
error = std::make_pair(RPC_WALLET_ERROR, strTxError);
2858+
return false;
2859+
}
2860+
return true;
2861+
}
2862+
28632863
bool SendAssetTransaction(CWallet* pwallet, CWalletTx& transaction, CReserveKey& reserveKey, std::pair<int, std::string>& error, std::string& txid)
28642864
{
28652865
CValidationState state;

0 commit comments

Comments
 (0)