TransferAuthorization 为 ibc.applications.transfer.v1.MsgTransfer 实现了 Authorization 接口。它允许授权方将代表自己提交 MsgTransfer 的权限授予被授权方。关于通过 x/authz 模块授予权限的更多细节,请参阅 Cosmos SDK 文档。 更具体地说,授权方允许被授权方通过指定通道转出属于授权方的资金。 对于指定通道,授权方必须能够为特定面额设置支出上限,以允许被授权方转移该面额的资产。 授权方还可以指定允许接收资金的地址列表。如果该列表为空,则允许所有地址接收。 其包含以下内容:
  • SourcePort 和 SourceChannel,二者共同构成唯一的转账通道标识符,授权资金可通过该通道转移。
  • SpendLimit,用于指定被授权方可转移的最大代币数量。随着代币被转出,SpendLimit 会相应更新;但如果金额使用 256 位无符号整数最大值这一哨兵值(即 2^256 - 1),则 SpendLimit 不会更新(请注意,使用该哨兵值将授予被授权方转移授权方账户中该面额 全部 可用代币的权限)。transfer 模块 types 包中的辅助函数 UnboundedSpendLimit 提供了可使用的该哨兵值。授权方也可以根据需要更新 SpendLimit,以提高或降低限额。
  • AllowList 列表,用于指定允许接收资金的地址列表。如果该列表为空,则允许所有地址从 TransferAuthorization 接收资金。
  • AllowedPacketData 列表,用于指定允许出现在数据包 memo 字段中的备注字符串列表。如果该列表为空,则只允许空 memo(包含非空内容的 memo 字段会被拒绝)。如果该列表只包含一个值为 "*" 的元素,则 memo 字段中允许包含任意内容。
在以下情况下,设置 TransferAuthorization 预期会失败:
  • 支出上限为 nil
  • 支出上限的面额不是合法的 coin 类型
  • 源端口 ID 非法
  • 源通道 ID 非法
  • AllowList 中存在重复项
  • memo 字段不被 AllowedPacketData 允许
以下是 TransferAuthorization 消息:
func NewTransferAuthorization(allocations ...Allocation) *TransferAuthorization {
    return &TransferAuthorization{
    Allocations: allocations,
}
}

type Allocation struct {
  / the port on which the packet will be sent
  SourcePort string 
  / the channel by which the packet will be sent
  SourceChannel string 
  / spend limitation on the channel
  SpendLimit sdk.Coins  
  / allow list of receivers, an empty allow list permits any receiver address
  AllowList []string 
  / allow list of memo strings, an empty list prohibits all memo strings;
  / a list only with "*" permits any memo string
  AllowedPacketData []string
}

TransferAuthorization implements the Authorization interface for ibc.applications.transfer.v1.MsgTransfer. It allows a granter to grant a grantee the privilege to submit MsgTransfer on its behalf. Please see the Cosmos SDK docs for more details on granting privileges via the x/authz module. More specifically, the granter allows the grantee to transfer funds that belong to the granter over a specified channel. For the specified channel, the granter must be able to specify a spend limit of a specific denomination they wish to allow the grantee to be able to transfer. The granter may be able to specify the list of addresses that they allow to receive funds. If empty, then all addresses are allowed. It takes:
  • a SourcePort and a SourceChannel which together comprise the unique transfer channel identifier over which authorized funds can be transferred.
  • a SpendLimit that specifies the maximum amount of tokens the grantee can transfer. The SpendLimit is updated as the tokens are transferred, unless the sentinel value of the maximum value for a 256-bit unsigned integer (i.e. 2^256 - 1) is used for the amount, in which case the SpendLimit will not be updated (please be aware that using this sentinel value will grant the grantee the privilege to transfer all the tokens of a given denomination available at the granter’s account). The helper function UnboundedSpendLimit in the types package of the transfer module provides the sentinel value that can be used. This SpendLimit may also be updated to increase or decrease the limit as the granter wishes.
  • an AllowList list that specifies the list of addresses that are allowed to receive funds. If this list is empty, then all addresses are allowed to receive funds from the TransferAuthorization.
  • an AllowedPacketData list that specifies the list of memo strings that are allowed to be included in the memo field of the packet. If this list is empty, then only an empty memo is allowed (a memo field with non-empty content will be denied). If this list includes a single element equal to "*", then any content in memo field will be allowed.
Setting a TransferAuthorization is expected to fail if:
  • the spend limit is nil
  • the denomination of the spend limit is an invalid coin type
  • the source port ID is invalid
  • the source channel ID is invalid
  • there are duplicate entries in the AllowList
  • the memo field is not allowed by AllowedPacketData
Below is the TransferAuthorization message:
func NewTransferAuthorization(allocations ...Allocation) *TransferAuthorization {
    return &TransferAuthorization{
    Allocations: allocations,
}
}

type Allocation struct {
  / the port on which the packet will be sent
  SourcePort string 
  / the channel by which the packet will be sent
  SourceChannel string 
  / spend limitation on the channel
  SpendLimit sdk.Coins  
  / allow list of receivers, an empty allow list permits any receiver address
  AllowList []string 
  / allow list of memo strings, an empty list prohibits all memo strings;
  / a list only with "*" permits any memo string
  AllowedPacketData []string
}