Open HinsonSIDAN opened 8 months ago
Can you provide the read permission for this repo?
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)
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
}
}
}
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.
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