Skip to content

Commit

Permalink
Merge pull request #216 from RavenProject/release_2.0.3
Browse files Browse the repository at this point in the history
Release 2.0.3
  • Loading branch information
cfrogjump authored Aug 13, 2018
2 parents fc5d1a7 + 39d8745 commit 01d8c15
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 75 deletions.
126 changes: 61 additions & 65 deletions src/assets/assets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,85 +725,81 @@ void CAssetsCache::AddToAssetBalance(const std::string& strName, const std::stri

bool CAssetsCache::TrySpendCoin(const COutPoint& out, const CTxOut& txOut)
{

if (vpwallets.size() == 0) {
CAssetCachePossibleMine possibleMine("", out, txOut);
setPossiblyMineRemove.insert(possibleMine);
return true;
}

std::pair<std::string, COutPoint> pairToRemove = std::make_pair("", COutPoint());
for (auto setOuts : mapMyUnspentAssets) {
// If we own one of the assets, we need to update our databases and memory
if (setOuts.second.count(out)) {

// Placeholder strings that will get set if you successfully get the transfer or asset from the script
std::string address = "";
std::string assetName = "";
CAmount nAmount = -1;
// Placeholder strings that will get set if you successfully get the transfer or asset from the script
std::string address = "";
std::string assetName = "";
CAmount nAmount = -1;

int nType = 0;
bool fIsOwner = false;
if (txOut.scriptPubKey.IsAssetScript(nType, fIsOwner)) {
txnouttype type = (txnouttype)nType;
// Get the asset tx data
int nType = 0;
bool fIsOwner = false;
if (txOut.scriptPubKey.IsAssetScript(nType, fIsOwner)) {
txnouttype type = (txnouttype)nType;

// Get the New Asset or Transfer Asset from the scriptPubKey
if (type == TX_NEW_ASSET && !fIsOwner) {
CNewAsset asset;
if (AssetFromScript(txOut.scriptPubKey, asset, address)) {
assetName = asset.strName;
nAmount = asset.nAmount;
}
} else if (type == TX_TRANSFER_ASSET) {
CAssetTransfer transfer;
if (TransferAssetFromScript(txOut.scriptPubKey, transfer, address)) {
assetName = transfer.strName;
nAmount = transfer.nAmount;
}
} else if (type == TX_NEW_ASSET && fIsOwner) {
if (!OwnerAssetFromScript(txOut.scriptPubKey, assetName, address))
return error("%s : ERROR Failed to get owner asset from the OutPoint: %s", __func__,
out.ToString());
nAmount = OWNER_ASSET_AMOUNT;
} else if (type == TX_REISSUE_ASSET) {
CReissueAsset reissue;
if (ReissueAssetFromScript(txOut.scriptPubKey, reissue, address)) {
assetName = reissue.strName;
nAmount = reissue.nAmount;
}
}
// Get the New Asset or Transfer Asset from the scriptPubKey
if (type == TX_NEW_ASSET && !fIsOwner) {
CNewAsset asset;
if (AssetFromScript(txOut.scriptPubKey, asset, address)) {
assetName = asset.strName;
nAmount = asset.nAmount;
}

// If we got the address and the assetName, proceed to remove it from the database, and in memory objects
if (address != "" && assetName != "" && nAmount > 0) {
CAssetCacheSpendAsset spend(assetName, address, nAmount);
if (GetBestAssetAddressAmount(*this, assetName, address)) {
assert(mapAssetsAddressAmount[make_pair(assetName, address)] >= nAmount);
mapAssetsAddressAmount[make_pair(assetName, address)] -= nAmount;
pairToRemove = std::make_pair(assetName, out);

if (mapAssetsAddressAmount[make_pair(assetName, address)] == 0 &&
mapAssetsAddresses.count(assetName))
mapAssetsAddresses.at(assetName).erase(address);

// Update the cache so we can save to database
vSpentAssets.push_back(spend);
} else {
return error("%s : ERROR Failed to find current assets address amount. Asset %s: , Address : %s", __func__, assetName, address);
}

} else {
return error("%s : ERROR Failed to get asset from the OutPoint: %s", __func__, out.ToString());
} else if (type == TX_TRANSFER_ASSET) {
CAssetTransfer transfer;
if (TransferAssetFromScript(txOut.scriptPubKey, transfer, address)) {
assetName = transfer.strName;
nAmount = transfer.nAmount;
}
} else if (type == TX_NEW_ASSET && fIsOwner) {
if (!OwnerAssetFromScript(txOut.scriptPubKey, assetName, address))
return error("%s : ERROR Failed to get owner asset from the OutPoint: %s", __func__,
out.ToString());
nAmount = OWNER_ASSET_AMOUNT;
} else if (type == TX_REISSUE_ASSET) {
CReissueAsset reissue;
if (ReissueAssetFromScript(txOut.scriptPubKey, reissue, address)) {
assetName = reissue.strName;
nAmount = reissue.nAmount;
}
break;
}
} else {
// If it isn't an asset tx return true, we only fail if an error occurs
return true;
}

if (pairToRemove.first != "" && !pairToRemove.second.IsNull() && mapMyUnspentAssets.count(pairToRemove.first)) {
mapMyUnspentAssets.at(pairToRemove.first).erase(pairToRemove.second);
// If we got the address and the assetName, proceed to remove it from the database, and in memory objects
if (address != "" && assetName != "" && nAmount > 0) {
CAssetCacheSpendAsset spend(assetName, address, nAmount);
if (GetBestAssetAddressAmount(*this, assetName, address)) {
assert(mapAssetsAddressAmount[make_pair(assetName, address)] >= nAmount);
mapAssetsAddressAmount[make_pair(assetName, address)] -= nAmount;

// Update the cache so we know which assets set of outpoint we need to save to database
setChangeOwnedOutPoints.insert(pairToRemove.first);
if (mapAssetsAddressAmount[make_pair(assetName, address)] == 0 &&
mapAssetsAddresses.count(assetName))
mapAssetsAddresses.at(assetName).erase(address);

// Update the cache so we can save to database
vSpentAssets.push_back(spend);
} else {
return error("%s : ERROR Failed to find current assets address amount. Asset %s: , Address : %s", __func__, assetName, address);
}

} else {
return error("%s : ERROR Failed to get asset from the OutPoint: %s", __func__, out.ToString());
}
// If we own one of the assets, we need to update our databases and memory
if (mapMyUnspentAssets.count(assetName)) {
if (mapMyUnspentAssets.at(assetName).count(out)) {
mapMyUnspentAssets.at(assetName).erase(out);

// Update the cache so we know which assets set of outpoint we need to save to database
setChangeOwnedOutPoints.insert(assetName);
}
}

return true;
Expand Down
2 changes: 0 additions & 2 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1429,8 +1429,6 @@ bool VerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, const C
std::string str;
str.assign(ScriptErrorString(*serror));
std::cout << str << std::endl;
} else {
std::cout << "serror wasn't set" << std::endl;
}
return false;
}
Expand Down
4 changes: 0 additions & 4 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2745,10 +2745,6 @@ bool CWallet::SelectAssets(const std::map<std::string, std::vector<COutput> >& m
break;
}

for (auto pair : mapValueRet) {
std::cout << "Selected Assets : " << pair.first << " : " << pair.second << std::endl;
}

if (mapValueRet.at(asset.first) < mapAssetTargetValue.at(asset.first)) {
return error(
"%s : Tried to transfer an asset but this wallet didn't have enough, Asset Name: %s, Transfer Amount: %d, Wallet Total: %d",
Expand Down
14 changes: 10 additions & 4 deletions test/functional/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def run_test(self):
self.log.info("Calling issue()...")
address0 = n0.getnewaddress()
ipfs_hash = "QmacSRmrkVmvJfbCpmU6pK72furJ8E8fbKHindrLxmYMQo"
n0.issue(asset_name="MY_ASSET", qty=1000, to_address=address0, change_address="",\
n0.issue(asset_name="MY_ASSET", qty=1000, to_address=address0, change_address="", \
units=4, reissuable=True, has_ipfs=True, ipfs_hash=ipfs_hash)

self.log.info("Waiting for ten confirmations after issue...")
Expand Down Expand Up @@ -70,6 +70,9 @@ def run_test(self):
assert_equal(n0.listassetbalancesbyaddress(address0)["MY_ASSET"], 1000)
assert_equal(n0.listassetbalancesbyaddress(address0)["MY_ASSET!"], 1)

self.log.info("Checking listassetbalancesbyaddress()...")
assert_equal(n0.listaddressesbyasset("MY_ASSET"), n1.listaddressesbyasset("MY_ASSET"))

self.log.info("Calling transfer()...")
address1 = n1.getnewaddress()
n0.transfer(asset_name="MY_ASSET", qty=200, to_address=address1)
Expand All @@ -93,6 +96,9 @@ def run_test(self):
self.log.info("Checking listassetbalancesbyaddress()...")
assert_equal(n1.listassetbalancesbyaddress(address1)["MY_ASSET"], 200)
changeaddress = None
assert_equal(n0.listaddressesbyasset("MY_ASSET"), n1.listaddressesbyasset("MY_ASSET"))
assert_equal(sum(n0.listaddressesbyasset("MY_ASSET").values()), 1000)
assert_equal(sum(n1.listaddressesbyasset("MY_ASSET").values()), 1000)
for assaddr in n0.listaddressesbyasset("MY_ASSET").keys():
if n0.validateaddress(assaddr)["ismine"] == True:
changeaddress = assaddr
Expand All @@ -102,7 +108,7 @@ def run_test(self):

self.log.info("Calling reissue()...")
address1 = n0.getnewaddress()
n0.reissue(asset_name="MY_ASSET", qty=2000, to_address=address0, change_address=address1,\
n0.reissue(asset_name="MY_ASSET", qty=2000, to_address=address0, change_address=address1, \
reissuable=False, new_ipfs=ipfs_hash[::-1])

self.log.info("Waiting for ten confirmations after reissue...")
Expand Down Expand Up @@ -131,8 +137,8 @@ def run_test(self):
n0.listassets(asset="RAVEN*", verbose=False, count=2, start=-2)

self.log.info("Creating some sub-assets...")
n0.issue(asset_name="MY_ASSET/SUB1", qty=1000, to_address=address0, change_address=address0, \
units=4, reissuable=True, has_ipfs=True, ipfs_hash=ipfs_hash)
n0.issue(asset_name="MY_ASSET/SUB1", qty=1000, to_address=address0, change_address=address0,\
units=4, reissuable=True, has_ipfs=True, ipfs_hash=ipfs_hash)

self.log.info("Waiting for ten confirmations after issuesubasset...")
n0.generate(10)
Expand Down

0 comments on commit 01d8c15

Please sign in to comment.