Skip to content

getMosaic DTO intermediary has no property nonce. #76

@Alexhuszagh

Description

@Alexhuszagh
  1. Expected behavior and actual behavior.

Calling MosaicHttp.getMosaic raises a TypeError, stating " TypeError: Cannot read property 'length' of undefined". The call should return a MosaicInfo object.

  1. Steps to reproduce the problem.

After running a local node on localhost:3000, simply run.

const nem2 = require('nem2-sdk');
var mosaicHttp = new nem2.MosaicHttp('http://localhost:3000');
var mosaicId = new nem2.MosaicId([3646934825, 3576016193]);
mosaicHttp.getMosaic(mosaicId).subscribe(x => console.log(x), err => console.error(err));
  1. Bug Cause

The source code attempts to read the mosaicInfoDTO.mosaic.nonce from the data-transfer object, a property which is never defined, and not present in the raw HTTP response.

    /**
     * Gets the MosaicInfo for a given mosaicId
     * @param mosaicId - Mosaic id
     * @returns Observable<MosaicInfo>
     */
    public getMosaic(mosaicId: MosaicId): Observable<MosaicInfo> {
        return this.getNetworkTypeObservable().pipe(
            mergeMap((networkType) => observableFrom(
                this.mosaicRoutesApi.getMosaic(mosaicId.toHex())).pipe(map((mosaicInfoDTO) => {
                return new MosaicInfo(
                    mosaicInfoDTO.meta.active,
                    mosaicInfoDTO.meta.index,
                    mosaicInfoDTO.meta.id,
                    new MosaicId(mosaicInfoDTO.mosaic.mosaicId),
                    new UInt64(mosaicInfoDTO.mosaic.nonce),
                    new UInt64(mosaicInfoDTO.mosaic.supply),
                    new UInt64(mosaicInfoDTO.mosaic.height),
                    PublicAccount.createFromPublicKey(mosaicInfoDTO.mosaic.owner, networkType),
                    new MosaicProperties(
                        new UInt64(mosaicInfoDTO.mosaic.properties[0]),
                        (new UInt64(mosaicInfoDTO.mosaic.properties[1])).compact(),
                        new UInt64(mosaicInfoDTO.mosaic.properties[2]),
                    ),
                    mosaicInfoDTO.mosaic.levy,
                );
            }))));
    }

The actual response object also has no nonce property, which is shown from a sample response from GET http://localhost:3000/mosaic/d525ad41d95fcf29

[
  {
    "meta": {
      "active": true,
      "index": 0,
      "id": "5C7C07005CC1FE000176FA2C"
    },
    "mosaic": {
      "namespaceId": [929036875, 2226345261],
      "mosaicId": [3646934825, 3576016193],
      "supply": [3403414400, 2095475],
      "height": [1, 0],
      "owner": "7A562888C7AE1E082579951D6D93BF931DE979360ACCA4C4085D754E5E122808",
      "properties": [[2, 0], [6, 0], [0, 0]],
      "levy": {}
    }
  }
]
  1. Specifications like the version of the project, operating system, or hardware.

Running "nem2-sdk" version "0.10.3-1", on Fedora, Linux.

Metadata

Metadata

Assignees

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