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

Error deserializing multiple UTXOs #14

Open
AlejandroPajon opened this issue Dec 15, 2022 · 0 comments
Open

Error deserializing multiple UTXOs #14

AlejandroPajon opened this issue Dec 15, 2022 · 0 comments

Comments

@AlejandroPajon
Copy link

When deserializing multiple UTXOs from the same wallet, in some point of the rawUtxos the process crash with this error. When doing the same process to deserialize the same UTXO but not on a loop, it works fine. Anyone maybe knows what could it be?

This is the typescript code that we use to deserialize, and the error is on the picture above

getUtxos= async () => {
    let Utxos = [];
    try {
        const rawUtxos = await this.API.getUtxos();
        for (const rawUtxo of rawUtxos) {
            const utxo = TransactionUnspentOutput.from_bytes(Buffer.from(rawUtxo, "hex"));
            const input = utxo.input();
            const txid = Buffer.from(input.transaction_id().to_bytes(), "utf8").toString("hex");
            const txindx = input.index();
            const output = utxo.output();
            const amount = output.amount().coin().to_str(); // ADA amount in lovelace
            const multiasset = output.amount().multiasset();
            let multiAssetStr = "";


            if (multiasset) {
                const keys = multiasset.keys() // policy Ids of thee multiasset
                const N = keys.len();
                // console.log(`${N} Multiassets in the UTXO`)


                for (let i = 0; i < N; i++){
                    const policyId = keys.get(i);
                    const policyIdHex = Buffer.from(policyId.to_bytes(), "utf8").toString("hex");
                    // console.log(`policyId: ${policyIdHex}`)
                    const assets = multiasset.get(policyId) as Assets
                    const assetNames = assets.keys();
                    const K = assetNames.len()
                    // console.log(`${K} Assets in the Multiasset`)

                    for (let j = 0; j < K; j++) {
                        const assetName = assetNames.get(j);
                        const assetNameString = Buffer.from(assetName.name(),"utf8").toString();
                        const assetNameHex = Buffer.from(assetName.name(),"utf8").toString("hex")
                        const multiassetAmt = multiasset.get_asset(policyId, assetName)
                        multiAssetStr += `+ ${multiassetAmt.to_str()} + ${policyIdHex}.${assetNameHex} (${assetNameString})`
                        // console.log(assetNameString)
                        // console.log(`Asset Name: ${assetNameHex}`)
                    }
                }
            }
            const obj = {
                txid: txid,
                txindx: txindx,
                amount: amount,
                str: `${txid} #${txindx} = ${amount}`,
                multiAssetStr: multiAssetStr,
                TransactionUnspentOutput: utxo
            }
            Utxos.push(obj);
            // console.log(`utxo: ${str}`)
        }
        this.state.Utxos = Utxos
        //this.setState({Utxos})
        console.log(Utxos)
    } catch (err) {
        console.log(err)
    }
  }

eqjJV

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

1 participant