Type: Keeper
The Keeper
type implements the ICS4Wrapper
interface but passes arguments for the corresponding methods to the underlying ics4Wrapper
provided during construction. The Keeper
stores a reference to a TransferKeeper
, which allows submitting ICS-20 transfer messages; a ChannelKeeper
for communicating over channels; and a BankKeeper
to handle manual balance updates.
Function: ForwardTransferPacket
The ForwardTransferPacket
function does the following:
It calls
TransferKeeper.Transfer
to transfer the funds (either to the receiver if there is no next hop, or to the next hop, with the remaining forwarding metadata).It decrements the
InFlightPacket
's remaining retries, if this is not the first forwarding attempt.It stores
InFlightPacket
data with the number of remaining retries underRefundPacketKey
in theKeeper
's store.
Function: GetAndClearInFlightPacket
The GetAndClearInFlightPacket
function retrieves InFlightPacket
data for the specified channel ID, port ID, and sequence number in the store under the RefundPacketKey
if present and deletes it, returning nil
if the key was absent from the store and panicking if data is present in the store but fails to unmarshal.
Function: WriteAcknowledgementForForwardedPacket
The WriteAcknowledgementForForwardedPacket
function does the following:
It looks up the channel corresponding to the
InFlightPacket
's(RefundPortId, RefundChannelId)
tuple.If the acknowledgment from the next hop is successful, it forwards the acknowledgment to the previous hop via the underlying
ics4Wrapper
.If the packet is nonrefundable (which other middleware can mark by setting
NonrefundableKey
totrue
in the context), it callsKeeper.moveFundsToUserRecoverableAccount
and propagates the success/failure of that in the acknowledgment.It does the following if the tokens in the acknowledgment are issued by a previous hop.
If the tokens to be refunded are issued by a forward hop, it moves tokens from the forward escrow to the previous escrow.
If the tokens to be refunded are not issued by a forward hop, it burns tokens from the forward escrow.
It decreases the total escrow balance (via
unescrowToken
).
It does the following if the tokens in the acknowledgment are not issued by a previous hop.
It mints tokens to the forward escrow.
It increases the total escrow balance (inlined, but symmetric logic to
unescrowToken
).
Function: moveFundsToUserRecoverableAccount
The moveFundsToUserRecoverableAccount
function does the following:
It determines an address on the current chain that the original sender can operate via
userRecoverableAccount
.If the tokens are not issued by a previous hop, it mints them and transfers them to the user's account on the current chain.
If the tokens are issued by a previous hop, it transfers them from the escrow account associated with the previous hop to the user's account on the current chain and updates the escrow balance via
unescrowToken
.
Function: TimeoutShouldRetry
The TimeoutShouldRetry
function retrieves InFlightPacket
data for the specified channel ID, port ID, and sequence number in the store under the RefundPacketKey
. It returns nil
if the key was absent from the store, panics if the data is present from the store but fails to unmarshal, returns both the InFlightPacket
and an error if it has a nonpositive amount of retries remaining, and returns the InFlightPacket
with no error otherwise.
Function: RetryTimeout
The RetryTimeout
function populates the metadata.Next
field from the packet's memo
field (returning an error if it did not contain valid JSON), validates that the packet's Amount
parses (returning an error if not), and calls Keeper.ForwardTransferPacket
to attempt to forward the packet again.