部署其它合约报错
zhouhuan2003 opened this issue · comments
就是部署其它的合约报错,命令如下:
xchain-cli evm deploy --account XC1111111111111111@xuper --cname FlightDelay --fee 5200000 solidity/FlightDelayInsurance.bin --abi solidity/FlightDelayInsurance.abi -a '{"_platformS":"0x6e3345DB2d22Da5E22cD051C565fB9BbEb67eF8a","_airlineV":"0x6e3345DB2d22Da5E22cD051C565fB9BbEb67eF8a","_insuranceCompanyC":"0x6e3345DB2d22Da5E22cD051C565fB9BbEb67eF8a","_premium":"20","_compensation":"20"}'
错误如下:
PreExe contract response : rpc error: code = Unknown desc = Err:500-50501-contract invoke failed+could not convert '0x6e3345DB2d22Da5E22cD051C565fB9BbEb67eF8a' to address: go-hex: invalid byte: U+0078 'x', logid:1685533854_3208951764792978
这是合约代码:
pragma solidity ^0.4.25;
contract FlightDelayInsurance {
address public platformS; // 平台S的地址
address public airlineV; // 航空公司V的地址
address public insuranceCompanyC; // 保险公司C的地址
uint public premium; // 保险费
uint public compensation; // 赔偿金额
uint public purchaseTime; // 购买保险的时间
uint public depositTime; // 存入赔偿金额的时间
bool public purchased; // 是否购买了保险
bool public deposited; // 是否存入了赔偿金额
mapping(address => uint256) public insured; // 已购买保险的用户及保费金额
mapping(address => bool) public policy; // 已生成保单的用户
mapping(address => bool) public purchasedTicket; // 已购买机票的用户
constructor(address _platformS, address _airlineV, address _insuranceCompanyC, uint _premium, uint _compensation) public {
platformS = _platformS; // 初始化平台S的地址
airlineV = _airlineV; // 初始化航空公司V的地址
insuranceCompanyC = _insuranceCompanyC; // 初始化保险公司C的地址
premium = _premium; // 初始化保险费
compensation = _compensation; // 初始化赔偿金额
}
function purchaseTicket() public {
require(!purchasedTicket[msg.sender], "Ticket has already beenpurchased"); // 该用户已购买机票
purchasedTicket[msg.sender] = true; // 标记该用户已购买机票
purchaseTime = block.timestamp;
}
/*********** 航班保险购买上链接口开发 **********/
function purchaseInsurance() public payable {
require(purchasedTicket[msg.sender], "Ticket has not been purchased"); // 该用户未购买机票
require(insured[msg.sender] == 0, "Insurance has already been purchased"); // 该用户已购买保险
require(msg.value == premium, "Premium amount is incorrect"); // 保费金额不正确
require(block.timestamp < purchaseTime + 30 minutes, "Purchase time has expired"); // 购买保险的时间已过期
purchased = true; // 标记已购买保险
insured[msg.sender] = msg.value; // 记录该用户已购买保险及保费金额
}
function depositCompensation() public payable {
require(msg.sender == insuranceCompanyC, "Only insurance company C can deposit compensation"); // 只有保险公司C可以存入赔偿金额
require(msg.value == compensation, "Compensation amount is incorrect"); // 赔偿金额不正确
require(block.timestamp < depositTime + 2 hours, "Deposit time has expired"); // 存入赔偿金额的时间已过期
deposited = true; // 标记已存入赔偿金额
}
function generatePolicy() public {
require(deposited, "Compensation has not been deposited"); // 赔偿金额未存入,无法生成保单
require(msg.sender == platformS, "Only platform S can generate policy"); // 只有平台S可以生成保单
require(!policy[msg.sender], "Policy has already been generated"); // 该用户已生成保单
policy[msg.sender] = true; // 标记该用户已生成保单
}
/*********** 退保接口开发 **********/
function refundInsurance() public {
require(deposited, "Compensation has not been deposited"); // 赔偿金额未存入,无法退保
require(insured[msg.sender] > 0, "Insurance has not been purchased"); // 该用户未购买保险,无法退保
require(!policy[msg.sender], "Policy has already been generated, refund not allowed"); // 该用户已生成保单,无法退保
uint256 refundAmount = insured[msg.sender]; // 获取用户购买保险的保费金额
insured[msg.sender] = 0; // 标记该用户已退保
msg.sender.transfer(refundAmount); // 退还用户保费
}
}
预期这里的 address 地址解析应该不包含0x
前缀
我查了下相关代码逻辑如下:
// Decode decodes src into DecodedLen(len(src)) bytes, returning the actual
// number of bytes written to dst.
//
// If Decode encounters invalid input, it returns an error describing the failure.
func Decode(dst, src []byte) (int, error) {
// ...
if n, ok := decodeGeneric(dst, src); !ok {
return 0, InvalidByteError(src[n])
}
// ...
}
func decodeGeneric(dst, src []byte) (uint64, bool) {
for i := 0; i < len(src)/2; i++ {
a, ok := fromHexChar(src[i*2])
// ...
b, ok := fromHexChar(src[i*2+1])
// ...
}
return 0, true
}
// fromHexChar converts a hex character into its value and a success flag.
func fromHexChar(c byte) (byte, bool) {
switch {
case '0' <= c && c <= '9':
return c - '0', true
case 'a' <= c && c <= 'f':
return c - 'a' + 10, true
case 'A' <= c && c <= 'F':
return c - 'A' + 10, true
}
return 0, false
}
这是Error的相关代码:
func (e InvalidByteError) Error() string {
return fmt.Sprintf("go-hex: invalid byte: %#U", rune(e))
}
把0x去掉