/
common.go
38 lines (32 loc) · 1.05 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package integrationTests
import (
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/testscommon/stakingcommon"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
)
// ProcessSCOutputAccounts will save account changes in accounts db from vmOutput
func ProcessSCOutputAccounts(vmOutput *vmcommon.VMOutput, accountsDB state.AccountsAdapter) error {
outputAccounts := process.SortVMOutputInsideData(vmOutput)
for _, outAcc := range outputAccounts {
acc := stakingcommon.LoadUserAccount(accountsDB, outAcc.Address)
storageUpdates := process.GetSortedStorageUpdates(outAcc)
for _, storeUpdate := range storageUpdates {
err := acc.SaveKeyValue(storeUpdate.Offset, storeUpdate.Data)
if err != nil {
return err
}
if outAcc.BalanceDelta != nil && outAcc.BalanceDelta.Cmp(zero) != 0 {
err = acc.AddToBalance(outAcc.BalanceDelta)
if err != nil {
return err
}
}
err = accountsDB.SaveAccount(acc)
if err != nil {
return err
}
}
}
return nil
}