nested Timepoint/Duration in struct args rejected by from_json
维护者通常 2 天内回复
评估
调研方向
问题位于 cmd/crates/soroban-spec-tools/src/lib.rs。查看第 328 行附近的 from_json 函数和第 937 行附近的 from_json_primitives 函数。修复需要将 ScType::Timepoint 和 ScType::Duration 添加到路由至 primitives 的 match 分支中,然后确保它们生成正确的 ScVal 变体 (ScVal::Timepoint 和 ScVal::Duration),而不是 ScVal::U64。通过构建 CLI 并运行提供的复现命令进行测试。
由索引模型根据 Issue 内容生成。
描述
Problem
When a contract function takes a struct with a `Timepoint` or `Duration` field, `stellar contract invoke` fails to parse the JSON argument. Top-level Timepoint/Duration args work fine.
Root cause
Two bugs in `cmd/crates/soroban-spec-tools/src/lib.rs`:
1. `from_json` does not route Timepoint/Duration to primitive parsing
The match arm at line ~328 that dispatches to `from_json_primitives` lists:
`Bool, U128, I128, U256, I256, I32, I64, U32, U64, String, Symbol, Address, MuxedAddress, Bytes, BytesN`
`Timepoint` and `Duration` are missing. When a struct field has type `Timepoint`, `parse_strukt` calls `from_json(Value::Number(1234), ScType::Timepoint)`. Since Timepoint is not in the list, it falls through to the serde catch-all which tries to deserialize a bare JSON number as `ScVal` -- this fails because `ScVal` expects tagged format (`{"timepoint": 1234}`).
Top-level args work because `from_string` pre-wraps the value as `{"timepoint": "value"}` before calling `from_json`.
2. `from_json_primitives` constructs `ScVal::U64` instead of `ScVal::Timepoint`
Line ~937:
```rust
(ScType::U64 | ScType::Timepoint | ScType::Duration, Value::Number(n)) => ScVal::U64(...)
```
This produces `ScVal::U64` for all three types. The Soroban VM distinguishes `SCV_U64` from `SCV_TIMEPOINT` and `SCV_DURATION` -- passing the wrong discriminant causes a host argument type mismatch at runtime.
Reproduce
Contract:
```rust
#[contracttype]
pub struct TimedAction {
pub deadline: Timepoint,
pub name: Symbol,
}
pub fn schedule(env: Env, action: TimedAction) -> TimedAction { action }
```
Invoke:
```
stellar contract invoke --id -- schedule --action '{"deadline": 1760501234, "name": "test"}'
```
Fails with a serde deserialization error on the `deadline` field.
Fix
- Add `| ScType::Timepoint | ScType::Duration` to the `from_json` primitives routing arm
- Split the `from_json_primitives` match so Timepoint produces `ScVal::Timepoint(TimePoint(...))` and Duration produces `ScVal::Duration(Duration(...))`
- 主要语言
- Rust
- 星标
- 129
- 派生
- 153
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 10
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
stellar/stellar-cli 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
stellar/stellar-cli#2880 ·
维护者通常 2 天内回复
-
arg_value_union panics on zero-arity union tuple case (unchecked type_[0] index)可能已有人在做 @hvoi 于 12 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 72/100
stellar/stellar-cli#2806 · 1 条评论 ·
维护者通常 2 天内回复
-
contract extend panics on single-change resultMetaXdr (index out of bounds at extend.rs:306)可能重新可做 @duongynhi000005-oss 于 8 天前认领,目前没有进行中的 PR。 未关闭
难度 1/5 1 小时以内 新手友好度 90/100
stellar/stellar-cli#2796 · 1 条评论 ·
维护者通常 2 天内回复
-
Document stellar-cli's RPC trust boundary可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 1/5 1-3 小时 新手友好度 85/100
stellar/stellar-cli#2781 · 1 条评论 ·
维护者通常 2 天内回复
-
Display the full authorization tree before signing auth entries可能已有人在做 @DeadZen 于 31 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
stellar/stellar-cli#2779 ·
维护者通常 2 天内回复
查看 stellar/stellar-cli 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
GiganticMinecraft/seichi-portal-backend#1651 ·
维护者通常 1 天内回复
-
Android visitors are offered the Linux .deb on cap.so's homepage and download page可能已有人在做 @patrickballard 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
CapSoftware/Cap#3677 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复