ts bindings: Failure when converting function return value

Open
#1,105 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale

Research direction

Start at soroban-client/lib/contract_spec.js around line 374 and inspect how the generated binding converts an Option<(u32, u32)> return value. Reproduce the JavaScript call to coords with token_id 0 and compare it with the CLI result [17,31]. Done means the TypeScript binding converts this return value without throwing.

Written by the indexing model from the issue text.

Description

bug
What version are you using?

soroban --version
soroban 20.0.0-rc4 (bce5e56ba16ba977200b022c91f3eaf6282f47eb)
soroban-env 20.0.0-rc2 (8c63bff68a15d79aca3a705ee6916a68db57b7e6)
soroban-env interface version 85899345977
stellar-xdr 20.0.0-rc1 (d5ce0c9e7aa83461773a6e81662067f35d39e4c1)
xdr curr (9ac02641139e6717924fdad716f6e958d0168491)

Rust
soroban-sdk = { version = "20.0.0-rc2", default-features = false }

What did you do?

I'm using the generated typescript binding and for a function returning an Option<(u32, u32)> throws an error when, it seems, the value is converted to native.

 error   Type [object Object] was not vec, but [object Object] is
  File:
    .../millionlumenhomepage/mlh-frontend/node_modules/Million/node_modules/soroban-client/lib/contract_spec.js:374:19
  Code:
    373 |             }
> 374 |             throw new TypeError("Type ".concat(typeDef, " was not vec, but ").concat(scv, " is"));
          |                   ^
      375 |           }
      376 |         case _stellarBase.xdr.ScValType.scvAddress().value:
      377 |           return _stellarBase.Address.fromScVal(scv);

The soroban function is like this:

    pub fn coords(env: Env, token_id: u32) -> Option<(u32, u32)> {
        Coords::Xy(token_id).get(&env)?
    }

And the javascript call that throws the error:

    let xy = await million.coords({token_id: parseInt(id)})

Calling the contract with the cli gives:

soroban contract invoke --id $(cat contract.id) --source user1 --network standalone -- coords --token_id 0
[17,31]
Dominant language
Rust
Stars
123
Forks
141
Avg merge
2d 21h
Merged PRs (30d)
17

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stellar/stellar-cli

All issues in stellar/stellar-cli

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.