forked from cerc-io/laconicd-deprecated
Coin balance fix (#151)
* Fix setting account balances from assuming single denom * Set order for end blocker to not override account balances * Panic instead of ignoring error (case should never be hit)
This commit is contained in:
parent
1f51b73d71
commit
327abc4edf
@ -139,10 +139,11 @@ func ethAnteHandler(
|
||||
// Cost calculates the fees paid to validators based on gas limit and price
|
||||
cost := new(big.Int).Mul(ethTxMsg.Data.Price, new(big.Int).SetUint64(ethTxMsg.Data.GasLimit))
|
||||
|
||||
err = auth.DeductFees(sk, ctx, senderAcc, sdk.Coins{
|
||||
feeAmt := sdk.Coins{
|
||||
sdk.NewCoin(emint.DenomDefault, sdk.NewIntFromBigInt(cost)),
|
||||
})
|
||||
}
|
||||
|
||||
err = auth.DeductFees(sk, ctx, senderAcc, feeAmt)
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
|
@ -197,9 +197,9 @@ func NewEthermintApp(
|
||||
// During begin block slashing happens after distr.BeginBlocker so that
|
||||
// there is nothing left over in the validator fee pool, so as to keep the
|
||||
// CanWithdrawInvariant invariant.
|
||||
app.mm.SetOrderBeginBlockers(mint.ModuleName, distr.ModuleName, slashing.ModuleName, evmtypes.ModuleName)
|
||||
app.mm.SetOrderBeginBlockers(evmtypes.ModuleName, mint.ModuleName, distr.ModuleName, slashing.ModuleName)
|
||||
|
||||
app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, staking.ModuleName, evmtypes.ModuleName)
|
||||
app.mm.SetOrderEndBlockers(evmtypes.ModuleName, crisis.ModuleName, gov.ModuleName, staking.ModuleName)
|
||||
|
||||
// NOTE: The genutils module must occur after staking so that pools are
|
||||
// properly initialized with tokens from genesis accounts.
|
||||
|
@ -47,10 +47,22 @@ func (acc Account) Balance() sdk.Int {
|
||||
return acc.GetCoins().AmountOf(DenomDefault)
|
||||
}
|
||||
|
||||
// SetBalance sets an account's balance.
|
||||
// SetBalance sets an account's balance of photons
|
||||
func (acc Account) SetBalance(amt sdk.Int) {
|
||||
//nolint:gosec,errcheck
|
||||
acc.SetCoins(sdk.Coins{sdk.NewCoin(DenomDefault, amt)})
|
||||
coins := acc.GetCoins()
|
||||
diff := amt.Sub(coins.AmountOf(DenomDefault))
|
||||
if diff.IsZero() {
|
||||
return
|
||||
} else if diff.IsPositive() {
|
||||
// Increase coins to amount
|
||||
coins = coins.Add(sdk.Coins{sdk.NewCoin(DenomDefault, diff)})
|
||||
} else {
|
||||
// Decrease coins to amount
|
||||
coins = coins.Sub(sdk.Coins{sdk.NewCoin(DenomDefault, diff.Neg())})
|
||||
}
|
||||
if err := acc.SetCoins(coins); err != nil {
|
||||
panic(fmt.Sprintf("Could not set coins for address %s", acc.GetAddress()))
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user