Giter Club home page Giter Club logo

Comments (4)

collincusce avatar collincusce commented on July 24, 2024

What are these bytes and where did you get them? When I try to parse them using Tx.fromBuffer() I get different messages.

from avalanchejs.

federicospini avatar federicospini commented on July 24, 2024

Examples are OperationTxs on X-Chain. Bytes come from getTx API of avalanchego and they are CB58-encoded.

Here follows the whole stacktrace for Example n.1 and n.2:

Error: Error - NBytes.fromBuffer: Error: Buffer length must be 20 bytes. Only have 6 remaining in buffer.
    at Address.fromBuffer (/home/XXX/parsetx/node_modules/avalanche/dist/common/nbytes.js:81:19)
    at SECPTransferOutput.fromBuffer (/home/XXX/parsetx/node_modules/avalanche/dist/common/output.js:242:27)
    at SECPTransferOutput.fromBuffer (/home/XXX/parsetx/node_modules/avalanche/dist/common/output.js:404:22)
    at SECPMintOperation.fromBuffer (/home/XXX/parsetx/node_modules/avalanche/dist/apis/avm/ops.js:308:34)
    at TransferableOperation.fromBuffer (/home/XXX/parsetx/node_modules/avalanche/dist/apis/avm/ops.js:202:31)
    at OperationTx.fromBuffer (/home/XXX/parsetx/node_modules/avalanche/dist/apis/avm/operationtx.js:91:25)
    at UnsignedTx.fromBuffer (/home/XXX/parsetx/node_modules/avalanche/dist/apis/avm/tx.js:75:33)
    at Tx.fromBuffer (/home/XXX/parsetx/node_modules/avalanche/dist/apis/avm/tx.js:120:34)
    at main (/home/XXX/parsetx/index.js:28:23)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Here follows the whole stacktrace for Example n.3:

Error: Error - SelectCredentialClass: unknown credid 0
    at Object.exports.SelectCredentialClass (/home/XXX/parsetx/node_modules/avalanche/dist/apis/avm/credentials.js:35:11)
    at Tx.fromBuffer (/home/XXX/parsetx/node_modules/avalanche/dist/apis/avm/tx.js:127:40)
    at main (/home/XXX/parsetx/index.js:28:23)
    at processTicksAndRejections (internal/process/task_queues.js:93:5

The issue is that SECPMintOperation has a single TransferOutput (as reported here https://github.com/ava-labs/avalanchego/blob/master/vms/avm/vm.go#L1053), but here https://github.com/ava-labs/avalanchejs/blob/master/src/apis/avm/ops.ts#L323 a list of TransferOutputs is parsed.

from avalanchejs.

collincusce avatar collincusce commented on July 24, 2024

Great!! Thanks! I'll work on a patch as my next priority after what I'm currently on.

from avalanchejs.

cgcardona avatar cgcardona commented on July 24, 2024

This has been resolved. You can parse the bytes like so

import { BinTools, Buffer } from "../../src"
import {
  Tx,
} from "../../src/apis/avm"

const bintools: BinTools = BinTools.getInstance()
const bytes: string = "11111eqtQvbRXgLu2Ggh1sfXyRxKRFwxiSC283i1LX8fS8uyHtcbbWDxASbh9ktwpg45Hnb5DXR8rHHp9opSTuPZZ1yHpPXP2dm6WDJtjJsmjcSCptEscH2dUJB1JEw2hTDWjrWZAjTKZiY2RHrJrEcsySqJA1byCMpxekKByTkpHJd8TjGLqEFsf5qmY8LxmAhUi16zoJhXAbLRHgiwTQ9vTxAdL4SUpmTjjnKWdF5Jh59CNfF61KZGzWy7ATxjGLL9RGzy1rQrxLvnL8KxFx8HyShNYrPdoLsRkwVA6htAfN9DaLen2WyGpjCCfMShzAhfqD1bdKshVNncviLEXisCds2dnjLspeTudhBocqA7fsb5bVPHD15Lrvdk3RZsRBBoiFi1MkFxsRFWRDwej4izcj7UUoXE3vUJkev7hgdPoALUDjfgsyTTHei3nSrFbVYhe7MGWBRi8aqsdEurLf9ttQEirfpLbtiK1owbwm8Cs8VuW6Mzj58tJbsh14dqHAMF7zoPuA2GWBcvxczdJTS17RpYMdNbJtwXqxGw9QD4brHwZr1SewAd1nyZwpVquYvSwNMaMbtYuowVXzXaJ9VBR4EBN3skqZLVpomXCFvzw34Ry2RDGHAKa4nRWsY6vTaQ1ZFhUPYQknj82ru4axs8zZyWSCHx5bsvc2Nj9TmaC9Paubwb4b9YFkrhGfwBQHrUybWxMepuSg5GnKQvV8MXVZUTJgEyWb72"
const bytesBuf: Buffer = bintools.cb58Decode(bytes)

const main = async (): Promise<any> => {
  const tx: Tx = new Tx()
  tx.fromBuffer(bytesBuf)
  console.log(tx)
}

main()

from avalanchejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.