Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot fetch offers - getOfferUTxOs #8

Open
HinsonSIDAN opened this issue Feb 20, 2024 · 4 comments
Open

Cannot fetch offers - getOfferUTxOs #8

HinsonSIDAN opened this issue Feb 20, 2024 · 4 comments

Comments

@HinsonSIDAN
Copy link
Collaborator

Calling this instance with implementation on here:
https://github.com/maestro-org/midi/blob/feature/direct-swap-single-asset-staking-apis/src/controllers/directSwap.controller/getAllOffers.controller.ts

Getting the error message of do not know how to serialize a bigint

@nikhils9
Copy link
Contributor

Can you provide the read permission for this repo?

@nikhils9
Copy link
Contributor

nikhils9 commented Feb 21, 2024

We generally solve this common serialization issue with bigint using a replacer function https://github.com/Anastasia-Labs/direct-offer-offchain/blob/main/src/core/utils/utils.ts#L187
In conjunction with JSON.stringify(offers, replacer)

@HinsonSIDAN
Copy link
Collaborator Author

Thanks for your swift reply! I can share the code snippet maybe, pretty much it is just directly calling the function, do i miss anything?

class GetAllOffersController implements Controller {
    public path = '/contracts/directSwap/getOffers'
    public router = Router()
    // placeholder for when/if we want to store these in a database
    // private getAllOffers = getAllOffersModel;

    constructor() {
        this.initializeRoutes()
    }

    private initializeRoutes() {
        this.router.get(this.path, this.createGetAllOffers)
    }

    private createGetAllOffers = async (
        request: Request,
        response: Response
    ) => {
        const acceptOfferConfig: FetchOfferConfig = {
            scripts: {
                spending: contracts.directOfferSpending.cborHex,
                staking: contracts.directOfferStaking.cborHex,
            },
        }

        try {
            const allOffers = await getOfferUTxOs(
                lucidSession,
                acceptOfferConfig
            )
            response.json(allOffers)
            return
        } catch (error) {
            response.status(400)
            const errMessageClean = error.message.toLowerCase()
            response.send(errMessageClean)
            console.log(error.message)
            return
        }
    }
}

@nikhils9
Copy link
Contributor

I believe the issue is occurring at response.json(allOffers)
Like I mentioned above its a serialization issue with bigint when you are trying to convert the allOffers into a json string maybe.
If you serialize it with a replacer function like we have one for JSON.stringify(offers, replacer) (https://github.com/Anastasia-Labs/direct-offer-offchain/blob/main/src/core/utils/utils.ts#L187 ) it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants