Field packing into a single quot;byte paramquot; field(将字段打包到单个字节参数中(Q;))
本文介绍了将字段打包到单个字节参数中(&Q;)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在试验AAVE的FlashLiqudidationAdapter.sol,它需要一个包含address,address,address,uint256,bool
的params
字段,但每当我编码和提交事务时,它都会在_decodeParameters
返回,这是一个函数,它将params
解包到智能合同中。我不确定我做错了什么。以下是我的纯(非编码)参数:
"0xb7c325266ec274feb1354021d27fa3e3379d840d,0xff682ff79feb2c057ec3ff1e083efdc66f9b37fb,0x1ea0B089673720e210552c624aFff9d67F8b1535,-1,0"
以下是已编码的参数):
b"000000000000000000000000b7c325266ec274feb1354021d27fa3e3379d840d000000000000000000000000ff682ff79feb2c057ec3ff1e083efdc66f9b37fb0000000000000000000000001ea0b089673720e210552c624afff9d67f8b1535ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000001"
这是整个交易:
tx = flash_loan.requestFlashLoan(["0xb7c325266ec274feb1354021d27fa3e3379d840d"], [(2.8134148508367174 / 2) * 1e18], [0], b"000000000000000000000000b7c325266ec274feb1354021d27fa3e3379d840d000000000000000000000000ff682ff79feb2c057ec3ff1e083efdc66f9b37fb0000000000000000000000001ea0b089673720e210552c624afff9d67f8b1535ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000001", {"gas_limit": "200000", "gas_price": Wei('4 gwei'), "from": account1, "allow_revert": True, "nonce": 46})
最后,这里是引用的_decodeParams
函数,如前所述,其中正在进行还原
/**
* @dev Decodes the information encoded in the flash loan params
* @param params Additional variadic field to include extra params. Expected parameters:
* address collateralAsset The collateral asset to claim
* address borrowedAsset The asset that must be covered and will be exchanged to pay the flash loan premium
* address user The user address with a Health Factor below 1
* uint256 debtToCover The amount of debt to cover
* bool useEthPath Use WETH as connector path between the collateralAsset and borrowedAsset at Uniswap
* @return LiquidationParams struct containing decoded params
*/
function _decodeParams(bytes memory params) internal pure returns (LiquidationParams memory) {
(
address collateralAsset,
address borrowedAsset,
address user,
uint256 debtToCover,
bool useEthPath
) = abi.decode(params, (address, address, address, uint256, bool));
return LiquidationParams(collateralAsset, borrowedAsset, user, debtToCover, useEthPath);
}
}
https://github.com/aave/protocol-v2/blob/master/contracts/adapters/FlashLiquidationAdapter.sol#L173-L184
注意,我使用的是固态编译器版本^0.6.12。
推荐答案
Solidity要求类型BYTE以0x
开头,因此作为params
传递的正确字节字符串应如下所示:
b"0x000000000000000000000000b7c325266ec274feb1354021d27fa3e3379d840d000000000000000000000000ff682ff79feb2c057ec3ff1e083efdc66f9b37fb0000000000000000000000001ea0b089673720e210552c624afff9d67f8b1535ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000001"
这篇关于将字段打包到单个字节参数中(&Q;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:将字段打包到单个字节参数中(&Q;)
基础教程推荐
猜你喜欢
- 将 YAML 文件转换为 python dict 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01