0

i have an array address[] allAssets which holds list of addresses and it is populated with

[
        '0xc778417e063141139fce010982780140aa0cd5ab',
        '0xaD6D458402F60fD3Bd25163575031ACDce07538D',
        '0x3D0Fc2b7A17d61915bcCA984B9eAA087C5486d18',
        '0xDb28dc14E5Eb60559844F6f900d23Dce35FcaE33',
    ];

when i tried to delete first two address from list which gives the following removed list

[
  '0x0000000000000000000000000000000000000000',
  '0x0000000000000000000000000000000000000000',
  '0x3D0Fc2b7A17d61915bcCA984B9eAA087C5486d18',
  '0xDb28dc14E5Eb60559844F6f900d23Dce35FcaE33'
]

but i need it to be like

[
     
      '0x3D0Fc2b7A17d61915bcCA984B9eAA087C5486d18',
      '0xDb28dc14E5Eb60559844F6f900d23Dce35FcaE33'
    ]

Here is my code:

 mapping(address => bool) approvedDenominationAssets;
    address[] allAssets;


 function getIndex(address denomination) internal returns (uint256) {
        for (uint256 i = 0; i < allAssets.length; i++) {
            if (denomination == allAssets[i]) return i;
        }
    }

 function removeAssets(address[] memory _assets) external {
        for (uint256 i = 0; i < _assets.length; i++) {
            require(
                approvedDenominationAssets[_assets[i]] == true,
                "Asset doesn't exist"
            );
            delete approvedDenominationAssets[_assets[i]];
            delete allAssets[getIndex(_assets[i])];
            emit AssetsDeleted(_assets[i]);
        }
    }

Thanks in advance

2

0

Browse other questions tagged or ask your own question.