mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-25 15:55:18 +00:00
feat(x/precisebank): Emit coin_spent and coin_received events (#1978)
This commit is contained in:
parent
f229afce1a
commit
5f802fcfbd
@ -60,14 +60,15 @@ func (k Keeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fullEmissionCoin := types.SumExtendedCoin(amt)
|
fullEmissionCoins := sdk.NewCoins(types.SumExtendedCoin(amt))
|
||||||
if fullEmissionCoin.IsZero() {
|
if fullEmissionCoins.IsZero() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.EventManager().EmitEvent(
|
ctx.EventManager().EmitEvents(sdk.Events{
|
||||||
banktypes.NewCoinBurnEvent(acc.GetAddress(), sdk.NewCoins(fullEmissionCoin)),
|
banktypes.NewCoinBurnEvent(acc.GetAddress(), fullEmissionCoins),
|
||||||
)
|
banktypes.NewCoinSpentEvent(acc.GetAddress(), fullEmissionCoins),
|
||||||
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -217,20 +217,22 @@ func (suite *burnIntegrationTestSuite) TestBurnCoins() {
|
|||||||
fraCoinAmt := tt.burnCoins.AmountOf(types.ExtendedCoinDenom)
|
fraCoinAmt := tt.burnCoins.AmountOf(types.ExtendedCoinDenom)
|
||||||
|
|
||||||
totalExtCoinAmt := intCoinAmt.Add(fraCoinAmt)
|
totalExtCoinAmt := intCoinAmt.Add(fraCoinAmt)
|
||||||
|
spentCoins := sdk.NewCoins(sdk.NewCoin(
|
||||||
events := suite.Ctx.EventManager().Events()
|
|
||||||
extendedEvent := banktypes.NewCoinBurnEvent(
|
|
||||||
recipientAddr,
|
|
||||||
sdk.NewCoins(sdk.NewCoin(
|
|
||||||
types.ExtendedCoinDenom,
|
types.ExtendedCoinDenom,
|
||||||
totalExtCoinAmt,
|
totalExtCoinAmt,
|
||||||
)),
|
))
|
||||||
)
|
|
||||||
|
events := suite.Ctx.EventManager().Events()
|
||||||
|
|
||||||
|
expBurnEvent := banktypes.NewCoinBurnEvent(recipientAddr, spentCoins)
|
||||||
|
expSpendEvent := banktypes.NewCoinSpentEvent(recipientAddr, spentCoins)
|
||||||
|
|
||||||
if totalExtCoinAmt.IsZero() {
|
if totalExtCoinAmt.IsZero() {
|
||||||
suite.Require().NotContains(events, extendedEvent)
|
suite.Require().NotContains(events, expBurnEvent)
|
||||||
|
suite.Require().NotContains(events, expSpendEvent)
|
||||||
} else {
|
} else {
|
||||||
suite.Require().Contains(events, extendedEvent)
|
suite.Require().Contains(events, expBurnEvent)
|
||||||
|
suite.Require().Contains(events, expSpendEvent)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -63,14 +63,15 @@ func (k Keeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fullEmissionCoin := types.SumExtendedCoin(amt)
|
fullEmissionCoins := sdk.NewCoins(types.SumExtendedCoin(amt))
|
||||||
if fullEmissionCoin.IsZero() {
|
if fullEmissionCoins.IsZero() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.EventManager().EmitEvent(
|
ctx.EventManager().EmitEvents(sdk.Events{
|
||||||
banktypes.NewCoinMintEvent(acc.GetAddress(), sdk.NewCoins(fullEmissionCoin)),
|
banktypes.NewCoinMintEvent(acc.GetAddress(), fullEmissionCoins),
|
||||||
)
|
banktypes.NewCoinReceivedEvent(acc.GetAddress(), fullEmissionCoins),
|
||||||
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -342,21 +342,27 @@ func (suite *mintIntegrationTestSuite) TestMintCoins() {
|
|||||||
fraCoinAmt := mt.mintAmount.AmountOf(types.ExtendedCoinDenom)
|
fraCoinAmt := mt.mintAmount.AmountOf(types.ExtendedCoinDenom)
|
||||||
|
|
||||||
totalExtCoinAmt := intCoinAmt.Add(fraCoinAmt)
|
totalExtCoinAmt := intCoinAmt.Add(fraCoinAmt)
|
||||||
|
extCoins := sdk.NewCoins(sdk.NewCoin(types.ExtendedCoinDenom, totalExtCoinAmt))
|
||||||
|
|
||||||
// Check for mint event
|
// Check for mint event
|
||||||
events := suite.Ctx.EventManager().Events()
|
events := suite.Ctx.EventManager().Events()
|
||||||
extendedEvent := banktypes.NewCoinMintEvent(
|
|
||||||
|
expMintEvent := banktypes.NewCoinMintEvent(
|
||||||
recipientAddr,
|
recipientAddr,
|
||||||
sdk.NewCoins(sdk.NewCoin(
|
extCoins,
|
||||||
types.ExtendedCoinDenom,
|
)
|
||||||
totalExtCoinAmt,
|
|
||||||
)),
|
expReceivedEvent := banktypes.NewCoinReceivedEvent(
|
||||||
|
recipientAddr,
|
||||||
|
extCoins,
|
||||||
)
|
)
|
||||||
|
|
||||||
if totalExtCoinAmt.IsZero() {
|
if totalExtCoinAmt.IsZero() {
|
||||||
suite.Require().NotContains(events, extendedEvent)
|
suite.Require().NotContains(events, expMintEvent)
|
||||||
|
suite.Require().NotContains(events, expReceivedEvent)
|
||||||
} else {
|
} else {
|
||||||
suite.Require().Contains(events, extendedEvent)
|
suite.Require().Contains(events, expMintEvent)
|
||||||
|
suite.Require().Contains(events, expReceivedEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -64,12 +64,12 @@ func (k Keeper) SendCoins(
|
|||||||
|
|
||||||
// Get a full extended coin amount (passthrough integer + fractional) ONLY
|
// Get a full extended coin amount (passthrough integer + fractional) ONLY
|
||||||
// for event attributes.
|
// for event attributes.
|
||||||
fullEmissionCoin := types.SumExtendedCoin(amt)
|
fullEmissionCoins := sdk.NewCoins(types.SumExtendedCoin(amt))
|
||||||
|
|
||||||
// If no passthrough integer nor fractional coins, then no event emission.
|
// If no passthrough integer nor fractional coins, then no event emission.
|
||||||
// We also want to emit the event with the whole equivalent extended coin
|
// We also want to emit the event with the whole equivalent extended coin
|
||||||
// if only integer coins are sent.
|
// if only integer coins are sent.
|
||||||
if fullEmissionCoin.IsZero() {
|
if fullEmissionCoins.IsZero() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,8 +79,10 @@ func (k Keeper) SendCoins(
|
|||||||
banktypes.EventTypeTransfer,
|
banktypes.EventTypeTransfer,
|
||||||
sdk.NewAttribute(banktypes.AttributeKeyRecipient, to.String()),
|
sdk.NewAttribute(banktypes.AttributeKeyRecipient, to.String()),
|
||||||
sdk.NewAttribute(banktypes.AttributeKeySender, from.String()),
|
sdk.NewAttribute(banktypes.AttributeKeySender, from.String()),
|
||||||
sdk.NewAttribute(sdk.AttributeKeyAmount, fullEmissionCoin.String()),
|
sdk.NewAttribute(sdk.AttributeKeyAmount, fullEmissionCoins.String()),
|
||||||
),
|
),
|
||||||
|
banktypes.NewCoinSpentEvent(from, fullEmissionCoins),
|
||||||
|
banktypes.NewCoinReceivedEvent(to, fullEmissionCoins),
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -435,6 +435,7 @@ func (suite *sendIntegrationTestSuite) TestSendCoins() {
|
|||||||
types.ExtendedCoinDenom,
|
types.ExtendedCoinDenom,
|
||||||
sendAmountFullExtended.AmountOf(types.ExtendedCoinDenom),
|
sendAmountFullExtended.AmountOf(types.ExtendedCoinDenom),
|
||||||
)
|
)
|
||||||
|
extCoins := sdk.NewCoins(sendExtendedAmount)
|
||||||
|
|
||||||
// No extra events if not sending akava
|
// No extra events if not sending akava
|
||||||
if sendExtendedAmount.IsZero() {
|
if sendExtendedAmount.IsZero() {
|
||||||
@ -448,7 +449,21 @@ func (suite *sendIntegrationTestSuite) TestSendCoins() {
|
|||||||
sdk.NewAttribute(sdk.AttributeKeyAmount, sendExtendedAmount.String()),
|
sdk.NewAttribute(sdk.AttributeKeyAmount, sendExtendedAmount.String()),
|
||||||
)
|
)
|
||||||
|
|
||||||
suite.Require().Contains(suite.Ctx.EventManager().Events(), extendedEvent)
|
expReceivedEvent := banktypes.NewCoinReceivedEvent(
|
||||||
|
recipient,
|
||||||
|
extCoins,
|
||||||
|
)
|
||||||
|
|
||||||
|
expSentEvent := banktypes.NewCoinSpentEvent(
|
||||||
|
sender,
|
||||||
|
extCoins,
|
||||||
|
)
|
||||||
|
|
||||||
|
events := suite.Ctx.EventManager().Events()
|
||||||
|
|
||||||
|
suite.Require().Contains(events, extendedEvent)
|
||||||
|
suite.Require().Contains(events, expReceivedEvent)
|
||||||
|
suite.Require().Contains(events, expSentEvent)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user