Contract call return value parsing problem
litcc opened this issue · 1 comments
litcc commented
When abi is the following result
{
"inputs": [],
"name": "slot0",
"outputs": [
{
"internalType": "uint160",
"name": "sqrtPriceX96",
"type": "uint160"
},
{
"internalType": "int24",
"name": "tick",
"type": "int24"
},
{
"internalType": "uint16",
"name": "observationIndex",
"type": "uint16"
},
{
"internalType": "uint16",
"name": "observationCardinality",
"type": "uint16"
},
{
"internalType": "uint16",
"name": "observationCardinalityNext",
"type": "uint16"
},
{
"internalType": "uint8",
"name": "feeProtocol",
"type": "uint8"
},
{
"internalType": "bool",
"name": "unlocked",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
}
Corresponding contract call code:
contract.query::<Vec<Token>,_,_,_>("slot0",(),None,Options::default(),None)
The code there always reports an error, no matter what I set the return value type to be
rust-web3/src/contract/tokens.rs
Line 20 in c593b72
Because the function returns a list, there may be more than one
Line 276 in c593b72
I think this is a bug
litcc commented
Sorry, this may be a misunderstanding, a separate implementation of Detokenize will solve the problem
#[derive(Debug)]
enum OutputData {
One(Token),
List(Vec<Token>)
}
impl Detokenize for OutputData {
fn from_tokens(tokens: Vec<Token>) -> std::result::Result<Self, Error> where Self: Sized {
if tokens.len() !=1 {
Ok(OutputData::List(tokens))
}else {
Ok(OutputData::One(tokens.first().unwrap().to_owned()))
}
}
}
contract.query::<OutputData,_,_,_>("slot0", (), None, Options::default(), None)