Documentation
¶
Index ¶
- Constants
- func FormatDenomUnits(units []*banktypes.DenomUnit) string
- func GetTransferAmount(packet channeltypes.Packet) (string, error)
- func GetTransferSenderRecipient(packet channeltypes.Packet) (sender, recipient sdk.AccAddress, senderBech32, recipientBech32 string, ...)
- func HasNilDenomUnit(units []*banktypes.DenomUnit) bool
- func NonZeroUnitExponent(units []*banktypes.DenomUnit, denom string) (uint32, bool)
- func NormalizeVoucherMetadata(metadata banktypes.Metadata) (banktypes.Metadata, string, bool)
- func SameDenomUnits(a, b []*banktypes.DenomUnit) bool
- type Module
- func (im Module) OnAcknowledgementPacket(ctx sdk.Context, channelVersion string, packet channeltypes.Packet, ...) error
- func (im Module) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string) error
- func (im Module) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error
- func (im Module) OnChanOpenAck(ctx sdk.Context, ...) error
- func (im Module) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error
- func (im Module) OnChanOpenInit(ctx sdk.Context, order channeltypes.Order, connectionHops []string, ...) (string, error)
- func (im Module) OnChanOpenTry(ctx sdk.Context, order channeltypes.Order, connectionHops []string, ...) (version string, err error)
- func (im Module) OnRecvPacket(ctx sdk.Context, channelVersion string, packet channeltypes.Packet, ...) exported.Acknowledgement
- func (im Module) OnTimeoutPacket(ctx sdk.Context, channelVersion string, packet channeltypes.Packet, ...) error
- type NormalizationOutcome
- type NormalizationResult
- type VoucherBankStore
Constants ¶
const VoucherPrefix = "ibc/"
VoucherPrefix marks the bank denominations that are ICS-20 vouchers: the denominations the ERC20 side of this file exists for.
Variables ¶
This section is empty.
Functions ¶
func FormatDenomUnits ¶ added in v0.5.0
FormatDenomUnits renders a unit list for the audit log, marking nil elements instead of dereferencing them.
func GetTransferAmount ¶
func GetTransferAmount(packet channeltypes.Packet) (string, error)
GetTransferAmount returns the amount from an ICS20 FungibleTokenPacketData.
func GetTransferSenderRecipient ¶
func GetTransferSenderRecipient(packet channeltypes.Packet) ( sender, recipient sdk.AccAddress, senderBech32, recipientBech32 string, err error, )
GetTransferSenderRecipient returns the sender and recipient sdk.AccAddresses from an ICS20 FungibleTokenPacketData as well as the original sender bech32 address from the packet data. This function fails if: - the packet data is not FungibleTokenPacketData - sender address is invalid - recipient address is invalid
func HasNilDenomUnit ¶ added in v0.5.0
HasNilDenomUnit reports whether a bank metadata denom-unit list contains a nil *DenomUnit element.
A proto repeated message field can carry nil elements, and x/bank's Metadata.Validate dereferences every unit without a nil check (SDK v0.53 x/bank/types/metadata.go:42-58: `denomUnit.Denom`, `.Exponent`). A single already-stored nil unit therefore turns the metadata repair and the export diagnostic into a panic -- and those paths exist precisely to cope with inconsistent historical state, so neither may assume the list is structurally sound.
func NonZeroUnitExponent ¶ added in v0.5.0
NonZeroUnitExponent returns the exponent the metadata already records for denom, if it is non-zero. ibc-go's shape carries the source denom with exponent 0, which is the value being repaired, so zero is not a usable answer here.
Nil elements are skipped rather than dereferenced: proto repeated message fields can carry them, and this repair's job is to survive inconsistent historical state, not to panic on it.
func NormalizeVoucherMetadata ¶ added in v0.5.0
NormalizeVoucherMetadata returns the shape-C rewrite of a voucher's metadata, or the reason it cannot be repaired. It never mutates its input.
It is pure: the caller decides whether to store the result. That is what lets the upgrade handler and the inbound registration path share the decision while writing from their own keepers.
func SameDenomUnits ¶ added in v0.5.0
SameDenomUnits reports whether two unit lists are equal in order and content. A nil element compares as such (never dereferenced), so a corrupt list is reported as changed rather than crashing the caller.
Types ¶
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module a concrete type for a module boilerplate.
func (Module) OnAcknowledgementPacket ¶
func (im Module) OnAcknowledgementPacket( ctx sdk.Context, channelVersion string, packet channeltypes.Packet, acknowledgement []byte, relayer sdk.AccAddress, ) error
OnAcknowledgementPacket implements the Module interface. It calls the underlying app's OnAcknowledgementPacket callback.
func (Module) OnChanCloseConfirm ¶
OnChanCloseConfirm implements the Module interface. It calls the underlying app's OnChanCloseConfirm callback.
func (Module) OnChanCloseInit ¶
OnChanCloseInit implements the Module interface It calls the underlying app's OnChanCloseInit callback.
func (Module) OnChanOpenAck ¶
func (im Module) OnChanOpenAck( ctx sdk.Context, portID, channelID, counterpartyChannelID, counterpartyVersion string, ) error
OnChanOpenAck implements the Module interface. It calls the underlying app's OnChanOpenAck callback.
func (Module) OnChanOpenConfirm ¶
OnChanOpenConfirm implements the Module interface. It calls the underlying app's OnChanOpenConfirm callback.
func (Module) OnChanOpenInit ¶
func (im Module) OnChanOpenInit( ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID string, channelID string, counterparty channeltypes.Counterparty, version string, ) (string, error)
OnChanOpenInit implements the Module interface It calls the underlying app's OnChanOpenInit callback.
func (Module) OnChanOpenTry ¶
func (im Module) OnChanOpenTry( ctx sdk.Context, order channeltypes.Order, connectionHops []string, portID, channelID string, counterparty channeltypes.Counterparty, counterpartyVersion string, ) (version string, err error)
OnChanOpenTry implements the Module interface. It calls the underlying app's OnChanOpenTry callback.
func (Module) OnRecvPacket ¶
func (im Module) OnRecvPacket( ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, ) exported.Acknowledgement
OnRecvPacket implements the Module interface. It calls the underlying app's OnRecvPacket callback.
func (Module) OnTimeoutPacket ¶
func (im Module) OnTimeoutPacket( ctx sdk.Context, channelVersion string, packet channeltypes.Packet, relayer sdk.AccAddress, ) error
OnTimeoutPacket implements the Module interface. It calls the underlying app's OnTimeoutPacket callback.
type NormalizationOutcome ¶ added in v0.5.0
type NormalizationOutcome uint8
NormalizationOutcome is what NormalizeVoucherDecimals did, or refused to do, with one denomination. It exists as a named type rather than a bool so the three "nothing was written" cases stay distinguishable: an operator reading a log line has to be able to tell "already correct" from "could not be repaired" from "nothing to repair", and only the middle one is a defect.
const ( // NormalizationNoMetadata: the denom carries no bank metadata at all. The // ERC20 precompile then falls back to deriving decimals from the source denom // (precompiles/erc20/query.go:96-109), which is already the correct branch, so // there is nothing to repair. NormalizationNoMetadata NormalizationOutcome = iota // NormalizationAlreadyNormalized: the metadata is already shape C. NormalizationAlreadyNormalized // NormalizationApplied: the metadata was rewritten into shape C. NormalizationApplied // NormalizationSkipped: the record cannot be repaired without guessing an // exponent. Reason carries why; the record was left byte-identical. NormalizationSkipped )
func (NormalizationOutcome) String ¶ added in v0.5.0
func (o NormalizationOutcome) String() string
String renders the outcome for logs and test failure messages.
type NormalizationResult ¶ added in v0.5.0
type NormalizationResult struct {
Outcome NormalizationOutcome
Reason string
Decimals uint32
}
NormalizationResult is NormalizeVoucherDecimals' full answer. Decimals is only meaningful when the outcome is NormalizationApplied or NormalizationAlreadyNormalized: it is the exponent the ERC20 precompile will now report.
func NormalizeVoucherDecimals ¶ added in v0.5.0
func NormalizeVoucherDecimals( ctx context.Context, bank VoucherBankStore, denom string, ) NormalizationResult
NormalizeVoucherDecimals rewrites an IBC voucher's bank metadata into the only shape that satisfies both of the constraints it lives under, so that cosmos/evm's ERC20 precompile reports the right decimals.
What is wrong without it ¶
ibc-go writes a voucher's metadata as:
Base = "ibc/3D02…" (the voucher hash)
Display = "transfer/channel-1/auoc" (the full denom path)
DenomUnits = [{Denom: "auoc", Exponent: 0}]
cosmos/evm's precompile (precompiles/erc20/query.go:115-128) reads decimals differently for these: with an "ibc/" base it matches the LAST SEGMENT of Display against DenomUnits. That segment is "auoc", it matches the only unit, and that unit's exponent is 0 -- so decimals() returns 0. Wallets, explorers and DEX front-ends then read a 1 auoc balance as 10^18.
THE SHAPE THAT WORKS ("shape C" in the test-side analysis)
Display = "auoc" (the source denom, no path)
DenomUnits = [{Base, 0}, {"auoc", 18}]
which satisfies:
- x/bank's Metadata.Validate (first unit is the base with exponent 0, units sorted ascending, Display present among them), so the metadata stops being illegal state; and
- the precompile's rule above, whose last-segment match now lands on the unit carrying the real exponent.
Why this lives here and not in the upgrade handler ¶
The v0.5.0 handler repairs what the chain already holds (one pass, bounded by what the chain accepted before the upgrade). The inbound auto-registration path keeps minting NEW vouchers after the upgrade, and it writes ibc-go's shape every time -- so a handler-only repair leaves two populations on one chain and decimals() depends on whether a pair predates the upgrade. Both callers therefore share this one implementation instead of each carrying a copy that can drift.
The counterparty picks the source denom, so a wrong exponent here silently rescales a real asset. Everything that cannot be read is therefore skipped with a reason rather than guessed.
CONTRACT: the caller passes a denomination that carries the ibc/ prefix; the entry point enforces it. NormalizeVoucherMetadata on its own assumes it.
func (NormalizationResult) Changed ¶ added in v0.5.0
func (r NormalizationResult) Changed() bool
Changed reports whether a state write happened. The callers log a repair only for this outcome, so that a replayed or crash-restarted pass stays silent.
type VoucherBankStore ¶ added in v0.5.0
type VoucherBankStore interface {
GetDenomMetaData(ctx context.Context, denom string) (banktypes.Metadata, bool)
SetDenomMetaData(ctx context.Context, metadata banktypes.Metadata)
}
VoucherBankStore is the slice of x/bank the voucher normalization needs. The SDK v0.53 bank keeper takes a plain context.Context (not sdk.Context), which sdk.Context satisfies, so both a live app and a test double fit this interface.