Skip to content

Commit

Permalink
fix delete issue
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing committed Jul 1, 2023
1 parent ea60756 commit a874af1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
57 changes: 32 additions & 25 deletions app/reconciliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,39 @@ func (app *BinanceChain) getAccountChanges(ctx sdk.Context, accountStore *store.

diff := accountStore.GetDiff()
version := accountStore.GetTree().Version() - 1
for k, v := range diff {
for k := range diff {
if k == globalAccountNumber {
continue
}
var acc1 sdk.Account
err := app.Codec.UnmarshalBinaryBare(v, &acc1)
if err != nil {
panic("failed to unmarshal diff value " + err.Error())
v := accountStore.Get([]byte(k))
if v != nil {
var acc1 sdk.Account
err := app.Codec.UnmarshalBinaryBare(v, &acc1)
if err != nil {
panic("failed to unmarshal current value " + err.Error())
}
nacc1 := acc1.(types.NamedAccount)
ctx.Logger().Debug("current account", "address", nacc1.GetAddress(), "coins", nacc1.GetCoins().String())
currentCoins = currentCoins.Plus(nacc1.GetCoins())
currentCoins = currentCoins.Plus(nacc1.GetFrozenCoins())
currentCoins = currentCoins.Plus(nacc1.GetLockedCoins())
}
nacc1 := acc1.(types.NamedAccount)
ctx.Logger().Debug("diff account", "address", nacc1.GetAddress(), "coins", nacc1.GetCoins().String())
currentCoins = currentCoins.Plus(nacc1.GetCoins())
currentCoins = currentCoins.Plus(nacc1.GetFrozenCoins())
currentCoins = currentCoins.Plus(nacc1.GetLockedCoins())

var acc2 sdk.Account
_, v = accountStore.GetTree().GetVersioned([]byte(k), version)
if v != nil { // it is not a new account
err = app.Codec.UnmarshalBinaryBare(v, &acc2)
var acc2 sdk.Account
err := app.Codec.UnmarshalBinaryBare(v, &acc2)
if err != nil {
panic("failed to unmarshal previous value " + err.Error())
}
nacc2 := acc2.(types.NamedAccount)

ctx.Logger().Debug("pre account", "address", nacc2.GetAddress(), "coins", nacc2.GetCoins().String())
preCoins = preCoins.Plus(nacc2.GetCoins())
preCoins = preCoins.Plus(nacc2.GetFrozenCoins())
preCoins = preCoins.Plus(nacc2.GetLockedCoins())
}
}
ctx.Logger().Debug("account changes", "diff", currentCoins.String(), "previous", preCoins.String(),
ctx.Logger().Debug("account changes", "current", currentCoins.String(), "previous", preCoins.String(),
"version", version, "height", ctx.BlockHeight())

return preCoins, currentCoins
Expand All @@ -85,29 +87,34 @@ func (app *BinanceChain) getTokenChanges(ctx sdk.Context, tokenStore *store.Iavl

diff := tokenStore.GetDiff()
version := tokenStore.GetTree().Version() - 1
for k, v := range diff {
var token1 types.IToken
err := app.Codec.UnmarshalBinaryBare(v, &token1)
if err != nil {
panic("failed to unmarshal diff value " + err.Error())
for k := range diff {
v := tokenStore.Get([]byte(k))
if v != nil {
var token1 types.IToken
err := app.Codec.UnmarshalBinaryBare(v, &token1)
if err != nil {
panic("failed to unmarshal current value " + err.Error())
}
ctx.Logger().Debug("current token", "symbol", token1.GetSymbol(), "supply", token1.GetTotalSupply().ToInt64())
currentCoins = currentCoins.Plus(sdk.Coins{
sdk.NewCoin(token1.GetSymbol(), token1.GetTotalSupply().ToInt64()),
})
}
currentCoins = currentCoins.Plus(sdk.Coins{
sdk.NewCoin(token1.GetSymbol(), token1.GetTotalSupply().ToInt64()),
})

var token2 types.IToken
_, v = tokenStore.GetTree().GetVersioned([]byte(k), version)
if v != nil { // it is not a new token
err = app.Codec.UnmarshalBinaryBare(v, &token2)
var token2 types.IToken
err := app.Codec.UnmarshalBinaryBare(v, &token2)
if err != nil {
panic("failed to unmarshal previous value " + err.Error())
}
ctx.Logger().Debug("previous token", "symbol", token2.GetSymbol(), "supply", token2.GetTotalSupply().ToInt64())
preCoins = preCoins.Plus(sdk.Coins{
sdk.NewCoin(token2.GetSymbol(), token2.GetTotalSupply().ToInt64()),
})
}
}
ctx.Logger().Debug("token changes", "diff", currentCoins.String(), "previous", preCoins.String(),
ctx.Logger().Debug("token changes", "current", currentCoins.String(), "previous", preCoins.String(),
"version", version, "height", ctx.BlockHeight())

return preCoins, currentCoins
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ require (
)

replace (
github.com/cosmos/cosmos-sdk => github.com/forcodedancing/bnc-cosmos-sdk v0.25.8-0.20230531023724-2e22c6326b67
github.com/cosmos/cosmos-sdk => github.com/forcodedancing/bnc-cosmos-sdk v0.25.8-0.20230701072933-c98179b67b45
github.com/tendermint/go-amino => github.com/bnb-chain/bnc-go-amino v0.14.1-binance.2
github.com/tendermint/iavl => github.com/bnb-chain/bnc-tendermint-iavl v0.12.0-binance.5
github.com/tendermint/tendermint => github.com/bnb-chain/bnc-tendermint v0.32.3-bc.10
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/etcd-io/bbolt v1.3.3 h1:gSJmxrs37LgTqR/oyJBWok6k6SvXEUerFTbltIhXkBM=
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
github.com/forcodedancing/bnc-cosmos-sdk v0.25.8-0.20230531023724-2e22c6326b67 h1:yysn9/l3K9jEcdJ4Nd25tvPLHQxw1J9PkS4a3RyNRNM=
github.com/forcodedancing/bnc-cosmos-sdk v0.25.8-0.20230531023724-2e22c6326b67/go.mod h1:XiDYVT+XqECR+AyCBO4KBsrbL/d1x2UTsVU36SvHxI8=
github.com/forcodedancing/bnc-cosmos-sdk v0.25.8-0.20230701072933-c98179b67b45 h1:TkZrewxzq2gL+Q8W3Smv6yt2bf3SHnsZvdGSKq2Cpzo=
github.com/forcodedancing/bnc-cosmos-sdk v0.25.8-0.20230701072933-c98179b67b45/go.mod h1:XiDYVT+XqECR+AyCBO4KBsrbL/d1x2UTsVU36SvHxI8=
github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
Expand Down

0 comments on commit a874af1

Please sign in to comment.