andy-dev
andy-dev

Reputation: 113

How to use PersistentUnorderedMap on NEAR contract using AssemblyScript? PersistentUnorderedMap does not appear in Contract Storage after init

In my contract I am attempting to use PersistentMap and PersistentUnorderedMap.

In my class I'm doing the following:

import { PersistentMap, PersistentUnorderedMap } from "near-sdk-core";

public vehicleOwners: PersistentMap<AccountId, VehicleOwner>;
public vehicleOwnersPmap: PersistentUnorderedMap<AccountId, VehicleOwner>;

constructor(public vehicle:string = 'Mini') {
    this.vehicleOwners = new PersistentMap<AccountId, VehicleOwner>("vo"),
    this.vehicleOwnersPmap = new PersistentUnorderedMap<AccountId,VehicleOwner>("pma")
  }

// Model
@nearBindgen
class VehicleOwner {
  constructor(public vehicleOwner: AccountId, public dateAcquired: string) {}
}

After running the init method near call $CONTRACT init --accountId $CONTRACT

If I check the contract's storage I see vehicleOwners but I do not see vehicleOwnersPmap.

state: {
  "vehicle": "Mini", 
  "vehicleOwners": {                                                             
     "_elementPrefix": "vo::"                                                     
   }

}

Upvotes: 2

Views: 109

Answers (1)

andy-dev
andy-dev

Reputation: 113

I figured out that after running one transaction and then seeing storage I can now see in state the PersistentUnorderedMap instance variable being set to null. I am still not sure why it won't show after init. This is different from PersistentMap where you can see it on state after init.

state: {
  "vehicle": "Mini",
  "vehicleOwnersPmap": null, 
  "vehicleOwners": {                                                             
     "_elementPrefix": "vo::"                                                     
   }
}

Upvotes: 2

Related Questions