Skip to content

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

Open
@hoangong

Description

@hoangong

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions