nested Timepoint/Duration in struct args rejected by from_json
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
Hướng nghiên cứu
Vấn đề nằm trong cmd/crates/soroban-spec-tools/src/lib.rs. Hãy xem hàm from_json quanh dòng 328 và hàm from_json_primitives quanh dòng 937. Cách khắc phục là thêm ScType::Timepoint và ScType::Duration vào nhánh match định tuyến đến primitives, sau đó đảm bảo chúng tạo ra biến thể ScVal phù hợp (ScVal::Timepoint và ScVal::Duration) thay vì ScVal::U64. Kiểm tra bằng cách build CLI và chạy lệnh tái hiện được cung cấp.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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(...))`
- Ngôn ngữ chính
- Rust
- Star
- 123
- Fork
- 147
- Merge trung bình
- 1 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 31
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của stellar/stellar-cli
-
contract extend panics on single-change resultMetaXdr (index out of bounds at extend.rs:306)Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
stellar/stellar-cli#2796 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 85/100
stellar/stellar-cli#2781 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Display the full authorization tree before signing auth entriesCó thể đã có người làm @DeadZen đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
stellar/stellar-cli#2779 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`tx update sequence-number next` fails when the transaction source is a muxed accountCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
stellar/stellar-cli#2774 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`tx edit` fails on transaction XDR that is wrapped across multiple linesCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
stellar/stellar-cli#2773 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của stellar/stellar-cli
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
bmander/geomsolver#118 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Three Windows builds are keyed on a later release than their layoutCó thể đã có người làm @ero-qt đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 2 ngày
-
priority:P3 type:docs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
sebastian-software/ferroni#253 ·
Maintainer thường phản hồi trong vòng 1 ngày