一个字节数组可以转换为Cadence中的地址吗?

huangapple go评论44阅读模式
英文:

Can a byte array be converted to an Address in Cadence

问题

在Cadence中,从UInt8字节数组构建地址的方法是什么?

文档中有这个例子:

let someAddress: Address = 0x436164656E636521
someAddress.toBytes()

我尝试过的:

let hexStr = String.encodeHex([0,0,0,0,0,0,0,1])
let addrStr = "0x".concat(hexStr) // 得到一个格式为 '0x0000000000000001' 的字符串,但如何转换为地址类型?

能否将UInt8字节数组转换为地址类型?

用例是从一个RLP编码的数据函数参数中构建一个交易中的地址。

英文:

Is there way to construct an Address from a byte array of UInt8 in Cadence?

Docs have this example:

let someAddress: Address = 0x436164656E636521
someAddress.toBytes()

What I've tried:

let hexStr = String.encodeHex([0,0,0,0,0,0,0,1])
let addrStr = "0x".concat(hexStr) // gives a string in format '0x0000000000000001' but how cast to Address type?

Possible to do UInt8 byte array to Address?

The use case is to build an Address in a tx from an RLP-encoded data function argument.

答案1

得分: 0

这份合同提供了一些用于处理地址并从其他类型中解析地址的实用工具。在此处输入字符串的操作可行,例如。

链接:https://github.com/green-goo-dao/flow-utils/blob/main/cadence/contracts/AddressUtils.cdc

英文:

This contract has some utilities for working with Addresses and parsing them from other types. Sending in a string here works for instance.

https://github.com/green-goo-dao/flow-utils/blob/main/cadence/contracts/AddressUtils.cdc

huangapple
  • 本文由 发表于 2023年4月11日 11:32:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75982208.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定