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

Refine the multi-color mechanism #104 #126

Open
wants to merge 70 commits into
base: develop
Choose a base branch
from

Conversation

hihiben
Copy link
Contributor

@hihiben hihiben commented Feb 2, 2017

The original value handling type CAmount does not support multi-color. The original method to implement multi-color is simply adding a new type_Color member when this function is needed. However, value and color have to be handled separated, which leads to different problems when upgrading the original function or developing new functions.

A new object class CColorAmount is implemented to solve these issues. Needed member functions and operators are provided.
Operators

  • -CColorAmount
  • CColorAmount+CColorAmount
  • CColorAmount+CAmount
  • CColorAmount-CColorAmount
  • CColorAmount-CAmount
  • CColorAmount*CAmount
  • CColorAmount/CAmount
  • CColorAmount%CAmount
  • CColorAmount+=CColorAmount
  • CColorAmount+=CAmount
  • CColorAmount-=CColorAmount
  • CColorAmount-=CAmount
  • CColorAmount*=CAmount
  • CColorAmount/=CAmount
  • CColorAmount%=CAmount
  • CColorAmount>CColorAmount
  • CColorAmount>=CColorAmount
  • CColorAmount<CColorAmount
  • CColorAmount<=CColorAmount
  • CColorAmount==CColorAmount
  • CColorAmount!=CColorAmount
  • CColorAmount++
  • CColorAmount--

Functions

  • Color()
  • Value()
  • TotalValue()
  • IsPos()

The printing and parsing of color amount becomes color:amount, such as 1:1000 means color 1 with amount 1000.

@hihiben hihiben closed this Feb 3, 2017
@hihiben hihiben reopened this Feb 3, 2017
@hihiben hihiben force-pushed the CColorAmount branch 15 times, most recently from 2d8ab66 to bae76fc Compare February 10, 2017 07:55
src/amount.h Outdated
if (!lhs.count(it->first))
lhs[it->first] -= it->second;
else
lhs[it->first] = -it->second;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

反了?

src/amount.h Outdated
{
CColorAmount lhs = (*this);
for (CColorAmount::const_iterator itr(rhs.begin()); itr != rhs.end(); itr++) {
CColorAmount::const_iterator itl = lhs.find(itr->first);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這樣寫會是兩層迴圈?

ret.first->second += it->second;
}
return *this;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不能用上面已經寫好的+來做嗎

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以下幾個一樣

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

換一個方式來implement了

src/coins.cpp Outdated
@@ -245,7 +245,7 @@ double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight) const
assert(coins);
if (!coins->IsAvailable(txin.prevout.n)) continue;
if (coins->nHeight < nHeight) {
dResult += coins->vout[txin.prevout.n].nValue * (nHeight-coins->nHeight);
dResult += (coins->vout[txin.prevout.n].mValue.TotalValue()) * (nHeight-coins->nHeight);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

為何要加括號

src/main.cpp Outdated
}
if (it->second < 0) {
Input -= txout.mValue;
if (!Input.IsPos()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pos蠻不容易看出來這function是要幹嘛的
或許可以打完整一點postive

src/main.cpp Outdated
}

void Fee::SetOutputForFee(CTxOut &txout, const CScript& scriptPubKeyIn, unsigned int cnt) {
txout.scriptPubKey = scriptPubKeyIn;
txout.nValue = value * cnt;
txout.color = color;
txout.mValue = mValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cnt?

@hihiben hihiben force-pushed the CColorAmount branch 3 times, most recently from 4250630 to ec92246 Compare February 15, 2017 10:16
if (totalfee > 0) {
CTxOut txout(totalfee, scriptPubKeyIn, TxFee.GetColor());
if (totalfee.Value() > 0) {
CTxOut txout(totalfee, scriptPubKeyIn);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大概從303行開始到這邊,
totalfee應該是map, 這樣不會把fee以外的東西一起丟進去嗎

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前設計上fee應該只會有color 1,因此前面的部分在totalfee紀錄了所有Normal type transaction的差值之後,這邊應該只留下color 1而已,因此用Value來取值,避免出現有多個color在裡面的狀況。如果以後有修改到fee可能出現在不同的color下的話,應就可以改成用TotalValue()來取值


bool ParseMoney(const string& str, CColorAmount& mRet)
{
size_t found;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

沒給初始值?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在105行found = str.find(",", i)的地方就會給值了


return nTotal;
CColorAmount balance = GetAddressBalance(strFromAddress, nMinDepth);
return balance[color];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

balance[color]沒東西會怎麼樣?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CColorAmount的value type是CAmount來說的話,會回傳0

}
else
strFailReason = _("Transaction amount too small");
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

為何要多加上上面那串 然後再註解掉啊

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已刪

{
map<CTxDestination, CColorAmount> balances = GetAddressBalances();
CTxDestination address = CBitcoinAddress(strAddress).Get();
return balances[address];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

空的會怎樣?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以這個map的value type是CColorAmount來說的話,會回傳一個空的map

@hihiben hihiben force-pushed the CColorAmount branch 2 times, most recently from e0d6fa1 to 3f2c0d5 Compare February 16, 2017 10:08
sendtoaddress()
listaddressgroupings()
getreceivedbyaddress()
getreceivedbyaccount()
coins_cache_simulation_test
DoS_mapOrphans
GetAccountBalance()
getbalance()
MempoolRemoveTest
multisig_verify
multisig_Sign
Verify()
sign
set
AreInputsStandard
GetAccountBalance()
GetAccountColorBalance()
getbalance()
getcolorbalance()
getaddressbalance()
getunconfirmedbalance()
movecmd()
sendfrom()
sendfromfeeaddress()
sendmany()
ListReceived()
ListTransactions()
AcentryToJSON()
listaccounts()
gettransaction()
getwalletinfo()
mint()
mintforlicense()
mintforminer()
struct NormalHandlerCheckValidFixture
NormalHandlerApplyNoMemberOnly
CreateLicenseHandlerCheckValidFixture
CreateLicenseHandlerCheckValidInvalidInfo
TransferLicenseHandlerCheckValidFixture
add_coin()
coin_selection_tests
rpc_sendlicensetoaddress_test
fix operators
processTransaction()
AcceptToMemoryPool()
unify fee to color 1 only
error msg of operators that amount size should be 1
change IsPos to IsPositive
CheckTxFeeandColor()
remove SetOutputForFee()
run the entire unit test
refine the operators
sendfrom()
sendtoaddress()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants