Skip to content

Commit

Permalink
fix(json-abi): accept nameless Params
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Feb 12, 2024
1 parent 5f07b82 commit 4b9c72c
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/json-abi/src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ impl EventParam {

#[derive(Deserialize, Serialize)]
struct BorrowedParam<'a> {
#[serde(default)]
name: &'a str,
#[serde(rename = "type")]
ty: &'a str,
Expand Down
2 changes: 1 addition & 1 deletion crates/json-abi/tests/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn to_sol_test(path: &str, abi: &JsonAbi, run_solc: bool) {
if matches!(
name,
// https://github.com/alloy-rs/core/issues/349
"ZeroXExchange" | "GaugeController" | "DoubleExponentInterestSetter"
"ZeroXExchange" | "GaugeController" | "DoubleExponentInterestSetter" | "NamelessParams"
) {
return;
}
Expand Down
131 changes: 131 additions & 0 deletions crates/json-abi/tests/abi/NamelessParams.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
[
{
"type": "event",
"name": "Approval",
"inputs": [
{ "name": "owner", "type": "address", "indexed": true },
{ "name": "approved", "type": "address", "indexed": true },
{ "name": "tokenId", "type": "uint256", "indexed": true }
],
"anonymous": false
},
{
"type": "event",
"name": "ApprovalForAll",
"inputs": [
{ "name": "owner", "type": "address", "indexed": true },
{ "name": "operator", "type": "address", "indexed": true },
{ "name": "approved", "type": "bool", "indexed": false }
],
"anonymous": false
},
{
"type": "event",
"name": "CancelLockupStream",
"inputs": [
{ "name": "streamId", "type": "uint256", "indexed": false },
{ "name": "sender", "type": "address", "indexed": true },
{ "name": "recipient", "type": "address", "indexed": true },
{ "name": "asset", "type": "address", "indexed": true },
{ "name": "senderAmount", "type": "uint128", "indexed": false },
{ "name": "recipientAmount", "type": "uint128", "indexed": false }
],
"anonymous": false
},
{
"type": "event",
"name": "CreateLockupDynamicStream",
"inputs": [
{ "name": "streamId", "type": "uint256", "indexed": false },
{ "name": "funder", "type": "address", "indexed": false },
{ "name": "sender", "type": "address", "indexed": true },
{ "name": "recipient", "type": "address", "indexed": true },
{
"name": "amounts",
"type": "tuple",
"indexed": false,
"components": [{ "type": "uint128" }, { "type": "uint128" }, { "type": "uint128" }]
},
{ "name": "asset", "type": "address", "indexed": true },
{ "name": "cancelable", "type": "bool", "indexed": false },
{ "name": "transferable", "type": "bool", "indexed": false },
{
"name": "segments",
"type": "tuple[]",
"indexed": false,
"components": [{ "type": "uint128" }, { "type": "uint64" }, { "type": "uint40" }]
},
{
"name": "range",
"type": "tuple",
"indexed": false,
"components": [{ "type": "uint40" }, { "type": "uint40" }]
},
{ "name": "broker", "type": "address", "indexed": false }
],
"anonymous": false
},
{
"type": "event",
"name": "CreateLockupLinearStream",
"inputs": [
{ "name": "streamId", "type": "uint256", "indexed": false },
{ "name": "funder", "type": "address", "indexed": false },
{ "name": "sender", "type": "address", "indexed": true },
{ "name": "recipient", "type": "address", "indexed": true },
{
"name": "amounts",
"type": "tuple",
"indexed": false,
"components": [{ "type": "uint128" }, { "type": "uint128" }, { "type": "uint128" }]
},
{ "name": "asset", "type": "address", "indexed": true },
{ "name": "cancelable", "type": "bool", "indexed": false },
{ "name": "transferable", "type": "bool", "indexed": false },
{
"name": "range",
"type": "tuple",
"indexed": false,
"components": [{ "type": "uint40" }, { "type": "uint40" }, { "type": "uint40" }]
},
{ "name": "broker", "type": "address", "indexed": false }
],
"anonymous": false
},
{
"type": "event",
"name": "RenounceLockupStream",
"inputs": [{ "name": "streamId", "type": "uint256", "indexed": true }],
"anonymous": false
},
{
"type": "event",
"name": "Transfer",
"inputs": [
{ "name": "from", "type": "address", "indexed": true },
{ "name": "to", "type": "address", "indexed": true },
{ "name": "tokenId", "type": "uint256", "indexed": true }
],
"anonymous": false
},
{
"type": "event",
"name": "TransferAdmin",
"inputs": [
{ "name": "oldAdmin", "type": "address", "indexed": true },
{ "name": "newAdmin", "type": "address", "indexed": true }
],
"anonymous": false
},
{
"type": "event",
"name": "WithdrawFromLockupStream",
"inputs": [
{ "name": "streamId", "type": "uint256", "indexed": true },
{ "name": "to", "type": "address", "indexed": true },
{ "name": "asset", "type": "address", "indexed": true },
{ "name": "amount", "type": "uint128", "indexed": false }
],
"anonymous": false
}
]
11 changes: 11 additions & 0 deletions crates/json-abi/tests/abi/NamelessParams.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
interface NamelessParams {
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
event CancelLockupStream(uint256 streamId, address indexed sender, address indexed recipient, address indexed asset, uint128 senderAmount, uint128 recipientAmount);
event CreateLockupDynamicStream(uint256 streamId, address funder, address indexed sender, address indexed recipient, (uint128, uint128, uint128) amounts, address indexed asset, bool cancelable, bool transferable, (uint128, uint64, uint40)[] segments, (uint40, uint40) range, address broker);
event CreateLockupLinearStream(uint256 streamId, address funder, address indexed sender, address indexed recipient, (uint128, uint128, uint128) amounts, address indexed asset, bool cancelable, bool transferable, (uint40, uint40, uint40) range, address broker);
event RenounceLockupStream(uint256 indexed streamId);
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event TransferAdmin(address indexed oldAdmin, address indexed newAdmin);
event WithdrawFromLockupStream(uint256 indexed streamId, address indexed to, address indexed asset, uint128 amount);
}
8 changes: 8 additions & 0 deletions crates/sol-types/src/types/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,14 @@ impl NameBuffer {
digits += 1;
}

// TODO(MSRV-1.67): Uncomment and remove everything above
/*
let Some(digits) = number.checked_ilog10() else {
return self.write_byte(b'0');
};
let digits = digits as usize + 1;
*/

let mut n = number;
let mut i = self.len + digits;
while n > 0 {
Expand Down

0 comments on commit 4b9c72c

Please sign in to comment.