zingolabs / zingolib

An API and test-app that exposes zcash functionality for app consumption
MIT License
15 stars 23 forks source link

Command `balance` result is not a valid JSON string #1485

Closed juanky201271 closed 3 weeks ago

juanky201271 commented 3 weeks ago

Ref: https://github.com/zingolabs/zingolib/pull/1464

I don't really understand why the balance command changed from a valid JSON string to something else...

Before:

{
  "sapling_balance": 0,
  "verified_sapling_balance": 0,
  "spendable_sapling_balance": null,
  "unverified_sapling_balance": 0,
  "orchard_balance": 4835100,
  "verified_orchard_balance": 4835100,
  "unverified_orchard_balance": 0,
  "spendable_orchard_balance": null,
  "transparent_balance": null
}

Now:

[
    sapling_balance: 20_0000
    verified_sapling_balance: 20_0000
    spendable_sapling_balance: 20_0000
    unverified_sapling_balance: 0

    orchard_balance: 972_8000
    verified_orchard_balance: 972_8000
    spendable_orchard_balance: 972_8000
    unverified_orchard_balance: 0

    transparent_balance: 19_2000
]

When we change some command result, we need to think about the consumers like our friend: zingo-mobile. Please someone can fix this soon?

james-katz commented 3 weeks ago

Yes, updating my projects to the new version of Zingolib, but got stuck on this for hours. For now my workaround is to recreate a valid JSON from the result:

const balStr = await native.zingolib_execute_async('balance', '');
const validJsonStr = balStr
                .replace(/[\[\]]/g, '') // Remove square braces
                .replace(/(\s*\w+:\s*[\d_]+)/g, '$1,') // Add commas after each entry
                .replace(/(\w+):/g, '"$1":') // Add double quotes to value name
                .replace(/_/g, '') // Remove underscores
                .replace(/,\s*$/, '') // Remove trailing comma
                .trim(); // Trim  whitespace or line breaks
const balJson = JSON.parse(`{${validJsonStr}}`); // Add curly braces before parsing

It's awful, but works. Will the command balance be back to "normal" ?

fluidvanadium commented 3 weeks ago

Ooops! Didnt realize this string needed to be JSON. reverted and documented in #1492

juanky201271 commented 3 weeks ago

Thanks @fluidvanadium the balance command is fixed.

fluidvanadium commented 3 weeks ago

sorry @james-katz