mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-05 13:06:20 +00:00
Merge pull request #546 from nspcc-dev/write-optimizations
Write optimizations
This commit is contained in:
commit
e4d821f32d
26 changed files with 59 additions and 50 deletions
|
@ -403,16 +403,17 @@ func (bc *Blockchain) storeBlock(block *Block) error {
|
|||
if balancesLen <= 1 {
|
||||
delete(account.Balances, prevTXOutput.AssetID)
|
||||
} else {
|
||||
var gotTx bool
|
||||
for index, balance := range account.Balances[prevTXOutput.AssetID] {
|
||||
if !gotTx && balance.Tx.Equals(input.PrevHash) && balance.Index == input.PrevIndex {
|
||||
gotTx = true
|
||||
}
|
||||
if gotTx && index+1 < balancesLen {
|
||||
account.Balances[prevTXOutput.AssetID][index] = account.Balances[prevTXOutput.AssetID][index+1]
|
||||
var index = -1
|
||||
for i, balance := range account.Balances[prevTXOutput.AssetID] {
|
||||
if balance.Tx.Equals(input.PrevHash) && balance.Index == input.PrevIndex {
|
||||
index = i
|
||||
break
|
||||
}
|
||||
}
|
||||
account.Balances[prevTXOutput.AssetID] = account.Balances[prevTXOutput.AssetID][:balancesLen-1]
|
||||
if index >= 0 {
|
||||
copy(account.Balances[prevTXOutput.AssetID][index:], account.Balances[prevTXOutput.AssetID][index+1:])
|
||||
account.Balances[prevTXOutput.AssetID] = account.Balances[prevTXOutput.AssetID][:balancesLen-1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue