Skip to content

Commit 267ac50

Browse files
authored
Merge branch 'master' into feature/efm-recovery
2 parents 94bb980 + 4d0e1d8 commit 267ac50

File tree

12 files changed

+152
-2209
lines changed

12 files changed

+152
-2209
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// FlowExecutionParameters stores the parameters for metering
2+
/// transaction fees for Flow transactions
3+
4+
access(all) contract FlowExecutionParameters {
5+
6+
// Gets Execution Effort Weights from the parameters account's storage
7+
access(all) view fun getExecutionEffortWeights(): {UInt64: UInt64} {
8+
return self.account.storage.copy<{UInt64: UInt64}>(from: /storage/executionEffortWeights)
9+
?? panic("execution effort weights not set yet")
10+
}
11+
12+
// Gets Execution Memory Weights from the parameters account's storage
13+
access(all) view fun getExecutionMemoryWeights(): {UInt64: UInt64} {
14+
return self.account.storage.copy<{UInt64: UInt64}>(from: /storage/executionMemoryWeights)
15+
?? panic("execution memory weights not set yet")
16+
}
17+
18+
// Gets Execution Memory Limit from the parameters account's storage
19+
access(all) view fun getExecutionMemoryLimit(): UInt64 {
20+
return self.account.storage.copy<UInt64>(from: /storage/executionMemoryLimit)
21+
?? panic("execution memory limit not set yet")
22+
}
23+
}

contracts/FlowServiceAccount.cdc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import FungibleToken from "FungibleToken"
22
import FlowToken from "FlowToken"
33
import FlowFees from "FlowFees"
44
import FlowStorageFees from "FlowStorageFees"
5+
import FlowExecutionParameters from "FlowExecutionParameters"
56

67
access(all) contract FlowServiceAccount {
78

@@ -128,20 +129,17 @@ access(all) contract FlowServiceAccount {
128129

129130
// Gets Execution Effort Weights from the service account's storage
130131
access(all) view fun getExecutionEffortWeights(): {UInt64: UInt64} {
131-
return self.account.storage.copy<{UInt64: UInt64}>(from: /storage/executionEffortWeights)
132-
?? panic("execution effort weights not set yet")
132+
return FlowExecutionParameters.getExecutionEffortWeights()
133133
}
134134

135135
// Gets Execution Memory Weights from the service account's storage
136136
access(all) view fun getExecutionMemoryWeights(): {UInt64: UInt64} {
137-
return self.account.storage.copy<{UInt64: UInt64}>(from: /storage/executionMemoryWeights)
138-
?? panic("execution memory weights not set yet")
137+
return FlowExecutionParameters.getExecutionMemoryWeights()
139138
}
140139

141140
// Gets Execution Memory Limit from the service account's storage
142141
access(all) view fun getExecutionMemoryLimit(): UInt64 {
143-
return self.account.storage.copy<UInt64>(from: /storage/executionMemoryLimit)
144-
?? panic("execution memory limit not set yet")
142+
return FlowExecutionParameters.getExecutionMemoryLimit()
145143
}
146144

147145
/// Authorization resource to change the fields of the contract

lib/go/contracts/contracts.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
const (
2929
flowFeesFilename = "FlowFees.cdc"
3030
storageFeesFilename = "FlowStorageFees.cdc"
31+
executionParametersFilename = "FlowExecutionParameters.cdc"
3132
flowServiceAccountFilename = "FlowServiceAccount.cdc"
3233
flowTokenFilename = "FlowToken.cdc"
3334
flowIdentityTableFilename = "FlowIDTableStaking.cdc"
@@ -171,13 +172,51 @@ func FlowStorageFees(env templates.Environment) []byte {
171172
return []byte(code)
172173
}
173174

175+
// FlowExecutionParameters returns the FlowExecutionParameters contract
176+
func FlowExecutionParameters(env templates.Environment) []byte {
177+
code := assets.MustAssetString(executionParametersFilename)
178+
179+
code = templates.ReplaceAddresses(code, env)
180+
181+
return []byte(code)
182+
}
183+
174184
// FlowServiceAccount returns the FlowServiceAccount contract.
175185
//
176186
// The returned contract will import the FungibleToken, FlowToken, FlowFees, and FlowStorageFees
177187
// contracts from the specified addresses.
178188
func FlowServiceAccount(env templates.Environment) []byte {
179189
code := assets.MustAssetString(flowServiceAccountFilename)
180190

191+
if env.FlowExecutionParametersAddress == "" {
192+
193+
// Remove the import of FlowExecutionParameters
194+
code = strings.ReplaceAll(
195+
code,
196+
"import FlowExecutionParameters from \"FlowExecutionParameters\"",
197+
"//import FlowExecutionParameters from \"FlowExecutionParameters\"",
198+
)
199+
200+
// Replace the metering getter functions
201+
code = strings.ReplaceAll(
202+
code,
203+
"return FlowExecutionParameters.getExecutionEffortWeights()",
204+
"return self.account.storage.copy<{UInt64: UInt64}>(from: /storage/executionEffortWeights) ?? panic(\"execution effort weights not set yet\")",
205+
)
206+
207+
code = strings.ReplaceAll(
208+
code,
209+
"return FlowExecutionParameters.getExecutionMemoryWeights()",
210+
"return self.account.storage.copy<{UInt64: UInt64}>(from: /storage/executionMemoryWeights) ?? panic(\"execution memory weights not set yet\")",
211+
)
212+
213+
code = strings.ReplaceAll(
214+
code,
215+
"return FlowExecutionParameters.getExecutionMemoryLimit()",
216+
"return self.account.storage.copy<UInt64>(from: /storage/executionMemoryLimit) ?? panic(\"execution memory limit not set yet\")",
217+
)
218+
}
219+
181220
code = templates.ReplaceAddresses(code, env)
182221

183222
return []byte(code)

lib/go/contracts/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toolchain go1.22.4
66

77
require (
88
github.com/kevinburke/go-bindata v3.24.0+incompatible
9-
github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240215153337-0be5cb4b4bc9
9+
github.com/onflow/flow-core-contracts/lib/go/templates v1.4.1-0.20250121150329-3add9787ef8b
1010
github.com/onflow/flow-ft/lib/go/contracts v1.0.1
1111
github.com/onflow/flow-nft/lib/go/contracts v1.2.2
1212
github.com/stretchr/testify v1.9.0
@@ -37,9 +37,9 @@ require (
3737
github.com/onflow/atree v0.8.0-rc.6 // indirect
3838
github.com/onflow/cadence v1.0.0-preview.51 // indirect
3939
github.com/onflow/crypto v0.25.1 // indirect
40-
github.com/onflow/flow-ft/lib/go/templates v0.7.1-0.20240213220156-959b70719876 // indirect
40+
github.com/onflow/flow-ft/lib/go/templates v1.0.1 // indirect
4141
github.com/onflow/flow-go-sdk v1.0.0-preview.54 // indirect
42-
github.com/onflow/flow-nft/lib/go/templates v0.0.0-20240213205729-48f42d9896f8 // indirect
42+
github.com/onflow/flow-nft/lib/go/templates v1.2.1 // indirect
4343
github.com/onflow/flow/protobuf/go/flow v0.4.3 // indirect
4444
github.com/onflow/go-ethereum v1.13.4 // indirect
4545
github.com/pelletier/go-toml v1.2.0 // indirect

0 commit comments

Comments
 (0)