onflow/flow-core-contracts

RandomBeaconHistory.getRandomSourceHistoryPage() performs impure function under Cadence 1.0

sisyphusSmiling opened this issue · 1 comments

Problem

The method getRandomSourceHistoryPage() is labeled view but, according to errors using Cadence 1.0, performs impure operation on the values: [RandomSource] array constructed and manipulated within its scope.

This should be an easy fix - remove the view label from the method.

Steps to Reproduce

Attempt to deploy RandomBeaconHistory to emulator (after a quick 1.0 refactor), and the deployment will fail with the following output:

Deploying 1 contracts for accounts: emulator-account

❌ Failed to deploy contract RandomBeaconHistory: failed to deploy contract RandomBeaconHistory: [Error Code: 1101] error caused by: 1 error occurred:
	* transaction execute failed: [Error Code: 1101] cadence runtime error: Execution failed:
error: cannot deploy invalid contract
 --> 7109abdfd44d02e5fe2951520d51e021c894f321adb521f97870282ac53b0d92:4:3
  |
4 | 			signer.contracts.add(name: name, code: code.decodeHex() )
  | 			^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: Impure operation performed in view context
   --> f8d6e0586b0a20c7.RandomBeaconHistory:131:19
    |
131 |             return RandomSourceHistoryPage(page: page, perPage: perPage, totalLength: totalLength, values: values)
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: Impure operation performed in view context
   --> f8d6e0586b0a20c7.RandomBeaconHistory:137:12
    |
137 |             values.append(
138 |                 RandomSource(
139 |                     blockHeight: lowestHeight + startIndex + UInt64(i),
140 |                     value: self.randomSourceHistory[startIndex + UInt64(i)]
141 |                 )
142 |             )
    |             ^

error: Impure operation performed in view context
   --> f8d6e0586b0a20c7.RandomBeaconHistory:138:16
    |
138 |                 RandomSource(
139 |                     blockHeight: lowestHeight + startIndex + UInt64(i),
140 |                     value: self.randomSourceHistory[startIndex + UInt64(i)]
141 |                 )
    |                 ^

error: Impure operation performed in view context
   --> f8d6e0586b0a20c7.RandomBeaconHistory:145:15
    |
145 |         return RandomSourceHistoryPage(
146 |             page: page,
147 |             perPage: perPage,
148 |             totalLength: totalLength,
149 |             values: values
150 |         )
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Fixed in e45ba2b