Skip to content

Commit

Permalink
common: improve documentation comments (ethereum#16701)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Dec 21, 2024
1 parent 82ff8c1 commit 08cd815
Show file tree
Hide file tree
Showing 21 changed files with 118 additions and 180 deletions.
2 changes: 1 addition & 1 deletion XDCx/order_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func DoSettleBalance(coinbase common.Address, takerOrder, makerOrder *tradingsta
matchingFee = new(big.Int).Add(matchingFee, common.RelayerFee)
matchingFee = new(big.Int).Add(matchingFee, common.RelayerFee)

if common.EmptyHash(takerExOwner.Hash()) || common.EmptyHash(makerExOwner.Hash()) {
if takerExOwner.Hash().IsZero() || makerExOwner.Hash().IsZero() {
return fmt.Errorf("empty echange owner: taker: %v , maker : %v", takerExOwner, makerExOwner)
}
mapBalances := map[common.Address]map[common.Address]*big.Int{}
Expand Down
22 changes: 11 additions & 11 deletions XDCx/tradingstate/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (t *TradingStateDB) DumpAskTrie(orderBook common.Hash) (map[*big.Int]DumpOr
it := trie.NewIterator(exhangeObject.getAsksTrie(t.db).NodeIterator(nil))
for it.Next() {
priceHash := common.BytesToHash(it.Key)
if common.EmptyHash(priceHash) {
if priceHash.IsZero() {
continue
}
price := new(big.Int).SetBytes(priceHash.Bytes())
Expand Down Expand Up @@ -99,7 +99,7 @@ func (t *TradingStateDB) DumpBidTrie(orderBook common.Hash) (map[*big.Int]DumpOr
it := trie.NewIterator(exhangeObject.getBidsTrie(t.db).NodeIterator(nil))
for it.Next() {
priceHash := common.BytesToHash(it.Key)
if common.EmptyHash(priceHash) {
if priceHash.IsZero() {
continue
}
price := new(big.Int).SetBytes(priceHash.Bytes())
Expand Down Expand Up @@ -142,7 +142,7 @@ func (t *TradingStateDB) GetBids(orderBook common.Hash) (map[*big.Int]*big.Int,
it := trie.NewIterator(exhangeObject.getBidsTrie(t.db).NodeIterator(nil))
for it.Next() {
priceHash := common.BytesToHash(it.Key)
if common.EmptyHash(priceHash) {
if priceHash.IsZero() {
continue
}
price := new(big.Int).SetBytes(priceHash.Bytes())
Expand Down Expand Up @@ -185,7 +185,7 @@ func (t *TradingStateDB) GetAsks(orderBook common.Hash) (map[*big.Int]*big.Int,
it := trie.NewIterator(exhangeObject.getAsksTrie(t.db).NodeIterator(nil))
for it.Next() {
priceHash := common.BytesToHash(it.Key)
if common.EmptyHash(priceHash) {
if priceHash.IsZero() {
continue
}
price := new(big.Int).SetBytes(priceHash.Bytes())
Expand Down Expand Up @@ -224,7 +224,7 @@ func (s *stateOrderList) DumpOrderList(db Database) DumpOrderList {
orderListIt := trie.NewIterator(s.getTrie(db).NodeIterator(nil))
for orderListIt.Next() {
keyHash := common.BytesToHash(orderListIt.Key)
if common.EmptyHash(keyHash) {
if keyHash.IsZero() {
continue
}
if _, exist := s.cachedStorage[keyHash]; exist {
Expand All @@ -235,7 +235,7 @@ func (s *stateOrderList) DumpOrderList(db Database) DumpOrderList {
}
}
for key, value := range s.cachedStorage {
if !common.EmptyHash(value) {
if !value.IsZero() {
mapResult.Orders[new(big.Int).SetBytes(key.Bytes())] = new(big.Int).SetBytes(value.Bytes())
}
}
Expand Down Expand Up @@ -277,7 +277,7 @@ func (s *stateLendingBook) DumpOrderList(db Database) DumpOrderList {
orderListIt := trie.NewIterator(s.getTrie(db).NodeIterator(nil))
for orderListIt.Next() {
keyHash := common.BytesToHash(orderListIt.Key)
if common.EmptyHash(keyHash) {
if keyHash.IsZero() {
continue
}
if _, exist := s.cachedStorage[keyHash]; exist {
Expand All @@ -288,7 +288,7 @@ func (s *stateLendingBook) DumpOrderList(db Database) DumpOrderList {
}
}
for key, value := range s.cachedStorage {
if !common.EmptyHash(value) {
if !value.IsZero() {
mapResult.Orders[new(big.Int).SetBytes(key.Bytes())] = new(big.Int).SetBytes(value.Bytes())
}
}
Expand All @@ -311,7 +311,7 @@ func (l *liquidationPriceState) DumpLendingBook(db Database) (DumpLendingBook, e
it := trie.NewIterator(l.getTrie(db).NodeIterator(nil))
for it.Next() {
lendingBook := common.BytesToHash(it.Key)
if common.EmptyHash(lendingBook) {
if lendingBook.IsZero() {
continue
}
if _, exist := l.stateLendingBooks[lendingBook]; exist {
Expand All @@ -326,7 +326,7 @@ func (l *liquidationPriceState) DumpLendingBook(db Database) (DumpLendingBook, e
}
}
for lendingBook, stateLendingBook := range l.stateLendingBooks {
if !common.EmptyHash(lendingBook) {
if !lendingBook.IsZero() {
result.LendingBooks[lendingBook] = stateLendingBook.DumpOrderList(db)
}
}
Expand All @@ -342,7 +342,7 @@ func (t *TradingStateDB) DumpLiquidationPriceTrie(orderBook common.Hash) (map[*b
it := trie.NewIterator(exhangeObject.getLiquidationPriceTrie(t.db).NodeIterator(nil))
for it.Next() {
priceHash := common.BytesToHash(it.Key)
if common.EmptyHash(priceHash) {
if priceHash.IsZero() {
continue
}
price := new(big.Int).SetBytes(priceHash.Bytes())
Expand Down
2 changes: 1 addition & 1 deletion XDCx/tradingstate/state_lendingbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (s *stateLendingBook) getAllTradeIds(db Database) []common.Hash {
return tradeIds
}
for id, value := range s.cachedStorage {
if !common.EmptyHash(value) {
if !value.IsZero() {
tradeIds = append(tradeIds, id)
}
}
Expand Down
8 changes: 4 additions & 4 deletions XDCx/tradingstate/state_orderbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ func (te *tradingExchanges) empty() bool {
if te.data.TotalQuantity != nil && te.data.TotalQuantity.Sign() > 0 {
return false
}
if !common.EmptyHash(te.data.AskRoot) {
if !te.data.AskRoot.IsZero() {
return false
}
if !common.EmptyHash(te.data.BidRoot) {
if !te.data.BidRoot.IsZero() {
return false
}
if !common.EmptyHash(te.data.OrderRoot) {
if !te.data.OrderRoot.IsZero() {
return false
}
if !common.EmptyHash(te.data.LiquidationPriceRoot) {
if !te.data.LiquidationPriceRoot.IsZero() {
return false
}
return true
Expand Down
4 changes: 2 additions & 2 deletions XDCx/tradingstate/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (t *TradingStateDB) GetBestAskPrice(orderBook common.Hash) (*big.Int, *big.
stateObject := t.getStateExchangeObject(orderBook)
if stateObject != nil {
priceHash := stateObject.getBestPriceAsksTrie(t.db)
if common.EmptyHash(priceHash) {
if priceHash.IsZero() {
return Zero, Zero
}
orderList := stateObject.getStateOrderListAskObject(t.db, priceHash)
Expand All @@ -375,7 +375,7 @@ func (t *TradingStateDB) GetBestBidPrice(orderBook common.Hash) (*big.Int, *big.
stateObject := t.getStateExchangeObject(orderBook)
if stateObject != nil {
priceHash := stateObject.getBestBidsTrie(t.db)
if common.EmptyHash(priceHash) {
if priceHash.IsZero() {
return Zero, Zero
}
orderList := stateObject.getStateBidOrderListObject(t.db, priceHash)
Expand Down
22 changes: 11 additions & 11 deletions XDCxlending/lendingstate/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (ls *LendingStateDB) DumpInvestingTrie(orderBook common.Hash) (map[*big.Int
it := trie.NewIterator(exhangeObject.getInvestingTrie(ls.db).NodeIterator(nil))
for it.Next() {
interestHash := common.BytesToHash(it.Key)
if common.EmptyHash(interestHash) {
if interestHash.IsZero() {
continue
}
interest := new(big.Int).SetBytes(interestHash.Bytes())
Expand Down Expand Up @@ -91,7 +91,7 @@ func (ls *LendingStateDB) DumpBorrowingTrie(orderBook common.Hash) (map[*big.Int
it := trie.NewIterator(exhangeObject.getBorrowingTrie(ls.db).NodeIterator(nil))
for it.Next() {
interestHash := common.BytesToHash(it.Key)
if common.EmptyHash(interestHash) {
if interestHash.IsZero() {
continue
}
interest := new(big.Int).SetBytes(interestHash.Bytes())
Expand Down Expand Up @@ -134,7 +134,7 @@ func (ls *LendingStateDB) GetInvestings(orderBook common.Hash) (map[*big.Int]*bi
it := trie.NewIterator(exhangeObject.getInvestingTrie(ls.db).NodeIterator(nil))
for it.Next() {
interestHash := common.BytesToHash(it.Key)
if common.EmptyHash(interestHash) {
if interestHash.IsZero() {
continue
}
interest := new(big.Int).SetBytes(interestHash.Bytes())
Expand Down Expand Up @@ -177,7 +177,7 @@ func (ls *LendingStateDB) GetBorrowings(orderBook common.Hash) (map[*big.Int]*bi
it := trie.NewIterator(exhangeObject.getBorrowingTrie(ls.db).NodeIterator(nil))
for it.Next() {
interestHash := common.BytesToHash(it.Key)
if common.EmptyHash(interestHash) {
if interestHash.IsZero() {
continue
}
interest := new(big.Int).SetBytes(interestHash.Bytes())
Expand Down Expand Up @@ -216,7 +216,7 @@ func (il *itemListState) DumpItemList(db Database) DumpOrderList {
orderListIt := trie.NewIterator(il.getTrie(db).NodeIterator(nil))
for orderListIt.Next() {
keyHash := common.BytesToHash(orderListIt.Key)
if common.EmptyHash(keyHash) {
if keyHash.IsZero() {
continue
}
if _, exist := il.cachedStorage[keyHash]; exist {
Expand All @@ -227,7 +227,7 @@ func (il *itemListState) DumpItemList(db Database) DumpOrderList {
}
}
for key, value := range il.cachedStorage {
if !common.EmptyHash(value) {
if !value.IsZero() {
mapResult.Orders[new(big.Int).SetBytes(key.Bytes())] = new(big.Int).SetBytes(value.Bytes())
}
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func (lts *liquidationTimeState) DumpItemList(db Database) DumpOrderList {
orderListIt := trie.NewIterator(lts.getTrie(db).NodeIterator(nil))
for orderListIt.Next() {
keyHash := common.BytesToHash(orderListIt.Key)
if common.EmptyHash(keyHash) {
if keyHash.IsZero() {
continue
}
if _, exist := lts.cachedStorage[keyHash]; exist {
Expand All @@ -276,7 +276,7 @@ func (lts *liquidationTimeState) DumpItemList(db Database) DumpOrderList {
}
}
for key, value := range lts.cachedStorage {
if !common.EmptyHash(value) {
if !value.IsZero() {
mapResult.Orders[new(big.Int).SetBytes(key.Bytes())] = new(big.Int).SetBytes(value.Bytes())
}
}
Expand All @@ -303,7 +303,7 @@ func (ls *LendingStateDB) DumpLiquidationTimeTrie(orderBook common.Hash) (map[*b
it := trie.NewIterator(exhangeObject.getLiquidationTimeTrie(ls.db).NodeIterator(nil))
for it.Next() {
unixTimeHash := common.BytesToHash(it.Key)
if common.EmptyHash(unixTimeHash) {
if unixTimeHash.IsZero() {
continue
}
unixTime := new(big.Int).SetBytes(unixTimeHash.Bytes())
Expand Down Expand Up @@ -346,7 +346,7 @@ func (ls *LendingStateDB) DumpLendingOrderTrie(orderBook common.Hash) (map[*big.
it := trie.NewIterator(exhangeObject.getLendingItemTrie(ls.db).NodeIterator(nil))
for it.Next() {
orderIdHash := common.BytesToHash(it.Key)
if common.EmptyHash(orderIdHash) {
if orderIdHash.IsZero() {
continue
}
orderId := new(big.Int).SetBytes(orderIdHash.Bytes())
Expand Down Expand Up @@ -386,7 +386,7 @@ func (ls *LendingStateDB) DumpLendingTradeTrie(orderBook common.Hash) (map[*big.
it := trie.NewIterator(exhangeObject.getLendingTradeTrie(ls.db).NodeIterator(nil))
for it.Next() {
tradeIdHash := common.BytesToHash(it.Key)
if common.EmptyHash(tradeIdHash) {
if tradeIdHash.IsZero() {
continue
}
tradeId := new(big.Int).SetBytes(tradeIdHash.Bytes())
Expand Down
10 changes: 5 additions & 5 deletions XDCxlending/lendingstate/state_lendingbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ func (s *lendingExchangeState) empty() bool {
if s.data.TradeNonce != 0 {
return false
}
if !common.EmptyHash(s.data.InvestingRoot) {
if !s.data.InvestingRoot.IsZero() {
return false
}
if !common.EmptyHash(s.data.BorrowingRoot) {
if !s.data.BorrowingRoot.IsZero() {
return false
}
if !common.EmptyHash(s.data.LendingItemRoot) {
if !s.data.LendingItemRoot.IsZero() {
return false
}
if !common.EmptyHash(s.data.LendingTradeRoot) {
if !s.data.LendingTradeRoot.IsZero() {
return false
}
if !common.EmptyHash(s.data.LiquidationTimeRoot) {
if !s.data.LiquidationTimeRoot.IsZero() {
return false
}
return true
Expand Down
2 changes: 1 addition & 1 deletion XDCxlending/lendingstate/state_liquidationtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (lt *liquidationTimeState) getAllTradeIds(db Database) []common.Hash {
return tradeIds
}
for id, value := range lt.cachedStorage {
if !common.EmptyHash(value) {
if !value.IsZero() {
tradeIds = append(tradeIds, id)
}
}
Expand Down
4 changes: 2 additions & 2 deletions XDCxlending/lendingstate/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func (ls *LendingStateDB) GetBestInvestingRate(orderBook common.Hash) (*big.Int,
stateObject := ls.getLendingExchange(orderBook)
if stateObject != nil {
investingHash := stateObject.getBestInvestingInterest(ls.db)
if common.EmptyHash(investingHash) {
if investingHash.IsZero() {
return Zero, Zero
}
orderList := stateObject.getInvestingOrderList(ls.db, investingHash)
Expand All @@ -360,7 +360,7 @@ func (ls *LendingStateDB) GetBestBorrowRate(orderBook common.Hash) (*big.Int, *b
stateObject := ls.getLendingExchange(orderBook)
if stateObject != nil {
priceHash := stateObject.getBestBorrowingInterest(ls.db)
if common.EmptyHash(priceHash) {
if priceHash.IsZero() {
return Zero, Zero
}
orderList := stateObject.getBorrowingOrderList(ls.db, priceHash)
Expand Down
2 changes: 1 addition & 1 deletion XDCxlending/order_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ func DoSettleBalance(coinbase common.Address, takerOrder, makerOrder *lendingsta
// masternodes only charge borrower relayer fee
matchingFee = new(big.Int).Add(matchingFee, common.RelayerLendingFee)

if common.EmptyHash(takerExOwner.Hash()) || common.EmptyHash(makerExOwner.Hash()) {
if takerExOwner.Hash().IsZero() || makerExOwner.Hash().IsZero() {
return fmt.Errorf("empty echange owner: taker: %v , maker : %v", takerExOwner, makerExOwner)
}
mapBalances := map[common.Address]map[common.Address]*big.Int{}
Expand Down
Loading

0 comments on commit 08cd815

Please sign in to comment.