Skip to content

nested Timepoint/Duration in struct args rejected by from_json #2753

Description

@yigitcangokmen

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

  1. Add `| ScType::Timepoint | ScType::Duration` to the `from_json` primitives routing arm
  2. Split the `from_json_primitives` match so Timepoint produces `ScVal::Timepoint(TimePoint(...))` and Duration produces `ScVal::Duration(Duration(...))`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Backlog (Not Ready)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions