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

Why are some Tx objects not extended from AvaxTx or Transaction? #905

Open
hoangong opened this issue Nov 8, 2024 · 0 comments
Open

Why are some Tx objects not extended from AvaxTx or Transaction? #905

hoangong opened this issue Nov 8, 2024 · 0 comments

Comments

@hoangong
Copy link

hoangong commented Nov 8, 2024

For example CreateAssetTx.

The issue is that there is no consistent way to getInputs or serialize it using toBytes()

This is how I currently read the inputs

const inputs: avaxSerial.TransferableInput[] = [];
  // @ts-ignore
  if (transaction.unsignedTx.inputs) {
    // @ts-ignore
    inputs.push(...transaction.unsignedTx.inputs);
    // @ts-ignore
  } else if (transaction.unsignedTx.baseTx.inputs) {
    // @ts-ignore
    inputs.push(...transaction.unsignedTx.baseTx.inputs);
  }

and this is how I serialize

export function serializeSignedTx(tx: avaxSerial.SignedTx): Buffer {
  if (tx.unsignedTx.vm) {
    return Buffer.from(tx.toBytes());
  } else if (tx.unsignedTx._type.startsWith('avm.')) {
    return Buffer.from(
      utils.concatBytes(
        new Short(0).toBytes(),
        utils.getManagerForVM('AVM').codecs[0].PackPrefix(tx.unsignedTx),
        utils.getManagerForVM('AVM').codecs[0].PackPrefixList(tx.credentials),
      ),
    );
  } else {
    return Buffer.from(
      utils.concatBytes(
        new Short(0).toBytes(),
        utils.getManagerForVM('PVM').codecs[0].PackPrefix(tx.unsignedTx),
        utils.getManagerForVM('PVM').codecs[0].PackPrefixList(tx.credentials),
      ),
    );
  }
}

is there better way?

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