-
Notifications
You must be signed in to change notification settings - Fork 58
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
base: develop
Are you sure you want to change the base?
Conversation
2d8ab66
to
bae76fc
Compare
src/amount.h
Outdated
if (!lhs.count(it->first)) | ||
lhs[it->first] -= it->second; | ||
else | ||
lhs[it->first] = -it->second; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不能用上面已經寫好的+來做嗎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
以下幾個一樣
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
為何要加括號
7526cd8
to
ecd501d
Compare
src/main.cpp
Outdated
} | ||
if (it->second < 0) { | ||
Input -= txout.mValue; | ||
if (!Input.IsPos()) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cnt?
4250630
to
ec92246
Compare
if (totalfee > 0) { | ||
CTxOut txout(totalfee, scriptPubKeyIn, TxFee.GetColor()); | ||
if (totalfee.Value() > 0) { | ||
CTxOut txout(totalfee, scriptPubKeyIn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大概從303行開始到這邊,
totalfee應該是map, 這樣不會把fee以外的東西一起丟進去嗎
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
沒給初始值?
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
balance[color]沒東西會怎麼樣?
There was a problem hiding this comment.
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"); | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
為何要多加上上面那串 然後再註解掉啊
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
空的會怎樣?
There was a problem hiding this comment.
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
e0d6fa1
to
3f2c0d5
Compare
sendtoaddress() listaddressgroupings() getreceivedbyaddress() getreceivedbyaccount()
coins_cache_simulation_test
DoS_mapOrphans
GetAccountBalance() getbalance()
MempoolRemoveTest
multisig_verify multisig_Sign
Verify() sign set AreInputsStandard
ConnectTransactions()
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()
refine the operators
be54d0f
to
a64c426
Compare
sendfrom() sendtoaddress()
The original value handling type
CAmount
does not support multi-color. The original method to implement multi-color is simply adding a newtype_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 as1:1000
means color 1 with amount 1000.